~rodrigo-moya/ubuntuone-client/no-enabling-on-special-udfs

« back to all changes in this revision

Viewing changes to libsyncdaemon/syncdaemon-status-interface.c

  • Committer: Tarmac
  • Author(s): Rodrigo Moya
  • Date: 2010-07-06 22:54:29 UTC
  • mfrom: (554.4.5 direct-dbus-is-no-more)
  • Revision ID: rodrigo@megeve-20100706225429-i9teuxkq5lyga87m
Do all Syncdaemon access via DBus from libsyncdaemon, no more direct DBus calls in the Nautilus plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
        GObject *proxy;
30
30
        GHashTable *downloads;
31
31
        GHashTable *uploads;
 
32
        SyncdaemonStatusInfo *current_status;
32
33
};
33
34
 
34
35
static void
43
44
                if (interface->priv->uploads != NULL)
44
45
                        g_hash_table_destroy (interface->priv->uploads);
45
46
 
 
47
                if (interface->priv->current_status != NULL)
 
48
                        g_object_unref (G_OBJECT (interface->priv->current_status));
 
49
 
46
50
                g_free (interface->priv);
47
51
        }
48
52
 
58
62
}
59
63
 
60
64
static void
 
65
status_changed_cb (DBusGProxy *proxy, GHashTable *hash, gpointer user_data)
 
66
{
 
67
        SyncdaemonDaemon *daemon;
 
68
        SyncdaemonStatusInterface *interface = SYNCDAEMON_STATUS_INTERFACE (user_data);
 
69
 
 
70
        g_object_get (G_OBJECT (interface), "daemon", &daemon, NULL);
 
71
        if (daemon != NULL) {
 
72
                if (interface->priv->current_status != NULL)
 
73
                        g_object_unref (G_OBJECT (interface->priv->current_status));
 
74
 
 
75
                interface->priv->current_status = syncdaemon_status_info_new_from_hash_table (hash);
 
76
                g_signal_emit_by_name (daemon, "status_changed", interface->priv->current_status);
 
77
        }
 
78
}
 
79
 
 
80
static void
61
81
download_started_cb (DBusGProxy *proxy, gchar *path, gpointer user_data)
62
82
{
63
83
        SyncdaemonDaemon *daemon;
190
210
                                                                   "/status", "com.ubuntuone.SyncDaemon.Status");
191
211
        if (interface->priv->proxy != NULL) {
192
212
                /* Connect to DBus signals */
 
213
                dbus_g_proxy_add_signal (DBUS_G_PROXY (interface->priv->proxy), "StatusChanged",
 
214
                                         dbus_g_type_get_map ("GHashTable",
 
215
                                                              G_TYPE_STRING,
 
216
                                                              G_TYPE_STRING),
 
217
                                         G_TYPE_INVALID);
 
218
                dbus_g_proxy_connect_signal (DBUS_G_PROXY (interface->priv->proxy), "StatusChanged",
 
219
                                             G_CALLBACK (status_changed_cb), interface, NULL);
 
220
 
193
221
                dbus_g_proxy_add_signal (DBUS_G_PROXY (interface->priv->proxy), "DownloadStarted",
194
222
                                         G_TYPE_STRING,
195
223
                                         G_TYPE_INVALID);
252
280
}
253
281
 
254
282
/**
 
283
 * syncdaemon_status_interface_get_current_status:
 
284
 *
 
285
 * Return value: A #SyncdaemonStatusInfo object containing information about
 
286
 * Syncdaemon's current status. When no longer needed, it should be freed by
 
287
 * calling g_object_unref.
 
288
 */
 
289
SyncdaemonStatusInfo *
 
290
syncdaemon_status_interface_get_current_status (SyncdaemonStatusInterface *interface)
 
291
{
 
292
        g_return_val_if_fail (SYNCDAEMON_IS_STATUS_INTERFACE (interface), NULL);
 
293
 
 
294
        /* Only call DBus method if we haven't got the status yet */
 
295
        if (interface->priv->current_status == NULL) {
 
296
                GHashTable *hash;
 
297
                GError *error;
 
298
 
 
299
                if (dbus_g_proxy_call (DBUS_G_PROXY (interface->priv->proxy), "current_status", &error,
 
300
                                       G_TYPE_INVALID,
 
301
                                       dbus_g_type_get_map ("GHashTable",
 
302
                                                            G_TYPE_STRING,
 
303
                                                            G_TYPE_STRING), &hash,
 
304
                                       G_TYPE_INVALID)) {
 
305
                        interface->priv->current_status = syncdaemon_status_info_new_from_hash_table (hash);
 
306
                        g_hash_table_destroy (hash);
 
307
                } else {
 
308
                        g_warning ("Error calling current_status: %s", error->message);
 
309
                        g_error_free (error);
 
310
 
 
311
                        return NULL;
 
312
                }
 
313
        }
 
314
 
 
315
        return g_object_ref (G_OBJECT (interface->priv->current_status));
 
316
}
 
317
 
 
318
/**
255
319
 * syncdaemon_status_interface_get_current_downloads:
256
320
 *
257
321
 * Return value: A GSList of #SyncdaemonTransferInfo objects, each of which contains
279
343
                if (!dbus_g_proxy_call (DBUS_G_PROXY (interface->priv->proxy), "current_downloads", &error,
280
344
                                        G_TYPE_INVALID,
281
345
                                        dbus_g_type_get_collection ("GSList",
282
 
                                                            dbus_g_type_get_map
283
 
                                                            ("GHashTable",
284
 
                                                             G_TYPE_STRING,
285
 
                                                             G_TYPE_STRING)), &list,
 
346
                                                                    dbus_g_type_get_map ("GHashTable",
 
347
                                                                                         G_TYPE_STRING,
 
348
                                                                                         G_TYPE_STRING)), &list,
286
349
                                        G_TYPE_INVALID)) {
287
350
                        g_warning ("Error calling current_downloads: %s", error->message);
288
351
                        g_error_free (error);