From 68d13604c069937cdb1e6cab3ecd54cfb45fc593 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Mar 2010 15:49:41 -0600 Subject: Flattening the build tree. --- src/dialog.c | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 src/dialog.c (limited to 'src/dialog.c') diff --git a/src/dialog.c b/src/dialog.c new file mode 100644 index 0000000..7e2347e --- /dev/null +++ b/src/dialog.c @@ -0,0 +1,153 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "dialog.h" + +/* Strings */ + +static const gchar * title_strings[LOGOUT_DIALOG_TYPE_CNT] = { + /* LOGOUT_DIALOG_LOGOUT, */ NC_("title", "Log Out"), + /* LOGOUT_DIALOG_RESTART, */ NC_("title", "Restart"), + /* LOGOUT_DIALOG_SHUTDOWN, */ NC_("title", "Switch Off") +}; + +static const gchar * body_strings[LOGOUT_DIALOG_TYPE_CNT] = { + /* LOGOUT_DIALOG_LOGOUT, */ N_("Are you sure you want to close all programs and log out?"), + /* LOGOUT_DIALOG_RESTART, */ N_("Are you sure you want to close all programs and restart the computer?"), + /* LOGOUT_DIALOG_SHUTDOWN, */ N_("Are you sure you want to close all programs and shut down the computer?") +}; + +static const gchar * button_strings[LOGOUT_DIALOG_TYPE_CNT] = { + /* LOGOUT_DIALOG_LOGOUT, */ NC_("button", "Log Out"), + /* LOGOUT_DIALOG_RESTART, */ NC_("button", "Restart"), + /* LOGOUT_DIALOG_SHUTDOWN, */ NC_("button", "Switch Off") +}; + +/* +static const gchar * restart_updates = N_("Restart Instead"); +static const gchar * restart_auth = N_("Restart..."); +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] = { + /* LOGOUT_DIALOG_LOGOUT, */ "system-log-out", + /* LOGOUT_DIALOG_RESTART, */ "system-restart", + /* LOGOUT_DIALOG_SHUTDOWN, */ "system-shutdown" +}; + + + +typedef struct _LogoutDialogPrivate LogoutDialogPrivate; +struct _LogoutDialogPrivate { + guint type; +}; + +#define LOGOUT_DIALOG_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), LOGOUT_DIALOG_TYPE, LogoutDialogPrivate)) + +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 void +logout_dialog_class_init (LogoutDialogClass *klass) +{ + 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; +} + +static void +logout_dialog_init (LogoutDialog *self) +{ + + return; +} + +static void +logout_dialog_dispose (GObject *object) +{ + + + G_OBJECT_CLASS (logout_dialog_parent_class)->dispose (object); + return; +} + +static void +logout_dialog_finalize (GObject *object) +{ + + + G_OBJECT_CLASS (logout_dialog_parent_class)->finalize (object); + return; +} + +/* Checks for updates that would signal that a restart is + required for them to apply */ +static gboolean +check_restart_required (void) +{ + + return FALSE; +} + +/* Checks with console kit to see if we can do what we want */ +static gboolean +ck_check_allowed (LogoutDialogType type) +{ + + + + return TRUE; +} + +LogoutDialog * +logout_dialog_new (LogoutDialogType type) +{ + 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", _(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)); + + 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(); + } + + gtk_dialog_add_buttons(GTK_DIALOG(dialog), + _("Cancel"), GTK_RESPONSE_CANCEL, + _(button_strings[type]), GTK_RESPONSE_OK, + NULL); + + return dialog; +} -- cgit v1.2.3 From 2ae450d4f50ed3da4383ad5e4fcd470986deee3b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Mar 2010 16:18:00 -0600 Subject: Filling in the code to check and see if we can restart or stop. --- src/dialog.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/dialog.c') diff --git a/src/dialog.c b/src/dialog.c index 7e2347e..6dd7a90 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -4,6 +4,7 @@ #include +#include "consolekit-manager-client.h" #include "dialog.h" /* Strings */ @@ -106,10 +107,30 @@ check_restart_required (void) static gboolean ck_check_allowed (LogoutDialogType type) { + DBusGConnection * system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); + g_return_val_if_fail(system_bus != NULL, TRUE); + + DBusGProxy * ck_proxy = dbus_g_proxy_new_for_name (system_bus, + "org.freedesktop.ConsoleKit", + "/org/freedesktop/ConsoleKit/Manager", + "org.freedesktop.ConsoleKit.Manager"); + g_return_val_if_fail(ck_proxy != NULL, TRUE); + + gboolean retval = TRUE; + switch (type) { + case LOGOUT_DIALOG_TYPE_RESTART: + org_freedesktop_ConsoleKit_Manager_can_restart(ck_proxy, &retval, NULL); + break; + case LOGOUT_DIALOG_TYPE_SHUTDOWN: + org_freedesktop_ConsoleKit_Manager_can_stop(ck_proxy, &retval, NULL); + break; + default: + break; + } + g_object_unref(ck_proxy); - - return TRUE; + return retval; } LogoutDialog * -- cgit v1.2.3 From a76563f00527498fd4121d2b824ef622bc062985 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Mar 2010 16:38:44 -0600 Subject: Adding in different button strings if we need authentication. --- src/dialog.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/dialog.c') diff --git a/src/dialog.c b/src/dialog.c index 6dd7a90..dd681b3 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -27,6 +27,14 @@ static const gchar * button_strings[LOGOUT_DIALOG_TYPE_CNT] = { /* LOGOUT_DIALOG_SHUTDOWN, */ NC_("button", "Switch Off") }; +/* TRANSLATORS: These strings have an ellipsis so that the user knows + they are also going to get a password dialog to do the action. */ +static const gchar * button_auth_strings[LOGOUT_DIALOG_TYPE_CNT] = { + /* LOGOUT_DIALOG_LOGOUT, */ NC_("button auth", "Log Out"), + /* LOGOUT_DIALOG_RESTART, */ NC_("button auth", "Restart..."), + /* LOGOUT_DIALOG_SHUTDOWN, */ NC_("button auth", "Switch Off...") +}; + /* static const gchar * restart_updates = N_("Restart Instead"); static const gchar * restart_auth = N_("Restart..."); @@ -165,9 +173,16 @@ logout_dialog_new (LogoutDialogType type) restart_required = check_restart_required(); } + const gchar * button_text; + if (allowed) { + button_text = _(button_strings[type]); + } else { + button_text = _(button_auth_strings[type]); + } + gtk_dialog_add_buttons(GTK_DIALOG(dialog), _("Cancel"), GTK_RESPONSE_CANCEL, - _(button_strings[type]), GTK_RESPONSE_OK, + button_text, GTK_RESPONSE_OK, NULL); return dialog; -- cgit v1.2.3 From 3928d091aaa4beacbf86dfc51b5ccc04c9ee4b36 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Mar 2010 16:55:50 -0600 Subject: Checking to see if we need updates and allowing that on logout dialogs. --- src/dialog.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'src/dialog.c') diff --git a/src/dialog.c b/src/dialog.c index dd681b3..f30eb17 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -35,11 +35,9 @@ static const gchar * button_auth_strings[LOGOUT_DIALOG_TYPE_CNT] = { /* LOGOUT_DIALOG_SHUTDOWN, */ NC_("button auth", "Switch Off...") }; -/* static const gchar * restart_updates = N_("Restart Instead"); static const gchar * restart_auth = N_("Restart..."); 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] = { /* LOGOUT_DIALOG_LOGOUT, */ "system-log-out", @@ -107,8 +105,7 @@ logout_dialog_finalize (GObject *object) static gboolean check_restart_required (void) { - - return FALSE; + return g_file_test("/var/run/reboot-required", G_FILE_TEST_EXISTS); } /* Checks with console kit to see if we can do what we want */ @@ -180,10 +177,27 @@ logout_dialog_new (LogoutDialogType type) button_text = _(button_auth_strings[type]); } - gtk_dialog_add_buttons(GTK_DIALOG(dialog), - _("Cancel"), GTK_RESPONSE_CANCEL, - button_text, GTK_RESPONSE_OK, - NULL); + 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); + } return dialog; } -- cgit v1.2.3 From 8d96a4fc56e194b1c4e8b1370d1a35703b92a3fe Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Mar 2010 16:57:37 -0600 Subject: String fixes and a comment. --- src/dialog.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/dialog.c') diff --git a/src/dialog.c b/src/dialog.c index f30eb17..b63ecef 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -35,8 +35,11 @@ static const gchar * button_auth_strings[LOGOUT_DIALOG_TYPE_CNT] = { /* LOGOUT_DIALOG_SHUTDOWN, */ NC_("button auth", "Switch Off...") }; +/* TRANSLATORS: This button appears on the logout dialog when + there are updates that require restart. It will do a restart + in place of a log out. */ static const gchar * restart_updates = N_("Restart Instead"); -static const gchar * restart_auth = N_("Restart..."); +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] = { -- cgit v1.2.3 From 10e1e69dae2be7388dca78a253173e3e5e9e3641 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Mar 2010 17:00:45 -0600 Subject: Setting the default button. --- src/dialog.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/dialog.c') diff --git a/src/dialog.c b/src/dialog.c index b63ecef..fcc3334 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -202,5 +202,7 @@ logout_dialog_new (LogoutDialogType type) NULL); } + gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); + return dialog; } -- cgit v1.2.3 From edeb525d966748a31e0abd7526c84c59f5c0e365 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Mar 2010 20:36:18 -0600 Subject: Slightly longer string for better wrapping. --- src/dialog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/dialog.c') diff --git a/src/dialog.c b/src/dialog.c index fcc3334..3e3799d 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -16,7 +16,7 @@ static const gchar * title_strings[LOGOUT_DIALOG_TYPE_CNT] = { }; static const gchar * body_strings[LOGOUT_DIALOG_TYPE_CNT] = { - /* LOGOUT_DIALOG_LOGOUT, */ N_("Are you sure you want to close all programs and log out?"), + /* LOGOUT_DIALOG_LOGOUT, */ N_("Are you sure you want to close all programs and log out of the computer?"), /* LOGOUT_DIALOG_RESTART, */ N_("Are you sure you want to close all programs and restart the computer?"), /* LOGOUT_DIALOG_SHUTDOWN, */ N_("Are you sure you want to close all programs and shut down the computer?") }; -- cgit v1.2.3 From 25e5df53f5584fa04ff0f9949f619f9031acc4a1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Mar 2010 20:37:47 -0600 Subject: Copyright headers --- src/dialog.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/dialog.c') diff --git a/src/dialog.c b/src/dialog.c index 3e3799d..deefe0b 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -1,3 +1,25 @@ +/* +A dialog to ask the user about the various logout options that +are available. + +Copyright 2010 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + #ifdef HAVE_CONFIG_H #include "config.h" #endif -- cgit v1.2.3