diff options
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | configure.in.in | 3 | ||||
-rw-r--r-- | xfce4-session-logout/Makefile.am | 2 | ||||
-rw-r--r-- | xfce4-session-logout/main.c | 134 | ||||
-rw-r--r-- | xfce4-session-logout/xfce4-session-logout.1 | 28 | ||||
-rw-r--r-- | xfce4-session/Makefile.am | 2 |
6 files changed, 146 insertions, 35 deletions
@@ -1,5 +1,17 @@ 2008-10-07 Brian Tarricone <bjt23@cornell.edu> + * configure.in.in: Add separate deps on dbus and dbus-glib. + * xfce4-session-logout/Makefile.am,xfce4-session/Makefile.am: + Fix/add dbus/dbus-glib deps. + * xfce4-session-logout/main.c: Make xfce4-session-logout use + the more flexible dbus interface for shutting down, and add + command-line options to take action while skipping the + logout confirmation dialog. + * xfce4-session-logout/xfce4-session-logout.1: Update manual + page to reflect new command-line options. + +2008-10-07 Brian Tarricone <bjt23@cornell.edu> + * configure.in.in,xfce4-session/Makefile.am: Add check for gnome-keyring support library. * xfce4-session/xfsm-compat-gnome.c: Don't start a new diff --git a/configure.in.in b/configure.in.in index 8f0d5e0e..6d76ca5d 100644 --- a/configure.in.in +++ b/configure.in.in @@ -74,7 +74,8 @@ dnl Check for required packages XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.5.90]) XDT_CHECK_PACKAGE([LIBXFCEGUI4], [libxfcegui4-1.0], [4.5.90]) XDT_CHECK_PACKAGE([LIBWNCK], [libwnck-1.0], [2.12]) -XDT_CHECK_PACKAGE([DBUS], [dbus-glib-1], [0.73]) +XDT_CHECK_PACKAGE([DBUS], [dbus-1], [1.0.0]) +XDT_CHECK_PACKAGE([DBUS_GLIB], [dbus-glib-1], [0.73]) dnl Check for gnome support XDT_CHECK_OPTIONAL_PACKAGE([GNOME], [gconf-2.0], [2.4.0], [gnome], diff --git a/xfce4-session-logout/Makefile.am b/xfce4-session-logout/Makefile.am index 63fb8b8b..354c760d 100644 --- a/xfce4-session-logout/Makefile.am +++ b/xfce4-session-logout/Makefile.am @@ -9,9 +9,11 @@ xfce4_session_logout_SOURCES = \ xfce4_session_logout_CFLAGS = \ -I$(top_srcdir) \ + $(DBUS_CFLAGS) \ $(LIBXFCEGUI4_CFLAGS) xfce4_session_logout_LDFLAGS = \ + $(DBUS_LIBS) \ $(LIBXFCEGUI4_LIBS) EXTRA_DIST = \ diff --git a/xfce4-session-logout/main.c b/xfce4-session-logout/main.c index 2be4d948..08db9c36 100644 --- a/xfce4-session-logout/main.c +++ b/xfce4-session-logout/main.c @@ -1,6 +1,6 @@ /* $Id$ */ /*- - * Copyright (c) 2004 Brian Tarricone <kelnos@xfce.org> + * Copyright (c) 2004,2008 Brian Tarricone <kelnos@xfce.org> * Copyright (c) 2004 Benedikt Meurer <benny@xfce.org> * All rights reserved. * @@ -35,31 +35,48 @@ #include <string.h> #endif -#include <libxfcegui4/libxfcegui4.h> +#include <dbus/dbus.h> +#include <gtk/gtk.h> +#include <libxfcegui4/libxfcegui4.h> -static gboolean -quit_timer (gpointer user_data) +/* copied from xfce4-session/shutdown.h -- ORDER MATTERS. The numbers + * correspond to the 'type' parameter of org.xfce.Session.Manager.Shutdown + */ +typedef enum { - SessionClient *client = user_data; - - logout_session (client); - - return FALSE; -} - + XFSM_SHUTDOWN_ASK = 0, + XFSM_SHUTDOWN_LOGOUT, + XFSM_SHUTDOWN_HALT, + XFSM_SHUTDOWN_REBOOT, + XFSM_SHUTDOWN_SUSPEND, + XFSM_SHUTDOWN_HIBERNATE, +} XfsmShutdownType; static void -die_handler (gpointer user_data) +xfce_session_logout_notify_error (const gchar *primary_message, + DBusError *derror, + gboolean have_display) { - if (gtk_main_level ()) - gtk_main_quit (); + if (G_LIKELY (have_display)) + { + xfce_message_dialog (NULL, _("Logout Error"), GTK_STOCK_DIALOG_ERROR, + primary_message, + derror && dbus_error_is_set (derror) + ? derror->message : _("Unknown error"), + GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL); + } + else + { + g_critical ("%s: %s", primary_message, + derror && dbus_error_is_set (derror) ? derror->message + : _("Unknown error")); + } } - static void usage (int exit_code) { @@ -70,6 +87,12 @@ usage (int exit_code) " --display=DISPLAY X display to use\n" "\n" "Application options\n" + " --logout Log out without displaying the logout dialog\n" + " --halt Halt without displaing the logout dialog\n" + " --reboot Reboot without displaying the logout dialog\n" + " --suspend Suspend without displaying the logout dialog\n" + " --hibernate Hibernate without displaying the logout dialog\n" + "\n" " --help Print this help message and exit\n" " --version Print version information and exit\n" "\n", @@ -82,14 +105,36 @@ usage (int exit_code) int main (int argc, char **argv) { - SessionClient *client; - gboolean managed; - - gtk_init (&argc, &argv); + XfsmShutdownType shutdown_type = XFSM_SHUTDOWN_ASK; + gboolean allow_save = TRUE; + DBusConnection *dbus_conn; + DBusMessage *message, *reply; + DBusError derror; + gboolean have_display = gtk_init_check (&argc, &argv); for (++argv; --argc > 0; ++argv) { - if (strcmp (*argv, "--version") == 0) + if (strcmp (*argv, "--logout") == 0) + { + shutdown_type = XFSM_SHUTDOWN_LOGOUT; + } + else if (strcmp (*argv, "--halt") == 0) + { + shutdown_type = XFSM_SHUTDOWN_HALT; + } + else if (strcmp (*argv, "--reboot") == 0) + { + shutdown_type = XFSM_SHUTDOWN_REBOOT; + } + else if (strcmp (*argv, "--suspend") == 0) + { + shutdown_type = XFSM_SHUTDOWN_SUSPEND; + } + else if (strcmp (*argv, "--hibernate") == 0) + { + shutdown_type = XFSM_SHUTDOWN_HIBERNATE; + } + else if (strcmp (*argv, "--version") == 0) { printf ("%s (Xfce %s)\n\n" "Copyright (c) 2004\n" @@ -106,21 +151,52 @@ main (int argc, char **argv) } } - client = client_session_new (argc, argv, NULL, SESSION_RESTART_NEVER, 99); - client->die = die_handler; - managed = session_init (client); + dbus_error_init (&derror); + dbus_conn = dbus_bus_get (DBUS_BUS_SESSION, &derror); + if (G_UNLIKELY (dbus_conn == NULL)) + { + xfce_session_logout_notify_error (_("Unable to contact D-Bus session bus."), + &derror, have_display); + dbus_error_free (&derror); + return EXIT_FAILURE; + } + + message = dbus_message_new_method_call ("org.xfce.SessionManager", + "/org/xfce/SessionManager", + "org.xfce.Session.Manager", + "Shutdown"); + if (G_UNLIKELY (message == NULL)) + { + xfce_session_logout_notify_error (_("Failed to create new D-Bus message"), + NULL, have_display); + return EXIT_FAILURE; + } - if (managed) + dbus_message_append_args (message, + DBUS_TYPE_UINT32, &shutdown_type, + DBUS_TYPE_BOOLEAN, &allow_save, + DBUS_TYPE_INVALID); + + reply = dbus_connection_send_with_reply_and_block (dbus_conn, message, + -1, &derror); + dbus_message_unref (message); + + if (G_UNLIKELY (reply == NULL)) { - g_idle_add_full (G_PRIORITY_LOW, quit_timer, - client, die_handler); - gtk_main (); + xfce_session_logout_notify_error (_("Failed to receive a reply from the session manager"), + &derror, have_display); + dbus_error_free (&derror); + return EXIT_FAILURE; } - else + else if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { - fprintf (stderr, "xfce4-session-logout: No session manager running.\n"); + dbus_set_error_from_message (&derror, reply); + xfce_session_logout_notify_error (_("Received error while trying to log out"), + &derror, have_display); + dbus_error_free (&derror); return EXIT_FAILURE; } + dbus_message_unref (reply); return EXIT_SUCCESS; } diff --git a/xfce4-session-logout/xfce4-session-logout.1 b/xfce4-session-logout/xfce4-session-logout.1 index 8341a52b..145318d4 100644 --- a/xfce4-session-logout/xfce4-session-logout.1 +++ b/xfce4-session-logout/xfce4-session-logout.1 @@ -1,4 +1,4 @@ -.TH xfce4-session-logout 1 "Nov 01, 2004" +.TH xfce4-session-logout 1 "Oct 7, 2008" .SH NAME xfce4-session-logout \- Logs out from Xfce .SH SYNOPSIS @@ -11,12 +11,29 @@ command. .PP The \fBxfce4-session-logout\fP command allows you to programmatically logout from your Xfce session. It requests the session manager to display -the logout confirmation screen. +the logout confirmation screen, or, if given one of the command-line +options below, causes the session manager to take the requested action +immediately. .SH OPTIONS \fBxfce4-session-logout\fP takes the following command line options: .TP +.B \-\-logout +Log out without displaying the logout dialog. +.TP +.B \-\-halt +Halt without displaing the logout dialog. +.TP +.B \-\-reboot +Reboot without displaying the logout dialog. +.TP +.B \-\-suspend +Suspend without displaying the logout dialog. +.TP +.B \-\-hibernate +Hibernate without displaying the logout dialog. +.TP .B \-\-help Print a help screen and exit. .TP @@ -24,12 +41,13 @@ Print a help screen and exit. Output version information and exit. .SH AUTHOR -\fBxfce4-session-logout\fP was written by Brian +\fBxfce4-session-logout\fP and this manual +page were written by Brian Tarricone <kelnos@xfce.org> and Benedikt Meurer <benny@xfce.org> as part of the Xfce project. -This manual page was written by Benedikt -Meurer <benny@xfce.org>. .SH "REPORTING BUGS" Report bugs to http://bugzilla.xfce.org/. .SH COPYRIGHT Copyright \(co 2004 Benedikt Meurer. +.br +Copyright \(co 2008 Brian Tarricone. diff --git a/xfce4-session/Makefile.am b/xfce4-session/Makefile.am index f8482a4a..de5ddbe1 100644 --- a/xfce4-session/Makefile.am +++ b/xfce4-session/Makefile.am @@ -57,6 +57,7 @@ xfce4_session_CFLAGS = \ $(LIBX11_CFLAGS) \ $(LIBXFCEGUI4_CFLAGS) \ $(DBUS_CFLAGS) \ + $(DBUS_GLIB_CFLAGS) \ $(LIBWNCK_CFLAGS) \ -DDBUS_API_SUBJECT_TO_CHANGE \ -DWNCK_I_KNOW_THIS_IS_UNSTABLE \ @@ -73,6 +74,7 @@ xfce4_session_LDADD = \ $(LIBX11_LIBS) \ $(LIBXFCEGUI4_LIBS) \ $(DBUS_LIBS) \ + $(DBUS_GLIB_LIBS) \ $(LIBWNCK_LIBS) \ $(GNOME_LIBS) \ $(GNOME_KEYRING_LIBS) |