general: Rename objects and provide GObject prefixes
Unfortunately the library was made without GObject prefixes, which makes
introspection impossible (and is wrong to do it this way anyway).
Take the opportunity to rename various objects, use new glib type
declarations, add prefixes and rename the files accordingly.
Carlos Soriano
6 years ago
0 | <!DOCTYPE node PUBLIC | |
1 | "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" | |
2 | "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> | |
3 | ||
4 | <!-- | |
5 | This library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2 of the License, or (at your option) any later version. | |
9 | ||
10 | This library is distributed in the hope that it will be useful, | |
11 | but 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 Lesser General | |
16 | Public License along with this library; if not, see <http://www.gnu.org/licenses/>. | |
17 | --> | |
18 | <node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd"> | |
19 | <interface name='org.freedesktop.CloudProviders.Provider'> | |
20 | <method name='GetName'> | |
21 | <arg type='s' name='name' direction='out'/> | |
22 | </method> | |
23 | <property name="Name" type="s" access="read"/> | |
24 | </interface> | |
25 | ||
26 | <interface name='org.freedesktop.CloudProviders.Account'> | |
27 | <method name='GetName'> | |
28 | <arg type='s' name='name' direction='out'/> | |
29 | </method> | |
30 | <property name="Name" type="s" access="read"/> | |
31 | <property name="Path" type="s" access="read"/> | |
32 | <property name="Icon" type="s" access="read"/> | |
33 | <property name="Status" type="i" access="read"/> | |
34 | <property name="StatusDetails" type="s" access="read"/> | |
35 | </interface> | |
36 | </node> |
0 | <!DOCTYPE node PUBLIC | |
1 | "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" | |
2 | "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> | |
3 | ||
4 | <!-- | |
5 | This library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2 of the License, or (at your option) any later version. | |
9 | ||
10 | This library is distributed in the hope that it will be useful, | |
11 | but 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 Lesser General | |
16 | Public License along with this library; if not, see <http://www.gnu.org/licenses/>. | |
17 | --> | |
18 | <node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd"> | |
19 | <interface name='org.freedesktop.CloudProvider.Account1'> | |
20 | <method name='GetName'> | |
21 | <arg type='s' name='name' direction='out'/> | |
22 | </method> | |
23 | <method name='GetStatus'> | |
24 | <arg type='i' name='status' direction='out'/> | |
25 | </method> | |
26 | <method name='GetStatusDetails'> | |
27 | <arg type='s' name='path' direction='out'/> | |
28 | </method> | |
29 | <method name='GetIcon'> | |
30 | <arg type='v' name='icon' direction='out'/> | |
31 | </method> | |
32 | <method name='GetPath'> | |
33 | <arg type='s' name='path' direction='out'/> | |
34 | </method> | |
35 | <signal name="CloudProviderChanged"></signal> | |
36 | </interface> | |
37 | </node> |
0 | <!DOCTYPE node PUBLIC | |
1 | "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" | |
2 | "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> | |
3 | ||
4 | <!-- | |
5 | This library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2 of the License, or (at your option) any later version. | |
9 | ||
10 | This library is distributed in the hope that it will be useful, | |
11 | but 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 Lesser General | |
16 | Public License along with this library; if not, see <http://www.gnu.org/licenses/>. | |
17 | --> | |
18 | <node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd"> | |
19 | <interface name='org.freedesktop.CloudProvider.Manager1'> | |
20 | <method name="GetCloudProviders"> | |
21 | <arg type="a(so)" name="providers" direction="out" /> | |
22 | </method> | |
23 | </interface> | |
24 | </node> |
41 | 41 | This part documents libcloudproviders libs. |
42 | 42 | </para> |
43 | 43 | </partintro> |
44 | <xi:include href="xml/cloudproviderexporter.xml"/> | |
45 | <xi:include href="xml/cloudprovideraccountexporter.xml"/> | |
46 | <xi:include href="xml/cloudproviders.xml"/> | |
47 | <xi:include href="xml/cloudprovideraccount.xml"/> | |
44 | <xi:include href="xml/cloudproviderscollector.xml"/> | |
45 | <xi:include href="xml/cloudprovidersproviderexporter.xml"/> | |
46 | <xi:include href="xml/cloudprovidersaccountexporter.xml"/> | |
47 | <xi:include href="xml/cloudprovidersaccount.xml"/> | |
48 | <xi:include href="xml/cloudprovidersprovider.xml"/> | |
48 | 49 | </part> |
49 | 50 | |
50 | 51 | <part id="libcloudproviders-integration"> |
59 | 60 | <para> |
60 | 61 | </para> |
61 | 62 | </partintro> |
62 | <xi:include href="generated-docs-org.freedesktop.CloudProvider.Account1.xml"/> | |
63 | <xi:include href="generated-docs-org.freedesktop.CloudProvider.Manager1.xml"/> | |
63 | <xi:include href="generated-docs-org.freedesktop.CloudProviders.Account1.xml"/> | |
64 | <xi:include href="generated-docs-org.freedesktop.CloudProviders.Manager1.xml"/> | |
65 | <xi:include href="generated-docs-org.freedesktop.CloudProviders.Provider1.xml"/> | |
64 | 66 | </part> |
65 | 67 | |
66 | 68 | <part id="cloudprovidersd"> |
0 | 0 | <SECTION> |
1 | <FILE>cloudproviderexporter</FILE> | |
2 | <TITLE>CloudProviderexporter</TITLE> | |
3 | cloud_provider_exporter_new | |
4 | cloud_provider_exporter_add_account | |
5 | cloud_provider_exporter_remove_account | |
6 | cloud_provider_exporter_export_objects | |
7 | cloud_provider_exporter_emit_account_changed | |
8 | CloudProviderExporter | |
9 | CloudProviderExporterClass | |
10 | <SUBSECTION Standard> | |
11 | CLOUD_PROVIDER_EXPORTER | |
12 | CLOUD_PROVIDER_EXPORTER_CLASS | |
13 | CLOUD_PROVIDER_EXPORTER_GET_CLASS | |
14 | IS_CLOUD_PROVIDER_EXPORTER | |
15 | IS_CLOUD_PROVIDER_EXPORTER_CLASS | |
16 | TYPE_CLOUD_PROVIDER_EXPORTER | |
17 | cloud_provider_exporter_get_type | |
1 | <FILE>cloudprovidersaccount</FILE> | |
2 | <TITLE>CloudProvidersAccount</TITLE> | |
3 | CloudProvidersAccountStatus | |
4 | CLOUD_PROVIDERS_TYPE_ACCOUNT | |
5 | CloudProvidersAccountClass | |
6 | cloud_providers_account_new | |
7 | cloud_providers_account_get_name | |
8 | cloud_providers_account_get_status | |
9 | cloud_providers_account_get_status_details | |
10 | cloud_providers_account_get_icon | |
11 | cloud_providers_account_get_menu_model | |
12 | cloud_providers_account_get_action_group | |
13 | cloud_providers_account_get_path | |
14 | CloudProvidersAccount | |
18 | 15 | </SECTION> |
19 | 16 | |
20 | 17 | <SECTION> |
21 | <FILE>cloudprovideraccountexporter</FILE> | |
22 | <TITLE>CloudProviderAccountExporter</TITLE> | |
23 | cloud_provider_account_exporter_new | |
24 | cloud_provider_account_exporter_add_menu_model | |
25 | cloud_provider_account_exporter_add_action_group | |
26 | cloud_provider_account_exporter_remove_menu | |
27 | cloud_provider_account_exporter_remove_action_group | |
28 | CloudProviderAccountExporter::handle-get-name | |
29 | CloudProviderAccountExporter::handle-get-icon | |
30 | CloudProviderAccountExporter::handle-get-status | |
31 | CloudProviderAccountExporter::handle-get-status-details | |
32 | CloudProviderAccountExporter::handle-get-path | |
33 | CloudProviderAccountExporter | |
34 | CloudProviderAccountExporterClass | |
35 | <SUBSECTION Standard> | |
36 | CLOUD_PROVIDER_ACCOUNT_EXPORTER | |
37 | CLOUD_PROVIDER_ACCOUNT_EXPORTER_CLASS | |
38 | CLOUD_PROVIDER_ACCOUNT_EXPORTER_GET_CLASS | |
39 | IS_CLOUD_PROVIDER_ACCOUNT_EXPORTER | |
40 | IS_CLOUD_PROVIDER_ACCOUNT_EXPORTER_CLASS | |
41 | TYPE_CLOUD_PROVIDER_ACCOUNT_EXPORTER | |
42 | cloud_provider_account_exporter_get_type | |
18 | <FILE>cloudprovidersaccountexporter</FILE> | |
19 | <TITLE>CloudProvidersAccountExporter</TITLE> | |
20 | CLOUD_PROVIDERS_TYPE_ACCOUNT_EXPORTER | |
21 | CloudProvidersAccountExporterClass | |
22 | cloud_providers_account_exporter_new | |
23 | cloud_providers_account_exporter_set_name | |
24 | cloud_providers_account_exporter_set_status | |
25 | cloud_providers_account_exporter_set_status_details | |
26 | cloud_providers_account_exporter_set_icon | |
27 | cloud_providers_account_exporter_set_menu_model | |
28 | cloud_providers_account_exporter_set_action_group | |
29 | cloud_providers_account_exporter_set_path | |
30 | CloudProvidersAccountExporter | |
31 | CloudProvidersProviderExporter | |
43 | 32 | </SECTION> |
44 | 33 | |
45 | 34 | <SECTION> |
46 | <FILE>cloudprovideraccount</FILE> | |
47 | <TITLE>CloudProviderAccount</TITLE> | |
48 | CloudProviderStatus | |
49 | cloud_provider_account_new | |
50 | cloud_provider_account_get_name | |
51 | cloud_provider_account_get_status | |
52 | cloud_provider_account_get_status_details | |
53 | cloud_provider_account_get_icon | |
54 | cloud_provider_account_get_menu_model | |
55 | cloud_provider_account_get_action_group | |
56 | cloud_provider_account_get_path | |
57 | cloud_provider_account_get_owner | |
58 | cloud_provider_account_is_available | |
59 | cloud_provider_account_update | |
60 | CloudProviderAccount | |
61 | CloudProviderAccountClass | |
62 | <SUBSECTION Standard> | |
63 | CLOUD_PROVIDER_ACCOUNT | |
64 | CLOUD_PROVIDER_ACCOUNT_CLASS | |
65 | CLOUD_PROVIDER_ACCOUNT_GET_CLASS | |
66 | IS_CLOUD_PROVIDER_ACCOUNT | |
67 | IS_CLOUD_PROVIDER_ACCOUNT_CLASS | |
68 | TYPE_CLOUD_PROVIDER_ACCOUNT | |
69 | cloud_provider_account_get_type | |
35 | <FILE>cloudproviderscollector</FILE> | |
36 | <TITLE>CloudProvidersCollector</TITLE> | |
37 | CLOUD_PROVIDERS_TYPE_COLLECTOR | |
38 | CloudProvidersCollectorClass | |
39 | cloud_providers_collector_dup_singleton | |
40 | cloud_providers_collector_update | |
41 | cloud_providers_collector_get_providers | |
42 | CloudProvidersCollector | |
70 | 43 | </SECTION> |
71 | 44 | |
72 | 45 | <SECTION> |
73 | <FILE>cloudproviders</FILE> | |
74 | <TITLE>CloudProviders</TITLE> | |
75 | cloud_providers_dup_singleton | |
76 | cloud_providers_update | |
77 | cloud_providers_get_providers | |
78 | CloudProviders | |
79 | CloudProvidersClass | |
80 | <SUBSECTION Standard> | |
81 | CLOUD_PROVIDERS | |
82 | CLOUD_PROVIDERS_CLASS | |
83 | CLOUD_PROVIDERS_GET_CLASS | |
84 | IS_CLOUD_PROVIDERS | |
85 | IS_CLOUD_PROVIDERS_CLASS | |
86 | TYPE_CLOUD_PROVIDERS | |
87 | cloud_providers_get_type | |
46 | <FILE>cloudprovidersmanager</FILE> | |
47 | <TITLE>CloudProvidersManager</TITLE> | |
48 | CLOUD_PROVIDERS_MANAGER_DBUS_IFACE | |
49 | CLOUD_PROVIDERS_MANAGER_DBUS_NAME | |
50 | CLOUD_PROVIDERS_MANAGER_DBUS_PATH | |
51 | CLOUD_PROVIDERS_TYPE_MANAGER | |
52 | CloudProvidersManagerClass | |
53 | cloud_providers_manager_new | |
54 | CloudProvidersManager | |
88 | 55 | </SECTION> |
89 | 56 | |
57 | <SECTION> | |
58 | <FILE>cloudprovidersprovider</FILE> | |
59 | CLOUD_PROVIDERS_PROVIDER_DBUS_IFACE | |
60 | CLOUD_PROVIDERS_PROVIDER_DBUS_NAME | |
61 | CLOUD_PROVIDERS_PROVIDER_DBUS_PATH | |
62 | CLOUD_PROVIDERS_TYPE_PROVIDER | |
63 | cloud_providers_provider_new | |
64 | cloud_providers_provider_get_name | |
65 | cloud_providers_provider_get_accounts | |
66 | CloudProvidersProvider | |
67 | </SECTION> | |
68 | ||
69 | <SECTION> | |
70 | <FILE>cloudprovidersproviderexporter</FILE> | |
71 | <TITLE>CloudProvidersProviderExporter</TITLE> | |
72 | CLOUD_PROVIDERS_TYPE_PROVIDER_EXPORTER | |
73 | CloudProvidersProviderExporterClass | |
74 | cloud_providers_provider_exporter_add_account | |
75 | cloud_providers_provider_exporter_remove_account | |
76 | cloud_providers_provider_exporter_set_name | |
77 | cloud_providers_provider_exporter_get_name | |
78 | cloud_providers_provider_exporter_new | |
79 | cloud_providers_provider_exporter_get_object_path | |
80 | cloud_providers_provider_exporter_get_bus | |
81 | CloudProvidersProviderExporter | |
82 | </SECTION> |
4 | 4 | configuration: cdata) |
5 | 5 | |
6 | 6 | codegen = find_program('gdbus-codegen') |
7 | message ('----------------------------') | |
7 | 8 | message('Generating DBUS docs…') |
8 | 9 | run_command('gdbus-codegen', '--generate-docbook', 'generated-docs', |
9 | join_paths(meson.source_root(), 'data/cloudprovider-dbus.xml'), | |
10 | join_paths(meson.source_root(), 'data/cloudprovidermanager-dbus.xml'), | |
10 | join_paths(meson.source_root(), 'data/cloud-providers-account-dbus.xml'), | |
11 | join_paths(meson.source_root(), 'data/cloud-providers-manager-dbus.xml'), | |
12 | join_paths(meson.source_root(), 'data/cloud-providers-provider-dbus.xml'), | |
11 | 13 | '--output-directory', join_paths(meson.source_root(), 'docs/reference')) |
12 | 14 | |
13 | 15 | gnome.gtkdoc('libcloudproviders', |
15 | 17 | dependencies: [libcloudproviders_dep], |
16 | 18 | gobject_typesfile: 'libcloudproviders.types', |
17 | 19 | main_xml: 'libcloudproviders-docs.xml', |
18 | content_files: ['generated-docs-org.freedesktop.CloudProvider.Account1.xml', | |
19 | 'generated-docs-org.freedesktop.CloudProvider.Manager1.xml'], | |
20 | content_files: ['generated-docs-org.freedesktop.CloudProviders.Account1.xml', | |
21 | 'generated-docs-org.freedesktop.CloudProviders.Manager1.xml', | |
22 | 'generated-docs-org.freedesktop.CloudProviders.Provider1.xml'], | |
20 | 23 | install : true, |
21 | scan_args: ['--ignore-headers=cloudprovidermanager.h', | |
24 | scan_args: ['--ignore-headers=cloudprovidersmanager.h', | |
22 | 25 | '--rebuild-types']) |
26 | ||
27 | message ('----------------------------') |
51 | 51 | subdir ('src') |
52 | 52 | subdir ('test') |
53 | 53 | if get_option ('enable-gtk-doc') |
54 | message ('####Going into docs') | |
54 | 55 | subdir ('docs/reference') |
55 | 56 | endif |
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 | /** | |
302 | * cloud_provider_account_new | |
303 | * @bus_name: DBus bus name | |
304 | * @object_path: Path to export the DBus object to | |
305 | * | |
306 | * A #CloudProviderAccount object are used to fetch details about cloud providers from DBus. | |
307 | * Object are usually fetched from cloud_providers_get_providers() as a list. | |
308 | */ | |
309 | CloudProviderAccount* | |
310 | cloud_provider_account_new (const gchar *bus_name, | |
311 | const gchar *object_path) | |
312 | { | |
313 | CloudProviderAccount *self; | |
314 | CloudProviderAccountPrivate *priv; | |
315 | ||
316 | self = g_object_new (TYPE_CLOUD_PROVIDER_ACCOUNT, NULL); | |
317 | priv = cloud_provider_account_get_instance_private (self); | |
318 | ||
319 | priv->bus_name = g_strdup (bus_name); | |
320 | priv->object_path = g_strdup (object_path); | |
321 | priv->cancellable = g_cancellable_new (); | |
322 | priv->status = CLOUD_PROVIDER_STATUS_INVALID; | |
323 | priv->ready = FALSE; | |
324 | g_bus_get (G_BUS_TYPE_SESSION, | |
325 | priv->cancellable, | |
326 | on_bus_acquired, | |
327 | self); | |
328 | ||
329 | return self; | |
330 | } | |
331 | ||
332 | static void | |
333 | cloud_provider_account_finalize (GObject *object) | |
334 | { | |
335 | CloudProviderAccount *self = (CloudProviderAccount *)object; | |
336 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
337 | ||
338 | g_cancellable_cancel (priv->cancellable); | |
339 | g_clear_object (&priv->cancellable); | |
340 | g_free (priv->name); | |
341 | g_free (priv->path); | |
342 | g_clear_object (&priv->icon); | |
343 | g_clear_object (&priv->action_group); | |
344 | g_clear_object (&priv->bus); | |
345 | g_clear_object (&priv->proxy); | |
346 | g_free (priv->bus_name); | |
347 | g_free (priv->object_path); | |
348 | ||
349 | G_OBJECT_CLASS (cloud_provider_account_parent_class)->finalize (object); | |
350 | } | |
351 | ||
352 | static void | |
353 | cloud_provider_account_class_init (CloudProviderAccountClass *klass) | |
354 | { | |
355 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
356 | ||
357 | object_class->finalize = cloud_provider_account_finalize; | |
358 | ||
359 | /** | |
360 | * CloudProviderAccount::changed | |
361 | * | |
362 | * This signal is emmited by an account if any information has changed. | |
363 | * Any UI elements should be updated after receiving this signal | |
364 | */ | |
365 | gSignals [CHANGED] = | |
366 | g_signal_new ("changed", | |
367 | G_TYPE_FROM_CLASS (klass), | |
368 | G_SIGNAL_RUN_LAST, | |
369 | 0, | |
370 | NULL, | |
371 | NULL, | |
372 | g_cclosure_marshal_generic, | |
373 | G_TYPE_NONE, | |
374 | 0); | |
375 | /** | |
376 | * CloudProviderAccount::ready | |
377 | * | |
378 | * This signal is emmited by an account if an initial set of information | |
379 | * has been fetched from DBus. Use this to get notified if the account details | |
380 | * are ready to be read after startup. | |
381 | */ | |
382 | gSignals [READY] = | |
383 | g_signal_new ("ready", | |
384 | G_TYPE_FROM_CLASS (klass), | |
385 | G_SIGNAL_RUN_LAST, | |
386 | 0, | |
387 | NULL, | |
388 | NULL, | |
389 | g_cclosure_marshal_generic, | |
390 | G_TYPE_NONE, | |
391 | 0); | |
392 | } | |
393 | ||
394 | static void | |
395 | cloud_provider_account_init (CloudProviderAccount *self) | |
396 | { | |
397 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
398 | ||
399 | priv->status = CLOUD_PROVIDER_STATUS_INVALID; | |
400 | } | |
401 | ||
402 | /** | |
403 | * cloud_provider_account_get_name: | |
404 | * @self: A cloud provider account | |
405 | * | |
406 | * Get the name of the account | |
407 | * | |
408 | * Returns: The name of the cloud provider account | |
409 | */ | |
410 | gchar* | |
411 | cloud_provider_account_get_name (CloudProviderAccount *self) | |
412 | { | |
413 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
414 | ||
415 | return priv->name; | |
416 | } | |
417 | ||
418 | /** | |
419 | * cloud_provider_account_get_status: | |
420 | * @self: A cloud provider account | |
421 | * | |
422 | * Get the status of the account | |
423 | * | |
424 | * Returns: The status of the cloud provider account | |
425 | */ | |
426 | CloudProviderStatus | |
427 | cloud_provider_account_get_status (CloudProviderAccount *self) | |
428 | { | |
429 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
430 | ||
431 | return priv->status; | |
432 | } | |
433 | ||
434 | /** | |
435 | * cloud_provider_account_get_status_details: | |
436 | * @self: A cloud provider account | |
437 | * | |
438 | * Get the status details of the account | |
439 | * | |
440 | * Returns: The status detail description of the cloud provider account | |
441 | */ | |
442 | gchar* | |
443 | cloud_provider_account_get_status_details (CloudProviderAccount *self) | |
444 | { | |
445 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
446 | ||
447 | return priv->status_details; | |
448 | } | |
449 | ||
450 | /** | |
451 | * cloud_provider_account_get_icon: | |
452 | * @self: A cloud provider account | |
453 | * | |
454 | * Get the icon of the account | |
455 | * | |
456 | * Returns: The icon of the cloud provider account | |
457 | */ | |
458 | GIcon* | |
459 | cloud_provider_account_get_icon (CloudProviderAccount *self) | |
460 | { | |
461 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
462 | ||
463 | return priv->icon; | |
464 | } | |
465 | ||
466 | /** | |
467 | * cloud_provider_account_get_menu_model: | |
468 | * @self: A cloud provider account | |
469 | * | |
470 | * Get the menu model exported for the account | |
471 | * | |
472 | * Returns: The menu model exported by the cloud provider account | |
473 | */ | |
474 | GMenuModel* | |
475 | cloud_provider_account_get_menu_model (CloudProviderAccount *self) | |
476 | { | |
477 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
478 | ||
479 | return priv->menu_model; | |
480 | } | |
481 | ||
482 | /** | |
483 | * cloud_provider_account_get_action_group: | |
484 | * @self: A cloud provider account | |
485 | * | |
486 | * Get the action group exported in addition to the #GMenuModel from | |
487 | * cloud_provider_account_get_menu_model() | |
488 | * | |
489 | * Returns: The action group exported by the cloud provider account | |
490 | */ | |
491 | GActionGroup* | |
492 | cloud_provider_account_get_action_group (CloudProviderAccount *self) | |
493 | { | |
494 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
495 | ||
496 | return priv->action_group; | |
497 | } | |
498 | ||
499 | /** | |
500 | * cloud_provider_account_get_path: | |
501 | * @self: A cloud provider account | |
502 | * | |
503 | * Get the directory path of the account | |
504 | * | |
505 | * Returns: The directory path of the cloud provider account | |
506 | */ | |
507 | gchar * | |
508 | cloud_provider_account_get_path (CloudProviderAccount *self) | |
509 | { | |
510 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
511 | ||
512 | return priv->path; | |
513 | } | |
514 | ||
515 | gchar * | |
516 | cloud_provider_account_get_owner (CloudProviderAccount *self) | |
517 | { | |
518 | CloudProviderAccountPrivate *priv = cloud_provider_account_get_instance_private (self); | |
519 | ||
520 | return g_dbus_proxy_get_name_owner (G_DBUS_PROXY(priv->proxy)); | |
521 | } | |
522 | ||
523 | /** | |
524 | * cloud_provider_account_is_available: | |
525 | * @self: A cloud provider account | |
526 | * | |
527 | * Check if the account is ready to be used. This will check if name, icon, status | |
528 | * and path are set since it cannot be garantued otherwise during startup of the | |
529 | * cloud provider client. | |
530 | */ | |
531 | gboolean cloud_provider_account_is_available(CloudProviderAccount *self) | |
532 | { | |
533 | GIcon *icon; | |
534 | gchar *name; | |
535 | gchar *path; | |
536 | guint status; | |
537 | ||
538 | name = cloud_provider_account_get_name (self); | |
539 | icon = cloud_provider_account_get_icon (self); | |
540 | status = cloud_provider_account_get_status (self); | |
541 | path = cloud_provider_account_get_path (self); | |
542 | if (name == NULL || icon == NULL || path == NULL || status == CLOUD_PROVIDER_STATUS_INVALID) | |
543 | return FALSE; | |
544 | return TRUE; | |
545 | } |
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 | /** | |
27 | * CloudProviderStatus: | |
28 | * @CLOUD_PROVIDER_STATUS_INVALID: Set if the initial state of the account is unknown | |
29 | * @CLOUD_PROVIDER_STATUS_IDLE: Set if the account is in idle mode | |
30 | * @CLOUD_PROVIDER_STATUS_SYNCING: Set if the account is currently synchronizing data | |
31 | * @CLOUD_PROVIDER_STATUS_ERROR: Set if an error occured | |
32 | * | |
33 | * Enum values used to describe the sync status of a cloud providers account | |
34 | **/ | |
35 | typedef enum { | |
36 | CLOUD_PROVIDER_STATUS_INVALID, | |
37 | CLOUD_PROVIDER_STATUS_IDLE, | |
38 | CLOUD_PROVIDER_STATUS_SYNCING, | |
39 | CLOUD_PROVIDER_STATUS_ERROR | |
40 | } CloudProviderStatus; | |
41 | ||
42 | #define TYPE_CLOUD_PROVIDER_ACCOUNT (cloud_provider_account_get_type()) | |
43 | #define CLOUD_PROVIDER_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CLOUD_PROVIDER_ACCOUNT, CloudProviderAccount)) | |
44 | #define CLOUD_PROVIDER_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CLOUD_PROVIDER_ACCOUNT, CloudProviderAccountClass)) | |
45 | #define IS_CLOUD_PROVIDER_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CLOUD_PROVIDER_ACCOUNT)) | |
46 | #define IS_CLOUD_PROVIDER_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CLOUD_PROVIDER_ACCOUNT)) | |
47 | #define CLOUD_PROVIDER_ACCOUNT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CLOUD_PROVIDER_ACCOUNT, CloudProviderAccountClass)) | |
48 | ||
49 | typedef struct _CloudProviderAccount CloudProviderAccount; | |
50 | typedef struct _CloudProviderAccountClass CloudProviderAccountClass; | |
51 | ||
52 | ||
53 | struct _CloudProviderAccountClass | |
54 | { | |
55 | GObjectClass parent_class; | |
56 | }; | |
57 | ||
58 | struct _CloudProviderAccount | |
59 | { | |
60 | GObject parent_instance; | |
61 | }; | |
62 | ||
63 | ||
64 | GType cloud_provider_account_get_type (void) G_GNUC_CONST; | |
65 | CloudProviderAccount *cloud_provider_account_new (const gchar *bus_name, | |
66 | const gchar *object_path); | |
67 | ||
68 | gchar* cloud_provider_account_get_name (CloudProviderAccount *self); | |
69 | CloudProviderStatus cloud_provider_account_get_status (CloudProviderAccount *self); | |
70 | gchar* cloud_provider_account_get_status_details (CloudProviderAccount *self); | |
71 | GIcon *cloud_provider_account_get_icon (CloudProviderAccount *self); | |
72 | GMenuModel *cloud_provider_account_get_menu_model (CloudProviderAccount *self); | |
73 | GActionGroup* cloud_provider_account_get_action_group (CloudProviderAccount *self); | |
74 | gchar *cloud_provider_account_get_path (CloudProviderAccount *self); | |
75 | gchar *cloud_provider_account_get_owner (CloudProviderAccount *self); | |
76 | gboolean cloud_provider_account_is_available(CloudProviderAccount *self); | |
77 | void cloud_provider_account_update (CloudProviderAccount *self); | |
78 | G_END_DECLS | |
79 | ||
80 | ||
81 | #endif /* CLOUD_PROVIDER_ACCOUNT_H */ |
0 | /* cloudprovideraccountexporter.c | |
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 | #include <gio/gio.h> | |
19 | #include "cloudprovideraccountexporter.h" | |
20 | #include "cloudprovideraccountexporterpriv.h" | |
21 | #include "cloudprovider-generated.h" | |
22 | ||
23 | typedef struct | |
24 | { | |
25 | gchar *object_name; | |
26 | CloudProviderAccount1 *skeleton; | |
27 | GMenuModel *menu_model; | |
28 | GActionGroup *action_group; | |
29 | } CloudProviderAccountExporterPrivate; | |
30 | ||
31 | G_DEFINE_TYPE_WITH_PRIVATE (CloudProviderAccountExporter, cloud_provider_account_exporter, G_TYPE_OBJECT) | |
32 | ||
33 | /** | |
34 | * SECTION:cloudprovideraccountexporter | |
35 | * @title: CloudProviderAccountExporter | |
36 | * @short_description: Base object for representing a cloud providers account | |
37 | * @include: src/cloudprovideraccountexporter.h | |
38 | */ | |
39 | ||
40 | gchar * | |
41 | cloud_provider_account_exporter_get_object_name (CloudProviderAccountExporter *self) | |
42 | { | |
43 | CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self); | |
44 | return priv->object_name; | |
45 | } | |
46 | ||
47 | GMenuModel * | |
48 | cloud_provider_account_exporter_get_menu_model (CloudProviderAccountExporter *self) | |
49 | { | |
50 | CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self); | |
51 | return priv->menu_model; | |
52 | } | |
53 | ||
54 | GActionGroup * | |
55 | cloud_provider_account_exporter_get_action_group (CloudProviderAccountExporter *self) | |
56 | { | |
57 | CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self); | |
58 | return priv->action_group; | |
59 | } | |
60 | ||
61 | GDBusInterfaceSkeleton* | |
62 | cloud_provider_account_exporter_get_skeleton (CloudProviderAccountExporter *self) | |
63 | { | |
64 | CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self); | |
65 | return G_DBUS_INTERFACE_SKELETON(priv->skeleton); | |
66 | } | |
67 | ||
68 | static void | |
69 | on_get_name (CloudProviderAccountExporter *self, | |
70 | GDBusMethodInvocation *invocation, | |
71 | gpointer user_data) | |
72 | { | |
73 | CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self); | |
74 | gchar *name; | |
75 | g_signal_emit_by_name (CLOUD_PROVIDER_ACCOUNT_EXPORTER(self), "handle_get_name", &name); | |
76 | cloud_provider_account1_complete_get_name (priv->skeleton, invocation, name); | |
77 | } | |
78 | ||
79 | static void | |
80 | on_get_icon (CloudProviderAccountExporter *self, | |
81 | GDBusMethodInvocation *invocation, | |
82 | gpointer user_data) | |
83 | { | |
84 | CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self); | |
85 | GIcon *icon = NULL; | |
86 | g_signal_emit_by_name (CLOUD_PROVIDER_ACCOUNT_EXPORTER(self), "handle_get_icon", &icon); | |
87 | cloud_provider_account1_complete_get_icon (priv->skeleton, invocation, g_variant_new("v", g_icon_serialize(icon))); | |
88 | } | |
89 | ||
90 | static void | |
91 | on_get_path (CloudProviderAccountExporter *self, | |
92 | GDBusMethodInvocation *invocation, | |
93 | gpointer user_data) | |
94 | { | |
95 | CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self); | |
96 | gchar *path = NULL; | |
97 | g_signal_emit_by_name (CLOUD_PROVIDER_ACCOUNT_EXPORTER(self), "handle_get_path", &path); | |
98 | cloud_provider_account1_complete_get_path (priv->skeleton, invocation, path); | |
99 | } | |
100 | ||
101 | static void | |
102 | on_get_status (CloudProviderAccountExporter *self, | |
103 | GDBusMethodInvocation *invocation, | |
104 | gpointer user_data) | |
105 | { | |
106 | CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self); | |
107 | gint *status = g_new0(gint, 1); | |
108 | g_signal_emit_by_name (CLOUD_PROVIDER_ACCOUNT_EXPORTER(self), "handle_get_status", status); | |
109 | cloud_provider_account1_complete_get_status (priv->skeleton, invocation, *status); | |
110 | g_free(status); | |
111 | } | |
112 | ||
113 | static void | |
114 | on_get_status_details (CloudProviderAccountExporter *self, | |
115 | GDBusMethodInvocation *invocation, | |
116 | gpointer user_data) | |
117 | { | |
118 | CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self); | |
119 | gchar *status_details = NULL; | |
120 | g_signal_emit_by_name (CLOUD_PROVIDER_ACCOUNT_EXPORTER(self), "handle_get_status_details", &status_details); | |
121 | cloud_provider_account1_complete_get_status_details (priv->skeleton, invocation, status_details); | |
122 | } | |
123 | ||
124 | /** | |
125 | * cloud_provider_account_exporter_new: | |
126 | * @object_name: A unique name for the account | |
127 | * must be a valid DBus object name | |
128 | * | |
129 | * Create a new #CloudProviderAccountExporter object | |
130 | */ | |
131 | CloudProviderAccountExporter* | |
132 | cloud_provider_account_exporter_new (const gchar *object_name) | |
133 | { | |
134 | CloudProviderAccountExporter *self; | |
135 | CloudProviderAccountExporterPrivate *priv; | |
136 | ||
137 | self = g_object_new (TYPE_CLOUD_PROVIDER_ACCOUNT_EXPORTER, NULL); | |
138 | priv = cloud_provider_account_exporter_get_instance_private (self); | |
139 | ||
140 | priv->skeleton = cloud_provider_account1_skeleton_new (); | |
141 | ||
142 | g_signal_connect_swapped(priv->skeleton, "handle_get_name", G_CALLBACK (on_get_name), self); | |
143 | g_signal_connect_swapped(priv->skeleton, "handle_get_icon", G_CALLBACK (on_get_icon), self); | |
144 | g_signal_connect_swapped(priv->skeleton, "handle_get_path", G_CALLBACK (on_get_path), self); | |
145 | g_signal_connect_swapped(priv->skeleton, "handle_get_status", G_CALLBACK (on_get_status), self); | |
146 | g_signal_connect_swapped(priv->skeleton, "handle_get_status_details", G_CALLBACK (on_get_status_details), self); | |
147 | ||
148 | priv->object_name = g_strdup (object_name); | |
149 | ||
150 | return self; | |
151 | } | |
152 | ||
153 | /** | |
154 | * cloud_provider_account_exporter_add_menu_model: | |
155 | * @self: The cloud provider account exporter | |
156 | * @menu_model: The g menu model to export | |
157 | * | |
158 | * Add a #GMenuModel to export via DBus which will be shown to the user | |
159 | * for actions with the cloud provider account | |
160 | */ | |
161 | void | |
162 | cloud_provider_account_exporter_add_menu_model (CloudProviderAccountExporter *self, | |
163 | GMenuModel *menu_model) | |
164 | { | |
165 | CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self); | |
166 | priv->menu_model = menu_model; | |
167 | } | |
168 | ||
169 | /** | |
170 | * cloud_provider_account_exporter_remove_menu: | |
171 | * @self: The cloud provider account exporter | |
172 | * | |
173 | * Remove a menu added with cloud_provider_account_exporter_add_menu_model() | |
174 | */ | |
175 | void | |
176 | cloud_provider_account_exporter_remove_menu (CloudProviderAccountExporter *self) | |
177 | { | |
178 | CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self); | |
179 | priv->menu_model = NULL; | |
180 | } | |
181 | ||
182 | /** | |
183 | * cloud_provider_account_exporter_add_action_group: | |
184 | * @self: The cloud provider account exporter | |
185 | * @action_group: The g action group to export | |
186 | * | |
187 | * Add a #GActionGroup to export via DBus to provide actions for menus exported | |
188 | * with #cloud_provider_account_exporter_add_menu() | |
189 | */ | |
190 | void | |
191 | cloud_provider_account_exporter_add_action_group (CloudProviderAccountExporter *self, | |
192 | GActionGroup *action_group) | |
193 | { | |
194 | CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self); | |
195 | priv->action_group = action_group; | |
196 | } | |
197 | ||
198 | /** | |
199 | * cloud_provider_account_exporter_remove_action_group: | |
200 | * @self: The cloud provider account exporter | |
201 | * | |
202 | * Remove an action group added with cloud_provider_account_exporter_add_action_group() | |
203 | */ | |
204 | void | |
205 | cloud_provider_account_exporter_remove_action_group (CloudProviderAccountExporter *self) | |
206 | { | |
207 | CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self); | |
208 | priv->action_group = NULL; | |
209 | } | |
210 | ||
211 | static void | |
212 | cloud_provider_account_exporter_finalize (GObject *object) | |
213 | { | |
214 | CloudProviderAccountExporter *self = (CloudProviderAccountExporter *)object; | |
215 | CloudProviderAccountExporterPrivate *priv = cloud_provider_account_exporter_get_instance_private (self); | |
216 | ||
217 | g_free (priv->object_name); | |
218 | g_object_unref (priv->skeleton); | |
219 | ||
220 | G_OBJECT_CLASS (cloud_provider_account_exporter_parent_class)->finalize (object); | |
221 | } | |
222 | ||
223 | static void | |
224 | cloud_provider_account_exporter_class_init (CloudProviderAccountExporterClass *klass) | |
225 | { | |
226 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
227 | ||
228 | object_class->finalize = cloud_provider_account_exporter_finalize; | |
229 | ||
230 | /** | |
231 | * CloudProviderAccountExporter::handle-get-name: | |
232 | * @self: The CloudProviderAccountExporter emitting the signal | |
233 | * | |
234 | * This signal is emitted each time someone tries to get the account name. | |
235 | * | |
236 | * Returns: Return a #gchar* in the signal handler | |
237 | */ | |
238 | g_signal_new ("handle-get-name", | |
239 | G_TYPE_FROM_CLASS (klass), | |
240 | G_SIGNAL_RUN_LAST, | |
241 | 0, | |
242 | NULL, | |
243 | NULL, | |
244 | g_cclosure_marshal_generic, | |
245 | G_TYPE_POINTER, | |
246 | 0); | |
247 | ||
248 | /** | |
249 | * CloudProviderAccountExporter::handle-get-icon | |
250 | * @self: The CloudProviderAccountExporter emitting the signal | |
251 | * | |
252 | * This signal is emitted each time someone tries to get the account name. | |
253 | * | |
254 | * Returns: Return a #GIcon* in the signal handler | |
255 | */ | |
256 | g_signal_new ("handle_get_icon", | |
257 | G_TYPE_FROM_CLASS (klass), | |
258 | G_SIGNAL_RUN_LAST, | |
259 | 0, | |
260 | NULL, | |
261 | NULL, | |
262 | g_cclosure_marshal_generic, | |
263 | G_TYPE_POINTER, | |
264 | 0); | |
265 | ||
266 | /** | |
267 | * CloudProviderAccountExporter::handle-get-path | |
268 | * @self: The #CloudProviderAccountExporter emitting the signal | |
269 | * | |
270 | * This signal is emitted each time someone tries to get the path. | |
271 | * | |
272 | * Returns: Return a #gchar* in the signal handler | |
273 | */ | |
274 | g_signal_new ("handle_get_path", | |
275 | G_TYPE_FROM_CLASS (klass), | |
276 | G_SIGNAL_RUN_LAST, | |
277 | 0, | |
278 | NULL, | |
279 | NULL, | |
280 | g_cclosure_marshal_generic, | |
281 | G_TYPE_POINTER, | |
282 | 0); | |
283 | ||
284 | /** | |
285 | * CloudProviderAccountExporter::handle-get-status | |
286 | * @self: The CloudProviderAccountExporter emitting the signal | |
287 | * | |
288 | * This signal is emitted each time someone tries to get the status. | |
289 | * | |
290 | * Returns: Return a #CloudProviderSyncStatus in the signal handler | |
291 | */ | |
292 | g_signal_new ("handle_get_status", | |
293 | G_TYPE_FROM_CLASS (klass), | |
294 | G_SIGNAL_RUN_LAST, | |
295 | 0, | |
296 | NULL, | |
297 | NULL, | |
298 | g_cclosure_marshal_generic, | |
299 | G_TYPE_POINTER, | |
300 | 0); | |
301 | ||
302 | /** | |
303 | * CloudProviderAccountExporter::handle-get-status-details | |
304 | * @self: The #CloudProviderAccountExporter emitting the signal | |
305 | * | |
306 | * This signal is emitted each time someone tries to get the status details. | |
307 | * | |
308 | * Returns: Return a #gchar* in the signal handler | |
309 | */ | |
310 | g_signal_new ("handle_get_status_details", | |
311 | G_TYPE_FROM_CLASS (klass), | |
312 | G_SIGNAL_RUN_LAST, | |
313 | 0, | |
314 | NULL, | |
315 | NULL, | |
316 | g_cclosure_marshal_generic, | |
317 | G_TYPE_POINTER, | |
318 | 0); | |
319 | } | |
320 | ||
321 | static void | |
322 | cloud_provider_account_exporter_init (CloudProviderAccountExporter *self) | |
323 | { | |
324 | } |
0 | /* cloudprovideraccountexporter.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_ACCOUNT_EXPORTER_H | |
19 | #define CLOUD_PROVIDER_ACCOUNT_EXPORTER_H | |
20 | ||
21 | G_BEGIN_DECLS | |
22 | ||
23 | #define TYPE_CLOUD_PROVIDER_ACCOUNT_EXPORTER (cloud_provider_account_exporter_get_type()) | |
24 | #define CLOUD_PROVIDER_ACCOUNT_EXPORTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CLOUD_PROVIDER_ACCOUNT_EXPORTER, CloudProviderAccountExporter)) | |
25 | #define CLOUD_PROVIDER_ACCOUNT_EXPORTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CLOUD_PROVIDER_ACCOUNT_EXPORTER, CloudProviderAccountExporterClass)) | |
26 | #define IS_CLOUD_PROVIDER_ACCOUNT_EXPORTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CLOUD_PROVIDER_ACCOUNT_EXPORTER)) | |
27 | #define IS_CLOUD_PROVIDER_ACCOUNT_EXPORTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CLOUD_PROVIDER_ACCOUNT_EXPORTER)) | |
28 | #define CLOUD_PROVIDER_ACCOUNT_EXPORTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CLOUD_PROVIDER_ACCOUNT_EXPORTER, CloudProviderAccountExporterClass)) | |
29 | ||
30 | typedef struct _CloudProviderAccountExporter CloudProviderAccountExporter; | |
31 | typedef struct _CloudProviderAccountExporterClass CloudProviderAccountExporterClass; | |
32 | ||
33 | ||
34 | struct _CloudProviderAccountExporterClass | |
35 | { | |
36 | GObjectClass parent_class; | |
37 | }; | |
38 | ||
39 | struct _CloudProviderAccountExporter | |
40 | { | |
41 | GObject parent_instance; | |
42 | }; | |
43 | ||
44 | GType | |
45 | cloud_provider_account_exporter_get_type (void) G_GNUC_CONST; | |
46 | ||
47 | CloudProviderAccountExporter* | |
48 | cloud_provider_account_exporter_new (const gchar *object_name); | |
49 | ||
50 | void | |
51 | cloud_provider_account_exporter_add_menu_model (CloudProviderAccountExporter *self, | |
52 | GMenuModel *menu_model); | |
53 | void | |
54 | cloud_provider_account_exporter_remove_menu (CloudProviderAccountExporter *self); | |
55 | ||
56 | void | |
57 | cloud_provider_account_exporter_add_action_group (CloudProviderAccountExporter *self, | |
58 | GActionGroup *action_group); | |
59 | void | |
60 | cloud_provider_account_exporter_remove_action_group (CloudProviderAccountExporter *self); | |
61 | ||
62 | G_END_DECLS | |
63 | ||
64 | #endif /* CLOUD_PROVIDER_ACCOUNT_EXPORTER_H */ |
0 | /* cloudprovideraccountexporterpriv.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_ACCOUNT_EXPORTER_PRIV_H | |
19 | #define CLOUD_PROVIDER_ACCOUNT_EXPORTER_PRIV_H | |
20 | ||
21 | #include "cloudprovideraccountexporter.h" | |
22 | #include <gio/gio.h> | |
23 | G_BEGIN_DECLS | |
24 | ||
25 | GDBusInterfaceSkeleton* | |
26 | cloud_provider_account_exporter_get_skeleton (CloudProviderAccountExporter *self); | |
27 | ||
28 | gchar * | |
29 | cloud_provider_account_exporter_get_object_name (CloudProviderAccountExporter *self); | |
30 | ||
31 | GMenuModel * | |
32 | cloud_provider_account_exporter_get_menu_model (CloudProviderAccountExporter *self); | |
33 | ||
34 | GActionGroup * | |
35 | cloud_provider_account_exporter_get_action_group (CloudProviderAccountExporter *self); | |
36 | ||
37 | #endif |
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 | void | |
39 | cloud_provider_exporter_export_account (CloudProviderExporter *cloud_provider_exporter, | |
40 | const gchar *account_name, | |
41 | CloudProviderAccount1 *account); | |
42 | void | |
43 | cloud_provider_exporter_unexport_account (CloudProviderExporter *cloud_provider_exporter, | |
44 | const gchar *account_name); | |
45 | guint | |
46 | cloud_provider_exporter_export_menu (CloudProviderExporter *cloud_provider_exporter, | |
47 | const gchar *account_name, | |
48 | GMenuModel *model); | |
49 | void | |
50 | cloud_provider_exporter_unexport_menu (CloudProviderExporter *cloud_provider_exporter, | |
51 | const gchar *account_name); | |
52 | guint | |
53 | cloud_provider_exporter_export_action_group (CloudProviderExporter *cloud_provider_exporter, | |
54 | const gchar *account_name, | |
55 | GActionGroup *action_group); | |
56 | void | |
57 | cloud_provider_exporter_unexport_action_group (CloudProviderExporter *cloud_provider_exporter, | |
58 | const gchar *account_name); | |
59 | ||
60 | ||
61 | /** | |
62 | * SECTION:cloudproviderexporter | |
63 | * @title: CloudProviderExporter | |
64 | * @short_description: Base object for representing a single provider | |
65 | * @include: src/cloudproviderexporter.h | |
66 | * | |
67 | * #CloudProviderExporter is the base object representing a single cloud provider. | |
68 | * Multiple #CloudProviderAccountExporter objects can be added with cloud_provider_exporter_add_account() | |
69 | * After adding the initial set of accounts cloud_provider_exporter_export_objects() must be called. | |
70 | */ | |
71 | ||
72 | /** | |
73 | * cloud_provider_exporter_add_account: | |
74 | * @self: The cloud provider exporter | |
75 | * @account: The account object | |
76 | * | |
77 | * Each cloud provider can have a variety of account associated with it. Use this | |
78 | * function to add the accounts the user set up. Calling cloud_provider_exporter_export_objects() | |
79 | * once is required after adding the initial set of accounts. | |
80 | */ | |
81 | void | |
82 | cloud_provider_exporter_add_account (CloudProviderExporter *self, | |
83 | CloudProviderAccountExporter *account) | |
84 | { | |
85 | CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(self); | |
86 | CloudProviderObjectSkeleton *object; | |
87 | gchar *object_name = cloud_provider_account_exporter_get_object_name (account); | |
88 | gchar *object_path = g_strconcat (priv->object_path, "/", object_name, NULL); | |
89 | object = cloud_provider_object_skeleton_new(object_path); | |
90 | cloud_provider_object_skeleton_set_account1(object, CLOUD_PROVIDER_ACCOUNT1 (cloud_provider_account_exporter_get_skeleton (account))); | |
91 | g_dbus_object_manager_server_export (priv->manager, G_DBUS_OBJECT_SKELETON(object)); | |
92 | ||
93 | /* export menus/actiongroups that are coupled with the account */ | |
94 | GMenuModel *menu = cloud_provider_account_exporter_get_menu_model (account); | |
95 | GActionGroup *action_group = cloud_provider_account_exporter_get_action_group (account); | |
96 | if (menu != NULL) | |
97 | { | |
98 | cloud_provider_exporter_export_menu (self, | |
99 | object_name, | |
100 | menu); | |
101 | } | |
102 | if (action_group != NULL) | |
103 | { | |
104 | cloud_provider_exporter_export_action_group (self, | |
105 | object_name, | |
106 | action_group); | |
107 | } | |
108 | ||
109 | g_free(object_path); | |
110 | } | |
111 | ||
112 | /** | |
113 | * cloud_provider_exporter_remove_account: | |
114 | * @self: The cloud provider exporter | |
115 | * @account: The account object | |
116 | * | |
117 | * Each cloud provider can have a variety of account associated with it. Use this | |
118 | * function to remove the accounts added by cloud_provider_exporter_add_account(). | |
119 | */ | |
120 | void | |
121 | cloud_provider_exporter_remove_account (CloudProviderExporter *self, | |
122 | CloudProviderAccountExporter *account) | |
123 | { | |
124 | gchar *object_name = cloud_provider_account_exporter_get_object_name (account); | |
125 | cloud_provider_exporter_unexport_account (self, object_name); | |
126 | } | |
127 | ||
128 | ||
129 | /** | |
130 | * cloud_provider_exporter_emit_account_changed: | |
131 | * @self: The cloud provider | |
132 | * @account: The account | |
133 | * | |
134 | * When an account changes its status, emit a signal to DBUS using this function | |
135 | * so clients are aware of the change. | |
136 | */ | |
137 | void | |
138 | cloud_provider_exporter_emit_account_changed (CloudProviderExporter *self, | |
139 | CloudProviderAccountExporter *account) | |
140 | { | |
141 | gchar *object_name = cloud_provider_account_exporter_get_object_name (account); | |
142 | cloud_provider_exporter_emit_changed (self, object_name); | |
143 | } | |
144 | ||
145 | ||
146 | /** | |
147 | * cloud_provider_exporter_export_account: | |
148 | * @self: The cloud provider exporter | |
149 | * @account_name: The account name | |
150 | * @account: The account object | |
151 | * | |
152 | * Each cloud provider can have a variety of account associated with it. Use this | |
153 | * function to export the accounts the user set up. | |
154 | */ | |
155 | void | |
156 | cloud_provider_exporter_export_account(CloudProviderExporter *self, | |
157 | const gchar *account_name, | |
158 | CloudProviderAccount1 *account) | |
159 | { | |
160 | CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(self); | |
161 | CloudProviderObjectSkeleton *object; | |
162 | gchar *object_path = g_strconcat (priv->object_path, "/", account_name, NULL); | |
163 | object = cloud_provider_object_skeleton_new(object_path); | |
164 | cloud_provider_object_skeleton_set_account1(object, account); | |
165 | g_dbus_object_manager_server_export (priv->manager, | |
166 | G_DBUS_OBJECT_SKELETON(object)); | |
167 | g_free(object_path); | |
168 | } | |
169 | ||
170 | /** | |
171 | * cloud_provider_exporter_unexport_account: | |
172 | * @self: The cloud provider | |
173 | * @account_name: The name of the account | |
174 | * | |
175 | * Each cloud provider can have a variety of account associated with it. Use this | |
176 | * function to remove an already set up account. | |
177 | */ | |
178 | void | |
179 | cloud_provider_exporter_unexport_account(CloudProviderExporter *self, | |
180 | const gchar *account_name) | |
181 | { | |
182 | CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(self); | |
183 | gchar *object_path = g_strconcat (priv->object_path, "/", account_name, NULL); | |
184 | g_dbus_object_manager_server_unexport (priv->manager, object_path); | |
185 | guint *export_id; | |
186 | export_id = (guint*)g_hash_table_lookup(priv->menuModels, account_name); | |
187 | if(export_id != NULL) { | |
188 | g_dbus_connection_unexport_menu_model(priv->bus, *export_id); | |
189 | g_free(export_id); | |
190 | } | |
191 | export_id = (guint*)g_hash_table_lookup(priv->actionGroups, account_name); | |
192 | if(export_id != NULL) { | |
193 | g_dbus_connection_unexport_action_group(priv->bus, *export_id); | |
194 | g_free(export_id); | |
195 | } | |
196 | g_free (object_path); | |
197 | } | |
198 | ||
199 | /** | |
200 | * cloud_provider_exporter_export_menu: | |
201 | * @self: The cloud provider | |
202 | * @account_name: The name of the account | |
203 | * | |
204 | * One of the benefits of the integration is to display a menu with available | |
205 | * options for an account. Use this function to export a GMenuModel menu to be | |
206 | * displayed by the choosen integration by the desktop environment or application. | |
207 | */ | |
208 | guint | |
209 | cloud_provider_exporter_export_menu(CloudProviderExporter *self, | |
210 | const gchar *account_name, | |
211 | GMenuModel *model) | |
212 | { | |
213 | CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(self); | |
214 | gchar *object_path = g_strconcat(priv->object_path, "/", account_name, NULL); | |
215 | GError *error = NULL; | |
216 | guint *export_id = g_new0(guint, 1); | |
217 | *export_id = g_dbus_connection_export_menu_model (priv->bus, object_path, model, &error); | |
218 | if (!*export_id) | |
219 | { | |
220 | g_warning ("Menu export failed: %s", error->message); | |
221 | return 0; | |
222 | } | |
223 | g_hash_table_insert(priv->menuModels, g_strdup(account_name), export_id); | |
224 | return *export_id; | |
225 | } | |
226 | ||
227 | /** | |
228 | * cloud_provider_exporter_unexport_menu: | |
229 | * @self: The cloud provider | |
230 | * @account_name: The name of the account | |
231 | * | |
232 | * Remove the menu added with cloud_provider_exporter_export_menu | |
233 | */ | |
234 | void | |
235 | cloud_provider_exporter_unexport_menu(CloudProviderExporter *self, | |
236 | const gchar *account_name) | |
237 | { | |
238 | CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(self); | |
239 | guint *export_id; | |
240 | export_id = (guint*)g_hash_table_lookup(priv->menuModels, account_name); | |
241 | if(export_id != NULL) { | |
242 | g_dbus_connection_unexport_menu_model(priv->bus, *export_id); | |
243 | g_hash_table_remove (priv->menuModels, account_name); | |
244 | g_free(export_id); | |
245 | } | |
246 | } | |
247 | ||
248 | /** | |
249 | * cloud_provider_exporter_action_group: | |
250 | * @self: The cloud provider | |
251 | * @account_name: The name of the account | |
252 | * @action_group: The GActionGroup to be used by the menu exported by cloud_provider_exporter_export_menu | |
253 | * | |
254 | * In order for a menu exported with cloud_provider_exporter_export_menu to receive events | |
255 | * that will eventually call your callbacks, it needs the corresponding GAcionGroup. | |
256 | * Use this function to export it. | |
257 | */ | |
258 | guint | |
259 | cloud_provider_exporter_export_action_group(CloudProviderExporter *self, | |
260 | const gchar *account_name, | |
261 | GActionGroup *action_group) | |
262 | { | |
263 | CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(self); | |
264 | gchar *object_path = g_strconcat(priv->object_path, "/", account_name, NULL); | |
265 | GError *error = NULL; | |
266 | guint *export_id = g_new0(guint, 1); | |
267 | *export_id = g_dbus_connection_export_action_group (priv->bus, object_path, action_group, &error); | |
268 | if (!*export_id) | |
269 | { | |
270 | g_warning ("Action export failed: %s", error->message); | |
271 | return 0; | |
272 | } | |
273 | g_hash_table_insert(priv->actionGroups, g_strdup(account_name), export_id); | |
274 | return *export_id; | |
275 | } | |
276 | ||
277 | /** | |
278 | * cloud_provider_exporter_unexport_action_group: | |
279 | * @self: The cloud provider | |
280 | * @account_name: The name of the account | |
281 | * | |
282 | * Unexport the GActionGroup exported by cloud_provider_exporter_export_action_group | |
283 | */ | |
284 | void | |
285 | cloud_provider_exporter_unexport_action_group(CloudProviderExporter *self, | |
286 | const gchar *account_name) | |
287 | { | |
288 | CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(self); | |
289 | guint *export_id; | |
290 | export_id = (guint*)g_hash_table_lookup(priv->actionGroups, account_name); | |
291 | if(export_id != NULL) { | |
292 | g_dbus_connection_unexport_action_group(priv->bus, *export_id); | |
293 | g_hash_table_remove (priv->actionGroups, account_name); | |
294 | g_free(export_id); | |
295 | } | |
296 | } | |
297 | ||
298 | /** | |
299 | * cloud_provider_exporter_export_objects: | |
300 | * @self: The cloud provider | |
301 | * | |
302 | * Export all objects assigned previously with cloud_provider_exporter_add_account() | |
303 | * to DBUS. | |
304 | * Use this function after adding all the required objects to avoid multiple signals | |
305 | * being emitted in a short time. This function needs to be called only once. | |
306 | * Objects added after the call will be propagated to DBus automatically. | |
307 | */ | |
308 | void | |
309 | cloud_provider_exporter_export_objects(CloudProviderExporter * self) | |
310 | { | |
311 | CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(self); | |
312 | g_dbus_object_manager_server_set_connection (priv->manager, priv->bus); | |
313 | } | |
314 | ||
315 | /** | |
316 | * cloud_provider_exporter_emit_changed: | |
317 | * @self: The cloud provider | |
318 | * @account_name: The name of the account | |
319 | * | |
320 | * When an account changes its status, emit a signal to DBUS using this function | |
321 | * so clients are aware of the change. | |
322 | */ | |
323 | void | |
324 | cloud_provider_exporter_emit_changed (CloudProviderExporter *self, | |
325 | const gchar *account_name) | |
326 | { | |
327 | CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private(self); | |
328 | gchar *object_path = g_strconcat(priv->object_path, "/", account_name, NULL); | |
329 | GDBusObject *object = g_dbus_object_manager_get_object((GDBusObjectManager*)priv->manager, object_path); | |
330 | CloudProviderAccount1 *account = cloud_provider_object_get_account1 (CLOUD_PROVIDER_OBJECT(object)); | |
331 | cloud_provider_account1_emit_cloud_provider_changed (account); | |
332 | g_object_unref (account); | |
333 | g_object_unref (object); | |
334 | g_free (object_path); | |
335 | } | |
336 | ||
337 | /** | |
338 | * cloud_provider_exporter_new: | |
339 | * @bus: A #GDbusConnection to export the objects to | |
340 | * @bus_name: A DBus name to bind to | |
341 | * @object_path: A DBus object path | |
342 | */ | |
343 | CloudProviderExporter * | |
344 | cloud_provider_exporter_new (GDBusConnection *bus, | |
345 | const gchar *bus_name, | |
346 | const gchar *object_path) | |
347 | { | |
348 | CloudProviderExporter *self; | |
349 | CloudProviderExporterPrivate *priv; | |
350 | ||
351 | self = g_object_new (TYPE_CLOUD_PROVIDER_EXPORTER, NULL); | |
352 | priv = cloud_provider_exporter_get_instance_private (self); | |
353 | ||
354 | priv->bus_name = g_strdup (bus_name); | |
355 | priv->object_path = g_strdup (object_path); | |
356 | priv->bus = bus; | |
357 | priv->cancellable = g_cancellable_new (); | |
358 | priv->manager = g_dbus_object_manager_server_new (object_path); | |
359 | ||
360 | priv->menuModels = g_hash_table_new(g_str_hash, g_str_equal); | |
361 | priv->actionGroups = g_hash_table_new(g_str_hash, g_str_equal); | |
362 | return self; | |
363 | } | |
364 | ||
365 | static void | |
366 | cloud_provider_exporter_finalize (GObject *object) | |
367 | { | |
368 | CloudProviderExporter *self = (CloudProviderExporter *)object; | |
369 | CloudProviderExporterPrivate *priv = cloud_provider_exporter_get_instance_private (self); | |
370 | ||
371 | g_cancellable_cancel (priv->cancellable); | |
372 | g_clear_object (&priv->cancellable); | |
373 | g_clear_object (&priv->bus); | |
374 | g_free (priv->bus_name); | |
375 | g_free (priv->object_path); | |
376 | g_object_unref(priv->manager); | |
377 | ||
378 | g_hash_table_remove_all(priv->menuModels); | |
379 | g_object_unref(priv->menuModels); | |
380 | g_hash_table_remove_all(priv->actionGroups); | |
381 | g_object_unref(priv->actionGroups); | |
382 | ||
383 | G_OBJECT_CLASS (cloud_provider_exporter_parent_class)->finalize (object); | |
384 | } | |
385 | ||
386 | static void | |
387 | cloud_provider_exporter_class_init (CloudProviderExporterClass *klass) | |
388 | { | |
389 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
390 | object_class->finalize = cloud_provider_exporter_finalize; | |
391 | } | |
392 | ||
393 | static void | |
394 | cloud_provider_exporter_init (CloudProviderExporter *self) | |
395 | { | |
396 | } |
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 | /* for CloudProviderStatus enum */ | |
22 | #include "cloudprovideraccount.h" | |
23 | #include "cloudprovideraccountexporter.h" | |
24 | ||
25 | G_BEGIN_DECLS | |
26 | ||
27 | #define TYPE_CLOUD_PROVIDER_EXPORTER (cloud_provider_exporter_get_type()) | |
28 | #define CLOUD_PROVIDER_EXPORTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CLOUD_PROVIDER_EXPORTER, CloudProviderExporter)) | |
29 | #define CLOUD_PROVIDER_EXPORTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CLOUD_PROVIDER_EXPORTER, CloudProviderExporterClass)) | |
30 | #define IS_CLOUD_PROVIDER_EXPORTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CLOUD_PROVIDER_EXPORTER)) | |
31 | #define IS_CLOUD_PROVIDER_EXPORTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CLOUD_PROVIDER_EXPORTER)) | |
32 | #define CLOUD_PROVIDER_EXPORTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CLOUD_PROVIDER_EXPORTER, CloudProviderExporterClass)) | |
33 | ||
34 | typedef struct _CloudProviderExporter CloudProviderExporter; | |
35 | typedef struct _CloudProviderExporterClass CloudProviderExporterClass; | |
36 | ||
37 | ||
38 | struct _CloudProviderExporterClass | |
39 | { | |
40 | GObjectClass parent_class; | |
41 | }; | |
42 | ||
43 | struct _CloudProviderExporter | |
44 | { | |
45 | GObject parent_instance; | |
46 | }; | |
47 | ||
48 | GType | |
49 | cloud_provider_exporter_get_type (void) G_GNUC_CONST; | |
50 | ||
51 | void | |
52 | cloud_provider_exporter_add_account (CloudProviderExporter *self, | |
53 | CloudProviderAccountExporter *account); | |
54 | void | |
55 | cloud_provider_exporter_remove_account (CloudProviderExporter *self, | |
56 | CloudProviderAccountExporter *account); | |
57 | ||
58 | ||
59 | void | |
60 | cloud_provider_exporter_export_objects (CloudProviderExporter *self); | |
61 | ||
62 | void | |
63 | cloud_provider_exporter_emit_changed (CloudProviderExporter *self, | |
64 | const gchar *account_name); | |
65 | void | |
66 | cloud_provider_exporter_emit_account_changed (CloudProviderExporter *self, | |
67 | CloudProviderAccountExporter *account); | |
68 | ||
69 | CloudProviderExporter* | |
70 | cloud_provider_exporter_new (GDBusConnection *bus, | |
71 | const gchar *bus_name, | |
72 | const gchar *object_path); | |
73 | ||
74 | G_END_DECLS | |
75 | ||
76 | ||
77 | #endif /* CLOUD_PROVIDER_EXPORTER_H */ |
0 | /* cloudprovidermanager.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 "cloudprovidermanager.h" | |
20 | #include "cloudprovideraccount.h" | |
21 | #include <glib.h> | |
22 | #include <glib/gprintf.h> | |
23 | #include <gio/gio.h> | |
24 | #include <stdlib.h> | |
25 | ||
26 | typedef struct | |
27 | { | |
28 | GList *providers; | |
29 | GDBusConnection *connection; | |
30 | GDBusNodeInfo *dbus_node_info; | |
31 | GVariantBuilder *provider_object_managers; | |
32 | GVariant *providers_objects; | |
33 | CloudProviderManager1 *skeleton; | |
34 | } CloudProviderManagerPrivate; | |
35 | ||
36 | G_DEFINE_TYPE_WITH_PRIVATE (CloudProviderManager, cloud_provider_manager, G_TYPE_OBJECT) | |
37 | ||
38 | enum | |
39 | { | |
40 | CHANGED, | |
41 | OWNERS_CHANGED, | |
42 | LAST_SIGNAL | |
43 | }; | |
44 | ||
45 | static guint gSignals [LAST_SIGNAL]; | |
46 | ||
47 | #define KEY_FILE_GROUP "Cloud Provider" | |
48 | ||
49 | /** | |
50 | * load_cloud_provider | |
51 | * @manager: A CloudProviderManager | |
52 | * @file: A GFile | |
53 | */ | |
54 | static void | |
55 | load_cloud_provider (CloudProviderManager *self, | |
56 | GFile *file, | |
57 | GVariantBuilder *builder) | |
58 | { | |
59 | GKeyFile *key_file; | |
60 | gchar *path; | |
61 | GError *error = NULL; | |
62 | gchar *bus_name; | |
63 | gchar *object_path; | |
64 | gboolean success = FALSE; | |
65 | ||
66 | key_file = g_key_file_new (); | |
67 | path = g_file_get_path (file); | |
68 | g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, &error); | |
69 | if (error != NULL) | |
70 | goto out; | |
71 | ||
72 | if (!g_key_file_has_group (key_file, KEY_FILE_GROUP)) | |
73 | goto out; | |
74 | ||
75 | bus_name = g_key_file_get_string (key_file, KEY_FILE_GROUP, "BusName", &error); | |
76 | if (error != NULL) | |
77 | goto out; | |
78 | object_path = g_key_file_get_string (key_file, KEY_FILE_GROUP, "ObjectPath", &error); | |
79 | if (error != NULL) | |
80 | goto out; | |
81 | ||
82 | g_variant_builder_add(builder, "(so)", bus_name, object_path); | |
83 | ||
84 | success = TRUE; | |
85 | g_free (bus_name); | |
86 | g_free (object_path); | |
87 | out: | |
88 | if (!success) | |
89 | g_warning ("Error while loading cloud provider key file at %s", path); | |
90 | g_key_file_free (key_file); | |
91 | g_object_unref (file); | |
92 | g_free (path); | |
93 | } | |
94 | ||
95 | void | |
96 | cloud_provider_manager_update (CloudProviderManager *manager) | |
97 | { | |
98 | CloudProviderManagerPrivate *priv = cloud_provider_manager_get_instance_private (manager); | |
99 | const gchar* const *data_dirs; | |
100 | gint i; | |
101 | gint len; | |
102 | gchar *key_files_directory_path; | |
103 | GFile *key_files_directory_file; | |
104 | GError *error = NULL; | |
105 | GFileEnumerator *file_enumerator; | |
106 | ||
107 | priv->provider_object_managers = g_variant_builder_new(G_VARIANT_TYPE("a(so)")); | |
108 | ||
109 | g_list_free_full (priv->providers, g_object_unref); | |
110 | priv->providers = NULL; | |
111 | ||
112 | data_dirs = g_get_system_data_dirs (); | |
113 | len = g_strv_length ((gchar **)data_dirs); | |
114 | ||
115 | for (i = 0; i < len; i++) | |
116 | { | |
117 | GFileInfo *info; | |
118 | ||
119 | key_files_directory_path = g_build_filename (data_dirs[i], "cloud-providers", NULL); | |
120 | key_files_directory_file = g_file_new_for_path (key_files_directory_path); | |
121 | file_enumerator = g_file_enumerate_children (key_files_directory_file, | |
122 | "standard::name,standard::type", | |
123 | G_FILE_QUERY_INFO_NONE, | |
124 | NULL, | |
125 | &error); | |
126 | if (error) | |
127 | { | |
128 | error = NULL; | |
129 | continue; | |
130 | } | |
131 | ||
132 | info = g_file_enumerator_next_file (file_enumerator, NULL, &error); | |
133 | if (error) | |
134 | { | |
135 | g_warning ("Error while enumerating file %s error: %s\n", key_files_directory_path, error->message); | |
136 | error = NULL; | |
137 | continue; | |
138 | } | |
139 | while (info != NULL && error == NULL) | |
140 | { | |
141 | load_cloud_provider (manager, g_file_enumerator_get_child (file_enumerator, info), priv->provider_object_managers); | |
142 | g_object_unref (info); | |
143 | info = g_file_enumerator_next_file (file_enumerator, NULL, &error); | |
144 | } | |
145 | g_object_unref (file_enumerator); | |
146 | g_free (key_files_directory_path); | |
147 | g_object_unref (key_files_directory_file); | |
148 | } | |
149 | ||
150 | g_free(priv->providers_objects); | |
151 | priv->providers_objects = g_variant_builder_end(priv->provider_object_managers); | |
152 | g_variant_builder_unref (priv->provider_object_managers); | |
153 | gchar *provider_debug = g_variant_print(priv->providers_objects, TRUE); | |
154 | g_debug("%s\n", provider_debug); | |
155 | g_free(provider_debug); | |
156 | } | |
157 | ||
158 | ||
159 | static void | |
160 | handle_get_cloud_providers (CloudProviderManager1 *interface, | |
161 | GDBusMethodInvocation *invocation, | |
162 | gpointer user_data) | |
163 | { | |
164 | CloudProviderManagerPrivate *priv = cloud_provider_manager_get_instance_private (CLOUD_PROVIDER_MANAGER(user_data)); | |
165 | g_variant_ref(priv->providers_objects); | |
166 | cloud_provider_manager1_complete_get_cloud_providers (interface, invocation, priv->providers_objects); | |
167 | } | |
168 | ||
169 | void | |
170 | cloud_provider_manager_export (CloudProviderManager *self) | |
171 | { | |
172 | CloudProviderManagerPrivate *priv = cloud_provider_manager_get_instance_private (CLOUD_PROVIDER_MANAGER (self)); | |
173 | g_signal_connect (priv->skeleton, | |
174 | "handle-get-cloud-providers", | |
175 | G_CALLBACK(handle_get_cloud_providers), | |
176 | CLOUD_PROVIDER_MANAGER(self)); | |
177 | g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->skeleton), | |
178 | priv->connection, | |
179 | CLOUD_PROVIDER_MANAGER_DBUS_PATH, | |
180 | NULL); | |
181 | ||
182 | ||
183 | } | |
184 | ||
185 | CloudProviderManager * | |
186 | cloud_provider_manager_new (GDBusConnection *connection) | |
187 | { | |
188 | CloudProviderManager *self; | |
189 | CloudProviderManagerPrivate *priv; | |
190 | ||
191 | self = g_object_new (TYPE_CLOUD_PROVIDER_MANAGER, NULL); | |
192 | priv = cloud_provider_manager_get_instance_private (self); | |
193 | ||
194 | priv->connection = connection; | |
195 | priv->providers = NULL; | |
196 | priv->skeleton = cloud_provider_manager1_skeleton_new (); | |
197 | cloud_provider_manager_update (CLOUD_PROVIDER_MANAGER(self)); | |
198 | ||
199 | return self; | |
200 | } | |
201 | ||
202 | static void | |
203 | cloud_provider_manager_finalize (GObject *object) | |
204 | { | |
205 | CloudProviderManager *self = (CloudProviderManager *)object; | |
206 | CloudProviderManagerPrivate *priv = cloud_provider_manager_get_instance_private (self); | |
207 | ||
208 | g_list_free_full (priv->providers, g_object_unref); | |
209 | g_dbus_node_info_unref (priv->dbus_node_info); | |
210 | ||
211 | G_OBJECT_CLASS (cloud_provider_manager_parent_class)->finalize (object); | |
212 | } | |
213 | ||
214 | static void | |
215 | cloud_provider_manager_class_init (CloudProviderManagerClass *klass) | |
216 | { | |
217 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
218 | ||
219 | object_class->finalize = cloud_provider_manager_finalize; | |
220 | ||
221 | gSignals [CHANGED] = | |
222 | g_signal_new ("changed", | |
223 | G_TYPE_FROM_CLASS (klass), | |
224 | G_SIGNAL_RUN_LAST, | |
225 | 0, | |
226 | NULL, | |
227 | NULL, | |
228 | g_cclosure_marshal_generic, | |
229 | G_TYPE_NONE, | |
230 | 0); | |
231 | gSignals [OWNERS_CHANGED] = | |
232 | g_signal_new ("owners-changed", | |
233 | G_TYPE_FROM_CLASS (klass), | |
234 | G_SIGNAL_RUN_LAST, | |
235 | 0, | |
236 | NULL, | |
237 | NULL, | |
238 | g_cclosure_marshal_generic, | |
239 | G_TYPE_NONE, | |
240 | 0); | |
241 | } | |
242 | ||
243 | static void | |
244 | cloud_provider_manager_init (CloudProviderManager *self) | |
245 | { | |
246 | } |
0 | /* cloudprovidermanager.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 | #ifndef CLOUD_PROVIDER_MANAGER_H | |
19 | #define CLOUD_PROVIDER_MANAGER_H | |
20 | ||
21 | #include <gio/gio.h> | |
22 | #include "cloudprovideraccount.h" | |
23 | #include "cloudprovidermanager-generated.h" | |
24 | ||
25 | #define CLOUD_PROVIDER_MANAGER_DBUS_IFACE "org.freedesktop.CloudProviderManager1" | |
26 | #define CLOUD_PROVIDER_MANAGER_DBUS_NAME "org.freedesktop.CloudProviderManager" | |
27 | #define CLOUD_PROVIDER_MANAGER_DBUS_PATH "/org/freedesktop/CloudProviderManager" | |
28 | ||
29 | G_BEGIN_DECLS | |
30 | ||
31 | #define TYPE_CLOUD_PROVIDER_MANAGER (cloud_provider_manager_get_type()) | |
32 | #define CLOUD_PROVIDER_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CLOUD_PROVIDER_MANAGER, CloudProviderManager)) | |
33 | #define CLOUD_PROVIDER_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CLOUD_PROVIDER_MANAGER, CloudProviderManagerClass)) | |
34 | #define IS_CLOUD_PROVIDER_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CLOUD_PROVIDER_MANAGER)) | |
35 | #define IS_CLOUD_PROVIDER_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CLOUD_PROVIDER_MANAGER)) | |
36 | #define CLOUD_PROVIDER_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CLOUD_PROVIDER_MANAGER, CloudProviderManagerClass)) | |
37 | ||
38 | typedef struct _CloudProviderManager CloudProviderManager; | |
39 | typedef struct _CloudProviderManagerClass CloudProviderManagerClass; | |
40 | ||
41 | struct _CloudProviderManagerClass | |
42 | { | |
43 | GObjectClass parent_class; | |
44 | }; | |
45 | ||
46 | struct _CloudProviderManager | |
47 | { | |
48 | GObject parent_instance; | |
49 | }; | |
50 | ||
51 | GType cloud_provider_manager_get_type (void) G_GNUC_CONST; | |
52 | CloudProviderManager *cloud_provider_manager_new (GDBusConnection *connection); | |
53 | void cloud_provider_manager_update (CloudProviderManager *manager); | |
54 | void cloud_provider_manager_export (CloudProviderManager *self); | |
55 | G_END_DECLS | |
56 | ||
57 | #endif /* CLOUD_PROVIDER_MANAGER_H */ |
0 | /* cloudproviders.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 "cloudproviders.h" | |
20 | #include "cloudprovideraccount.h" | |
21 | #include "cloudprovidermanager.h" | |
22 | #include "cloudprovidermanager-generated.h" | |
23 | #include "cloudprovider-generated.h" | |
24 | #include <glib.h> | |
25 | #include <glib/gprintf.h> | |
26 | #include <gio/gio.h> | |
27 | ||
28 | #define KEY_FILE_GROUP "Cloud Provider" | |
29 | ||
30 | typedef struct | |
31 | { | |
32 | GList *providers; | |
33 | guint dbus_owner_id; | |
34 | GDBusNodeInfo *dbus_node_info; | |
35 | GHashTable* provider_object_managers; | |
36 | GDBusConnection *bus; | |
37 | CloudProviderManager1 *proxy; | |
38 | GCancellable *cancellable; | |
39 | } CloudProvidersPrivate; | |
40 | ||
41 | G_DEFINE_TYPE_WITH_PRIVATE (CloudProviders, cloud_providers, G_TYPE_OBJECT) | |
42 | ||
43 | /** | |
44 | * SECTION:cloudproviders | |
45 | * @title: CloudProviders | |
46 | * @short_description: Singleton for tracking all providers. | |
47 | * @include: src/cloudproviders.h | |
48 | * | |
49 | * #CloudProviders is a singleton to track all the changes in all providers. | |
50 | * Using a #CloudProviders you can implement integration for all of them at once | |
51 | * and represent them in the UI, track new providers added or removed and their | |
52 | * status. | |
53 | */ | |
54 | ||
55 | enum | |
56 | { | |
57 | CHANGED, | |
58 | OWNERS_CHANGED, | |
59 | LAST_SIGNAL | |
60 | }; | |
61 | ||
62 | static guint gSignals [LAST_SIGNAL]; | |
63 | ||
64 | static void | |
65 | on_cloud_provider_proxy_ready (CloudProviderAccount *cloud_provider, CloudProviders *self) | |
66 | { | |
67 | // notify clients that cloud provider list has changed | |
68 | g_signal_emit_by_name (self, "owners-changed", NULL); | |
69 | } | |
70 | ||
71 | static void | |
72 | on_cloud_provider_changed (CloudProviderAccount *cloud_provider, CloudProviders *self) | |
73 | { | |
74 | // notify clients that cloud provider has changed | |
75 | g_signal_emit_by_name (self, "changed", NULL); | |
76 | } | |
77 | ||
78 | /** | |
79 | * Update provider list if objects are added/removed at object manager. | |
80 | */ | |
81 | static void | |
82 | on_cloud_provider_object_manager_notify (GObject *object, | |
83 | GParamSpec *pspec, | |
84 | gpointer user_data) | |
85 | { | |
86 | CloudProviders *self = CLOUD_PROVIDERS(user_data); | |
87 | cloud_providers_update(self); | |
88 | } | |
89 | ||
90 | static void | |
91 | on_proxy_created (GObject *source_object, | |
92 | GAsyncResult *res, | |
93 | gpointer user_data) | |
94 | { | |
95 | GError *error = NULL; | |
96 | CloudProviders *self; | |
97 | CloudProvidersPrivate *priv; | |
98 | CloudProviderManager1 *proxy; | |
99 | ||
100 | proxy = cloud_provider_manager1_proxy_new_for_bus_finish (res, &error); | |
101 | if (error != NULL) | |
102 | { | |
103 | if (error->code != G_IO_ERROR_CANCELLED) | |
104 | g_warning ("Error creating proxy for cloud provider %s", error->message); | |
105 | return; | |
106 | } | |
107 | self = CLOUD_PROVIDERS (user_data); | |
108 | priv = cloud_providers_get_instance_private (self); | |
109 | ||
110 | priv->proxy = proxy; | |
111 | ||
112 | cloud_providers_update(self); | |
113 | } | |
114 | ||
115 | static void | |
116 | on_bus_acquired (GObject *source_object, | |
117 | GAsyncResult *res, | |
118 | gpointer user_data) | |
119 | { | |
120 | GError *error = NULL; | |
121 | CloudProviders *self; | |
122 | GDBusConnection *bus; | |
123 | CloudProvidersPrivate *priv; | |
124 | ||
125 | bus = g_bus_get_finish (res, &error); | |
126 | if (error != NULL) | |
127 | { | |
128 | if (error->code != G_IO_ERROR_CANCELLED) | |
129 | g_warning ("Error acdquiring bus for cloud provider %s", error->message); | |
130 | return; | |
131 | } | |
132 | ||
133 | self = CLOUD_PROVIDERS (user_data); | |
134 | priv = cloud_providers_get_instance_private (user_data); | |
135 | priv->bus = bus; | |
136 | g_clear_object (&priv->cancellable); | |
137 | priv->cancellable = g_cancellable_new (); | |
138 | cloud_provider_manager1_proxy_new (priv->bus, | |
139 | G_DBUS_PROXY_FLAGS_NONE, | |
140 | CLOUD_PROVIDER_MANAGER_DBUS_NAME, | |
141 | CLOUD_PROVIDER_MANAGER_DBUS_PATH, | |
142 | priv->cancellable, | |
143 | on_proxy_created, | |
144 | self); | |
145 | } | |
146 | ||
147 | /** | |
148 | * cloud_providers_dup_singleton: | |
149 | * Main object to track changes in all providers. | |
150 | * | |
151 | * Returns: (transfer full): A manager singleton | |
152 | */ | |
153 | CloudProviders * | |
154 | cloud_providers_dup_singleton (void) | |
155 | { | |
156 | static GObject *self = NULL; | |
157 | ||
158 | if (self == NULL) | |
159 | { | |
160 | CloudProvidersPrivate *priv; | |
161 | self = g_object_new (TYPE_CLOUD_PROVIDERS, NULL); | |
162 | priv = cloud_providers_get_instance_private (CLOUD_PROVIDERS(self)); | |
163 | priv->provider_object_managers = g_hash_table_new(g_str_hash, g_str_equal); | |
164 | ||
165 | g_bus_get (G_BUS_TYPE_SESSION, | |
166 | priv->cancellable, | |
167 | on_bus_acquired, | |
168 | self); | |
169 | ||
170 | return CLOUD_PROVIDERS (self); | |
171 | } | |
172 | else | |
173 | { | |
174 | return g_object_ref (self); | |
175 | } | |
176 | } | |
177 | ||
178 | static void | |
179 | cloud_providers_finalize (GObject *object) | |
180 | { | |
181 | CloudProviders *self = (CloudProviders *)object; | |
182 | CloudProvidersPrivate *priv = cloud_providers_get_instance_private (self); | |
183 | ||
184 | g_list_free_full (priv->providers, g_object_unref); | |
185 | g_bus_unown_name (priv->dbus_owner_id); | |
186 | g_dbus_node_info_unref (priv->dbus_node_info); | |
187 | ||
188 | G_OBJECT_CLASS (cloud_providers_parent_class)->finalize (object); | |
189 | } | |
190 | ||
191 | static void | |
192 | cloud_providers_class_init (CloudProvidersClass *klass) | |
193 | { | |
194 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
195 | ||
196 | object_class->finalize = cloud_providers_finalize; | |
197 | ||
198 | /** | |
199 | * CloudProviders::changed | |
200 | * | |
201 | * This signal is emitted if any of the cloud provider accounts has changed | |
202 | * their details | |
203 | */ | |
204 | gSignals [CHANGED] = | |
205 | g_signal_new ("changed", | |
206 | G_TYPE_FROM_CLASS (klass), | |
207 | G_SIGNAL_RUN_LAST, | |
208 | 0, | |
209 | NULL, | |
210 | NULL, | |
211 | g_cclosure_marshal_generic, | |
212 | G_TYPE_NONE, | |
213 | 0); | |
214 | /** | |
215 | * CloudProviders::owners-changed | |
216 | * | |
217 | * This signal is emitted if the list of available cloud providers has changed | |
218 | */ | |
219 | gSignals [OWNERS_CHANGED] = | |
220 | g_signal_new ("owners-changed", | |
221 | G_TYPE_FROM_CLASS (klass), | |
222 | G_SIGNAL_RUN_LAST, | |
223 | 0, | |
224 | NULL, | |
225 | NULL, | |
226 | g_cclosure_marshal_generic, | |
227 | G_TYPE_NONE, | |
228 | 0); | |
229 | } | |
230 | ||
231 | static void | |
232 | cloud_providers_init (CloudProviders *self) | |
233 | { | |
234 | } | |
235 | ||
236 | /** | |
237 | * cloud_providers_get_providers | |
238 | * @self: A CloudProviders | |
239 | * Returns: (transfer none): A GList* of #CloudProviderAccount objects. | |
240 | */ | |
241 | GList* | |
242 | cloud_providers_get_providers (CloudProviders *self) | |
243 | { | |
244 | CloudProvidersPrivate *priv = cloud_providers_get_instance_private (self); | |
245 | return priv->providers; | |
246 | } | |
247 | ||
248 | ||
249 | static void | |
250 | on_get_cloud_providers (GObject *source_object, | |
251 | GAsyncResult *res, | |
252 | gpointer user_data) | |
253 | { | |
254 | CloudProviders *self = CLOUD_PROVIDERS (user_data); | |
255 | CloudProvidersPrivate *priv = cloud_providers_get_instance_private (self); | |
256 | GError *error = NULL; | |
257 | GVariant *foo; | |
258 | CloudProviderAccount*cloud_provider; | |
259 | gboolean success = FALSE; | |
260 | GVariantIter iter; | |
261 | gchar *bus_name; | |
262 | gchar *object_path; | |
263 | ||
264 | cloud_provider_manager1_call_get_cloud_providers_finish (priv->proxy, &foo, res, &error); | |
265 | if (error != NULL) | |
266 | { | |
267 | g_warning ("Error getting the provider name %s", error->message); | |
268 | return; | |
269 | } | |
270 | ||
271 | g_list_free_full (priv->providers, g_object_unref); | |
272 | priv->providers = NULL; | |
273 | ||
274 | g_variant_iter_init (&iter, foo); | |
275 | while (g_variant_iter_next (&iter, "(so)", &bus_name, &object_path)) | |
276 | { | |
277 | GList *objects; | |
278 | GList *l; | |
279 | GDBusObjectManager *manager = g_hash_table_lookup(priv->provider_object_managers, bus_name); | |
280 | if (manager == NULL) | |
281 | { | |
282 | manager = cloud_provider_object_manager_client_new_for_bus_sync(G_BUS_TYPE_SESSION, | |
283 | G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, | |
284 | bus_name, | |
285 | object_path, | |
286 | NULL, | |
287 | &error); | |
288 | ||
289 | if (error != NULL) | |
290 | { | |
291 | g_printerr ("Error getting object manager client: %s", error->message); | |
292 | g_error_free (error); | |
293 | goto out; | |
294 | } | |
295 | ||
296 | g_signal_connect(manager, "notify::name-owner", G_CALLBACK(on_cloud_provider_object_manager_notify), self); | |
297 | g_signal_connect(manager, "object-added", G_CALLBACK(on_cloud_provider_object_manager_notify), self); | |
298 | g_signal_connect(manager, "object-removed", G_CALLBACK(on_cloud_provider_object_manager_notify), self); | |
299 | g_hash_table_insert(priv->provider_object_managers, bus_name, manager); | |
300 | } | |
301 | objects = g_dbus_object_manager_get_objects (manager); | |
302 | for (l = objects; l != NULL; l = l->next) | |
303 | { | |
304 | CloudProviderObject *object = CLOUD_PROVIDER_OBJECT(l->data); | |
305 | cloud_provider = cloud_provider_account_new (bus_name, g_dbus_object_get_object_path (G_DBUS_OBJECT (object))); | |
306 | g_signal_connect (cloud_provider, "ready", | |
307 | G_CALLBACK (on_cloud_provider_proxy_ready), self); | |
308 | g_signal_connect (cloud_provider, "changed", | |
309 | G_CALLBACK (on_cloud_provider_changed), self); | |
310 | cloud_provider_account_update (cloud_provider); | |
311 | priv->providers = g_list_append (priv->providers, cloud_provider); | |
312 | } | |
313 | } | |
314 | success = TRUE; | |
315 | g_signal_emit_by_name (self, "owners-changed", NULL); | |
316 | out: | |
317 | if (!success) | |
318 | g_warning ("Error while loading cloud providers"); | |
319 | ||
320 | } | |
321 | ||
322 | /** | |
323 | * cloud_providers_update | |
324 | * @self: A CloudProviders | |
325 | */ | |
326 | void | |
327 | cloud_providers_update (CloudProviders *self) | |
328 | { | |
329 | CloudProvidersPrivate *priv = cloud_providers_get_instance_private (self); | |
330 | if(priv->proxy == NULL) | |
331 | return; | |
332 | cloud_provider_manager1_call_get_cloud_providers (priv->proxy, | |
333 | NULL, | |
334 | (GAsyncReadyCallback) on_get_cloud_providers, | |
335 | self); | |
336 | } | |
337 |
0 | /* cloudproviders.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 | #ifndef CLOUD_PROVIDERS_H | |
19 | #define CLOUD_PROVIDERS_H | |
20 | ||
21 | #include <gio/gio.h> | |
22 | #include "cloudprovideraccount.h" | |
23 | ||
24 | G_BEGIN_DECLS | |
25 | ||
26 | #define TYPE_CLOUD_PROVIDERS (cloud_providers_get_type()) | |
27 | #define CLOUD_PROVIDERS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CLOUD_PROVIDERS, CloudProviders)) | |
28 | #define CLOUD_PROVIDERS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CLOUD_PROVIDERS, CloudProvidersClass)) | |
29 | #define IS_CLOUD_PROVIDERS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CLOUD_PROVIDERS)) | |
30 | #define IS_CLOUD_PROVIDERS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CLOUD_PROVIDERS)) | |
31 | #define CLOUD_PROVIDERS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CLOUD_PROVIDERS, CloudProvidersClass)) | |
32 | ||
33 | typedef struct _CloudProviders CloudProviders; | |
34 | typedef struct _CloudProvidersClass CloudProvidersClass; | |
35 | ||
36 | struct _CloudProvidersClass | |
37 | { | |
38 | GObjectClass parent_class; | |
39 | }; | |
40 | ||
41 | struct _CloudProviders | |
42 | { | |
43 | GObject parent_instance; | |
44 | }; | |
45 | ||
46 | GType cloud_providers_get_type (void) G_GNUC_CONST; | |
47 | CloudProviders *cloud_providers_dup_singleton (void); | |
48 | void cloud_providers_update (CloudProviders *self); | |
49 | GList *cloud_providers_get_providers (CloudProviders *self); | |
50 | G_END_DECLS | |
51 | ||
52 | #endif /* CLOUD_PROVIDERS_H */ |
0 | /* cloudprovidersaccount.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 "cloudprovidersaccount.h" | |
20 | #include "cloudprovidersprovider.h" | |
21 | #include "cloudproviders-generated.h" | |
22 | #include "enums.h" | |
23 | ||
24 | struct _CloudProvidersAccount | |
25 | { | |
26 | GObject parent; | |
27 | ||
28 | gchar *name; | |
29 | gchar *path; | |
30 | CloudProvidersAccountStatus status; | |
31 | gchar *status_details; | |
32 | GIcon *icon; | |
33 | GMenuModel *menu_model; | |
34 | GActionGroup *action_group; | |
35 | ||
36 | GDBusConnection *bus; | |
37 | CloudProvidersDbusAccount *proxy; | |
38 | gchar *bus_name; | |
39 | gchar *object_path; | |
40 | }; | |
41 | ||
42 | G_DEFINE_TYPE (CloudProvidersAccount, cloud_providers_account, G_TYPE_OBJECT) | |
43 | ||
44 | /** | |
45 | * SECTION:cloudprovideraccount | |
46 | * @title: CloudProvidersAccount | |
47 | * @short_description: Base object for representing a single account for clients. | |
48 | * @include: src/cloudprovideraccount.h | |
49 | * | |
50 | * #CloudProvidersAccount is the basic object used to construct the integrator UI | |
51 | * and actions that a provider will present to the user, from the client side. | |
52 | * Integrators of the cloud providers can use this object to poll the | |
53 | * #CloudProvider menus, status and actions. | |
54 | */ | |
55 | ||
56 | enum | |
57 | { | |
58 | PROP_0, | |
59 | PROP_NAME, | |
60 | PROP_ICON, | |
61 | PROP_STATUS, | |
62 | PROP_STATUS_DETAILS, | |
63 | PROP_MENU_MODEL, | |
64 | PROP_ACTION_GROUP, | |
65 | PROP_PATH, | |
66 | N_PROPS | |
67 | }; | |
68 | ||
69 | static GParamSpec *properties [N_PROPS]; | |
70 | ||
71 | static void | |
72 | on_name_changed (GObject *object, | |
73 | GParamSpec *pspec, | |
74 | CloudProvidersAccount *self) | |
75 | { | |
76 | g_free (self->name); | |
77 | self->name = cloud_providers_dbus_account_dup_name (self->proxy); | |
78 | g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_NAME]); | |
79 | } | |
80 | ||
81 | static void | |
82 | on_status_changed (GObject *object, | |
83 | GParamSpec *pspec, | |
84 | CloudProvidersAccount *self) | |
85 | { | |
86 | self->status = cloud_providers_dbus_account_get_status (self->proxy); | |
87 | g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_STATUS]); | |
88 | } | |
89 | ||
90 | static void | |
91 | on_status_details_changed (GObject *object, | |
92 | GParamSpec *pspec, | |
93 | CloudProvidersAccount *self) | |
94 | { | |
95 | g_free (self->status_details); | |
96 | self->status_details = cloud_providers_dbus_account_dup_status_details (self->proxy); | |
97 | g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_STATUS_DETAILS]); | |
98 | } | |
99 | ||
100 | static void | |
101 | on_icon_changed (GObject *object, | |
102 | GParamSpec *pspec, | |
103 | CloudProvidersAccount *self) | |
104 | { | |
105 | GError *error = NULL; | |
106 | ||
107 | self->icon = g_icon_new_for_string (cloud_providers_dbus_account_get_icon (self->proxy), &error); | |
108 | g_print ("setting icon %d", g_icon_hash (self->icon)); | |
109 | if (error != NULL) | |
110 | { | |
111 | g_printerr ("Error getting the icon in the client %s", error->message); | |
112 | } | |
113 | g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON]); | |
114 | } | |
115 | ||
116 | static void | |
117 | on_path_changed (GObject *object, | |
118 | GParamSpec *pspec, | |
119 | CloudProvidersAccount *self) | |
120 | { | |
121 | g_free (self->path); | |
122 | self->path = cloud_providers_dbus_account_dup_path (self->proxy); | |
123 | g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PATH]); | |
124 | } | |
125 | ||
126 | static void | |
127 | setup_proxy (CloudProvidersAccount *self) | |
128 | { | |
129 | GMenuModel *menu_model; | |
130 | GActionGroup *action_group; | |
131 | GIcon *icon = NULL; | |
132 | GError *error = NULL; | |
133 | ||
134 | g_signal_connect (self->proxy, "notify::name", G_CALLBACK (on_name_changed), self); | |
135 | g_signal_connect (self->proxy, "notify::status", G_CALLBACK (on_status_changed), self); | |
136 | g_signal_connect (self->proxy, "notify::status-details", G_CALLBACK (on_status_details_changed), self); | |
137 | g_signal_connect (self->proxy, "notify::icon", G_CALLBACK (on_icon_changed), self); | |
138 | g_signal_connect (self->proxy, "notify::path", G_CALLBACK (on_path_changed), self); | |
139 | ||
140 | icon = g_icon_new_for_string (cloud_providers_dbus_account_get_icon (self->proxy), &error); | |
141 | if (error != NULL) | |
142 | { | |
143 | g_printerr ("Error getting the icon in the client %s", error->message); | |
144 | } | |
145 | menu_model = (GMenuModel*) g_dbus_menu_model_get (self->bus, | |
146 | self->bus_name, | |
147 | self->object_path); | |
148 | action_group = (GActionGroup*) g_dbus_action_group_get (self->bus, | |
149 | self->bus_name, | |
150 | self->object_path); | |
151 | self->name = cloud_providers_dbus_account_dup_name (self->proxy); | |
152 | self->status = cloud_providers_dbus_account_get_status (self->proxy); | |
153 | self->status_details = cloud_providers_dbus_account_dup_status_details (self->proxy); | |
154 | self->icon = icon; | |
155 | self->path = cloud_providers_dbus_account_dup_path (self->proxy); | |
156 | self->menu_model = menu_model; | |
157 | self->action_group = action_group; | |
158 | ||
159 | g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_NAME]); | |
160 | g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_STATUS]); | |
161 | g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_STATUS_DETAILS]); | |
162 | g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON]); | |
163 | g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PATH]); | |
164 | g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTION_GROUP]); | |
165 | g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MENU_MODEL]); | |
166 | } | |
167 | ||
168 | static void | |
169 | cloud_providers_account_get_property (GObject *object, | |
170 | guint prop_id, | |
171 | GValue *value, | |
172 | GParamSpec *pspec) | |
173 | { | |
174 | CloudProvidersAccount *self = CLOUD_PROVIDERS_ACCOUNT (object); | |
175 | ||
176 | switch (prop_id) | |
177 | { | |
178 | case PROP_NAME: | |
179 | { | |
180 | g_value_set_string (value, self->name); | |
181 | } | |
182 | break; | |
183 | ||
184 | case PROP_STATUS: | |
185 | { | |
186 | g_value_set_enum (value, self->status); | |
187 | } | |
188 | break; | |
189 | ||
190 | case PROP_STATUS_DETAILS: | |
191 | { | |
192 | g_value_set_string (value, self->status_details); | |
193 | } | |
194 | break; | |
195 | ||
196 | case PROP_ICON: | |
197 | { | |
198 | g_value_set_object (value, self->icon); | |
199 | } | |
200 | break; | |
201 | ||
202 | case PROP_PATH: | |
203 | { | |
204 | g_value_set_string (value, self->path); | |
205 | } | |
206 | break; | |
207 | ||
208 | case PROP_ACTION_GROUP: | |
209 | { | |
210 | g_value_set_object (value, self->action_group); | |
211 | } | |
212 | break; | |
213 | ||
214 | case PROP_MENU_MODEL: | |
215 | { | |
216 | g_value_set_object (value, self->menu_model); | |
217 | } | |
218 | break; | |
219 | ||
220 | default: | |
221 | { | |
222 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
223 | } | |
224 | } | |
225 | } | |
226 | ||
227 | static void | |
228 | cloud_providers_account_set_property (GObject *object, | |
229 | guint prop_id, | |
230 | const GValue *value, | |
231 | GParamSpec *pspec) | |
232 | { | |
233 | switch (prop_id) | |
234 | { | |
235 | default: | |
236 | { | |
237 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
238 | } | |
239 | ||
240 | } | |
241 | } | |
242 | ||
243 | /** | |
244 | * cloud_providers_account_new | |
245 | * @bus_name: DBus bus name | |
246 | * @object_path: Path to export the DBus object to | |
247 | * | |
248 | * A #CloudProvidersAccount object are used to fetch details about cloud providers from DBus. | |
249 | * Object are usually fetched from cloud_providers_get_providers() as a list. | |
250 | */ | |
251 | CloudProvidersAccount* | |
252 | cloud_providers_account_new (CloudProvidersDbusAccountProxy *proxy) | |
253 | { | |
254 | CloudProvidersAccount *self; | |
255 | ||
256 | self = g_object_new (CLOUD_PROVIDERS_TYPE_ACCOUNT, NULL); | |
257 | ||
258 | ||
259 | g_object_ref (proxy); | |
260 | self->proxy = CLOUD_PROVIDERS_DBUS_ACCOUNT (proxy); | |
261 | self->bus = g_dbus_proxy_get_connection (G_DBUS_PROXY (self->proxy)); | |
262 | self->bus_name = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (self->proxy)); | |
263 | self->object_path = g_strdup (g_dbus_proxy_get_object_path (G_DBUS_PROXY (self->proxy))); | |
264 | ||
265 | setup_proxy (self); | |
266 | ||
267 | return self; | |
268 | } | |
269 | ||
270 | static void | |
271 | cloud_providers_account_finalize (GObject *object) | |
272 | { | |
273 | CloudProvidersAccount *self = (CloudProvidersAccount *)object; | |
274 | ||
275 | g_signal_handlers_disconnect_by_data (self->proxy, self); | |
276 | g_free (self->name); | |
277 | g_free (self->path); | |
278 | g_clear_object (&self->icon); | |
279 | g_clear_object (&self->action_group); | |
280 | g_clear_object (&self->bus); | |
281 | g_clear_object (&self->proxy); | |
282 | g_free (self->bus_name); | |
283 | g_free (self->object_path); | |
284 | ||
285 | G_OBJECT_CLASS (cloud_providers_account_parent_class)->finalize (object); | |
286 | } | |
287 | ||
288 | static void | |
289 | cloud_providers_account_class_init (CloudProvidersAccountClass *klass) | |
290 | { | |
291 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
292 | ||
293 | object_class->set_property = cloud_providers_account_set_property; | |
294 | object_class->get_property = cloud_providers_account_get_property; | |
295 | object_class->finalize = cloud_providers_account_finalize; | |
296 | ||
297 | properties [PROP_NAME] = | |
298 | g_param_spec_string ("name", | |
299 | "Name", | |
300 | "The name of the account", | |
301 | NULL, | |
302 | (G_PARAM_READABLE | | |
303 | G_PARAM_STATIC_STRINGS)); | |
304 | g_object_class_install_property (object_class, PROP_NAME, | |
305 | properties [PROP_NAME]); | |
306 | properties [PROP_PATH] = | |
307 | g_param_spec_string ("path", | |
308 | "Path", | |
309 | "The path of the directory where files are located", | |
310 | NULL, | |
311 | (G_PARAM_READABLE | | |
312 | G_PARAM_STATIC_STRINGS)); | |
313 | g_object_class_install_property (object_class, PROP_PATH, | |
314 | properties [PROP_PATH]); | |
315 | properties [PROP_STATUS] = | |
316 | g_param_spec_enum ("status", | |
317 | "Status", | |
318 | "Status of the account", | |
319 | CLOUD_TYPE_PROVIDERS_ACCOUNT_STATUS, | |
320 | CLOUD_PROVIDERS_ACCOUNT_STATUS_INVALID, | |
321 | (G_PARAM_READABLE | | |
322 | G_PARAM_STATIC_STRINGS)); | |
323 | g_object_class_install_property (object_class, PROP_STATUS, | |
324 | properties [PROP_STATUS]); | |
325 | properties [PROP_STATUS_DETAILS] = | |
326 | g_param_spec_string ("status-details", | |
327 | "StatusDetails", | |
328 | "The details of the account status", | |
329 | NULL, | |
330 | (G_PARAM_READABLE | | |
331 | G_PARAM_STATIC_STRINGS)); | |
332 | g_object_class_install_property (object_class, PROP_STATUS_DETAILS, | |
333 | properties [PROP_STATUS_DETAILS]); | |
334 | properties [PROP_ICON] = | |
335 | g_param_spec_object ("icon", | |
336 | "Icon", | |
337 | "The icon representing the account", | |
338 | G_TYPE_ICON, | |
339 | (G_PARAM_READABLE | | |
340 | G_PARAM_STATIC_STRINGS)); | |
341 | g_object_class_install_property (object_class, PROP_ICON, | |
342 | properties [PROP_ICON]); | |
343 | properties [PROP_MENU_MODEL] = | |
344 | g_param_spec_object ("menu-model", | |
345 | "MenuModel", | |
346 | "The menu model associated with the account", | |
347 | G_TYPE_MENU_MODEL, | |
348 | (G_PARAM_READABLE | | |
349 | G_PARAM_STATIC_STRINGS)); | |
350 | g_object_class_install_property (object_class, PROP_MENU_MODEL, | |
351 | properties [PROP_MENU_MODEL]); | |
352 | properties [PROP_ACTION_GROUP] = | |
353 | g_param_spec_object ("action-group", | |
354 | "ActionGroup", | |
355 | "The action group associated with the account and menu model", | |
356 | G_TYPE_ACTION_GROUP, | |
357 | (G_PARAM_READABLE | | |
358 | G_PARAM_STATIC_STRINGS)); | |
359 | g_object_class_install_property (object_class, PROP_ACTION_GROUP, | |
360 | properties [PROP_ACTION_GROUP]); | |
361 | ||
362 | ||
363 | } | |
364 | ||
365 | static void | |
366 | cloud_providers_account_init (CloudProvidersAccount *self) | |
367 | { | |
368 | } | |
369 | ||
370 | /** | |
371 | * cloud_providers_account_get_name: | |
372 | * @self: A cloud provider account | |
373 | * | |
374 | * Get the name of the account | |
375 | * | |
376 | * Returns: The name of the cloud provider account | |
377 | */ | |
378 | gchar* | |
379 | cloud_providers_account_get_name (CloudProvidersAccount *self) | |
380 | { | |
381 | return self->name; | |
382 | } | |
383 | ||
384 | /** | |
385 | * cloud_providers_account_get_status: | |
386 | * @self: A cloud provider account | |
387 | * | |
388 | * Get the status of the account | |
389 | * | |
390 | * Returns: The status of the cloud provider account | |
391 | */ | |
392 | CloudProvidersAccountStatus | |
393 | cloud_providers_account_get_status (CloudProvidersAccount *self) | |
394 | { | |
395 | return self->status; | |
396 | } | |
397 | ||
398 | /** | |
399 | * cloud_providers_account_get_status_details: | |
400 | * @self: A cloud provider account | |
401 | * | |
402 | * Get the status details of the account | |
403 | * | |
404 | * Returns: The status detail description of the cloud provider account | |
405 | */ | |
406 | gchar* | |
407 | cloud_providers_account_get_status_details (CloudProvidersAccount *self) | |
408 | { | |
409 | return self->status_details; | |
410 | } | |
411 | ||
412 | /** | |
413 | * cloud_providers_account_get_icon: | |
414 | * @self: A cloud provider account | |
415 | * | |
416 | * Get the icon of the account | |
417 | * | |
418 | * Returns: The icon of the cloud provider account | |
419 | */ | |
420 | GIcon* | |
421 | cloud_providers_account_get_icon (CloudProvidersAccount *self) | |
422 | { | |
423 | return self->icon; | |
424 | } | |
425 | ||
426 | /** | |
427 | * cloud_providers_account_get_menu_model: | |
428 | * @self: A cloud provider account | |
429 | * | |
430 | * Get the menu model exported for the account | |
431 | * | |
432 | * Returns: The menu model exported by the cloud provider account | |
433 | */ | |
434 | GMenuModel* | |
435 | cloud_providers_account_get_menu_model (CloudProvidersAccount *self) | |
436 | { | |
437 | return self->menu_model; | |
438 | } | |
439 | ||
440 | /** | |
441 | * cloud_providers_account_get_action_group: | |
442 | * @self: A cloud provider account | |
443 | * | |
444 | * Get the action group exported in addition to the #GMenuModel from | |
445 | * cloud_providers_account_get_menu_model() | |
446 | * | |
447 | * Returns: The action group exported by the cloud provider account | |
448 | */ | |
449 | GActionGroup* | |
450 | cloud_providers_account_get_action_group (CloudProvidersAccount *self) | |
451 | { | |
452 | return self->action_group; | |
453 | } | |
454 | ||
455 | /** | |
456 | * cloud_providers_account_get_path: | |
457 | * @self: A cloud provider account | |
458 | * | |
459 | * Get the directory path of the account | |
460 | * | |
461 | * Returns: The directory path of the cloud provider account | |
462 | */ | |
463 | gchar * | |
464 | cloud_providers_account_get_path (CloudProvidersAccount *self) | |
465 | { | |
466 | return self->path; | |
467 | } |
0 | /* cloudprovidersaccount.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_PROVIDERS_ACCOUNT_H | |
20 | #define CLOUD_PROVIDERS_ACCOUNT_H | |
21 | ||
22 | #include <gio/gio.h> | |
23 | #include "cloudproviders-generated.h" | |
24 | ||
25 | G_BEGIN_DECLS | |
26 | ||
27 | #define CLOUD_PROVIDERS_ACCOUNT_DBUS_IFACE "org.freedesktop.CloudProviders.Account" | |
28 | ||
29 | /** | |
30 | * CloudProviderStatus: | |
31 | * @CLOUD_PROVIDERS_ACCOUNT_STATUS_INVALID: Set if the initial state of the account is unknown | |
32 | * @CLOUD_PROVIDERS_ACCOUNT_STATUS_IDLE: Set if the account is in idle mode | |
33 | * @CLOUD_PROVIDERS_ACCOUNT_STATUS_SYNCING: Set if the account is currently synchronizing data | |
34 | * @CLOUD_PROVIDERS_ACCOUNT_STATUS_ERROR: Set if an error occured | |
35 | * | |
36 | * Enum values used to describe the sync status of a cloud providers account | |
37 | **/ | |
38 | typedef enum { | |
39 | CLOUD_PROVIDERS_ACCOUNT_STATUS_INVALID, | |
40 | CLOUD_PROVIDERS_ACCOUNT_STATUS_IDLE, | |
41 | CLOUD_PROVIDERS_ACCOUNT_STATUS_SYNCING, | |
42 | CLOUD_PROVIDERS_ACCOUNT_STATUS_ERROR | |
43 | } CloudProvidersAccountStatus; | |
44 | ||
45 | #define CLOUD_PROVIDERS_TYPE_ACCOUNT (cloud_providers_account_get_type()) | |
46 | G_DECLARE_FINAL_TYPE (CloudProvidersAccount, cloud_providers_account, CLOUD_PROVIDERS, ACCOUNT, GObject); | |
47 | ||
48 | struct _CloudProvidersAccountClass | |
49 | { | |
50 | GObjectClass parent_class; | |
51 | }; | |
52 | ||
53 | CloudProvidersAccount *cloud_providers_account_new (CloudProvidersDbusAccountProxy *proxy); | |
54 | ||
55 | gchar* cloud_providers_account_get_name (CloudProvidersAccount *self); | |
56 | CloudProvidersAccountStatus cloud_providers_account_get_status (CloudProvidersAccount *self); | |
57 | gchar* cloud_providers_account_get_status_details (CloudProvidersAccount *self); | |
58 | GIcon *cloud_providers_account_get_icon (CloudProvidersAccount *self); | |
59 | GMenuModel *cloud_providers_account_get_menu_model (CloudProvidersAccount *self); | |
60 | GActionGroup* cloud_providers_account_get_action_group (CloudProvidersAccount *self); | |
61 | gchar *cloud_providers_account_get_path (CloudProvidersAccount *self); | |
62 | G_END_DECLS | |
63 | ||
64 | ||
65 | #endif /* CLOUD_PROVIDERS_ACCOUNT_H */ |
0 | /* cloudprovidersaccountexporter.c | |
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 | #include <gio/gio.h> | |
19 | #include "cloudprovidersaccount.h" | |
20 | #include "cloudprovidersaccountexporter.h" | |
21 | #include "cloudprovidersproviderexporter.h" | |
22 | #include "cloudprovidersaccountexporterpriv.h" | |
23 | #include "cloudproviders-generated.h" | |
24 | #include "enums.h" | |
25 | ||
26 | struct _CloudProvidersAccountExporter | |
27 | { | |
28 | GObject parent; | |
29 | ||
30 | gchar *bus_name; | |
31 | CloudProvidersDbusAccount *skeleton; | |
32 | ||
33 | GDBusConnection *bus; | |
34 | gchar *object_path; | |
35 | gchar *name; | |
36 | gchar *path; | |
37 | CloudProvidersAccountStatus status; | |
38 | gchar *status_details; | |
39 | gchar *icon; | |
40 | GMenuModel *menu_model; | |
41 | GActionGroup *action_group; | |
42 | ||
43 | gint menu_model_export_id; | |
44 | gint action_group_export_id; | |
45 | CloudProvidersProviderExporter *provider; | |
46 | }; | |
47 | ||
48 | G_DEFINE_TYPE (CloudProvidersAccountExporter, cloud_providers_account_exporter, G_TYPE_OBJECT) | |
49 | ||
50 | enum | |
51 | { | |
52 | PROP_0, | |
53 | PROP_NAME, | |
54 | PROP_BUS_NAME, | |
55 | PROP_PROVIDER, | |
56 | PROP_ICON, | |
57 | PROP_STATUS, | |
58 | PROP_STATUS_DETAILS, | |
59 | PROP_MENU_MODEL, | |
60 | PROP_ACTION_GROUP, | |
61 | PROP_PATH, | |
62 | N_PROPS | |
63 | }; | |
64 | ||
65 | static GParamSpec *properties [N_PROPS]; | |
66 | ||
67 | /** | |
68 | * SECTION:cloudprovidersaccountexporter | |
69 | * @title: CloudProvidersAccountExporter | |
70 | * @short_description: Base object for representing a cloud providers account | |
71 | * @include: src/cloudprovidersaccountexporter.h | |
72 | */ | |
73 | ||
74 | static void | |
75 | export_menu_model (CloudProvidersAccountExporter *self) | |
76 | { | |
77 | GError *error = NULL; | |
78 | ||
79 | self->menu_model_export_id = g_dbus_connection_export_menu_model (self->bus, | |
80 | self->object_path, | |
81 | self->menu_model, | |
82 | &error); | |
83 | if (self->menu_model_export_id == 0) | |
84 | { | |
85 | g_warning ("Menu export failed: %s", error->message); | |
86 | } | |
87 | } | |
88 | ||
89 | #if 0 | |
90 | static void | |
91 | unexport_menu_model (CloudProvidersAccountExporter *self) | |
92 | { | |
93 | if(self->menu_model_export_id != 0) | |
94 | { | |
95 | g_dbus_connection_unexport_menu_model(self->bus, self->menu_model_export_id); | |
96 | } | |
97 | } | |
98 | #endif | |
99 | ||
100 | static void | |
101 | export_action_group(CloudProvidersAccountExporter *self) | |
102 | { | |
103 | GError *error = NULL; | |
104 | ||
105 | self->action_group_export_id = g_dbus_connection_export_action_group (self->bus, | |
106 | self->object_path, | |
107 | self->action_group, | |
108 | &error); | |
109 | if (self->action_group_export_id == 0) | |
110 | { | |
111 | g_warning ("Action export failed: %s", error->message); | |
112 | } | |
113 | } | |
114 | ||
115 | #if 0 | |
116 | /** | |
117 | * cloud_providers_account_exporter_unexport_action_group: | |
118 | * @self: The cloud provider | |
119 | * @account_name: The name of the account | |
120 | * | |
121 | * Unexport the GActionGroup exported by cloud_providers_account_exporter_export_action_group | |
122 | */ | |
123 | static void | |
124 | unexport_action_group(CloudProvidersAccountExporter *self) | |
125 | { | |
126 | if (self->action_group_export_id != 0) | |
127 | { | |
128 | g_dbus_connection_unexport_action_group(self->bus, self->action_group_export_id); | |
129 | } | |
130 | } | |
131 | #endif | |
132 | ||
133 | gchar * | |
134 | cloud_providers_account_exporter_get_object_path (CloudProvidersAccountExporter *self) | |
135 | { | |
136 | return self->object_path; | |
137 | } | |
138 | ||
139 | gchar * | |
140 | cloud_providers_account_exporter_get_bus_name (CloudProvidersAccountExporter *self) | |
141 | { | |
142 | return self->bus_name; | |
143 | } | |
144 | ||
145 | CloudProvidersDbusAccount* | |
146 | cloud_providers_account_exporter_get_skeleton (CloudProvidersAccountExporter *self) | |
147 | { | |
148 | return self->skeleton; | |
149 | } | |
150 | #if 0 | |
151 | GMenuModel * | |
152 | cloud_providers_account_exporter_get_menu_model (CloudProvidersAccountExporter *self) | |
153 | { | |
154 | return self->menu_model; | |
155 | } | |
156 | ||
157 | GActionGroup * | |
158 | cloud_providers_account_exporter_get_action_group (CloudProvidersAccountExporter *self) | |
159 | { | |
160 | return self->action_group; | |
161 | } | |
162 | ||
163 | #endif | |
164 | ||
165 | /** | |
166 | * cloud_providers_account_exporter_new: | |
167 | * @bus_name: A unique name for the account | |
168 | * must be a valid DBus object name | |
169 | * | |
170 | * Create a new #CloudProvidersAccountExporter object | |
171 | */ | |
172 | CloudProvidersAccountExporter* | |
173 | cloud_providers_account_exporter_new (CloudProvidersProviderExporter *provider, | |
174 | const gchar *bus_name) | |
175 | { | |
176 | CloudProvidersAccountExporter *self; | |
177 | ||
178 | self = g_object_new (CLOUD_PROVIDERS_TYPE_ACCOUNT_EXPORTER, | |
179 | "provider", provider, | |
180 | "bus-name", bus_name, | |
181 | NULL); | |
182 | return self; | |
183 | } | |
184 | ||
185 | static void | |
186 | cloud_providers_account_exporter_get_property (GObject *object, | |
187 | guint prop_id, | |
188 | GValue *value, | |
189 | GParamSpec *pspec) | |
190 | { | |
191 | CloudProvidersAccountExporter *self = CLOUD_PROVIDERS_ACCOUNT_EXPORTER (object); | |
192 | ||
193 | switch (prop_id) | |
194 | { | |
195 | case PROP_NAME: | |
196 | { | |
197 | g_value_set_string (value, self->name); | |
198 | } | |
199 | break; | |
200 | ||
201 | case PROP_BUS_NAME: | |
202 | { | |
203 | g_value_set_string (value, self->bus_name); | |
204 | } | |
205 | break; | |
206 | ||
207 | case PROP_PROVIDER: | |
208 | { | |
209 | g_value_set_object (value, self->provider); | |
210 | } | |
211 | break; | |
212 | ||
213 | case PROP_STATUS: | |
214 | { | |
215 | g_value_set_enum (value, self->status); | |
216 | } | |
217 | break; | |
218 | ||
219 | case PROP_STATUS_DETAILS: | |
220 | { | |
221 | g_value_set_string (value, self->status_details); | |
222 | } | |
223 | break; | |
224 | ||
225 | case PROP_ICON: | |
226 | { | |
227 | g_autoptr (GIcon) icon = NULL; | |
228 | ||
229 | icon = g_icon_new_for_string (self->icon, NULL); | |
230 | g_value_set_object (value, icon); | |
231 | } | |
232 | break; | |
233 | ||
234 | case PROP_PATH: | |
235 | { | |
236 | g_value_set_string (value, self->path); | |
237 | } | |
238 | break; | |
239 | ||
240 | case PROP_ACTION_GROUP: | |
241 | { | |
242 | g_value_set_object (value, self->action_group); | |
243 | } | |
244 | break; | |
245 | ||
246 | case PROP_MENU_MODEL: | |
247 | { | |
248 | g_value_set_object (value, self->menu_model); | |
249 | } | |
250 | break; | |
251 | ||
252 | default: | |
253 | { | |
254 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
255 | } | |
256 | ||
257 | } | |
258 | } | |
259 | ||
260 | static void | |
261 | cloud_providers_account_exporter_set_property (GObject *object, | |
262 | guint prop_id, | |
263 | const GValue *value, | |
264 | GParamSpec *pspec) | |
265 | { | |
266 | CloudProvidersAccountExporter *self = CLOUD_PROVIDERS_ACCOUNT_EXPORTER (object); | |
267 | ||
268 | switch (prop_id) | |
269 | { | |
270 | case PROP_NAME: | |
271 | { | |
272 | g_free (self->name); | |
273 | self->name = g_strdup (g_value_get_string (value)); | |
274 | cloud_providers_dbus_account_set_name (self->skeleton, self->name); | |
275 | } | |
276 | break; | |
277 | ||
278 | case PROP_BUS_NAME: | |
279 | { | |
280 | g_return_if_fail (self->bus_name == NULL); | |
281 | self->bus_name = g_strdup (g_value_get_string (value)); | |
282 | } | |
283 | break; | |
284 | ||
285 | case PROP_PROVIDER: | |
286 | { | |
287 | g_return_if_fail (self->provider == NULL); | |
288 | self->provider = g_object_ref (g_value_get_object (value)); | |
289 | } | |
290 | break; | |
291 | ||
292 | case PROP_STATUS: | |
293 | { | |
294 | self->status = g_value_get_enum (value); | |
295 | cloud_providers_dbus_account_set_status (self->skeleton, self->status); | |
296 | } | |
297 | break; | |
298 | ||
299 | case PROP_STATUS_DETAILS: | |
300 | { | |
301 | g_free (self->status_details); | |
302 | self->status_details = g_strdup (g_value_get_string (value)); | |
303 | cloud_providers_dbus_account_set_status_details (self->skeleton, self->status_details); | |
304 | } | |
305 | break; | |
306 | ||
307 | case PROP_ICON: | |
308 | { | |
309 | g_free (self->icon); | |
310 | self->icon = g_icon_to_string (g_value_get_object (value)); | |
311 | cloud_providers_dbus_account_set_icon (self->skeleton, | |
312 | self->icon); | |
313 | } | |
314 | break; | |
315 | ||
316 | case PROP_PATH: | |
317 | { | |
318 | g_free (self->path); | |
319 | self->path = g_strdup (g_value_get_string (value)); | |
320 | cloud_providers_dbus_account_set_path (self->skeleton, self->path); | |
321 | } | |
322 | break; | |
323 | ||
324 | case PROP_ACTION_GROUP: | |
325 | { | |
326 | g_return_if_fail (self->action_group == NULL); | |
327 | ||
328 | self->action_group = g_object_ref (g_value_get_object (value)); | |
329 | export_action_group (self); | |
330 | } | |
331 | break; | |
332 | ||
333 | case PROP_MENU_MODEL: | |
334 | { | |
335 | g_return_if_fail (self->menu_model == NULL); | |
336 | ||
337 | self->menu_model = g_object_ref (g_value_get_object (value)); | |
338 | export_menu_model (self); | |
339 | } | |
340 | break; | |
341 | ||
342 | default: | |
343 | { | |
344 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
345 | } | |
346 | } | |
347 | } | |
348 | ||
349 | void | |
350 | cloud_providers_account_exporter_set_name (CloudProvidersAccountExporter *self, | |
351 | const gchar *name) | |
352 | { | |
353 | g_object_set (self, "name", name, NULL); | |
354 | } | |
355 | ||
356 | void | |
357 | cloud_providers_account_exporter_set_status (CloudProvidersAccountExporter *self, | |
358 | CloudProvidersAccountStatus status) | |
359 | { | |
360 | g_object_set (self, "status", status, NULL); | |
361 | } | |
362 | ||
363 | void | |
364 | cloud_providers_account_exporter_set_status_details (CloudProvidersAccountExporter *self, | |
365 | const gchar *status_details) | |
366 | { | |
367 | g_object_set (self, "status_details", status_details, NULL); | |
368 | } | |
369 | ||
370 | void | |
371 | cloud_providers_account_exporter_set_icon (CloudProvidersAccountExporter *self, | |
372 | GIcon *icon) | |
373 | { | |
374 | g_object_set (self, "icon", icon, NULL); | |
375 | } | |
376 | ||
377 | /** | |
378 | * cloud_providers_account_exporter_set_menu_model: | |
379 | * @self: The account | |
380 | * @menu_model: The menu model to export | |
381 | * | |
382 | * One of the benefits of the integration is to display a menu with available | |
383 | * options for an account. Use this function to export a GMenuModel menu to be | |
384 | * displayed by the choosen integration by the desktop environment or application. | |
385 | */ | |
386 | void | |
387 | cloud_providers_account_exporter_set_menu_model (CloudProvidersAccountExporter *self, | |
388 | GMenuModel *menu_model) | |
389 | { | |
390 | g_object_set (self, "menu_model", menu_model, NULL); | |
391 | } | |
392 | ||
393 | /** | |
394 | * cloud_providers_account_exporter_set_action_group: | |
395 | * @self: The cloud provider | |
396 | * @account_name: The name of the account | |
397 | * @action_group: The GActionGroup to be used by the menu exported by cloud_providers_account_exporter_export_menu | |
398 | * | |
399 | * In order for a menu exported with cloud_providers_account_exporter_export_menu to receive events | |
400 | * that will eventually call your callbacks, it needs the corresponding GAcionGroup. | |
401 | * Use this function to export it. | |
402 | */ | |
403 | void | |
404 | cloud_providers_account_exporter_set_action_group (CloudProvidersAccountExporter *self, | |
405 | GActionGroup *action_group) | |
406 | { | |
407 | g_object_set (self, "action_group", action_group, NULL); | |
408 | } | |
409 | ||
410 | void | |
411 | cloud_providers_account_exporter_set_path (CloudProvidersAccountExporter *self, | |
412 | const gchar *path) | |
413 | { | |
414 | g_object_set (self, "path", path, NULL); | |
415 | } | |
416 | ||
417 | static void | |
418 | cloud_providers_account_exporter_finalize (GObject *object) | |
419 | { | |
420 | CloudProvidersAccountExporter *self = (CloudProvidersAccountExporter *)object; | |
421 | ||
422 | g_debug ("finalize account"); | |
423 | g_free (self->bus_name); | |
424 | g_object_unref (self->skeleton); | |
425 | ||
426 | g_free (self->name); | |
427 | g_free (self->object_path); | |
428 | g_free (self->status_details); | |
429 | g_free (self->path); | |
430 | g_free (self->icon); | |
431 | g_object_unref (self->action_group); | |
432 | g_object_unref (self->menu_model); | |
433 | g_object_unref (self->provider); | |
434 | ||
435 | G_OBJECT_CLASS (cloud_providers_account_exporter_parent_class)->finalize (object); | |
436 | } | |
437 | ||
438 | static void | |
439 | cloud_providers_account_exporter_constructed (GObject *object) | |
440 | { | |
441 | const gchar *provider_object_path; | |
442 | g_autofree gchar *object_path = NULL; | |
443 | CloudProvidersAccountExporter *self = CLOUD_PROVIDERS_ACCOUNT_EXPORTER (object); | |
444 | ||
445 | self->bus = cloud_providers_provider_exporter_get_bus (self->provider); | |
446 | self->skeleton = cloud_providers_dbus_account_skeleton_new (); | |
447 | provider_object_path = cloud_providers_provider_exporter_get_object_path (self->provider); | |
448 | self->object_path = g_strconcat (provider_object_path, "/", self->bus_name, NULL); | |
449 | } | |
450 | ||
451 | static void | |
452 | cloud_providers_account_exporter_init (CloudProvidersAccountExporter *self) | |
453 | { | |
454 | } | |
455 | ||
456 | static void | |
457 | cloud_providers_account_exporter_class_init (CloudProvidersAccountExporterClass *klass) | |
458 | { | |
459 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
460 | ||
461 | object_class->get_property = cloud_providers_account_exporter_get_property; | |
462 | object_class->set_property = cloud_providers_account_exporter_set_property; | |
463 | object_class->constructed = cloud_providers_account_exporter_constructed; | |
464 | object_class->finalize = cloud_providers_account_exporter_finalize; | |
465 | ||
466 | properties [PROP_NAME] = | |
467 | g_param_spec_string ("name", | |
468 | "Name", | |
469 | "The name of the account", | |
470 | NULL, | |
471 | (G_PARAM_READWRITE | | |
472 | G_PARAM_STATIC_STRINGS)); | |
473 | g_object_class_install_property (object_class, PROP_NAME, | |
474 | properties [PROP_NAME]); | |
475 | properties [PROP_BUS_NAME] = | |
476 | g_param_spec_string ("bus-name", | |
477 | "BusName", | |
478 | "The bus name of the account", | |
479 | NULL, | |
480 | (G_PARAM_READWRITE | | |
481 | G_PARAM_STATIC_STRINGS| | |
482 | G_PARAM_CONSTRUCT_ONLY)); | |
483 | g_object_class_install_property (object_class, PROP_BUS_NAME, | |
484 | properties [PROP_BUS_NAME]); | |
485 | properties [PROP_PROVIDER] = | |
486 | g_param_spec_object ("provider", | |
487 | "Provider", | |
488 | "The provider associated with the account", | |
489 | CLOUD_PROVIDERS_TYPE_PROVIDER_EXPORTER, | |
490 | (G_PARAM_READWRITE | | |
491 | G_PARAM_STATIC_STRINGS | | |
492 | G_PARAM_CONSTRUCT_ONLY)); | |
493 | g_object_class_install_property (object_class, PROP_PROVIDER, | |
494 | properties [PROP_PROVIDER]); | |
495 | properties [PROP_PATH] = | |
496 | g_param_spec_string ("path", | |
497 | "Path", | |
498 | "The path of the directory where files are located", | |
499 | NULL, | |
500 | (G_PARAM_READWRITE | | |
501 | G_PARAM_STATIC_STRINGS)); | |
502 | g_object_class_install_property (object_class, PROP_PATH, | |
503 | properties [PROP_PATH]); | |
504 | properties [PROP_STATUS] = | |
505 | g_param_spec_enum ("status", | |
506 | "Status", | |
507 | "Status of the account", | |
508 | CLOUD_TYPE_PROVIDERS_ACCOUNT_STATUS, | |
509 | CLOUD_PROVIDERS_ACCOUNT_STATUS_INVALID, | |
510 | (G_PARAM_READWRITE | | |
511 | G_PARAM_STATIC_STRINGS)); | |
512 | g_object_class_install_property (object_class, PROP_STATUS, | |
513 | properties [PROP_STATUS]); | |
514 | properties [PROP_STATUS_DETAILS] = | |
515 | g_param_spec_string ("status-details", | |
516 | "StatusDetails", | |
517 | "The details of the account status", | |
518 | NULL, | |
519 | (G_PARAM_READWRITE | | |
520 | G_PARAM_STATIC_STRINGS)); | |
521 | g_object_class_install_property (object_class, PROP_STATUS_DETAILS, | |
522 | properties [PROP_STATUS_DETAILS]); | |
523 | properties [PROP_ICON] = | |
524 | g_param_spec_object ("icon", | |
525 | "Icon", | |
526 | "The icon representing the account", | |
527 | G_TYPE_ICON, | |
528 | (G_PARAM_READWRITE | | |
529 | G_PARAM_STATIC_STRINGS)); | |
530 | g_object_class_install_property (object_class, PROP_ICON, | |
531 | properties [PROP_ICON]); | |
532 | properties [PROP_MENU_MODEL] = | |
533 | g_param_spec_object ("menu-model", | |
534 | "MenuModel", | |
535 | "The menu model associated with the account", | |
536 | G_TYPE_MENU_MODEL, | |
537 | (G_PARAM_READWRITE | | |
538 | G_PARAM_STATIC_STRINGS)); | |
539 | g_object_class_install_property (object_class, PROP_MENU_MODEL, | |
540 | properties [PROP_MENU_MODEL]); | |
541 | properties [PROP_ACTION_GROUP] = | |
542 | g_param_spec_object ("action-group", | |
543 | "ActionGroup", | |
544 | "The action group associated with the account and menu model", | |
545 | G_TYPE_ACTION_GROUP, | |
546 | (G_PARAM_READWRITE | | |
547 | G_PARAM_STATIC_STRINGS)); | |
548 | g_object_class_install_property (object_class, PROP_ACTION_GROUP, | |
549 | properties [PROP_ACTION_GROUP]); | |
550 | } | |
551 |
0 | /* cloudprovidersaccountexporter.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_PROVIDERS_ACCOUNT_EXPORTER_H | |
19 | #define CLOUD_PROVIDERS_ACCOUNT_EXPORTER_H | |
20 | ||
21 | #include <gio/gio.h> | |
22 | #include "cloudprovidersaccount.h" | |
23 | ||
24 | G_BEGIN_DECLS | |
25 | ||
26 | #define CLOUD_PROVIDERS_TYPE_ACCOUNT_EXPORTER (cloud_providers_account_exporter_get_type()) | |
27 | G_DECLARE_FINAL_TYPE (CloudProvidersAccountExporter, cloud_providers_account_exporter, CLOUD_PROVIDERS, ACCOUNT_EXPORTER, GObject); | |
28 | ||
29 | typedef struct _CloudProvidersProviderExporter CloudProvidersProviderExporter; | |
30 | ||
31 | struct _CloudProvidersAccountExporterClass | |
32 | { | |
33 | GObjectClass parent_class; | |
34 | }; | |
35 | ||
36 | CloudProvidersAccountExporter* | |
37 | cloud_providers_account_exporter_new (CloudProvidersProviderExporter *provider, | |
38 | const gchar *bus_name); | |
39 | ||
40 | void | |
41 | cloud_providers_account_exporter_set_name (CloudProvidersAccountExporter *self, | |
42 | const gchar *name); | |
43 | ||
44 | void | |
45 | cloud_providers_account_exporter_set_status (CloudProvidersAccountExporter *self, | |
46 | CloudProvidersAccountStatus status); | |
47 | ||
48 | void | |
49 | cloud_providers_account_exporter_set_status_details (CloudProvidersAccountExporter *self, | |
50 | const gchar *status_details); | |
51 | ||
52 | void | |
53 | cloud_providers_account_exporter_set_icon (CloudProvidersAccountExporter *self, | |
54 | GIcon *icon); | |
55 | ||
56 | void | |
57 | cloud_providers_account_exporter_set_menu_model (CloudProvidersAccountExporter *self, | |
58 | GMenuModel *menu_model); | |
59 | ||
60 | void | |
61 | cloud_providers_account_exporter_set_action_group (CloudProvidersAccountExporter *self, | |
62 | GActionGroup *action_group); | |
63 | ||
64 | void | |
65 | cloud_providers_account_exporter_set_path (CloudProvidersAccountExporter *self, | |
66 | const gchar *path); | |
67 | ||
68 | G_END_DECLS | |
69 | ||
70 | #endif /* CLOUD_PROVIDERS_ACCOUNT_EXPORTER_H */ |
0 | /* cloudprovidersaccountexporterpriv.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_PROVIDERS_ACCOUNT_EXPORTER_PRIV_H | |
19 | #define CLOUD_PROVIDERS_ACCOUNT_EXPORTER_PRIV_H | |
20 | ||
21 | #include <gio/gio.h> | |
22 | #include "cloudprovidersaccountexporter.h" | |
23 | #include "cloudproviders-generated.h" | |
24 | G_BEGIN_DECLS | |
25 | ||
26 | CloudProvidersDbusAccount* | |
27 | cloud_providers_account_exporter_get_skeleton (CloudProvidersAccountExporter *self); | |
28 | gchar * | |
29 | cloud_providers_account_exporter_get_object_path (CloudProvidersAccountExporter *self); | |
30 | gchar * | |
31 | cloud_providers_account_exporter_get_bus_name (CloudProvidersAccountExporter *self); | |
32 | ||
33 | #endif |
0 | /* cloudproviders.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 "cloudproviderscollector.h" | |
20 | #include "cloudprovidersaccount.h" | |
21 | #include "cloudprovidersprovider.h" | |
22 | #include "cloudproviders-generated.h" | |
23 | #include <glib.h> | |
24 | #include <glib/gprintf.h> | |
25 | #include <gio/gio.h> | |
26 | ||
27 | #define KEY_FILE_GROUP "Cloud Providers" | |
28 | ||
29 | struct _CloudProvidersCollector | |
30 | { | |
31 | GObject parent; | |
32 | ||
33 | GList *providers; | |
34 | guint dbus_owner_id; | |
35 | GDBusNodeInfo *dbus_node_info; | |
36 | GHashTable* provider_object_managers; | |
37 | GDBusConnection *bus; | |
38 | GCancellable *cancellable; | |
39 | GList *monitors; | |
40 | }; | |
41 | ||
42 | G_DEFINE_TYPE (CloudProvidersCollector, cloud_providers_collector, G_TYPE_OBJECT) | |
43 | ||
44 | /** | |
45 | * SECTION:cloudproviderscollector | |
46 | * @title: CloudProvidersCollector | |
47 | * @short_description: Singleton for tracking all providers. | |
48 | * @include: src/cloudproviders.h | |
49 | * | |
50 | * #CloudProvidersCollector is a singleton to track all the changes in all providers. | |
51 | * Using a #CloudProvidersCollector you can implement integration for all of them at once | |
52 | * and represent them in the UI, track new providers added or removed and their | |
53 | * status. | |
54 | */ | |
55 | ||
56 | enum | |
57 | { | |
58 | PROVIDERS_CHANGED, | |
59 | LAST_SIGNAL | |
60 | }; | |
61 | ||
62 | static guint signals [LAST_SIGNAL]; | |
63 | ||
64 | static void | |
65 | update_cloud_providers (CloudProvidersCollector *self); | |
66 | ||
67 | static void | |
68 | on_bus_acquired (GObject *source_object, | |
69 | GAsyncResult *res, | |
70 | gpointer user_data) | |
71 | { | |
72 | GError *error = NULL; | |
73 | CloudProvidersCollector *self; | |
74 | GDBusConnection *bus; | |
75 | ||
76 | bus = g_bus_get_finish (res, &error); | |
77 | if (error != NULL) | |
78 | { | |
79 | if (error->code != G_IO_ERROR_CANCELLED) | |
80 | g_warning ("Error acdquiring bus for cloud provider %s", error->message); | |
81 | return; | |
82 | } | |
83 | ||
84 | self = CLOUD_PROVIDERS_COLLECTOR (user_data); | |
85 | self->bus = bus; | |
86 | g_clear_object (&self->cancellable); | |
87 | self->cancellable = g_cancellable_new (); | |
88 | ||
89 | update_cloud_providers (self); | |
90 | } | |
91 | ||
92 | static void | |
93 | cloud_providers_collector_finalize (GObject *object) | |
94 | { | |
95 | CloudProvidersCollector *self = (CloudProvidersCollector *)object; | |
96 | GList *l; | |
97 | ||
98 | g_cancellable_cancel (self->cancellable); | |
99 | for (l = self->monitors; l != NULL; l = l->next) | |
100 | { | |
101 | g_signal_handlers_disconnect_by_data (G_OBJECT (l->data), self); | |
102 | } | |
103 | g_list_free_full (self->providers, g_object_unref); | |
104 | g_list_free_full (self->monitors, g_object_unref); | |
105 | ||
106 | g_bus_unown_name (self->dbus_owner_id); | |
107 | g_dbus_node_info_unref (self->dbus_node_info); | |
108 | ||
109 | G_OBJECT_CLASS (cloud_providers_collector_parent_class)->finalize (object); | |
110 | } | |
111 | ||
112 | static void | |
113 | cloud_providers_collector_class_init (CloudProvidersCollectorClass *klass) | |
114 | { | |
115 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
116 | ||
117 | object_class->finalize = cloud_providers_collector_finalize; | |
118 | ||
119 | /** | |
120 | * CloudProviderCollector::providers-changed | |
121 | * | |
122 | * This signal is emmited by the ammount of providers changed. | |
123 | */ | |
124 | signals [PROVIDERS_CHANGED] = g_signal_new ("providers-changed", | |
125 | G_TYPE_FROM_CLASS (klass), | |
126 | G_SIGNAL_RUN_LAST, | |
127 | 0, | |
128 | NULL, | |
129 | NULL, | |
130 | g_cclosure_marshal_generic, | |
131 | G_TYPE_NONE, | |
132 | 0); | |
133 | } | |
134 | ||
135 | static void | |
136 | cloud_providers_collector_init (CloudProvidersCollector *self) | |
137 | { | |
138 | } | |
139 | ||
140 | /** | |
141 | * cloud_providers_collector_get_providers | |
142 | * @self: A CloudProvidersCollector | |
143 | * Returns: (transfer none): A GList* of #CloudProvidersAccount objects. | |
144 | */ | |
145 | GList* | |
146 | cloud_providers_collector_get_providers (CloudProvidersCollector *self) | |
147 | { | |
148 | return self->providers; | |
149 | } | |
150 | ||
151 | static void | |
152 | load_cloud_provider (CloudProvidersCollector *self, | |
153 | GFile *file) | |
154 | { | |
155 | GKeyFile *key_file; | |
156 | gchar *path; | |
157 | GError *error = NULL; | |
158 | gchar *bus_name; | |
159 | gchar *object_path; | |
160 | gboolean success = FALSE; | |
161 | CloudProvidersProvider *provider; | |
162 | ||
163 | key_file = g_key_file_new (); | |
164 | path = g_file_get_path (file); | |
165 | g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, &error); | |
166 | if (error != NULL) | |
167 | { | |
168 | g_debug ("test 1"); | |
169 | goto out; | |
170 | } | |
171 | ||
172 | if (!g_key_file_has_group (key_file, KEY_FILE_GROUP)) | |
173 | { | |
174 | g_debug ("test 2"); | |
175 | goto out; | |
176 | } | |
177 | ||
178 | bus_name = g_key_file_get_string (key_file, KEY_FILE_GROUP, "BusName", &error); | |
179 | if (error != NULL) | |
180 | { | |
181 | g_debug ("test 3"); | |
182 | goto out; | |
183 | } | |
184 | object_path = g_key_file_get_string (key_file, KEY_FILE_GROUP, "ObjectPath", &error); | |
185 | if (error != NULL) | |
186 | { | |
187 | g_debug ("test 4"); | |
188 | goto out; | |
189 | } | |
190 | ||
191 | provider = cloud_providers_provider_new (bus_name, object_path); | |
192 | self->providers = g_list_append (self->providers, provider); | |
193 | ||
194 | g_debug("Client loading provider: %s %s\n", bus_name, object_path); | |
195 | ||
196 | success = TRUE; | |
197 | g_free (bus_name); | |
198 | g_free (object_path); | |
199 | out: | |
200 | if (!success) | |
201 | { | |
202 | g_warning ("Error while loading cloud provider key file at %s with error %s", path, error != NULL ? error->message : NULL); | |
203 | } | |
204 | g_key_file_free (key_file); | |
205 | g_object_unref (file); | |
206 | g_free (path); | |
207 | } | |
208 | ||
209 | static void | |
210 | on_providers_file_changed (CloudProvidersCollector *self) | |
211 | { | |
212 | update_cloud_providers (self); | |
213 | } | |
214 | ||
215 | static void | |
216 | load_cloud_providers (CloudProvidersCollector *self) | |
217 | { | |
218 | const gchar* const *data_dirs; | |
219 | gint i; | |
220 | gint len; | |
221 | gchar *key_files_directory_path; | |
222 | GFile *key_files_directory_file; | |
223 | GError *error = NULL; | |
224 | GFileEnumerator *file_enumerator; | |
225 | ||
226 | data_dirs = g_get_system_data_dirs (); | |
227 | len = g_strv_length ((gchar **)data_dirs); | |
228 | for (i = 0; i < len; i++) | |
229 | { | |
230 | GFileInfo *info; | |
231 | GFileMonitor *monitor; | |
232 | ||
233 | key_files_directory_path = g_build_filename (data_dirs[i], "cloud-providers", NULL); | |
234 | key_files_directory_file = g_file_new_for_path (key_files_directory_path); | |
235 | monitor = g_file_monitor (key_files_directory_file, G_FILE_MONITOR_WATCH_MOVES, | |
236 | self->cancellable, NULL); | |
237 | g_signal_connect_swapped (monitor, "changed", G_CALLBACK (on_providers_file_changed), self); | |
238 | self->monitors = g_list_append (self->monitors, monitor); | |
239 | file_enumerator = g_file_enumerate_children (key_files_directory_file, | |
240 | "standard::name,standard::type", | |
241 | G_FILE_QUERY_INFO_NONE, | |
242 | NULL, | |
243 | &error); | |
244 | if (error) | |
245 | { | |
246 | error = NULL; | |
247 | continue; | |
248 | } | |
249 | ||
250 | info = g_file_enumerator_next_file (file_enumerator, NULL, &error); | |
251 | if (error) | |
252 | { | |
253 | g_warning ("Error while enumerating file %s error: %s\n", key_files_directory_path, error->message); | |
254 | error = NULL; | |
255 | continue; | |
256 | } | |
257 | while (info != NULL && error == NULL) | |
258 | { | |
259 | load_cloud_provider (self, g_file_enumerator_get_child (file_enumerator, info)); | |
260 | g_object_unref (info); | |
261 | info = g_file_enumerator_next_file (file_enumerator, NULL, &error); | |
262 | } | |
263 | g_object_unref (file_enumerator); | |
264 | g_free (key_files_directory_path); | |
265 | g_object_unref (key_files_directory_file); | |
266 | } | |
267 | } | |
268 | ||
269 | static void | |
270 | update_cloud_providers (CloudProvidersCollector *self) | |
271 | { | |
272 | GList *l; | |
273 | ||
274 | g_cancellable_cancel (self->cancellable); | |
275 | self->cancellable = g_cancellable_new (); | |
276 | for (l = self->monitors; l != NULL; l = l->next) | |
277 | { | |
278 | g_signal_handlers_disconnect_by_data (G_OBJECT (l->data), self); | |
279 | } | |
280 | g_list_free_full (self->providers, g_object_unref); | |
281 | g_list_free_full (self->monitors, g_object_unref); | |
282 | self->providers = NULL; | |
283 | self->monitors = NULL; | |
284 | ||
285 | load_cloud_providers (self); | |
286 | ||
287 | g_signal_emit_by_name (G_OBJECT (self), "providers-changed"); | |
288 | } | |
289 | ||
290 | /** | |
291 | * cloud_providers_collector_dup_singleton: | |
292 | * Main object to track changes in all providers. | |
293 | * | |
294 | * Returns: (transfer full): A manager singleton | |
295 | */ | |
296 | CloudProvidersCollector * | |
297 | cloud_providers_collector_dup_singleton (void) | |
298 | { | |
299 | static CloudProvidersCollector *self = NULL; | |
300 | ||
301 | if (self == NULL) | |
302 | { | |
303 | self = CLOUD_PROVIDERS_COLLECTOR (g_object_new (CLOUD_PROVIDERS_TYPE_COLLECTOR, NULL)); | |
304 | self->provider_object_managers = g_hash_table_new(g_str_hash, g_str_equal); | |
305 | ||
306 | g_bus_get (G_BUS_TYPE_SESSION, | |
307 | self->cancellable, | |
308 | on_bus_acquired, | |
309 | self); | |
310 | ||
311 | return self; | |
312 | } | |
313 | else | |
314 | { | |
315 | return g_object_ref (self); | |
316 | } | |
317 | } | |
318 |
0 | /* cloudproviderscollector.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 | #ifndef CLOUD_PROVIDERS_COLLECTOR_H | |
19 | #define CLOUD_PROVIDERS_COLLECTOR_H | |
20 | ||
21 | #include <gio/gio.h> | |
22 | #include "cloudprovidersaccount.h" | |
23 | ||
24 | G_BEGIN_DECLS | |
25 | ||
26 | #define CLOUD_PROVIDERS_TYPE_COLLECTOR (cloud_providers_collector_get_type()) | |
27 | G_DECLARE_FINAL_TYPE (CloudProvidersCollector, cloud_providers_collector, CLOUD_PROVIDERS, COLLECTOR, GObject); | |
28 | ||
29 | struct _CloudProvidersCollectorClass | |
30 | { | |
31 | GObjectClass parent_class; | |
32 | }; | |
33 | ||
34 | CloudProvidersCollector *cloud_providers_collector_dup_singleton (void); | |
35 | void cloud_providers_collector_update (CloudProvidersCollector *self); | |
36 | GList *cloud_providers_collector_get_providers (CloudProvidersCollector *self); | |
37 | G_END_DECLS | |
38 | ||
39 | #endif /* CLOUD_PROVIDERS_COLLECTOR_H */ |
16 | 16 | */ |
17 | 17 | |
18 | 18 | #include <glib.h> |
19 | #include <cloudprovidermanager.h> | |
19 | #include <cloudprovidersmanager.h> | |
20 | 20 | |
21 | 21 | static GMainLoop *loop; |
22 | static CloudProviderManager *manager; | |
22 | static CloudProvidersManager *manager; | |
23 | 23 | static guint dbus_owner_id; |
24 | 24 | |
25 | 25 | static void |
55 | 55 | |
56 | 56 | g_debug ("Acquired the name %s on the session message bus", name); |
57 | 57 | |
58 | manager = cloud_provider_manager_new (connection); | |
59 | cloud_provider_manager_export (manager); | |
58 | manager = cloud_providers_manager_new (connection); | |
60 | 59 | } |
61 | 60 | |
62 | 61 | gint |
63 | main (gint argc, gchar *argv[]) | |
62 | main (gint argc, gchar *argv[]) | |
64 | 63 | { |
65 | 64 | loop = g_main_loop_new(NULL, FALSE); |
66 | 65 | |
67 | 66 | dbus_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, |
68 | CLOUD_PROVIDER_MANAGER_DBUS_NAME, | |
67 | CLOUD_PROVIDERS_MANAGER_DBUS_NAME, | |
69 | 68 | G_BUS_NAME_OWNER_FLAGS_NONE, |
70 | 69 | on_bus_acquired, |
71 | 70 | on_name_acquired, |
0 | /* cloudprovidersmanager.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 "cloudprovidersmanager.h" | |
20 | #include <glib.h> | |
21 | #include <glib/gprintf.h> | |
22 | #include <gio/gio.h> | |
23 | ||
24 | struct _CloudProvidersManager | |
25 | { | |
26 | GObject parent; | |
27 | ||
28 | GList *providers; | |
29 | GDBusConnection *connection; | |
30 | GDBusNodeInfo *dbus_node_info; | |
31 | GVariant *providers_objects; | |
32 | CloudProvidersDbusManager *skeleton; | |
33 | }; | |
34 | ||
35 | G_DEFINE_TYPE (CloudProvidersManager, cloud_providers_manager, G_TYPE_OBJECT) | |
36 | ||
37 | #define KEY_FILE_GROUP "Cloud Providers" | |
38 | ||
39 | /** | |
40 | * load_cloud_provider | |
41 | * @manager: A CloudProvidersManager | |
42 | * @file: A GFile | |
43 | */ | |
44 | static void | |
45 | load_cloud_provider (CloudProvidersManager *self, | |
46 | GFile *file, | |
47 | GVariantBuilder *builder) | |
48 | { | |
49 | GKeyFile *key_file; | |
50 | gchar *path; | |
51 | GError *error = NULL; | |
52 | gchar *bus_name; | |
53 | gchar *object_path; | |
54 | gboolean success = FALSE; | |
55 | ||
56 | key_file = g_key_file_new (); | |
57 | path = g_file_get_path (file); | |
58 | g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, &error); | |
59 | if (error != NULL) | |
60 | { | |
61 | g_warning ("Error while loading cloud provider key file at %s", path); | |
62 | goto out; | |
63 | } | |
64 | ||
65 | if (!g_key_file_has_group (key_file, KEY_FILE_GROUP)) | |
66 | goto out; | |
67 | ||
68 | bus_name = g_key_file_get_string (key_file, KEY_FILE_GROUP, "BusName", &error); | |
69 | if (error != NULL) | |
70 | goto out; | |
71 | object_path = g_key_file_get_string (key_file, KEY_FILE_GROUP, "ObjectPath", &error); | |
72 | if (error != NULL) | |
73 | goto out; | |
74 | ||
75 | g_variant_builder_add(builder, "(so)", bus_name, object_path); | |
76 | ||
77 | success = TRUE; | |
78 | g_free (bus_name); | |
79 | g_free (object_path); | |
80 | out: | |
81 | if (!success) | |
82 | g_warning ("Error while loading cloud provider key file at %s", path); | |
83 | g_key_file_free (key_file); | |
84 | g_object_unref (file); | |
85 | g_free (path); | |
86 | } | |
87 | ||
88 | static void | |
89 | cloud_providers_manager_update (CloudProvidersManager *self) | |
90 | { | |
91 | const gchar* const *data_dirs; | |
92 | gint i; | |
93 | gint len; | |
94 | gchar *key_files_directory_path; | |
95 | GFile *key_files_directory_file; | |
96 | GError *error = NULL; | |
97 | GFileEnumerator *file_enumerator; | |
98 | GVariantBuilder *providers_dbus_objects; | |
99 | ||
100 | providers_dbus_objects = g_variant_builder_new(G_VARIANT_TYPE("a(so)")); | |
101 | ||
102 | g_list_free_full (self->providers, g_object_unref); | |
103 | self->providers = NULL; | |
104 | ||
105 | data_dirs = g_get_system_data_dirs (); | |
106 | len = g_strv_length ((gchar **)data_dirs); | |
107 | ||
108 | for (i = 0; i < len; i++) | |
109 | { | |
110 | GFileInfo *info; | |
111 | ||
112 | key_files_directory_path = g_build_filename (data_dirs[i], "cloud-providers", NULL); | |
113 | key_files_directory_file = g_file_new_for_path (key_files_directory_path); | |
114 | file_enumerator = g_file_enumerate_children (key_files_directory_file, | |
115 | "standard::name,standard::type", | |
116 | G_FILE_QUERY_INFO_NONE, | |
117 | NULL, | |
118 | &error); | |
119 | if (error) | |
120 | { | |
121 | error = NULL; | |
122 | continue; | |
123 | } | |
124 | ||
125 | info = g_file_enumerator_next_file (file_enumerator, NULL, &error); | |
126 | if (error) | |
127 | { | |
128 | g_warning ("Error while enumerating file %s error: %s\n", key_files_directory_path, error->message); | |
129 | error = NULL; | |
130 | continue; | |
131 | } | |
132 | while (info != NULL && error == NULL) | |
133 | { | |
134 | load_cloud_provider (self, g_file_enumerator_get_child (file_enumerator, info), providers_dbus_objects); | |
135 | g_object_unref (info); | |
136 | info = g_file_enumerator_next_file (file_enumerator, NULL, &error); | |
137 | } | |
138 | g_object_unref (file_enumerator); | |
139 | g_free (key_files_directory_path); | |
140 | g_object_unref (key_files_directory_file); | |
141 | } | |
142 | ||
143 | g_free(self->providers_objects); | |
144 | self->providers_objects = g_variant_builder_end(providers_dbus_objects); | |
145 | g_variant_builder_unref (providers_dbus_objects); | |
146 | ||
147 | gchar *provider_debug = g_variant_print(self->providers_objects, TRUE); | |
148 | g_debug("Manager loading provider: %s\n", provider_debug); | |
149 | g_free(provider_debug); | |
150 | } | |
151 | ||
152 | CloudProvidersManager * | |
153 | cloud_providers_manager_new (GDBusConnection *connection) | |
154 | { | |
155 | CloudProvidersManager *self; | |
156 | ||
157 | self = g_object_new (CLOUD_PROVIDERS_TYPE_MANAGER, NULL); | |
158 | ||
159 | self->connection = connection; | |
160 | self->providers = NULL; | |
161 | self->skeleton = cloud_providers_dbus_manager_skeleton_new (); | |
162 | g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self->skeleton), | |
163 | self->connection, | |
164 | CLOUD_PROVIDERS_MANAGER_DBUS_PATH, | |
165 | NULL); | |
166 | cloud_providers_manager_update (CLOUD_PROVIDERS_MANAGER(self)); | |
167 | cloud_providers_dbus_manager_set_providers (self->skeleton, self->providers_objects); | |
168 | ||
169 | return self; | |
170 | } | |
171 | ||
172 | static void | |
173 | cloud_providers_manager_finalize (GObject *object) | |
174 | { | |
175 | CloudProvidersManager *self = (CloudProvidersManager *)object; | |
176 | ||
177 | g_list_free_full (self->providers, g_object_unref); | |
178 | g_dbus_node_info_unref (self->dbus_node_info); | |
179 | ||
180 | G_OBJECT_CLASS (cloud_providers_manager_parent_class)->finalize (object); | |
181 | } | |
182 | ||
183 | static void | |
184 | cloud_providers_manager_class_init (CloudProvidersManagerClass *klass) | |
185 | { | |
186 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
187 | ||
188 | object_class->finalize = cloud_providers_manager_finalize; | |
189 | } | |
190 | ||
191 | static void | |
192 | cloud_providers_manager_init (CloudProvidersManager *self) | |
193 | { | |
194 | } |
0 | /* cloudprovidersmanager.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 | #ifndef CLOUD_PROVIDERS_MANAGER_H | |
19 | #define CLOUD_PROVIDERS_MANAGER_H | |
20 | ||
21 | #include <gio/gio.h> | |
22 | #include "cloudproviders-generated.h" | |
23 | ||
24 | #define CLOUD_PROVIDERS_MANAGER_DBUS_IFACE "org.freedesktop.CloudProviders.Manager1" | |
25 | #define CLOUD_PROVIDERS_MANAGER_DBUS_NAME "org.freedesktop.CloudProviders.Manager" | |
26 | #define CLOUD_PROVIDERS_MANAGER_DBUS_PATH "/org/freedesktop/CloudProviders/Manager" | |
27 | ||
28 | G_BEGIN_DECLS | |
29 | ||
30 | #define CLOUD_PROVIDERS_TYPE_MANAGER (cloud_providers_manager_get_type()) | |
31 | G_DECLARE_FINAL_TYPE (CloudProvidersManager, cloud_providers_manager, CLOUD_PROVIDERS, MANAGER, GObject); | |
32 | ||
33 | struct _CloudProvidersManagerClass | |
34 | { | |
35 | GObjectClass parent_class; | |
36 | }; | |
37 | ||
38 | CloudProvidersManager *cloud_providers_manager_new (GDBusConnection *connection); | |
39 | G_END_DECLS | |
40 | ||
41 | #endif /* CLOUD_PROVIDERS_MANAGER_H */ |
0 | /* cloudprovidersprovider.c | |
1 | * | |
2 | * Copyright (C) 2017 Carlos Soriano <csoriano@gnome.org> | |
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 | #include <gio/gio.h> | |
19 | ||
20 | #include "cloudprovidersprovider.h" | |
21 | #include "cloudprovidersaccount.h" | |
22 | #include "cloudproviders-generated.h" | |
23 | ||
24 | struct _CloudProvidersProvider | |
25 | { | |
26 | GObject parent_instance; | |
27 | ||
28 | GDBusObjectManager *manager; | |
29 | gchar *name; | |
30 | GList *accounts; | |
31 | gchar *manager_bus_name; | |
32 | gchar *manager_object_path; | |
33 | gchar *provider_object_path; | |
34 | ||
35 | GHashTable* accounts_object_managers; | |
36 | GDBusConnection *bus; | |
37 | CloudProvidersDbusProvider *proxy; | |
38 | GCancellable *cancellable; | |
39 | }; | |
40 | ||
41 | G_DEFINE_TYPE (CloudProvidersProvider, cloud_providers_provider, G_TYPE_OBJECT) | |
42 | ||
43 | enum | |
44 | { | |
45 | PROP_0, | |
46 | PROP_NAME, | |
47 | N_PROPS | |
48 | }; | |
49 | ||
50 | enum | |
51 | { | |
52 | ACCOUNTS_CHANGED, | |
53 | REMOVED, | |
54 | LAST_SIGNAL | |
55 | }; | |
56 | ||
57 | static guint signals [LAST_SIGNAL]; | |
58 | static GParamSpec *properties [N_PROPS]; | |
59 | ||
60 | static void | |
61 | on_name_changed (CloudProvidersProvider *self); | |
62 | ||
63 | CloudProvidersProvider * | |
64 | cloud_providers_provider_new (const gchar *bus_name, | |
65 | const gchar *object_path) | |
66 | { | |
67 | CloudProvidersProvider *self; | |
68 | ||
69 | self = g_object_new (CLOUD_PROVIDERS_TYPE_PROVIDER, NULL); | |
70 | self->manager_bus_name = g_strdup (bus_name); | |
71 | self->manager_object_path = g_strdup (object_path); | |
72 | ||
73 | return self; | |
74 | } | |
75 | ||
76 | static void | |
77 | cloud_providers_provider_finalize (GObject *object) | |
78 | { | |
79 | CloudProvidersProvider *self = (CloudProvidersProvider *)object; | |
80 | ||
81 | g_list_free_full (self->accounts, g_object_unref); | |
82 | g_free (self->name); | |
83 | g_signal_handlers_disconnect_by_data (self->proxy, self); | |
84 | g_clear_object (&self->proxy); | |
85 | ||
86 | G_OBJECT_CLASS (cloud_providers_provider_parent_class)->finalize (object); | |
87 | } | |
88 | ||
89 | static void | |
90 | cloud_providers_provider_get_property (GObject *object, | |
91 | guint prop_id, | |
92 | GValue *value, | |
93 | GParamSpec *pspec) | |
94 | { | |
95 | CloudProvidersProvider *self = CLOUD_PROVIDERS_PROVIDER (object); | |
96 | ||
97 | switch (prop_id) | |
98 | { | |
99 | case PROP_NAME: | |
100 | { | |
101 | g_value_set_string (value, self->name); | |
102 | } | |
103 | break; | |
104 | ||
105 | default: | |
106 | { | |
107 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
108 | } | |
109 | ||
110 | } | |
111 | } | |
112 | ||
113 | static void | |
114 | cloud_providers_provider_set_property (GObject *object, | |
115 | guint prop_id, | |
116 | const GValue *value, | |
117 | GParamSpec *pspec) | |
118 | { | |
119 | CloudProvidersProvider *self = CLOUD_PROVIDERS_PROVIDER (object); | |
120 | ||
121 | switch (prop_id) | |
122 | { | |
123 | case PROP_NAME: | |
124 | { | |
125 | g_free (self->name); | |
126 | self->name = g_strdup (g_value_get_string (value)); | |
127 | g_object_notify_by_pspec (object, properties[PROP_NAME]); | |
128 | } | |
129 | break; | |
130 | ||
131 | break; | |
132 | default: | |
133 | { | |
134 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
135 | } | |
136 | ||
137 | } | |
138 | } | |
139 | ||
140 | static void | |
141 | cloud_providers_provider_class_init (CloudProvidersProviderClass *klass) | |
142 | { | |
143 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
144 | ||
145 | object_class->finalize = cloud_providers_provider_finalize; | |
146 | object_class->get_property = cloud_providers_provider_get_property; | |
147 | object_class->set_property = cloud_providers_provider_set_property; | |
148 | ||
149 | properties [PROP_NAME] = | |
150 | g_param_spec_string ("name", | |
151 | "Name", | |
152 | "Name of the provider", | |
153 | NULL, | |
154 | (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); | |
155 | g_object_class_install_property (object_class, PROP_NAME, | |
156 | properties [PROP_NAME]); | |
157 | ||
158 | /** | |
159 | * CloudProviderProvider::accounts-changed | |
160 | * | |
161 | * This signal is emmited by a provider if the number of accounts changed. | |
162 | */ | |
163 | signals [ACCOUNTS_CHANGED] = | |
164 | g_signal_new ("accounts-changed", | |
165 | G_TYPE_FROM_CLASS (klass), | |
166 | G_SIGNAL_RUN_LAST, | |
167 | 0, | |
168 | NULL, | |
169 | NULL, | |
170 | g_cclosure_marshal_generic, | |
171 | G_TYPE_NONE, | |
172 | 0); | |
173 | /** | |
174 | * CloudProviderProvider::removed | |
175 | * | |
176 | * This signal is emmited by a provider when the provider is removed in DBUS. | |
177 | */ | |
178 | signals [ACCOUNTS_CHANGED] = | |
179 | g_signal_new ("removed", | |
180 | G_TYPE_FROM_CLASS (klass), | |
181 | G_SIGNAL_RUN_LAST, | |
182 | 0, | |
183 | NULL, | |
184 | NULL, | |
185 | g_cclosure_marshal_generic, | |
186 | G_TYPE_NONE, | |
187 | 0); | |
188 | } | |
189 | ||
190 | static void | |
191 | update_cloud_providers_accounts (CloudProvidersProvider *self) | |
192 | { | |
193 | GList *objects; | |
194 | GList *l; | |
195 | ||
196 | g_list_free_full (self->accounts, g_object_unref); | |
197 | self->accounts = NULL; | |
198 | objects = g_dbus_object_manager_get_objects (self->manager); | |
199 | if (objects == NULL) | |
200 | { | |
201 | if (self->name != NULL) | |
202 | { | |
203 | g_debug ("Provider accounts not ready server side for %s\n", self->name); | |
204 | } | |
205 | else | |
206 | { | |
207 | g_debug ("Provider accounts not ready server side for %p\n", self); | |
208 | } | |
209 | return; | |
210 | } | |
211 | ||
212 | for (l = objects; l != NULL; l = l->next) | |
213 | { | |
214 | CloudProvidersDbusObject *object; | |
215 | GDBusInterface *interface; | |
216 | ||
217 | object = CLOUD_PROVIDERS_DBUS_OBJECT (l->data); | |
218 | interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), | |
219 | CLOUD_PROVIDERS_PROVIDER_DBUS_IFACE); | |
220 | if (interface != NULL) | |
221 | { | |
222 | self->proxy = cloud_providers_dbus_object_get_provider (object); | |
223 | g_signal_connect_swapped (self->proxy, "notify::name", G_CALLBACK (on_name_changed), self); | |
224 | on_name_changed (self); | |
225 | g_object_unref (interface); | |
226 | ||
227 | continue; | |
228 | } | |
229 | interface = g_dbus_object_get_interface (G_DBUS_OBJECT (object), | |
230 | CLOUD_PROVIDERS_ACCOUNT_DBUS_IFACE); | |
231 | if (interface != NULL) | |
232 | { | |
233 | CloudProvidersAccount *account; | |
234 | ||
235 | account = cloud_providers_account_new (CLOUD_PROVIDERS_DBUS_ACCOUNT_PROXY (cloud_providers_dbus_object_peek_account (object))); | |
236 | ||
237 | self->accounts = g_list_append (self->accounts, account); | |
238 | g_object_unref (interface); | |
239 | ||
240 | continue; | |
241 | } | |
242 | } | |
243 | ||
244 | g_list_free_full (objects, g_object_unref); | |
245 | ||
246 | g_signal_emit_by_name (G_OBJECT (self), "accounts-changed", NULL); | |
247 | } | |
248 | ||
249 | static void | |
250 | on_cloud_providers_object_manager_object_added (GObject *object, | |
251 | GParamSpec *pspec, | |
252 | gpointer user_data) | |
253 | { | |
254 | CloudProvidersProvider *self; | |
255 | ||
256 | self = CLOUD_PROVIDERS_PROVIDER (user_data); | |
257 | update_cloud_providers_accounts (self); | |
258 | } | |
259 | ||
260 | static void | |
261 | on_cloud_providers_object_manager_object_removed (GObject *object, | |
262 | GParamSpec *pspec, | |
263 | gpointer user_data) | |
264 | { | |
265 | CloudProvidersProvider *self; | |
266 | ||
267 | self = CLOUD_PROVIDERS_PROVIDER (user_data); | |
268 | update_cloud_providers_accounts (self); | |
269 | } | |
270 | ||
271 | static void | |
272 | on_cloud_providers_object_manager_name_owner_changed (GObject *object, | |
273 | GParamSpec *pspec, | |
274 | gpointer user_data) | |
275 | { | |
276 | CloudProvidersProvider *self; | |
277 | ||
278 | self = CLOUD_PROVIDERS_PROVIDER (user_data); | |
279 | g_signal_emit_by_name (G_OBJECT (self), "removed", NULL); | |
280 | } | |
281 | ||
282 | static void | |
283 | on_name_changed (CloudProvidersProvider *self) | |
284 | { | |
285 | g_free (self->name); | |
286 | self->name = cloud_providers_dbus_provider_dup_name (self->proxy); | |
287 | if (self->name == NULL) | |
288 | { | |
289 | g_debug ("Provider name not ready for %p\n", self); | |
290 | return; | |
291 | } | |
292 | ||
293 | g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_NAME]); | |
294 | } | |
295 | ||
296 | static void | |
297 | on_object_manager_created (GObject *source_object, | |
298 | GAsyncResult *res, | |
299 | gpointer user_data) | |
300 | { | |
301 | CloudProvidersProvider *self; | |
302 | GError *error = NULL; | |
303 | ||
304 | self = CLOUD_PROVIDERS_PROVIDER (user_data); | |
305 | self->manager = cloud_providers_dbus_object_manager_client_new_for_bus_finish (res, &error); | |
306 | if (error != NULL) | |
307 | { | |
308 | g_printerr ("Error getting object manager client: %s", error->message); | |
309 | g_error_free (error); | |
310 | return; | |
311 | } | |
312 | ||
313 | g_signal_connect (self->manager, "notify::name-owner", | |
314 | G_CALLBACK (on_cloud_providers_object_manager_name_owner_changed), | |
315 | self); | |
316 | g_signal_connect (self->manager, "object-added", | |
317 | G_CALLBACK (on_cloud_providers_object_manager_object_added), | |
318 | self); | |
319 | g_signal_connect (self->manager, "object-removed", | |
320 | G_CALLBACK (on_cloud_providers_object_manager_object_removed), | |
321 | self); | |
322 | ||
323 | update_cloud_providers_accounts (self); | |
324 | } | |
325 | ||
326 | static void | |
327 | on_bus_acquired (GObject *source_object, | |
328 | GAsyncResult *res, | |
329 | gpointer user_data) | |
330 | { | |
331 | GError *error = NULL; | |
332 | CloudProvidersProvider *self; | |
333 | GDBusConnection *bus; | |
334 | ||
335 | bus = g_bus_get_finish (res, &error); | |
336 | if (error != NULL) | |
337 | { | |
338 | if (error->code != G_IO_ERROR_CANCELLED) | |
339 | g_warning ("Error acdquiring bus for cloud provider %s", error->message); | |
340 | return; | |
341 | } | |
342 | ||
343 | self = CLOUD_PROVIDERS_PROVIDER (user_data); | |
344 | self->bus = bus; | |
345 | g_clear_object (&self->cancellable); | |
346 | self->cancellable = g_cancellable_new (); | |
347 | ||
348 | cloud_providers_dbus_object_manager_client_new_for_bus (G_BUS_TYPE_SESSION, | |
349 | G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, | |
350 | self->manager_bus_name, | |
351 | self->manager_object_path, | |
352 | NULL, | |
353 | on_object_manager_created, | |
354 | self); | |
355 | } | |
356 | ||
357 | ||
358 | static void | |
359 | cloud_providers_provider_init (CloudProvidersProvider *self) | |
360 | { | |
361 | g_bus_get (G_BUS_TYPE_SESSION, | |
362 | self->cancellable, | |
363 | on_bus_acquired, | |
364 | self); | |
365 | } | |
366 | ||
367 | ||
368 | const gchar* | |
369 | cloud_providers_provider_get_name (CloudProvidersProvider *self) | |
370 | { | |
371 | return self->name; | |
372 | } | |
373 | ||
374 | GList* | |
375 | cloud_providers_provider_get_accounts (CloudProvidersProvider *self) | |
376 | { | |
377 | return self->accounts; | |
378 | } | |
379 |
0 | /* cloudprovidersprovider.h | |
1 | * | |
2 | * Copyright (C) 2017 Carlos Soriano <csoriano@gnome.org> | |
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 | #ifndef CLOUD_PROVIDERS_PROVIDER_H | |
18 | #define CLOUD_PROVIDERS_PROVIDER_H | |
19 | ||
20 | #include <gio/gio.h> | |
21 | #include "cloudprovidersaccount.h" | |
22 | ||
23 | G_BEGIN_DECLS | |
24 | ||
25 | #define CLOUD_PROVIDERS_PROVIDER_DBUS_IFACE "org.freedesktop.CloudProviders.Provider" | |
26 | ||
27 | #define CLOUD_PROVIDERS_TYPE_PROVIDER (cloud_providers_provider_get_type()) | |
28 | ||
29 | G_DECLARE_FINAL_TYPE (CloudProvidersProvider, cloud_providers_provider, CLOUD, PROVIDERS_PROVIDER, GObject) | |
30 | ||
31 | CloudProvidersProvider *cloud_providers_provider_new (const gchar *bus_name, | |
32 | const gchar *object_path); | |
33 | const gchar* cloud_providers_provider_get_name (CloudProvidersProvider *self); | |
34 | GList* cloud_providers_provider_get_accounts (CloudProvidersProvider *self); | |
35 | ||
36 | G_END_DECLS | |
37 | ||
38 | #endif /* CLOUD_PROVIDERS_PROVIDER_H */ | |
39 |
0 | /* cloudprovidersexporter.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 "cloudprovidersproviderexporter.h" | |
20 | #include "cloudprovidersaccountexporterpriv.h" | |
21 | #include "cloudprovidersaccountexporter.h" | |
22 | #include "cloudproviders-generated.h" | |
23 | #include <gio/gio.h> | |
24 | ||
25 | struct _CloudProvidersProviderExporter | |
26 | { | |
27 | GObject parent; | |
28 | ||
29 | CloudProvidersDbusProvider *skeleton; | |
30 | GDBusConnection *bus; | |
31 | GDBusObjectManagerServer *manager; | |
32 | gchar *manager_bus_name; | |
33 | gchar *manager_bus_path; | |
34 | ||
35 | gchar *bus_name; | |
36 | gchar *bus_path; | |
37 | gchar *provider_bus_path; | |
38 | ||
39 | gchar *name; | |
40 | GList *accounts; | |
41 | GVariant *dbus_accounts; | |
42 | }; | |
43 | ||
44 | G_DEFINE_TYPE (CloudProvidersProviderExporter, cloud_providers_provider_exporter, G_TYPE_OBJECT) | |
45 | ||
46 | enum | |
47 | { | |
48 | PROP_0, | |
49 | PROP_NAME, | |
50 | PROP_BUS_NAME, | |
51 | PROP_BUS_PATH, | |
52 | PROP_BUS, | |
53 | N_PROPS | |
54 | }; | |
55 | ||
56 | static GParamSpec *properties [N_PROPS]; | |
57 | ||
58 | /** | |
59 | * SECTION:cloudprovidersexporter | |
60 | * @title: CloudProvidersProviderExporter | |
61 | * @short_description: Base object for representing a single provider | |
62 | * @include: src/cloudprovidersexporter.h | |
63 | * | |
64 | * #CloudProvidersProviderExporter is the base object representing a single cloud provider. | |
65 | * Multiple #CloudProvidersAccountExporter objects can be added with cloud_providers_provider_exporter_add_account() | |
66 | * After adding the initial set of accounts cloud_providers_provider_exporter_export_objects() must be called. | |
67 | */ | |
68 | ||
69 | #if 0 | |
70 | static void | |
71 | update_accounts_in_dbus (CloudProvidersProviderExporter *self) | |
72 | { | |
73 | return; | |
74 | g_autoptr (GVariantBuilder) accounts_dbus_objects; | |
75 | GVariant *accounts_variant; | |
76 | GList *l; | |
77 | ||
78 | accounts_dbus_objects = g_variant_builder_new (G_VARIANT_TYPE("a(so)")); | |
79 | for (l = self->accounts; l != NULL; l = l->next) | |
80 | { | |
81 | const gchar *object_path; | |
82 | ||
83 | object_path = cloud_providers_account_exporter_get_object_path (CLOUD_PROVIDERS_ACCOUNT_EXPORTER (l->data)); | |
84 | g_variant_builder_add(accounts_dbus_objects, "(so)", self->provider_bus_name, object_path); | |
85 | } | |
86 | ||
87 | accounts_variant = g_variant_builder_end (accounts_dbus_objects); | |
88 | ||
89 | g_autofree gchar *provider_debug = g_variant_print(accounts_variant, TRUE); | |
90 | g_debug("Update accounts in dbus: %s\n", provider_debug); | |
91 | ||
92 | cloud_providers_dbus_provider_set_accounts (self->skeleton, accounts_variant); | |
93 | } | |
94 | #endif | |
95 | ||
96 | static void | |
97 | export_provider (CloudProvidersProviderExporter *self) | |
98 | { | |
99 | CloudProvidersDbusObjectSkeleton *provider_object_skeleton; | |
100 | ||
101 | provider_object_skeleton = cloud_providers_dbus_object_skeleton_new (self->provider_bus_path); | |
102 | cloud_providers_dbus_object_skeleton_set_provider (provider_object_skeleton, self->skeleton); | |
103 | g_dbus_object_manager_server_export (self->manager, | |
104 | G_DBUS_OBJECT_SKELETON (provider_object_skeleton)); | |
105 | ||
106 | g_debug ("provider object path: %s %s\n", self->provider_bus_path, | |
107 | g_dbus_object_manager_get_object_path (G_DBUS_OBJECT_MANAGER (self->manager))); | |
108 | } | |
109 | ||
110 | static void | |
111 | export_account (CloudProvidersProviderExporter *self, | |
112 | CloudProvidersAccountExporter *account) | |
113 | { | |
114 | CloudProvidersDbusAccount *account_skeleton; | |
115 | const gchar *account_object_path; | |
116 | CloudProvidersDbusObjectSkeleton *account_object_skeleton; | |
117 | ||
118 | account_object_path = cloud_providers_account_exporter_get_object_path (account); | |
119 | account_skeleton = cloud_providers_account_exporter_get_skeleton (account); | |
120 | account_object_skeleton = cloud_providers_dbus_object_skeleton_new (account_object_path); | |
121 | cloud_providers_dbus_object_skeleton_set_account (account_object_skeleton, account_skeleton); | |
122 | g_dbus_object_manager_server_export (self->manager, G_DBUS_OBJECT_SKELETON (account_object_skeleton)); | |
123 | g_debug ("account object path: %s %s\n", account_object_path, | |
124 | g_dbus_object_manager_get_object_path (G_DBUS_OBJECT_MANAGER (self->manager))); | |
125 | } | |
126 | ||
127 | static void | |
128 | unexport_account(CloudProvidersProviderExporter *self, | |
129 | CloudProvidersAccountExporter *account) | |
130 | { | |
131 | const gchar *object_path; | |
132 | CloudProvidersDbusAccount *account_skeleton; | |
133 | ||
134 | account_skeleton = cloud_providers_account_exporter_get_skeleton (account); | |
135 | object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (account_skeleton)); | |
136 | g_dbus_object_manager_server_unexport (self->manager, object_path); | |
137 | } | |
138 | ||
139 | /** | |
140 | * cloud_providers_provider_exporter_add_account: | |
141 | * @self: The cloud provider exporter | |
142 | * @account: The account object | |
143 | * | |
144 | * Each cloud provider can have a variety of account associated with it. Use this | |
145 | * function to add the accounts the user set up. Calling cloud_providers_provider_exporter_export_objects() | |
146 | * once is required after adding the initial set of accounts. | |
147 | */ | |
148 | void | |
149 | cloud_providers_provider_exporter_add_account (CloudProvidersProviderExporter *self, | |
150 | CloudProvidersAccountExporter *account) | |
151 | { | |
152 | export_account (self, account); | |
153 | //update_accounts_in_dbus (self); | |
154 | self->accounts = g_list_append (self->accounts, g_object_ref (account)); | |
155 | } | |
156 | ||
157 | /** | |
158 | * cloud_providers_provider_exporter_remove_account: | |
159 | * @self: The cloud provider exporter | |
160 | * @account: The account object | |
161 | * | |
162 | * Each cloud provider can have a variety of account associated with it. Use this | |
163 | * function to remove the accounts added by cloud_providers_provider_exporter_add_account(). | |
164 | */ | |
165 | void | |
166 | cloud_providers_provider_exporter_remove_account (CloudProvidersProviderExporter *self, | |
167 | CloudProvidersAccountExporter *account) | |
168 | { | |
169 | GList *removed_account; | |
170 | ||
171 | unexport_account (self, account); | |
172 | removed_account = g_list_find (self->accounts, account); | |
173 | g_return_if_fail (removed_account != NULL); | |
174 | self->accounts = g_list_remove (self->accounts, removed_account); | |
175 | g_object_unref (account); | |
176 | } | |
177 | ||
178 | #if 0 | |
179 | ||
180 | /** | |
181 | * cloud_providers_provider_exporter_export_objects: | |
182 | * @self: The cloud provider | |
183 | * | |
184 | * Export all objects assigned previously with cloud_providers_provider_exporter_add_account() | |
185 | * to DBUS. | |
186 | * Use this function after adding all the required objects to avoid multiple signals | |
187 | * being emitted in a short time. This function needs to be called only once. | |
188 | * Objects added after the call will be propagated to DBus automatically. | |
189 | */ | |
190 | static void | |
191 | cloud_providers_provider_exporter_export_objects(CloudProvidersProviderExporter *self) | |
192 | { | |
193 | } | |
194 | ||
195 | #endif | |
196 | ||
197 | static void | |
198 | cloud_providers_provider_exporter_get_property (GObject *object, | |
199 | guint prop_id, | |
200 | GValue *value, | |
201 | GParamSpec *pspec) | |
202 | { | |
203 | CloudProvidersProviderExporter *self = CLOUD_PROVIDERS_PROVIDER_EXPORTER (object); | |
204 | ||
205 | switch (prop_id) | |
206 | { | |
207 | case PROP_NAME: | |
208 | { | |
209 | g_value_set_string (value, self->name); | |
210 | } | |
211 | break; | |
212 | ||
213 | case PROP_BUS_NAME: | |
214 | { | |
215 | g_value_set_string (value, self->bus_name); | |
216 | } | |
217 | break; | |
218 | ||
219 | case PROP_BUS_PATH: | |
220 | { | |
221 | g_value_set_string (value, self->bus_path); | |
222 | } | |
223 | break; | |
224 | ||
225 | case PROP_BUS: | |
226 | { | |
227 | g_value_set_object (value, self->bus); | |
228 | } | |
229 | break; | |
230 | ||
231 | default: | |
232 | { | |
233 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
234 | } | |
235 | ||
236 | } | |
237 | } | |
238 | ||
239 | static void | |
240 | cloud_providers_provider_exporter_set_property (GObject *object, | |
241 | guint prop_id, | |
242 | const GValue *value, | |
243 | GParamSpec *pspec) | |
244 | { | |
245 | CloudProvidersProviderExporter *self = CLOUD_PROVIDERS_PROVIDER_EXPORTER (object); | |
246 | ||
247 | switch (prop_id) | |
248 | { | |
249 | case PROP_NAME: | |
250 | { | |
251 | g_free (self->name); | |
252 | self->name = g_strdup (g_value_get_string (value)); | |
253 | g_debug ("setting name %s\n", self->name); | |
254 | cloud_providers_dbus_provider_set_name (self->skeleton, self->name); | |
255 | } | |
256 | break; | |
257 | ||
258 | case PROP_BUS_NAME: | |
259 | { | |
260 | g_return_if_fail (self->bus_name == NULL); | |
261 | self->bus_name = g_strdup (g_value_get_string (value)); | |
262 | } | |
263 | break; | |
264 | ||
265 | case PROP_BUS_PATH: | |
266 | { | |
267 | g_return_if_fail (self->bus_path == NULL); | |
268 | self->bus_path = g_strdup (g_value_get_string (value)); | |
269 | } | |
270 | break; | |
271 | ||
272 | case PROP_BUS: | |
273 | { | |
274 | g_return_if_fail (self->bus == NULL); | |
275 | self->bus = g_object_ref (g_value_get_object (value)); | |
276 | } | |
277 | break; | |
278 | ||
279 | default: | |
280 | { | |
281 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
282 | } | |
283 | } | |
284 | } | |
285 | ||
286 | static void | |
287 | cloud_providers_provider_exporter_finalize (GObject *object) | |
288 | { | |
289 | CloudProvidersProviderExporter *self = (CloudProvidersProviderExporter *)object; | |
290 | ||
291 | g_debug ("finalize provider"); | |
292 | g_clear_object (&self->skeleton); | |
293 | g_clear_object (&self->bus); | |
294 | g_free (self->bus_name); | |
295 | g_free (self->bus_path); | |
296 | g_free (self->provider_bus_path); | |
297 | g_clear_object (&self->manager); | |
298 | g_free (self->name); | |
299 | ||
300 | g_list_free_full (self->accounts, g_object_unref); | |
301 | ||
302 | G_OBJECT_CLASS (cloud_providers_provider_exporter_parent_class)->finalize (object); | |
303 | } | |
304 | ||
305 | static void | |
306 | cloud_providers_provider_exporter_constructed (GObject *object) | |
307 | { | |
308 | CloudProvidersProviderExporter *self = CLOUD_PROVIDERS_PROVIDER_EXPORTER (object); | |
309 | ||
310 | self->manager = g_dbus_object_manager_server_new (self->bus_path); | |
311 | self->provider_bus_path = g_strconcat (self->bus_path, "/Provider", NULL); | |
312 | g_debug ("constructed, manager %s", self->bus_path); | |
313 | self->skeleton = cloud_providers_dbus_provider_skeleton_new (); | |
314 | g_dbus_object_manager_server_set_connection (self->manager, self->bus); | |
315 | export_provider (self); | |
316 | #if 0 | |
317 | g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self->skeleton), | |
318 | self->bus, self->bus_path, NULL); | |
319 | #endif | |
320 | } | |
321 | ||
322 | static void | |
323 | cloud_providers_provider_exporter_init (CloudProvidersProviderExporter *self) | |
324 | { | |
325 | } | |
326 | ||
327 | static void | |
328 | cloud_providers_provider_exporter_class_init (CloudProvidersProviderExporterClass *klass) | |
329 | { | |
330 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
331 | ||
332 | object_class->set_property = cloud_providers_provider_exporter_set_property; | |
333 | object_class->get_property = cloud_providers_provider_exporter_get_property; | |
334 | object_class->constructed = cloud_providers_provider_exporter_constructed; | |
335 | object_class->finalize = cloud_providers_provider_exporter_finalize; | |
336 | ||
337 | properties [PROP_NAME] = | |
338 | g_param_spec_string ("name", | |
339 | "Name", | |
340 | "The name of the cloud provider", | |
341 | NULL, | |
342 | (G_PARAM_READWRITE | | |
343 | G_PARAM_STATIC_STRINGS)); | |
344 | g_object_class_install_property (object_class, PROP_NAME, | |
345 | properties [PROP_NAME]); | |
346 | ||
347 | properties [PROP_BUS_NAME] = | |
348 | g_param_spec_string ("bus-name", | |
349 | "BusName", | |
350 | "BusName", | |
351 | NULL, | |
352 | (G_PARAM_READWRITE | | |
353 | G_PARAM_STATIC_STRINGS | | |
354 | G_PARAM_CONSTRUCT_ONLY)); | |
355 | g_object_class_install_property (object_class, PROP_BUS_NAME, | |
356 | properties [PROP_BUS_NAME]); | |
357 | ||
358 | properties [PROP_BUS_PATH] = | |
359 | g_param_spec_string ("bus-path", | |
360 | "BusPath", | |
361 | "BusPath", | |
362 | NULL, | |
363 | (G_PARAM_READWRITE | | |
364 | G_PARAM_STATIC_STRINGS | | |
365 | G_PARAM_CONSTRUCT_ONLY)); | |
366 | g_object_class_install_property (object_class, PROP_BUS_PATH, | |
367 | properties [PROP_BUS_PATH]); | |
368 | ||
369 | properties [PROP_BUS] = | |
370 | g_param_spec_object ("bus", | |
371 | "Bus", | |
372 | "Bus", | |
373 | G_TYPE_DBUS_CONNECTION, | |
374 | (G_PARAM_READWRITE | | |
375 | G_PARAM_STATIC_STRINGS | | |
376 | G_PARAM_CONSTRUCT_ONLY)); | |
377 | g_object_class_install_property (object_class, PROP_BUS, | |
378 | properties [PROP_BUS]); | |
379 | } | |
380 | ||
381 | void | |
382 | cloud_providers_provider_exporter_set_name (CloudProvidersProviderExporter *self, | |
383 | const gchar *name) | |
384 | { | |
385 | g_object_set (self, "name", name, NULL); | |
386 | } | |
387 | ||
388 | const gchar* | |
389 | cloud_providers_provider_exporter_get_name (CloudProvidersProviderExporter *self) | |
390 | { | |
391 | return self->name; | |
392 | } | |
393 | ||
394 | /** | |
395 | * cloud_providers_provider_exporter_new: | |
396 | * @bus: A #GDbusConnection to export the objects to | |
397 | * @bus_name: A DBus name to bind to | |
398 | * @bus_path: A DBus object path | |
399 | */ | |
400 | CloudProvidersProviderExporter * | |
401 | cloud_providers_provider_exporter_new (GDBusConnection *bus, | |
402 | const gchar *bus_name, | |
403 | const gchar *bus_path) | |
404 | { | |
405 | CloudProvidersProviderExporter *self; | |
406 | ||
407 | self = g_object_new (CLOUD_PROVIDERS_TYPE_PROVIDER_EXPORTER, | |
408 | "bus", bus, | |
409 | "bus-name", bus_name, | |
410 | "bus-path", bus_path, | |
411 | NULL); | |
412 | ||
413 | return self; | |
414 | } | |
415 | ||
416 | GDBusConnection* | |
417 | cloud_providers_provider_exporter_get_bus (CloudProvidersProviderExporter *self) | |
418 | { | |
419 | return self->bus; | |
420 | } | |
421 | ||
422 | const gchar* | |
423 | cloud_providers_provider_exporter_get_object_path (CloudProvidersProviderExporter *self) | |
424 | { | |
425 | return self->bus_path; | |
426 | } | |
427 |
0 | /* cloudprovidersexporter.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_PROVIDERS_PROVIDER_EXPORTER_H | |
19 | #define CLOUD_PROVIDERS_PROVIDER_EXPORTER_H | |
20 | ||
21 | #include <gio/gio.h> | |
22 | #include "cloudprovidersaccountexporter.h" | |
23 | ||
24 | G_BEGIN_DECLS | |
25 | ||
26 | #define CLOUD_PROVIDERS_TYPE_PROVIDER_EXPORTER (cloud_providers_provider_exporter_get_type()) | |
27 | G_DECLARE_FINAL_TYPE (CloudProvidersProviderExporter, cloud_providers_provider_exporter, CLOUD_PROVIDERS, PROVIDER_EXPORTER, GObject); | |
28 | ||
29 | struct _CloudProvidersProviderExporterClass | |
30 | { | |
31 | GObjectClass parent_class; | |
32 | }; | |
33 | ||
34 | void | |
35 | cloud_providers_provider_exporter_add_account (CloudProvidersProviderExporter *self, | |
36 | CloudProvidersAccountExporter *account); | |
37 | void | |
38 | cloud_providers_provider_exporter_remove_account (CloudProvidersProviderExporter *self, | |
39 | CloudProvidersAccountExporter *account); | |
40 | ||
41 | void | |
42 | cloud_providers_provider_exporter_set_name (CloudProvidersProviderExporter *self, | |
43 | const gchar *name); | |
44 | const gchar* | |
45 | cloud_providers_provider_exporter_get_name (CloudProvidersProviderExporter *self); | |
46 | ||
47 | CloudProvidersProviderExporter* | |
48 | cloud_providers_provider_exporter_new (GDBusConnection *bus, | |
49 | const gchar *bus_name, | |
50 | const gchar *object_path); | |
51 | // Priv | |
52 | const gchar* | |
53 | cloud_providers_provider_exporter_get_object_path (CloudProvidersProviderExporter *self); | |
54 | ||
55 | GDBusConnection* | |
56 | cloud_providers_provider_exporter_get_bus (CloudProvidersProviderExporter *self); | |
57 | ||
58 | ||
59 | G_END_DECLS | |
60 | ||
61 | #endif /* CLOUD_PROVIDERS_PROVIDER_EXPORTER_H */ |
3 | 3 | [Service] |
4 | 4 | ExecStart=@libexecdir@/cloudprovidersd |
5 | 5 | Type=dbus |
6 | BusName=org.freedesktop.CloudProvidersd | |
6 | BusName=org.freedesktop.CloudProviders.Daemon |
0 | libcloudproviders_deps = [glib, gio, gio_unix] | |
1 | ||
0 | 2 | libcloudproviders_headers = [ |
1 | 'cloudproviders.h', | |
2 | 'cloudprovideraccount.h', | |
3 | 'cloudproviderexporter.h', | |
4 | 'cloudprovideraccountexporter.h', | |
3 | 'cloudproviderscollector.h', | |
4 | 'cloudprovidersaccount.h', | |
5 | 'cloudprovidersaccountexporter.h', | |
6 | 'cloudprovidersprovider.h', | |
7 | 'cloudprovidersproviderexporter.h', | |
5 | 8 | ] |
6 | 9 | |
7 | 10 | libcloudproviders_sources = [ |
8 | 'cloudproviders.c', | |
9 | 'cloudprovideraccount.c', | |
10 | 'cloudproviderexporter.c', | |
11 | 'cloudprovideraccountexporter.c', | |
11 | 'cloudproviderscollector.c', | |
12 | 'cloudprovidersaccount.c', | |
13 | 'cloudprovidersaccountexporter.c', | |
14 | 'cloudprovidersprovider.c', | |
15 | 'cloudprovidersproviderexporter.c', | |
12 | 16 | ] |
13 | 17 | |
14 | cloudprovidersd_sources = [ | |
15 | 'cloudprovidersd.c', | |
16 | 'cloudprovidermanager.c', | |
17 | ] | |
18 | ||
19 | libcloudproviders_deps = [glib, gio, gio_unix] | |
18 | headers_with_enums = gnome.mkenums_simple('enums', sources : libcloudproviders_headers) | |
20 | 19 | |
21 | 20 | generated_sources = [] |
22 | 21 | generated_sources += gnome.gdbus_codegen( |
23 | 'cloudprovider-generated', '../data/cloudprovider-dbus.xml', | |
24 | interface_prefix: 'org.freedesktop.CloudProvider', | |
25 | namespace: 'CloudProvider', | |
22 | 'cloudproviders-generated', '../data/cloud-providers-dbus.xml', | |
23 | interface_prefix: 'org.freedesktop.CloudProviders', | |
24 | namespace: 'CloudProvidersDbus', | |
26 | 25 | object_manager: true |
27 | ) | |
28 | ||
29 | generated_sources += gnome.gdbus_codegen( | |
30 | 'cloudprovidermanager-generated', '../data/cloudprovidermanager-dbus.xml', | |
31 | interface_prefix: 'org.freedesktop.CloudProvider', | |
32 | namespace: 'CloudProvider' | |
33 | 26 | ) |
34 | 27 | |
35 | 28 | libcloudproviders_sources += generated_sources |
36 | 29 | |
37 | 30 | libcloudproviders = shared_library ('cloudproviders', |
38 | libcloudproviders_sources, | |
31 | libcloudproviders_sources, headers_with_enums, | |
39 | 32 | dependencies: libcloudproviders_deps, |
40 | 33 | version: meson.project_version(), |
41 | 34 | install: true |
70 | 63 | include_directories: include_directories('.') |
71 | 64 | ) |
72 | 65 | |
73 | executable('cloudprovidersd', | |
74 | cloudprovidersd_sources, | |
75 | dependencies: libcloudproviders_dep, | |
76 | install: true, | |
77 | install_dir: libexecdir | |
78 | ) |
0 | <?xml version='1.0' encoding='UTF-8' standalone='no'?> | |
1 | <!-- Created with Inkscape (http://www.inkscape.org/) --> | |
2 | ||
3 | <svg xmlns:cc='http://creativecommons.org/ns#' xmlns:dc='http://purl.org/dc/elements/1.1/' sodipodi:docname='application-x-appliance-symbolic.svg' height='16.03125' id='svg7384' xmlns:inkscape='http://www.inkscape.org/namespaces/inkscape' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:sodipodi='http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd' xmlns:svg='http://www.w3.org/2000/svg' inkscape:version='0.48.4 r9939' version='1.1' width='16.03125' xmlns='http://www.w3.org/2000/svg'> | |
4 | <metadata id='metadata90'> | |
5 | <rdf:RDF> | |
6 | <cc:Work rdf:about=''> | |
7 | <dc:format>image/svg+xml</dc:format> | |
8 | <dc:type rdf:resource='http://purl.org/dc/dcmitype/StillImage'/> | |
9 | <dc:title>Gnome Symbolic Icon Theme</dc:title> | |
10 | </cc:Work> | |
11 | </rdf:RDF> | |
12 | </metadata> | |
13 | <sodipodi:namedview inkscape:bbox-nodes='false' inkscape:bbox-paths='true' bordercolor='#666666' borderopacity='1' inkscape:current-layer='layer14' inkscape:cx='-2.88943' inkscape:cy='-0.340373' gridtolerance='10' inkscape:guide-bbox='true' guidetolerance='10' id='namedview88' inkscape:object-nodes='false' inkscape:object-paths='false' objecttolerance='10' pagecolor='#3a3b39' inkscape:pageopacity='1' inkscape:pageshadow='2' showborder='false' showgrid='false' showguides='true' inkscape:snap-bbox='true' inkscape:snap-bbox-midpoints='false' inkscape:snap-global='true' inkscape:snap-grids='true' inkscape:snap-nodes='false' inkscape:snap-others='false' inkscape:snap-to-guides='true' inkscape:window-height='1381' inkscape:window-maximized='1' inkscape:window-width='2560' inkscape:window-x='0' inkscape:window-y='27' inkscape:zoom='1'> | |
14 | <inkscape:grid empspacing='2' enabled='true' id='grid4866' originx='-340px' originy='84.03125px' snapvisiblegridlinesonly='true' spacingx='1px' spacingy='1px' type='xygrid' visible='true'/> | |
15 | </sodipodi:namedview> | |
16 | <title id='title9167'>Gnome Symbolic Icon Theme</title> | |
17 | <defs id='defs7386'/> | |
18 | <g inkscape:groupmode='layer' id='layer9' inkscape:label='status' style='display:inline' transform='translate(-581.0002,-301)'/> | |
19 | <g inkscape:groupmode='layer' id='layer10' inkscape:label='devices' transform='translate(-581.0002,-301)'/> | |
20 | <g inkscape:groupmode='layer' id='layer11' inkscape:label='apps' transform='translate(-581.0002,-301)'/> | |
21 | <g inkscape:groupmode='layer' id='layer13' inkscape:label='places' transform='translate(-581.0002,-301)'/> | |
22 | <g inkscape:groupmode='layer' id='layer14' inkscape:label='mimetypes' transform='translate(-581.0002,-301)'> | |
23 | ||
24 | <path sodipodi:cx='-176.01562' sodipodi:cy='-39.984375' d='m -174,-39.984375 a 2.015625,2.015625 0 1 1 -4.03125,0 2.015625,2.015625 0 1 1 4.03125,0 z' id='path3908-61' sodipodi:rx='2.015625' sodipodi:ry='2.015625' style='color:#000000;fill:#bebebe;fill-opacity:1;stroke:none;stroke-width:0.99999976;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:new' transform='translate(759.03145,343.03125)' sodipodi:type='arc'/> | |
25 | <path sodipodi:cx='-176.01562' sodipodi:cy='-39.984375' d='m -174,-39.984375 a 2.015625,2.015625 0 1 1 -4.03125,0 2.015625,2.015625 0 1 1 4.03125,0 z' id='path3910-1' sodipodi:rx='2.015625' sodipodi:ry='2.015625' style='color:#000000;fill:#bebebe;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.99999976;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:new' transform='translate(759.03145,354.96875)' sodipodi:type='arc'/> | |
26 | <path sodipodi:cx='-176.01562' sodipodi:cy='-39.984375' d='m -174,-39.984375 a 2.015625,2.015625 0 1 1 -4.03125,0 2.015625,2.015625 0 1 1 4.03125,0 z' id='path3912' sodipodi:rx='2.015625' sodipodi:ry='2.015625' style='color:#000000;fill:#bebebe;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.99999976;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:new' transform='translate(771.03145,354.96875)' sodipodi:type='arc'/> | |
27 | <path sodipodi:cx='-176.01562' sodipodi:cy='-39.984375' d='m -174,-39.984375 a 2.015625,2.015625 0 1 1 -4.03125,0 2.015625,2.015625 0 1 1 4.03125,0 z' id='path3914' sodipodi:rx='2.015625' sodipodi:ry='2.015625' style='color:#000000;fill:#bebebe;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.99999976;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:new' transform='translate(771.03145,343)' sodipodi:type='arc'/> | |
28 | <path inkscape:connector-curvature='0' d='m 582.0625,302.0625 0,1 0,11.96875 0,1 1,0 11.96875,0 1,0 0,-1 0,-11.96875 0,-1 -1,0 -11.96875,0 -1,0 z m 2,2 9.96875,0 0,9.96875 -9.96875,0 0,-9.96875 z' id='rect3916' style='font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:normal;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;baseline-shift:baseline;color:#000000;fill:#bebebe;fill-opacity:1;stroke:none;stroke-width:2;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:new;font-family:Sans;-inkscape-font-specification:Sans'/> | |
29 | <path inkscape:connector-curvature='0' d='m 585.96875,306.03125 0,0.5 0,5 0,0.5 0.5,0 5.0625,0 0.5,0 0,-0.5 0,-5 0,-0.5 -0.5,0 -5.0625,0 -0.5,0 z m 1,1 4.0625,0 0,4 -4.0625,0 0,-4 z' id='rect3918' style='font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:normal;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;baseline-shift:baseline;color:#000000;fill:#bebebe;fill-opacity:1;stroke:none;stroke-width:0.9999997;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:new;font-family:Sans;-inkscape-font-specification:Sans'/> | |
30 | <path sodipodi:cx='-167.76562' sodipodi:cy='-31.765625' d='m -166.5,-31.765625 a 1.265625,1.265625 0 1 1 -2.53125,0 1.265625,1.265625 0 1 1 2.53125,0 z' id='path3937' sodipodi:rx='1.265625' sodipodi:ry='1.265625' style='color:#000000;fill:#bebebe;fill-opacity:1;stroke:none;stroke-width:0.99999976;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:new' transform='matrix(1.1975309,0,0,1.1975309,792.42034,349.55594)' sodipodi:type='arc'/> | |
31 | <path sodipodi:cx='-167.76562' sodipodi:cy='-31.765625' d='m -166.5,-31.765625 a 1.265625,1.265625 0 1 1 -2.53125,0 1.265625,1.265625 0 1 1 2.53125,0 z' id='path3939' sodipodi:rx='1.265625' sodipodi:ry='1.265625' style='color:#000000;fill:#bebebe;fill-opacity:1;stroke:none;stroke-width:0.99999976;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:new' transform='matrix(1.1975309,0,0,1.1975309,787.42034,349.55594)' sodipodi:type='arc'/> | |
32 | <path sodipodi:cx='-167.76562' sodipodi:cy='-31.765625' d='m -166.5,-31.765625 a 1.265625,1.265625 0 1 1 -2.53125,0 1.265625,1.265625 0 1 1 2.53125,0 z' id='path3941' sodipodi:rx='1.265625' sodipodi:ry='1.265625' style='color:#000000;fill:#bebebe;fill-opacity:1;stroke:none;stroke-width:0.99999976;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:new' transform='matrix(1.1975309,0,0,1.1975309,787.42034,344.58719)' sodipodi:type='arc'/> | |
33 | <path sodipodi:cx='-167.76562' sodipodi:cy='-31.765625' d='m -166.5,-31.765625 a 1.265625,1.265625 0 1 1 -2.53125,0 1.265625,1.265625 0 1 1 2.53125,0 z' id='path3943' sodipodi:rx='1.265625' sodipodi:ry='1.265625' style='color:#000000;fill:#bebebe;fill-opacity:1;stroke:none;stroke-width:0.99999976;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:new' transform='matrix(1.1975309,0,0,1.1975309,792.48284,344.58719)' sodipodi:type='arc'/> | |
34 | <path inkscape:connector-curvature='0' d='m 591.875,311.21875 -0.6875,0.6875 3.40625,3.4375 0.71875,-0.71875 -3.4375,-3.40625 z' id='path3945' style='font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:normal;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;baseline-shift:baseline;color:#000000;fill:#bebebe;fill-opacity:1;stroke:none;stroke-width:0.99999976;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:new;font-family:Sans;-inkscape-font-specification:Sans'/> | |
35 | <path inkscape:connector-curvature='0' d='m 586.59375,311.21875 -3.40625,3.40625 0.6875,0.71875 3.4375,-3.4375 -0.71875,-0.6875 z' id='path3949' style='font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:normal;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;baseline-shift:baseline;color:#000000;fill:#bebebe;fill-opacity:1;stroke:none;stroke-width:0.99999976;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:new;font-family:Sans;-inkscape-font-specification:Sans'/> | |
36 | <path inkscape:connector-curvature='0' d='m 594.59375,303.21875 -3.40625,3.40625 0.6875,0.71875 3.4375,-3.4375 -0.71875,-0.6875 z' id='path3953' style='font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:normal;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;baseline-shift:baseline;color:#000000;fill:#bebebe;fill-opacity:1;stroke:none;stroke-width:0.99999976;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:new;font-family:Sans;-inkscape-font-specification:Sans'/> | |
37 | <path inkscape:connector-curvature='0' d='m 583.875,303.21875 -0.6875,0.6875 3.40625,3.4375 0.71875,-0.71875 -3.4375,-3.40625 z' id='path3955' style='font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:normal;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;baseline-shift:baseline;color:#000000;fill:#bebebe;fill-opacity:1;stroke:none;stroke-width:0.99999976;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:new;font-family:Sans;-inkscape-font-specification:Sans'/> | |
38 | </g> | |
39 | <g inkscape:groupmode='layer' id='layer15' inkscape:label='emblems' style='display:inline' transform='translate(-581.0002,-301)'/> | |
40 | <g inkscape:groupmode='layer' id='g71291' inkscape:label='emotes' style='display:inline' transform='translate(-581.0002,-301)'/> | |
41 | <g inkscape:groupmode='layer' id='g4953' inkscape:label='categories' style='display:inline' transform='translate(-581.0002,-301)'/> | |
42 | <g inkscape:groupmode='layer' id='layer12' inkscape:label='actions' style='display:inline' transform='translate(-581.0002,-301)'/> | |
43 | </svg> |
0 | 0 | installed = get_option('installed-tests') |
1 | executable('testcloudproviderserver', 'testcloudproviderserver.c', | |
1 | executable('testcloudprovidersserver', 'testcloudprovidersserver.c', | |
2 | 2 | dependencies: libcloudproviders_dep, |
3 | 3 | install: installed, |
4 | 4 | ) |
5 | executable('testcloudproviderclient', 'testcloudproviderclient.c', | |
5 | executable('testcloudprovidersclient', 'testcloudprovidersclient.c', | |
6 | 6 | dependencies: libcloudproviders_dep, |
7 | 7 | install: installed, |
8 | 8 | ) |
9 | 9 | |
10 | configure_file(input : 'icon.svg', | |
11 | output : 'icon.svg', | |
12 | configuration : configuration_data()) | |
10 | 13 | |
11 | 14 | if installed |
12 | 15 | service_conf = configuration_data () |
18 | 21 | install_dir: servicedir, |
19 | 22 | ) |
20 | 23 | cloudprovidersdata = join_paths (datadir, 'cloud-providers') |
21 | install_data('org.freedesktop.CloudProviderServerExample.ini', install_dir : cloudprovidersdata) | |
24 | install_data('org.freedesktop.CloudProviders.ServerExample.ini', install_dir: cloudprovidersdata) | |
22 | 25 | endif |
0 | [Cloud Provider] | |
1 | BusName=org.freedesktop.CloudProviderServerExample | |
2 | ObjectPath=/org/freedesktop/CloudProviderServerExample | |
3 | Version=1 |
0 | [D-BUS Service] | |
1 | Name=org.freedesktop.CloudProviderServerExample | |
2 | Exec=@bindir@/testcloudproviderclient |
0 | [Cloud Providers] | |
1 | BusName=org.freedesktop.CloudProviders.ServerExample | |
2 | ObjectPath=/org/freedesktop/CloudProviders/ServerExample | |
3 | Version=1 |
0 | [D-BUS Service] | |
1 | Name=org.freedesktop.CloudProviders.ServerExample | |
2 | Exec=@bindir@/testcloudprovidersclient |
0 | #include <glib.h> | |
1 | #include <cloudprovideraccount.h> | |
2 | #include <cloudprovidermanager.h> | |
3 | #include <cloudproviders.h> | |
4 | ||
5 | static void | |
6 | print_gmenu_model (GMenuModel *model) | |
7 | { | |
8 | gint i, n_items; | |
9 | GMenuModel *submodel = NULL; | |
10 | gchar *label; | |
11 | ||
12 | n_items = g_menu_model_get_n_items (model); | |
13 | ||
14 | for (i = 0; i < n_items; i++) | |
15 | { | |
16 | label = NULL; | |
17 | if (g_menu_model_get_item_attribute (model, i, G_MENU_ATTRIBUTE_LABEL, "s", &label)) | |
18 | { | |
19 | g_print ("Menu item - %s\n", label); | |
20 | if (label != NULL) | |
21 | g_free (label); | |
22 | } | |
23 | ||
24 | submodel = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION); | |
25 | if (!submodel) | |
26 | submodel = g_menu_model_get_item_link (model, i, G_MENU_LINK_SUBMENU); | |
27 | ||
28 | if (!submodel) | |
29 | continue; | |
30 | g_print ("---------\n"); | |
31 | print_gmenu_model (submodel); | |
32 | g_print ("---------\n"); | |
33 | g_clear_object (&submodel); | |
34 | } | |
35 | } | |
36 | ||
37 | static void | |
38 | on_manager_changed (CloudProviders *manager) | |
39 | { | |
40 | GList *providers; | |
41 | GList *l; | |
42 | gint provider_status; | |
43 | gchar *status_string; | |
44 | GIcon *icon; | |
45 | gchar *icon_representation; | |
46 | GMenuModel *menu; | |
47 | ||
48 | providers = cloud_providers_get_providers (manager); | |
49 | if(providers == NULL) | |
50 | return; | |
51 | for (l = providers; l != NULL; l = l->next) | |
52 | { | |
53 | if(!cloud_provider_account_is_available(CLOUD_PROVIDER_ACCOUNT(l->data))) { | |
54 | continue; | |
55 | } | |
56 | g_print ("Providers data\n"); | |
57 | g_print ("##############\n"); | |
58 | provider_status = cloud_provider_account_get_status (CLOUD_PROVIDER_ACCOUNT (l->data)); | |
59 | switch (provider_status) | |
60 | { | |
61 | case CLOUD_PROVIDER_STATUS_INVALID: | |
62 | status_string = "invalid"; | |
63 | break; | |
64 | ||
65 | case CLOUD_PROVIDER_STATUS_IDLE: | |
66 | status_string = "idle"; | |
67 | break; | |
68 | ||
69 | case CLOUD_PROVIDER_STATUS_SYNCING: | |
70 | status_string = "syncing"; | |
71 | break; | |
72 | ||
73 | case CLOUD_PROVIDER_STATUS_ERROR: | |
74 | status_string = "error"; | |
75 | break; | |
76 | ||
77 | default: | |
78 | g_assert_not_reached (); | |
79 | } | |
80 | ||
81 | icon = cloud_provider_account_get_icon (l->data); | |
82 | icon_representation = g_icon_to_string (icon); | |
83 | ||
84 | g_print ("Name - %s, Status - %s (%s), Path - %s, Icon - %s\n", | |
85 | cloud_provider_account_get_name (CLOUD_PROVIDER_ACCOUNT (l->data)), | |
86 | status_string, | |
87 | cloud_provider_account_get_status_details (CLOUD_PROVIDER_ACCOUNT (l->data)), | |
88 | cloud_provider_account_get_path (CLOUD_PROVIDER_ACCOUNT (l->data)), | |
89 | icon_representation); | |
90 | ||
91 | g_free (icon_representation); | |
92 | ||
93 | menu = cloud_provider_account_get_menu_model (l->data); | |
94 | g_print ("\nMenu\n"); | |
95 | print_gmenu_model (menu); | |
96 | } | |
97 | g_print ("\n"); | |
98 | } | |
99 | ||
100 | gint | |
101 | main (gint argc, | |
102 | gchar *argv[]) | |
103 | { | |
104 | CloudProviders *manager; | |
105 | GMainLoop *loop = g_main_loop_new(NULL, FALSE); | |
106 | ||
107 | manager = cloud_providers_dup_singleton (); | |
108 | g_signal_connect (manager, "changed", G_CALLBACK (on_manager_changed), manager); | |
109 | cloud_providers_update (manager); | |
110 | ||
111 | g_print("Waiting for cloud providers\n\n"); | |
112 | ||
113 | g_main_loop_run(loop); | |
114 | g_free(loop); | |
115 | ||
116 | return 0; | |
117 | } |
0 | #include <glib.h> | |
1 | #include <cloudprovidersaccount.h> | |
2 | #include <cloudproviderscollector.h> | |
3 | #include <cloudprovidersprovider.h> | |
4 | ||
5 | static void | |
6 | print_gmenu_model (GMenuModel *model) | |
7 | { | |
8 | gint i, n_items; | |
9 | GMenuModel *submodel = NULL; | |
10 | gchar *label; | |
11 | ||
12 | n_items = g_menu_model_get_n_items (model); | |
13 | ||
14 | for (i = 0; i < n_items; i++) | |
15 | { | |
16 | label = NULL; | |
17 | if (g_menu_model_get_item_attribute (model, i, G_MENU_ATTRIBUTE_LABEL, "s", &label)) | |
18 | { | |
19 | g_print ("Menu item - %s\n", label); | |
20 | if (label != NULL) | |
21 | g_free (label); | |
22 | } | |
23 | ||
24 | submodel = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION); | |
25 | if (!submodel) | |
26 | submodel = g_menu_model_get_item_link (model, i, G_MENU_LINK_SUBMENU); | |
27 | ||
28 | if (!submodel) | |
29 | continue; | |
30 | g_print ("---------\n"); | |
31 | print_gmenu_model (submodel); | |
32 | g_print ("---------\n"); | |
33 | g_clear_object (&submodel); | |
34 | } | |
35 | } | |
36 | ||
37 | static gchar* | |
38 | get_status_string (CloudProvidersAccountStatus status) | |
39 | { | |
40 | gchar *status_string; | |
41 | ||
42 | switch (status) | |
43 | { | |
44 | case CLOUD_PROVIDERS_ACCOUNT_STATUS_INVALID: | |
45 | status_string = "invalid"; | |
46 | break; | |
47 | ||
48 | case CLOUD_PROVIDERS_ACCOUNT_STATUS_IDLE: | |
49 | status_string = "idle"; | |
50 | break; | |
51 | ||
52 | case CLOUD_PROVIDERS_ACCOUNT_STATUS_SYNCING: | |
53 | status_string = "syncing"; | |
54 | break; | |
55 | ||
56 | case CLOUD_PROVIDERS_ACCOUNT_STATUS_ERROR: | |
57 | status_string = "error"; | |
58 | break; | |
59 | ||
60 | default: | |
61 | g_assert_not_reached (); | |
62 | } | |
63 | ||
64 | return g_strdup (status_string); | |
65 | } | |
66 | ||
67 | static void | |
68 | on_account_status_changed (CloudProvidersAccount *account) | |
69 | { | |
70 | g_autofree gchar* status_string = NULL; | |
71 | GIcon *icon; | |
72 | g_autofree gchar *icon_representation = NULL; | |
73 | GMenuModel *menu; | |
74 | ||
75 | icon = cloud_providers_account_get_icon (account); | |
76 | icon_representation = g_icon_to_string (icon); | |
77 | status_string = get_status_string (cloud_providers_account_get_status (account)); | |
78 | g_print ("Account: Name - %s, Status - %s (%s), Path - %s, Icon - %s\n", | |
79 | cloud_providers_account_get_name (account), | |
80 | status_string, | |
81 | cloud_providers_account_get_status_details (account), | |
82 | cloud_providers_account_get_path (account), | |
83 | icon_representation); | |
84 | menu = cloud_providers_account_get_menu_model (account); | |
85 | g_print ("\nMenu\n"); | |
86 | print_gmenu_model (menu); | |
87 | } | |
88 | ||
89 | static void | |
90 | on_provider_accounts_changed (CloudProvidersProvider *provider) | |
91 | { | |
92 | GList *l; | |
93 | gint status; | |
94 | gchar *status_string; | |
95 | GIcon *icon; | |
96 | gchar *icon_representation; | |
97 | GList *accounts; | |
98 | GMenuModel *menu; | |
99 | ||
100 | accounts = cloud_providers_provider_get_accounts (provider); | |
101 | for (l = accounts; l != NULL; l = l->next) | |
102 | { | |
103 | CloudProvidersAccount *account; | |
104 | ||
105 | account = CLOUD_PROVIDERS_ACCOUNT (l->data); | |
106 | g_signal_connect (account, | |
107 | "notify::status", | |
108 | G_CALLBACK (on_account_status_changed), | |
109 | NULL); | |
110 | status = cloud_providers_account_get_status (account); | |
111 | status_string = get_status_string (status); | |
112 | icon = cloud_providers_account_get_icon (account); | |
113 | icon_representation = icon != NULL ? g_icon_to_string (icon) : "no icon"; | |
114 | ||
115 | g_print ("Account: Name - %s, Status - %s (%s), Path - %s, Icon - %s\n", | |
116 | cloud_providers_account_get_name (account), | |
117 | status_string, | |
118 | cloud_providers_account_get_status_details (account), | |
119 | cloud_providers_account_get_path (account), | |
120 | icon_representation); | |
121 | ||
122 | g_free (icon_representation); | |
123 | ||
124 | menu = cloud_providers_account_get_menu_model (account); | |
125 | g_print ("\nMenu\n"); | |
126 | print_gmenu_model (menu); | |
127 | } | |
128 | } | |
129 | ||
130 | static void | |
131 | on_provider_name_changed (CloudProvidersProvider *provider) | |
132 | { | |
133 | g_print ("Provider changed: %s\n", cloud_providers_provider_get_name (provider)); | |
134 | } | |
135 | ||
136 | static void | |
137 | on_collector_changed (CloudProvidersCollector *collector) | |
138 | { | |
139 | GList *providers; | |
140 | GList *accounts; | |
141 | GList *l; | |
142 | GList *l2; | |
143 | gint status; | |
144 | gchar *status_string; | |
145 | GIcon *icon; | |
146 | gchar *icon_representation; | |
147 | GMenuModel *menu; | |
148 | ||
149 | providers = cloud_providers_collector_get_providers (collector); | |
150 | if (providers == NULL) | |
151 | { | |
152 | return; | |
153 | } | |
154 | ||
155 | for (l = providers; l != NULL; l = l->next) | |
156 | { | |
157 | CloudProvidersProvider *provider; | |
158 | ||
159 | provider = CLOUD_PROVIDERS_PROVIDER (l->data); | |
160 | g_print ("Provider data for %s\n", cloud_providers_provider_get_name (provider)); | |
161 | g_print ("--------------------------\n"); | |
162 | accounts = cloud_providers_provider_get_accounts (provider); | |
163 | for (l2 = accounts; l2 != NULL; l2 = l2->next) | |
164 | { | |
165 | CloudProvidersAccount *account; | |
166 | ||
167 | account = CLOUD_PROVIDERS_ACCOUNT (l2->data); | |
168 | g_signal_connect_swapped (account, | |
169 | "notify::status", | |
170 | G_CALLBACK (on_account_status_changed), | |
171 | NULL); | |
172 | status = cloud_providers_account_get_status (account); | |
173 | status_string = get_status_string (status); | |
174 | icon = cloud_providers_account_get_icon (account); | |
175 | icon_representation = g_icon_to_string (icon); | |
176 | ||
177 | g_print ("Account: Name - %s, Status - %s (%s), Path - %s, Icon - %s\n", | |
178 | cloud_providers_account_get_name (account), | |
179 | status_string, | |
180 | cloud_providers_account_get_status_details (account), | |
181 | cloud_providers_account_get_path (account), | |
182 | icon_representation); | |
183 | ||
184 | g_free (icon_representation); | |
185 | ||
186 | menu = cloud_providers_account_get_menu_model (account); | |
187 | g_print ("\nMenu\n"); | |
188 | print_gmenu_model (menu); | |
189 | } | |
190 | ||
191 | g_signal_connect_swapped (provider, "accounts-changed", | |
192 | G_CALLBACK (on_provider_accounts_changed), provider); | |
193 | g_signal_connect_swapped (provider, "notify::name", | |
194 | G_CALLBACK (on_provider_name_changed), provider); | |
195 | } | |
196 | g_print ("\n"); | |
197 | } | |
198 | ||
199 | gint | |
200 | main (gint argc, | |
201 | gchar *argv[]) | |
202 | { | |
203 | CloudProvidersCollector *collector; | |
204 | GMainLoop *loop = g_main_loop_new(NULL, FALSE); | |
205 | ||
206 | collector = cloud_providers_collector_dup_singleton (); | |
207 | g_signal_connect_swapped (collector, "providers-changed", | |
208 | G_CALLBACK (on_collector_changed), collector); | |
209 | on_collector_changed (collector); | |
210 | ||
211 | g_print("Waiting for cloud providers\n\n"); | |
212 | ||
213 | g_main_loop_run(loop); | |
214 | g_free(loop); | |
215 | ||
216 | return 0; | |
217 | } |
0 | #include <glib.h> | |
1 | #include <stdlib.h> | |
2 | #include <gio/gio.h> | |
3 | #include <cloudproviderexporter.h> | |
4 | #include <cloudprovideraccountexporter.h> | |
5 | /* for CLoudProviderStatus enum */ | |
6 | #include <cloudprovideraccount.h> | |
7 | ||
8 | ||
9 | #define TIMEOUT 800 | |
10 | #define COUNT_PLACEHOLDER_ACCOUNTS 3 | |
11 | #define TEST_CLOUD_PROVIDER_BUS_NAME "org.freedesktop.CloudProviderServerExample" | |
12 | #define TEST_CLOUD_PROVIDER_OBJECT_PATH "/org/freedesktop/CloudProviderServerExample" | |
13 | ||
14 | typedef struct _TestCloudProviderClass TestCloudProviderClass; | |
15 | typedef struct _TestCloudProvider TestCloudProvider; | |
16 | ||
17 | struct _TestCloudProviderClass | |
18 | { | |
19 | GObjectClass parent_class; | |
20 | }; | |
21 | ||
22 | struct _TestCloudProvider | |
23 | { | |
24 | GObject parent_instance; | |
25 | ||
26 | gchar *name; | |
27 | gint status; | |
28 | GIcon *icon; | |
29 | gchar *path; | |
30 | guint timeout_handler; | |
31 | GDBusConnection *connection; | |
32 | CloudProviderExporter *cloud_provider; | |
33 | GDBusObjectManagerServer *manager; | |
34 | }; | |
35 | ||
36 | ||
37 | static GType test_cloud_provider_get_type (void); | |
38 | G_DEFINE_TYPE (TestCloudProvider, test_cloud_provider, G_TYPE_OBJECT); | |
39 | ||
40 | static TestCloudProvider* | |
41 | test_cloud_provider_new (const gchar *name) | |
42 | { | |
43 | TestCloudProvider *self; | |
44 | ||
45 | self = g_object_new (test_cloud_provider_get_type(), NULL); | |
46 | self->name = g_strdup(name); | |
47 | ||
48 | return self; | |
49 | } | |
50 | ||
51 | static void | |
52 | test_cloud_provider_finalize (GObject *object) | |
53 | { | |
54 | TestCloudProvider *self = (TestCloudProvider*)object; | |
55 | ||
56 | g_free (self->name); | |
57 | g_free (self->path); | |
58 | g_clear_object (&self->icon); | |
59 | ||
60 | G_OBJECT_CLASS (test_cloud_provider_parent_class)->finalize (object); | |
61 | } | |
62 | ||
63 | static void | |
64 | test_cloud_provider_init (TestCloudProvider *self) | |
65 | { | |
66 | GFile *icon_file; | |
67 | gchar *current_dir; | |
68 | gchar *uri; | |
69 | ||
70 | current_dir = g_get_current_dir (); | |
71 | ||
72 | self->name = "MyCloud"; | |
73 | self->path = g_strdup (current_dir); | |
74 | self->status = CLOUD_PROVIDER_STATUS_INVALID; | |
75 | uri = g_build_filename (current_dir, "icon.png", NULL); | |
76 | icon_file = g_file_new_for_uri (uri); | |
77 | self->icon = g_file_icon_new (icon_file); | |
78 | ||
79 | g_object_unref (icon_file); | |
80 | g_free (uri); | |
81 | g_free (current_dir); | |
82 | } | |
83 | ||
84 | static void | |
85 | test_cloud_provider_class_init (TestCloudProviderClass *class) | |
86 | { | |
87 | GObjectClass *gobject_class = G_OBJECT_CLASS (class); | |
88 | ||
89 | gobject_class->finalize = test_cloud_provider_finalize; | |
90 | } | |
91 | ||
92 | static void | |
93 | test_cloud_provider_set_status (TestCloudProvider *self, | |
94 | gint status) | |
95 | { | |
96 | self->status = status; | |
97 | } | |
98 | ||
99 | /* ---------------------------------------------------------------------------------------------------- */ | |
100 | ||
101 | static void | |
102 | activate_action (GSimpleAction *action, | |
103 | GVariant *parameter, | |
104 | gpointer user_data) | |
105 | { | |
106 | g_print ("Action %s activated\n", g_action_get_name (G_ACTION (action))); | |
107 | } | |
108 | ||
109 | static void | |
110 | activate_toggle (GSimpleAction *action, | |
111 | GVariant *parameter, | |
112 | gpointer user_data) | |
113 | { | |
114 | GVariant *old_state, *new_state; | |
115 | ||
116 | old_state = g_action_get_state (G_ACTION (action)); | |
117 | new_state = g_variant_new_boolean (!g_variant_get_boolean (old_state)); | |
118 | ||
119 | g_print ("Toggle action %s activated, state changes from %d to %d\n", | |
120 | g_action_get_name (G_ACTION (action)), | |
121 | g_variant_get_boolean (old_state), | |
122 | g_variant_get_boolean (new_state)); | |
123 | ||
124 | g_simple_action_set_state (action, new_state); | |
125 | g_variant_unref (old_state); | |
126 | } | |
127 | ||
128 | static void | |
129 | activate_radio (GSimpleAction *action, | |
130 | GVariant *parameter, | |
131 | gpointer user_data) | |
132 | { | |
133 | GVariant *old_state, *new_state; | |
134 | ||
135 | old_state = g_action_get_state (G_ACTION (action)); | |
136 | new_state = g_variant_new_string (g_variant_get_string (parameter, NULL)); | |
137 | ||
138 | g_print ("Radio action %s activated, state changes from %s to %s\n", | |
139 | g_action_get_name (G_ACTION (action)), | |
140 | g_variant_get_string (old_state, NULL), | |
141 | g_variant_get_string (new_state, NULL)); | |
142 | ||
143 | g_simple_action_set_state (action, new_state); | |
144 | g_variant_unref (old_state); | |
145 | } | |
146 | ||
147 | static GActionEntry actions[] = { | |
148 | { "website", activate_action, NULL, NULL, NULL }, | |
149 | { "photos", activate_action, NULL, NULL, NULL }, | |
150 | { "notes", activate_action, NULL, NULL, NULL }, | |
151 | { "allow-sync", activate_toggle, NULL, "true", NULL }, | |
152 | { "buy", activate_radio, "s", NULL, NULL }, | |
153 | }; | |
154 | ||
155 | struct menu { | |
156 | GMenu *mainMenu; | |
157 | GMenuItem *website; | |
158 | GMenuItem *photos; | |
159 | GMenuItem *notes; | |
160 | GMenuItem *allowSync; | |
161 | GMenuItem *buy; | |
162 | }; | |
163 | ||
164 | static GMenuModel * | |
165 | get_model (void) | |
166 | { | |
167 | GMenu *section; | |
168 | struct menu *m; | |
169 | GMenuItem *item; | |
170 | GMenu *submenu; | |
171 | ||
172 | m = g_new0(struct menu, 1); | |
173 | m->mainMenu = g_menu_new(); | |
174 | ||
175 | section = g_menu_new(); | |
176 | m->website = g_menu_item_new("MyCloud website", "cloudprovider.website"); | |
177 | g_menu_append_item(section, m->website); | |
178 | m->photos = g_menu_item_new("MyCloud photos", "cloudprovider.photos"); | |
179 | g_menu_append_item(section, m->photos); | |
180 | m->notes = g_menu_item_new("MyCloud notes", "cloudprovider.notes"); | |
181 | g_menu_append_item(section, m->notes); | |
182 | g_menu_append_section(m->mainMenu, NULL, G_MENU_MODEL(section)); | |
183 | ||
184 | section = g_menu_new(); | |
185 | m->allowSync = g_menu_item_new("Allow Synchronization", "cloudprovider.allow-sync"); | |
186 | g_menu_append_item(section, m->allowSync); | |
187 | ||
188 | submenu = g_menu_new(); | |
189 | item = g_menu_item_new("5GB", "5"); | |
190 | g_menu_append_item(submenu, item); | |
191 | item = g_menu_item_new("10GB", "10"); | |
192 | g_menu_append_item(submenu, item); | |
193 | item = g_menu_item_new("50GB", "50"); | |
194 | g_menu_append_item(submenu, item); | |
195 | item = g_menu_item_new_submenu("Buy storage", G_MENU_MODEL(submenu)); | |
196 | g_menu_append_item(section, item); | |
197 | g_menu_append_section(m->mainMenu, NULL, G_MENU_MODEL(section)); | |
198 | ||
199 | return G_MENU_MODEL(m->mainMenu); | |
200 | } | |
201 | ||
202 | static GActionGroup * | |
203 | get_action_group (void) | |
204 | { | |
205 | GSimpleActionGroup *group; | |
206 | ||
207 | group = g_simple_action_group_new (); | |
208 | ||
209 | g_action_map_add_action_entries (G_ACTION_MAP (group), | |
210 | actions, | |
211 | G_N_ELEMENTS (actions), NULL); | |
212 | ||
213 | return G_ACTION_GROUP (group); | |
214 | } | |
215 | ||
216 | static gboolean | |
217 | change_random_cloud_provider_state (gpointer user_data) | |
218 | { | |
219 | TestCloudProvider *test_cloud_provider = (TestCloudProvider *)user_data; | |
220 | GRand *rand; | |
221 | gint new_status; | |
222 | gint account_id; | |
223 | gchar *account_object_name; | |
224 | ||
225 | rand = g_rand_new (); | |
226 | account_id = g_rand_int_range (rand, 0, COUNT_PLACEHOLDER_ACCOUNTS); | |
227 | new_status = g_rand_int_range (rand, | |
228 | CLOUD_PROVIDER_STATUS_IDLE, | |
229 | CLOUD_PROVIDER_STATUS_ERROR + 1); | |
230 | ||
231 | account_object_name = g_strdup_printf ("MyCloud%d", account_id); | |
232 | g_print ("Change status of %03d to %d\n", account_id, new_status); | |
233 | test_cloud_provider_set_status (test_cloud_provider, new_status); | |
234 | cloud_provider_exporter_emit_changed (test_cloud_provider->cloud_provider, account_object_name); | |
235 | return TRUE; | |
236 | } | |
237 | ||
238 | ||
239 | static gchar * | |
240 | on_get_name (CloudProviderAccountExporter *account, | |
241 | gpointer user_data) | |
242 | { | |
243 | gchar *name = (gchar*)user_data; | |
244 | return name; | |
245 | } | |
246 | ||
247 | static GIcon * | |
248 | on_get_icon (CloudProviderAccountExporter *account, | |
249 | gpointer user_data) | |
250 | { | |
251 | TestCloudProvider *self = user_data; | |
252 | return self->icon; | |
253 | } | |
254 | ||
255 | static gchar * | |
256 | on_get_path (CloudProviderAccountExporter *account, | |
257 | gpointer user_data) | |
258 | { | |
259 | TestCloudProvider *self = user_data; | |
260 | return self->path; | |
261 | } | |
262 | ||
263 | static guint | |
264 | on_get_status (CloudProviderAccountExporter *account, | |
265 | gpointer user_data) | |
266 | { | |
267 | TestCloudProvider *self = user_data; | |
268 | return self->status; | |
269 | } | |
270 | ||
271 | static gchar * | |
272 | on_get_status_details (CloudProviderAccountExporter *account, | |
273 | gpointer user_data) | |
274 | { | |
275 | gchar *description = ""; | |
276 | TestCloudProvider *self = user_data; | |
277 | switch (self->status) { | |
278 | case CLOUD_PROVIDER_STATUS_IDLE: | |
279 | description = "Sync idle"; | |
280 | break; | |
281 | case CLOUD_PROVIDER_STATUS_SYNCING: | |
282 | description = "Syncing"; | |
283 | break; | |
284 | case CLOUD_PROVIDER_STATUS_ERROR: | |
285 | description = "Error"; | |
286 | break; | |
287 | } | |
288 | return description; | |
289 | } | |
290 | ||
291 | static void | |
292 | on_bus_acquired (GDBusConnection *connection, | |
293 | const gchar *name, | |
294 | gpointer user_data) | |
295 | { | |
296 | TestCloudProvider *self = user_data; | |
297 | guint n; | |
298 | ||
299 | self->connection = connection; | |
300 | self->cloud_provider = cloud_provider_exporter_new(self->connection, | |
301 | TEST_CLOUD_PROVIDER_BUS_NAME, | |
302 | TEST_CLOUD_PROVIDER_OBJECT_PATH); | |
303 | ||
304 | g_debug ("Registering cloud provider server 'MyCloud'\n"); | |
305 | ||
306 | // export multiple accounts as DBus objects to the bus | |
307 | for (n = 0; n < COUNT_PLACEHOLDER_ACCOUNTS; n++) | |
308 | { | |
309 | gchar *account_object_name = g_strdup_printf ("MyCloud%d", n); | |
310 | gchar *account_name = g_strdup_printf ("MyCloud %d", n); | |
311 | ||
312 | CloudProviderAccountExporter *account = cloud_provider_account_exporter_new(account_object_name); | |
313 | g_signal_connect (account, "handle_get_name", G_CALLBACK (on_get_name), account_name); | |
314 | g_signal_connect (account, "handle_get_icon", G_CALLBACK (on_get_icon), self); | |
315 | g_signal_connect (account, "handle_get_path", G_CALLBACK (on_get_path), self); | |
316 | g_signal_connect (account, "handle_get_status", G_CALLBACK (on_get_status), self); | |
317 | g_signal_connect (account, "handle_get_status_details", G_CALLBACK (on_get_status_details), self); | |
318 | cloud_provider_account_exporter_add_menu_model (account, get_model ()); | |
319 | cloud_provider_account_exporter_add_action_group (account, get_action_group ()); | |
320 | ||
321 | cloud_provider_exporter_add_account(self->cloud_provider, account); | |
322 | ||
323 | g_free(account_object_name); | |
324 | } | |
325 | ||
326 | cloud_provider_exporter_export_objects (self->cloud_provider); | |
327 | ||
328 | return; | |
329 | } | |
330 | ||
331 | static void | |
332 | on_name_acquired (GDBusConnection *connection, | |
333 | const gchar *name, | |
334 | gpointer user_data) | |
335 | { | |
336 | TestCloudProvider *self = (TestCloudProvider *)user_data; | |
337 | self->timeout_handler = g_timeout_add (TIMEOUT, | |
338 | (GSourceFunc) change_random_cloud_provider_state, | |
339 | self); | |
340 | change_random_cloud_provider_state (self); | |
341 | } | |
342 | ||
343 | static void | |
344 | on_name_lost (GDBusConnection *connection, | |
345 | const gchar *name, | |
346 | gpointer user_data) | |
347 | { | |
348 | exit (1); | |
349 | } | |
350 | ||
351 | int | |
352 | main (int argc, char *argv[]) | |
353 | { | |
354 | GMainLoop *loop; | |
355 | TestCloudProvider *test_cloud_provider; | |
356 | guint owner_id; | |
357 | ||
358 | test_cloud_provider = g_object_new (test_cloud_provider_get_type (), NULL); | |
359 | ||
360 | owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, | |
361 | TEST_CLOUD_PROVIDER_BUS_NAME, | |
362 | G_BUS_NAME_OWNER_FLAGS_NONE, | |
363 | on_bus_acquired, | |
364 | on_name_acquired, | |
365 | on_name_lost, | |
366 | test_cloud_provider, | |
367 | NULL); | |
368 | ||
369 | loop = g_main_loop_new (NULL, FALSE); | |
370 | g_main_loop_run (loop); | |
371 | ||
372 | g_bus_unown_name (owner_id); | |
373 | g_object_unref (test_cloud_provider); | |
374 | ||
375 | return 0; | |
376 | } | |
377 |
0 | #include <glib.h> | |
1 | #include <stdlib.h> | |
2 | #include <gio/gio.h> | |
3 | #include <cloudprovidersproviderexporter.h> | |
4 | #include <cloudprovidersaccountexporter.h> | |
5 | /* for CLoudProviderStatus enum */ | |
6 | #include <cloudprovidersaccount.h> | |
7 | ||
8 | ||
9 | #define TIMEOUT 800 | |
10 | #define COUNT_PLACEHOLDER_ACCOUNTS 3 | |
11 | #define TEST_CLOUD_PROVIDERS_BUS_NAME "org.freedesktop.CloudProviders.ServerExample" | |
12 | #define TEST_CLOUD_PROVIDERS_OBJECT_PATH "/org/freedesktop/CloudProviders/ServerExample" | |
13 | ||
14 | #define CLOUD_PROVIDERS_TYPE_TEST_SERVER (cloud_providers_test_server_get_type()) | |
15 | G_DECLARE_FINAL_TYPE (CloudProvidersTestServer, cloud_providers_test_server, CLOUD_PROVIDERS, TEST_SERVER, GObject); | |
16 | ||
17 | struct _CloudProvidersTestServerClass | |
18 | { | |
19 | GObjectClass parent_class; | |
20 | }; | |
21 | ||
22 | struct _CloudProvidersTestServer | |
23 | { | |
24 | GObject parent_instance; | |
25 | ||
26 | GHashTable *accounts; | |
27 | gchar *name; | |
28 | GIcon *icon; | |
29 | gchar *path; | |
30 | guint timeout_handler; | |
31 | GDBusConnection *connection; | |
32 | CloudProvidersProviderExporter *exporter; | |
33 | }; | |
34 | ||
35 | G_DEFINE_TYPE (CloudProvidersTestServer, cloud_providers_test_server, G_TYPE_OBJECT); | |
36 | ||
37 | static CloudProvidersTestServer* | |
38 | cloud_providers_test_server_new (void) | |
39 | { | |
40 | CloudProvidersTestServer *self; | |
41 | ||
42 | self = g_object_new (CLOUD_PROVIDERS_TYPE_TEST_SERVER, NULL); | |
43 | ||
44 | return self; | |
45 | } | |
46 | ||
47 | static void | |
48 | test_cloud_provider_finalize (GObject *object) | |
49 | { | |
50 | CloudProvidersTestServer *self = CLOUD_PROVIDERS_TEST_SERVER (object); | |
51 | ||
52 | g_hash_table_unref (self->accounts); | |
53 | g_free (self->name); | |
54 | g_free (self->path); | |
55 | g_clear_object (&self->icon); | |
56 | ||
57 | G_OBJECT_CLASS (cloud_providers_test_server_parent_class)->finalize (object); | |
58 | } | |
59 | ||
60 | static void | |
61 | cloud_providers_test_server_init (CloudProvidersTestServer *self) | |
62 | { | |
63 | GFile *icon_file; | |
64 | gchar *current_dir; | |
65 | gchar *uri; | |
66 | ||
67 | current_dir = g_get_current_dir (); | |
68 | ||
69 | self->accounts = g_hash_table_new_full (NULL, NULL, NULL, g_object_unref); | |
70 | self->name = "MyCloud"; | |
71 | self->path = g_strdup (current_dir); | |
72 | uri = g_build_filename (current_dir, "icon.svg", NULL); | |
73 | icon_file = g_file_new_for_uri (uri); | |
74 | self->icon = g_file_icon_new (icon_file); | |
75 | ||
76 | g_object_unref (icon_file); | |
77 | g_free (uri); | |
78 | g_free (current_dir); | |
79 | } | |
80 | ||
81 | static void | |
82 | cloud_providers_test_server_class_init (CloudProvidersTestServerClass *class) | |
83 | { | |
84 | GObjectClass *gobject_class = G_OBJECT_CLASS (class); | |
85 | ||
86 | gobject_class->finalize = test_cloud_provider_finalize; | |
87 | } | |
88 | ||
89 | /* ---------------------------------------------------------------------------------------------------- */ | |
90 | ||
91 | static void | |
92 | activate_action (GSimpleAction *action, | |
93 | GVariant *parameter, | |
94 | gpointer user_data) | |
95 | { | |
96 | g_print ("Action %s activated\n", g_action_get_name (G_ACTION (action))); | |
97 | } | |
98 | ||
99 | static void | |
100 | activate_toggle (GSimpleAction *action, | |
101 | GVariant *parameter, | |
102 | gpointer user_data) | |
103 | { | |
104 | GVariant *old_state, *new_state; | |
105 | ||
106 | old_state = g_action_get_state (G_ACTION (action)); | |
107 | new_state = g_variant_new_boolean (!g_variant_get_boolean (old_state)); | |
108 | ||
109 | g_print ("Toggle action %s activated, state changes from %d to %d\n", | |
110 | g_action_get_name (G_ACTION (action)), | |
111 | g_variant_get_boolean (old_state), | |
112 | g_variant_get_boolean (new_state)); | |
113 | ||
114 | g_simple_action_set_state (action, new_state); | |
115 | g_variant_unref (old_state); | |
116 | } | |
117 | ||
118 | static void | |
119 | activate_radio (GSimpleAction *action, | |
120 | GVariant *parameter, | |
121 | gpointer user_data) | |
122 | { | |
123 | GVariant *old_state, *new_state; | |
124 | ||
125 | old_state = g_action_get_state (G_ACTION (action)); | |
126 | new_state = g_variant_new_string (g_variant_get_string (parameter, NULL)); | |
127 | ||
128 | g_print ("Radio action %s activated, state changes from %s to %s\n", | |
129 | g_action_get_name (G_ACTION (action)), | |
130 | g_variant_get_string (old_state, NULL), | |
131 | g_variant_get_string (new_state, NULL)); | |
132 | ||
133 | g_simple_action_set_state (action, new_state); | |
134 | g_variant_unref (old_state); | |
135 | } | |
136 | ||
137 | static GActionEntry actions[] = { | |
138 | { "website", activate_action, NULL, NULL, NULL }, | |
139 | { "photos", activate_action, NULL, NULL, NULL }, | |
140 | { "notes", activate_action, NULL, NULL, NULL }, | |
141 | { "allow-sync", activate_toggle, NULL, "true", NULL }, | |
142 | { "buy", activate_radio, "s", NULL, NULL }, | |
143 | }; | |
144 | ||
145 | struct menu { | |
146 | GMenu *mainMenu; | |
147 | GMenuItem *website; | |
148 | GMenuItem *photos; | |
149 | GMenuItem *notes; | |
150 | GMenuItem *allowSync; | |
151 | GMenuItem *buy; | |
152 | }; | |
153 | ||
154 | static GMenuModel * | |
155 | get_model (void) | |
156 | { | |
157 | GMenu *section; | |
158 | struct menu *m; | |
159 | GMenuItem *item; | |
160 | GMenu *submenu; | |
161 | ||
162 | m = g_new0(struct menu, 1); | |
163 | m->mainMenu = g_menu_new(); | |
164 | ||
165 | section = g_menu_new(); | |
166 | m->website = g_menu_item_new("MyCloud website", "cloudprovider.website"); | |
167 | g_menu_append_item(section, m->website); | |
168 | m->photos = g_menu_item_new("MyCloud photos", "cloudprovider.photos"); | |
169 | g_menu_append_item(section, m->photos); | |
170 | m->notes = g_menu_item_new("MyCloud notes", "cloudprovider.notes"); | |
171 | g_menu_append_item(section, m->notes); | |
172 | g_menu_append_section(m->mainMenu, NULL, G_MENU_MODEL(section)); | |
173 | ||
174 | section = g_menu_new(); | |
175 | m->allowSync = g_menu_item_new("Allow Synchronization", "cloudprovider.allow-sync"); | |
176 | g_menu_append_item(section, m->allowSync); | |
177 | ||
178 | submenu = g_menu_new(); | |
179 | item = g_menu_item_new("5GB", "5"); | |
180 | g_menu_append_item(submenu, item); | |
181 | item = g_menu_item_new("10GB", "10"); | |
182 | g_menu_append_item(submenu, item); | |
183 | item = g_menu_item_new("50GB", "50"); | |
184 | g_menu_append_item(submenu, item); | |
185 | item = g_menu_item_new_submenu("Buy storage", G_MENU_MODEL(submenu)); | |
186 | g_menu_append_item(section, item); | |
187 | g_menu_append_section(m->mainMenu, NULL, G_MENU_MODEL(section)); | |
188 | ||
189 | return G_MENU_MODEL(m->mainMenu); | |
190 | } | |
191 | ||
192 | static GActionGroup * | |
193 | get_action_group (void) | |
194 | { | |
195 | GSimpleActionGroup *group; | |
196 | ||
197 | group = g_simple_action_group_new (); | |
198 | ||
199 | g_action_map_add_action_entries (G_ACTION_MAP (group), | |
200 | actions, | |
201 | G_N_ELEMENTS (actions), NULL); | |
202 | ||
203 | return G_ACTION_GROUP (group); | |
204 | } | |
205 | ||
206 | static gboolean | |
207 | change_random_cloud_provider_state (gpointer user_data) | |
208 | { | |
209 | CloudProvidersTestServer *self = (CloudProvidersTestServer *)user_data; | |
210 | CloudProvidersAccountExporter *account; | |
211 | GRand *rand; | |
212 | gint new_status; | |
213 | gint account_id; | |
214 | ||
215 | rand = g_rand_new (); | |
216 | account_id = g_rand_int_range (rand, 0, COUNT_PLACEHOLDER_ACCOUNTS); | |
217 | new_status = g_rand_int_range (rand, | |
218 | CLOUD_PROVIDERS_ACCOUNT_STATUS_IDLE, | |
219 | CLOUD_PROVIDERS_ACCOUNT_STATUS_ERROR + 1); | |
220 | ||
221 | g_print ("Change status of %03d to %d\n", account_id, new_status); | |
222 | account = g_hash_table_lookup (self->accounts, GINT_TO_POINTER (account_id)); | |
223 | cloud_providers_account_exporter_set_status (account, new_status); | |
224 | ||
225 | return TRUE; | |
226 | } | |
227 | ||
228 | static gchar * | |
229 | get_status_details (CloudProvidersAccountStatus status) | |
230 | { | |
231 | gchar *description = ""; | |
232 | switch (status) { | |
233 | case CLOUD_PROVIDERS_ACCOUNT_STATUS_IDLE: | |
234 | description = "Details: Sync idle"; | |
235 | break; | |
236 | case CLOUD_PROVIDERS_ACCOUNT_STATUS_SYNCING: | |
237 | description = "Details: Syncing"; | |
238 | break; | |
239 | case CLOUD_PROVIDERS_ACCOUNT_STATUS_ERROR: | |
240 | description = "Details: Error"; | |
241 | break; | |
242 | case CLOUD_PROVIDERS_ACCOUNT_STATUS_INVALID: | |
243 | description = "Details: Sync status details not set"; | |
244 | break; | |
245 | } | |
246 | return description; | |
247 | } | |
248 | ||
249 | static gboolean | |
250 | add_accounts (CloudProvidersTestServer *self) | |
251 | { | |
252 | guint n; | |
253 | ||
254 | // export multiple accounts as DBus objects to the bus | |
255 | for (n = 0; n < COUNT_PLACEHOLDER_ACCOUNTS; n++) | |
256 | { | |
257 | g_autoptr (CloudProvidersAccountExporter) account = NULL; | |
258 | g_autofree gchar *account_object_name = NULL; | |
259 | g_autofree gchar *account_name = NULL; | |
260 | ||
261 | account_object_name = g_strdup_printf ("MyAccount%d", n); | |
262 | account_name = g_strdup_printf ("MyAccount %d", n); | |
263 | g_debug ("Adding account %s", account_name); | |
264 | account = cloud_providers_account_exporter_new (self->exporter, | |
265 | account_object_name); | |
266 | ||
267 | cloud_providers_provider_exporter_add_account (self->exporter, account); | |
268 | ||
269 | cloud_providers_account_exporter_set_name (account, account_name); | |
270 | cloud_providers_account_exporter_set_icon (account, self->icon); | |
271 | cloud_providers_account_exporter_set_path (account, self->path); | |
272 | cloud_providers_account_exporter_set_status (account, | |
273 | CLOUD_PROVIDERS_ACCOUNT_STATUS_INVALID); | |
274 | cloud_providers_account_exporter_set_status_details (account, | |
275 | get_status_details (CLOUD_PROVIDERS_ACCOUNT_STATUS_INVALID)); | |
276 | cloud_providers_account_exporter_set_menu_model (account, get_model ()); | |
277 | cloud_providers_account_exporter_set_action_group (account, get_action_group ()); | |
278 | g_hash_table_insert (self->accounts, GINT_TO_POINTER (n), account); | |
279 | } | |
280 | ||
281 | return G_SOURCE_REMOVE; | |
282 | } | |
283 | ||
284 | static void | |
285 | on_bus_acquired (GDBusConnection *connection, | |
286 | const gchar *name, | |
287 | gpointer user_data) | |
288 | { | |
289 | CloudProvidersTestServer *self = CLOUD_PROVIDERS_TEST_SERVER (user_data); | |
290 | ||
291 | g_debug ("Bus adquired: %s\n", name); | |
292 | ||
293 | g_debug ("Registering cloud provider server 'MyCloud'\n"); | |
294 | ||
295 | self->connection = connection; | |
296 | self->exporter = cloud_providers_provider_exporter_new(self->connection, | |
297 | TEST_CLOUD_PROVIDERS_BUS_NAME, | |
298 | TEST_CLOUD_PROVIDERS_OBJECT_PATH); | |
299 | cloud_providers_provider_exporter_set_name (self->exporter, "My cloud"); | |
300 | add_accounts (self); | |
301 | ||
302 | } | |
303 | ||
304 | static void | |
305 | on_name_acquired (GDBusConnection *connection, | |
306 | const gchar *name, | |
307 | gpointer user_data) | |
308 | { | |
309 | CloudProvidersTestServer *self = (CloudProvidersTestServer *)user_data; | |
310 | self->timeout_handler = g_timeout_add (TIMEOUT, | |
311 | (GSourceFunc) change_random_cloud_provider_state, | |
312 | self); | |
313 | g_debug ("Server test name adquired"); | |
314 | change_random_cloud_provider_state (self); | |
315 | } | |
316 | ||
317 | static void | |
318 | on_name_lost (GDBusConnection *connection, | |
319 | const gchar *name, | |
320 | gpointer user_data) | |
321 | { | |
322 | g_critical ("Name lost: %s\n", name); | |
323 | } | |
324 | ||
325 | int | |
326 | main (int argc, char *argv[]) | |
327 | { | |
328 | GMainLoop *loop; | |
329 | CloudProvidersTestServer *test_cloud_provider; | |
330 | guint owner_id; | |
331 | ||
332 | test_cloud_provider = cloud_providers_test_server_new (); | |
333 | ||
334 | owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, | |
335 | TEST_CLOUD_PROVIDERS_BUS_NAME, | |
336 | G_BUS_NAME_OWNER_FLAGS_NONE, | |
337 | on_bus_acquired, | |
338 | on_name_acquired, | |
339 | on_name_lost, | |
340 | test_cloud_provider, | |
341 | NULL); | |
342 | ||
343 | loop = g_main_loop_new (NULL, FALSE); | |
344 | g_main_loop_run (loop); | |
345 | ||
346 | g_debug("going oooooout/n"); | |
347 | g_bus_unown_name (owner_id); | |
348 | g_object_unref (test_cloud_provider); | |
349 | ||
350 | return 0; | |
351 | } | |
352 |