summaryrefslogtreecommitdiff
path: root/xfce4-session-logout
diff options
context:
space:
mode:
authorEric Koegel <eric.koegel@gmail.com>2016-04-25 11:48:19 +0300
committerEric Koegel <eric.koegel@gmail.com>2016-04-25 11:48:19 +0300
commit63ac95e2f6f4c3692ac1a4726e2447b33a03ae3f (patch)
tree8215d1d8e109af61f5ffd190a137557d1d2f14de /xfce4-session-logout
parent38a8819834264020c5de6c628c8d402dc11e58dd (diff)
downloadxfce4-session-63ac95e2f6f4c3692ac1a4726e2447b33a03ae3f.tar.gz
session-logout: Port to GDBus
Diffstat (limited to 'xfce4-session-logout')
-rw-r--r--xfce4-session-logout/Makefile.am6
-rw-r--r--xfce4-session-logout/main.c128
2 files changed, 75 insertions, 59 deletions
diff --git a/xfce4-session-logout/Makefile.am b/xfce4-session-logout/Makefile.am
index d12a63a7..2c4240ca 100644
--- a/xfce4-session-logout/Makefile.am
+++ b/xfce4-session-logout/Makefile.am
@@ -9,14 +9,12 @@ xfce4_session_logout_SOURCES = \
xfce4_session_logout_CFLAGS = \
-I$(top_srcdir) \
- $(DBUS_CFLAGS) \
- $(DBUS_GLIB_CFLAGS) \
+ $(GIO_CFLAGS) \
$(LIBXFCE4UI_CFLAGS) \
-DPACKAGE_LOCALE_DIR=\"$(localedir)\"
xfce4_session_logout_LDFLAGS = \
- $(DBUS_LIBS) \
- $(DBUS_GLIB_LIBS) \
+ $(GIO_LIBS) \
$(LIBXFCE4UI_LIBS)
desktopdir = $(datadir)/applications
diff --git a/xfce4-session-logout/main.c b/xfce4-session-logout/main.c
index d9067cef..702b51ee 100644
--- a/xfce4-session-logout/main.c
+++ b/xfce4-session-logout/main.c
@@ -35,8 +35,7 @@
#include <string.h>
#endif
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
+#include <gio/gio.h>
#include <gtk/gtk.h>
#include <libxfce4ui/libxfce4ui.h>
@@ -116,12 +115,11 @@ xfce_session_logout_notify_error (const gchar *message,
int
main (int argc, char **argv)
{
- DBusGConnection *conn;
- DBusGProxy *proxy = NULL;
+ GDBusProxy *proxy = NULL;
GError *err = NULL;
gboolean have_display;
gboolean show_dialog;
- gboolean result = FALSE;
+ GVariant *result = NULL;
guint shutdown_type;
gboolean allow_save;
@@ -132,7 +130,7 @@ main (int argc, char **argv)
if (opt_version)
{
g_print ("%s %s (Xfce %s)\n\n", PACKAGE_NAME, PACKAGE_VERSION, xfce_version_string ());
- g_print ("%s\n", "Copyright (c) 2004-2012");
+ g_print ("%s\n", "Copyright (c) 2004-2016");
g_print ("\t%s\n\n", _("The Xfce development team. All rights reserved."));
g_print ("%s\n", _("Written by Benedikt Meurer <benny@xfce.org>"));
g_print ("%s\n\n", _("and Brian Tarricone <kelnos@xfce.org>."));
@@ -141,61 +139,75 @@ main (int argc, char **argv)
return EXIT_SUCCESS;
}
- /* open session bus */
- conn = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
- if (conn == NULL)
+ /* save the session, unless fast is provided */
+ allow_save = !opt_fast;
+
+ /* create messsage */
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.xfce.SessionManager",
+ "/org/xfce/SessionManager",
+ "org.xfce.Session.Manager",
+ NULL,
+ &err);
+ if (proxy == NULL)
{
- xfce_session_logout_notify_error (_("Unable to contact D-Bus session bus"), err, have_display);
+ xfce_session_logout_notify_error (_("Received error while trying to log out"), err, have_display);
g_error_free (err);
return EXIT_FAILURE;
}
- /* save the session, unless fast is provided */
- allow_save = !opt_fast;
-
- /* create messsage */
- proxy = dbus_g_proxy_new_for_name_owner (conn,
- "org.xfce.SessionManager",
- "/org/xfce/SessionManager",
- "org.xfce.Session.Manager",
- &err);
- if (proxy != NULL)
+ if (opt_halt)
{
- if (opt_halt)
- {
- result = dbus_g_proxy_call (proxy, "Shutdown", &err,
- G_TYPE_BOOLEAN, allow_save,
- G_TYPE_INVALID, G_TYPE_INVALID);
- }
- else if (opt_reboot)
- {
- result = dbus_g_proxy_call (proxy, "Restart", &err,
- G_TYPE_BOOLEAN, allow_save,
- G_TYPE_INVALID, G_TYPE_INVALID);
- }
- else if (opt_suspend)
- {
- result = dbus_g_proxy_call (proxy, "Suspend", &err,
- G_TYPE_INVALID, G_TYPE_INVALID);
- }
- else if (opt_hibernate)
- {
- result = dbus_g_proxy_call (proxy, "Hibernate", &err,
- G_TYPE_INVALID, G_TYPE_INVALID);
- }
- else
- {
- show_dialog = !opt_logout;
- result = dbus_g_proxy_call (proxy, "Logout", &err,
- G_TYPE_BOOLEAN, show_dialog,
- G_TYPE_BOOLEAN, allow_save,
- G_TYPE_INVALID, G_TYPE_INVALID);
- }
+ result = g_dbus_proxy_call_sync (proxy, "Shutdown",
+ g_variant_new_boolean(allow_save),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &err);
+ }
+ else if (opt_reboot)
+ {
+ result = g_dbus_proxy_call_sync (proxy, "Restart",
+ g_variant_new_boolean(allow_save),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &err);
+ }
+ else if (opt_suspend)
+ {
+ result = g_dbus_proxy_call_sync (proxy, "Suspend",
+ g_variant_new("()"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &err);
+ }
+ else if (opt_hibernate)
+ {
+ result = g_dbus_proxy_call_sync (proxy, "Hibernate",
+ g_variant_new("()"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &err);
+ }
+ else
+ {
+ show_dialog = !opt_logout;
+ result = g_dbus_proxy_call_sync (proxy, "Logout",
+ g_variant_new("(bb)",show_dialog, allow_save),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &err);
}
/* fallback for the old 4.8 API dbus, so users can logout if
* they upgraded their system, see bug #8630 */
- if (!result && g_error_matches (err, DBUS_GERROR, DBUS_GERROR_UNKNOWN_METHOD))
+ if (!result)
{
g_clear_error (&err);
@@ -212,10 +224,12 @@ main (int argc, char **argv)
else
shutdown_type = XFSM_SHUTDOWN_ASK;
- result = dbus_g_proxy_call (proxy, "Shutdown", &err,
- G_TYPE_UINT, shutdown_type,
- G_TYPE_BOOLEAN, allow_save,
- G_TYPE_INVALID, G_TYPE_INVALID);
+ result = g_dbus_proxy_call_sync (proxy, "Shutdown",
+ g_variant_new("(yb)",shutdown_type, allow_save),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &err);
}
@@ -228,6 +242,10 @@ main (int argc, char **argv)
g_error_free (err);
return EXIT_FAILURE;
}
+ else
+ {
+ g_variant_unref (result);
+ }
return EXIT_SUCCESS;
}