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 <dbus/dbus-glib.h>
30
#include "settings-helper.h"
33
consolekit_fallback (LogoutDialogType action)
35
g_debug("Falling back to using ConsoleKit for action");
37
DBusGConnection * sbus = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
38
g_return_if_fail(sbus != NULL); /* worst case */
39
DBusGProxy * proxy = dbus_g_proxy_new_for_name(sbus, "org.freedesktop.ConsoleKit",
40
"/org/freedesktop/ConsoleKit/Manager",
41
"org.freedesktop.ConsoleKit.Manager");
44
g_warning("Unable to get consolekit proxy");
48
GError * error = NULL;
51
case LOGOUT_DIALOG_TYPE_LOG_OUT:
52
g_warning("Unable to fallback to ConsoleKit for logout as it's a session issue. We need some sort of session handler.");
54
case LOGOUT_DIALOG_TYPE_SHUTDOWN:
55
g_debug("Telling ConsoleKit to 'Stop'");
56
dbus_g_proxy_call(proxy,
62
case LOGOUT_DIALOG_TYPE_RESTART:
63
g_debug("Telling ConsoleKit to 'Restart'");
64
dbus_g_proxy_call(proxy,
71
g_warning("Unknown action");
75
g_object_unref(proxy);
78
g_warning("Unable to signal ConsoleKit");
86
session_action (LogoutDialogType action)
88
DBusGConnection * sbus;
89
DBusGProxy * sm_proxy;
90
GError * error = NULL;
93
sbus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
95
g_warning("Unable to get DBus session bus.");
98
sm_proxy = dbus_g_proxy_new_for_name_owner (sbus,
99
"org.gnome.SessionManager",
100
"/org/gnome/SessionManager",
101
"org.gnome.SessionManager",
103
if (sm_proxy == NULL) {
104
g_warning("Unable to get DBus proxy to SessionManager interface: %s", error->message);
107
consolekit_fallback(action);
111
g_clear_error (&error);
113
if (action == LOGOUT_DIALOG_TYPE_LOG_OUT) {
114
g_debug("Asking Session manager to 'Logout'");
115
res = dbus_g_proxy_call_with_timeout (sm_proxy, "Logout", INT_MAX, &error,
116
G_TYPE_UINT, 1, G_TYPE_INVALID, G_TYPE_INVALID);
117
} else if (action == LOGOUT_DIALOG_TYPE_SHUTDOWN) {
118
g_debug("Asking Session manager to 'RequestShutdown'");
119
res = dbus_g_proxy_call_with_timeout (sm_proxy, "RequestShutdown", INT_MAX, &error,
120
G_TYPE_INVALID, G_TYPE_INVALID);
121
} else if (action == LOGOUT_DIALOG_TYPE_RESTART) {
122
g_debug("Asking Session manager to 'RequestReboot'");
123
res = dbus_g_proxy_call_with_timeout (sm_proxy, "RequestReboot", INT_MAX, &error,
124
G_TYPE_INVALID, G_TYPE_INVALID);
126
g_warning ("Unknown session action");
131
g_warning ("SessionManager action failed: %s", error->message);
133
g_warning ("SessionManager action failed: unknown error");
136
consolekit_fallback(action);
139
g_object_unref(sm_proxy);
148
static LogoutDialogType type = LOGOUT_DIALOG_TYPE_LOG_OUT;
151
option_logout (const gchar * arg, const gchar * value, gpointer data, GError * error)
153
type = LOGOUT_DIALOG_TYPE_LOG_OUT;
154
g_debug("Dialog type: logout");
159
option_shutdown (const gchar * arg, const gchar * value, gpointer data, GError * error)
161
type = LOGOUT_DIALOG_TYPE_SHUTDOWN;
162
g_debug("Dialog type: shutdown");
167
option_restart (const gchar * arg, const gchar * value, gpointer data, GError * error)
169
type = LOGOUT_DIALOG_TYPE_RESTART;
170
g_debug("Dialog type: restart");
174
static GOptionEntry options[] = {
175
{"logout", 'l', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_logout, "Log out of the current session", NULL},
176
{"shutdown", 's', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_shutdown, "Switch off the entire system", NULL},
177
{"restart", 'r', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_restart, "Restart the system", NULL},
183
main (int argc, char * argv[])
185
gtk_init(&argc, &argv);
187
/* Setting up i18n and gettext. Apparently, we need
189
setlocale (LC_ALL, "");
190
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
191
textdomain (GETTEXT_PACKAGE);
193
GError * error = NULL;
194
GOptionContext * context = g_option_context_new(" - logout of the current session");
195
g_option_context_add_main_entries(context, options, "gtk-logout-helper");
196
g_option_context_add_group(context, gtk_get_option_group(TRUE));
197
g_option_context_set_help_enabled(context, TRUE);
199
if (!g_option_context_parse(context, &argc, &argv, &error)) {
200
g_debug("Option parsing failed: %s", error->message);
205
/* Init some theme/icon stuff */
206
gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(),
207
INDICATOR_ICONS_DIR);
209
GtkWidget * dialog = NULL;
210
if (!supress_confirmations()) {
211
g_debug("Showing dialog to ask for user confirmation");
212
dialog = GTK_WIDGET(logout_dialog_new(type));
215
if (dialog != NULL) {
216
GtkResponseType response = gtk_dialog_run(GTK_DIALOG(dialog));
217
gtk_widget_hide(dialog);
219
if (response == GTK_RESPONSE_OK) {
220
g_debug("Dialog return response: 'okay'");
221
} else if (response == GTK_RESPONSE_HELP) {
222
g_debug("Dialog return response: 'help'");
224
g_debug("Dialog return response: %d", response);
227
if (response == GTK_RESPONSE_HELP) {
228
type = LOGOUT_DIALOG_TYPE_RESTART;
229
response = GTK_RESPONSE_OK;
232
if (response != GTK_RESPONSE_OK) {
233
g_debug("Final response was not okay, quiting");
238
session_action(type);
239
g_debug("Finished action, quiting");