gnome-session r4928 - in trunk: . gnome-session tools



Author: mccann
Date: Fri Aug  8 22:26:32 2008
New Revision: 4928
URL: http://svn.gnome.org/viewvc/gnome-session?rev=4928&view=rev

Log:
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.



Modified:
   trunk/ChangeLog
   trunk/gnome-session/gsm-manager.c
   trunk/gnome-session/gsm-manager.h
   trunk/gnome-session/org.gnome.SessionManager.xml
   trunk/tools/gnome-session-save.c

Modified: trunk/gnome-session/gsm-manager.c
==============================================================================
--- trunk/gnome-session/gsm-manager.c	(original)
+++ trunk/gnome-session/gsm-manager.c	Fri Aug  8 22:26:32 2008
@@ -152,6 +152,7 @@
                         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 @@
 
 gboolean
 gsm_manager_logout (GsmManager *manager,
-                    gint        logout_mode,
+                    guint       logout_mode,
                     GError    **error)
 {
         g_debug ("GsmManager: Logout called");
@@ -2482,7 +2483,13 @@
                 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;

Modified: trunk/gnome-session/gsm-manager.h
==============================================================================
--- trunk/gnome-session/gsm-manager.h	(original)
+++ trunk/gnome-session/gsm-manager.h	Fri Aug  8 22:26:32 2008
@@ -93,6 +93,7 @@
         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_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,

Modified: trunk/gnome-session/org.gnome.SessionManager.xml
==============================================================================
--- trunk/gnome-session/org.gnome.SessionManager.xml	(original)
+++ trunk/gnome-session/org.gnome.SessionManager.xml	Fri Aug  8 22:26:32 2008
@@ -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>

Modified: trunk/tools/gnome-session-save.c
==============================================================================
--- trunk/tools/gnome-session-save.c	(original)
+++ trunk/tools/gnome-session-save.c	Fri Aug  8 22:26:32 2008
@@ -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 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 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 @@
                 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 @@
         }
 }
 
-
-/*
- * 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 @@
 }
 
 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 @@
                 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 @@
         }
 
  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;
+
+        bus = get_session_bus ();
+        if (bus == NULL) {
+                display_error (_("Could not connect to the session manager"));
+                goto out;
+        }
 
-        IceAddConnectionWatch (ice_connection_watch, NULL);
+        sm_proxy = get_sm_proxy (bus);
+        if (sm_proxy == 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);
+        flags = 0;
+        if (! show_confirmation) {
+                flags |= 1;
+        }
 
-        gnome_program_init ("gnome-session-save", VERSION,
-                            LIBGNOMEUI_MODULE, argc, argv,
-                            GNOME_PARAM_GOPTION_CONTEXT, goption_context,
-                            NULL);
+        error = NULL;
+        res = dbus_g_proxy_call (sm_proxy,
+                                 "Logout",
+                                 &error,
+                                 G_TYPE_UINT, flags,
+                                 G_TYPE_INVALID,
+                                 G_TYPE_INVALID);
 
-        gtk_window_set_default_icon_name (GTK_STOCK_SAVE);
+        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");
+                }
 
-        client = gnome_master_client ();
+                goto out;
+        }
 
-        if (!GNOME_CLIENT_CONNECTED (client)) {
-                display_error (_("Could not connect to the session manager"));
-                return 1;
+ out:
+        if (sm_proxy != NULL) {
+                g_object_unref (sm_proxy);
         }
+}
+
+int
+main (int argc, char *argv[])
+{
+        GError *error;
 
-        gnome_client_set_restart_style (client, GNOME_RESTART_NEVER);
+        /* Initialize the i18n stuff */
+        bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
+        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+        textdomain (GETTEXT_PACKAGE);
 
-        if (session_name != NULL) {
-                set_session_name (client, session_name);
+        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;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]