4
#include <dbus/dbus-glib.h>
5
#include "logout-dialog.h"
6
#include "ck-pk-helper.h"
9
session_action (LogoutDialogAction action)
11
DBusGConnection * sbus;
12
DBusGProxy * sm_proxy;
13
GError * error = NULL;
16
sbus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
18
g_warning("Unable to get DBus session bus.");
21
sm_proxy = dbus_g_proxy_new_for_name_owner (sbus,
22
"org.gnome.SessionManager",
23
"/org/gnome/SessionManager",
24
"org.gnome.SessionManager",
26
if (sm_proxy == NULL) {
27
g_warning("Unable to get DBus proxy to SessionManager interface: %s", error->message);
32
g_clear_error (&error);
34
if (action == LOGOUT_DIALOG_LOGOUT) {
35
res = dbus_g_proxy_call_with_timeout (sm_proxy, "Logout", INT_MAX, &error,
36
G_TYPE_UINT, 1, G_TYPE_INVALID, G_TYPE_INVALID);
37
} else if (action == LOGOUT_DIALOG_SHUTDOWN) {
38
res = dbus_g_proxy_call_with_timeout (sm_proxy, "RequestShutdown", INT_MAX, &error,
39
G_TYPE_INVALID, G_TYPE_INVALID);
40
} else if (action == LOGOUT_DIALOG_RESTART) {
41
res = dbus_g_proxy_call_with_timeout (sm_proxy, "RequestReboot", INT_MAX, &error,
42
G_TYPE_INVALID, G_TYPE_INVALID);
44
g_warning ("Unknown session action");
49
g_warning ("SessionManager action failed: %s", error->message);
51
g_warning ("SessionManager action failed: unknown error");
55
g_object_unref(sm_proxy);
64
static LogoutDialogAction type = LOGOUT_DIALOG_LOGOUT;
67
option_logout (const gchar * arg, const gchar * value, gpointer data, GError * error)
69
type = LOGOUT_DIALOG_LOGOUT;
74
option_shutdown (const gchar * arg, const gchar * value, gpointer data, GError * error)
76
type = LOGOUT_DIALOG_SHUTDOWN;
81
option_restart (const gchar * arg, const gchar * value, gpointer data, GError * error)
83
type = LOGOUT_DIALOG_RESTART;
87
static GOptionEntry options[] = {
88
{"logout", 'l', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_logout, "Log out of the current session", NULL},
89
{"shutdown", 's', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_shutdown, "Shutdown the entire system", NULL},
90
{"restart", 'r', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_restart, "Restart the system", NULL},
96
main (int argc, char * argv[])
98
gtk_init(&argc, &argv);
100
GError * error = NULL;
101
GOptionContext * context = g_option_context_new(" - logout of the current session");
102
g_option_context_add_main_entries(context, options, "gtk-logout-helper");
103
g_option_context_add_group(context, gtk_get_option_group(TRUE));
104
g_option_context_set_help_enabled(context, TRUE);
106
if (!g_option_context_parse(context, &argc, &argv, &error)) {
107
g_debug("Option parsing failed: %s", error->message);
112
GtkWidget * dialog = NULL;
113
if (!pk_require_auth(type)) {
114
dialog = logout_dialog_new(type);
117
if (dialog != NULL) {
118
GtkResponseType response = gtk_dialog_run(GTK_DIALOG(dialog));
119
gtk_widget_hide(dialog);
121
if (response == GTK_RESPONSE_HELP) {
122
type = LOGOUT_DIALOG_RESTART;
123
response = GTK_RESPONSE_OK;
126
if (response != GTK_RESPONSE_OK) {
131
session_action(type);