Skip to content

Commit 413050e

Browse files
yetistmonsta
authored andcommitted
Migrate from dbus-glib to gdbus
- tools/Makefile.am - tools/mate-session-save.c
1 parent f20dad8 commit 413050e

File tree

2 files changed

+56
-83
lines changed

2 files changed

+56
-83
lines changed

‎tools/Makefile.am‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ bin_PROGRAMS = mate-session-save mate-session-inhibit
22

33
AM_CPPFLAGS = \
44
$(MATE_SESSION_CFLAGS) \
5-
$(DBUS_GLIB_CFLAGS) \
65
-DLOCALE_DIR=\""$(datadir)/locale"\" \
76
$(DISABLE_DEPRECATED_CFLAGS)
87

@@ -14,8 +13,7 @@ mate_session_save_SOURCES = \
1413
mate_session_save_LDADD = \
1514
$(SM_LIBS) \
1615
$(ICE_LIBS) \
17-
$(MATE_SESSION_LIBS) \
18-
$(DBUS_GLIB_LIBS)
16+
$(MATE_SESSION_LIBS)
1917

2018
mate_session_inhibit_SOURCES = \
2119
mate-session-inhibit.c

‎tools/mate-session-save.c‎

Lines changed: 55 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
#include <glib/gi18n.h>
3131
#include <gtk/gtk.h>
3232

33-
#include <dbus/dbus-glib.h>
34-
#include <dbus/dbus-glib-lowlevel.h>
35-
3633
#define GSM_SERVICE_DBUS "org.gnome.SessionManager"
3734
#define GSM_PATH_DBUS "/org/gnome/SessionManager"
3835
#define GSM_INTERFACE_DBUS "org.gnome.SessionManager"
@@ -95,59 +92,38 @@ static void display_error(const char* message)
9592
}
9693
}
9794

98-
static DBusGConnection* get_session_bus(void)
99-
{
100-
GError* error = NULL;
101-
DBusGConnection* bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
102-
103-
if (bus == NULL)
104-
{
105-
g_warning("Couldn't connect to session bus: %s", error->message);
106-
g_error_free(error);
107-
}
108-
109-
return bus;
110-
}
111-
112-
static DBusGProxy* create_proxy(DBusGConnection *connection, const char *name, const char *path, const char *iface)
95+
static GDBusProxy* get_sm_proxy(void)
11396
{
114-
GError* error = NULL;
115-
DBusGProxy* proxy = dbus_g_proxy_new_for_name_owner(connection, name, path, iface, &error);
116-
117-
if (proxy == NULL)
118-
{
119-
g_warning("Couldn't create DBus proxy: %s", error->message);
120-
g_error_free(error);
121-
}
122-
123-
return proxy;
124-
}
125-
126-
static DBusGProxy* get_sm_proxy(void)
127-
{
128-
DBusGConnection* connection;
129-
DBusGProxy* sm_proxy;
130-
131-
connection = get_session_bus();
132-
133-
if (connection == NULL)
134-
{
135-
display_error(_("Could not connect to the session manager"));
136-
return NULL;
137-
}
138-
139-
sm_proxy = create_proxy(connection, GSM_SERVICE_DBUS, GSM_PATH_DBUS, GSM_INTERFACE_DBUS);
140-
97+
GError *error = NULL;
98+
GDBusProxy *sm_proxy = NULL;
99+
100+
sm_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
101+
G_DBUS_PROXY_FLAGS_NONE,
102+
NULL,
103+
GSM_SERVICE_DBUS,
104+
GSM_PATH_DBUS,
105+
GSM_INTERFACE_DBUS,
106+
NULL,
107+
&error);
141108
if (sm_proxy == NULL)
142109
{
110+
g_warning ("Couldn't create DBus proxy: %s", error->message);
111+
g_error_free (error);
112+
143113
/* Try the old name - for the case when we've just upgraded from 1.10
144114
* so the old m-s-m is currently running */
145-
sm_proxy = create_proxy(connection, GSM_SERVICE_DBUS_OLD, GSM_PATH_DBUS_OLD, GSM_INTERFACE_DBUS_OLD);
146-
115+
sm_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
116+
G_DBUS_PROXY_FLAGS_NONE,
117+
NULL,
118+
GSM_SERVICE_DBUS_OLD,
119+
GSM_PATH_DBUS_OLD,
120+
GSM_INTERFACE_DBUS_OLD,
121+
NULL,
122+
NULL);
147123
if (sm_proxy == NULL)
148124
{
149125
/* Okay, it wasn't the upgrade case, so now we can give up. */
150-
display_error(_("Could not connect to the session manager"));
126+
display_error (_("Could not connect to the session manager"));
151127
return NULL;
152128
}
153129
}
@@ -157,71 +133,70 @@ static DBusGProxy* get_sm_proxy(void)
157133

