Codebase list libcloudproviders / b7d467d
libcloudproviders: rename CloudProvider to CloudProviderExporter Julius Härtl 6 years ago
6 changed file(s) with 421 addition(s) and 420 deletion(s). Raw diff Collapse all Expand all
+0
-316
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 "cloudprovideraccountexporterpriv.h"
21 #include "cloudprovider-generated.h"
22 #include <gio/gio.h>
23
24 typedef struct
25 {
26 GDBusConnection *bus;
27 GDBusObjectManagerServer *manager;
28 gchar *bus_name;
29 gchar *object_path;
30 GCancellable *cancellable;
31 GHashTable *menuModels;
32 GHashTable *actionGroups;
33 } CloudProviderPrivate;
34
35 G_DEFINE_TYPE_WITH_PRIVATE (CloudProvider, cloud_provider, G_TYPE_OBJECT)
36
37 /**
38 * SECTION:cloudprovider
39 * @title: CloudProvider
40 * @short_description: Base object for representing a single provider
41 * @include: src/cloudprovider.h
42 *
43 * #CloudProvider is the basic object that interacts with UI and actions that a
44 * provider will present to the user.
45 * list view. Extensions can provide #NautilusColumn by registering a
46 * #NautilusColumnProvider and returning them from
47 * nautilus_column_provider_get_columns(), which will be called by the main
48 * application when creating a view.
49 */
50
51 /**
52 * cloud_provider_add_account:
53 * @self: The cloud provider
54 * @account: The account object
55 *
56 * Each cloud provider can have a variety of account associated with it. Use this
57 * function to export the accounts the user set up.
58 */
59 void
60 cloud_provider_add_account (CloudProvider *cloud_provider,
61 CloudProviderAccountExporter *account)
62 {
63 CloudProviderPrivate *priv = cloud_provider_get_instance_private(cloud_provider);
64 CloudProviderObjectSkeleton *object;
65 gchar *object_path = g_strconcat (priv->object_path, "/", cloud_provider_account_exporter_get_object_name (account), NULL);
66 object = cloud_provider_object_skeleton_new(object_path);
67 cloud_provider_object_skeleton_set_account1(object, CLOUD_PROVIDER_ACCOUNT1 (cloud_provider_account_exporter_get_skeleton (account)));
68 g_dbus_object_manager_server_export (priv->manager, G_DBUS_OBJECT_SKELETON(object));
69 g_free(object_path);
70 }
71
72 /**
73 * cloud_provider_export_account:
74 * @self: The cloud provider
75 * @account_name: The account name
76 * @account: The account object
77 *
78 * Each cloud provider can have a variety of account associated with it. Use this
79 * function to export the accounts the user set up.
80 */
81 void
82 cloud_provider_export_account(CloudProvider* self,
83 const gchar *account_name,
84 CloudProviderAccount1 *account)
85 {
86 CloudProviderPrivate *priv = cloud_provider_get_instance_private(self);
87 CloudProviderObjectSkeleton *object;
88 gchar *object_path = g_strconcat (priv->object_path, "/", account_name, NULL);
89 object = cloud_provider_object_skeleton_new(object_path);
90 cloud_provider_object_skeleton_set_account1(object, account);
91 g_dbus_object_manager_server_export (priv->manager,
92 G_DBUS_OBJECT_SKELETON(object));
93 g_free(object_path);
94 }
95
96 /**
97 * cloud_provider_unexport_account:
98 * @self: The cloud provider
99 * @account_name: The name of the account
100 *
101 * Each cloud provider can have a variety of account associated with it. Use this
102 * function to remove an already set up account.
103 */
104 void
105 cloud_provider_unexport_account(CloudProvider *self,
106 const gchar *account_name)
107 {
108 CloudProviderPrivate *priv = cloud_provider_get_instance_private(self);
109 gchar *object_path = g_strconcat (priv->object_path, "/", account_name, NULL);
110 g_dbus_object_manager_server_unexport (priv->manager, object_path);
111 guint *export_id;
112 export_id = (guint*)g_hash_table_lookup(priv->menuModels, account_name);
113 if(export_id != NULL) {
114 g_dbus_connection_unexport_menu_model(priv->bus, *export_id);
115 g_free(export_id);
116 }
117 export_id = (guint*)g_hash_table_lookup(priv->actionGroups, account_name);
118 if(export_id != NULL) {
119 g_dbus_connection_unexport_action_group(priv->bus, *export_id);
120 g_free(export_id);
121 }
122 g_free (object_path);
123 }
124
125 /**
126 * cloud_provider_export_menu:
127 * @self: The cloud provider
128 * @account_name: The name of the account
129 *
130 * One of the benefits of the integration is to display a menu with available
131 * options for an account. Use this function to export a GMenuModel menu to be
132 * displayed by the choosen integration by the desktop environment or application.
133 */
134 guint
135 cloud_provider_export_menu(CloudProvider *self,
136 const gchar *account_name,
137 GMenuModel *model)
138 {
139 CloudProviderPrivate *priv = cloud_provider_get_instance_private(self);
140 gchar *object_path = g_strconcat(priv->object_path, "/", account_name, NULL);
141 GError *error = NULL;
142 guint *export_id = g_new0(guint, 1);
143 *export_id = g_dbus_connection_export_menu_model (priv->bus, object_path, model, &error);
144 if (!*export_id)
145 {
146 g_warning ("Menu export failed: %s", error->message);
147 return 0;
148 }
149 g_hash_table_insert(priv->menuModels, g_strdup(account_name), export_id);
150 return *export_id;
151 }
152
153 /**
154 * cloud_provider_unexport_menu:
155 * @self: The cloud provider
156 * @account_name: The name of the account
157 *
158 * Remove the menu added with cloud_provider_export_menu
159 */
160 void
161 cloud_provider_unexport_menu(CloudProvider *self,
162 const gchar *account_name)
163 {
164 CloudProviderPrivate *priv = cloud_provider_get_instance_private(self);
165 guint *export_id;
166 export_id = (guint*)g_hash_table_lookup(priv->menuModels, account_name);
167 if(export_id != NULL) {
168 g_dbus_connection_unexport_menu_model(priv->bus, *export_id);
169 g_hash_table_remove (priv->menuModels, account_name);
170 g_free(export_id);
171 }
172 }
173
174 /**
175 * cloud_provider_action_group:
176 * @self: The cloud provider
177 * @account_name: The name of the account
178 * @action_group: The GActionGroup to be used by the menu exported by cloud_provider_export_menu
179 *
180 * In order for a menu exported with cloud_provider_export_menu to receive events
181 * that will eventually call your callbacks, it needs the corresponding GAcionGroup.
182 * Use this function to export it.
183 */
184 guint
185 cloud_provider_export_action_group(CloudProvider *self,
186 const gchar *account_name,
187 GActionGroup *action_group)
188 {
189 CloudProviderPrivate *priv = cloud_provider_get_instance_private(self);
190 gchar *object_path = g_strconcat(priv->object_path, "/", account_name, NULL);
191 GError *error = NULL;
192 guint *export_id = g_new0(guint, 1);
193 *export_id = g_dbus_connection_export_action_group (priv->bus, object_path, action_group, &error);
194 if (!*export_id)
195 {
196 g_warning ("Action export failed: %s", error->message);
197 return 0;
198 }
199 g_hash_table_insert(priv->actionGroups, g_strdup(account_name), export_id);
200 return *export_id;
201 }
202
203 /**
204 * cloud_provider_unexport_action_group:
205 * @self: The cloud provider
206 * @account_name: The name of the account
207 *
208 * Unexport the GActionGroup exported by cloud_provider_export_action_group
209 */
210 void
211 cloud_provider_unexport_action_group(CloudProvider *self,
212 const gchar *account_name)
213 {
214 CloudProviderPrivate *priv = cloud_provider_get_instance_private(self);
215 guint *export_id;
216 export_id = (guint*)g_hash_table_lookup(priv->actionGroups, account_name);
217 if(export_id != NULL) {
218 g_dbus_connection_unexport_action_group(priv->bus, *export_id);
219 g_hash_table_remove (priv->actionGroups, account_name);
220 g_free(export_id);
221 }
222 }
223
224 /**
225 * cloud_provider_export_objects:
226 * @self: The cloud provider
227 *
228 * Export all objects assigned previously with functions like cloud_provider_export_menu
229 * to DBUS.
230 * Use this function after exporting all the required object to avoid multiple signals
231 * being emitted in a short time.
232 */
233 void
234 cloud_provider_export_objects(CloudProvider* self)
235 {
236 CloudProviderPrivate *priv = cloud_provider_get_instance_private(self);
237 g_dbus_object_manager_server_set_connection (priv->manager, priv->bus);
238 }
239
240 /**
241 * cloud_provider_emit_changed:
242 * @self: The cloud provider
243 * @account_name: The name of the account
244 *
245 * When an account changes its status, emit a signal to DBUS using this function
246 * so clients are aware of the change.
247 */
248 void
249 cloud_provider_emit_changed (CloudProvider *self,
250 const gchar *account_name)
251 {
252 CloudProviderPrivate *priv = cloud_provider_get_instance_private(self);
253 gchar *object_path = g_strconcat(priv->object_path, "/", account_name, NULL);
254 GDBusObject *object = g_dbus_object_manager_get_object((GDBusObjectManager*)priv->manager, object_path);
255 CloudProviderAccount1 *account = cloud_provider_object_get_account1 (CLOUD_PROVIDER_OBJECT(object));
256 cloud_provider_account1_emit_cloud_provider_changed (account);
257 g_object_unref (account);
258 g_object_unref (object);
259 g_free (object_path);
260 }
261
262 CloudProvider*
263 cloud_provider_new (GDBusConnection *bus,
264 const gchar *bus_name,
265 const gchar *object_path)
266 {
267 CloudProvider *self;
268 CloudProviderPrivate *priv;
269
270 self = g_object_new (TYPE_CLOUD_PROVIDER, NULL);
271 priv = cloud_provider_get_instance_private (self);
272
273 priv->bus_name = g_strdup (bus_name);
274 priv->object_path = g_strdup (object_path);
275 priv->bus = bus;
276 priv->cancellable = g_cancellable_new ();
277 priv->manager = g_dbus_object_manager_server_new (object_path);
278
279 priv->menuModels = g_hash_table_new(g_str_hash, g_str_equal);
280 priv->actionGroups = g_hash_table_new(g_str_hash, g_str_equal);
281 return self;
282 }
283
284 static void
285 cloud_provider_finalize (GObject *object)
286 {
287 CloudProvider *self = (CloudProvider *)object;
288 CloudProviderPrivate *priv = cloud_provider_get_instance_private (self);
289
290 g_cancellable_cancel (priv->cancellable);
291 g_clear_object (&priv->cancellable);
292 g_clear_object (&priv->bus);
293 g_free (priv->bus_name);
294 g_free (priv->object_path);
295 g_object_unref(priv->manager);
296
297 g_hash_table_remove_all(priv->menuModels);
298 g_object_unref(priv->menuModels);
299 g_hash_table_remove_all(priv->actionGroups);
300 g_object_unref(priv->actionGroups);
301
302 G_OBJECT_CLASS (cloud_provider_parent_class)->finalize (object);
303 }
304
305 static void
306 cloud_provider_class_init (CloudProviderClass *klass)
307 {
308 GObjectClass *object_class = G_OBJECT_CLASS (klass);
309 object_class->finalize = cloud_provider_finalize;
310 }
311
312 static void
313 cloud_provider_init (CloudProvider *self)
314 {
315 }
+0
-92
src/cloudprovider.h less more
0 /* cloudprovider.h
1 *
2 * Copyright (C) 2017 Julius Haertl <jus@bitgrid.net>
3 *
4 * This file is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This file is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef CLOUD_PROVIDER_H
19 #define CLOUD_PROVIDER_H
20
21 #include "cloudprovider-generated.h"
22 /* for CloudProviderStatus enum */
23 #include "cloudprovideraccount.h"
24 #include "cloudprovideraccountexporter.h"
25
26 G_BEGIN_DECLS
27
28 #define TYPE_CLOUD_PROVIDER (cloud_provider_get_type())
29 #define CLOUD_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CLOUD_PROVIDER, CloudProvider))
30 #define CLOUD_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CLOUD_PROVIDER, CloudProviderClass))
31 #define IS_CLOUD_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CLOUD_PROVIDER))
32 #define IS_CLOUD_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CLOUD_PROVIDER))
33 #define CLOUD_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CLOUD_PROVIDER, CloudProviderClass))
34
35 typedef struct _CloudProvider CloudProvider;
36 typedef struct _CloudProviderClass CloudProviderClass;
37
38
39 struct _CloudProviderClass
40 {
41 GObjectClass parent_class;
42 };
43
44 struct _CloudProvider
45 {
46 GObject parent_instance;
47 };
48
49 GType
50 cloud_provider_get_type (void) G_GNUC_CONST;
51 void
52 cloud_provider_export_account (CloudProvider* cloud_provider,
53 const gchar *account_name,
54 CloudProviderAccount1 *account);
55 void
56 cloud_provider_unexport_account (CloudProvider* cloud_provider,
57 const gchar *account_name);
58 guint
59 cloud_provider_export_menu (CloudProvider* cloud_provider,
60 const gchar *account_name,
61 GMenuModel *model);
62 void
63 cloud_provider_unexport_menu (CloudProvider* cloud_provider,
64 const gchar *account_name);
65 guint
66 cloud_provider_export_action_group (CloudProvider* cloud_provider,
67 const gchar *account_name,
68 GActionGroup *action_group);
69 void
70 cloud_provider_unexport_action_group (CloudProvider *cloud_provider,
71 const gchar *account_name);
72
73 void
74 cloud_provider_add_account (CloudProvider *cloud_provider,
75 CloudProviderAccountExporter *account);
76
77 void
78 cloud_provider_export_objects (CloudProvider* cloud_provider);
79
80 void
81 cloud_provider_emit_changed (CloudProvider *cloud_provider, const gchar *account_name);
82
83 CloudProvider*
84 cloud_provider_new (GDBusConnection *bus,
85 const gchar *bus_name,
86 const gchar *object_path);
87
88 G_END_DECLS
89
90
91 #endif /* CLOUD_PROVIDER_H */
0 /* cloudproviderexporter.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 "cloudproviderexporter.h"
20 #include "cloudprovideraccountexporterpriv.h"
21 #include "cloudprovider-generated.h"
22 #include <gio/gio.h>
23
24 typedef struct
25 {
26 GDBusConnection *bus;
27 GDBusObjectManagerServer *manager;
28 gchar *bus_name;
29 gchar *object_path;
30 GCancellable *cancellable;
31 GHashTable *menuModels;
32 GHashTable *actionGroups;
33 } CloudProviderExporterPrivate;
34
35 G_DEFINE_TYPE_WITH_PRIVATE (CloudProviderExporter, cloud_provider_exporter, G_TYPE_OBJECT)
36
37 /**
38 * SECTION:cloudproviderexporter
39 * @title: CloudProviderExporter
40 * @short_description: Base object for representing a single provider
41 * @include: src/cloudproviderexporter.h
42 *
43 * #CloudProviderExporter is the basic object that interacts with UI and actions that a
44 * provider will present to the user.
45 * list view. Extensions can provide #NautilusColumn by registering a
46 * #NautilusColumnProvider and returning them from
47 * nautilus_column_provider_get_columns(), which will be called by the main
48 * application when creating a view.
49 */
50
51 /**
52 * cloud_provider_exporter_add_account:
53 * @self: The cloud provider
54 * @account: The account object
55 *
56 * Each cloud provider can have a variety of account associated with it. Use this
57 * function to export the accounts the user set up.
58 */
59 void
60 cloud_provider_exporter_add_account (CloudProviderExporter *cloud_provider,
61 CloudProviderAccountExporter *account)
62 {
63 CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(cloud_provider);
64 CloudProviderObjectSkeleton *object;
65 gchar *object_path = g_strconcat (priv->object_path, "/", cloud_provider_account_exporter_get_object_name (account), NULL);
66 object = cloud_provider_object_skeleton_new(object_path);
67 cloud_provider_object_skeleton_set_account1(object, CLOUD_PROVIDER_ACCOUNT1 (cloud_provider_account_exporter_get_skeleton (account)));
68 g_dbus_object_manager_server_export (priv->manager, G_DBUS_OBJECT_SKELETON(object));
69 g_free(object_path);
70 }
71
72 /**
73 * cloud_provider_export_account:
74 * @self: The cloud provider
75 * @account_name: The account name
76 * @account: The account object
77 *
78 * Each cloud provider can have a variety of account associated with it. Use this
79 * function to export the accounts the user set up.
80 */
81 void
82 cloud_provider_exporter_export_account(CloudProviderExporter * self,
83 const gchar *account_name,
84 CloudProviderAccount1 *account)
85 {
86 CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(self);
87 CloudProviderObjectSkeleton *object;
88 gchar *object_path = g_strconcat (priv->object_path, "/", account_name, NULL);
89 object = cloud_provider_object_skeleton_new(object_path);
90 cloud_provider_object_skeleton_set_account1(object, account);
91 g_dbus_object_manager_server_export (priv->manager,
92 G_DBUS_OBJECT_SKELETON(object));
93 g_free(object_path);
94 }
95
96 /**
97 * cloud_provider_exporter_unexport_account:
98 * @self: The cloud provider
99 * @account_name: The name of the account
100 *
101 * Each cloud provider can have a variety of account associated with it. Use this
102 * function to remove an already set up account.
103 */
104 void
105 cloud_provider_exporter_unexport_account(CloudProviderExporter *self,
106 const gchar *account_name)
107 {
108 CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(self);
109 gchar *object_path = g_strconcat (priv->object_path, "/", account_name, NULL);
110 g_dbus_object_manager_server_unexport (priv->manager, object_path);
111 guint *export_id;
112 export_id = (guint*)g_hash_table_lookup(priv->menuModels, account_name);
113 if(export_id != NULL) {
114 g_dbus_connection_unexport_menu_model(priv->bus, *export_id);
115 g_free(export_id);
116 }
117 export_id = (guint*)g_hash_table_lookup(priv->actionGroups, account_name);
118 if(export_id != NULL) {
119 g_dbus_connection_unexport_action_group(priv->bus, *export_id);
120 g_free(export_id);
121 }
122 g_free (object_path);
123 }
124
125 /**
126 * cloud_provider_exporter_export_menu:
127 * @self: The cloud provider
128 * @account_name: The name of the account
129 *
130 * One of the benefits of the integration is to display a menu with available
131 * options for an account. Use this function to export a GMenuModel menu to be
132 * displayed by the choosen integration by the desktop environment or application.
133 */
134 guint
135 cloud_provider_exporter_export_menu(CloudProviderExporter *self,
136 const gchar *account_name,
137 GMenuModel *model)
138 {
139 CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(self);
140 gchar *object_path = g_strconcat(priv->object_path, "/", account_name, NULL);
141 GError *error = NULL;
142 guint *export_id = g_new0(guint, 1);
143 *export_id = g_dbus_connection_export_menu_model (priv->bus, object_path, model, &error);
144 if (!*export_id)
145 {
146 g_warning ("Menu export failed: %s", error->message);
147 return 0;
148 }
149 g_hash_table_insert(priv->menuModels, g_strdup(account_name), export_id);
150 return *export_id;
151 }
152
153 /**
154 * cloud_provider_exporter_unexport_menu:
155 * @self: The cloud provider
156 * @account_name: The name of the account
157 *
158 * Remove the menu added with cloud_provider_exporter_export_menu
159 */
160 void
161 cloud_provider_exporter_unexport_menu(CloudProviderExporter *self,
162 const gchar *account_name)
163 {
164 CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(self);
165 guint *export_id;
166 export_id = (guint*)g_hash_table_lookup(priv->menuModels, account_name);
167 if(export_id != NULL) {
168 g_dbus_connection_unexport_menu_model(priv->bus, *export_id);
169 g_hash_table_remove (priv->menuModels, account_name);
170 g_free(export_id);
171 }
172 }
173
174 /**
175 * cloud_provider_exporter_action_group:
176 * @self: The cloud provider
177 * @account_name: The name of the account
178 * @action_group: The GActionGroup to be used by the menu exported by cloud_provider_exporter_export_menu
179 *
180 * In order for a menu exported with cloud_provider_exporter_export_menu to receive events
181 * that will eventually call your callbacks, it needs the corresponding GAcionGroup.
182 * Use this function to export it.
183 */
184 guint
185 cloud_provider_exporter_export_action_group(CloudProviderExporter *self,
186 const gchar *account_name,
187 GActionGroup *action_group)
188 {
189 CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(self);
190 gchar *object_path = g_strconcat(priv->object_path, "/", account_name, NULL);
191 GError *error = NULL;
192 guint *export_id = g_new0(guint, 1);
193 *export_id = g_dbus_connection_export_action_group (priv->bus, object_path, action_group, &error);
194 if (!*export_id)
195 {
196 g_warning ("Action export failed: %s", error->message);
197 return 0;
198 }
199 g_hash_table_insert(priv->actionGroups, g_strdup(account_name), export_id);
200 return *export_id;
201 }
202
203 /**
204 * cloud_provider_exporter_unexport_action_group:
205 * @self: The cloud provider
206 * @account_name: The name of the account
207 *
208 * Unexport the GActionGroup exported by cloud_provider_exporter_export_action_group
209 */
210 void
211 cloud_provider_exporter_unexport_action_group(CloudProviderExporter *self,
212 const gchar *account_name)
213 {
214 CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(self);
215 guint *export_id;
216 export_id = (guint*)g_hash_table_lookup(priv->actionGroups, account_name);
217 if(export_id != NULL) {
218 g_dbus_connection_unexport_action_group(priv->bus, *export_id);
219 g_hash_table_remove (priv->actionGroups, account_name);
220 g_free(export_id);
221 }
222 }
223
224 /**
225 * cloud_provider_exporter_export_objects:
226 * @self: The cloud provider
227 *
228 * Export all objects assigned previously with functions like cloud_provider_exporter_export_account
229 * to DBUS.
230 * Use this function after exporting all the required object to avoid multiple signals
231 * being emitted in a short time.
232 */
233 void
234 cloud_provider_exporter_export_objects(CloudProviderExporter * self)
235 {
236 CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(self);
237 g_dbus_object_manager_server_set_connection (priv->manager, priv->bus);
238 }
239
240 /**
241 * cloud_provider_exporter_emit_changed:
242 * @self: The cloud provider
243 * @account_name: The name of the account
244 *
245 * When an account changes its status, emit a signal to DBUS using this function
246 * so clients are aware of the change.
247 */
248 void
249 cloud_provider_exporter_emit_changed (CloudProviderExporter *self,
250 const gchar *account_name)
251 {
252 CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(self);
253 gchar *object_path = g_strconcat(priv->object_path, "/", account_name, NULL);
254 GDBusObject *object = g_dbus_object_manager_get_object((GDBusObjectManager*)priv->manager, object_path);
255 CloudProviderAccount1 *account = cloud_provider_object_get_account1 (CLOUD_PROVIDER_OBJECT(object));
256 cloud_provider_account1_emit_cloud_provider_changed (account);
257 g_object_unref (account);
258 g_object_unref (object);
259 g_free (object_path);
260 }
261
262 CloudProviderExporter *
263 cloud_provider_exporter_new (GDBusConnection *bus,
264 const gchar *bus_name,
265 const gchar *object_path)
266 {
267 CloudProviderExporter *self;
268 CloudProviderExporterPrivate *priv;
269
270 self = g_object_new (TYPE_CLOUD_PROVIDER_EXPORTER, NULL);
271 priv = cloud_provider_exporter_get_instance_private (self);
272
273 priv->bus_name = g_strdup (bus_name);
274 priv->object_path = g_strdup (object_path);
275 priv->bus = bus;
276 priv->cancellable = g_cancellable_new ();
277 priv->manager = g_dbus_object_manager_server_new (object_path);
278
279 priv->menuModels = g_hash_table_new(g_str_hash, g_str_equal);
280 priv->actionGroups = g_hash_table_new(g_str_hash, g_str_equal);
281 return self;
282 }
283
284 static void
285 cloud_provider_exporter_finalize (GObject *object)
286 {
287 CloudProviderExporter *self = (CloudProviderExporter *)object;
288 CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private (self);
289
290 g_cancellable_cancel (priv->cancellable);
291 g_clear_object (&priv->cancellable);
292 g_clear_object (&priv->bus);
293 g_free (priv->bus_name);
294 g_free (priv->object_path);
295 g_object_unref(priv->manager);
296
297 g_hash_table_remove_all(priv->menuModels);
298 g_object_unref(priv->menuModels);
299 g_hash_table_remove_all(priv->actionGroups);
300 g_object_unref(priv->actionGroups);
301
302 G_OBJECT_CLASS (cloud_provider_exporter_parent_class)->finalize (object);
303 }
304
305 static void
306 cloud_provider_exporter_class_init (CloudProviderExporterClass *klass)
307 {
308 GObjectClass *object_class = G_OBJECT_CLASS (klass);
309 object_class->finalize = cloud_provider_exporter_finalize;
310 }
311
312 static void
313 cloud_provider_exporter_init (CloudProviderExporter *self)
314 {
315 }
0 /* cloudprovider.h
1 *
2 * Copyright (C) 2017 Julius Haertl <jus@bitgrid.net>
3 *
4 * This file is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This file is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef CLOUD_PROVIDER_EXPORTER_H
19 #define CLOUD_PROVIDER_EXPORTER_H
20
21 #include "cloudprovider-generated.h"
22 /* for CloudProviderStatus enum */
23 #include "cloudprovideraccount.h"
24 #include "cloudprovideraccountexporter.h"
25
26 G_BEGIN_DECLS
27
28 #define TYPE_CLOUD_PROVIDER_EXPORTER (cloud_provider_exporter_get_type())
29 #define CLOUD_PROVIDER_EXPORTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CLOUD_PROVIDER_EXPORTER, CloudProviderExporter))
30 #define CLOUD_PROVIDER_EXPORTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CLOUD_PROVIDER_EXPORTER, CloudProviderExporterClass))
31 #define IS_CLOUD_PROVIDER_EXPORTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CLOUD_PROVIDER_EXPORTER))
32 #define IS_CLOUD_PROVIDER_EXPORTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CLOUD_PROVIDER_EXPORTER))
33 #define CLOUD_PROVIDER_EXPORTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CLOUD_PROVIDER_EXPORTER, CloudProviderExporterClass))
34
35 typedef struct _CloudProviderExporter CloudProviderExporter;
36 typedef struct _CloudProviderExporterClass CloudProviderExporterClass;
37
38
39 struct _CloudProviderExporterClass
40 {
41 GObjectClass parent_class;
42 };
43
44 struct _CloudProviderExporter
45 {
46 GObject parent_instance;
47 };
48
49 GType
50 cloud_provider_exporter_get_type (void) G_GNUC_CONST;
51 void
52 cloud_provider_exporter_export_account (CloudProviderExporter *cloud_provider_exporter,
53 const gchar *account_name,
54 CloudProviderAccount1 *account);
55 void
56 cloud_provider_exporter_unexport_account (CloudProviderExporter *cloud_provider_exporter,
57 const gchar *account_name);
58 guint
59 cloud_provider_exporter_export_menu (CloudProviderExporter *cloud_provider_exporter,
60 const gchar *account_name,
61 GMenuModel *model);
62 void
63 cloud_provider_exporter_unexport_menu (CloudProviderExporter *cloud_provider_exporter,
64 const gchar *account_name);
65 guint
66 cloud_provider_exporter_export_action_group (CloudProviderExporter *cloud_provider_exporter,
67 const gchar *account_name,
68 GActionGroup *action_group);
69 void
70 cloud_provider_exporter_unexport_action_group (CloudProviderExporter *cloud_provider_exporter,
71 const gchar *account_name);
72
73 void
74 cloud_provider_exporter_add_account (CloudProviderExporter *cloud_provider_exporter,
75 CloudProviderAccountExporter *account);
76
77 void
78 cloud_provider_exporter_export_objects (CloudProviderExporter *cloud_provider_exporter);
79
80 void
81 cloud_provider_exporter_emit_changed (CloudProviderExporter *cloud_provider_exporter,
82 const gchar *account_name);
83
84 CloudProviderExporter*
85 cloud_provider_exporter_new (GDBusConnection *bus,
86 const gchar *bus_name,
87 const gchar *object_path);
88
89 G_END_DECLS
90
91
92 #endif /* CLOUD_PROVIDER_EXPORTER_H */
11 'cloudprovidermanager.h',
22 'cloudprovideraccount.h',
33 'cloudproviders.h',
4 'cloudprovider.h',
4 'cloudproviderexporter.h',
55 'cloudprovideraccountexporter.h',
66 ]
77
99 'cloudprovidermanager.c',
1010 'cloudprovideraccount.c',
1111 'cloudproviders.c',
12 'cloudprovider.c',
12 'cloudproviderexporter.c',
1313 'cloudprovideraccountexporter.c',
1414 ]
1515
00 #include <glib.h>
11 #include <stdlib.h>
22 #include <gio/gio.h>
3 #include <cloudprovider.h>
3 #include <cloudproviderexporter.h>
44 #include <cloudprovideraccountexporter.h>
55 /* for CLoudProviderStatus enum */
66 #include <cloudprovideraccount.h>
2929 gchar *path;
3030 guint timeout_handler;
3131 GDBusConnection *connection;
32 CloudProvider *cloud_provider;
32 CloudProviderExporter *cloud_provider;
3333 GDBusObjectManagerServer *manager;
3434 };
3535
231231 account_object_name = g_strdup_printf ("MyCloud%d", account_id);
232232 g_print ("Change status of %03d to %d\n", account_id, new_status);
233233 test_cloud_provider_set_status (test_cloud_provider, new_status);
234 cloud_provider_emit_changed (test_cloud_provider->cloud_provider, account_object_name);
234 cloud_provider_exporter_emit_changed (test_cloud_provider->cloud_provider, account_object_name);
235235 return TRUE;
236236 }
237237
297297 guint n;
298298
299299 self->connection = connection;
300 self->cloud_provider = cloud_provider_new(self->connection,
301 TEST_CLOUD_PROVIDER_BUS_NAME,
302 TEST_CLOUD_PROVIDER_OBJECT_PATH);
300 self->cloud_provider = cloud_provider_exporter_new(self->connection,
301 TEST_CLOUD_PROVIDER_BUS_NAME,
302 TEST_CLOUD_PROVIDER_OBJECT_PATH);
303303
304304 g_debug ("Registering cloud provider server 'MyCloud'\n");
305305
316316 g_signal_connect(cloud_provider_account_exporter, "handle_get_status", G_CALLBACK (on_get_status), self);
317317 g_signal_connect(cloud_provider_account_exporter, "handle_get_status_details", G_CALLBACK (on_get_status_details), self);
318318
319 cloud_provider_add_account(self->cloud_provider, cloud_provider_account_exporter);
320 cloud_provider_export_menu (self->cloud_provider, account_object_name, get_model ());
321 cloud_provider_export_action_group (self->cloud_provider, account_object_name, get_action_group ());
319 cloud_provider_exporter_add_account(self->cloud_provider, cloud_provider_account_exporter);
320 cloud_provider_exporter_export_menu (self->cloud_provider, account_object_name, get_model ());
321 cloud_provider_exporter_export_action_group (self->cloud_provider, account_object_name, get_action_group ());
322322
323323 g_free(account_object_name);
324324 }
325325
326 cloud_provider_export_objects (self->cloud_provider);
326 cloud_provider_exporter_export_objects (self->cloud_provider);
327327
328328 return;
329329 }