Skip to content

Commit a34f531

Browse files
yetistraveit65
authored andcommitted
Migrate mate-panel from dbus-glib to gdbus
- Code optimization - Put GDBusProxy in PanelSessionManager struct
1 parent a73abb8 commit a34f531

File tree

7 files changed

+159
-609
lines changed

7 files changed

+159
-609
lines changed

‎applets/clock/set-timezone.c‎

Lines changed: 90 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -28,74 +28,80 @@
2828
#include <unistd.h>
2929
#include <string.h>
3030
#include <sys/wait.h>
31-
32-
#include <dbus/dbus-glib.h>
33-
#include <dbus/dbus-glib-lowlevel.h>
31+
#include <gio/gio.h>
3432

3533
#include "set-timezone.h"
3634

35+
#define DATETIME_DBUS_NAME "org.mate.SettingsDaemon.DateTimeMechanism"
36+
#define DATETIME_DBUS_PATH "/"
3737

38-
static DBusGConnection *
39-
get_system_bus (void)
38+
static GDBusProxy *
39+
get_bus_proxy (void)
4040
{
41-
GError *error;
42-
static DBusGConnection *bus = NULL;
43-
44-
if (bus == NULL) {
45-
error = NULL;
46-
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
47-
if (bus == NULL) {
48-
g_warning ("Couldn't connect to system bus: %s",
49-
error->message);
50-
g_error_free (error);
41+
GError *error = NULL;
42+
static GDBusProxy *proxy = NULL;
43+
if (proxy == NULL) {
44+
proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
45+
G_DBUS_PROXY_FLAGS_NONE,
46+
NULL,
47+
DATETIME_DBUS_NAME,
48+
DATETIME_DBUS_PATH,
49+
DATETIME_DBUS_NAME,
50+
NULL,
51+
&error);
52+
if (proxy == NULL) {
53+
g_warning ("Unable to contact datetime settings daemon: %s\n", error->message);
54+
g_error_free (error);
5155
}
52-
}
53-
54-
return bus;
56+
}
57+
return proxy;
5558
}
5659

5760
#define CACHE_VALIDITY_SEC 2
5861

5962
typedef void (*CanDoFunc) (gint value);
6063

6164
static void
62-
notify_can_do (DBusGProxy *proxy,
63-
DBusGProxyCall *call,
64-
void *user_data)
65+
notify_can_do (GObject *source_object,
66+
GAsyncResult *res,
67+
gpointer user_data)
6568
{
69+
GDBusProxy *proxy;
70+
GVariant *variant;
71+
GError *error = NULL;
72+
gint32 value;
73+
6674
CanDoFunc callback = user_data;
67-
GError *error = NULL;
68-
gint value;
6975

70-
if (dbus_g_proxy_end_call (proxy, call,
71-
&error,
72-
G_TYPE_INT, &value,
73-
G_TYPE_INVALID)) {
76+
proxy = get_bus_proxy ();
77+
variant = g_dbus_proxy_call_finish (proxy, res, &error);
78+
if (variant == NULL) {
79+
g_warning ("Call can set time zone dbus method: %s", error->message);
80+
g_error_free (error);
81+
} else {
82+
g_variant_get (variant, "(i)", &value);
83+
g_variant_unref (variant);
7484
callback (value);
7585
}
7686
}
7787

7888
static void
7989
refresh_can_do (const gchar *action, CanDoFunc callback)
8090
{
81-
DBusGConnection *bus;
82-
DBusGProxy *proxy;
83-
84-
bus = get_system_bus ();
85-
if (bus == NULL)
86-
return;
87-
88-
proxy = dbus_g_proxy_new_for_name (bus,
89-
"org.mate.SettingsDaemon.DateTimeMechanism",
90-
"/",
91-
"org.mate.SettingsDaemon.DateTimeMechanism");
92-
93-
dbus_g_proxy_begin_call_with_timeout (proxy,
94-
action,
95-
notify_can_do,
96-
callback, NULL,
97-
INT_MAX,
98-
G_TYPE_INVALID);
91+
GDBusProxy *proxy;
92+
93+
proxy = get_bus_proxy ();
94+
if (proxy == NULL)
95+
return;
96+
97+
g_dbus_proxy_call (proxy,
98+
action,
99+
g_variant_new ("()"),
100+
G_DBUS_CALL_FLAGS_NONE,
101+
G_MAXINT,
102+
NULL,
103+
notify_can_do,
104+
callback);
99105
}
100106

101107
static gint settimezone_cache = 0;
@@ -171,75 +177,61 @@ free_data (gpointer d)
171177
}
172178