158134
static void do_logout(unsigned int mode)
159135
{
160-
DBusGProxy* sm_proxy;
136+
GDBusProxy* sm_proxy;
161137
GError* error;
162-
gboolean res;
138+
GVariant *ret;
163139

164-
sm_proxy = get_sm_proxy();
140+
sm_proxy = get_sm_proxy ();
165141

166142
if (sm_proxy == NULL)
167143
{
168144
return;
169145
}
170146

171147
error = NULL;
172-
res = dbus_g_proxy_call(sm_proxy, "Logout", &error, G_TYPE_UINT, mode, G_TYPE_INVALID, G_TYPE_INVALID);
173-
174-
if (!res)
148+
ret = g_dbus_proxy_call_sync (sm_proxy, "Logout",
149+
g_variant_new ("(u)", mode),
150+
G_DBUS_CALL_FLAGS_NONE,
151+
-1,
152+
NULL,
153+
&error);
154+
155+
if (ret == NULL)
175156
{
176-
if (error != NULL)
177-
{
178-
g_warning("Failed to call logout: %s", error->message);
179-
g_error_free(error);
180-
}
181-
else
182-
{
183-
g_warning("Failed to call logout");
184-
}
157+
g_warning ("Failed to call logout: %s", error->message);
158+
g_error_free (error);
159+
} else {
160+
g_variant_unref (ret);
185161
}
186162

187163
if (sm_proxy != NULL)
188164
{
189-
g_object_unref(sm_proxy);
165+
g_object_unref (sm_proxy);
190166
}
191167
}
192168

193169
static void do_shutdown_dialog(void)
194170
{
195-
DBusGProxy* sm_proxy;
171+
GDBusProxy* sm_proxy;
196172
GError* error;
197-
gboolean res;
173+
GVariant *ret;
198174

199-
sm_proxy = get_sm_proxy();
175+
sm_proxy = get_sm_proxy ();
200176

201177
if (sm_proxy == NULL)
202178
{
203179
return;
204180
}
205181

206182
error = NULL;
207-
res = dbus_g_proxy_call(sm_proxy, "Shutdown", &error, G_TYPE_INVALID, G_TYPE_INVALID);
208-
209-
if (!res)
183+
ret = g_dbus_proxy_call_sync (sm_proxy, "Shutdown",
184+
g_variant_new ("()"),
185+
G_DBUS_CALL_FLAGS_NONE,
186+
-1,
187+
NULL,
188+
&error);
189+
if (ret == NULL)
210190
{
211-
if (error != NULL)
212-
{
213-
g_warning("Failed to call shutdown: %s", error->message);
214-
g_error_free(error);
215-
}
216-
else
217-
{
218-
g_warning("Failed to call shutdown");
219-
}
191+
g_warning ("Failed to call shutdown: %s", error->message);
192+
g_error_free (error);
193+
} else {
194+
g_variant_unref (ret);
220195
}
221196

222197
if (sm_proxy != NULL)
223198
{
224-
g_object_unref(sm_proxy);
199+
g_object_unref (sm_proxy);
225200
}
226201
}
227202

0 commit comments

Comments
 (0)