~didrocks/ubuntuone-client/use_result_var

« back to all changes in this revision

Viewing changes to nautilus/location-widget.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2010-08-12 10:36:50 UTC
  • mto: This revision was merged to the branch mainline in revision 45.
  • Revision ID: james.westby@ubuntu.com-20100812103650-fgrtuxztjdwkt956
Tags: upstream-1.3.8
ImportĀ upstreamĀ versionĀ 1.3.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <libsyncdaemon/syncdaemon-shares-interface.h>
25
25
#include "location-widget.h"
26
26
 
27
 
#define EXPANDER_STATUS_SECTION "/apps/ubuntuone/nautilus"
28
 
#define EXPANDER_STATUS_KEY EXPANDER_STATUS_SECTION "/expand-location"
29
 
 
30
27
G_DEFINE_TYPE(LocationWidget, location_widget, GTK_TYPE_HBOX)
31
28
 
32
29
static void
33
 
set_label_text (LocationWidget *location, gboolean enabled)
34
 
{
35
 
        gchar *labeltext;
36
 
 
37
 
        if (enabled) {
38
 
                labeltext = g_strdup_printf ("<b>Ubuntu One</b> - %s", _("folder synchronized"));
39
 
                gtk_widget_hide (location->help_label);
40
 
        } else {
41
 
                labeltext = g_strdup_printf ("<b>Ubuntu One</b> - %s", _("folder not synchronized"));
42
 
                if (location->expander_status == GTK_ARROW_DOWN)
43
 
                        gtk_widget_show (location->help_label);
44
 
        }
45
 
                
46
 
        gtk_label_set_markup (GTK_LABEL (location->info_label), labeltext);
47
 
        g_free (labeltext);
48
 
}
49
 
 
50
 
