Codebase list libcloudproviders / 743da25
Rename CloudProvider class to CloudProviderProxy Julius Härtl 6 years ago
8 changed file(s) with 494 addition(s) and 492 deletion(s). Raw diff Collapse all Expand all
+0
-404
src/cloudprovider.c less more
0 /* cloudprovider.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 "cloudprovider.h"
20 #include "cloudprovider-generated.h"
21
22
23 typedef struct
24 {
25 gchar *name;
26 gchar *path;
27 CloudProviderStatus status;
28 GIcon *icon;
29 GMenuModel *menu_model;
30 GActionGroup *action_group;
31
32 GDBusConnection *bus;
33 CloudProvider1 *proxy;
34 gchar *bus_name;
35 gchar *object_path;
36 GCancellable *cancellable;
37 gboolean ready;
38 } CloudProviderPrivate;
39
40 G_DEFINE_TYPE_WITH_PRIVATE (CloudProvider, cloud_provider, G_TYPE_OBJECT)
41
42 enum {
43 CHANGED,
44 READY,
45 LAST_SIGNAL
46 };
47
48 static guint gSignals [LAST_SIGNAL];
49
50 static void
51 on_get_icon (GObject *source_object,
52 GAsyncResult *res,
53 gpointer user_data)
54 {
55 CloudProvider *self = CLOUD_PROVIDER (user_data);
56 CloudProviderPrivate *priv = cloud_provider_get_instance_private (self);
57 GError *error = NULL;
58 GVariant *variant_tuple;
59 GVariant *variant_dict;
60 GVariant *variant;
61
62 g_clear_object (&priv->icon);
63
64 cloud_provider1_call_get_icon_finish (priv->proxy, &variant_tuple, res, &error);
65 if (error != NULL)
66 {
67 g_warning ("Error getting the provider icon %s", error->message);
68 goto out;
69 }
70
71 variant_dict = g_variant_get_child_value (variant_tuple, 0);
72 variant = g_variant_get_child_value (variant_dict, 0);
73 priv->icon = g_icon_deserialize (variant_dict);
74 g_variant_unref (variant);
75 g_variant_unref (variant_dict);
76
77 out:
78 g_variant_unref (variant_tuple);
79 g_signal_emit_by_name (self, "changed");
80 if(cloud_provider_is_available(self) && !priv->ready) {
81 priv->ready = TRUE;
82 g_signal_emit_by_name (self, "ready");
83 }
84 }
85
86 static void
87 on_get_name (GObject *source_object,
88 GAsyncResult *res,
89 gpointer user_data)
90 {
91 CloudProvider *self = CLOUD_PROVIDER (user_data);
92 CloudProviderPrivate *priv = cloud_provider_get_instance_private (self);
93 GError *error = NULL;
94
95 if (priv->name != NULL)
96 g_free (priv->name);
97
98 cloud_provider1_call_get_name_finish (priv->proxy, &priv->name, res, &error);
99 if (error != NULL)
100 {
101 g_warning ("Error getting the provider name %s", error->message);
102 return;
103 }
104 g_signal_emit_by_name (self, "changed");
105 if(cloud_provider_is_available(self) && !priv->ready) {
106 priv->ready = TRUE;
107 g_signal_emit_by_name (self, "ready");
108 }
109 }
110
111
112 static void
113 on_get_path (GObject *source_object,
114 GAsyncResult *res,
115 gpointer user_data)
116 {
117 CloudProvider *self = CLOUD_PROVIDER (user_data);
118 CloudProviderPrivate *priv = cloud_provider_get_instance_private (self);
119 GError *error = NULL;
120
121 if (priv->path != NULL)
122 g_free (priv->path);
123
124 cloud_provider1_call_get_path_finish (priv->proxy, &priv->path, res, &error);
125 if (error != NULL)
126 {
127 g_warning ("Error getting the provider name %s", error->message);
128 return;
129 }
130 g_signal_emit_by_name (self, "changed");
131 if(cloud_provider_is_available(self) && !priv->ready) {
132 priv->ready = TRUE;
133 g_signal_emit_by_name (self, "ready");
134 }
135 }
136
137 static void
138 on_get_status (GObject *source_object,
139 GAsyncResult *res,
140 gpointer user_data)
141 {
142 CloudProvider *self = CLOUD_PROVIDER (user_data);
143 CloudProviderPrivate *priv = cloud_provider_get_instance_private (self);
144 GError *error = NULL;
145 gint status;
146
147 cloud_provider1_call_get_status_finish (priv->proxy, &status, res, &error);
148 if (error != NULL)
149 {
150 g_warning ("Error getting the provider name %s", error->message);
151 return;
152 }
153 priv->status = status;
154 g_signal_emit_by_name (self, "changed");
155 if(cloud_provider_is_available(self) && !priv->ready) {
156 priv->ready = TRUE;
157 g_signal_emit_by_name (self, "ready");
158 }
159 }
160
161 void
162 cloud_provider_update (CloudProvider *self)
163 {
164 CloudProviderPrivate *priv = cloud_provider_get_instance_private (self);
165
166 if (priv->proxy != NULL)
167 {
168 cloud_provider1_call_get_name (priv->proxy,
169 NULL,
170 (GAsyncReadyCallback) on_get_name,
171 self);
172 cloud_provider1_call_get_status (priv->proxy,
173 NULL,
174 (GAsyncReadyCallback) on_get_status,
175 self);
176 cloud_provider1_call_get_icon (priv->proxy,
177 NULL,
178 (GAsyncReadyCallback) on_get_icon,
179 self);
180 cloud_provider1_call_get_path (priv->proxy,
181 NULL,
182 (GAsyncReadyCallback) on_get_path,
183 self);
184
185 priv->menu_model = (GMenuModel*) g_dbus_menu_model_get (priv->bus,
186 priv->bus_name,
187 priv->object_path);
188 priv->action_group = (GActionGroup*) g_dbus_action_group_get (priv->bus,
189 priv->bus_name,
190 priv->object_path);
191 }
192 }
193
194 static void
195 on_proxy_created (GObject *source_object,
196 GAsyncResult *res,
197 gpointer user_data)
198 {
199 GError *error = NULL;
200 CloudProvider *self;
201 CloudProviderPrivate *priv;
202 CloudProvider1 *proxy;
203
204 proxy = cloud_provider1_proxy_new_for_bus_finish (res, &error);
205 if (error != NULL)
206 {
207 if (error->code != G_IO_ERROR_CANCELLED)
208 g_warning ("Error creating proxy for cloud provider %s", error->message);
209 return;
210 }
211 self = CLOUD_PROVIDER (user_data);
212 priv = cloud_provider_get_instance_private (self);
213
214 priv->proxy = proxy;
215
216 g_signal_connect_swapped(priv->proxy, "cloud-provider-changed", G_CALLBACK(cloud_provider_update), self);
217
218 cloud_provider_update(self);
219 }
220
221 static void
222 on_bus_acquired (GObject *source_object,
223 GAsyncResult *res,
224 gpointer user_data)
225 {
226 GError *error = NULL;
227 CloudProvider *self;
228 GDBusConnection *bus;
229 CloudProviderPrivate *priv;
230
231 bus = g_bus_get_finish (res, &error);
232 if (error != NULL)
233 {
234 if (error->code != G_IO_ERROR_CANCELLED)
235 g_warning ("Error acdquiring bus for cloud provider %s", error->message);
236 return;
237 }
238
239 self = CLOUD_PROVIDER (user_data);
240 priv = cloud_provider_get_instance_private (user_data);
241 priv->bus = bus;
242 g_clear_object (&priv->cancellable);
243 priv->cancellable = g_cancellable_new ();
244 cloud_provider1_proxy_new (priv->bus,
245 G_DBUS_PROXY_FLAGS_NONE,
246 priv->bus_name,
247 priv->object_path,
248 priv->cancellable,
249 on_proxy_created,
250 self);
251 }
252
253 CloudProvider*
254 cloud_provider_new (const gchar *bus_name,
255 const gchar *object_path)
256 {
257 CloudProvider *self;
258 CloudProviderPrivate *priv;
259
260 self = g_object_new (TYPE_CLOUD_PROVIDER, NULL);
261 priv = cloud_provider_get_instance_private (self);
262
263 priv->bus_name = g_strdup (bus_name);
264 priv->object_path = g_strdup (object_path);
265 priv->cancellable = g_cancellable_new ();
266 priv->status = CLOUD_PROVIDER_STATUS_INVALID;
267 priv->ready = FALSE;
268 g_bus_get (G_BUS_TYPE_SESSION,
269 priv->cancellable,
270 on_bus_acquired,
271 self);
272
273 return self;
274 }
275
276 static void
277 cloud_provider_finalize (GObject *object)
278 {
279 CloudProvider *self = (CloudProvider *)object;
280 CloudProviderPrivate *priv = cloud_provider_get_instance_private (self);
281
282 g_cancellable_cancel (priv->cancellable);
283 g_clear_object (&priv->cancellable);
284 g_free (priv->name);
285 g_free (priv->path);
286 g_clear_object (&priv->icon);
287 g_clear_object (&priv->action_group);
288 g_clear_object (&priv->bus);
289 g_clear_object (&priv->proxy);
290 g_free (priv->bus_name);
291 g_free (priv->object_path);
292
293 G_OBJECT_CLASS (cloud_provider_parent_class)->finalize (object);
294 }
295
296 static void
297 cloud_provider_class_init (CloudProviderClass *klass)
298 {
299 GObjectClass *object_class = G_OBJECT_CLASS (klass);
300
301 object_class->finalize = cloud_provider_finalize;
302
303 gSignals [CHANGED] =
304 g_signal_new ("changed",
305 G_TYPE_FROM_CLASS (klass),
306 G_SIGNAL_RUN_LAST,
307 0,
308 NULL,
309 NULL,
310 g_cclosure_marshal_generic,
311 G_TYPE_NONE,
312 0);
313 gSignals [READY] =
314 g_signal_new ("ready",
315 G_TYPE_FROM_CLASS (klass),
316 G_SIGNAL_RUN_LAST,
317 0,
318 NULL,
319 NULL,
320 g_cclosure_marshal_generic,
321 G_TYPE_NONE,
322 0);
323 }
324
325 static void
326 cloud_provider_init (CloudProvider *self)
327 {
328 CloudProviderPrivate *priv = cloud_provider_get_instance_private (self);
329
330 priv->status = CLOUD_PROVIDER_STATUS_INVALID;
331 }
332
333 gchar*
334 cloud_provider_get_name (CloudProvider *self)
335 {
336 CloudProviderPrivate *priv = cloud_provider_get_instance_private (self);
337
338 return priv->name;
339 }
340
341 CloudProviderStatus
342 cloud_provider_get_status (CloudProvider *self)
343 {
344 CloudProviderPrivate *priv = cloud_provider_get_instance_private (self);
345
346 return priv->status;
347 }
348
349 GIcon*
350 cloud_provider_get_icon (CloudProvider *self)
351 {
352 CloudProviderPrivate *priv = cloud_provider_get_instance_private (self);
353
354 return priv->icon;
355 }
356
357 GMenuModel*
358 cloud_provider_get_menu_model (CloudProvider *self)
359 {
360 CloudProviderPrivate *priv = cloud_provider_get_instance_private (self);
361
362 return priv->menu_model;
363 }
364
365 GActionGroup*
366 cloud_provider_get_action_group (CloudProvider *self)
367 {
368 CloudProviderPrivate *priv = cloud_provider_get_instance_private (self);
369
370 return priv->action_group;
371 }
372
373 gchar *
374 cloud_provider_get_path (CloudProvider *self)
375 {
376 CloudProviderPrivate *priv = cloud_provider_get_instance_private (self);
377
378 return priv->path;
379 }
380
381 gchar *
382 cloud_provider_get_owner (CloudProvider *self)
383 {
384 CloudProviderPrivate *priv = cloud_provider_get_instance_private (self);
385
386 return g_dbus_proxy_get_name_owner (G_DBUS_PROXY(priv->proxy));
387 }
388
389 gboolean cloud_provider_is_available(CloudProvider *self)
390 {
391 GIcon *icon;
392 gchar *name;
393 gchar *path;
394 guint status;
395
396 name = cloud_provider_get_name (self);
397 icon = cloud_provider_get_icon (self);
398 status = cloud_provider_get_status (self);
399 path = cloud_provider_get_path (self);
400 if (name == NULL || icon == NULL || path == NULL || status == CLOUD_PROVIDER_STATUS_INVALID)
401 return FALSE;
402 return TRUE;
403 }
+0
-71
src/cloudprovider.h less more
0 /* cloudprovider.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_H
20 #define CLOUD_PROVIDER_H
21
22 #include <gio/gio.h>
23 #include "cloudprovider-generated.h"
24
25 G_BEGIN_DECLS
26
27 typedef enum {
28 CLOUD_PROVIDER_STATUS_INVALID,
29 CLOUD_PROVIDER_STATUS_IDLE,
30 CLOUD_PROVIDER_STATUS_SYNCING,
31 CLOUD_PROVIDER_STATUS_ERROR
32 } CloudProviderStatus;
33
34 #define TYPE_CLOUD_PROVIDER (cloud_provider_get_type())
35 #define CLOUD_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CLOUD_PROVIDER, CloudProvider))
36 #define CLOUD_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CLOUD_PROVIDER, CloudProviderClass))
37 #define IS_CLOUD_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CLOUD_PROVIDER))
38 #define IS_CLOUD_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CLOUD_PROVIDER))
39 #define CLOUD_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CLOUD_PROVIDER, CloudProviderClass))
40
41 typedef struct _CloudProvider CloudProvider;
42 typedef struct _CloudProviderClass CloudProviderClass;
43
44
45 struct _CloudProviderClass
46 {
47 GObjectClass parent_class;
48 };
49
50 struct _CloudProvider
51 {
52 GObject parent_instance;
53 };
54
55
56 GType cloud_provider_get_type (void) G_GNUC_CONST;
57 CloudProvider *cloud_provider_new (const gchar *bus_name,
58 const gchar *object_path);
59
60 gchar* cloud_provider_get_name (CloudProvider *self);
61 CloudProviderStatus cloud_provider_get_status (CloudProvider *self);
62 GIcon *cloud_provider_get_icon (CloudProvider *self);
63 GMenuModel *cloud_provider_get_menu_model (CloudProvider *self);
64 GActionGroup* cloud_provider_get_action_group (CloudProvider *self);
65 gchar *cloud_provider_get_path (CloudProvider *self);
66 gchar *cloud_provider_get_owner (CloudProvider *self);
67 G_END_DECLS
68 gboolean cloud_provider_is_available(CloudProvider *self);
69
70 #endif /* CLOUD_PROVIDER_H */
1717 */
1818
1919 #include "cloudprovidermanager.h"
20 #include "cloudprovider.h"
20 #include "cloudproviderproxy.h"
2121 #include <glib.h>
2222 #include <glib/gprintf.h>
2323 #include <gio/gio.h>
4545 static guint gSignals [LAST_SIGNAL];
4646
4747 static void
48 on_cloud_provider_ready (CloudProvider *cloud_provider, CloudProviderManager *self)
48 on_cloud_provider_proxy_ready (CloudProviderProxy *cloud_provider, CloudProviderManager *self)
4949 {
5050 // notify clients that cloud provider list has changed
5151 g_signal_emit_by_name (self, "owners-changed", NULL);
52 g_print("on_cloud_provider_ready\n");
52 g_print("on_cloud_provider_proxy_ready\n");
5353 // update manager to remove cloud providers after owner disappeared
5454 /*if(cloud_provider_get_owner(cloud_provider) == NULL) {
5555 g_signal_emit_by_name (self, "owners-changed", NULL);
223223 gchar *bus_name;
224224 gchar *object_path;
225225 gboolean success = FALSE;
226 CloudProvider *cloud_provider;
226 CloudProviderProxy*cloud_provider;
227227
228228 key_file = g_key_file_new ();
229229 path = g_file_get_path (file);
271271 Object *object = OBJECT(l->data);
272272 g_print (" - Object at %s\n", g_dbus_object_get_object_path (G_DBUS_OBJECT (object)));
273273 g_print("New cloud provider instance\n");
274 cloud_provider = cloud_provider_new (bus_name, g_dbus_object_get_object_path (G_DBUS_OBJECT (object)));
274 cloud_provider = cloud_provider_proxy_new (bus_name, g_dbus_object_get_object_path (G_DBUS_OBJECT (object)));
275275 g_signal_connect (cloud_provider, "ready",
276 G_CALLBACK (on_cloud_provider_ready), self);
277 cloud_provider_update(cloud_provider);
276 G_CALLBACK (on_cloud_provider_proxy_ready), self);
277 cloud_provider_proxy_update(cloud_provider);
278278 priv->providers = g_list_append (priv->providers, cloud_provider);
279279 }
280280 success = TRUE;
1919 #define CLOUD_PROVIDER_MANAGER_H
2020
2121 #include <gio/gio.h>
22 #include "cloudprovider.h"
22 #include "cloudproviderproxy.h"
2323 #include "cloudprovidermanager-generated.h"
2424
2525 #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 GIcon *icon;
29 GMenuModel *menu_model;
30 GActionGroup *action_group;
31
32 GDBusConnection *bus;
33 CloudProvider1 *proxy;
34 gchar *bus_name;
35 gchar *object_path;
36 GCancellable *cancellable;
37 gboolean ready;
38 } CloudProviderProxyPrivate;
39
40 G_DEFINE_TYPE_WITH_PRIVATE (CloudProviderProxy, cloud_provider_proxy, G_TYPE_OBJECT)
41
42 enum {
43 CHANGED,
44 READY,
45 LAST_SIGNAL
46 };
47
48 static guint gSignals [LAST_SIGNAL];
49
50 static void
51 on_get_icon (GObject *source_object,
52 GAsyncResult *res,
53 gpointer user_data)
54 {
55 CloudProviderProxy *self = CLOUD_PROVIDER_PROXY (user_data);
56 CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self);
57 GError *error = NULL;
58 GVariant *variant_tuple;
59 GVariant *variant_dict;
60 GVariant *variant;
61
62 g_clear_object (&priv->icon);
63
64 cloud_provider1_call_get_icon_finish (priv->proxy, &variant_tuple, res, &error);
65 if (error != NULL)
66 {
67 g_warning ("Error getting the provider icon %s", error->message);
68 goto out;
69 }
70
71 variant_dict = g_variant_get_child_value (variant_tuple, 0);
72 variant = g_variant_get_child_value (variant_dict, 0);
73 priv->icon = g_icon_deserialize (variant_dict);
74 g_variant_unref (variant);
75 g_variant_unref (variant_dict);
76
77 out:
78 g_variant_unref (variant_tuple);
79 g_signal_emit_by_name (self, "changed");
80 if(cloud_provider_proxy_is_available(self) && !priv->ready) {
81 priv->ready = TRUE;
82 g_signal_emit_by_name (self, "ready");
83 }
84 }
85
86 static void
87 on_get_name (GObject *source_object,
88 GAsyncResult *res,
89 gpointer user_data)
90 {
91 CloudProviderProxy *self = CLOUD_PROVIDER_PROXY (user_data);
92 CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self);
93 GError *error = NULL;
94
95 if (priv->name != NULL)
96 g_free (priv->name);
97
98 cloud_provider1_call_get_name_finish (priv->proxy, &priv->name, res, &error);
99 if (error != NULL)
100 {
101 g_warning ("Error getting the provider name %s", error->message);
102 return;
103 }
104 g_signal_emit_by_name (self, "changed");
105 if(cloud_provider_proxy_is_available(self) && !priv->ready) {
106 priv->ready = TRUE;
107 g_signal_emit_by_name (self, "ready");
108 }
109 }
110
111
112 static void
113 on_get_path (GObject *source_object,
114 GAsyncResult *res,
115 gpointer user_data)
116 {
117 CloudProviderProxy *self = CLOUD_PROVIDER_PROXY (user_data);
118 CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self);
119 GError *error = NULL;
120
121 if (priv->path != NULL)
122 g_free (priv->path);
123
124 cloud_provider1_call_get_path_finish (priv->proxy, &priv->path, res, &error);
125 if (error != NULL)
126 {
127 g_warning ("Error getting the provider name %s", error->message);
128 return;
129 }
130 g_signal_emit_by_name (self, "changed");
131 if(cloud_provider_proxy_is_available(self) && !priv->ready) {
132 priv->ready = TRUE;
133 g_signal_emit_by_name (self, "ready");
134 }
135 }
136
137 static void
138 on_get_status (GObject *source_object,
139 GAsyncResult *res,
140 gpointer user_data)
141 {
142 CloudProviderProxy *self = CLOUD_PROVIDER_PROXY (user_data);
143 CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self);
144 GError *error = NULL;
145 gint status;
146
147 cloud_provider1_call_get_status_finish (priv->proxy, &status, res, &error);
148 if (error != NULL)
149 {
150 g_warning ("Error getting the provider name %s", error->message);
151 return;
152 }
153 priv->status = status;
154 g_signal_emit_by_name (self, "changed");
155 if(cloud_provider_proxy_is_available(self) && !priv->ready) {
156 priv->ready = TRUE;
157 g_signal_emit_by_name (self, "ready");
158 }
159 }
160
161 void
162 cloud_provider_proxy_update (CloudProviderProxy *self)
163 {
164 CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self);
165
166 if (priv->proxy != NULL)
167 {
168 cloud_provider1_call_get_name (priv->proxy,
169 NULL,
170 (GAsyncReadyCallback) on_get_name,
171 self);
172 cloud_provider1_call_get_status (priv->proxy,
173 NULL,
174 (GAsyncReadyCallback) on_get_status,
175 self);
176 cloud_provider1_call_get_icon (priv->proxy,
177 NULL,
178 (GAsyncReadyCallback) on_get_icon,
179 self);
180 cloud_provider1_call_get_path (priv->proxy,
181 NULL,
182 (GAsyncReadyCallback) on_get_path,
183 self);
184
185 priv->menu_model = (GMenuModel*) g_dbus_menu_model_get (priv->bus,
186 priv->bus_name,
187 priv->object_path);
188 priv->action_group = (GActionGroup*) g_dbus_action_group_get (priv->bus,
189 priv->bus_name,
190 priv->object_path);
191 }
192 }
193
194 static void
195 on_proxy_created (GObject *source_object,
196 GAsyncResult *res,
197 gpointer user_data)
198 {
199 GError *error = NULL;
200 CloudProviderProxy *self;
201 CloudProviderProxyPrivate *priv;
202 CloudProvider1 *proxy;
203
204 proxy = cloud_provider1_proxy_new_for_bus_finish (res, &error);
205 if (error != NULL)
206 {
207 if (error->code != G_IO_ERROR_CANCELLED)
208 g_warning ("Error creating proxy for cloud provider %s", error->message);
209 return;
210 }
211 self = CLOUD_PROVIDER_PROXY (user_data);
212 priv = cloud_provider_proxy_get_instance_private (self);
213
214 priv->proxy = proxy;
215
216 g_signal_connect_swapped(priv->proxy, "cloud-provider-changed", G_CALLBACK(cloud_provider_proxy_update), self);
217
218 cloud_provider_proxy_update(self);
219 }
220
221 static void
222 on_bus_acquired (GObject *source_object,
223 GAsyncResult *res,
224 gpointer user_data)
225 {
226 GError *error = NULL;
227 CloudProviderProxy *self;
228 GDBusConnection *bus;
229 CloudProviderProxyPrivate *priv;
230
231 bus = g_bus_get_finish (res, &error);
232 if (error != NULL)
233 {
234 if (error->code != G_IO_ERROR_CANCELLED)
235 g_warning ("Error acdquiring bus for cloud provider %s", error->message);
236 return;
237 }
238
239 self = CLOUD_PROVIDER_PROXY (user_data);
240 priv = cloud_provider_proxy_get_instance_private (user_data);
241 priv->bus = bus;
242 g_clear_object (&priv->cancellable);
243 priv->cancellable = g_cancellable_new ();
244 cloud_provider1_proxy_new (priv->bus,
245 G_DBUS_PROXY_FLAGS_NONE,
246 priv->bus_name,
247 priv->object_path,
248 priv->cancellable,
249 on_proxy_created,
250 self);
251 }
252
253 CloudProviderProxy*
254 cloud_provider_proxy_new (const gchar *bus_name,
255 const gchar *object_path)
256 {
257 CloudProviderProxy *self;
258 CloudProviderProxyPrivate *priv;
259
260 self = g_object_new (TYPE_CLOUD_PROVIDER_PROXY, NULL);
261 priv = cloud_provider_proxy_get_instance_private (self);
262
263 priv->bus_name = g_strdup (bus_name);
264 priv->object_path = g_strdup (object_path);
265 priv->cancellable = g_cancellable_new ();
266 priv->status = CLOUD_PROVIDER_STATUS_INVALID;
267 priv->ready = FALSE;
268 g_bus_get (G_BUS_TYPE_SESSION,
269 priv->cancellable,
270 on_bus_acquired,
271 self);
272
273 return self;
274 }
275
276 static void
277 cloud_provider_proxy_finalize (GObject *object)
278 {
279 CloudProviderProxy *self = (CloudProviderProxy *)object;
280 CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self);
281
282 g_cancellable_cancel (priv->cancellable);
283 g_clear_object (&priv->cancellable);
284 g_free (priv->name);
285 g_free (priv->path);
286 g_clear_object (&priv->icon);
287 g_clear_object (&priv->action_group);
288 g_clear_object (&priv->bus);
289 g_clear_object (&priv->proxy);
290 g_free (priv->bus_name);
291 g_free (priv->object_path);
292
293 G_OBJECT_CLASS (cloud_provider_proxy_parent_class)->finalize (object);
294 }
295
296 static void
297 cloud_provider_proxy_class_init (CloudProviderProxyClass *klass)
298 {
299 GObjectClass *object_class = G_OBJECT_CLASS (klass);
300
301 object_class->finalize = cloud_provider_proxy_finalize;
302
303 gSignals [CHANGED] =
304 g_signal_new ("changed",
305 G_TYPE_FROM_CLASS (klass),
306 G_SIGNAL_RUN_LAST,
307 0,
308 NULL,
309 NULL,
310 g_cclosure_marshal_generic,
311 G_TYPE_NONE,
312 0);
313 gSignals [READY] =
314 g_signal_new ("ready",
315 G_TYPE_FROM_CLASS (klass),
316 G_SIGNAL_RUN_LAST,
317 0,
318 NULL,
319 NULL,
320 g_cclosure_marshal_generic,
321 G_TYPE_NONE,
322 0);
323 }
324
325 static void
326 cloud_provider_proxy_init (CloudProviderProxy *self)
327 {
328 CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self);
329
330 priv->status = CLOUD_PROVIDER_STATUS_INVALID;
331 }
332
333 gchar*
334 cloud_provider_proxy_get_name (CloudProviderProxy *self)
335 {
336 CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self);
337
338 return priv->name;
339 }
340
341 CloudProviderStatus
342 cloud_provider_proxy_get_status (CloudProviderProxy *self)
343 {
344 CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self);
345
346 return priv->status;
347 }
348
349 GIcon*
350 cloud_provider_proxy_get_icon (CloudProviderProxy *self)
351 {
352 CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self);
353
354 return priv->icon;
355 }
356
357 GMenuModel*
358 cloud_provider_proxy_get_menu_model (CloudProviderProxy *self)
359 {
360 CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self);
361
362 return priv->menu_model;
363 }
364
365 GActionGroup*
366 cloud_provider_proxy_get_action_group (CloudProviderProxy *self)
367 {
368 CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self);
369
370 return priv->action_group;
371 }
372
373 gchar *
374 cloud_provider_proxy_get_path (CloudProviderProxy *self)
375 {
376 CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self);
377
378 return priv->path;
379 }
380
381 gchar *
382 cloud_provider_proxy_get_owner (CloudProviderProxy *self)
383 {
384 CloudProviderProxyPrivate *priv = cloud_provider_proxy_get_instance_private (self);
385
386 return g_dbus_proxy_get_name_owner (G_DBUS_PROXY(priv->proxy));
387 }
388
389 gboolean cloud_provider_proxy_is_available(CloudProviderProxy *self)
390 {
391 GIcon *icon;
392 gchar *name;
393 gchar *path;
394 guint status;
395
396 name = cloud_provider_proxy_get_name (self);
397 icon = cloud_provider_proxy_get_icon (self);
398 status = cloud_provider_proxy_get_status (self);
399 path = cloud_provider_proxy_get_path (self);
400 if (name == NULL || icon == NULL || path == NULL || status == CLOUD_PROVIDER_STATUS_INVALID)
401 return FALSE;
402 return TRUE;
403 }
0 /* cloudprovider.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_H
20 #define CLOUD_PROVIDER_H
21
22 #include <gio/gio.h>
23 #include "cloudprovider-generated.h"
24
25 G_BEGIN_DECLS
26
27 typedef enum {
28 CLOUD_PROVIDER_STATUS_INVALID,
29 CLOUD_PROVIDER_STATUS_IDLE,
30 CLOUD_PROVIDER_STATUS_SYNCING,
31 CLOUD_PROVIDER_STATUS_ERROR
32 } CloudProviderStatus;
33
34 #define TYPE_CLOUD_PROVIDER_PROXY (cloud_provider_proxy_get_type())
35 #define CLOUD_PROVIDER_PROXY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CLOUD_PROVIDER_PROXY, CloudProviderProxy))
36 #define CLOUD_PROVIDER_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CLOUD_PROVIDER_PROXY, CloudProviderProxyClass))
37 #define IS_CLOUD_PROVIDER_PROXY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CLOUD_PROVIDER_PROXY))
38 #define IS_CLOUD_PROVIDER_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CLOUD_PROVIDER_PROXY))
39 #define CLOUD_PROVIDER_PROXY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CLOUD_PROVIDER_PROXY, CloudProviderProxyClass))
40
41 typedef struct _CloudProviderProxy CloudProviderProxy;
42 typedef struct _CloudProviderProxyClass CloudProviderProxyClass;
43
44
45 struct _CloudProviderProxyClass
46 {
47 GObjectClass parent_class;
48 };
49
50 struct _CloudProviderProxy
51 {
52 GObject parent_instance;
53 };
54
55
56 GType cloud_provider_proxy_get_type (void) G_GNUC_CONST;
57 CloudProviderProxy *cloud_provider_proxy_new (const gchar *bus_name,
58 const gchar *object_path);
59
60 gchar* cloud_provider_proxy_get_name (CloudProviderProxy *self);
61 CloudProviderStatus cloud_provider_proxy_get_status (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_H */
00 libcloudproviders_headers = [
11 'cloudprovidermanager.h',
2 'cloudprovider.h',
2 'cloudproviderproxy.h',
33 'cloudprovider-generated.h',
44 'cloudprovidermanager-generated.h'
55 ]
66
77 libcloudproviders_sources = [
88 'cloudprovidermanager.c',
9 'cloudprovider.c'
9 'cloudproviderproxy.c'
1010 ]
1111
1212 libcloudproviders_deps = [glib, gio, gio_unix]
00 #include <glib.h>
1 #include <cloudprovider.h>
1 #include <cloudproviderproxy.h>
22 #include <cloudprovidermanager.h>
33
44 static void
5151 g_print ("##############\n");
5252 for (l = providers; l != NULL; l = l->next)
5353 {
54 if(!cloud_provider_is_available(CLOUD_PROVIDER (l->data))) {
54 if(!cloud_provider_proxy_is_available(CLOUD_PROVIDER_PROXY(l->data))) {
5555 continue;
5656 }
57 provider_status = cloud_provider_get_status (CLOUD_PROVIDER (l->data));
57 provider_status = cloud_provider_proxy_get_status (CLOUD_PROVIDER_PROXY (l->data));
5858 switch (provider_status)
5959 {
6060 case CLOUD_PROVIDER_STATUS_INVALID:
7777 g_assert_not_reached ();
7878 }
7979
80 icon = cloud_provider_get_icon (l->data);
80 icon = cloud_provider_proxy_get_icon (l->data);
8181 icon_representation = g_icon_to_string (icon);
8282
8383 g_print ("Name - %s, Status - %s, Path - %s, Icon - %s\n",
84 cloud_provider_get_name (CLOUD_PROVIDER (l->data)),
84 cloud_provider_proxy_get_name (CLOUD_PROVIDER_PROXY (l->data)),
8585 status_string,
86 cloud_provider_get_path (CLOUD_PROVIDER (l->data)),
86 cloud_provider_proxy_get_path (CLOUD_PROVIDER_PROXY (l->data)),
8787 icon_representation);
8888
8989 g_free (icon_representation);
9090
91 menu = cloud_provider_get_menu_model (l->data);
91 menu = cloud_provider_proxy_get_menu_model (l->data);
9292 g_print ("\nMenu\n");
9393 print_gmenu_model (menu);
9494 }