WIP: publish changes only when objects first dbus get is finished
Julius Härtl
6 years ago
34 | 34 | gchar *bus_name; |
35 | 35 | gchar *object_path; |
36 | 36 | GCancellable *cancellable; |
37 | gboolean ready; | |
37 | 38 | } CloudProviderPrivate; |
38 | 39 | |
39 | 40 | G_DEFINE_TYPE_WITH_PRIVATE (CloudProvider, cloud_provider, G_TYPE_OBJECT) |
41 | 42 | enum { |
42 | 43 | CHANGED, |
43 | 44 | CHANGED_NOTIFY, |
45 | READY, | |
44 | 46 | LAST_SIGNAL |
45 | 47 | }; |
46 | 48 | |
76 | 78 | out: |
77 | 79 | g_variant_unref (variant_tuple); |
78 | 80 | g_signal_emit_by_name (self, "changed"); |
81 | if(cloud_provider_is_available(self) && !priv->ready) { | |
82 | priv->ready = TRUE; | |
83 | g_signal_emit_by_name (self, "ready"); | |
84 | } | |
79 | 85 | } |
80 | 86 | |
81 | 87 | static void |
97 | 103 | return; |
98 | 104 | } |
99 | 105 | g_signal_emit_by_name (self, "changed"); |
106 | if(cloud_provider_is_available(self) && !priv->ready) { | |
107 | priv->ready = TRUE; | |
108 | g_signal_emit_by_name (self, "ready"); | |
109 | } | |
100 | 110 | } |
101 | 111 | |
102 | 112 | |
119 | 129 | return; |
120 | 130 | } |
121 | 131 | g_signal_emit_by_name (self, "changed"); |
132 | if(cloud_provider_is_available(self) && !priv->ready) { | |
133 | priv->ready = TRUE; | |
134 | g_signal_emit_by_name (self, "ready"); | |
135 | } | |
122 | 136 | } |
123 | 137 | |
124 | 138 | static void |
139 | 153 | } |
140 | 154 | priv->status = status; |
141 | 155 | g_signal_emit_by_name (self, "changed"); |
156 | if(cloud_provider_is_available(self) && !priv->ready) { | |
157 | priv->ready = TRUE; | |
158 | g_signal_emit_by_name (self, "ready"); | |
159 | } | |
142 | 160 | } |
143 | 161 | |
144 | 162 | void |
207 | 225 | |
208 | 226 | g_signal_connect_swapped(priv->proxy, "cloud-provider-changed", G_CALLBACK(cloud_provider_update), self); |
209 | 227 | g_signal_connect_swapped(priv->proxy, "notify", G_CALLBACK(cloud_provider_notify), self); |
228 | ||
229 | cloud_provider_update(self); | |
210 | 230 | } |
211 | 231 | |
212 | 232 | static void |
255 | 275 | priv->object_path = g_strdup (object_path); |
256 | 276 | priv->cancellable = g_cancellable_new (); |
257 | 277 | priv->status = CLOUD_PROVIDER_STATUS_INVALID; |
278 | priv->ready = FALSE; | |
258 | 279 | g_bus_get (G_BUS_TYPE_SESSION, |
259 | 280 | priv->cancellable, |
260 | 281 | on_bus_acquired, |
310 | 331 | g_cclosure_marshal_generic, |
311 | 332 | G_TYPE_NONE, |
312 | 333 | 0); |
334 | gSignals [READY] = | |
335 | g_signal_new ("ready", | |
336 | G_TYPE_FROM_CLASS (klass), | |
337 | G_SIGNAL_RUN_LAST, | |
338 | 0, | |
339 | NULL, | |
340 | NULL, | |
341 | g_cclosure_marshal_generic, | |
342 | G_TYPE_NONE, | |
343 | 0); | |
313 | 344 | } |
314 | 345 | |
315 | 346 | static void |
380 | 411 | { |
381 | 412 | GIcon *icon; |
382 | 413 | gchar *name; |
414 | gchar *path; | |
383 | 415 | guint status; |
384 | 416 | |
385 | 417 | name = cloud_provider_get_name (self); |
386 | 418 | icon = cloud_provider_get_icon (self); |
387 | 419 | status = cloud_provider_get_status (self); |
388 | if (name == NULL || icon == NULL || status == CLOUD_PROVIDER_STATUS_INVALID) | |
420 | path = cloud_provider_get_path (self); | |
421 | if (name == NULL || icon == NULL || path == NULL || status == CLOUD_PROVIDER_STATUS_INVALID) | |
389 | 422 | return FALSE; |
390 | 423 | return TRUE; |
391 | 424 | } |
62 | 62 | // update manager to remove cloud providers after owner disappeared |
63 | 63 | if(cloud_provider_get_owner(cloud_provider) == NULL) { |
64 | 64 | cloud_provider_manager_update(self); |
65 | g_signal_emit_by_name (self, "changed", NULL); | |
66 | 65 | g_signal_emit_by_name (self, "owners-changed", NULL); |
67 | 66 | } |
68 | 67 | } |
68 | ||
69 | static void | |
70 | on_cloud_provider_ready (CloudProvider *cloud_provider, CloudProviderManager *self) | |
71 | { | |
72 | g_signal_emit_by_name (self, "owners-changed", NULL); | |
73 | g_print("on_cloud_provider_ready\n"); | |
74 | // update manager to remove cloud providers after owner disappeared | |
75 | /*if(cloud_provider_get_owner(cloud_provider) == NULL) { | |
76 | g_signal_emit_by_name (self, "owners-changed", NULL); | |
77 | }*/ | |
78 | } | |
79 | ||
69 | 80 | |
70 | 81 | static void |
71 | 82 | on_cloud_provider_object_manager_notify ( |
79 | 90 | |
80 | 91 | name_owner = g_dbus_object_manager_client_get_name_owner (manager); |
81 | 92 | g_print ("name-owner: %s\n", name_owner); |
93 | ||
82 | 94 | cloud_provider_manager_update(self); |
83 | 95 | g_free (name_owner); |
84 | g_signal_emit_by_name (self, "changed", NULL); | |
96 | g_signal_emit_by_name (self, "owners-changed", NULL); | |
85 | 97 | } |
86 | 98 | |
87 | 99 | |
271 | 283 | { |
272 | 284 | Object *object = OBJECT(l->data); |
273 | 285 | g_print (" - Object at %s\n", g_dbus_object_get_object_path (G_DBUS_OBJECT (object))); |
286 | g_print("New cloud provider instance\n"); | |
274 | 287 | cloud_provider = cloud_provider_new (bus_name, g_dbus_object_get_object_path (G_DBUS_OBJECT (object))); |
275 | g_signal_connect (cloud_provider, "changed", | |
276 | G_CALLBACK (on_cloud_provider_changed), self); | |
277 | g_signal_connect (cloud_provider, "changed-notify", | |
278 | G_CALLBACK (on_cloud_provider_changed_notify), self); | |
288 | g_signal_connect (cloud_provider, "ready", | |
289 | G_CALLBACK (on_cloud_provider_ready), self); | |
290 | cloud_provider_update(cloud_provider); | |
279 | 291 | priv->providers = g_list_append (priv->providers, cloud_provider); |
280 | 292 | } |
281 | 293 | success = TRUE; |
336 | 336 | |
337 | 337 | export_menu (connection, account_object_name); |
338 | 338 | // FIXME: send initial changed signal to notify already running e.g. nautilus |
339 | g_dbus_connection_emit_signal (connection, | |
339 | /*g_dbus_connection_emit_signal (connection, | |
340 | 340 | NULL, |
341 | 341 | account_object_name, |
342 | 342 | "org.freedesktop.CloudProvider1", |
343 | 343 | "CloudProviderChanged", |
344 | 344 | NULL, |
345 | NULL /*error*/); | |
346 | ||
345 | // NULL); | |
346 | */ | |
347 | 347 | g_free(account_object_name); |
348 | 348 | } |
349 | 349 | g_dbus_object_manager_server_set_connection (self->manager, connection); |