173179
static void
174-
set_time_notify (DBusGProxy *proxy,
175-
DBusGProxyCall *call,
176-
void *user_data)
180+
set_time_notify (GObject *source_object,
181+
GAsyncResult *res,
182+
gpointer user_data)
177183
{
178-
SetTimeCallbackData *data = user_data;
179-
GError *error = NULL;
180-
181-
if (dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID)) {
182-
if (data->callback)
183-
data->callback (data->data, NULL);
184-
}
185-
else {
186-
if (error->domain == DBUS_GERROR &&
187-
error->code == DBUS_GERROR_NO_REPLY) {
188-
/* these errors happen because dbus doesn't
189-
* use monotonic clocks
190-
*/
191-
g_warning ("ignoring no-reply error when setting time");
184+
SetTimeCallbackData *data = user_data;
185+
GError *error = NULL;
186+
GDBusProxy *proxy;
187+
GVariant *variant;
188+
189+
proxy = get_bus_proxy ();
190+
variant = g_dbus_proxy_call_finish (proxy, res, &error);
191+
if (variant == NULL) {
192+
if (error != NULL) {
193+
if (data->callback)
194+
data->callback (data->data, error);
192195
g_error_free (error);
196+
} else {
193197
if (data->callback)
194198
data->callback (data->data, NULL);
195199
}
196-
else {
197-
if (data->callback)
198-
data->callback (data->data, error);
199-
else
200-
g_error_free (error);
201-
}
200+
} else {
201+
g_variant_unref (variant);
202+
if (data->callback)
203+
data->callback (data->data, NULL);
202204
}
203205
}
204206

205207
static void
206208
set_time_async (SetTimeCallbackData *data)
207209
{
208-
DBusGConnection *bus;
209-
DBusGProxy *proxy;
210+
GDBusProxy *proxy;
210211

211-
bus = get_system_bus ();
212-
if (bus == NULL)
213-
return;
214-
215-
proxy = dbus_g_proxy_new_for_name (bus,
216-
"org.mate.SettingsDaemon.DateTimeMechanism",
217-
"/",
218-
"org.mate.SettingsDaemon.DateTimeMechanism");
212+
proxy = get_bus_proxy ();
213+
if (proxy == NULL)
214+
return;
219215

220216
data->ref_count++;
221217
if (strcmp (data->call, "SetTime") == 0)
222-
dbus_g_proxy_begin_call_with_timeout (proxy,
223-
"SetTime",
224-
set_time_notify,
225-
data, free_data,
226-
INT_MAX,
227-
/* parameters: */
228-
G_TYPE_INT64, data->time,
229-
G_TYPE_INVALID,
230-
/* return values: */
231-
G_TYPE_INVALID);
218+
g_dbus_proxy_call (proxy,
219+
"SetTime",
220+
g_variant_new ("(x)", data->time),
221+
G_DBUS_CALL_FLAGS_NONE,
222+
G_MAXINT,
223+
NULL,
224+
set_time_notify,
225+
data);
232226
else
233-
dbus_g_proxy_begin_call_with_timeout (proxy,
234-
"SetTimezone",
235-
set_time_notify,
236-
data, free_data,
237-
INT_MAX,
238-
/* parameters: */
239-
G_TYPE_STRING, data->filename,
240-
G_TYPE_INVALID,
241-
/* return values: */
242-
G_TYPE_INVALID);
227+
g_dbus_proxy_call (proxy,
228+
"SetTimezone",
229+
g_variant_new ("(s)", data->filename),
230+
G_DBUS_CALL_FLAGS_NONE,
231+
G_MAXINT,
232+
NULL,
233+
set_time_notify,
234+
data);
243235
}
244236

245237
void

‎configure.ac‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ PANGO_REQUIRED=1.15.4
6060
GLIB_REQUIRED=2.50.0
6161
LIBMATE_MENU_REQUIRED=1.21.0
6262
CAIRO_REQUIRED=1.0.0
63-
DBUS_GLIB_REQUIRED=0.80
6463
DCONF_REQUIRED=0.13.4
6564
LIBRSVG_REQUIRED=2.36.2
6665
GTK_REQUIRED=3.22.0
@@ -72,7 +71,7 @@ dnl pkg-config dependency checks
7271
PKG_CHECK_MODULES(EGG_SMCLIENT, ice sm gtk+-3.0)
7372

7473
PKG_CHECK_MODULES(GMODULE, gmodule-2.0,[GMODULE_ADD="gmodule-2.0"],[GMODULE_ADD=""])
75-
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)
74+
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)
7675
AC_SUBST(PANEL_CFLAGS)
7776
AC_SUBST(PANEL_LIBS)
7877

@@ -101,12 +100,10 @@ PKG_CHECK_MODULES(TZ, gio-2.0 >= $GLIB_REQUIRED)
101100
AC_SUBST(TZ_CFLAGS)
102101
AC_SUBST(TZ_LIBS)
103102

104-
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)
103+
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)
105104
AC_SUBST(CLOCK_CFLAGS)
106105
AC_SUBST(CLOCK_LIBS)
107106

108-
DBUS_REQUIRED=1.1.2
109-
110107
# Make it possible to compile the applets in-process
111108
PANEL_INPROCESS_NONE=
112109
PANEL_INPROCESS_ALL=

‎mate-panel/libpanel-util/Makefile.am‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ AM_CFLAGS = $(WARN_CFLAGS)
1414
libpanel_util_la_SOURCES = \
1515
panel-cleanup.c \
1616
panel-cleanup.h \
17-
panel-dbus-service.c \
18-
panel-dbus-service.h \
1917
panel-color.c \
2018
panel-color.h \
2119
panel-error.c \

0 commit comments

Comments
 (0)