static void
51
30
start_spinner (LocationWidget *location)
52
31
{
53
32
        gtk_widget_hide (location->help_label);
71
50
        path = syncdaemon_folder_info_get_path (folder_info);
72
51
        g_warning ("in folder_created_cb with path = %s", path);
73
52
        if (g_strcmp0 (path, location->path) == 0) {
74
 
                set_label_text (location, success);
75
 
                if (success) {
76
 
                        gtk_widget_hide (location->expander);
77
 
                        gtk_widget_set_sensitive (location->toggle_button, TRUE);
78
 
                        gtk_widget_hide (location->help_label);
79
 
                } else {
80
 
                        gtk_widget_set_sensitive (location->toggle_button, TRUE);
 
53
                gtk_widget_set_sensitive (location->toggle_button, TRUE);
 
54
                if (!success) {
81
55
                        ubuntuone_show_error_dialog (location->uon, _("Error enabling folder"),
82
56
                                                     _("Could not enable folder %s for synchronizing to Ubuntu One"),
83
57
                                                     location->path);
96
70
        path = syncdaemon_folder_info_get_path (folder_info);
97
71
        if (g_strcmp0 (path, location->path) == 0) {
98
72
                if (success) {
99
 
                        gtk_widget_show (location->expander);
100
 
                        set_label_text (location, FALSE);
101
73
                        gtk_widget_set_sensitive (location->toggle_button, TRUE);
102
 
                        if (location->expander_status == GTK_ARROW_DOWN)
103
 
                                gtk_widget_show (location->help_label);
104
74
                } else {
105
 
                        set_label_text (location, TRUE);
106
75
                        gtk_widget_set_sensitive (location->toggle_button, TRUE);
107
76
                        ubuntuone_show_error_dialog (location->uon, _("Error disabling folder"),
108
77
                                                     _("Could not disable folder %s for synchronizing to Ubuntu One"),
141
110
        object_class->finalize = location_widget_finalize;
142
111
}
143
112
 
144
 
static gboolean
145
 
check_shared_for_folder (LocationWidget *location, SyncdaemonFolderInfo *folder_info)
 
113
/* this is the wrong place for this, but it'll have to do for now */
 
114
gboolean
 
115
location_widget_check_shared_for_folder (SyncdaemonDaemon *daemon, SyncdaemonFolderInfo *folder_info, GtkWidget *widget)
146
116
{
147
117
        SyncdaemonInterface *interface;
148
118
        GHashTable *shares = NULL;
149
119
        gboolean result = TRUE;
150
120
 
151
 
        interface = syncdaemon_daemon_get_shares_interface (location->uon->syncdaemon);
 
121
        interface = syncdaemon_daemon_get_shares_interface (daemon);
152
122
        if (SYNCDAEMON_IS_SHARES_INTERFACE (interface)) {
153
123
                GSList *shared_list, *l;
154
124
 
223
193
                                                                " Would you like to proceed?"));
224
194
 
225
195
                        dialog = gtk_message_dialog_new (
226
 
                                GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (location))),
 
196
                                GTK_WINDOW (gtk_widget_get_toplevel (widget)),
227
197
                                0, GTK_MESSAGE_QUESTION,
228
198
                                GTK_BUTTONS_YES_NO,
229
199
                                "%s", question->str);
250
220
        if (interface != NULL) {
251
221
                SyncdaemonFolderInfo *folder_info;
252
222
 
253
 
                folder_info = syncdaemon_folders_interface_get_info (
254
 
                        SYNCDAEMON_FOLDERS_INTERFACE (interface),
255
 
                        location->path);
256
 
                if (folder_info != NULL && check_shared_for_folder (location, folder_info)) {
257
 
                        set_label_text (location, FALSE);
258
 
                        gtk_widget_set_sensitive (location->toggle_button, FALSE);
259
 
 
260
 
                        syncdaemon_folders_interface_delete (
261
 
                                SYNCDAEMON_FOLDERS_INTERFACE (interface),
262
 
                                syncdaemon_folder_info_get_volume_id (folder_info));
263
 
 
264
 
                        g_object_unref (G_OBJECT (folder_info));
265
 
                }
266
 
        }
 
223
                folder_info = syncdaemon_folders_interface_get_info (
 
224
                        SYNCDAEMON_FOLDERS_INTERFACE (interface),
 
225
                        location->path);
 
226
                if (folder_info != NULL) {
 
227
                        if (location_widget_check_shared_for_folder (location->uon->syncdaemon, folder_info, GTK_WIDGET (location))) {
 
228
                                gtk_widget_set_sensitive (location->toggle_button, FALSE);
 
229
 
 
230
                                syncdaemon_folders_interface_delete (
 
231
                                        SYNCDAEMON_FOLDERS_INTERFACE (interface),
 
232
                                        syncdaemon_folder_info_get_volume_id (folder_info));
 
233
                        }
 
234
 
 
235
                        g_object_unref (G_OBJECT (folder_info));
 
236
                }
 
237
        }
267
238
}
268
239
 
269
240
static void enable_u1 (LocationWidget *location);
290
261
        if (interface != NULL) {
291
262
                gchar *labeltext;
292
263
 
293
 
                /* Update label to show progress */
294
 
                labeltext = g_strdup_printf ("<b>Ubuntu One</b> - %s", _("sync in progress"));
295
 
                gtk_label_set_markup (GTK_LABEL (location->info_label), labeltext);
296
 
                g_free (labeltext);
297
 
 
298
 
                start_spinner (location);               
 
264
                start_spinner (location);
299
265
                gtk_widget_set_sensitive (location->toggle_button, FALSE);
300
266
 
301
267
                /* If there is no user authenticated, make Syncdaemon do so */
323
289
}
324
290
 
325
291
static gboolean
326
 
expander_clicked_cb (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
 
292
expander_clicked_cb (GtkExpander *expander, gpointer user_data)
327
293
{
328
294
        LocationWidget *location = LOCATION_WIDGET (user_data);
 
295
        gboolean expander_status = gtk_expander_get_expanded (expander);
329
296
 
330
 
        if (event->button == 1) {
331
 
                switch (location->expander_status) {
332
 
                case GTK_ARROW_DOWN: /* expanded */
333
 
                        gconf_client_set_bool (location->conf_client, EXPANDER_STATUS_KEY, FALSE, NULL);
334
 
                        break;
335
 
                case GTK_ARROW_RIGHT: /* collapsed */
336
 
                        gconf_client_set_bool (location->conf_client, EXPANDER_STATUS_KEY, TRUE, NULL);
337
 
                        break;
338
 
                }
339
 
        }
 
297
        gconf_client_set_bool (location->conf_client,
 
298
                               EXPANDER_STATUS_KEY,
 
299
                               expander_status,
 
300
                               NULL);
340
301
 
341
302
        return FALSE;
342
303
}
347
308
        LocationWidget *location = LOCATION_WIDGET (user_data);
348
309
 
349
310
        if (g_strcmp0 (gconf_entry_get_key (entry), EXPANDER_STATUS_KEY) == 0) {
350
 
                if (gconf_value_get_bool (gconf_entry_get_value (entry))) {
351
 
                        location->expander_status = GTK_ARROW_DOWN;
352
 
                        gtk_widget_show (location->help_label);
353
 
                } else {
354
 
                        location->expander_status = GTK_ARROW_RIGHT;
355
 
                        gtk_widget_hide (location->help_label);
356
 
                }
357
 
 
358
 
                gtk_arrow_set (GTK_ARROW (location->expander),  location->expander_status, GTK_SHADOW_IN);
 
311
                gboolean expanded = gconf_client_get_bool (location->conf_client,
 
312
                                                           EXPANDER_STATUS_KEY,
 
313
                                                           NULL);
 
314
                gtk_expander_set_expanded (GTK_EXPANDER (location->expander),
 
315
                                           expanded);
 
316
                location->expander_status = expanded;
359
317
        }
360
318
}
361
319
 
362
320
static void
 
321
allocate_cb (GtkWidget *label, GtkAllocation *allocation, gpointer user_data)
 
322
{
 
323
        gint width;
 
324
 
 
325
        if (allocation->width < 100)
 
326
                width = 100;    /* some number */
 
327
        else
 
328
                width = allocation->width - 2;
 
329
        gtk_widget_set_size_request(label, width, -1);
 
330
}
 
331
 
 
332
static void
363
333
location_widget_init (LocationWidget *location)
364
334
{
365
 
        GtkWidget *table, *box;
 
335
        GtkWidget *hbox, *align;
366
336
 
367
337
        location->path = NULL;
368
338
        location->info_label = NULL;
369
339
 
370
340
        /* Read expander status from GConf */
371
341
        location->conf_client = gconf_client_get_default ();
372
 
        gconf_client_add_dir (location->conf_client, EXPANDER_STATUS_SECTION, GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
 
342
        gconf_client_add_dir (location->conf_client, EXPANDER_STATUS_SECTION,
 
343
                              GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
373
344
        location->conf_notify_id = gconf_client_notify_add (location->conf_client,
374
345
                                                            EXPANDER_STATUS_SECTION,
375
346
                                                            (GConfClientNotifyFunc) config_changed_cb,
376
347
                                                            location,
377
348
                                                            NULL,
378
349
                                                            NULL);
379
 
 
380
 
        if (gconf_client_get_bool (location->conf_client, EXPANDER_STATUS_KEY, NULL))
381
 
                location->expander_status = GTK_ARROW_DOWN;
382
 
        else
383
 
                location->expander_status = GTK_ARROW_RIGHT;
 
350
        location->expander_status = gconf_client_get_bool (location->conf_client,
 
351
                                                           EXPANDER_STATUS_KEY, NULL);
384
352
 
385
353
        /* Create the widgets in the interface */
386
 
        table = gtk_table_new (2, 4, FALSE);
387
 
        gtk_widget_show (table);
388
 
        gtk_box_pack_start (GTK_BOX (location), table, TRUE, TRUE, 0);
389
 
 
390
 
        box = gtk_event_box_new ();
391
 
        g_signal_connect (G_OBJECT (box), "button-press-event",
392
 
                          G_CALLBACK (expander_clicked_cb), location);
393
 
        gtk_widget_show (box);
394
 
        gtk_table_attach (GTK_TABLE (table), box, 0, 1, 0, 1,
395
 
                          GTK_FILL, GTK_FILL, 3, 3);
396
 
 
397
 
        location->expander = gtk_arrow_new (location->expander_status, GTK_SHADOW_IN);
 
354
        hbox = gtk_hbox_new (FALSE, 0);
 
355
        gtk_widget_show (hbox);
 
356
        gtk_box_pack_start (GTK_BOX (location), hbox, TRUE, TRUE, 0);
 
357
 
 
358
        location->expander = gtk_expander_new ("<b>Ubuntu One</b>");
398
359
        gtk_widget_show (location->expander);
399
 
        gtk_container_add (GTK_CONTAINER (box), location->expander);
400
 
 
401
 
        location->info_label = gtk_label_new ("<b>Ubuntu One</b>");
402
 
        gtk_label_set_use_markup (GTK_LABEL (location->info_label), TRUE);
403
 
        gtk_misc_set_alignment (GTK_MISC (location->info_label), 0.0, 0.5);
404
 
        gtk_widget_show (location->info_label);
405
 
        gtk_table_attach (GTK_TABLE (table), location->info_label, 1, 2, 0, 1,
406
 
                          GTK_EXPAND | GTK_FILL | GTK_SHRINK, GTK_FILL, 3, 3);
 
360
        gtk_expander_set_use_markup (GTK_EXPANDER (location->expander), TRUE);
 
361
        gtk_expander_set_expanded (GTK_EXPANDER (location->expander),
 
362
                                   location->expander_status);
 
363
        g_signal_connect_after (G_OBJECT (location->expander), "activate",
 
364
                                G_CALLBACK (expander_clicked_cb), location);
 
365
        gtk_box_pack_start (GTK_BOX (hbox), location->expander, TRUE, TRUE, 0);
 
366
        location->info_label = gtk_expander_get_label_widget (GTK_EXPANDER (location->expander));
407
367
 
408
368
        location->help_label = gtk_label_new (_("These files are not backed up and will not be available in your other computers"));
 
369
        gtk_widget_show (location->help_label);
409
370
        gtk_label_set_use_markup (GTK_LABEL (location->help_label), TRUE);
 
371
        gtk_label_set_line_wrap (GTK_LABEL (location->help_label), TRUE);
410
372
        gtk_misc_set_alignment (GTK_MISC (location->help_label), 0.0, 0.5);
411
 
        gtk_table_attach (GTK_TABLE (table), location->help_label, 1, 3, 1, 2,
412
 
                          GTK_EXPAND | GTK_FILL | GTK_SHRINK, GTK_FILL, 3, 3);
 
373
        gtk_misc_set_padding (GTK_MISC (location->help_label), 4, 4);
 
374
        g_signal_connect (G_OBJECT (location->help_label), "size-allocate",
 
375
                          G_CALLBACK (allocate_cb), NULL );
 
376
        gtk_container_add (GTK_CONTAINER (location->expander),
 
377
                           location->help_label);
413
378
 
414
379
        location->spinner = gtk_spinner_new ();
415
 
        gtk_table_attach (GTK_TABLE (table), location->spinner, 2, 3, 0, 1,
416
 
                          GTK_SHRINK, GTK_SHRINK, 3, 3);
 
380
        gtk_box_pack_start (GTK_BOX (hbox), location->spinner, FALSE, FALSE, 0);
417
381
 
418
382
        /* Buttons */
419
 
        location->toggle_button = gtk_check_button_new_with_label (_("Synchronize folder"));
 
383
        align = gtk_alignment_new (1.0, 0.0, 0.0, 0.0);
 
384
        gtk_widget_show (align);
 
385
        gtk_box_pack_start (GTK_BOX (hbox), align,
 
386
                            FALSE, FALSE, 0);
 
387
 
 
388
        location->toggle_button = gtk_check_button_new_with_label (_("Synchronize this folder"));
420
389
        gtk_widget_show (location->toggle_button);
421
 
        gtk_table_attach (GTK_TABLE (table), location->toggle_button, 3, 4, 0, 1,
422
 
                          GTK_FILL, GTK_FILL, 3, 3);
 
390
        gtk_container_add (GTK_CONTAINER (align), location->toggle_button);
423
391
}
424
392
 
425
393
static gboolean
455
423
{
456
424
        LocationWidget *location;
457
425
        gboolean is_root;
 
426
        gboolean is_xdg = FALSE;
 
427
        guint i = 0;
458
428
 
459
429
        g_return_val_if_fail (uon != NULL, NULL);
460
430
        g_return_val_if_fail (path != NULL, NULL);
464
434
            strlen (path) == strlen (g_get_home_dir ()))
465
435
                return NULL;
466
436
 
 
437
        /* in fact, we only show it for the toplevel XDG dirs, or the
 
438
           root of UDFs */
 
439
        for (i = 0; i < G_USER_N_DIRECTORIES; i++) {
 
440
                if (g_strcmp0 (g_get_user_special_dir (i), path) == 0) {
 
441
                        is_xdg = TRUE;
 
442
                        break;
 
443
                }
 
444
        }
 
445
        if (!is_xdg) {
 
446
                /* last chance */
 
447
                ubuntuone_is_storagefs (uon, path, &is_root);
 
448
                if (!is_root || is_special_udf (uon, path))
 
449
                        return NULL;
 
450
        }
 
451
 
467
452
        location = (LocationWidget *) g_object_new (TYPE_LOCATION_WIDGET, NULL);
468
453
        location->uon = uon;
469
454
        location->path = g_strdup (path);
476
461
 
477
462
        if (ubuntuone_is_storagefs (uon, path, &is_root)) {
478
463
                /* Create label and disable button */
479
 
                gtk_widget_hide (location->expander);
480
 
                set_label_text (location, TRUE);
481
464
                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (location->toggle_button), TRUE);
482
465
                if (!is_root || is_special_udf (uon, path))
483
466
                        gtk_widget_set_sensitive (location->toggle_button, FALSE);
484
467
        } else {
485
468
                /* Check if this is the 'Shared with me' folder */
486
469
                if (is_special_udf (uon, path)) {
487
 
                        gtk_widget_hide (location->expander);
488
 
                        set_label_text (location, TRUE);
489
470
                        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (location->toggle_button), TRUE);
490
471
                        gtk_widget_set_sensitive (location->toggle_button, FALSE);
491
472
                } else {
506
487
                        g_slist_free (udfs);
507
488
                        
508
489
                        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (location->toggle_button), FALSE);
509
 
                        if (allow_enabling) {
510
 
                                set_label_text (location, FALSE);
511
 
                        } else {
 
490
                        if (!allow_enabling) {
512
491
                                gchar *labeltext;
513
492
 
514
 
                                labeltext = g_strdup_printf ("<b>Ubuntu One</b> - %s",
515
 
                                                             _("cannot synchronize this folder"));
516
 
                                gtk_label_set_markup (GTK_LABEL (location->info_label), labeltext);
517
 
                                g_free (labeltext);
518
 
 
519
493
                                gtk_label_set_text (GTK_LABEL (location->help_label),
520
494
                                                    _("This folder cannot be synchronized because it contains "
521
 
                                                      "one or more folders that already synchronized"));
522
 
                                if (location->expander_status == GTK_ARROW_DOWN)
523
 
                                        gtk_widget_show (location->help_label);
 
495
                                                      "one or more folders that are already synchronized"));
524
496
 
525
497
                                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (location->toggle_button), FALSE);
526
498
                                gtk_widget_set_sensitive (location->toggle_button, FALSE);
534
506
                gtk_label_set_text (GTK_LABEL (location->help_label),
535
507
                                    _("Operations on this folder are disabled because there is no network "
536
508
                                      "connection"));
537
 
                if (location->expander_status == GTK_ARROW_DOWN)
538
 
                                        gtk_widget_show (location->help_label);
539
509
        }
540
510
 
541
511
        g_signal_connect (G_OBJECT (location->toggle_button), "toggled",