~ubuntu-branches/ubuntu/wily/caja/wily

« back to all changes in this revision

Viewing changes to src/caja-places-sidebar.c

  • Committer: Package Import Robot
  • Author(s): John Paul Adrian Glaubitz, Martin Wimpress, John Paul Adrian Glaubitz
  • Date: 2015-08-10 13:39:55 UTC
  • mfrom: (1.2.1) (9.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20150810133955-b2uyptg7cf8rn8su
Tags: 1.10.3-1
[ Martin Wimpress ]
* New upstream release.
* debian/caja-common.install:
  + Add common files.
* debian/caja.install:
  + Remove common files.
* debian/libcaja-extension-dev.install:
  + Add usr/share/gtk-doc.
* debian/rules:
  + Add --enable-gtk-doc.
  + Remove dfsg suffix.
* debian/watch:
  + Remove dfsg suffix.

[ John Paul Adrian Glaubitz ]
* Fix spelling in debian/control (allows to -> allows one to).
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
#include "caja-places-sidebar.h"
54
54
#include "caja-window.h"
55
55
 
56
 
#include "glibcompat.h" /* for g_list_free_full and g_clear_object */
57
 
 
58
56
#define EJECT_BUTTON_XPAD 6
59
57
#define ICON_CELL_XPAD 6
60
58
 
149
147
} PlaceType;
150
148
 
151
149
typedef enum {
 
150
    SECTION_COMPUTER,
152
151
    SECTION_DEVICES,
153
152
    SECTION_BOOKMARKS,
154
 
    SECTION_COMPUTER,
155
153
    SECTION_NETWORK,
156
154
} SectionType;
157
155
 
489
487
 
490
488
    volume_monitor = sidebar->volume_monitor;
491
489
 
 
490
    /* COMPUTER */
 
491
    last_iter = add_heading (sidebar, SECTION_COMPUTER,
 
492
                             _("Computer"));
 
493
 
 
494
    /* add built in bookmarks */
 
495
    desktop_path = caja_get_desktop_directory ();
 
496
 
 
497
    /* home folder */
 
498
    if (strcmp (g_get_home_dir(), desktop_path) != 0) {
 
499
        char *display_name;
 
500
 
 
501
        mount_uri = caja_get_home_directory_uri ();
 
502
        display_name = g_filename_display_basename (g_get_home_dir ());
 
503
        icon = g_themed_icon_new (CAJA_ICON_HOME);
 
504
        last_iter = add_place (sidebar, PLACES_BUILT_IN,
 
505
                               SECTION_COMPUTER,
 
506
                               display_name, icon,
 
507
                               mount_uri, NULL, NULL, NULL, 0,
 
508
                               _("Open your personal folder"));
 
509
        g_object_unref (icon);
 
510
        g_free (display_name);
 
511
        compare_for_selection (sidebar,
 
512
                               location, mount_uri, last_uri,
 
513
                               &last_iter, &select_path);
 
514
        g_free (mount_uri);
 
515
    }
 
516
 
 
517
    /* desktop */
 
518
    mount_uri = g_filename_to_uri (desktop_path, NULL, NULL);
 
519
    icon = g_themed_icon_new (CAJA_ICON_DESKTOP);
 
520
    last_iter = add_place (sidebar, PLACES_BUILT_IN,
 
521
                           SECTION_COMPUTER,
 
522
                           _("Desktop"), icon,
 
523
                           mount_uri, NULL, NULL, NULL, 0,
 
524
                           _("Open the contents of your desktop in a folder"));
 
525
    g_object_unref (icon);
 
526
    compare_for_selection (sidebar,
 
527
                           location, mount_uri, last_uri,
 
528
                           &last_iter, &select_path);
 
529
    g_free (mount_uri);
 
530
    g_free (desktop_path);
 
531
 
 
532
    /* file system root */
 
533
    mount_uri = "file:///"; /* No need to strdup */
 
534
    icon = g_themed_icon_new (CAJA_ICON_FILESYSTEM);
 
535
    last_iter = add_place (sidebar, PLACES_BUILT_IN,
 
536
                           SECTION_COMPUTER,
 
537
                           _("File System"), icon,
 
538
                           mount_uri, NULL, NULL, NULL, 0,
 
539
                           _("Open the contents of the File System"));
 
540
    g_object_unref (icon);
 
541
    compare_for_selection (sidebar,
 
542
                           location, mount_uri, last_uri,
 
543
                           &last_iter, &select_path);
 
544
 
 
545
    
 
546
    /* XDG directories */
 
547
    xdg_dirs = NULL;
 
