From a34f531da4f03eecfc38414295ebe70742dfad71 Mon Sep 17 00:00:00 2001 From: yetist Date: Tue, 4 Sep 2018 14:27:45 +0800 Subject: Migrate mate-panel from dbus-glib to gdbus - Code optimization - Put GDBusProxy in PanelSessionManager struct --- applets/clock/set-timezone.c | 188 +++++++------- configure.ac | 7 +- mate-panel/libpanel-util/Makefile.am | 2 - mate-panel/libpanel-util/panel-dbus-service.c | 307 ----------------------- mate-panel/libpanel-util/panel-dbus-service.h | 78 ------ mate-panel/libpanel-util/panel-session-manager.c | 157 +++++------- mate-panel/libpanel-util/panel-session-manager.h | 29 +-- 7 files changed, 159 insertions(+), 609 deletions(-) delete mode 100644 mate-panel/libpanel-util/panel-dbus-service.c delete mode 100644 mate-panel/libpanel-util/panel-dbus-service.h diff --git a/applets/clock/set-timezone.c b/applets/clock/set-timezone.c index fba91894..0df3e24b 100644 --- a/applets/clock/set-timezone.c +++ b/applets/clock/set-timezone.c @@ -28,30 +28,33 @@ #include #include #include - -#include -#include +#include #include "set-timezone.h" +#define DATETIME_DBUS_NAME "org.mate.SettingsDaemon.DateTimeMechanism" +#define DATETIME_DBUS_PATH "/" -static DBusGConnection * -get_system_bus (void) +static GDBusProxy * +get_bus_proxy (void) { - GError *error; - static DBusGConnection *bus = NULL; - - if (bus == NULL) { - error = NULL; - bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); - if (bus == NULL) { - g_warning ("Couldn't connect to system bus: %s", - error->message); - g_error_free (error); + GError *error = NULL; + static GDBusProxy *proxy = NULL; + if (proxy == NULL) { + proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + DATETIME_DBUS_NAME, + DATETIME_DBUS_PATH, + DATETIME_DBUS_NAME, + NULL, + &error); + if (proxy == NULL) { + g_warning ("Unable to contact datetime settings daemon: %s\n", error->message); + g_error_free (error); } - } - - return bus; + } + return proxy; } #define CACHE_VALIDITY_SEC 2 @@ -59,18 +62,25 @@ get_system_bus (void) typedef void (*CanDoFunc) (gint value); static void -notify_can_do (DBusGProxy *proxy, - DBusGProxyCall *call, - void *user_data) +notify_can_do (GObject *source_object, + GAsyncResult *res, + gpointer user_data) { + GDBusProxy *proxy; + GVariant *variant; + GError *error = NULL; + gint32 value; + CanDoFunc callback = user_data; - GError *error = NULL; - gint value; - if (dbus_g_proxy_end_call (proxy, call, - &error, - G_TYPE_INT, &value, - G_TYPE_INVALID)) { + proxy = get_bus_proxy (); + variant = g_dbus_proxy_call_finish (proxy, res, &error); + if (variant == NULL) { + g_warning ("Call can set time zone dbus method: %s", error->message); + g_error_free (error); + } else { + g_variant_get (variant, "(i)", &value); + g_variant_unref (variant); callback (value); } } @@ -78,24 +88,20 @@ notify_can_do (DBusGProxy *proxy, static void refresh_can_do (const gchar *action, CanDoFunc callback) { - DBusGConnection *bus; - DBusGProxy *proxy; - - bus = get_system_bus (); - if (bus == NULL) - return; - - proxy = dbus_g_proxy_new_for_name (bus, - "org.mate.SettingsDaemon.DateTimeMechanism", - "/", - "org.mate.SettingsDaemon.DateTimeMechanism"); - - dbus_g_proxy_begin_call_with_timeout (proxy, - action, - notify_can_do, - callback, NULL, - INT_MAX, - G_TYPE_INVALID); + GDBusProxy *proxy; + + proxy = get_bus_proxy (); + if (proxy == NULL) + return; + + g_dbus_proxy_call (proxy, + action, + g_variant_new ("()"), + G_DBUS_CALL_FLAGS_NONE, + G_MAXINT, + NULL, + notify_can_do, + callback); } static gint settimezone_cache = 0; @@ -171,75 +177,61 @@ free_data (gpointer d) } static void -set_time_notify (DBusGProxy *proxy, - DBusGProxyCall *call, - void *user_data) +set_time_notify (GObject *source_object, + GAsyncResult *res, + gpointer user_data) { - SetTimeCallbackData *data = user_data; - GError *error = NULL; - - if (dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID)) { - if (data->callback) - data->callback (data->data, NULL); - } - else { - if (error->domain == DBUS_GERROR && - error->code == DBUS_GERROR_NO_REPLY) { - /* these errors happen because dbus doesn't - * use monotonic clocks - */ - g_warning ("ignoring no-reply error when setting time"); + SetTimeCallbackData *data = user_data; + GError *error = NULL; + GDBusProxy *proxy; + GVariant *variant; + + proxy = get_bus_proxy (); + variant = g_dbus_proxy_call_finish (proxy, res, &error); + if (variant == NULL) { + if (error != NULL) { + if (data->callback) + data->callback (data->data, error); g_error_free (error); + } else { if (data->callback) data->callback (data->data, NULL); } - else { - if (data->callback) - data->callback (data->data, error); - else - g_error_free (error); - } + } else { + g_variant_unref (variant); + if (data->callback) + data->callback (data->data, NULL); } } static void set_time_async (SetTimeCallbackData *data) { - DBusGConnection *bus; - DBusGProxy *proxy; + GDBusProxy *proxy; - bus = get_system_bus (); - if (bus == NULL) - return; - - proxy = dbus_g_proxy_new_for_name (bus, - "org.mate.SettingsDaemon.DateTimeMechanism", - "/", - "org.mate.SettingsDaemon.DateTimeMechanism"); + proxy = get_bus_proxy (); + if (proxy == NULL) + return; data->ref_count++; if (strcmp (data->call, "SetTime") == 0) - dbus_g_proxy_begin_call_with_timeout (proxy, - "SetTime", - set_time_notify, - data, free_data, - INT_MAX, - /* parameters: */ - G_TYPE_INT64, data->time, - G_TYPE_INVALID, - /* return values: */ - G_TYPE_INVALID); + g_dbus_proxy_call (proxy, + "SetTime", + g_variant_new ("(x)", data->time), + G_DBUS_CALL_FLAGS_NONE, + G_MAXINT, + NULL, + set_time_notify, + data); else - dbus_g_proxy_begin_call_with_timeout (proxy, - "SetTimezone", - set_time_notify, - data, free_data, - INT_MAX, - /* parameters: */ - G_TYPE_STRING, data->filename, - G_TYPE_INVALID, - /* return values: */ - G_TYPE_INVALID); + g_dbus_proxy_call (proxy, + "SetTimezone", + g_variant_new ("(s)", data->filename), + G_DBUS_CALL_FLAGS_NONE, + G_MAXINT, + NULL, + set_time_notify, + data); } void diff --git a/configure.ac b/configure.ac index 5d845983..dd5ff9d9 100644 --- a/configure.ac +++ b/configure.ac @@ -60,7 +60,6 @@ PANGO_REQUIRED=1.15.4 GLIB_REQUIRED=2.50.0 LIBMATE_MENU_REQUIRED=1.21.0 CAIRO_REQUIRED=1.0.0 -DBUS_GLIB_REQUIRED=0.80 DCONF_REQUIRED=0.13.4 LIBRSVG_REQUIRED=2.36.2 GTK_REQUIRED=3.22.0 @@ -72,7 +71,7 @@ dnl pkg-config dependency checks PKG_CHECK_MODULES(EGG_SMCLIENT, ice sm gtk+-3.0) PKG_CHECK_MODULES(GMODULE, gmodule-2.0,[GMODULE_ADD="gmodule-2.0"],[GMODULE_ADD=""]) -PKG_CHECK_MODULES(PANEL, $GMODULE_ADD gdk-pixbuf-2.0 >= $GDK_PIXBUF_REQUIRED pango >= $PANGO_REQUIRED gtk+-3.0 >= $GTK_REQUIRED glib-2.0 >= $GLIB_REQUIRED gio-unix-2.0 >= $GLIB_REQUIRED mate-desktop-2.0 >= $LIBMATE_DESKTOP_REQUIRED gio-2.0 >= $GLIB_REQUIRED libmate-menu >= $LIBMATE_MENU_REQUIRED dbus-glib-1 >= $DBUS_GLIB_REQUIRED) +PKG_CHECK_MODULES(PANEL, $GMODULE_ADD gdk-pixbuf-2.0 >= $GDK_PIXBUF_REQUIRED pango >= $PANGO_REQUIRED gtk+-3.0 >= $GTK_REQUIRED glib-2.0 >= $GLIB_REQUIRED gio-unix-2.0 >= $GLIB_REQUIRED mate-desktop-2.0 >= $LIBMATE_DESKTOP_REQUIRED gio-2.0 >= $GLIB_REQUIRED libmate-menu >= $LIBMATE_MENU_REQUIRED) AC_SUBST(PANEL_CFLAGS) AC_SUBST(PANEL_LIBS) @@ -101,12 +100,10 @@ PKG_CHECK_MODULES(TZ, gio-2.0 >= $GLIB_REQUIRED) AC_SUBST(TZ_CFLAGS) AC_SUBST(TZ_LIBS) -PKG_CHECK_MODULES(CLOCK, pango >= $PANGO_REQUIRED gtk+-3.0 >= $GTK_REQUIRED glib-2.0 >= $GLIB_REQUIRED gio-2.0 >= $GLIB_REQUIRED librsvg-2.0 >= $LIBRSVG_REQUIRED dbus-glib-1 mateweather >= $WEATHER_REQUIRED mate-desktop-2.0 >= $LIBMATE_DESKTOP_REQUIRED) +PKG_CHECK_MODULES(CLOCK, pango >= $PANGO_REQUIRED gtk+-3.0 >= $GTK_REQUIRED glib-2.0 >= $GLIB_REQUIRED gio-2.0 >= $GLIB_REQUIRED librsvg-2.0 >= $LIBRSVG_REQUIRED mateweather >= $WEATHER_REQUIRED mate-desktop-2.0 >= $LIBMATE_DESKTOP_REQUIRED) AC_SUBST(CLOCK_CFLAGS) AC_SUBST(CLOCK_LIBS) -DBUS_REQUIRED=1.1.2 - # Make it possible to compile the applets in-process PANEL_INPROCESS_NONE= PANEL_INPROCESS_ALL= diff --git a/mate-panel/libpanel-util/Makefile.am b/mate-panel/libpanel-util/Makefile.am index ce796e9e..8f7e4d09 100644 --- a/mate-panel/libpanel-util/Makefile.am +++ b/mate-panel/libpanel-util/Makefile.am @@ -14,8 +14,6 @@ AM_CFLAGS = $(WARN_CFLAGS) libpanel_util_la_SOURCES = \ panel-cleanup.c \ panel-cleanup.h \ - panel-dbus-service.c \ - panel-dbus-service.h \ panel-color.c \ panel-color.h \ panel-error.c \ diff --git a/mate-panel/libpanel-util/panel-dbus-service.c b/mate-panel/libpanel-util/panel-dbus-service.c deleted file mode 100644 index 405b8bf0..00000000 --- a/mate-panel/libpanel-util/panel-dbus-service.c +++ /dev/null @@ -1,307 +0,0 @@ -/* - * panel-dbus-service.c: a simple base object to use a DBus service. Only - * useful when subclassed. - * - * Copyright (C) 2008 Novell, Inc. - * - * Based on code from panel-power-manager.c: - * Copyright (C) 2006 Ray Strode - * (not sure the copyright header was complete) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * Authors: - * Vincent Untz - */ - -#include - -#include -#include - -#include - -#include "panel-dbus-service.h" - -struct _PanelDBusServicePrivate { - DBusGConnection *dbus_connection; - DBusGProxy *bus_proxy; - DBusGProxy *service_proxy; - guint32 is_connected : 1; - - const char *service_name; - const char *service_path; - const char *service_interface; -}; - -static void panel_dbus_service_finalize (GObject *object); -static void panel_dbus_service_class_install_properties (PanelDBusServiceClass *service_class); - -static void panel_dbus_service_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); - -enum { - PROP_0 = 0, - PROP_IS_CONNECTED -}; - -G_DEFINE_TYPE (PanelDBusService, panel_dbus_service, G_TYPE_OBJECT); - -static void -panel_dbus_service_class_init (PanelDBusServiceClass *service_class) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (service_class); - - object_class->finalize = panel_dbus_service_finalize; - - panel_dbus_service_class_install_properties (service_class); - - g_type_class_add_private (service_class, - sizeof (PanelDBusServicePrivate)); -} - -static void -panel_dbus_service_class_install_properties (PanelDBusServiceClass *service_class) -{ - GObjectClass *object_class; - GParamSpec *param_spec; - - object_class = G_OBJECT_CLASS (service_class); - object_class->get_property = panel_dbus_service_get_property; - - param_spec = g_param_spec_boolean ("is-connected", - "Is connected", - "Whether the panel is connected to " - "a DBus service", - FALSE, - G_PARAM_READABLE); - g_object_class_install_property (object_class, PROP_IS_CONNECTED, - param_spec); -} - -static void -panel_dbus_service_init (PanelDBusService *service) -{ - service->priv = G_TYPE_INSTANCE_GET_PRIVATE (service, - PANEL_TYPE_DBUS_SERVICE, - PanelDBusServicePrivate); - - service->priv->dbus_connection = NULL; - service->priv->bus_proxy = NULL; - service->priv->service_proxy = NULL; - service->priv->is_connected = FALSE; - - service->priv->service_name = NULL; - service->priv->service_path = NULL; - service->priv->service_interface = NULL; -} - -static void -panel_dbus_service_finalize (GObject *object) -{ - PanelDBusService *service; - - service = PANEL_DBUS_SERVICE (object); - - if (service->priv->dbus_connection != NULL) { - dbus_g_connection_unref (service->priv->dbus_connection); - service->priv->dbus_connection = NULL; - } - - if (service->priv->bus_proxy != NULL) { - g_object_unref (service->priv->bus_proxy); - service->priv->bus_proxy = NULL; - } - - if (service->priv->service_proxy != NULL) { - g_object_unref (service->priv->service_proxy); - service->priv->service_proxy = NULL; - } - - G_OBJECT_CLASS (panel_dbus_service_parent_class)->finalize (object); -} - -static void -panel_dbus_service_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - PanelDBusService *service; - - service = PANEL_DBUS_SERVICE (object); - - switch (prop_id) { - case PROP_IS_CONNECTED: - g_value_set_boolean (value, - service->priv->is_connected); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, - prop_id, - pspec); - } -} - -static void -panel_dbus_service_on_name_owner_changed (DBusGProxy *bus_proxy, - const char *name, - const char *prev_owner, - const char *new_owner, - PanelDBusService *service) -{ - g_assert (service->priv->service_name != NULL); - - if (name && strcmp (name, service->priv->service_name) != 0) - return; - - if (service->priv->service_proxy != NULL) { - g_object_unref (service->priv->service_proxy); - service->priv->service_proxy = NULL; - } - - panel_dbus_service_ensure_connection (service, NULL); -} - -gboolean -panel_dbus_service_ensure_connection (PanelDBusService *service, - GError **error) -{ - GError *connection_error; - gboolean is_connected; - - g_return_val_if_fail (PANEL_IS_DBUS_SERVICE (service), FALSE); - - if (!service->priv->service_name || - !service->priv->service_path || - !service->priv->service_interface) - return FALSE; - - connection_error = NULL; - if (service->priv->dbus_connection == NULL) { - service->priv->dbus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, - &connection_error); - - if (service->priv->dbus_connection == NULL) { - g_propagate_error (error, connection_error); - is_connected = FALSE; - goto out; - } - } - - if (service->priv->bus_proxy == NULL) { - service->priv->bus_proxy = - dbus_g_proxy_new_for_name_owner (service->priv->dbus_connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS, - &connection_error); - - if (service->priv->bus_proxy == NULL) { - g_propagate_error (error, connection_error); - is_connected = FALSE; - goto out; - } - - dbus_g_proxy_add_signal (service->priv->bus_proxy, - "NameOwnerChanged", - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_INVALID); - dbus_g_proxy_connect_signal (service->priv->bus_proxy, - "NameOwnerChanged", - G_CALLBACK (panel_dbus_service_on_name_owner_changed), - service, NULL); - } - - if (service->priv->service_proxy == NULL) { - service->priv->service_proxy = - dbus_g_proxy_new_for_name_owner ( - service->priv->dbus_connection, - service->priv->service_name, - service->priv->service_path, - service->priv->service_interface, - &connection_error); - - if (service->priv->service_proxy == NULL) { - g_propagate_error (error, connection_error); - is_connected = FALSE; - goto out; - } - } - is_connected = TRUE; - -out: - if (service->priv->is_connected != is_connected) { - service->priv->is_connected = is_connected; - g_object_notify (G_OBJECT (service), "is-connected"); - } - - if (!is_connected) { - if (service->priv->dbus_connection == NULL) { - if (service->priv->bus_proxy != NULL) { - g_object_unref (service->priv->bus_proxy); - service->priv->bus_proxy = NULL; - } - - if (service->priv->service_proxy != NULL) { - g_object_unref (service->priv->service_proxy); - service->priv->service_proxy = NULL; - } - } else if (service->priv->bus_proxy == NULL) { - if (service->priv->service_proxy != NULL) { - g_object_unref (service->priv->service_proxy); - service->priv->service_proxy = NULL; - } - } - } - - return is_connected; -} - -void -panel_dbus_service_define_service (PanelDBusService *service, - const char *name, - const char *path, - const char *interface) -{ - g_return_if_fail (PANEL_IS_DBUS_SERVICE (service)); - - g_assert (name != NULL); - g_assert (path != NULL); - g_assert (interface != NULL); - g_assert (service->priv->service_name == NULL); - g_assert (service->priv->service_path == NULL); - g_assert (service->priv->service_interface == NULL); - - service->priv->service_name = name; - service->priv->service_path = path; - service->priv->service_interface = interface; -} - -DBusGProxy * -panel_dbus_service_get_proxy (PanelDBusService *service) -{ - g_return_val_if_fail (PANEL_IS_DBUS_SERVICE (service), NULL); - - return service->priv->service_proxy; -} diff --git a/mate-panel/libpanel-util/panel-dbus-service.h b/mate-panel/libpanel-util/panel-dbus-service.h deleted file mode 100644 index 3d488a71..00000000 --- a/mate-panel/libpanel-util/panel-dbus-service.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * panel-dbus-service.h: a simple base object to use a DBus service. Only - * useful when subclassed. - * - * Copyright (C) 2008 Novell, Inc. - * - * Based on code from panel-power-manager.h: - * Copyright (C) 2006 Ray Strode - * (not sure the copyright header was complete) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301, USA. - * - * Authors: - * Vincent Untz - */ - -#ifndef PANEL_DBUS_SERVICE_H -#define PANEL_DBUS_SERVICE_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define PANEL_TYPE_DBUS_SERVICE (panel_dbus_service_get_type ()) -#define PANEL_DBUS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PANEL_TYPE_DBUS_SERVICE, PanelDBusService)) -#define PANEL_DBUS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANEL_TYPE_DBUS_SERVICE, PanelDBusServiceClass)) -#define PANEL_IS_DBUS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PANEL_TYPE_DBUS_SERVICE)) -#define PANEL_IS_DBUS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANEL_TYPE_DBUS_SERVICE)) -#define PANEL_DBUS_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PANEL_TYPE_DBUS_SERVICE, PanelDBusServiceClass)) - -typedef struct _PanelDBusService PanelDBusService; -typedef struct _PanelDBusServiceClass PanelDBusServiceClass; -typedef struct _PanelDBusServicePrivate PanelDBusServicePrivate; - -struct _PanelDBusService { - GObject parent; - - /*< private > */ - PanelDBusServicePrivate *priv; -}; - -struct _PanelDBusServiceClass { - GObjectClass parent_class; -}; - -GType panel_dbus_service_get_type (void); - -void panel_dbus_service_define_service (PanelDBusService *service, - const char *name, - const char *path, - const char *interface); - -gboolean panel_dbus_service_ensure_connection (PanelDBusService *service, - GError **error); - -DBusGProxy *panel_dbus_service_get_proxy (PanelDBusService *service); - -#ifdef __cplusplus -} -#endif - -#endif /* PANEL_DBUS_SERVICE_H */ diff --git a/mate-panel/libpanel-util/panel-session-manager.c b/mate-panel/libpanel-util/panel-session-manager.c index 65a1e330..191ca2dd 100644 --- a/mate-panel/libpanel-util/panel-session-manager.c +++ b/mate-panel/libpanel-util/panel-session-manager.c @@ -22,18 +22,27 @@ * Vincent Untz */ -#include - +#include #include "panel-cleanup.h" -#include "panel-dbus-service.h" - #include "panel-session-manager.h" -static GObject *panel_session_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties); +struct _PanelSessionManager { + GObject parent; + GDBusProxy *proxy; +}; + +G_DEFINE_TYPE (PanelSessionManager, panel_session_manager, G_TYPE_OBJECT) + +static void +panel_session_manager_finalize (GObject *object) +{ + PanelSessionManager *manager = PANEL_SESSION_MANAGER (object); + + if (manager->proxy != NULL) + g_object_unref (manager->proxy); -G_DEFINE_TYPE (PanelSessionManager, panel_session_manager, PANEL_TYPE_DBUS_SERVICE); + G_OBJECT_CLASS (panel_session_manager_parent_class)->finalize (object); +} static void panel_session_manager_class_init (PanelSessionManagerClass *klass) @@ -42,136 +51,98 @@ panel_session_manager_class_init (PanelSessionManagerClass *klass) object_class = G_OBJECT_CLASS (klass); - object_class->constructor = panel_session_manager_constructor; + object_class->finalize = panel_session_manager_finalize; } static void panel_session_manager_init (PanelSessionManager *manager) { -} - -static GObject * -panel_session_manager_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) -{ - GObject *obj; - GError *error; - - obj = G_OBJECT_CLASS (panel_session_manager_parent_class)->constructor ( - type, - n_construct_properties, - construct_properties); - - - panel_dbus_service_define_service (PANEL_DBUS_SERVICE (obj), - "org.gnome.SessionManager", - "/org/gnome/SessionManager", - "org.gnome.SessionManager"); - - error = NULL; - if (!panel_dbus_service_ensure_connection (PANEL_DBUS_SERVICE (obj), - &error)) { - g_message ("Could not connect to session manager: %s", - error->message); + GError *error = NULL; + + manager->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.gnome.SessionManager", + "/org/gnome/SessionManager", + "org.gnome.SessionManager", + NULL, + &error); + if (manager->proxy == NULL) { + g_warning ("Unable to contact session manager daemon: %s\n", error->message); g_error_free (error); } - - return obj; } void panel_session_manager_request_logout (PanelSessionManager *manager, PanelSessionManagerLogoutType mode) { - GError *error; - DBusGProxy *proxy; + GError *error = NULL; + GVariant *ret; g_return_if_fail (PANEL_IS_SESSION_MANAGER (manager)); - error = NULL; - - if (!panel_dbus_service_ensure_connection (PANEL_DBUS_SERVICE (manager), - &error)) { - g_warning ("Could not connect to session manager: %s", - error->message); - g_error_free (error); - return; - } - - proxy = panel_dbus_service_get_proxy (PANEL_DBUS_SERVICE (manager)); - - if (!dbus_g_proxy_call (proxy, "Logout", &error, - G_TYPE_UINT, mode, G_TYPE_INVALID, - G_TYPE_INVALID) && - error != NULL) { + ret = g_dbus_proxy_call_sync (manager->proxy, "Logout", + g_variant_new ("(u)", mode), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (ret == NULL) { g_warning ("Could not ask session manager to log out: %s", error->message); g_error_free (error); + } else { + g_variant_unref (ret); } } void panel_session_manager_request_shutdown (PanelSessionManager *manager) { - GError *error; - DBusGProxy *proxy; + GError *error = NULL; + GVariant *ret; g_return_if_fail (PANEL_IS_SESSION_MANAGER (manager)); - error = NULL; - - if (!panel_dbus_service_ensure_connection (PANEL_DBUS_SERVICE (manager), - &error)) { - g_warning ("Could not connect to session manager: %s", - error->message); - g_error_free (error); - return; - } - - proxy = panel_dbus_service_get_proxy (PANEL_DBUS_SERVICE (manager)); - - if (!dbus_g_proxy_call (proxy, "Shutdown", &error, - G_TYPE_INVALID, - G_TYPE_INVALID) && - error != NULL) { + ret = g_dbus_proxy_call_sync (manager->proxy, "Shutdown", + g_variant_new ("()"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (ret == NULL) { g_warning ("Could not ask session manager to shut down: %s", error->message); g_error_free (error); + } else { + g_variant_unref (ret); } } gboolean panel_session_manager_is_shutdown_available (PanelSessionManager *manager) { - GError *error; - DBusGProxy *proxy; + GError *error = NULL; gboolean is_shutdown_available; + GVariant *ret; g_return_val_if_fail (PANEL_IS_SESSION_MANAGER (manager), FALSE); - error = NULL; - - if (!panel_dbus_service_ensure_connection (PANEL_DBUS_SERVICE (manager), - &error)) { - g_warning ("Could not connect to session manager: %s", - error->message); - g_error_free (error); - - return FALSE; - } - - proxy = panel_dbus_service_get_proxy (PANEL_DBUS_SERVICE (manager)); - - if (!dbus_g_proxy_call (proxy, "CanShutdown", &error, - G_TYPE_INVALID, G_TYPE_BOOLEAN, - &is_shutdown_available, G_TYPE_INVALID) && - error != NULL) { + ret = g_dbus_proxy_call_sync (manager->proxy, "CanShutdown", + g_variant_new ("()"), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (ret == NULL) { g_warning ("Could not ask session manager if shut down is available: %s", error->message); g_error_free (error); - return FALSE; + } else { + g_variant_get (ret, "(b)", &is_shutdown_available); + g_variant_unref (ret); } return is_shutdown_available; diff --git a/mate-panel/libpanel-util/panel-session-manager.h b/mate-panel/libpanel-util/panel-session-manager.h index 1e1d8fc5..98d09c94 100644 --- a/mate-panel/libpanel-util/panel-session-manager.h +++ b/mate-panel/libpanel-util/panel-session-manager.h @@ -27,31 +27,10 @@ #include -#include "panel-dbus-service.h" - -#ifdef __cplusplus -extern "C" { -#endif +G_BEGIN_DECLS #define PANEL_TYPE_SESSION_MANAGER (panel_session_manager_get_type ()) -#define PANEL_SESSION_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PANEL_TYPE_SESSION_MANAGER, PanelSessionManager)) -#define PANEL_SESSION_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PANEL_TYPE_SESSION_MANAGER, PanelSessionManagerClass)) -#define PANEL_IS_SESSION_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PANEL_TYPE_SESSION_MANAGER)) -#define PANEL_IS_SESSION_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANEL_TYPE_SESSION_MANAGER)) -#define PANEL_SESSION_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PANEL_TYPE_SESSION_MANAGER, PanelSessionManagerClass)) - -typedef struct _PanelSessionManager PanelSessionManager; -typedef struct _PanelSessionManagerClass PanelSessionManagerClass; - -struct _PanelSessionManager { - PanelDBusService parent; -}; - -struct _PanelSessionManagerClass { - PanelDBusServiceClass parent_class; -}; - -GType panel_session_manager_get_type (void); +G_DECLARE_FINAL_TYPE (PanelSessionManager, panel_session_manager, PANEL, SESSION_MANAGER, GObject); /* Keep in sync with the values defined in mate-session/session.h */ typedef enum { @@ -68,8 +47,6 @@ void panel_session_manager_request_shutdown (PanelSessionManager *session); gboolean panel_session_manager_is_shutdown_available (PanelSessionManager *session); -#ifdef __cplusplus -} -#endif +G_END_DECLS #endif /* PANEL_SESSION_MANAGER_H */ -- cgit v1.2.1