|
28 | 28 | #include <unistd.h> |
29 | 29 | #include <string.h> |
30 | 30 | #include <sys/wait.h> |
31 | | - |
32 | | -#include <dbus/dbus-glib.h> |
33 | | -#include <dbus/dbus-glib-lowlevel.h> |
| 31 | +#include <gio/gio.h> |
34 | 32 |
|
35 | 33 | #include "set-timezone.h" |
36 | 34 |
|
| 35 | +#define DATETIME_DBUS_NAME "org.mate.SettingsDaemon.DateTimeMechanism" |
| 36 | +#define DATETIME_DBUS_PATH "/" |
37 | 37 |
|
38 | | -static DBusGConnection * |
39 | | -get_system_bus (void) |
| 38 | +static GDBusProxy * |
| 39 | +get_bus_proxy (void) |
40 | 40 | { |
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); |
51 | 55 | } |
52 | | - } |
53 | | - |
54 | | - return bus; |
| 56 | + } |
| 57 | + return proxy; |
55 | 58 | } |
56 | 59 |
|
57 | 60 | #define CACHE_VALIDITY_SEC 2 |
58 | 61 |
|
59 | 62 | typedef void (*CanDoFunc) (gint value); |
60 | 63 |
|
61 | 64 | 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) |
65 | 68 | { |
| 69 | + GDBusProxy *proxy; |
| 70 | + GVariant *variant; |
| 71 | + GError *error = NULL; |
| 72 | + gint32 value; |
| 73 | + |
66 | 74 | CanDoFunc callback = user_data; |
67 | | - GError *error = NULL; |
68 | | - gint value; |
69 | 75 |
|
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); |
74 | 84 | callback (value); |
75 | 85 | } |
76 | 86 | } |
77 | 87 |
|
78 | 88 | static void |
79 | 89 | refresh_can_do (const gchar *action, CanDoFunc callback) |
80 | 90 | { |
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); |
99 | 105 | } |
100 | 106 |
|
101 | 107 | static gint settimezone_cache = 0; |
@@ -171,75 +177,61 @@ free_data (gpointer d) |
171 | 177 | } |
172 | 178 |
|
173 | 179 | 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) |
177 | 183 | { |
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); |
192 | 195 | g_error_free (error); |
| 196 | + } else { |
193 | 197 | if (data->callback) |
194 | 198 | data->callback (data->data, NULL); |
195 | 199 | } |
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); |
202 | 204 | } |
203 | 205 | } |
204 | 206 |
|
205 | 207 | static void |
206 | 208 | set_time_async (SetTimeCallbackData *data) |
207 | 209 | { |
208 | | - DBusGConnection *bus; |
209 | | - DBusGProxy *proxy; |
| 210 | + GDBusProxy *proxy; |
210 | 211 |
|
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; |
219 | 215 |
|
220 | 216 | data->ref_count++; |
221 | 217 | 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); |
232 | 226 | 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); |
243 | 235 | } |
244 | 236 |
|
245 | 237 | void |
|
0 commit comments