548
    for (index = 0; index < G_USER_N_DIRECTORIES; index++) {
 
549
 
 
550
        if (index == G_USER_DIRECTORY_DESKTOP ||
 
551
            index == G_USER_DIRECTORY_TEMPLATES ||
 
552
            index == G_USER_DIRECTORY_PUBLIC_SHARE) {
 
553
            continue;
 
554
        }
 
555
 
 
556
        path = g_get_user_special_dir (index);
 
557
 
 
558
        /* xdg resets special dirs to the home directory in case
 
559
         * it's not finiding what it expects. We don't want the home
 
560
         * to be added multiple times in that weird configuration.
 
561
         */
 
562
        if (path == NULL
 
563
            || g_strcmp0 (path, g_get_home_dir ()) == 0
 
564
            || g_list_find_custom (xdg_dirs, path, (GCompareFunc) g_strcmp0) != NULL) {
 
565
            continue;
 
566
        }
 
567
 
 
568
        root = g_file_new_for_path (path);
 
569
        name = g_file_get_basename (root);
 
570
        icon = caja_user_special_directory_get_gicon (index);
 
571
        mount_uri = g_file_get_uri (root);
 
572
        tooltip = g_file_get_parse_name (root);
 
573
 
 
574
        last_iter = add_place (sidebar, PLACES_BUILT_IN,
 
575
                               SECTION_COMPUTER,
 
576
                               name, icon, mount_uri,
 
577
                               NULL, NULL, NULL, 0,
 
578
                               tooltip);
 
579
        compare_for_selection (sidebar,
 
580
                               location, mount_uri, last_uri,
 
581
                               &last_iter, &select_path);
 
582
        g_free (name);
 
583
        g_object_unref (root);
 
584
        g_object_unref (icon);
 
585
        g_free (mount_uri);
 
586
        g_free (tooltip);
 
587
 
 
588
        xdg_dirs = g_list_prepend (xdg_dirs, (char *)path);
 
589
    }
 
590
    g_list_free (xdg_dirs);
 
591
 
 
592
    mount_uri = "trash:///"; /* No need to strdup */
 
593
    icon = caja_trash_monitor_get_icon ();
 
594
    last_iter = add_place (sidebar, PLACES_BUILT_IN,
 
595
                           SECTION_COMPUTER,
 
596
                           _("Trash"), icon, mount_uri,
 
597
                           NULL, NULL, NULL, 0,
 
598
                           _("Open the trash"));
 
599
    compare_for_selection (sidebar,
 
600
                           location, mount_uri, last_uri,
 
601
                           &last_iter, &select_path);
 
602
    g_object_unref (icon);
 
603
 
492
604
    /* first go through all connected drives */
493
605
    drives = g_volume_monitor_get_connected_drives (volume_monitor);
494
606
 
631
743
    }
632
744
    g_list_free (volumes);
633
745
 
 
746
    /* add mounts that has no volume (/etc/mtab mounts, ftp, sftp,...) */
 
747
    network_mounts = NULL;
 
748
    mounts = g_volume_monitor_get_mounts (volume_monitor);
 
749
 
 
750
    for (l = mounts; l != NULL; l = l->next)
 
751
    {
 
752
        mount = l->data;
 
753
        if (g_mount_is_shadowed (mount))
 
754
        {
 
755
            g_object_unref (mount);
 
756
            continue;
 
757
        }
 
758
        volume = g_mount_get_volume (mount);
 
759
        if (volume != NULL)
 
760
        {
 
761
            g_object_unref (volume);
 
762
            g_object_unref (mount);
 
763
            continue;
 
764
        }
 
765
        root = g_mount_get_default_location (mount);
 
766
 
 
767
        if (!g_file_is_native (root)) {
 
768
            network_mounts = g_list_prepend (network_mounts, g_object_ref (mount));
 
769
            continue;
 
770
        }
 
771
 
 
772
        icon = g_mount_get_icon (mount);
 
773
        mount_uri = g_file_get_uri (root);
 
774
        name = g_mount_get_name (mount);
 
775
        tooltip = g_file_get_parse_name (root);
 
776
        last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME,
 
777
                               SECTION_COMPUTER,
 
778
                               name, icon, mount_uri,
 
779
                               NULL, NULL, mount, 0, tooltip);
 
780
        compare_for_selection (sidebar,
 
781
                               location, mount_uri, last_uri,
 
782
                               &last_iter, &select_path);
 
783
        g_object_unref (root);
 
784
        g_object_unref (mount);
 
785
        g_object_unref (icon);
 
