gnome-session r5029 - in trunk: . doc/man tools



Author: vuntz
Date: Mon Sep  1 16:49:20 2008
New Revision: 5029
URL: http://svn.gnome.org/viewvc/gnome-session?rev=5029&view=rev

Log:
2008-09-01  Vincent Untz  <vuntz gnome org>

	Add --logout, --force-logout, --logout-dialog and --shutdown-dialog
	arguments to gnome-session-save, and deprecate --kill. This will make
	things less ambiguous.

	* tools/gnome-session-save.c: rename some variables
	(display_error): updated
	(get_sm_proxy): call get_session_bus() from there, since it simplifies
	code elsewhere
	(set_session_name): updated
	(do_logout): renamed from logout_session(), and simplified. Also add
	a mode argument for the logout dbus method.
	(do_shutdown_dialog): new
	(main): updated for new options
	* doc/man/gnome-session-save.1: update man page
	Fix bug #550211.


Modified:
   trunk/ChangeLog
   trunk/doc/man/gnome-session-save.1
   trunk/tools/gnome-session-save.c

Modified: trunk/doc/man/gnome-session-save.1
==============================================================================
--- trunk/doc/man/gnome-session-save.1	(original)
+++ trunk/doc/man/gnome-session-save.1	Mon Sep  1 16:49:20 2008
@@ -2,31 +2,38 @@
 .\" gnome-session-save manual page.
 .\" (C) 2000 Miguel de Icaza (miguel helixcode com)
 .\"
-.TH GNOME 1 "GNOME 1.0"
+.TH GNOME-SESSION-SAVE 1 "GNOME"
 .SH NAME
-gnome-session-save \- Saves the current GNOME session (or terminates it)
+gnome-session-save \- Saves or ends the current GNOME session
 .SH SYNOPSIS
-.B gnome-session-save [\-\-kill] [\-\-gui] [\-\-silent]
+.B gnome-session-save [\-\-logout] [\-\-force\-logout] [\-\-logout\-dialog] [\-\-shutdown\-dialog] [\-\-gui] [\-\-kill [\-\-silent]]
 .SH DESCRIPTION
 \fIgnome-session-save\fP can be used from a GNOME session to save a snapshot
 of the currently running applications.  This session will be later
 restored at your next GNOME startup session.
 .PP
-You can specify the 
-.B \-\-kill 
-argument to terminate the GNOME session.
+The \fB\-\-gui\fP argument will report errors in dialog boxes instead of
+printing to stderr.
 
-The
-.B \-\-gui
-argument will report errors in dialog boxes instead of printing to stderr.
+If called with the \fB\-\-logout\fP argument, the current GNOME session will be
+ended, unless logging out has been inhibited by an application.  The
+\fB\-\-force\-logout\fP argument can be used to end the session regardless of
+the inhibition state.
 
-The
-.B \-\-silent
-argument will perform the requested action without confirmation from the user.
+When the \fB\-\-logout\-dialog\fP argument is given, the standard dialog
+displaying logout options is displayed.  When \fB\-\-shutdown\-dialog\fP
+argument is given, the standard dialog displaying shutdown options is
+displayed.
+
+The \fB\-\-kill\fP argument is deprecated.  It is equivalent to the
+\fB\-\-logout\-dialog\fP argument.  If \fB\-\-silent\fP is used with
+\fB\-\-kill\fR, then it will behave as if \fB\-\-logout\fP was used.
+
+The session is not saved when \fIgnome-session-save\fP is called with any of
+the arguments ending the session.
 
 .SH SEE ALSO
 .BR gnome-session(1)
 .SH BUGS
 If you find bugs in the \fIgnome-session-save\fP program, please report
-these using either \fIbug-buddy\fP or \fIgnome-bug\fP included with the GNOME
-libraries distribution.
+these on http://bugzilla.gnome.org.

Modified: trunk/tools/gnome-session-save.c
==============================================================================
--- trunk/tools/gnome-session-save.c	(original)
+++ trunk/tools/gnome-session-save.c	Mon Sep  1 16:49:20 2008
@@ -37,22 +37,39 @@
 #define GSM_PATH_DBUS      "/org/gnome/SessionManager"
 #define GSM_INTERFACE_DBUS "org.gnome.SessionManager"
 
