Back to index

indicator-session  12.10.0
Classes | Defines | Typedefs | Functions | Variables
dialog.c File Reference
#include <glib/gi18n.h>
#include "dbus-consolekit-manager.h"
#include "dialog.h"

Go to the source code of this file.

Classes

struct  _LogoutDialogPrivate

Defines

#define LOGOUT_DIALOG_GET_PRIVATE(o)   (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOGOUT_DIALOG_TYPE, LogoutDialogPrivate))

Typedefs

typedef struct _LogoutDialogPrivate

Functions

static void logout_dialog_class_init (LogoutDialogClass *klass)
static void logout_dialog_init (LogoutDialog *self)
static void logout_dialog_dispose (GObject *object)
static void logout_dialog_finalize (GObject *object)
 G_DEFINE_TYPE (LogoutDialog, logout_dialog, GTK_TYPE_MESSAGE_DIALOG)
static gboolean check_restart_required (void)
static gboolean ck_check_allowed (LogoutDialogType type)
LogoutDialog * logout_dialog_new (LogoutDialogType type)

Variables

static const gchar * title_strings [LOGOUT_DIALOG_TYPE_CNT]
static const gchar * body_strings [LOGOUT_DIALOG_TYPE_CNT]
static const gchar * button_strings [LOGOUT_DIALOG_TYPE_CNT]
static const gchar * button_auth_strings [LOGOUT_DIALOG_TYPE_CNT]
static const gchar * restart_updates = N_("Restart Instead")
static const gchar * restart_auth = N_("Restart Instead…")
static const gchar * body_logout_update = N_("Some software updates won’t apply until the computer next restarts.")
static const gchar * icon_strings [LOGOUT_DIALOG_TYPE_CNT]

Class Documentation

struct _LogoutDialogPrivate

Definition at line 76 of file dialog.c.

Class Members
guint type

Define Documentation

#define LOGOUT_DIALOG_GET_PRIVATE (   o)    (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOGOUT_DIALOG_TYPE, LogoutDialogPrivate))

Definition at line 80 of file dialog.c.


Typedef Documentation

typedef struct _LogoutDialogPrivate

Definition at line 75 of file dialog.c.


Function Documentation

static gboolean check_restart_required ( void  ) [static]

Definition at line 131 of file dialog.c.

{
       return g_file_test("/var/run/reboot-required", G_FILE_TEST_EXISTS);
}

Here is the caller graph for this function:

static gboolean ck_check_allowed ( LogoutDialogType  type) [static]

Definition at line 138 of file dialog.c.

{
       gboolean allowed = TRUE;

       ConsoleKitManager * ck_proxy = console_kit_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
                                                                                  G_DBUS_PROXY_FLAGS_NONE,
                                                                                  "org.freedesktop.ConsoleKit",
                                                                                  "/org/freedesktop/ConsoleKit/Manager",
                                                                                  NULL,
                                                                                  NULL);
       if (ck_proxy != NULL)
       {
              switch (type) {
              case LOGOUT_DIALOG_TYPE_RESTART:
                     console_kit_manager_call_can_restart_sync (ck_proxy, &allowed, NULL, NULL);
                     break;
              case LOGOUT_DIALOG_TYPE_SHUTDOWN:
                     console_kit_manager_call_can_stop_sync (ck_proxy, &allowed, NULL, NULL);
                     break;
              default:
                     break;
              }

              g_object_unref(ck_proxy);
       }

       return allowed;
}

Here is the call graph for this function:

Here is the caller graph for this function:

G_DEFINE_TYPE ( LogoutDialog  ,
logout_dialog  ,
GTK_TYPE_MESSAGE_DIALOG   
)
static void logout_dialog_class_init ( LogoutDialogClass *  klass) [static]

Definition at line 91 of file dialog.c.

{
       GObjectClass *object_class = G_OBJECT_CLASS (klass);

       g_type_class_add_private (klass, sizeof (LogoutDialogPrivate));

       object_class->dispose = logout_dialog_dispose;
       object_class->finalize = logout_dialog_finalize;

       return;
}

Here is the call graph for this function:

static void logout_dialog_dispose ( GObject *  object) [static]

Definition at line 111 of file dialog.c.

{


       G_OBJECT_CLASS (logout_dialog_parent_class)->dispose (object);
       return;
}

Here is the caller graph for this function:

static void logout_dialog_finalize ( GObject *  object) [static]

Definition at line 120 of file dialog.c.

{


       G_OBJECT_CLASS (logout_dialog_parent_class)->finalize (object);
       return;
}

Here is the caller graph for this function:

static void logout_dialog_init ( LogoutDialog *  self) [static]

Definition at line 104 of file dialog.c.

{

       return;
}
LogoutDialog* logout_dialog_new ( LogoutDialogType  type)

Definition at line 168 of file dialog.c.