786
        g_free (name);
 
787
        g_free (mount_uri);
 
788
        g_free (tooltip);
 
789
    }
 
790
    g_list_free (mounts);
 
791
 
 
792
 
634
793
    /* add bookmarks */
635
794
    bookmark_count = caja_bookmark_list_length (sidebar->bookmarks);
636
795
 
670
829
        g_free (tooltip);
671
830
    }
672
831
 
673
 
    last_iter = add_heading (sidebar, SECTION_COMPUTER,
674
 
                             _("Computer"));
675
 
 
676
 
    /* add built in bookmarks */
677
 
    desktop_path = caja_get_desktop_directory ();
678
 
 
679
 
    /* home folder */
680
 
    if (strcmp (g_get_home_dir(), desktop_path) != 0) {
681
 
        char *display_name;
682
 
 
683
 
        mount_uri = caja_get_home_directory_uri ();
684
 
        display_name = g_filename_display_basename (g_get_home_dir ());
685
 
        icon = g_themed_icon_new (CAJA_ICON_HOME);
686
 
        last_iter = add_place (sidebar, PLACES_BUILT_IN,
687
 
                               SECTION_COMPUTER,
688
 
                               display_name, icon,
689
 
                               mount_uri, NULL, NULL, NULL, 0,
690
 
                               _("Open your personal folder"));
691
 
        g_object_unref (icon);
692
 
        g_free (display_name);
693
 
        compare_for_selection (sidebar,
694
 
                               location, mount_uri, last_uri,
695
 
                               &last_iter, &select_path);
696
 
        g_free (mount_uri);
697
 
    }
698
 
 
699
 
    /* desktop */
700
 
    mount_uri = g_filename_to_uri (desktop_path, NULL, NULL);
701
 
    icon = g_themed_icon_new (CAJA_ICON_DESKTOP);
702
 
    last_iter = add_place (sidebar, PLACES_BUILT_IN,
703
 
                           SECTION_COMPUTER,
704
 
                           _("Desktop"), icon,
705
 
                           mount_uri, NULL, NULL, NULL, 0,
706
 
                           _("Open the contents of your desktop in a folder"));
707
 
    g_object_unref (icon);
708
 
    compare_for_selection (sidebar,
709
 
                           location, mount_uri, last_uri,
710
 
                           &last_iter, &select_path);
711
 
    g_free (mount_uri);
712
 
    g_free (desktop_path);
713
 
 
714
 
    /* file system root */
715
 
    mount_uri = "file:///"; /* No need to strdup */
716
 
    icon = g_themed_icon_new (CAJA_ICON_FILESYSTEM);
717
 
    last_iter = add_place (sidebar, PLACES_BUILT_IN,
718
 
                           SECTION_COMPUTER,
719
 
                           _("File System"), icon,
720
 
                           mount_uri, NULL, NULL, NULL, 0,
721
 
                           _("Open the contents of the File System"));
722
 
    g_object_unref (icon);
723
 
    compare_for_selection (sidebar,
724
 
                           location, mount_uri, last_uri,
725
 
                           &last_iter, &select_path);
726
 
 
727
 
    
728
 
    /* XDG directories */
729
 
    xdg_dirs = NULL;
730
 
    for (index = 0; index < G_USER_N_DIRECTORIES; index++) {
731
 
 
732
 
        if (index == G_USER_DIRECTORY_DESKTOP ||
733
 
            index == G_USER_DIRECTORY_TEMPLATES ||
734
 
            index == G_USER_DIRECTORY_PUBLIC_SHARE) {
735
 
            continue;
736
 
        }
737
 
 
738
 
        path = g_get_user_special_dir (index);
739
 
 
740
 
        /* xdg resets special dirs to the home directory in case
741
 
         * it's not finiding what it expects. We don't want the home
742
 
         * to be added multiple times in that weird configuration.
743
 
         */
744
 
        if (path == NULL
745
 
            || g_strcmp0 (path, g_get_home_dir ()) == 0
746
 
            || g_list_find_custom (xdg_dirs, path, (GCompareFunc) g_strcmp0) != NULL) {
747
 
            continue;
748
 
        }
749
 
 
750
 
        root = g_file_new_for_path (path);
751
 
        name = g_file_get_basename (root);
752
 
        icon = caja_user_special_directory_get_gicon (index);
753
 
        mount_uri = g_file_get_uri (root);
754
 
        tooltip = g_file_get_parse_name (root);
755
 
 
756
 
        last_iter = add_place (sidebar, PLACES_BUILT_IN,
757
 
                               SECTION_COMPUTER,
758
 
                               name, icon, mount_uri,
759
 
                               NULL, NULL, NULL, 0,
760
 
                               tooltip);
761
 
        compare_for_selection (sidebar,
762
 
                               location, mount_uri, last_uri,
763
 
                               &last_iter, &select_path);
764
 
        g_free (name);
765
 
        g_object_unref (root);
766
 
        g_object_unref (icon);
767
 
        g_free (mount_uri);
768
 
        g_free (tooltip);
769
 
 
770
 
        xdg_dirs = g_list_prepend (xdg_dirs, (char *)path);
771
 
    }
772
 
    g_list_free (xdg_dirs);
773
 
 
774
 
    /* add mounts that has no volume (/etc/mtab mounts, ftp, sftp,...) */
775
 
    network_mounts = NULL;
776
 
    mounts = g_volume_monitor_get_mounts (volume_monitor);
777
 
 
778
 
    for (l = mounts; l != NULL; l = l->next)
779
 
    {
780
 
        mount = l->data;
781
 
        if (g_mount_is_shadowed (mount))
782
 
        {
783
 
            g_object_unref (mount);
784
 
            continue;
785
 
        }
786
 
        volume = g_mount_get_volume (mount);
787
 
        if (volume != NULL)
788
 
        {
789
 
            g_object_unref (volume);
790
 
            g_object_unref (mount);
791
 
            continue;
792
 
        }
793
 
        root = g_mount_get_default_location (mount);
794
 
 
795
 
        if (!g_file_is_native (root)) {
796
 
            network_mounts = g_list_prepend (network_mounts, g_object_ref (mount));
797
 
            continue;
798
 
        }
799
 
 
800
 
        icon = g_mount_get_icon (mount);
801
 
        mount_uri = g_file_get_uri (root);
802
 
        name = g_mount_get_name (mount);
803
 
        tooltip = g_file_get_parse_name (root);
804
 
        last_iter = add_place (sidebar, PLACES_MOUNTED_VOLUME,
805
 
                               SECTION_COMPUTER,
806
 
                               name, icon, mount_uri,
807
 
                               NULL, NULL, mount, 0, tooltip);
808
 
        compare_for_selection (sidebar,
809
 
                               location, mount_uri, last_uri,
810
 
                               &last_iter, &select_path);
811
 
        g_object_unref (root);
812
 
        g_object_unref (mount);
813
 
        g_object_unref (icon);
814
 
        g_free (name);
815
 
        g_free (mount_uri);
816
 
        g_free (tooltip);
817
 
    }
818
 
    g_list_free (mounts);
819
 
 
820
 
    mount_uri = "trash:///"; /* No need to strdup */
821
 
    icon = caja_trash_monitor_get_icon ();
822
 
    last_iter = add_place (sidebar, PLACES_BUILT_IN,
823
 
                           SECTION_COMPUTER,
824
 
                           _("Trash"), icon, mount_uri,
825
 
                           NULL, NULL, NULL, 0,
826
 
                           _("Open the trash"));
827
 
    compare_for_selection (sidebar,
828
 
                           location, mount_uri, last_uri,
829
 
                           &last_iter, &select_path);
830
 
    g_object_unref (icon);
831
 
 
832
832
    /* network */
833
833
    last_iter = add_heading (sidebar, SECTION_NETWORK,
834
834
                             _("Network"));
1130
1130
                        PLACES_SIDEBAR_COLUMN_SECTION_TYPE, &section_type,
1131
1131
                        -1);
1132
1132
 
1133
 
    if (place_type == PLACES_HEADING && section_type != SECTION_BOOKMARKS) {
1134
 
        /* never drop on headings, but special case the bookmarks heading,
1135
 
         * so we can drop bookmarks in between it and the first item.
 
1133
    if (place_type == PLACES_HEADING &&
 
1134
        section_type != SECTION_BOOKMARKS &&
 
1135
        section_type != SECTION_NETWORK) {
 
1136
        /* never drop on headings, but the bookmarks or network heading
 
1137
         * is a special case, so we can create new bookmarks by dragging
 
1138
         * at the beginning or end of the bookmark list.
1136
1139
         */
1137
 
 
1138
1140
        gtk_tree_path_free (*path);
1139
1141
        *path = NULL;
1140
1142
 
1145
1147
        sidebar->drag_data_received &&
1146
1148
        sidebar->drag_data_info == GTK_TREE_MODEL_ROW) {
1147
1149
        /* don't allow dropping bookmarks into non-bookmark areas */
1148
 
 
1149
 
    gtk_tree_path_free (*path);
1150
 
    *path = NULL;
 
1150
        gtk_tree_path_free (*path);
 
1151
        *path = NULL;
1151
1152
 
1152
1153
        return FALSE;
1153
1154
    }