-/* True if killing.  */
-static gboolean do_logout = FALSE;
+enum {
+        GSM_LOGOUT_MODE_NORMAL = 0,
+        GSM_LOGOUT_MODE_NO_CONFIRMATION,
+        GSM_LOGOUT_MODE_FORCE
+};
+
+/* True if killing. This is deprecated, but we keep it for compatibility
+ * reasons. */
+static gboolean kill = FALSE;
+
+/* The real options that should be used now. They are not ambiguous. */
+static gboolean logout = FALSE;
+static gboolean force_logout = FALSE;
+static gboolean logout_dialog = FALSE;
+static gboolean shutdown_dialog = FALSE;
 
 /* True if we should use dialog boxes */
-static gboolean gui = FALSE;
+static gboolean show_error_dialogs = FALSE;
 
 /* True if we should do the requested action without confirmation */
-static gboolean silent = FALSE;
+static gboolean no_interaction = FALSE;
 
 static char *session_name = NULL;
 
 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, &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},
+        {"logout", '\0', 0, G_OPTION_ARG_NONE, &logout, N_("Log out"), NULL},
+        {"force-logout", '\0', 0, G_OPTION_ARG_NONE, &force_logout, N_("Log out, ignoring any existing inhibitors"), NULL},
+        {"logout-dialog", '\0', 0, G_OPTION_ARG_NONE, &logout_dialog, N_("Show logout dialog"), NULL},
+        {"shutdown-dialog", '\0', 0, G_OPTION_ARG_NONE, &shutdown_dialog, N_("Show shutdown dialog"), NULL},
+        {"kill", '\0', 0, G_OPTION_ARG_NONE, &kill, N_("Kill session"), NULL},
+        {"gui",  '\0', 0, G_OPTION_ARG_NONE, &show_error_dialogs, N_("Use dialog boxes for errors"), NULL},
+        {"silent", '\0', 0, G_OPTION_ARG_NONE, &no_interaction, N_("Do not require confirmation"), NULL},
         {NULL}
 };
 
@@ -61,7 +78,7 @@
 static void
 display_error (const char *message)
 {
-        if (gui && !silent) {
+        if (show_error_dialogs && !no_interaction) {
                 GtkWidget *dialog;
 
                 dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR,
@@ -76,19 +93,6 @@
         }
 }
 
-static DBusGProxy *
-get_sm_proxy (DBusGConnection *connection)
-{
-        DBusGProxy *sm_proxy;
-
-        sm_proxy = dbus_g_proxy_new_for_name (connection,
-                                               GSM_SERVICE_DBUS,
-                                               GSM_PATH_DBUS,
-                                               GSM_INTERFACE_DBUS);
-
-        return sm_proxy;
-}
-
 static DBusGConnection *
 get_session_bus (void)
 {
@@ -105,26 +109,42 @@
         return bus;
 }
 
-#if 0
-static void
-set_session_name (const char  *session_name)
+static DBusGProxy *
+get_sm_proxy (void)
 {
-        DBusGConnection *bus;
+        DBusGConnection *connection;
         DBusGProxy      *sm_proxy;
-        GError          *error;
-        gboolean         res;
 
-        bus = get_session_bus ();
-
-        if (bus == NULL) {
+        connection = get_session_bus ();
+        if (connection == NULL) {
                 display_error (_("Could not connect to the session manager"));
-                goto out;
+                return NULL;
         }
 
-        sm_proxy = get_sm_proxy (bus);
+        sm_proxy = dbus_g_proxy_new_for_name (connection,
+                                               GSM_SERVICE_DBUS,
+                                               GSM_PATH_DBUS,
+                                               GSM_INTERFACE_DBUS);
+
         if (sm_proxy == NULL) {
                 display_error (_("Could not connect to the session manager"));
-                goto out;
+                return NULL;
+        }
+
+        return sm_proxy;
+}
+
+#if 0
+static void
+set_session_name (const char  *session_name)
+{
+        DBusGProxy *sm_proxy;
+        GError     *error;
+        gboolean    res;
+
+        sm_proxy = get_sm_proxy ();
+        if (sm_proxy == NULL) {
+                return;
         }
 
         error = NULL;
@@ -143,11 +163,8 @@
                         g_warning ("Failed to set session name '%s'",
                                    session_name);
                 }
-
-                goto out;
         }
 
- out:
         if (sm_proxy != NULL) {
                 g_object_unref (sm_proxy);
         }
@@ -155,38 +172,22 @@
 #endif
 
 static void
-logout_session (gboolean show_confirmation)
+do_logout (unsigned int mode)
 {
-        DBusGConnection *bus;
-        DBusGProxy      *sm_proxy;
-        GError          *error;
-        gboolean         res;
-        guint            flags;
-
-        sm_proxy = NULL;
-
-        bus = get_session_bus ();
-        if (bus == NULL) {
-                display_error (_("Could not connect to the session manager"));
-                goto out;
-        }
+        DBusGProxy *sm_proxy;
+        GError     *error;
+        gboolean    res;
 
-        sm_proxy = get_sm_proxy (bus);
+        sm_proxy = get_sm_proxy ();
         if (sm_proxy == NULL) {
-                display_error (_("Could not connect to the session manager"));
-                goto out;
-        }
-
-        flags = 0;
-        if (! show_confirmation) {
-                flags |= 1;
+                return;
         }
 
         error = NULL;
         res = dbus_g_proxy_call (sm_proxy,
                                  "Logout",
                                  &error,
-                                 G_TYPE_UINT, flags,
+                                 G_TYPE_UINT, mode,
                                  G_TYPE_INVALID,
                                  G_TYPE_INVALID);
 
@@ -198,11 +199,42 @@
                 } else {
                         g_warning ("Failed to call logout");
                 }
+        }
 
