[Xfce4-commits] <thunar:nick/new-shortcuts-pane-model> Simplify eject and make it work for mounts.

Nick Schermer noreply at xfce.org
Fri Oct 5 23:22:01 CEST 2012


Updating branch refs/heads/nick/new-shortcuts-pane-model
         to db9592e261de7b72119b2665e2881f8a23211525 (commit)
       from f4d52f019b794b9f7917b7161a42e0fdacf58811 (commit)

commit db9592e261de7b72119b2665e2881f8a23211525
Author: Nick Schermer <nick at xfce.org>
Date:   Fri Oct 5 23:20:23 2012 +0200

    Simplify eject and make it work for mounts.

 thunar/thunar-shortcuts-model.c |   29 +++++++++++++++--------------
 thunar/thunar-shortcuts-model.h |    2 +-
 thunar/thunar-shortcuts-view.c  |   11 +++++------
 3 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/thunar/thunar-shortcuts-model.c b/thunar/thunar-shortcuts-model.c
index 3d4ba1d..de204a1 100644
--- a/thunar/thunar-shortcuts-model.c
+++ b/thunar/thunar-shortcuts-model.c
@@ -483,8 +483,8 @@ thunar_shortcuts_model_get_column_type (GtkTreeModel *tree_model,
     case THUNAR_SHORTCUTS_MODEL_COLUMN_MUTABLE:
       return G_TYPE_BOOLEAN;
 
-    case THUNAR_SHORTCUTS_MODEL_COLUMN_EJECT:
-      return G_TYPE_STRING;
+    case THUNAR_SHORTCUTS_MODEL_COLUMN_CAN_EJECT:
+      return G_TYPE_BOOLEAN;
 
     case THUNAR_SHORTCUTS_MODEL_COLUMN_GROUP:
       return G_TYPE_UINT;
@@ -550,6 +550,7 @@ thunar_shortcuts_model_get_value (GtkTreeModel *tree_model,
   ThunarFile     *file;
   GMount         *mount;
   GFile          *mount_point;
+  gboolean        can_eject;
 
   _thunar_return_if_fail (iter->stamp == THUNAR_SHORTCUTS_MODEL (tree_model)->stamp);
   _thunar_return_if_fail (THUNAR_IS_SHORTCUTS_MODEL (tree_model));
@@ -645,24 +646,24 @@ thunar_shortcuts_model_get_value (GtkTreeModel *tree_model,
       g_value_set_boolean (value, shortcut->group == THUNAR_SHORTCUT_GROUP_BOOKMARKS);
       break;
 
-    case THUNAR_SHORTCUTS_MODEL_COLUMN_EJECT:
-      g_value_init (value, G_TYPE_STRING);
+    case THUNAR_SHORTCUTS_MODEL_COLUMN_CAN_EJECT:
       if (shortcut->volume != NULL)
         {
-          if (thunar_g_volume_is_removable (shortcut->volume)
-              && thunar_g_volume_is_present (shortcut->volume))
-            {
-              g_value_set_static_string (value, "media-eject");
-            }
-          else
-            {
-              g_value_set_static_string (value, "");
-            }
+          can_eject = thunar_g_volume_is_removable (shortcut->volume)
+                        && thunar_g_volume_is_present (shortcut->volume);
+        }
+      else if (shortcut->mount != NULL)
+        {
+          can_eject = g_mount_can_eject (shortcut->mount)
+                      || g_mount_can_unmount (shortcut->mount);
         }
       else
         {
-          g_value_set_static_string (value, "");
+          can_eject = FALSE;
         }
+
+      g_value_init (value, G_TYPE_BOOLEAN);
+      g_value_set_boolean (value, can_eject);
       break;
 
     case THUNAR_SHORTCUTS_MODEL_COLUMN_GROUP:
diff --git a/thunar/thunar-shortcuts-model.h b/thunar/thunar-shortcuts-model.h
index 7be3034..ce5def4 100644
--- a/thunar/thunar-shortcuts-model.h
+++ b/thunar/thunar-shortcuts-model.h
@@ -60,7 +60,7 @@ typedef enum
   THUNAR_SHORTCUTS_MODEL_COLUMN_VOLUME,
   THUNAR_SHORTCUTS_MODEL_COLUMN_MOUNT,
   THUNAR_SHORTCUTS_MODEL_COLUMN_MUTABLE,
-  THUNAR_SHORTCUTS_MODEL_COLUMN_EJECT,
+  THUNAR_SHORTCUTS_MODEL_COLUMN_CAN_EJECT,
   THUNAR_SHORTCUTS_MODEL_COLUMN_GROUP,
   THUNAR_SHORTCUTS_MODEL_N_COLUMNS,
 } ThunarShortcutsModelColumn;
diff --git a/thunar/thunar-shortcuts-view.c b/thunar/thunar-shortcuts-view.c
index afdb213..91802d9 100644
--- a/thunar/thunar-shortcuts-view.c
+++ b/thunar/thunar-shortcuts-view.c
@@ -333,10 +333,10 @@ thunar_shortcuts_view_init (ThunarShortcutsView *view)
 
   /* allocate icon renderer for the eject symbol */
   renderer = gtk_cell_renderer_pixbuf_new ();
-  g_object_set (renderer, "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
+  g_object_set (renderer, "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, "icon-name", "media-eject", NULL);
   gtk_tree_view_column_pack_start (column, renderer, FALSE);
   gtk_tree_view_column_set_attributes (column, renderer,
-                                       "icon-name", THUNAR_SHORTCUTS_MODEL_COLUMN_EJECT,
+                                       "visible", THUNAR_SHORTCUTS_MODEL_COLUMN_CAN_EJECT,
                                        "visible", THUNAR_SHORTCUTS_MODEL_COLUMN_NOT_HEADER,
                                        NULL);
 
@@ -389,7 +389,7 @@ thunar_shortcuts_view_button_press_event (GtkWidget      *widget,
   GtkTreePath         *path;
   GtkTreeIter          iter;
   gboolean             result;
-  gchar               *eject_icon;
+  gboolean             can_eject;
 
   /* reset the pressed button state */
   view->pressed_button = -1;
@@ -432,10 +432,9 @@ thunar_shortcuts_view_button_press_event (GtkWidget      *widget,
               model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
               if (gtk_tree_model_get_iter (model, &iter, path))
                 {
-                  gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_EJECT, &eject_icon, -1);
-                  if (strlen (eject_icon) > 0)
+                  gtk_tree_model_get (model, &iter, THUNAR_SHORTCUTS_MODEL_COLUMN_CAN_EJECT, &can_eject, -1);
+                  if (can_eject)
                     view->pressed_eject_button = 1;
-                  g_free (eject_icon);
                 }
             }
 


More information about the Xfce4-commits mailing list