1154
1155
 
1155
 
    if (section_type == SECTION_BOOKMARKS) {
 
1156
    /* drag to top or bottom of bookmark list to add a bookmark */
 
1157
    if (place_type == PLACES_HEADING && section_type == SECTION_BOOKMARKS) {
1156
1158
        *pos = GTK_TREE_VIEW_DROP_AFTER;
 
1159
    } else if (place_type == PLACES_HEADING && section_type == SECTION_NETWORK) {
 
1160
        *pos = GTK_TREE_VIEW_DROP_BEFORE;
1157
1161
    } else {
1158
 
        /* non-bookmark shortcuts can only be dragged into */
 
1162
        /* or else you want to drag items INTO the existing bookmarks */
1159
1163
        *pos = GTK_TREE_VIEW_DROP_INTO_OR_BEFORE;
1160
1164
    }
1161
1165
 
1245
1249
{
1246
1250
    GtkTreePath *path;
1247
1251
    GtkTreeViewDropPosition pos;
1248
 
    int action;
 
1252
    int action = 0;
1249
1253
    GtkTreeIter iter;
1250
1254
    char *uri;
1251
1255
    gboolean res;
1266
1270
    }
1267
1271
 
1268
1272
    if (pos == GTK_TREE_VIEW_DROP_BEFORE ||
1269
 
            pos == GTK_TREE_VIEW_DROP_AFTER )
 
1273
        pos == GTK_TREE_VIEW_DROP_AFTER )
1270
1274
    {
1271
1275
        if (sidebar->drag_data_received &&
1272
 
                sidebar->drag_data_info == GTK_TREE_MODEL_ROW)
 
1276
            sidebar->drag_data_info == GTK_TREE_MODEL_ROW)
1273
1277
        {
1274
1278
            action = GDK_ACTION_MOVE;
1275
1279
        }
1527
1531
    success = FALSE;
1528
1532
 
1529
1533
    if (tree_pos == GTK_TREE_VIEW_DROP_BEFORE ||
1530
 
            tree_pos == GTK_TREE_VIEW_DROP_AFTER)
 
1534
        tree_pos == GTK_TREE_VIEW_DROP_AFTER)
1531
1535
    {
1532
1536
        model = gtk_tree_view_get_model (tree_view);
1533
1537
 
1538
1542
 
1539
1543
        gtk_tree_model_get (model, &iter,
1540
1544
                            PLACES_SIDEBAR_COLUMN_SECTION_TYPE, &section_type,
1541
 
                                PLACES_SIDEBAR_COLUMN_ROW_TYPE, &place_type,
 
1545
                            PLACES_SIDEBAR_COLUMN_ROW_TYPE, &place_type,
1542
1546
                            PLACES_SIDEBAR_COLUMN_INDEX, &position,
1543
1547
                            -1);
1544
1548
 
1545
 
        if (section_type != SECTION_BOOKMARKS) {
 
1549
        if (section_type != SECTION_BOOKMARKS &&
 
1550
            !(section_type == SECTION_NETWORK && place_type == PLACES_HEADING)) {
1546
1551
            goto out;
1547
1552
        }
1548
1553
 
 
1554
        if (section_type == SECTION_NETWORK && place_type == PLACES_HEADING &&
 
1555
            tree_pos == GTK_TREE_VIEW_DROP_BEFORE) {
 
1556
            position = caja_bookmark_list_length (sidebar->bookmarks);
 
1557
        }
 
1558
 
1549
1559
        if (tree_pos == GTK_TREE_VIEW_DROP_AFTER && place_type != PLACES_HEADING) {
1550
1560
            /* heading already has position 0 */
1551
1561
            position++;
3096
3106
        g_object_set (cell,
3097
3107
                      "visible", TRUE,
3098
3108
                      "xpad", 3,
3099
 
                      "ypad", 3,
 
3109
                      "ypad", 0,
3100
3110
                      NULL);
3101
3111
    }
3102
3112
}
3165
3175
    g_object_set (cell,
3166
3176
                  "weight", PANGO_WEIGHT_BOLD,
3167
3177
                  "weight-set", TRUE,
3168
 
                  "ypad", 6,
 
3178
                  "ypad", 1,
3169
3179
                  "xpad", 0,
3170
3180
                  NULL);
3171
3181
    gtk_tree_view_column_set_cell_data_func (col, cell,