libcloudproviders: Rename CloudProviderProxy to CloudProviderAccount
Julius Härtl
6 years ago
20 | 20 | |
21 | 21 | #include "cloudprovider-generated.h" |
22 | 22 | /* for CloudProviderStatus enum */ |
23 | #include "cloudproviderproxy.h" | |
23 | #include "cloudprovideraccount.h" | |
24 | 24 | #include "cloudprovideraccountexporter.h" |
25 | 25 | |
26 | 26 | G_BEGIN_DECLS |
0 | /* cloudprovideraccount.c | |
1 | * | |
2 | * Copyright (C) 2015 Carlos Soriano <csoriano@gnome.org> | |
3 | * Copyright (C) 2017 Julius Haertl <jus@bitgrid.net> | |
4 | * | |
5 | * This file is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU Lesser General Public License as | |
7 | * published by the Free Software Foundation; either version 3 of the | |
8 | * License, or (at your option) any later version. | |
9 | * | |
10 | * This file is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | #include "cloudprovideraccount.h" | |
20 | #include "cloudprovider-generated.h" | |
21 | ||
22 | ||
23 | typedef struct | |
24 | { | |
25 | gchar *name; | |
26 | gchar *path; | |
27 | CloudProviderStatus status; | |
28 | gchar *status_details; | |
29 | GIcon *icon; | |
30 | GMenuModel *menu_model; | |
31 | GActionGroup *action_group; | |
32 | ||
33 | GDBusConnection *bus; | |
34 | CloudProviderAccount1 *proxy; | |
35 | gchar *bus_name; | |
36 | gchar *object_path; | |
37 | GCancellable *cancellable; | |
38 | gboolean ready; | |
39 | } CloudProviderAccountPrivate; | |
40 | ||
41 | G_DEFINE_TYPE_WITH_PRIVATE (CloudProviderAccount, cloud_provider_account, G_TYPE_OBJECT) | |
42 | ||
43 | /** | |
44 | * SECTION:cloudprovideraccount | |
45 | * @title: CloudProviderAccount | |
46 | * @short_description: Base object for representing a single account for clients. | |
47 | * @include: src/cloudprovideraccount.h | |
48 | * | |
49 | * #CloudProviderAccount is the basic object used to construct the integrator UI | |
50 | * and actions that a provider will present to the user, from the client side. | |
51 | * Integrators of the cloud providers can use this object to poll the | |
52 | * #CloudProvider menus, status and actions. | |
53 | */ | |
54 | ||
55 | enum { | |
56 | CHANGED, | |
57 | READY, | |
58 | LAST_SIGNAL | |
59 | }; | |
60 | ||
61 | static guint gSignals [LAST_SIGNAL]; | |
62 | ||
63 | static void | |
64 | on_get_icon (GObject *source_object, | |
65 | GAsyncResult *res, | |
66 | gpointer user_data) | |
67 | { | |
68 | CloudProviderAccount *self = CLOUD_PROVIDER_ACCOUNT (user_data); | |
69 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
70 | GError *error = NULL; | |
71 | GVariant *variant_tuple; | |
72 | GVariant *variant_dict; | |
73 | GVariant *variant; | |
74 | ||
75 | g_clear_object (&priv->icon); | |
76 | ||
77 | cloud_provider_account1_call_get_icon_finish (priv->proxy, &variant_tuple, res, &error); | |
78 | if (error != NULL) | |
79 | { | |
80 | g_warning ("Error getting the provider icon %s", error->message); | |
81 | goto out; | |
82 | } | |
83 | ||
84 | variant_dict = g_variant_get_child_value (variant_tuple, 0); | |
85 | if (g_variant_is_of_type(variant_dict, G_VARIANT_TYPE_STRING)) | |
86 | { | |
87 | priv->icon = g_icon_deserialize (variant_dict); | |
88 | g_variant_unref (variant_dict); | |
89 | goto out; | |
90 | } | |
91 | variant = g_variant_get_child_value (variant_dict, 0); | |
92 | priv->icon = g_icon_deserialize (variant_dict); | |
93 | g_variant_unref (variant); | |
94 | g_variant_unref (variant_dict); | |
95 | ||
96 | out: | |
97 | g_variant_unref (variant_tuple); | |
98 | g_signal_emit_by_name (self, "changed"); | |
99 | if(cloud_provider_account_is_available(self) && !priv->ready) { | |
100 | priv->ready = TRUE; | |
101 | g_signal_emit_by_name (self, "ready"); | |
102 | } | |
103 | } | |
104 | ||
105 | static void | |
106 | on_get_name (GObject *source_object, | |
107 | GAsyncResult *res, | |
108 | gpointer user_data) | |
109 | { | |
110 | CloudProviderAccount *self = CLOUD_PROVIDER_ACCOUNT (user_data); | |
111 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
112 | GError *error = NULL; | |
113 | ||
114 | if (priv->name != NULL) | |
115 | g_free (priv->name); | |
116 | ||
117 | cloud_provider_account1_call_get_name_finish (priv->proxy, &priv->name, res, &error); | |
118 | if (error != NULL) | |
119 | { | |
120 | g_warning ("Error getting the provider name %s", error->message); | |
121 | return; | |
122 | } | |
123 | g_signal_emit_by_name (self, "changed"); | |
124 | if(cloud_provider_account_is_available(self) && !priv->ready) { | |
125 | priv->ready = TRUE; | |
126 | g_signal_emit_by_name (self, "ready"); | |
127 | } | |
128 | } | |
129 | ||
130 | ||
131 | static void | |
132 | on_get_path (GObject *source_object, | |
133 | GAsyncResult *res, | |
134 | gpointer user_data) | |
135 | { | |
136 | CloudProviderAccount *self = CLOUD_PROVIDER_ACCOUNT (user_data); | |
137 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
138 | GError *error = NULL; | |
139 | ||
140 | if (priv->path != NULL) | |
141 | g_free (priv->path); | |
142 | ||
143 | cloud_provider_account1_call_get_path_finish (priv->proxy, &priv->path, res, &error); | |
144 | if (error != NULL) | |
145 | { | |
146 | g_warning ("Error getting the provider name %s", error->message); | |
147 | return; | |
148 | } | |
149 | g_signal_emit_by_name (self, "changed"); | |
150 | if(cloud_provider_account_is_available(self) && !priv->ready) { | |
151 | priv->ready = TRUE; | |
152 | g_signal_emit_by_name (self, "ready"); | |
153 | } | |
154 | } | |
155 | ||
156 | static void | |
157 | on_get_status (GObject *source_object, | |
158 | GAsyncResult *res, | |
159 | gpointer user_data) | |
160 | { | |
161 | CloudProviderAccount *self = CLOUD_PROVIDER_ACCOUNT (user_data); | |
162 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
163 | GError *error = NULL; | |
164 | gint status; | |
165 | ||
166 | cloud_provider_account1_call_get_status_finish (priv->proxy, &status, res, &error); | |
167 | if (error != NULL) | |
168 | { | |
169 | g_warning ("Error getting the provider name %s", error->message); | |
170 | return; | |
171 | } | |
172 | priv->status = status; | |
173 | g_signal_emit_by_name (self, "changed"); | |
174 | if(cloud_provider_account_is_available(self) && !priv->ready) { | |
175 | priv->ready = TRUE; | |
176 | g_signal_emit_by_name (self, "ready"); | |
177 | } | |
178 | } | |
179 | ||
180 | static void | |
181 | on_get_status_details(GObject *source_object, | |
182 | GAsyncResult *res, | |
183 | gpointer user_data) | |
184 | { | |
185 | CloudProviderAccount *self = CLOUD_PROVIDER_ACCOUNT (user_data); | |
186 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
187 | GError *error = NULL; | |
188 | ||
189 | if (priv->status_details != NULL) | |
190 | g_free (priv->status_details); | |
191 | ||
192 | cloud_provider_account1_call_get_status_details_finish (priv->proxy, &priv->status_details, res, &error); | |
193 | if (error != NULL) | |
194 | { | |
195 | g_warning ("Error getting the status details %s", error->message); | |
196 | return; | |
197 | } | |
198 | g_signal_emit_by_name (self, "changed"); | |
199 | if(cloud_provider_account_is_available(self) && !priv->ready) { | |
200 | priv->ready = TRUE; | |
201 | g_signal_emit_by_name (self, "ready"); | |
202 | } | |
203 | } | |
204 | ||
205 | void | |
206 | cloud_provider_account_update (CloudProviderAccount *self) | |
207 | { | |
208 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
209 | ||
210 | if (priv->proxy != NULL) | |
211 | { | |
212 | cloud_provider_account1_call_get_name (priv->proxy, | |
213 | NULL, | |
214 | (GAsyncReadyCallback) on_get_name, | |
215 | self); | |
216 | cloud_provider_account1_call_get_status (priv->proxy, | |
217 | NULL, | |
218 | (GAsyncReadyCallback) on_get_status, | |
219 | self); | |
220 | cloud_provider_account1_call_get_status_details (priv->proxy, | |
221 | NULL, | |
222 | (GAsyncReadyCallback) on_get_status_details, | |
223 | self); | |
224 | cloud_provider_account1_call_get_icon (priv->proxy, | |
225 | NULL, | |
226 | (GAsyncReadyCallback) on_get_icon, | |
227 | self); | |
228 | cloud_provider_account1_call_get_path (priv->proxy, | |
229 | NULL, | |
230 | (GAsyncReadyCallback) on_get_path, | |
231 | self); | |
232 | ||
233 | priv->menu_model = (GMenuModel*) g_dbus_menu_model_get (priv->bus, | |
234 | priv->bus_name, | |
235 | priv->object_path); | |
236 | priv->action_group = (GActionGroup*) g_dbus_action_group_get (priv->bus, | |
237 | priv->bus_name, | |
238 | priv->object_path); | |
239 | } | |
240 | } | |
241 | ||
242 | static void | |
243 | on_proxy_created (GObject *source_object, | |
244 | GAsyncResult *res, | |
245 | gpointer user_data) | |
246 | { | |
247 | GError *error = NULL; | |
248 | CloudProviderAccount *self; | |
249 | CloudProviderAccountPrivate *priv; | |
250 | CloudProviderAccount1 *proxy; | |
251 | ||
252 | proxy = cloud_provider_account1_proxy_new_for_bus_finish (res, &error); | |
253 | if (error != NULL) | |
254 | { | |
255 | if (error->code != G_IO_ERROR_CANCELLED) | |
256 | g_warning ("Error creating proxy for cloud provider %s", error->message); | |
257 | return; | |
258 | } | |
259 | self = CLOUD_PROVIDER_ACCOUNT (user_data); | |
260 | priv = cloud_provider_account_get_instance_private (self); | |
261 | ||
262 | priv->proxy = proxy; | |
263 | ||
264 | g_signal_connect_swapped(priv->proxy, "cloud-provider-changed", G_CALLBACK(cloud_provider_account_update), self); | |
265 | ||
266 | cloud_provider_account_update(self); | |
267 | } | |
268 | ||
269 | static void | |
270 | on_bus_acquired (GObject *source_object, | |
271 | GAsyncResult *res, | |
272 | gpointer user_data) | |
273 | { | |
274 | GError *error = NULL; | |
275 | CloudProviderAccount *self; | |
276 | GDBusConnection *bus; | |
277 | CloudProviderAccountPrivate *priv; | |
278 | ||
279 | bus = g_bus_get_finish (res, &error); | |
280 | if (error != NULL) | |
281 | { | |
282 | if (error->code != G_IO_ERROR_CANCELLED) | |
283 | g_warning ("Error acdquiring bus for cloud provider %s", error->message); | |
284 | return; | |
285 | } | |
286 | ||
287 | self = CLOUD_PROVIDER_ACCOUNT (user_data); | |
288 | priv = cloud_provider_account_get_instance_private (user_data); | |
289 | priv->bus = bus; | |
290 | g_clear_object (&priv->cancellable); | |
291 | priv->cancellable = g_cancellable_new (); | |
292 | cloud_provider_account1_proxy_new (priv->bus, | |
293 | G_DBUS_PROXY_FLAGS_NONE, | |
294 | priv->bus_name, | |
295 | priv->object_path, | |
296 | priv->cancellable, | |
297 | on_proxy_created, | |
298 | self); | |
299 | } | |
300 | ||
301 | CloudProviderAccount* | |
302 | cloud_provider_account_new (const gchar *bus_name, | |
303 | const gchar *object_path) | |
304 | { | |
305 | CloudProviderAccount *self; | |
306 | CloudProviderAccountPrivate *priv; | |
307 | ||
308 | self = g_object_new (TYPE_CLOUD_PROVIDER_ACCOUNT, NULL); | |
309 | priv = cloud_provider_account_get_instance_private (self); | |
310 | ||
311 | priv->bus_name = g_strdup (bus_name); | |
312 | priv->object_path = g_strdup (object_path); | |
313 | priv->cancellable = g_cancellable_new (); | |
314 | priv->status = CLOUD_PROVIDER_STATUS_INVALID; | |
315 | priv->ready = FALSE; | |
316 | g_bus_get (G_BUS_TYPE_SESSION, | |
317 | priv->cancellable, | |
318 | on_bus_acquired, | |
319 | self); | |
320 | ||
321 | return self; | |
322 | } | |
323 | ||
324 | static void | |
325 | cloud_provider_account_finalize (GObject *object) | |
326 | { | |
327 | CloudProviderAccount *self = (CloudProviderAccount *)object; | |
328 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
329 | ||
330 | g_cancellable_cancel (priv->cancellable); | |
331 | g_clear_object (&priv->cancellable); | |
332 | g_free (priv->name); | |
333 | g_free (priv->path); | |
334 | g_clear_object (&priv->icon); | |
335 | g_clear_object (&priv->action_group); | |
336 | g_clear_object (&priv->bus); | |
337 | g_clear_object (&priv->proxy); | |
338 | g_free (priv->bus_name); | |
339 | g_free (priv->object_path); | |
340 | ||
341 | G_OBJECT_CLASS (cloud_provider_account_parent_class)->finalize (object); | |
342 | } | |
343 | ||
344 | static void | |
345 | cloud_provider_account_class_init (CloudProviderAccountClass *klass) | |
346 | { | |
347 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
348 | ||
349 | object_class->finalize = cloud_provider_account_finalize; | |
350 | ||
351 | gSignals [CHANGED] = | |
352 | g_signal_new ("changed", | |
353 | G_TYPE_FROM_CLASS (klass), | |
354 | G_SIGNAL_RUN_LAST, | |
355 | 0, | |
356 | NULL, | |
357 | NULL, | |
358 | g_cclosure_marshal_generic, | |
359 | G_TYPE_NONE, | |
360 | 0); | |
361 | gSignals [READY] = | |
362 | g_signal_new ("ready", | |
363 | G_TYPE_FROM_CLASS (klass), | |
364 | G_SIGNAL_RUN_LAST, | |
365 | 0, | |
366 | NULL, | |
367 | NULL, | |
368 | g_cclosure_marshal_generic, | |
369 | G_TYPE_NONE, | |
370 | 0); | |
371 | } | |
372 | ||
373 | static void | |
374 | cloud_provider_account_init (CloudProviderAccount *self) | |
375 | { | |
376 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
377 | ||
378 | priv->status = CLOUD_PROVIDER_STATUS_INVALID; | |
379 | } | |
380 | ||
381 | gchar* | |
382 | cloud_provider_account_get_name (CloudProviderAccount *self) | |
383 | { | |
384 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
385 | ||
386 | return priv->name; | |
387 | } | |
388 | ||
389 | CloudProviderStatus | |
390 | cloud_provider_account_get_status (CloudProviderAccount *self) | |
391 | { | |
392 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
393 | ||
394 | return priv->status; | |
395 | } | |
396 | ||
397 | gchar* | |
398 | cloud_provider_account_get_status_details (CloudProviderAccount *self) | |
399 | { | |
400 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
401 | ||
402 | return priv->status_details; | |
403 | } | |
404 | ||
405 | GIcon* | |
406 | cloud_provider_account_get_icon (CloudProviderAccount *self) | |
407 | { | |
408 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
409 | ||
410 | return priv->icon; | |
411 | } | |
412 | ||
413 | GMenuModel* | |
414 | cloud_provider_account_get_menu_model (CloudProviderAccount *self) | |
415 | { | |
416 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
417 | ||
418 | return priv->menu_model; | |
419 | } | |
420 | ||
421 | GActionGroup* | |
422 | cloud_provider_account_get_action_group (CloudProviderAccount *self) | |
423 | { | |
424 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
425 | ||
426 | return priv->action_group; | |
427 | } | |
428 | ||
429 | gchar * | |
430 | cloud_provider_account_get_path (CloudProviderAccount *self) | |
431 | { | |
432 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
433 | ||
434 | return priv->path; | |
435 | } | |
436 | ||
437 | gchar * | |
438 | cloud_provider_account_get_owner (CloudProviderAccount *self) | |
439 | { | |
440 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
441 | ||
442 | return g_dbus_proxy_get_name_owner (G_DBUS_PROXY(priv->proxy)); | |
443 | } | |
444 | ||
445 | gboolean cloud_provider_account_is_available(CloudProviderAccount *self) | |
446 | { | |
447 | GIcon *icon; | |
448 | gchar *name; | |
449 | gchar *path; | |
450 | guint status; | |
451 | ||
452 | name = cloud_provider_account_get_name (self); | |
453 | icon = cloud_provider_account_get_icon (self); | |
454 | status = cloud_provider_account_get_status (self); | |
455 | path = cloud_provider_account_get_path (self); | |
456 | if (name == NULL || icon == NULL || path == NULL || status == CLOUD_PROVIDER_STATUS_INVALID) | |
457 | return FALSE; | |
458 | return TRUE; | |
459 | } |
0 | /* cloudprovideraccount.h | |
1 | * | |
2 | * Copyright (C) 2015 Carlos Soriano <csoriano@gnome.org> | |
3 | * Copyright (C) 2017 Julius Haertl <jus@bitgrid.net> | |
4 | * | |
5 | * This file is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU Lesser General Public License as | |
7 | * published by the Free Software Foundation; either version 3 of the | |
8 | * License, or (at your option) any later version. | |
9 | * | |
10 | * This file is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | #ifndef CLOUD_PROVIDER_ACCOUNT_H | |
20 | #define CLOUD_PROVIDER_ACCOUNT_H | |
21 | ||
22 | #include <gio/gio.h> | |
23 | ||
24 | G_BEGIN_DECLS | |
25 | ||
26 | typedef enum { | |
27 | CLOUD_PROVIDER_STATUS_INVALID, | |
28 | CLOUD_PROVIDER_STATUS_IDLE, | |
29 | CLOUD_PROVIDER_STATUS_SYNCING, | |
30 | CLOUD_PROVIDER_STATUS_ERROR | |
31 | } CloudProviderStatus; | |
32 | ||
33 | #define TYPE_CLOUD_PROVIDER_ACCOUNT (cloud_provider_account_get_type()) | |
34 | #define CLOUD_PROVIDER_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CLOUD_PROVIDER_ACCOUNT, CloudProviderAccount)) | |
35 | #define CLOUD_PROVIDER_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CLOUD_PROVIDER_ACCOUNT, CloudProviderAccountClass)) | |
36 | #define IS_CLOUD_PROVIDER_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CLOUD_PROVIDER_ACCOUNT)) | |
37 | #define IS_CLOUD_PROVIDER_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CLOUD_PROVIDER_ACCOUNT)) | |
38 | #define CLOUD_PROVIDER_ACCOUNT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CLOUD_PROVIDER_ACCOUNT, CloudProviderAccountClass)) | |
39 | ||
40 | typedef struct _CloudProviderAccount CloudProviderAccount; | |
41 | typedef struct _CloudProviderAccountClass CloudProviderAccountClass; | |
42 | ||
43 | ||
44 | struct _CloudProviderAccountClass | |
45 | { | |
46 | GObjectClass parent_class; | |
47 | }; | |
48 | ||
49 | struct _CloudProviderAccount | |
50 | { | |
51 | GObject parent_instance; | |
52 | }; | |
53 | ||
54 | ||
55 | GType cloud_provider_account_get_type (void) G_GNUC_CONST; | |
56 | CloudProviderAccount *cloud_provider_account_new (const gchar *bus_name, | |
57 | const gchar *object_path); | |
58 | ||
59 | gchar* cloud_provider_account_get_name (CloudProviderAccount *self); | |
60 | CloudProviderStatus cloud_provider_account_get_status (CloudProviderAccount *self); | |
61 | gchar* cloud_provider_account_get_status_details (CloudProviderAccount *self); | |
62 | GIcon *cloud_provider_account_get_icon (CloudProviderAccount *self); | |
63 | GMenuModel *cloud_provider_account_get_menu_model (CloudProviderAccount *self); | |
64 | GActionGroup* cloud_provider_account_get_action_group (CloudProviderAccount *self); | |
65 | gchar *cloud_provider_account_get_path (CloudProviderAccount *self); | |
66 | gchar *cloud_provider_account_get_owner (CloudProviderAccount *self); | |
67 | gboolean cloud_provider_account_is_available(CloudProviderAccount *self); | |
68 | void cloud_provider_account_update (CloudProviderAccount *self); | |
69 | G_END_DECLS | |
70 | ||
71 | ||
72 | #endif /* CLOUD_PROVIDER_ACCOUNT_H */ |
17 | 17 | */ |
18 | 18 | |
19 | 19 | #include "cloudprovidermanager.h" |
20 | #include "cloudproviderproxy.h" | |
20 | #include "cloudprovideraccount.h" | |
21 | 21 | #include <glib.h> |
22 | 22 | #include <glib/gprintf.h> |
23 | 23 | #include <gio/gio.h> |
19 | 19 | #define CLOUD_PROVIDER_MANAGER_H |
20 | 20 | |
21 | 21 | #include <gio/gio.h> |
22 | #include "cloudproviderproxy.h" | |
22 | #include "cloudprovideraccount.h" | |
23 | 23 | #include "cloudprovidermanager-generated.h" |
24 | 24 | |
25 | 25 | #define CLOUD_PROVIDER_MANAGER_DBUS_IFACE "org.freedesktop.CloudProviderManager1" |
0 | /* cloudproviderproxy.c | |
1 | * | |
2 | * Copyright (C) 2015 Carlos Soriano <csoriano@gnome.org> | |
3 | * Copyright (C) 2017 Julius Haertl <jus@bitgrid.net> | |
4 | * | |
5 | * This file is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU Lesser General Public License as | |
7 | * published by the Free Software Foundation; either version 3 of the | |
8 | * License, or (at your option) any later version. | |
9 | * | |
10 | * This file is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | #include "cloudproviderproxy.h" | |
20 | #include "cloudprovider-generated.h" | |
21 | ||
22 | ||
23 | typedef struct | |
24 | { | |
25 | gchar *name; | |
26 | gchar *path; | |
27 | CloudProviderStatus status; | |
28 | gchar *status_details; | |
29 | GIcon *icon; | |
30 | GMenuModel *menu_model; | |
31 | GActionGroup *action_group; | |
32 | ||
33 | GDBusConnection *bus; | |
34 | CloudProviderAccount1 *proxy; | |
35 | gchar *bus_name; | |
36 | gchar *object_path; | |
37 | GCancellable *cancellable; | |
38 | gboolean ready; | |
39 | } CloudProviderProxyPrivate; | |
40 | ||
41 | G_DEFINE_TYPE_WITH_PRIVATE (CloudProviderProxy, cloud_provider_proxy, G_TYPE_OBJECT) | |
42 | ||
43 | /** | |
44 | * SECTION:cloudproviderproxy | |
45 | * @title: CloudProviderProxy | |
46 | * @short_description: Base object for representing a single provider for clients. | |
47 | * @include: src/cloudproviderproxy.h | |
48 | * | |
49 | * #CloudProviderProxy is the basic object used to construct the integrator UI | |
50 | * and actions that a provider will present to the user, from the client side. | |
51 | * Integrators of the cloud providers can use this object to poll the | |
52 | * #CloudProvider menus, status and actions. | |
53 | */ | |
54 | ||
55 | enum { | |
56 | CHANGED, | |
57 | READY, | |
58 | LAST_SIGNAL | |
59 | }; | |
60 | ||
61 | static guint gSignals [LAST_SIGNAL]; | |
62 | ||
63 | static void | |
64 | on_get_icon (GObject *source_object, | |
65 | GAsyncResult *res, | |
66 | gpointer user_data) | |
67 | { | |
68 | CloudProviderProxy *self = CLOUD_PROVIDER_PROXY (user_data); | |
69 | CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self); | |
70 | GError *error = NULL; | |
71 | GVariant *variant_tuple; | |
72 | GVariant *variant_dict; | |
73 | GVariant *variant; | |
74 | ||
75 | g_clear_object (&priv->icon); | |
76 | ||
77 | cloud_provider_account1_call_get_icon_finish (priv->proxy, &variant_tuple, res, &error); | |
78 | if (error != NULL) | |
79 | { | |
80 | g_warning ("Error getting the provider icon %s", error->message); | |
81 | goto out; | |
82 | } | |
83 | ||
84 | variant_dict = g_variant_get_child_value (variant_tuple, 0); | |
85 | if (g_variant_is_of_type(variant_dict, G_VARIANT_TYPE_STRING)) | |
86 | { | |
87 | priv->icon = g_icon_deserialize (variant_dict); | |
88 | g_variant_unref (variant_dict); | |
89 | goto out; | |
90 | } | |
91 | variant = g_variant_get_child_value (variant_dict, 0); | |
92 | priv->icon = g_icon_deserialize (variant_dict); | |
93 | g_variant_unref (variant); | |
94 | g_variant_unref (variant_dict); | |
95 | ||
96 | out: | |
97 | g_variant_unref (variant_tuple); | |
98 | g_signal_emit_by_name (self, "changed"); | |
99 | if(cloud_provider_proxy_is_available(self) && !priv->ready) { | |
100 | priv->ready = TRUE; | |
101 | g_signal_emit_by_name (self, "ready"); | |
102 | } | |
103 | } | |
104 | ||
105 | static void | |
106 | on_get_name (GObject *source_object, | |
107 | GAsyncResult *res, | |
108 | gpointer user_data) | |
109 | { | |
110 | CloudProviderProxy *self = CLOUD_PROVIDER_PROXY (user_data); | |
111 | CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self); | |
112 | GError *error = NULL; | |
113 | ||
114 | if (priv->name != NULL) | |
115 | g_free (priv->name); | |
116 | ||
117 | cloud_provider_account1_call_get_name_finish (priv->proxy, &priv->name, res, &error); | |
118 | if (error != NULL) | |
119 | { | |
120 | g_warning ("Error getting the provider name %s", error->message); | |
121 | return; | |
122 | } | |
123 | g_signal_emit_by_name (self, "changed"); | |
124 | if(cloud_provider_proxy_is_available(self) && !priv->ready) { | |
125 | priv->ready = TRUE; | |
126 | g_signal_emit_by_name (self, "ready"); | |
127 | } | |
128 | } | |
129 | ||
130 | ||
131 | static void | |
132 | on_get_path (GObject *source_object, | |
133 | GAsyncResult *res, | |
134 | gpointer user_data) | |
135 | { | |
136 | CloudProviderProxy *self = CLOUD_PROVIDER_PROXY (user_data); | |
137 | CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self); | |
138 | GError *error = NULL; | |
139 | ||
140 | if (priv->path != NULL) | |
141 | g_free (priv->path); | |
142 | ||
143 | cloud_provider_account1_call_get_path_finish (priv->proxy, &priv->path, res, &error); | |
144 | if (error != NULL) | |
145 | { | |
146 | g_warning ("Error getting the provider name %s", error->message); | |
147 | return; | |
148 | } | |
149 | g_signal_emit_by_name (self, "changed"); | |
150 | if(cloud_provider_proxy_is_available(self) && !priv->ready) { | |
151 | priv->ready = TRUE; | |
152 | g_signal_emit_by_name (self, "ready"); | |
153 | } | |
154 | } | |
155 | ||
156 | static void | |
157 | on_get_status (GObject *source_object, | |
158 | GAsyncResult *res, | |
159 | gpointer user_data) | |
160 | { | |
161 | CloudProviderProxy *self = CLOUD_PROVIDER_PROXY (user_data); | |
162 | CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self); | |
163 | GError *error = NULL; | |
164 | gint status; | |
165 | ||
166 | cloud_provider_account1_call_get_status_finish (priv->proxy, &status, res, &error); | |
167 | if (error != NULL) | |
168 | { | |
169 | g_warning ("Error getting the provider name %s", error->message); | |
170 | return; | |
171 | } | |
172 | priv->status = status; | |
173 | g_signal_emit_by_name (self, "changed"); | |
174 | if(cloud_provider_proxy_is_available(self) && !priv->ready) { | |
175 | priv->ready = TRUE; | |
176 | g_signal_emit_by_name (self, "ready"); | |
177 | } | |
178 | } | |
179 | ||
180 | static void | |
181 | on_get_status_details(GObject *source_object, | |
182 | GAsyncResult *res, | |
183 | gpointer user_data) | |
184 | { | |
185 | CloudProviderProxy *self = CLOUD_PROVIDER_PROXY (user_data); | |
186 | CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self); | |
187 | GError *error = NULL; | |
188 | ||
189 | if (priv->status_details != NULL) | |
190 | g_free (priv->status_details); | |
191 | ||
192 | cloud_provider_account1_call_get_status_details_finish (priv->proxy, &priv->status_details, res, &error); | |
193 | if (error != NULL) | |
194 | { | |
195 | g_warning ("Error getting the status details %s", error->message); | |
196 | return; | |
197 | } | |
198 | g_signal_emit_by_name (self, "changed"); | |
199 | if(cloud_provider_proxy_is_available(self) && !priv->ready) { | |
200 | priv->ready = TRUE; | |
201 | g_signal_emit_by_name (self, "ready"); | |
202 | } | |
203 | } | |
204 | ||
205 | void | |
206 | cloud_provider_proxy_update (CloudProviderProxy *self) | |
207 | { | |
208 | CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self); | |
209 | ||
210 | if (priv->proxy != NULL) | |
211 | { | |
212 | cloud_provider_account1_call_get_name (priv->proxy, | |
213 | NULL, | |
214 | (GAsyncReadyCallback) on_get_name, | |
215 | self); | |
216 | cloud_provider_account1_call_get_status (priv->proxy, | |
217 | NULL, | |
218 | (GAsyncReadyCallback) on_get_status, | |
219 | self); | |
220 | cloud_provider_account1_call_get_status_details (priv->proxy, | |
221 | NULL, | |
222 | (GAsyncReadyCallback) on_get_status_details, | |
223 | self); | |
224 | cloud_provider_account1_call_get_icon (priv->proxy, | |
225 | NULL, | |
226 | (GAsyncReadyCallback) on_get_icon, | |
227 | self); | |
228 | cloud_provider_account1_call_get_path (priv->proxy, | |
229 | NULL, | |
230 | (GAsyncReadyCallback) on_get_path, | |
231 | self); | |
232 | ||
233 | priv->menu_model = (GMenuModel*) g_dbus_menu_model_get (priv->bus, | |
234 | priv->bus_name, | |
235 | priv->object_path); | |
236 | priv->action_group = (GActionGroup*) g_dbus_action_group_get (priv->bus, | |
237 | priv->bus_name, | |
238 | priv->object_path); | |
239 | } | |
240 | } | |
241 | ||
242 | static void | |
243 | on_proxy_created (GObject *source_object, | |
244 | GAsyncResult *res, | |
245 | gpointer user_data) | |
246 | { | |
247 | GError *error = NULL; | |
248 | CloudProviderProxy *self; | |
249 | CloudProviderProxyPrivate *priv; | |
250 | CloudProviderAccount1 *proxy; | |
251 | ||
252 | proxy = cloud_provider_account1_proxy_new_for_bus_finish (res, &error); | |
253 | if (error != NULL) | |
254 | { | |
255 | if (error->code != G_IO_ERROR_CANCELLED) | |
256 | g_warning ("Error creating proxy for cloud provider %s", error->message); | |
257 | return; | |
258 | } | |
259 | self = CLOUD_PROVIDER_PROXY (user_data); | |
260 | priv = cloud_provider_proxy_get_instance_private (self); | |
261 | ||
262 | priv->proxy = proxy; | |
263 | ||
264 | g_signal_connect_swapped(priv->proxy, "cloud-provider-changed", G_CALLBACK(cloud_provider_proxy_update), self); | |
265 | ||
266 | cloud_provider_proxy_update(self); | |
267 | } | |
268 | ||
269 | static void | |
270 | on_bus_acquired (GObject *source_object, | |
271 | GAsyncResult *res, | |
272 | gpointer user_data) | |
273 | { | |
274 | GError *error = NULL; | |
275 | CloudProviderProxy *self; | |
276 | GDBusConnection *bus; | |
277 | CloudProviderProxyPrivate *priv; | |
278 | ||
279 | bus = g_bus_get_finish (res, &error); | |
280 | if (error != NULL) | |
281 | { | |
282 | if (error->code != G_IO_ERROR_CANCELLED) | |
283 | g_warning ("Error acdquiring bus for cloud provider %s", error->message); | |
284 | return; | |
285 | } | |
286 | ||
287 | self = CLOUD_PROVIDER_PROXY (user_data); | |
288 | priv = cloud_provider_proxy_get_instance_private (user_data); | |
289 | priv->bus = bus; | |
290 | g_clear_object (&priv->cancellable); | |
291 | priv->cancellable = g_cancellable_new (); | |
292 | cloud_provider_account1_proxy_new (priv->bus, | |
293 | G_DBUS_PROXY_FLAGS_NONE, | |
294 | priv->bus_name, | |
295 | priv->object_path, | |
296 | priv->cancellable, | |
297 | on_proxy_created, | |
298 | self); | |
299 | } | |
300 | ||
301 | CloudProviderProxy* | |
302 | cloud_provider_proxy_new (const gchar *bus_name, | |
303 | const gchar *object_path) | |
304 | { | |
305 | CloudProviderProxy *self; | |
306 | CloudProviderProxyPrivate *priv; | |
307 | ||
308 | self = g_object_new (TYPE_CLOUD_PROVIDER_PROXY, NULL); | |
309 | priv = cloud_provider_proxy_get_instance_private (self); | |
310 | ||
311 | priv->bus_name = g_strdup (bus_name); | |
312 | priv->object_path = g_strdup (object_path); | |
313 | priv->cancellable = g_cancellable_new (); | |
314 | priv->status = CLOUD_PROVIDER_STATUS_INVALID; | |
315 | priv->ready = FALSE; | |
316 | g_bus_get (G_BUS_TYPE_SESSION, | |
317 | priv->cancellable, | |
318 | on_bus_acquired, | |
319 | self); | |
320 | ||
321 | return self; | |
322 | } | |
323 | ||
324 | static void | |
325 | cloud_provider_proxy_finalize (GObject *object) | |
326 | { | |
327 | CloudProviderProxy *self = (CloudProviderProxy *)object; | |
328 | CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self); | |
329 | ||
330 | g_cancellable_cancel (priv->cancellable); | |
331 | g_clear_object (&priv->cancellable); | |
332 | g_free (priv->name); | |
333 | g_free (priv->path); | |
334 | g_clear_object (&priv->icon); | |
335 | g_clear_object (&priv->action_group); | |
336 | g_clear_object (&priv->bus); | |
337 | g_clear_object (&priv->proxy); | |
338 | g_free (priv->bus_name); | |
339 | g_free (priv->object_path); | |
340 | ||
341 | G_OBJECT_CLASS (cloud_provider_proxy_parent_class)->finalize (object); | |
342 | } | |
343 | ||
344 | static void | |
345 | cloud_provider_proxy_class_init (CloudProviderProxyClass *klass) | |
346 | { | |
347 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
348 | ||
349 | object_class->finalize = cloud_provider_proxy_finalize; | |
350 | ||
351 | gSignals [CHANGED] = | |
352 | g_signal_new ("changed", | |
353 | G_TYPE_FROM_CLASS (klass), | |
354 | G_SIGNAL_RUN_LAST, | |
355 | 0, | |
356 | NULL, | |
357 | NULL, | |
358 | g_cclosure_marshal_generic, | |
359 | G_TYPE_NONE, | |
360 | 0); | |
361 | gSignals [READY] = | |
362 | g_signal_new ("ready", | |
363 | G_TYPE_FROM_CLASS (klass), | |
364 | G_SIGNAL_RUN_LAST, | |
365 | 0, | |
366 | NULL, | |
367 | NULL, | |
368 | g_cclosure_marshal_generic, | |
369 | G_TYPE_NONE, | |
370 | 0); | |
371 | } | |
372 | ||
373 | static void | |
374 | cloud_provider_proxy_init (CloudProviderProxy *self) | |
375 | { | |
376 | CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self); | |
377 | ||
378 | priv->status = CLOUD_PROVIDER_STATUS_INVALID; | |
379 | } | |
380 | ||
381 | gchar* | |
382 | cloud_provider_proxy_get_name (CloudProviderProxy *self) | |
383 | { | |
384 | CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self); | |
385 | ||
386 | return priv->name; | |
387 | } | |
388 | ||
389 | CloudProviderStatus | |
390 | cloud_provider_proxy_get_status (CloudProviderProxy *self) | |
391 | { | |
392 | CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self); | |
393 | ||
394 | return priv->status; | |
395 | } | |
396 | ||
397 | gchar* | |
398 | cloud_provider_proxy_get_status_details (CloudProviderProxy *self) | |
399 | { | |
400 | CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self); | |
401 | ||
402 | return priv->status_details; | |
403 | } | |
404 | ||
405 | GIcon* | |
406 | cloud_provider_proxy_get_icon (CloudProviderProxy *self) | |
407 | { | |
408 | CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self); | |
409 | ||
410 | return priv->icon; | |
411 | } | |
412 | ||
413 | GMenuModel* | |
414 | cloud_provider_proxy_get_menu_model (CloudProviderProxy *self) | |
415 | { | |
416 | CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self); | |
417 | ||
418 | return priv->menu_model; | |
419 | } | |
420 | ||
421 | GActionGroup* | |
422 | cloud_provider_proxy_get_action_group (CloudProviderProxy *self) | |
423 | { | |
424 | CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self); | |
425 | ||
426 | return priv->action_group; | |
427 | } | |
428 | ||
429 | gchar * | |
430 | cloud_provider_proxy_get_path (CloudProviderProxy *self) | |
431 | { | |
432 | CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self); | |
433 | ||
434 | return priv->path; | |
435 | } | |
436 | ||
437 | gchar * | |
438 | cloud_provider_proxy_get_owner (CloudProviderProxy *self) | |
439 | { | |
440 | CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self); | |
441 | ||
442 | return g_dbus_proxy_get_name_owner (G_DBUS_PROXY(priv->proxy)); | |
443 | } | |
444 | ||
445 | gboolean cloud_provider_proxy_is_available(CloudProviderProxy *self) | |
446 | { | |
447 | GIcon *icon; | |
448 | gchar *name; | |
449 | gchar *path; | |
450 | guint status; | |
451 | ||
452 | name = cloud_provider_proxy_get_name (self); | |
453 | icon = cloud_provider_proxy_get_icon (self); | |
454 | status = cloud_provider_proxy_get_status (self); | |
455 | path = cloud_provider_proxy_get_path (self); | |
456 | if (name == NULL || icon == NULL || path == NULL || status == CLOUD_PROVIDER_STATUS_INVALID) | |
457 | return FALSE; | |
458 | return TRUE; | |
459 | } |
0 | /* cloudproviderproxy.h | |
1 | * | |
2 | * Copyright (C) 2015 Carlos Soriano <csoriano@gnome.org> | |
3 | * Copyright (C) 2017 Julius Haertl <jus@bitgrid.net> | |
4 | * | |
5 | * This file is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU Lesser General Public License as | |
7 | * published by the Free Software Foundation; either version 3 of the | |
8 | * License, or (at your option) any later version. | |
9 | * | |
10 | * This file is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | #ifndef CLOUD_PROVIDER_PROXY_H | |
20 | #define CLOUD_PROVIDER_PROXY_H | |
21 | ||
22 | #include <gio/gio.h> | |
23 | ||
24 | G_BEGIN_DECLS | |
25 | ||
26 | typedef enum { | |
27 | CLOUD_PROVIDER_STATUS_INVALID, | |
28 | CLOUD_PROVIDER_STATUS_IDLE, | |
29 | CLOUD_PROVIDER_STATUS_SYNCING, | |
30 | CLOUD_PROVIDER_STATUS_ERROR | |
31 | } CloudProviderStatus; | |
32 | ||
33 | #define TYPE_CLOUD_PROVIDER_PROXY (cloud_provider_proxy_get_type()) | |
34 | #define CLOUD_PROVIDER_PROXY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CLOUD_PROVIDER_PROXY, CloudProviderProxy)) | |
35 | #define CLOUD_PROVIDER_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CLOUD_PROVIDER_PROXY, CloudProviderProxyClass)) | |
36 | #define IS_CLOUD_PROVIDER_PROXY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CLOUD_PROVIDER_PROXY)) | |
37 | #define IS_CLOUD_PROVIDER_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CLOUD_PROVIDER_PROXY)) | |
38 | #define CLOUD_PROVIDER_PROXY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CLOUD_PROVIDER_PROXY, CloudProviderProxyClass)) | |
39 | ||
40 | typedef struct _CloudProviderProxy CloudProviderProxy; | |
41 | typedef struct _CloudProviderProxyClass CloudProviderProxyClass; | |
42 | ||
43 | ||
44 | struct _CloudProviderProxyClass | |
45 | { | |
46 | GObjectClass parent_class; | |
47 | }; | |
48 | ||
49 | struct _CloudProviderProxy | |
50 | { | |
51 | GObject parent_instance; | |
52 | }; | |
53 | ||
54 | ||
55 | GType cloud_provider_proxy_get_type (void) G_GNUC_CONST; | |
56 | CloudProviderProxy *cloud_provider_proxy_new (const gchar *bus_name, | |
57 | const gchar *object_path); | |
58 | ||
59 | gchar* cloud_provider_proxy_get_name (CloudProviderProxy *self); | |
60 | CloudProviderStatus cloud_provider_proxy_get_status (CloudProviderProxy *self); | |
61 | gchar* cloud_provider_proxy_get_status_details (CloudProviderProxy *self); | |
62 | GIcon *cloud_provider_proxy_get_icon (CloudProviderProxy *self); | |
63 | GMenuModel *cloud_provider_proxy_get_menu_model (CloudProviderProxy *self); | |
64 | GActionGroup* cloud_provider_proxy_get_action_group (CloudProviderProxy *self); | |
65 | gchar *cloud_provider_proxy_get_path (CloudProviderProxy *self); | |
66 | gchar *cloud_provider_proxy_get_owner (CloudProviderProxy *self); | |
67 | gboolean cloud_provider_proxy_is_available(CloudProviderProxy *self); | |
68 | void cloud_provider_proxy_update (CloudProviderProxy *self); | |
69 | G_END_DECLS | |
70 | ||
71 | ||
72 | #endif /* CLOUD_PROVIDER_PROXY_H */ |
17 | 17 | */ |
18 | 18 | |
19 | 19 | #include "cloudproviders.h" |
20 | #include "cloudproviderproxy.h" | |
20 | #include "cloudprovideraccount.h" | |
21 | 21 | #include "cloudprovidermanager.h" |
22 | 22 | #include "cloudprovidermanager-generated.h" |
23 | 23 | #include "cloudprovider-generated.h" |
62 | 62 | static guint gSignals [LAST_SIGNAL]; |
63 | 63 | |
64 | 64 | static void |
65 | on_cloud_provider_proxy_ready (CloudProviderProxy *cloud_provider, CloudProviders *self) | |
65 | on_cloud_provider_proxy_ready (CloudProviderAccount *cloud_provider, CloudProviders *self) | |
66 | 66 | { |
67 | 67 | // notify clients that cloud provider list has changed |
68 | 68 | g_signal_emit_by_name (self, "owners-changed", NULL); |
69 | 69 | } |
70 | 70 | |
71 | 71 | static void |
72 | on_cloud_provider_changed (CloudProviderProxy *cloud_provider, CloudProviders *self) | |
72 | on_cloud_provider_changed (CloudProviderAccount *cloud_provider, CloudProviders *self) | |
73 | 73 | { |
74 | 74 | // notify clients that cloud provider has changed |
75 | 75 | g_signal_emit_by_name (self, "changed", NULL); |
225 | 225 | /** |
226 | 226 | * cloud_providers_get_providers |
227 | 227 | * @self: A CloudProviders |
228 | * Returns: (transfer none): A GList* of #CloudProviderProxy objects. | |
228 | * Returns: (transfer none): A GList* of #CloudProviderAccount objects. | |
229 | 229 | */ |
230 | 230 | GList* |
231 | 231 | cloud_providers_get_providers (CloudProviders *self) |
244 | 244 | CloudProvidersPrivate *priv = cloud_providers_get_instance_private (self); |
245 | 245 | GError *error = NULL; |
246 | 246 | GVariant *foo; |
247 | CloudProviderProxy*cloud_provider; | |
247 | CloudProviderAccount*cloud_provider; | |
248 | 248 | gboolean success = FALSE; |
249 | 249 | GVariantIter iter; |
250 | 250 | gchar *bus_name; |
291 | 291 | for (l = objects; l != NULL; l = l->next) |
292 | 292 | { |
293 | 293 | CloudProviderObject *object = CLOUD_PROVIDER_OBJECT(l->data); |
294 | cloud_provider = cloud_provider_proxy_new (bus_name, g_dbus_object_get_object_path (G_DBUS_OBJECT (object))); | |
294 | cloud_provider = cloud_provider_account_new (bus_name, g_dbus_object_get_object_path (G_DBUS_OBJECT (object))); | |
295 | 295 | g_signal_connect (cloud_provider, "ready", |
296 | 296 | G_CALLBACK (on_cloud_provider_proxy_ready), self); |
297 | 297 | g_signal_connect (cloud_provider, "changed", |
298 | 298 | G_CALLBACK (on_cloud_provider_changed), self); |
299 | cloud_provider_proxy_update (cloud_provider); | |
299 | cloud_provider_account_update (cloud_provider); | |
300 | 300 | priv->providers = g_list_append (priv->providers, cloud_provider); |
301 | 301 | } |
302 | 302 | } |
19 | 19 | #define CLOUD_PROVIDERS_H |
20 | 20 | |
21 | 21 | #include <gio/gio.h> |
22 | #include "cloudproviderproxy.h" | |
22 | #include "cloudprovideraccount.h" | |
23 | 23 | |
24 | 24 | G_BEGIN_DECLS |
25 | 25 |
0 | 0 | libcloudproviders_headers = [ |
1 | 1 | 'cloudprovidermanager.h', |
2 | 'cloudproviderproxy.h', | |
2 | 'cloudprovideraccount.h', | |
3 | 3 | 'cloudproviders.h', |
4 | 4 | 'cloudprovider.h', |
5 | 5 | 'cloudprovideraccountexporter.h', |
7 | 7 | |
8 | 8 | libcloudproviders_sources = [ |
9 | 9 | 'cloudprovidermanager.c', |
10 | 'cloudproviderproxy.c', | |
10 | 'cloudprovideraccount.c', | |
11 | 11 | 'cloudproviders.c', |
12 | 12 | 'cloudprovider.c', |
13 | 13 | 'cloudprovideraccountexporter.c', |
0 | 0 | #include <glib.h> |
1 | #include <cloudproviderproxy.h> | |
1 | #include <cloudprovideraccount.h> | |
2 | 2 | #include <cloudprovidermanager.h> |
3 | 3 | #include <cloudproviders.h> |
4 | 4 | |
50 | 50 | return; |
51 | 51 | for (l = providers; l != NULL; l = l->next) |
52 | 52 | { |
53 | if(!cloud_provider_proxy_is_available(CLOUD_PROVIDER_PROXY(l->data))) { | |
53 | if(!cloud_provider_account_is_available(CLOUD_PROVIDER_ACCOUNT(l->data))) { | |
54 | 54 | continue; |
55 | 55 | } |
56 | 56 | g_print ("Providers data\n"); |
57 | 57 | g_print ("##############\n"); |
58 | provider_status = cloud_provider_proxy_get_status (CLOUD_PROVIDER_PROXY (l->data)); | |
58 | provider_status = cloud_provider_account_get_status (CLOUD_PROVIDER_ACCOUNT (l->data)); | |
59 | 59 | switch (provider_status) |
60 | 60 | { |
61 | 61 | case CLOUD_PROVIDER_STATUS_INVALID: |
78 | 78 | g_assert_not_reached (); |
79 | 79 | } |
80 | 80 | |
81 | icon = cloud_provider_proxy_get_icon (l->data); | |
81 | icon = cloud_provider_account_get_icon (l->data); | |
82 | 82 | icon_representation = g_icon_to_string (icon); |
83 | 83 | |
84 | 84 | g_print ("Name - %s, Status - %s (%s), Path - %s, Icon - %s\n", |
85 | cloud_provider_proxy_get_name (CLOUD_PROVIDER_PROXY (l->data)), | |
85 | cloud_provider_account_get_name (CLOUD_PROVIDER_ACCOUNT (l->data)), | |
86 | 86 | status_string, |
87 | cloud_provider_proxy_get_status_details (CLOUD_PROVIDER_PROXY (l->data)), | |
88 | cloud_provider_proxy_get_path (CLOUD_PROVIDER_PROXY (l->data)), | |
87 | cloud_provider_account_get_status_details (CLOUD_PROVIDER_ACCOUNT (l->data)), | |
88 | cloud_provider_account_get_path (CLOUD_PROVIDER_ACCOUNT (l->data)), | |
89 | 89 | icon_representation); |
90 | 90 | |
91 | 91 | g_free (icon_representation); |
92 | 92 | |
93 | menu = cloud_provider_proxy_get_menu_model (l->data); | |
93 | menu = cloud_provider_account_get_menu_model (l->data); | |
94 | 94 | g_print ("\nMenu\n"); |
95 | 95 | print_gmenu_model (menu); |
96 | 96 | } |