diff options
author | William Jon McCann <jmccann@redhat.com> | 2008-08-08 22:26:32 +0000 |
---|---|---|
committer | William Jon McCann <mccann@src.gnome.org> | 2008-08-08 22:26:32 +0000 |
commit | 7b3abd5f955b81a2aa9ebaef4a8bc82c09ad18c2 (patch) | |
tree | 91401d2454d4a3de7b698abef2890a352b4dd4aa | |
parent | 252772f17385c6d1c4f5e2525ead9bd729de44fc (diff) | |
download | gnome-session-7b3abd5f955b81a2aa9ebaef4a8bc82c09ad18c2.tar.gz |
Melt the gnome-session-save tool and make it actually work. Fix the api
2008-08-08 William Jon McCann <jmccann@redhat.com>
* gnome-session/gsm-manager.c (gsm_manager_error_get_type),
(gsm_manager_logout):
* gnome-session/gsm-manager.h:
* gnome-session/org.gnome.SessionManager.xml:
* tools/gnome-session-save.c (display_error), (get_sm_proxy),
(set_session_name), (logout_session), (main):
Melt the gnome-session-save tool and make it actually work.
Fix the api for Logout to take a uint.
svn path=/trunk/; revision=4928
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | gnome-session/gsm-manager.c | 11 | ||||
-rw-r--r-- | gnome-session/gsm-manager.h | 3 | ||||
-rw-r--r-- | gnome-session/org.gnome.SessionManager.xml | 2 | ||||
-rw-r--r-- | tools/gnome-session-save.c | 214 |
5 files changed, 105 insertions, 136 deletions
@@ -1,3 +1,14 @@ +2008-08-08 William Jon McCann <jmccann@redhat.com> + + * gnome-session/gsm-manager.c (gsm_manager_error_get_type), + (gsm_manager_logout): + * gnome-session/gsm-manager.h: + * gnome-session/org.gnome.SessionManager.xml: + * tools/gnome-session-save.c (display_error), (get_sm_proxy), + (set_session_name), (logout_session), (main): + Melt the gnome-session-save tool and make it actually work. + Fix the api for Logout to take a uint. + 2008-08-08 Jonh Wendell <jwendell@gnome.org> * gnome-session/gsm-autostart-app.c (is_disabled): Dropped the diff --git a/gnome-session/gsm-manager.c b/gnome-session/gsm-manager.c index 7efec0ee..b0964eb2 100644 --- a/gnome-session/gsm-manager.c +++ b/gnome-session/gsm-manager.c @@ -152,6 +152,7 @@ gsm_manager_error_get_type (void) ENUM_ENTRY (GSM_MANAGER_ERROR_NOT_IN_RUNNING, "NotInRunning"), ENUM_ENTRY (GSM_MANAGER_ERROR_ALREADY_REGISTERED, "AlreadyRegistered"), ENUM_ENTRY (GSM_MANAGER_ERROR_NOT_REGISTERED, "NotRegistered"), + ENUM_ENTRY (GSM_MANAGER_ERROR_INVALID_OPTION, "InvalidOption"), { 0, 0, 0 } }; @@ -2453,7 +2454,7 @@ gsm_manager_shutdown (GsmManager *manager, gboolean gsm_manager_logout (GsmManager *manager, - gint logout_mode, + guint logout_mode, GError **error) { g_debug ("GsmManager: Logout called"); @@ -2482,7 +2483,13 @@ gsm_manager_logout (GsmManager *manager, break; default: - g_assert_not_reached (); + g_debug ("Unknown logout mode option"); + + g_set_error (error, + GSM_MANAGER_ERROR, + GSM_MANAGER_ERROR_INVALID_OPTION, + "Unknown logout mode flag"); + return FALSE; } return TRUE; diff --git a/gnome-session/gsm-manager.h b/gnome-session/gsm-manager.h index e9a9949a..c67f51db 100644 --- a/gnome-session/gsm-manager.h +++ b/gnome-session/gsm-manager.h @@ -93,6 +93,7 @@ typedef enum GSM_MANAGER_ERROR_NOT_IN_RUNNING, GSM_MANAGER_ERROR_ALREADY_REGISTERED, GSM_MANAGER_ERROR_NOT_REGISTERED, + GSM_MANAGER_ERROR_INVALID_OPTION, GSM_MANAGER_NUM_ERRORS } GsmManagerError; @@ -143,7 +144,7 @@ gboolean gsm_manager_is_inhibited (GsmManager gboolean gsm_manager_shutdown (GsmManager *manager, GError **error); gboolean gsm_manager_logout (GsmManager *manager, - int logout_mode, + guint logout_mode, GError **error); gboolean gsm_manager_setenv (GsmManager *manager, diff --git a/gnome-session/org.gnome.SessionManager.xml b/gnome-session/org.gnome.SessionManager.xml index 9926385f..cf9670d9 100644 --- a/gnome-session/org.gnome.SessionManager.xml +++ b/gnome-session/org.gnome.SessionManager.xml @@ -253,7 +253,7 @@ </method> <method name="Logout"> - <arg name="mode" type="i" direction="in"> + <arg name="mode" type="u" direction="in"> <doc:doc> <doc:summary>The type of logout that is being requested</doc:summary> </doc:doc> diff --git a/tools/gnome-session-save.c b/tools/gnome-session-save.c index 1c9789cb..ccd98222 100644 --- a/tools/gnome-session-save.c +++ b/tools/gnome-session-save.c @@ -2,6 +2,7 @@ * save-session.c - Small program to talk to session manager. Copyright (C) 1998 Tom Tromey + Copyright (C) 2008 Red Hat, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,26 +22,23 @@ #include <config.h> +#include <unistd.h> +#include <stdlib.h> #include <stdio.h> #include <string.h> #include <glib/gi18n.h> #include <gtk/gtk.h> -#include <libgnomeui/gnome-client.h> -#include <libgnomeui/gnome-ui-init.h> - #include <dbus/dbus-glib.h> #include <dbus/dbus-glib-lowlevel.h> -#include <X11/SM/SMlib.h> - #define GSM_SERVICE_DBUS "org.gnome.SessionManager" #define GSM_PATH_DBUS "/org/gnome/SessionManager" #define GSM_INTERFACE_DBUS "org.gnome.SessionManager" /* True if killing. */ -static gboolean zap = FALSE; +static gboolean do_logout = FALSE; /* True if we should use dialog boxes */ static gboolean gui = FALSE; @@ -50,11 +48,9 @@ static gboolean silent = FALSE; static char *session_name = NULL; -static IceConn ice_conn = NULL; - -static const GOptionEntry options[] = { +static GOptionEntry options[] = { {"session-name", 's', 0, G_OPTION_ARG_STRING, &session_name, N_("Set the current session name"), N_("NAME")}, - {"kill", '\0', 0, G_OPTION_ARG_NONE, &zap, N_("Kill session"), NULL}, + {"kill", '\0', 0, G_OPTION_ARG_NONE, &do_logout, N_("Kill session"), NULL}, {"gui", '\0', 0, G_OPTION_ARG_NONE, &gui, N_("Use dialog boxes for errors"), NULL}, {"silent", '\0', 0, G_OPTION_ARG_NONE, &silent, N_("Do not require confirmation"), NULL}, {NULL} @@ -63,53 +59,6 @@ static const GOptionEntry options[] = { static int exit_status = 0; static void -ping_reply (IceConn ice_conn, - IcePointer clientData) -{ - gtk_main_quit (); -} - -static void -ice_ping (void) -{ - /* We can't exit immediately, because the trash mode above - * might be discarded. So we do the equivalent of an XSync. - */ - if (ice_conn) { - IcePing (ice_conn, ping_reply, NULL); - } else { - g_warning ("save complete, but we don't have an ice connection."); - } -} - -static void -save_complete (GnomeClient* client, gpointer data) -{ - /* We could expose more of the arguments to the user if we wanted - to. Some of them aren't particularly useful. Interestingly, - there is no way to request a shutdown without a save. */ - gnome_client_request_save (client, GNOME_SAVE_BOTH, zap, - silent ? GNOME_INTERACT_NONE : GNOME_INTERACT_ANY, - 0, 1); - - ice_ping (); -} - -static void -die_cb (GnomeClient *client, - gpointer data) -{ - ice_ping (); -} - -static void -cancelled_cb (GnomeClient *client, - gpointer data) -{ - ice_ping (); -} - -static void display_error (const char *message) { if (gui && !silent) { @@ -118,6 +67,8 @@ display_error (const char *message) dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, message); + /*gtk_window_set_default_icon_name (GTK_STOCK_SAVE);*/ + gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } else { @@ -125,42 +76,17 @@ display_error (const char *message) } } - -/* - * we do this so we can pick up our IceConnection to do a ping on - */ -static void -ice_connection_watch (IceConn connection, - IcePointer client_data, - Bool opening, - IcePointer *watch_data) -{ - if (opening) { - if (!ice_conn) { - ice_conn = connection; - } else { - g_message ("Second ICE connection opened: ignoring."); - } - } else { - if (ice_conn == connection) { - ice_conn = NULL; - } else { - g_message ("Second ICE connection closed: ignoring."); - } - } -} - static DBusGProxy * -get_bus_proxy (DBusGConnection *connection) +get_sm_proxy (DBusGConnection *connection) { - DBusGProxy *bus_proxy; + DBusGProxy *sm_proxy; - bus_proxy = dbus_g_proxy_new_for_name (connection, + sm_proxy = dbus_g_proxy_new_for_name (connection, GSM_SERVICE_DBUS, GSM_PATH_DBUS, GSM_INTERFACE_DBUS); - return bus_proxy; + return sm_proxy; } static DBusGConnection * @@ -180,12 +106,11 @@ get_session_bus (void) } static void -set_session_name (GnomeClient *client, - const char *session_name) +set_session_name (const char *session_name) { DBusGConnection *bus; - DBusGProxy *bus_proxy = NULL; - GError *error = NULL; + DBusGProxy *sm_proxy; + GError *error; gboolean res; bus = get_session_bus (); @@ -195,15 +120,14 @@ set_session_name (GnomeClient *client, goto out; } - bus_proxy = get_bus_proxy (bus); - dbus_g_connection_unref (bus); - - if (bus_proxy == NULL) { + sm_proxy = get_sm_proxy (bus); + if (sm_proxy == NULL) { display_error (_("Could not connect to the session manager")); goto out; } - res = dbus_g_proxy_call (bus_proxy, + error = NULL; + res = dbus_g_proxy_call (sm_proxy, "SetName", &error, G_TYPE_STRING, session_name, @@ -223,59 +147,85 @@ set_session_name (GnomeClient *client, } out: - if (bus_proxy != NULL) { - g_object_unref (bus_proxy); + if (sm_proxy != NULL) { + g_object_unref (sm_proxy); } } -int -main (int argc, char *argv[]) +static void +logout_session (gboolean show_confirmation) { - GnomeClient *client; - GOptionContext *goption_context; + DBusGConnection *bus; + DBusGProxy *sm_proxy; + GError *error; + gboolean res; + guint flags; - /* Initialize the i18n stuff */ - bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); + sm_proxy = NULL; - IceAddConnectionWatch (ice_connection_watch, NULL); + bus = get_session_bus (); + if (bus == NULL) { + display_error (_("Could not connect to the session manager")); + goto out; + } - goption_context = g_option_context_new (N_(" - Save the current session")); - g_option_context_set_translation_domain (goption_context, GETTEXT_PACKAGE); - g_option_context_add_main_entries (goption_context, options, GETTEXT_PACKAGE); + sm_proxy = get_sm_proxy (bus); + if (sm_proxy == NULL) { + display_error (_("Could not connect to the session manager")); + goto out; + } - gnome_program_init ("gnome-session-save", VERSION, - LIBGNOMEUI_MODULE, argc, argv, - GNOME_PARAM_GOPTION_CONTEXT, goption_context, - NULL); + flags = 0; + if (! show_confirmation) { + flags |= 1; + } - gtk_window_set_default_icon_name (GTK_STOCK_SAVE); + error = NULL; + res = dbus_g_proxy_call (sm_proxy, + "Logout", + &error, + G_TYPE_UINT, flags, + G_TYPE_INVALID, + G_TYPE_INVALID); - client = gnome_master_client (); + if (!res) { + if (error != NULL) { + g_warning ("Failed to call logout: %s", + error->message); + g_error_free (error); + } else { + g_warning ("Failed to call logout"); + } - if (!GNOME_CLIENT_CONNECTED (client)) { - display_error (_("Could not connect to the session manager")); - return 1; + goto out; } - gnome_client_set_restart_style (client, GNOME_RESTART_NEVER); + out: + if (sm_proxy != NULL) { + g_object_unref (sm_proxy); + } +} - if (session_name != NULL) { - set_session_name (client, session_name); +int +main (int argc, char *argv[]) +{ + GError *error; + + /* Initialize the i18n stuff */ + bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); + + error = NULL; + if (! gtk_init_with_args (&argc, &argv, NULL, options, NULL, &error)) { + g_warning ("Unable to start: %s", error->message); + g_error_free (error); + exit (1); } - /* Wait until our request is acknowledged: - * gnome-session queues requests but does not honour them if the - * requesting client is dead when the save starts. */ - g_signal_connect (client, "save_complete", - G_CALLBACK (save_complete), GINT_TO_POINTER (1)); - g_signal_connect (client, "die", - G_CALLBACK (die_cb), GINT_TO_POINTER (2)); - g_signal_connect (client, "shutdown_cancelled", - G_CALLBACK (cancelled_cb), GINT_TO_POINTER (3)); - - gtk_main (); + if (do_logout) { + logout_session (! silent); + } return exit_status; } |