[Xfce4-commits] <thunar:nick/new-shortcuts-pane-model> Only show eject icon on ejectable devices.
Nick Schermer
noreply at xfce.org
Sun Oct 7 02:10:01 CEST 2012
Updating branch refs/heads/nick/new-shortcuts-pane-model
to e96bd793fbed41667d3fd8bbfc2ed231af71559d (commit)
from 08df1859847a6284cee55a54e3dab3d5bda6d42e (commit)
commit e96bd793fbed41667d3fd8bbfc2ed231af71559d
Author: Nick Schermer <nick at xfce.org>
Date: Sat Oct 6 13:23:25 2012 +0200
Only show eject icon on ejectable devices.
thunar/thunar-gio-extensions.c | 37 +++++++++++++++++++++++++
thunar/thunar-gio-extensions.h | 2 +
thunar/thunar-shortcuts-model.c | 56 +++++---------------------------------
thunar/thunar-shortcuts-view.c | 2 +-
4 files changed, 48 insertions(+), 49 deletions(-)
diff --git a/thunar/thunar-gio-extensions.c b/thunar/thunar-gio-extensions.c
index ae52cda..288d936 100644
--- a/thunar/thunar-gio-extensions.c
+++ b/thunar/thunar-gio-extensions.c
@@ -578,6 +578,43 @@ thunar_g_volume_is_present (GVolume *volume)
+/**
+ * thunar_g_volume_can_eject:
+ *
+ * If we should show the eject arrow/menu item
+ * in the interface.
+ *
+ * Check if the mount can eject/unmount or else look at
+ * the capability of the drive.
+ **/
+gboolean
+thunar_g_volume_can_eject (GVolume *volume)
+{
+ GMount *mount;
+ GDrive *drive;
+ gboolean can_eject;
+
+ mount = g_volume_get_mount (volume);
+ if (mount != NULL)
+ {
+ can_eject = g_mount_can_eject (mount) || g_mount_can_unmount (mount);
+ g_object_unref (mount);
+ return can_eject;
+ }
+
+ drive = g_volume_get_drive (volume);
+ if (drive != NULL)
+ {
+ can_eject = g_drive_can_eject (drive);
+ g_object_unref (drive);
+ return can_eject;
+ }
+
+ return FALSE;
+}
+
+
+
gboolean
thunar_g_app_info_launch (GAppInfo *info,
GFile *working_directory,
diff --git a/thunar/thunar-gio-extensions.h b/thunar/thunar-gio-extensions.h
index 7afb1dd..c7fde60 100644
--- a/thunar/thunar-gio-extensions.h
+++ b/thunar/thunar-gio-extensions.h
@@ -72,6 +72,8 @@ void thunar_g_file_list_free (GList *list);
gboolean thunar_g_volume_is_removable (GVolume *volume);
gboolean thunar_g_volume_is_mounted (GVolume *volume);
gboolean thunar_g_volume_is_present (GVolume *volume);
+gboolean
+thunar_g_volume_can_eject (GVolume *volume);
gboolean thunar_g_app_info_launch (GAppInfo *info,
GFile *working_directory,
diff --git a/thunar/thunar-shortcuts-model.c b/thunar/thunar-shortcuts-model.c
index e16f2c9..79bd03d 100644
--- a/thunar/thunar-shortcuts-model.c
+++ b/thunar/thunar-shortcuts-model.c
@@ -557,9 +557,6 @@ thunar_shortcuts_model_get_value (GtkTreeModel *tree_model,
GValue *value)
{
ThunarShortcut *shortcut;
- ThunarFile *file;
- GMount *mount;
- GFile *mount_point;
gboolean can_eject;
_thunar_return_if_fail (iter->stamp == THUNAR_SHORTCUTS_MODEL (tree_model)->stamp);
@@ -598,34 +595,7 @@ thunar_shortcuts_model_get_value (GtkTreeModel *tree_model,
case THUNAR_SHORTCUTS_MODEL_COLUMN_FILE:
g_value_init (value, THUNAR_TYPE_FILE);
-
- if (shortcut->file != NULL)
- {
- g_value_set_object (value, shortcut->file);
- }
- if (shortcut->volume != NULL
- || shortcut->mount != NULL)
- {
- /* determine the mount of the volume */
- if (shortcut->volume != NULL)
- mount = g_volume_get_mount (shortcut->volume);
- else
- mount = g_object_ref (shortcut->mount);
-
- if (G_LIKELY (mount != NULL))
- {
- /* the volume is mounted, get the mount point */
- mount_point = g_mount_get_root (mount);
-
- /* try to allocate/reference a file pointing to the mount point */
- file = thunar_file_get (mount_point, NULL);
- g_value_take_object (value, file);
-
- /* release resources */
- g_object_unref (mount_point);
- g_object_unref (mount);
- }
- }
+ g_value_set_object (value, shortcut->file);
break;
case THUNAR_SHORTCUTS_MODEL_COLUMN_GICON:
@@ -658,19 +628,11 @@ thunar_shortcuts_model_get_value (GtkTreeModel *tree_model,
case THUNAR_SHORTCUTS_MODEL_COLUMN_CAN_EJECT:
if (shortcut->volume != NULL)
- {
- can_eject = thunar_g_volume_is_removable (shortcut->volume)
- && thunar_g_volume_is_present (shortcut->volume);
- }
+ can_eject = thunar_g_volume_can_eject (shortcut->volume);
else if (shortcut->mount != NULL)
- {
- can_eject = g_mount_can_eject (shortcut->mount)
- || g_mount_can_unmount (shortcut->mount);
- }
+ can_eject = g_mount_can_eject (shortcut->mount) || g_mount_can_unmount (shortcut->mount);
else
- {
- can_eject = FALSE;
- }
+ can_eject = FALSE;
g_value_init (value, G_TYPE_BOOLEAN);
g_value_set_boolean (value, can_eject);
@@ -1550,12 +1512,10 @@ thunar_shortcut_free (ThunarShortcut *shortcut,
}
if (G_LIKELY (shortcut->volume != NULL))
- {
- g_signal_handlers_disconnect_matched (shortcut->volume,
- G_SIGNAL_MATCH_DATA, 0,
- 0, NULL, NULL, model);
- g_object_unref (shortcut->volume);
- }
+ g_object_unref (shortcut->volume);
+
+ if (G_LIKELY (shortcut->mount != NULL))
+ g_object_unref (shortcut->mount);
if (G_LIKELY (shortcut->gicon != NULL))
g_object_unref (shortcut->gicon);
diff --git a/thunar/thunar-shortcuts-view.c b/thunar/thunar-shortcuts-view.c
index 781ec92..720fb44 100644
--- a/thunar/thunar-shortcuts-view.c
+++ b/thunar/thunar-shortcuts-view.c
@@ -941,7 +941,7 @@ thunar_shortcuts_view_context_menu (ThunarShortcutsView *view,
/* append the "Disconnect" (eject + safely remove drive) item */
item = gtk_image_menu_item_new_with_mnemonic (_("_Eject"));
- gtk_widget_set_visible (item, (volume_mount != NULL && g_mount_can_eject (volume_mount)) || g_volume_can_eject (volume));
+ gtk_widget_set_visible (item, thunar_g_volume_can_eject (volume));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (thunar_shortcuts_view_disconnect), view);
More information about the Xfce4-commits
mailing list