summaryrefslogtreecommitdiff
path: root/xfce4-session-logout
diff options
context:
space:
mode:
authorBrian Tarricone <brian@tarricone.org>2008-10-08 00:58:45 +0000
committerBrian Tarricone <brian@tarricone.org>2008-10-08 00:58:45 +0000
commit8faa755e2de2e0ce26be11035e6e1ef96fc5cab8 (patch)
tree9cc40faa4c062990fa78a2bf5b38088e63a45634 /xfce4-session-logout
parent8db9b4b27a5535d6ee5688d71a864d6c885134a1 (diff)
downloadxfce4-session-8faa755e2de2e0ce26be11035e6e1ef96fc5cab8.tar.gz
* 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. (Old svn revision: 28099)
Diffstat (limited to 'xfce4-session-logout')
-rw-r--r--xfce4-session-logout/Makefile.am2
-rw-r--r--xfce4-session-logout/main.c134
-rw-r--r--xfce4-session-logout/xfce4-session-logout.128
3 files changed, 130 insertions, 34 deletions
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.