From 74da0353e9344e80e01464c74a75d0ce0a4ca0dd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 23 Jul 2009 00:18:28 -0500 Subject: Basic command line parsing. Not working 100% yet. --- src/gtk-dialog/gtk-logout-helper.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/gtk-dialog/gtk-logout-helper.c') diff --git a/src/gtk-dialog/gtk-logout-helper.c b/src/gtk-dialog/gtk-logout-helper.c index f6598bc..1564404 100644 --- a/src/gtk-dialog/gtk-logout-helper.c +++ b/src/gtk-dialog/gtk-logout-helper.c @@ -1,12 +1,42 @@ +#include #include #include "logout-dialog.h" +static LogoutDialogAction type = LOGOUT_DIALOG_LOGOUT; + +static gboolean +option_cb (const gchar * arg, const gchar * value, gpointer data, GError * error) +{ + type = GPOINTER_TO_INT(data); + return TRUE; +} + +static GOptionEntry options[] = { + {"logout", 'l', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_cb, "Log out of the current session", GINT_TO_POINTER(LOGOUT_DIALOG_LOGOUT)}, + {"shutdown", 's', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_cb, "Shutdown the entire system", GINT_TO_POINTER(LOGOUT_DIALOG_RESTART)}, + {"restart", 'r', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_cb, "Restart the system", GINT_TO_POINTER(LOGOUT_DIALOG_SHUTDOWN)}, + + {NULL} +}; + int main (int argc, char * argv[]) { gtk_init(&argc, &argv); + GError * error = NULL; + GOptionContext * context = g_option_context_new(" - logout of the current session"); + g_option_context_add_main_entries(context, options, "gtk-logout-helper"); + g_option_context_add_group(context, gtk_get_option_group(TRUE)); + g_option_context_set_help_enabled(context, TRUE); + + if (!g_option_context_parse(context, &argc, &argv, &error)) { + g_debug("Option parsing failed: %s", error->message); + g_error_free(error); + return 1; + } + GtkWidget * dialog = logout_dialog_new(LOGOUT_DIALOG_LOGOUT); gtk_dialog_run(GTK_DIALOG(dialog)); -- cgit v1.2.3 From bf936e17c6ac25344055de4eab06afc8b3893cb2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 23 Jul 2009 10:19:20 -0500 Subject: Getting all the parameters working so that we can set the dialog type --- src/gtk-dialog/gtk-logout-helper.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/gtk-dialog/gtk-logout-helper.c') diff --git a/src/gtk-dialog/gtk-logout-helper.c b/src/gtk-dialog/gtk-logout-helper.c index 1564404..505ea16 100644 --- a/src/gtk-dialog/gtk-logout-helper.c +++ b/src/gtk-dialog/gtk-logout-helper.c @@ -6,16 +6,30 @@ static LogoutDialogAction type = LOGOUT_DIALOG_LOGOUT; static gboolean -option_cb (const gchar * arg, const gchar * value, gpointer data, GError * error) +option_logout (const gchar * arg, const gchar * value, gpointer data, GError * error) { - type = GPOINTER_TO_INT(data); + type = LOGOUT_DIALOG_LOGOUT; + return TRUE; +} + +static gboolean +option_shutdown (const gchar * arg, const gchar * value, gpointer data, GError * error) +{ + type = LOGOUT_DIALOG_SHUTDOWN; + return TRUE; +} + +static gboolean +option_restart (const gchar * arg, const gchar * value, gpointer data, GError * error) +{ + type = LOGOUT_DIALOG_RESTART; return TRUE; } static GOptionEntry options[] = { - {"logout", 'l', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_cb, "Log out of the current session", GINT_TO_POINTER(LOGOUT_DIALOG_LOGOUT)}, - {"shutdown", 's', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_cb, "Shutdown the entire system", GINT_TO_POINTER(LOGOUT_DIALOG_RESTART)}, - {"restart", 'r', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_cb, "Restart the system", GINT_TO_POINTER(LOGOUT_DIALOG_SHUTDOWN)}, + {"logout", 'l', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_logout, "Log out of the current session", NULL}, + {"shutdown", 's', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_shutdown, "Shutdown the entire system", NULL}, + {"restart", 'r', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_restart, "Restart the system", NULL}, {NULL} }; @@ -37,7 +51,7 @@ main (int argc, char * argv[]) return 1; } - GtkWidget * dialog = logout_dialog_new(LOGOUT_DIALOG_LOGOUT); + GtkWidget * dialog = logout_dialog_new(type); gtk_dialog_run(GTK_DIALOG(dialog)); return 0; -- cgit v1.2.3 From 624c4acbd0c256f5cf8e7067e8dab935bf6c2b5f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 23 Jul 2009 15:46:07 -0500 Subject: Now check for the PK dialog and otherwise run ours. If we get restart, restart --- src/gtk-dialog/gtk-logout-helper.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/gtk-dialog/gtk-logout-helper.c') diff --git a/src/gtk-dialog/gtk-logout-helper.c b/src/gtk-dialog/gtk-logout-helper.c index 505ea16..c7f67a5 100644 --- a/src/gtk-dialog/gtk-logout-helper.c +++ b/src/gtk-dialog/gtk-logout-helper.c @@ -2,6 +2,7 @@ #include #include #include "logout-dialog.h" +#include "ck-pk-helper.h" static LogoutDialogAction type = LOGOUT_DIALOG_LOGOUT; @@ -51,8 +52,24 @@ main (int argc, char * argv[]) return 1; } - GtkWidget * dialog = logout_dialog_new(type); - gtk_dialog_run(GTK_DIALOG(dialog)); + GtkWidget * dialog = NULL; + if (!pk_require_auth(type)) { + dialog = logout_dialog_new(type); + } + + if (dialog != NULL) { + GtkResponseType response = gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_hide(dialog); + + if (response == GTK_RESPONSE_HELP) { + type = LOGOUT_DIALOG_RESTART; + response = GTK_RESPONSE_OK; + } + + if (response != GTK_RESPONSE_OK) { + return 0; + } + } return 0; } -- cgit v1.2.3 From 04c5db216a561b9232df1e7626a852ff8df9cbf1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 23 Jul 2009 15:56:04 -0500 Subject: Adding in the action code from our previous patches to FUSA --- src/gtk-dialog/gtk-logout-helper.c | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'src/gtk-dialog/gtk-logout-helper.c') diff --git a/src/gtk-dialog/gtk-logout-helper.c b/src/gtk-dialog/gtk-logout-helper.c index c7f67a5..75ab63f 100644 --- a/src/gtk-dialog/gtk-logout-helper.c +++ b/src/gtk-dialog/gtk-logout-helper.c @@ -1,9 +1,66 @@ #include #include +#include #include "logout-dialog.h" #include "ck-pk-helper.h" +static void +session_action (LogoutDialogAction action) +{ + DBusGConnection * sbus; + DBusGProxy * sm_proxy; + GError * error = NULL; + gboolean res = FALSE; + + sbus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); + if (sbus == NULL) { + g_warning("Unable to get DBus session bus."); + return; + } + sm_proxy = dbus_g_proxy_new_for_name_owner (sbus, + "org.gnome.SessionManager", + "/org/gnome/SessionManager", + "org.gnome.SessionManager", + &error); + if (sm_proxy == NULL) { + g_warning("Unable to get DBus proxy to SessionManager interface: %s", error->message); + g_error_free(error); + return; + } + + g_clear_error (&error); + + if (action == LOGOUT_DIALOG_LOGOUT) { + res = dbus_g_proxy_call_with_timeout (sm_proxy, "Logout", INT_MAX, &error, + G_TYPE_UINT, 1, G_TYPE_INVALID, G_TYPE_INVALID); + } else if (action == LOGOUT_DIALOG_SHUTDOWN) { + res = dbus_g_proxy_call_with_timeout (sm_proxy, "RequestShutdown", INT_MAX, &error, + G_TYPE_INVALID, G_TYPE_INVALID); + } else if (action == LOGOUT_DIALOG_RESTART) { + res = dbus_g_proxy_call_with_timeout (sm_proxy, "RequestReboot", INT_MAX, &error, + G_TYPE_INVALID, G_TYPE_INVALID); + } else { + g_warning ("Unknown session action"); + } + + if (!res) { + if (error != NULL) { + g_warning ("SessionManager action failed: %s", error->message); + } else { + g_warning ("SessionManager action failed: unknown error"); + } + } + + g_object_unref(sm_proxy); + + if (error != NULL) { + g_error_free(error); + } + + return; +} + static LogoutDialogAction type = LOGOUT_DIALOG_LOGOUT; static gboolean @@ -71,5 +128,7 @@ main (int argc, char * argv[]) } } + session_action(type); + return 0; } -- cgit v1.2.3