-                goto out;
+        if (sm_proxy != NULL) {
+                g_object_unref (sm_proxy);
+        }
+}
+
+static void
+do_shutdown_dialog (void)
+{
+        DBusGProxy *sm_proxy;
+        GError     *error;
+        gboolean    res;
+
+        sm_proxy = get_sm_proxy ();
+        if (sm_proxy == NULL) {
+                return;
+        }
+
+        error = NULL;
+        res = dbus_g_proxy_call (sm_proxy,
+                                 "Shutdown",
+                                 &error,
+                                 G_TYPE_INVALID,
+                                 G_TYPE_INVALID);
+
+        if (!res) {
+                if (error != NULL) {
+                        g_warning ("Failed to call shutdown: %s",
+                                   error->message);
+                        g_error_free (error);
+                } else {
+                        g_warning ("Failed to call shutdown");
+                }
         }
 
- out:
         if (sm_proxy != NULL) {
                 g_object_unref (sm_proxy);
         }
@@ -212,6 +244,7 @@
 main (int argc, char *argv[])
 {
         GError *error;
+        int     conflicting_options;
 
         /* Initialize the i18n stuff */
         bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
@@ -225,8 +258,35 @@
                 exit (1);
         }
 
-        if (do_logout) {
-                logout_session (! silent);
+        conflicting_options = 0;
+        if (kill)
+                conflicting_options++;
+        if (logout)
+                conflicting_options++;
+        if (force_logout)
+                conflicting_options++;
+        if (logout_dialog)
+                conflicting_options++;
+        if (shutdown_dialog)
+                conflicting_options++;
+        if (conflicting_options > 1)
+                display_error (_("Program called with conflicting options"));
+
+        if (kill) {
+                if (no_interaction)
+                        logout = TRUE;
+                else
+                        logout_dialog = TRUE;
+        }
+
+        if (logout) {
+                do_logout (GSM_LOGOUT_MODE_NO_CONFIRMATION);
+        } else if (force_logout) {
+                do_logout (GSM_LOGOUT_MODE_FORCE);
+        } else if (logout_dialog) {
+                do_logout (GSM_LOGOUT_MODE_NORMAL);
+        } else if (shutdown_dialog) {
+                do_shutdown_dialog ();
         }
 
         return exit_status;



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