2
A dialog to ask the user about the various logout options that
5
Copyright 2010 Canonical Ltd.
8
Ted Gould <ted@canonical.com>
10
This program is free software: you can redistribute it and/or modify it
11
under the terms of the GNU General Public License version 3, as published
12
by the Free Software Foundation.
14
This program is distributed in the hope that it will be useful, but
15
WITHOUT ANY WARRANTY; without even the implied warranties of
16
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
17
PURPOSE. See the GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License along
20
with this program. If not, see <http://www.gnu.org/licenses/>.
27
#include <glib/gi18n.h>
29
#include "dbus-consolekit-manager.h"
34
static const gchar * title_strings[LOGOUT_DIALOG_TYPE_CNT] = {
35
/* LOGOUT_DIALOG_LOGOUT, */ NC_("title", "Log Out"),
36
/* LOGOUT_DIALOG_RESTART, */ NC_("title", "Restart"),
37
/* LOGOUT_DIALOG_SHUTDOWN, */ NC_("title", "Shut Down")
40
static const gchar * body_strings[LOGOUT_DIALOG_TYPE_CNT] = {
41
/* LOGOUT_DIALOG_LOGOUT, */ N_("Are you sure you want to close all programs and log out of the computer?"),
42
/* LOGOUT_DIALOG_RESTART, */ N_("Are you sure you want to close all programs and restart the computer?"),
43
/* LOGOUT_DIALOG_SHUTDOWN, */ N_("Are you sure you want to close all programs and shut down the computer?")
46
static const gchar * button_strings[LOGOUT_DIALOG_TYPE_CNT] = {
47
/* LOGOUT_DIALOG_LOGOUT, */ NC_("button", "Log Out"),
48
/* LOGOUT_DIALOG_RESTART, */ NC_("button", "Restart"),
49
/* LOGOUT_DIALOG_SHUTDOWN, */ NC_("button", "Shut Down")
52
/* TRANSLATORS: These strings have an ellipsis so that the user knows
53
they are also going to get a password dialog to do the action. */
54
static const gchar * button_auth_strings[LOGOUT_DIALOG_TYPE_CNT] = {
55
/* LOGOUT_DIALOG_LOGOUT, */ NC_("button auth", "Log Out"),
56
/* LOGOUT_DIALOG_RESTART, */ NC_("button auth", "Restart…"),
57
/* LOGOUT_DIALOG_SHUTDOWN, */ NC_("button auth", "Shut Down…")
60
/* TRANSLATORS: This button appears on the logout dialog when
61
there are updates that require restart. It will do a restart
62
in place of a log out. */
63
static const gchar * restart_updates = N_("Restart Instead");
64
static const gchar * restart_auth = N_("Restart Instead…");
65
static const gchar * body_logout_update = N_("Some software updates won’t apply until the computer next restarts.");
67
static const gchar * icon_strings[LOGOUT_DIALOG_TYPE_CNT] = {
68
/* LOGOUT_DIALOG_LOGOUT, */ "system-log-out",
69
/* LOGOUT_DIALOG_RESTART, */ "system-restart",
70
/* LOGOUT_DIALOG_SHUTDOWN, */ "system-shutdown"
75
typedef struct _LogoutDialogPrivate LogoutDialogPrivate;
76
struct _LogoutDialogPrivate {
80
#define LOGOUT_DIALOG_GET_PRIVATE(o) \
81
(G_TYPE_INSTANCE_GET_PRIVATE ((o), LOGOUT_DIALOG_TYPE, LogoutDialogPrivate))
83
static void logout_dialog_class_init (LogoutDialogClass *klass);
84
static void logout_dialog_init (LogoutDialog *self);
85
static void logout_dialog_dispose (GObject *object);
86
static void logout_dialog_finalize (GObject *object);
88
G_DEFINE_TYPE (LogoutDialog, logout_dialog, GTK_TYPE_MESSAGE_DIALOG);
91
logout_dialog_class_init (LogoutDialogClass *klass)
93
GObjectClass *object_class = G_OBJECT_CLASS (klass);
95
g_type_class_add_private (klass, sizeof (LogoutDialogPrivate));
97
object_class->dispose = logout_dialog_dispose;
98
object_class->finalize = logout_dialog_finalize;
104
logout_dialog_init (LogoutDialog *self)
111
logout_dialog_dispose (GObject *object)
115
G_OBJECT_CLASS (logout_dialog_parent_class)->dispose (object);
120
logout_dialog_finalize (GObject *object)
124
G_OBJECT_CLASS (logout_dialog_parent_class)->finalize (object);
128
/* Checks for updates that would signal that a restart is
129
required for them to apply */
131
check_restart_required (void)
133
return g_file_test("/var/run/reboot-required", G_FILE_TEST_EXISTS);
136
/* Checks with console kit to see if we can do what we want */
138
ck_check_allowed (LogoutDialogType type)
140
gboolean allowed = TRUE;
142
ConsoleKitManager * ck_proxy = console_kit_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
143
G_DBUS_PROXY_FLAGS_NONE,
144
"org.freedesktop.ConsoleKit",
145
"/org/freedesktop/ConsoleKit/Manager",
148
if (ck_proxy != NULL)
151
case LOGOUT_DIALOG_TYPE_RESTART:
152
console_kit_manager_call_can_restart_sync (ck_proxy, &allowed, NULL, NULL);
154
case LOGOUT_DIALOG_TYPE_SHUTDOWN:
155
console_kit_manager_call_can_stop_sync (ck_proxy, &allowed, NULL, NULL);
161
g_object_unref(ck_proxy);
168
logout_dialog_new (LogoutDialogType type)
170
GtkWidget * image = gtk_image_new_from_icon_name(icon_strings[type], GTK_ICON_SIZE_DIALOG);
171
gtk_widget_show(image);
173
LogoutDialog * dialog = LOGOUT_DIALOG(g_object_new(LOGOUT_DIALOG_TYPE,
175
"icon-name", icon_strings[type],
178
"title", g_dpgettext2 (NULL, "title", title_strings[type]),
179
"window-position", GTK_WIN_POS_CENTER_ALWAYS,
181
"buttons", GTK_BUTTONS_NONE,
183
"message-type", GTK_MESSAGE_OTHER,
184
"text", _(body_strings[type]),
187
gtk_window_set_keep_above(GTK_WINDOW(dialog), TRUE);
189
gboolean allowed = FALSE;
190
if (type == LOGOUT_DIALOG_TYPE_LOG_OUT) {
191
allowed = ck_check_allowed(LOGOUT_DIALOG_TYPE_RESTART);
193
allowed = ck_check_allowed(type);
196
gboolean restart_required = FALSE;
197
if (type == LOGOUT_DIALOG_TYPE_LOG_OUT) {
198
restart_required = check_restart_required();
201
const gchar * button_text;
203
button_text = g_dpgettext2 (NULL, "button", button_strings[type]);
205
button_text = g_dpgettext2 (NULL, "button auth", button_auth_strings[type]);
208
if (restart_required) {
209
const gchar * restart_req;
211
restart_req = restart_updates;
213
restart_req = restart_auth;
216
g_object_set(dialog, "secondary-text", _(body_logout_update), NULL);
218
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
219
_(restart_req), GTK_RESPONSE_HELP,
220
_("Cancel"), GTK_RESPONSE_CANCEL,
221
button_text, GTK_RESPONSE_OK,
224
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
225
_("Cancel"), GTK_RESPONSE_CANCEL,
226
button_text, GTK_RESPONSE_OK,
230
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
232
/* The following is a workaround to fix an issue in GtkMessageDialog
233
in which the user can tab through the text in addition to
235
GtkWidget *message_area = gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(dialog));
236
GList *children = gtk_container_get_children(GTK_CONTAINER(message_area));
239
for (l = children; l != NULL; l = g_list_next (l))
241
GtkWidget *child = l->data;
242
gtk_widget_set_can_focus(child, FALSE);
245
g_list_free (children);