{
       GtkWidget * image = gtk_image_new_from_icon_name(icon_strings[type], GTK_ICON_SIZE_DIALOG);
       gtk_widget_show(image);

       LogoutDialog * dialog = LOGOUT_DIALOG(g_object_new(LOGOUT_DIALOG_TYPE,
                                             /* Window */
                                             "icon-name", icon_strings[type],
                                             "modal", TRUE,
                                             "resizable", FALSE,
                                             "title", g_dpgettext2 (NULL, "title", title_strings[type]),
                                             "window-position", GTK_WIN_POS_CENTER_ALWAYS,
                                             /* Message Dialog */
                                             "buttons", GTK_BUTTONS_NONE,
                                             "image", image,
                                             "message-type", GTK_MESSAGE_OTHER,
                                             "text", _(body_strings[type]),
                                             NULL));

       gtk_window_set_keep_above(GTK_WINDOW(dialog), TRUE);

       gboolean allowed = FALSE;
       if (type == LOGOUT_DIALOG_TYPE_LOG_OUT) {
              allowed = ck_check_allowed(LOGOUT_DIALOG_TYPE_RESTART);
       } else {
              allowed = ck_check_allowed(type);
       }

       gboolean restart_required = FALSE;
       if (type == LOGOUT_DIALOG_TYPE_LOG_OUT) {
              restart_required = check_restart_required();
       }

       const gchar * button_text;
       if (allowed) {
              button_text = g_dpgettext2 (NULL, "button", button_strings[type]);
       } else {
              button_text = g_dpgettext2 (NULL, "button auth", button_auth_strings[type]);
       }

       if (restart_required) {
              const gchar * restart_req;
              if (allowed) {
                     restart_req = restart_updates;
              } else {
                     restart_req = restart_auth;
              }

              g_object_set(dialog, "secondary-text", _(body_logout_update), NULL);

              gtk_dialog_add_buttons(GTK_DIALOG(dialog),
                                     _(restart_req), GTK_RESPONSE_HELP,
                                     _("Cancel"), GTK_RESPONSE_CANCEL,
                                     button_text, GTK_RESPONSE_OK,
                                     NULL);
       } else {
              gtk_dialog_add_buttons(GTK_DIALOG(dialog),
                                     _("Cancel"), GTK_RESPONSE_CANCEL,
                                     button_text, GTK_RESPONSE_OK,
                                     NULL);
       }

       if (type == LOGOUT_DIALOG_TYPE_SHUTDOWN) {
              const gchar * restart_text;
              restart_text = g_dpgettext2 (NULL, "button", button_strings[LOGOUT_DIALOG_TYPE_RESTART]);
              gtk_dialog_add_button (GTK_DIALOG(dialog), restart_text, GTK_RESPONSE_HELP);
       }

       gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);

        /* The following  is a workaround to fix an issue in GtkMessageDialog
           in which the user can tab through the text in addition to
           the buttons. */
        GtkWidget *message_area = gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(dialog));
        GList *children = gtk_container_get_children(GTK_CONTAINER(message_area));
        GList *l;

        for (l = children; l != NULL; l = g_list_next (l))
        {
                GtkWidget *child = l->data;
                gtk_widget_set_can_focus(child, FALSE);
        }

        g_list_free (children);

       return dialog;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const gchar* body_logout_update = N_("Some software updates won’t apply until the computer next restarts.") [static]

Definition at line 65 of file dialog.c.

const gchar* body_strings[LOGOUT_DIALOG_TYPE_CNT] [static]
Initial value:
 {
              N_("Are you sure you want to close all programs and log out of the computer?"),
              N_("Are you sure you want to close all programs and restart the computer?"),
              N_("Are you sure you want to close all programs and shut down the computer?")
}

Definition at line 40 of file dialog.c.

const gchar* button_auth_strings[LOGOUT_DIALOG_TYPE_CNT] [static]
Initial value:
 {
              NC_("button auth", "Log Out"),
              NC_("button auth", "Restart…"),
              NC_("button auth", "Switch Off…")
}

Definition at line 54 of file dialog.c.

const gchar* button_strings[LOGOUT_DIALOG_TYPE_CNT] [static]
Initial value:
 {
              NC_("button", "Log Out"),
              NC_("button", "Restart"),
              NC_("button", "Switch Off")
}

Definition at line 46 of file dialog.c.

const gchar* icon_strings[LOGOUT_DIALOG_TYPE_CNT] [static]
Initial value:
 {
              "system-log-out",
              "system-restart",
              "system-shutdown"
}

Definition at line 67 of file dialog.c.

const gchar* restart_auth = N_("Restart Instead…") [static]

Definition at line 64 of file dialog.c.

const gchar* restart_updates = N_("Restart Instead") [static]

Definition at line 63 of file dialog.c.

const gchar* title_strings[LOGOUT_DIALOG_TYPE_CNT] [static]
Initial value:
 {
              NC_("title", "Log Out"),
              NC_("title", "Restart"),
              NC_("title", "Switch Off")
}

Definition at line 34 of file dialog.c.