2
A small wrapper utility to load indicators and put them as menu items
3
into the gnome-panel using it's applet interface.
5
Copyright 2009 Canonical Ltd.
8
Ted Gould <ted@canonical.com>
9
Christoph Korn <c_korn@gmx.de>
11
This program is free software: you can redistribute it and/or modify it
12
under the terms of the GNU General Public License version 3, as published
13
by the Free Software Foundation.
15
This program is distributed in the hope that it will be useful, but
16
WITHOUT ANY WARRANTY; without even the implied warranties of
17
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
18
PURPOSE. See the GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License along
21
with this program. If not, see <http://www.gnu.org/licenses/>.
28
#include <glib/gi18n.h> /* textdomain(), bindtextdomain() */
31
#include "shared-names.h"
34
call_logind (const gchar *method, GVariant *parameters, GError **error)
36
GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error);
39
g_variant_unref (parameters);
43
GVariant *result = g_dbus_connection_call_sync(bus,
44
"org.freedesktop.login1",
45
"/org/freedesktop/login1",
46
"org.freedesktop.login1.Manager",
50
G_DBUS_CALL_FLAGS_NONE,
60
logind_fallback (LogoutDialogType action)
62
GError * error = NULL;
63
GVariant *result = NULL;
65
g_debug("Falling back to using logind for action");
68
case LOGOUT_DIALOG_TYPE_LOG_OUT:
69
g_warning("Unable to fallback to logind for logout as it's a session issue. We need some sort of session handler.");
71
case LOGOUT_DIALOG_TYPE_SHUTDOWN:
72
g_debug("Telling logind to 'PowerOff'");
73
result = call_logind ("PowerOff", g_variant_new ("(b)", FALSE), &error);
75
case LOGOUT_DIALOG_TYPE_RESTART:
76
g_debug("Telling logind to 'Reboot'");
77
result = call_logind ("Reboot", g_variant_new ("(b)", FALSE), &error);
80
g_warning("Unknown action");
86
g_warning ("logind action failed: %s", error->message);
88
g_warning ("logind action failed: unknown error");
92
g_variant_unref (result);
93
g_clear_error (&error);
99
call_gnome_session (const gchar *method, GVariant *parameters, GError **error)
101
GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, error);
104
g_variant_unref (parameters);
108
GVariant *result = g_dbus_connection_call_sync(bus,
109
"org.gnome.SessionManager",
110
"/org/gnome/SessionManager",
111
"org.gnome.SessionManager",
115
G_DBUS_CALL_FLAGS_NONE,
119
g_object_unref (bus);
125
session_action (LogoutDialogType action)
127
GError * error = NULL;
128
GVariant *result = NULL;
130
if (action == LOGOUT_DIALOG_TYPE_LOG_OUT) {
131
g_debug("Asking Session manager to 'Logout'");
132
result = call_gnome_session ("Logout", g_variant_new ("(u)", 1), &error);
133
} else if (action == LOGOUT_DIALOG_TYPE_SHUTDOWN) {
134
g_debug("Asking Session manager to 'RequestShutdown'");
135
result = call_gnome_session ("RequestShutdown", g_variant_new ("()"), &error);
136
} else if (action == LOGOUT_DIALOG_TYPE_RESTART) {
137
g_debug("Asking Session manager to 'RequestReboot'");
138
result = call_gnome_session ("RequestReboot", g_variant_new ("()"), &error);
140
g_warning ("Unknown session action");
145
g_warning ("SessionManager action failed: %s", error->message);
147
g_warning ("SessionManager action failed: unknown error");
150
logind_fallback(action);
153
g_variant_unref (result);
154
g_clear_error (&error);
159
static LogoutDialogType type = LOGOUT_DIALOG_TYPE_LOG_OUT;
162
option_logout (const gchar * arg, const gchar * value, gpointer data, GError * error)
164
type = LOGOUT_DIALOG_TYPE_LOG_OUT;
165
g_debug("Dialog type: logout");
170
option_shutdown (const gchar * arg, const gchar * value, gpointer data, GError * error)
172
type = LOGOUT_DIALOG_TYPE_SHUTDOWN;
173
g_debug("Dialog type: shutdown");
178
option_restart (const gchar * arg, const gchar * value, gpointer data, GError * error)
180
type = LOGOUT_DIALOG_TYPE_RESTART;
181
g_debug("Dialog type: restart");
185
static GOptionEntry options[] = {
186
{"logout", 'l', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_logout, "Log out of the current session", NULL},
187
{"shutdown", 's', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_shutdown, "Switch off the entire system", NULL},
188
{"restart", 'r', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_restart, "Restart the system", NULL},
194
suppress_confirmations (void)
196
GSettings * s = g_settings_new (SESSION_SCHEMA);
197
const gboolean suppress = g_settings_get_boolean (s, SUPPRESS_KEY);
205
main (int argc, char * argv[])
207
gtk_init(&argc, &argv);
209
/* Setting up i18n and gettext. Apparently, we need
211
setlocale (LC_ALL, "");
212
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
213
textdomain (GETTEXT_PACKAGE);
215
GError * error = NULL;
216
GOptionContext * context = g_option_context_new(" - logout of the current session");
217
g_option_context_add_main_entries(context, options, "gtk-logout-helper");
218
g_option_context_add_group(context, gtk_get_option_group(TRUE));
219
g_option_context_set_help_enabled(context, TRUE);
221
if (!g_option_context_parse(context, &argc, &argv, &error)) {
222
g_debug("Option parsing failed: %s", error->message);
227
/* Init some theme/icon stuff */
228
gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(),
229
INDICATOR_ICONS_DIR);
231
GtkWidget * dialog = NULL;
232
if (!suppress_confirmations()) {
233
g_debug("Showing dialog to ask for user confirmation");
234
dialog = GTK_WIDGET(logout_dialog_new(type));
237
if (dialog != NULL) {
238
GtkResponseType response = gtk_dialog_run(GTK_DIALOG(dialog));
239
gtk_widget_hide(dialog);
241
if (response == GTK_RESPONSE_OK) {
242
g_debug("Dialog return response: 'okay'");
243
} else if (response == GTK_RESPONSE_HELP) {
244
g_debug("Dialog return response: 'help'");
246
g_debug("Dialog return response: %d", response);
249
if (response == GTK_RESPONSE_HELP) {
250
type = LOGOUT_DIALOG_TYPE_RESTART;
251
response = GTK_RESPONSE_OK;
254
if (response != GTK_RESPONSE_OK) {
255
g_debug("Final response was not okay, quiting");
260
session_action(type);
261
g_debug("Finished action, quiting");