diff options
author | Wu Xiaotian <[email protected]> | 2018-12-10 19:29:01 +0800 |
---|---|---|
committer | monsta <[email protected]> | 2018-12-10 14:29:01 +0300 |
commit | 413050e91f814dbda33758f3f332ad48d3479f64 (patch) | |
tree | 3284f920eada159619bf8500ec40ae98e8b238f6 /tools | |
parent | f20dad80e2dc3258c0dcb3c76e08a76ea2715ea8 (diff) | |
download | mate-session-manager-413050e91f814dbda33758f3f332ad48d3479f64.tar.bz2 mate-session-manager-413050e91f814dbda33758f3f332ad48d3479f64.tar.xz |
Migrate from dbus-glib to gdbus
- tools/Makefile.am
- tools/mate-session-save.c
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile.am | 4 | ||||
-rw-r--r-- | tools/mate-session-save.c | 135 |
2 files changed, 56 insertions, 83 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am index ea00cff..5680214 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -2,7 +2,6 @@ bin_PROGRAMS = mate-session-save mate-session-inhibit AM_CPPFLAGS = \ $(MATE_SESSION_CFLAGS) \ - $(DBUS_GLIB_CFLAGS) \ -DLOCALE_DIR=\""$(datadir)/locale"\" \ $(DISABLE_DEPRECATED_CFLAGS) @@ -14,8 +13,7 @@ mate_session_save_SOURCES = \ mate_session_save_LDADD = \ $(SM_LIBS) \ $(ICE_LIBS) \ - $(MATE_SESSION_LIBS) \ - $(DBUS_GLIB_LIBS) + $(MATE_SESSION_LIBS) mate_session_inhibit_SOURCES = \ mate-session-inhibit.c diff --git a/tools/mate-session-save.c b/tools/mate-session-save.c index 1e958eb..ff3fc5c 100644 --- a/tools/mate-session-save.c +++ b/tools/mate-session-save.c @@ -30,9 +30,6 @@ #include <glib/gi18n.h> #include <gtk/gtk.h> -#include <dbus/dbus-glib.h> -#include <dbus/dbus-glib-lowlevel.h> - #define GSM_SERVICE_DBUS "org.gnome.SessionManager" #define GSM_PATH_DBUS "/org/gnome/SessionManager" #define GSM_INTERFACE_DBUS "org.gnome.SessionManager" @@ -95,59 +92,38 @@ static void display_error(const char* message) } } -static DBusGConnection* get_session_bus(void) -{ - GError* error = NULL; - DBusGConnection* bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); - - if (bus == NULL) - { - g_warning("Couldn't connect to session bus: %s", error->message); - g_error_free(error); - } - - return bus; -} - -static DBusGProxy* create_proxy(DBusGConnection *connection, const char *name, const char *path, const char *iface) +static GDBusProxy* get_sm_proxy(void) { - GError* error = NULL; - DBusGProxy* proxy = dbus_g_proxy_new_for_name_owner(connection, name, path, iface, &error); - - if (proxy == NULL) - { - g_warning("Couldn't create DBus proxy: %s", error->message); - g_error_free(error); - } - - return proxy; -} - -static DBusGProxy* get_sm_proxy(void) -{ - DBusGConnection* connection; - DBusGProxy* sm_proxy; - - connection = get_session_bus(); - - if (connection == NULL) - { - display_error(_("Could not connect to the session manager")); - return NULL; - } - - sm_proxy = create_proxy(connection, GSM_SERVICE_DBUS, GSM_PATH_DBUS, GSM_INTERFACE_DBUS); - + GError *error = NULL; + GDBusProxy *sm_proxy = NULL; + + sm_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + GSM_SERVICE_DBUS, + GSM_PATH_DBUS, + GSM_INTERFACE_DBUS, + NULL, + &error); if (sm_proxy == NULL) { + g_warning ("Couldn't create DBus proxy: %s", error->message); + g_error_free (error); + /* Try the old name - for the case when we've just upgraded from 1.10 * so the old m-s-m is currently running */ - sm_proxy = create_proxy(connection, GSM_SERVICE_DBUS_OLD, GSM_PATH_DBUS_OLD, GSM_INTERFACE_DBUS_OLD); - + sm_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + GSM_SERVICE_DBUS_OLD, + GSM_PATH_DBUS_OLD, + GSM_INTERFACE_DBUS_OLD, + NULL, + NULL); if (sm_proxy == NULL) { /* Okay, it wasn't the upgrade case, so now we can give up. */ - display_error(_("Could not connect to the session manager")); + display_error (_("Could not connect to the session manager")); return NULL; } } @@ -157,11 +133,11 @@ static DBusGProxy* get_sm_proxy(void) static void do_logout(unsigned int mode) { - DBusGProxy* sm_proxy; + GDBusProxy* sm_proxy; GError* error; - gboolean res; + GVariant *ret; - sm_proxy = get_sm_proxy(); + sm_proxy = get_sm_proxy (); if (sm_proxy == NULL) { @@ -169,34 +145,34 @@ static void do_logout(unsigned int mode) } error = NULL; - res = dbus_g_proxy_call(sm_proxy, "Logout", &error, G_TYPE_UINT, mode, G_TYPE_INVALID, G_TYPE_INVALID); - - if (!res) + ret = g_dbus_proxy_call_sync (sm_proxy, "Logout", + g_variant_new ("(u)", mode), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + + if (ret == NULL) { - if (error != NULL) - { - g_warning("Failed to call logout: %s", error->message); - g_error_free(error); - } - else - { - g_warning("Failed to call logout"); - } + g_warning ("Failed to call logout: %s", error->message); + g_error_free (error); + } else { + g_variant_unref (ret); } if (sm_proxy != NULL) { - g_object_unref(sm_proxy); + g_object_unref (sm_proxy); } } static void do_shutdown_dialog(void) { - DBusGProxy* sm_proxy; + GDBusProxy* sm_proxy; GError* error; - gboolean res; + GVariant *ret; - sm_proxy = get_sm_proxy(); + sm_proxy = get_sm_proxy (); if (sm_proxy == NULL) { @@ -204,24 +180,23 @@ static void do_shutdown_dialog(void) } error = NULL; - res = dbus_g_proxy_call(sm_proxy, "Shutdown", &error, G_TYPE_INVALID, G_TYPE_INVALID); - - if (!res) + ret = g_dbus_proxy_call_sync (sm_proxy, "Shutdown", + g_variant_new ("()"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (ret == NULL) { - if (error != NULL) - { - g_warning("Failed to call shutdown: %s", error->message); - g_error_free(error); - } - else - { - g_warning("Failed to call shutdown"); - } + g_warning ("Failed to call shutdown: %s", error->message); + g_error_free (error); + } else { + g_variant_unref (ret); } if (sm_proxy != NULL) { - g_object_unref(sm_proxy); + g_object_unref (sm_proxy); } } |