Updating branch refs/heads/jannis/new-shortcuts-pane to 92ff6996ea58f5f772164f803c19978eb82ad54c (commit) from 7f5f9814d999ad873d451cf605476f3020ed73f1 (commit)
commit 92ff6996ea58f5f772164f803c19978eb82ad54c Author: Jannis Pohlmann <jan...@xfce.org> Date: Fri Nov 25 02:07:17 2011 +0000 Initial work on gphoto2 and detecting linked mounts/volumes. thunar/thunar-enum-types.c | 1 + thunar/thunar-enum-types.h | 1 + thunar/thunar-shortcut-group.c | 23 ++++++++-- thunar/thunar-shortcut-group.h | 43 ++++++++++--------- thunar/thunar-shortcut.c | 90 +++++++++++++++++++++++++++++++-------- thunar/thunar-shortcut.h | 2 + thunar/thunar-shortcuts-view.c | 89 ++++++++++++++++++++++++++++----------- thunar/thunar-shortcuts-view.h | 2 + 8 files changed, 182 insertions(+), 69 deletions(-) diff --git a/thunar/thunar-enum-types.c b/thunar/thunar-enum-types.c index 6893656..374d25c 100644 --- a/thunar/thunar-enum-types.c +++ b/thunar/thunar-enum-types.c @@ -350,6 +350,7 @@ thunar_shortcut_type_get_type (void) { THUNAR_SHORTCUT_REGULAR_MOUNT, "THUNAR_SHORTCUT_REGULAR_MOUNT", "regular-mount", }, { THUNAR_SHORTCUT_ARCHIVE_MOUNT, "THUNAR_SHORTCUT_ARCHIVE_MOUNT", "archive-mount", }, { THUNAR_SHORTCUT_NETWORK_MOUNT, "THUNAR_SHORTCUT_NETWORK_MOUNT", "network-mount", }, + { THUNAR_SHORTCUT_DEVICE_MOUNT, "THUNAR_SHORTCUT_DEVICE_MOUNT", "device-mount", }, { 0, NULL, NULL, }, }; diff --git a/thunar/thunar-enum-types.h b/thunar/thunar-enum-types.h index 609de31..68b1f5c 100644 --- a/thunar/thunar-enum-types.h +++ b/thunar/thunar-enum-types.h @@ -309,6 +309,7 @@ typedef enum THUNAR_SHORTCUT_REGULAR_MOUNT = 1 << 5, THUNAR_SHORTCUT_ARCHIVE_MOUNT = 1 << 6, THUNAR_SHORTCUT_NETWORK_MOUNT = 1 << 7, + THUNAR_SHORTCUT_DEVICE_MOUNT = 1 << 8, } ThunarShortcutType; GType thunar_shortcut_type_get_type (void) G_GNUC_CONST; diff --git a/thunar/thunar-shortcut-group.c b/thunar/thunar-shortcut-group.c index 68d8965..258877a 100644 --- a/thunar/thunar-shortcut-group.c +++ b/thunar/thunar-shortcut-group.c @@ -591,13 +591,26 @@ thunar_shortcut_group_find_shortcut_by_file (ThunarShortcutGroup *group, ThunarFile *file, ThunarShortcut **result) { + _thunar_return_val_if_fail (THUNAR_IS_SHORTCUT_GROUP (group), FALSE); + _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE); + + return thunar_shortcut_group_find_shortcut_by_location (group, file->gfile, result); +} + + + +gboolean +thunar_shortcut_group_find_shortcut_by_location (ThunarShortcutGroup *group, + GFile *location, + ThunarShortcut **result) +{ ThunarShortcut *shortcut; - gboolean has_shortcut = FALSE; - GList *children; - GList *iter; + gboolean has_shortcut = FALSE; + GList *children; + GList *iter; _thunar_return_val_if_fail (THUNAR_IS_SHORTCUT_GROUP (group), FALSE); - _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE); + _thunar_return_val_if_fail (G_IS_FILE (location), FALSE); children = gtk_container_get_children (GTK_CONTAINER (group->shortcuts)); @@ -608,7 +621,7 @@ thunar_shortcut_group_find_shortcut_by_file (ThunarShortcutGroup *group, { shortcut = THUNAR_SHORTCUT (iter->data); - if (thunar_shortcut_matches_file (shortcut, file)) + if (thunar_shortcut_matches_location (shortcut, location)) { if (result != NULL) *result = shortcut; diff --git a/thunar/thunar-shortcut-group.h b/thunar/thunar-shortcut-group.h index eed1d66..b21bcc6 100644 --- a/thunar/thunar-shortcut-group.h +++ b/thunar/thunar-shortcut-group.h @@ -37,27 +37,30 @@ typedef struct _ThunarShortcutGroupPrivate ThunarShortcutGroupPrivate; typedef struct _ThunarShortcutGroupClass ThunarShortcutGroupClass; typedef struct _ThunarShortcutGroup ThunarShortcutGroup; -GType thunar_shortcut_group_get_type (void) G_GNUC_CONST; +GType thunar_shortcut_group_get_type (void) G_GNUC_CONST; -GtkWidget *thunar_shortcut_group_new (const gchar *label, - ThunarShortcutType accepted_types); -gboolean thunar_shortcut_group_try_add_shortcut (ThunarShortcutGroup *group, - ThunarShortcut *shortcut); -void thunar_shortcut_group_unselect_shortcuts (ThunarShortcutGroup *group, - ThunarShortcut *exception); -void thunar_shortcut_group_unprelight_shortcuts (ThunarShortcutGroup *group, - ThunarShortcut *exception); -void thunar_shortcut_group_cancel_activations (ThunarShortcutGroup *group, - ThunarShortcut *exception); -void thunar_shortcut_group_update_selection (ThunarShortcutGroup *group, - ThunarFile *file); -void thunar_shortcut_group_remove_volume_shortcut (ThunarShortcutGroup *group, - GVolume *volume); -void thunar_shortcut_group_remove_mount_shortcut (ThunarShortcutGroup *group, - GMount *mount); -gboolean thunar_shortcut_group_find_shortcut_by_file (ThunarShortcutGroup *group, - ThunarFile *file, - ThunarShortcut **result); +GtkWidget *thunar_shortcut_group_new (const gchar *label, + ThunarShortcutType accepted_types); +gboolean thunar_shortcut_group_try_add_shortcut (ThunarShortcutGroup *group, + ThunarShortcut *shortcut); +void thunar_shortcut_group_unselect_shortcuts (ThunarShortcutGroup *group, + ThunarShortcut *exception); +void thunar_shortcut_group_unprelight_shortcuts (ThunarShortcutGroup *group, + ThunarShortcut *exception); +void thunar_shortcut_group_cancel_activations (ThunarShortcutGroup *group, + ThunarShortcut *exception); +void thunar_shortcut_group_update_selection (ThunarShortcutGroup *group, + ThunarFile *file); +void thunar_shortcut_group_remove_volume_shortcut (ThunarShortcutGroup *group, + GVolume *volume); +void thunar_shortcut_group_remove_mount_shortcut (ThunarShortcutGroup *group, + GMount *mount); +gboolean thunar_shortcut_group_find_shortcut_by_file (ThunarShortcutGroup *group, + ThunarFile *file, + ThunarShortcut **result); +gboolean thunar_shortcut_group_find_shortcut_by_location (ThunarShortcutGroup *group, + GFile *location, + ThunarShortcut **result); G_END_DECLS diff --git a/thunar/thunar-shortcut.c b/thunar/thunar-shortcut.c index 66fa959..80f49d9 100644 --- a/thunar/thunar-shortcut.c +++ b/thunar/thunar-shortcut.c @@ -505,7 +505,11 @@ thunar_shortcut_finalize (GObject *object) g_object_unref (shortcut->file); if (shortcut->volume != NULL) - g_object_unref (shortcut->volume); + { + g_signal_handlers_disconnect_matched (shortcut->volume, G_SIGNAL_MATCH_DATA, + 0, 0, NULL, 0, shortcut); + g_object_unref (shortcut->volume); + } if (shortcut->mount != NULL) g_object_unref (shortcut->mount); @@ -1111,8 +1115,9 @@ thunar_shortcut_name_changed (ThunarShortcut *shortcut) static void thunar_shortcut_volume_changed (ThunarShortcut *shortcut) { - GIcon *icon; - gchar *name; + GMount *mount; + GIcon *icon; + gchar *name; _thunar_return_if_fail (THUNAR_IS_SHORTCUT (shortcut)); @@ -1136,6 +1141,33 @@ thunar_shortcut_volume_changed (ThunarShortcut *shortcut) icon = g_volume_get_icon (shortcut->volume); thunar_shortcut_set_icon (shortcut, icon); g_object_unref (icon); + + if (g_volume_can_eject (shortcut->volume)) + { + gtk_widget_set_visible (shortcut->action_button, TRUE); + } + else + { + /* check if we have a mount now */ + mount = g_volume_get_mount (shortcut->volume); + if (mount != NULL) + { + /* show the disconnect button if the mount is removable */ + if (g_mount_can_unmount (mount) || g_mount_can_eject (mount)) + gtk_widget_set_visible (shortcut->action_button, TRUE); + else + gtk_widget_set_visible (shortcut->action_button, FALSE); + + /* release the mount */ + g_object_unref (mount); + } + else + { + /* we neither have a removable volume nor a removabl mount, + * so hide the disconnect button */ + gtk_widget_set_visible (shortcut->action_button, FALSE); + } + } } else { @@ -1159,7 +1191,8 @@ thunar_shortcut_mount_changed (ThunarShortcut *shortcut) if (!thunar_shortcut_matches_types (shortcut, THUNAR_SHORTCUT_REGULAR_MOUNT | THUNAR_SHORTCUT_ARCHIVE_MOUNT - | THUNAR_SHORTCUT_NETWORK_MOUNT)) + | THUNAR_SHORTCUT_NETWORK_MOUNT + | THUNAR_SHORTCUT_DEVICE_MOUNT)) { return; } @@ -1210,6 +1243,7 @@ thunar_shortcut_shortcut_type_changed (ThunarShortcut *shortcut) case THUNAR_SHORTCUT_REGULAR_MOUNT: case THUNAR_SHORTCUT_ARCHIVE_MOUNT: case THUNAR_SHORTCUT_NETWORK_MOUNT: + case THUNAR_SHORTCUT_DEVICE_MOUNT: thunar_shortcut_mount_changed (shortcut); break; @@ -1643,10 +1677,22 @@ thunar_shortcut_set_volume (ThunarShortcut *shortcut, return; if (shortcut->volume != NULL) - g_object_unref (shortcut->volume); + { + /* disconnect from the volume */ + g_signal_handlers_disconnect_matched (volume, G_SIGNAL_MATCH_DATA, + 0, 0, 0, NULL, shortcut); + + g_object_unref (shortcut->volume); + } if (volume != NULL) - shortcut->volume = g_object_ref (volume); + { + shortcut->volume = g_object_ref (volume); + + /* connect to the volume */ + g_signal_connect_swapped (volume, "changed", + G_CALLBACK (thunar_shortcut_volume_changed), shortcut); + } else shortcut->volume = NULL; @@ -2086,8 +2132,6 @@ thunar_shortcut_unmount (ThunarShortcut *shortcut) _thunar_return_if_fail (THUNAR_IS_SHORTCUT (shortcut)); - g_debug ("shortcut unmount"); - /* check if we are currently mounting/ejecting something */ if (shortcut->state != THUNAR_SHORTCUT_STATE_NORMAL) { @@ -2104,13 +2148,9 @@ thunar_shortcut_unmount (ThunarShortcut *shortcut) if (shortcut->mount != NULL) { - g_debug (" have mount"); - /* only handle mounts that can be unmounted here */ if (g_mount_can_unmount (shortcut->mount)) { - g_debug (" mount can unmount"); - /* start spinning */ thunar_shortcut_set_spinning (shortcut, TRUE, THUNAR_SHORTCUT_STATE_EJECTING); @@ -2303,17 +2343,29 @@ gboolean thunar_shortcut_matches_file (ThunarShortcut *shortcut, ThunarFile *file) { + _thunar_return_val_if_fail (THUNAR_IS_SHORTCUT (shortcut), FALSE); + _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE); + + return thunar_shortcut_matches_location (shortcut, file->gfile); +} + + + +gboolean +thunar_shortcut_matches_location (ThunarShortcut *shortcut, + GFile *location) +{ gboolean matches = FALSE; GVolume *shortcut_volume; GMount *mount; GFile *mount_point; - GFile *shortcut_file; + GFile *shortcut_location; _thunar_return_val_if_fail (THUNAR_IS_SHORTCUT (shortcut), FALSE); - _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE); + _thunar_return_val_if_fail (G_IS_FILE (location), FALSE); /* get the file and volume of the view */ - shortcut_file = thunar_shortcut_get_location (shortcut); + shortcut_location = thunar_shortcut_get_location (shortcut); shortcut_volume = thunar_shortcut_get_volume (shortcut); /* check if we have a volume */ @@ -2326,7 +2378,7 @@ thunar_shortcut_matches_file (ThunarShortcut *shortcut, mount_point = g_mount_get_root (mount); /* select the shortcut if the mount point and the selected file are equal */ - if (g_file_equal (file->gfile, mount_point)) + if (g_file_equal (location, mount_point)) matches = TRUE; /* release mount point and mount */ @@ -2339,16 +2391,16 @@ thunar_shortcut_matches_file (ThunarShortcut *shortcut, mount_point = g_mount_get_root (shortcut->mount); /* select the shortcut if the mount point and the selected file are equal */ - if (g_file_equal (file->gfile, mount_point)) + if (g_file_equal (location, mount_point)) matches = TRUE; /* release mount point and mount */ g_object_unref (mount_point); } - else if (shortcut_file != NULL) + else if (shortcut_location != NULL) { /* select the shortcut if the bookmark and the selected file are equal */ - if (g_file_equal (file->gfile, shortcut_file)) + if (g_file_equal (location, shortcut_location)) matches = TRUE; } diff --git a/thunar/thunar-shortcut.h b/thunar/thunar-shortcut.h index 4cd0bc2..c28b373 100644 --- a/thunar/thunar-shortcut.h +++ b/thunar/thunar-shortcut.h @@ -90,6 +90,8 @@ void thunar_shortcut_unmount (ThunarShortcut *shor void thunar_shortcut_disconnect (ThunarShortcut *shortcut); gboolean thunar_shortcut_matches_file (ThunarShortcut *shortcut, ThunarFile *file); +gboolean thunar_shortcut_matches_location (ThunarShortcut *shortcut, + GFile *location); G_END_DECLS diff --git a/thunar/thunar-shortcuts-view.c b/thunar/thunar-shortcuts-view.c index 2f69d1e..eae6082 100644 --- a/thunar/thunar-shortcuts-view.c +++ b/thunar/thunar-shortcuts-view.c @@ -246,7 +246,8 @@ thunar_shortcuts_view_init (ThunarShortcutsView *view) THUNAR_SHORTCUT_REGULAR_VOLUME | THUNAR_SHORTCUT_EJECTABLE_VOLUME | THUNAR_SHORTCUT_REGULAR_MOUNT - | THUNAR_SHORTCUT_ARCHIVE_MOUNT); + | THUNAR_SHORTCUT_ARCHIVE_MOUNT + | THUNAR_SHORTCUT_DEVICE_MOUNT); gtk_box_pack_start (GTK_BOX (view->group_box), group, FALSE, TRUE, 0); gtk_widget_show (group); @@ -801,32 +802,44 @@ thunar_shortcuts_view_mount_added (ThunarShortcutsView *view, { /* read information from the mount */ location = g_mount_get_root (mount); - eject_icon = g_themed_icon_new ("media-eject"); - /* determine the shortcut type */ - if (g_file_has_uri_scheme (location, "file")) - shortcut_type = THUNAR_SHORTCUT_REGULAR_MOUNT; - else if (g_file_has_uri_scheme (location, "archive")) - shortcut_type = THUNAR_SHORTCUT_ARCHIVE_MOUNT; - else - shortcut_type = THUNAR_SHORTCUT_NETWORK_MOUNT; - - /* create a shortcut for the mount */ - shortcut = g_object_new (THUNAR_TYPE_SHORTCUT, - "shortcut-type", shortcut_type, - "location", location, - "mount", mount, - "eject-icon", eject_icon, - "hidden", FALSE, - "mutable", FALSE, - "persistent", FALSE, - NULL); - - /* add the shortcut to the view */ - thunar_shortcuts_view_add_shortcut (view, shortcut); + /* skip gphoto2 mounts as those are always associated with a volume, + * only add a new shortcut if we have none for the mount point yet */ + if (!g_file_has_uri_scheme (location, "gphoto2") + && thunar_shortcuts_view_has_location (view, location)) + { + /* create an eject icon */ + eject_icon = g_themed_icon_new ("media-eject"); + + /* determine the shortcut type */ + if (g_file_has_uri_scheme (location, "file")) + shortcut_type = THUNAR_SHORTCUT_REGULAR_MOUNT; + else if (g_file_has_uri_scheme (location, "archive")) + shortcut_type = THUNAR_SHORTCUT_ARCHIVE_MOUNT; + else if (g_file_has_uri_scheme (location, "gphoto2")) + shortcut_type = THUNAR_SHORTCUT_DEVICE_MOUNT; + else + shortcut_type = THUNAR_SHORTCUT_NETWORK_MOUNT; + + /* create a shortcut for the mount */ + shortcut = g_object_new (THUNAR_TYPE_SHORTCUT, + "shortcut-type", shortcut_type, + "location", location, + "mount", mount, + "eject-icon", eject_icon, + "hidden", FALSE, + "mutable", FALSE, + "persistent", FALSE, + NULL); + + /* add the shortcut to the view */ + thunar_shortcuts_view_add_shortcut (view, shortcut); + + /* release eject icon */ + g_object_unref (eject_icon); + } - /* release volume information */ - g_object_unref (eject_icon); + /* release the mount point */ g_object_unref (location); } } @@ -1360,6 +1373,32 @@ thunar_shortcuts_view_has_file (ThunarShortcutsView *view, +gboolean +thunar_shortcuts_view_has_location (ThunarShortcutsView *view, + GFile *location) +{ + gboolean has_location = FALSE; + GList *groups; + GList *iter; + + _thunar_return_val_if_fail (THUNAR_IS_SHORTCUTS_VIEW (view), FALSE); + _thunar_return_val_if_fail (G_IS_FILE (location), FALSE); + + groups = gtk_container_get_children (GTK_CONTAINER (view->group_box)); + + for (iter = groups; !has_location && iter != NULL; iter = iter->next) + { + if (thunar_shortcut_group_find_shortcut_by_location (iter->data, location, NULL)) + has_location = TRUE; + } + + g_list_free (groups); + + return has_location; +} + + + void thunar_shortcuts_view_add_file (ThunarShortcutsView *view, ThunarFile *file) diff --git a/thunar/thunar-shortcuts-view.h b/thunar/thunar-shortcuts-view.h index 73b72c4..d614bd1 100644 --- a/thunar/thunar-shortcuts-view.h +++ b/thunar/thunar-shortcuts-view.h @@ -41,6 +41,8 @@ GtkWidget *thunar_shortcuts_view_new (void) G_GNUC_MALLOC; gboolean thunar_shortcuts_view_has_file (ThunarShortcutsView *view, ThunarFile *file); +gboolean thunar_shortcuts_view_has_location (ThunarShortcutsView *view, + GFile *location); void thunar_shortcuts_view_add_file (ThunarShortcutsView *view, ThunarFile *file); void thunar_shortcuts_view_select_by_file (ThunarShortcutsView *view, _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits