[Xfce4-commits] <thunar:master> Put remote bookmarks in places and improve icon loading.

Nick Schermer noreply at xfce.org
Sun Dec 9 18:22:01 CET 2012


Updating branch refs/heads/master
         to 6137b711dab10e2e8223e09e5d420e3cfeda5923 (commit)
       from 19e8b13ab4246bed7030b85a1982dc7244030b84 (commit)

commit 6137b711dab10e2e8223e09e5d420e3cfeda5923
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Dec 9 17:49:39 2012 +0100

    Put remote bookmarks in places and improve icon loading.

 thunar/thunar-file.c            |   41 +++++++++++++++++++++++++++---
 thunar/thunar-shortcuts-model.c |   52 +++++++++++++++++++++------------------
 thunar/thunar-shortcuts-model.h |    6 +---
 thunar/thunar-shortcuts-view.c  |    3 +-
 4 files changed, 68 insertions(+), 34 deletions(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index a2a4504..484ba23 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -3502,6 +3502,7 @@ thunar_file_get_icon_name (ThunarFile          *file,
   const gchar         *special_names[] = { NULL, "folder", NULL };
   guint                i;
   const gchar         *special_dir;
+  GFileInfo           *fileinfo;
 
   _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
   _thunar_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
@@ -3539,11 +3540,21 @@ thunar_file_get_icon_name (ThunarFile          *file,
               g_free (path);
             }
         }
-      else if (g_file_has_uri_scheme (file->gfile, "trash")
-               && !thunar_file_has_parent (file))
+      else if (!thunar_file_has_parent (file))
         {
-          special_names[0] = thunar_file_get_item_count (file) > 0 ? "user-trash-full" : "user-trash";
-          special_names[1] = "user-trash";
+          if (g_file_has_uri_scheme (file->gfile, "trash"))
+            {
+              special_names[0] = thunar_file_get_item_count (file) > 0 ? "user-trash-full" : "user-trash";
+              special_names[1] = "user-trash";
+            }
+          else if (g_file_has_uri_scheme (file->gfile, "recent"))
+            {
+              special_names[0] = "document-open-recent";
+            }
+          else if (g_file_has_uri_scheme (file->gfile, "computer"))
+            {
+              special_names[0] = "computer";
+            }
         }
 
       if (*special_names != NULL)
@@ -3552,6 +3563,26 @@ thunar_file_get_icon_name (ThunarFile          *file,
           goto check_names;
         }
     }
+  else if (thunar_file_is_mountable (file))
+    {
+      /* query the icon (computer:// backend) */
+      fileinfo = g_file_query_info (file->gfile,
+                                    G_FILE_ATTRIBUTE_STANDARD_ICON,
+                                    G_FILE_QUERY_INFO_NONE, NULL, NULL);
+      if (G_LIKELY (fileinfo != NULL))
+        {
+          /* take the icon from the info */
+          icon = g_file_info_get_icon (fileinfo);
+          if (G_LIKELY (icon != NULL))
+            g_object_ref (icon);
+
+          /* release */
+          g_object_unref (G_OBJECT (fileinfo));
+
+          if (G_LIKELY (icon != NULL))
+            goto check_icon;
+        }
+    }
 
   /* try again later */
   if (file->info == NULL)
@@ -3561,6 +3592,8 @@ thunar_file_get_icon_name (ThunarFile          *file,
   icon = g_content_type_get_icon (thunar_file_get_content_type (file));
   if (G_LIKELY (icon != NULL))
     {
+      check_icon:
+
       if (G_IS_THEMED_ICON (icon))
         {
           names = g_themed_icon_get_names (G_THEMED_ICON (icon));
diff --git a/thunar/thunar-shortcuts-model.c b/thunar/thunar-shortcuts-model.c
index 2ff7e89..94d4be1 100644
--- a/thunar/thunar-shortcuts-model.c
+++ b/thunar/thunar-shortcuts-model.c
@@ -651,8 +651,7 @@ thunar_shortcuts_model_get_value (GtkTreeModel *tree_model,
     case THUNAR_SHORTCUTS_MODEL_COLUMN_MUTABLE:
       g_value_init (value, G_TYPE_BOOLEAN);
       g_value_set_boolean (value,
-                           shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS
-                           || shortcut->group == THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS);
+                           shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS);
       break;
 
     case THUNAR_SHORTCUTS_MODEL_COLUMN_CAN_EJECT:
@@ -1175,8 +1174,7 @@ thunar_shortcuts_model_remove_shortcut (ThunarShortcutsModel *model,
       gtk_tree_path_free (path);
 
       /* check if we need to save */
-      needs_save = shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS
-                   || shortcut->group == THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS;
+      needs_save = (shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS);
 
       /* actually free the shortcut */
       thunar_shortcut_free (shortcut, model);
@@ -1189,6 +1187,22 @@ thunar_shortcuts_model_remove_shortcut (ThunarShortcutsModel *model,
 
 
 
+static gboolean
+thunar_shortcuts_model_local_file (GFile *gfile)
+{
+  _thunar_return_val_if_fail (G_IS_FILE (gfile), FALSE);
+
+  /* schemes we'd like to have as ThunarFiles in the model */
+  if (g_file_has_uri_scheme (gfile, "file")
+      || g_file_has_uri_scheme (gfile, "computer")
+      || g_file_has_uri_scheme (gfile, "recent"))
+    return TRUE;
+
+  return FALSE;
+}
+
+
+
 static void
 thunar_shortcuts_model_load_line (GFile       *file_path,
                                   const gchar *name,
@@ -1204,7 +1218,7 @@ thunar_shortcuts_model_load_line (GFile       *file_path,
   _thunar_return_if_fail (name == NULL || g_utf8_validate (name, -1, NULL));
 
   /* handle local and remove files differently */
-  if (g_file_has_uri_scheme (file_path, "file"))
+  if (thunar_shortcuts_model_local_file (file_path))
     {
       /* try to open the file corresponding to the uri */
       file = thunar_file_get (file_path, NULL);
@@ -1234,7 +1248,7 @@ thunar_shortcuts_model_load_line (GFile       *file_path,
     {
       /* create the shortcut entry */
       shortcut = g_slice_new0 (ThunarShortcut);
-      shortcut->group = THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS;
+      shortcut->group = THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS;
       shortcut->gicon = g_themed_icon_new ("folder-remote");
       shortcut->location = g_object_ref (file_path);
       shortcut->sort_id = row_num;
@@ -1364,8 +1378,7 @@ thunar_shortcuts_model_save (ThunarShortcutsModel *model)
   for (lp = model->shortcuts; lp != NULL; lp = lp->next)
     {
       shortcut = THUNAR_SHORTCUT (lp->data);
-      if (shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS
-          || shortcut->group == THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS)
+      if (shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS)
         {
           if (shortcut->file != NULL)
             uri = thunar_file_dup_uri (shortcut->file);
@@ -1733,8 +1746,7 @@ thunar_shortcuts_model_has_bookmark (ThunarShortcutsModel *model,
       shortcut = lp->data;
 
       /* only check bookmarks */
-      if (shortcut->group != THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS
-          && shortcut->group != THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS)
+      if (shortcut->group != THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS)
         continue;
 
       if (shortcut->file != NULL
@@ -1890,22 +1902,16 @@ thunar_shortcuts_model_add (ThunarShortcutsModel *model,
 
   /* create the new shortcut that will be inserted */
   shortcut = g_slice_new0 (ThunarShortcut);
+  shortcut->group = THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS;
 
-  if (THUNAR_IS_FILE (file) && thunar_file_is_local (file))
-    shortcut->file = g_object_ref (G_OBJECT (file));
-  else
-    shortcut->location = g_object_ref (G_OBJECT (location));
-
-  if (g_file_has_uri_scheme (location, "file"))
+  if (thunar_shortcuts_model_local_file (location))
     {
-      shortcut->group = THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS;
+      shortcut->file = thunar_file_get (location, NULL);
     }
   else
     {
-      shortcut->group = THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS;
+      shortcut->location = g_object_ref (G_OBJECT (location));
       shortcut->gicon = g_themed_icon_new ("folder-remote");
-
-      dst_path = NULL;
     }
 
   /* add the shortcut to the list at the given position */
@@ -2036,8 +2042,7 @@ thunar_shortcuts_model_remove (ThunarShortcutsModel *model,
   shortcut = g_list_nth_data (model->shortcuts, gtk_tree_path_get_indices (path)[0]);
 
   /* verify that the shortcut is removable */
-  _thunar_assert (shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS
-                  || shortcut->group == THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS);
+  _thunar_assert (shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS);
 
   /* remove the shortcut (using the file destroy handler) */
   thunar_shortcuts_model_remove_shortcut (model, shortcut);
@@ -2075,8 +2080,7 @@ thunar_shortcuts_model_rename (ThunarShortcutsModel *model,
   shortcut = THUNAR_SHORTCUT (((GList *) iter->user_data)->data);
 
   /* verify the shortcut */
-  _thunar_assert (shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS
-                  || shortcut->group == THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS);
+  _thunar_assert (shortcut->group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS);
 
   /* perform the rename */
   if (G_UNLIKELY (shortcut->name != NULL))
diff --git a/thunar/thunar-shortcuts-model.h b/thunar/thunar-shortcuts-model.h
index 99bb708..5164fac 100644
--- a/thunar/thunar-shortcuts-model.h
+++ b/thunar/thunar-shortcuts-model.h
@@ -65,8 +65,7 @@ typedef enum
                                        | THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS)
 #define THUNAR_SHORTCUT_GROUP_NETWORK (THUNAR_SHORTCUT_GROUP_NETWORK_HEADER \
                                        | THUNAR_SHORTCUT_GROUP_NETWORK_DEFAULT \
-                                       | THUNAR_SHORTCUT_GROUP_NETWORK_MOUNTS \
-                                       | THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS)
+                                       | THUNAR_SHORTCUT_GROUP_NETWORK_MOUNTS)
 #define THUNAR_SHORTCUT_GROUP_HEADER  (THUNAR_SHORTCUT_GROUP_DEVICES_HEADER \
                                        | THUNAR_SHORTCUT_GROUP_PLACES_HEADER \
                                        | THUNAR_SHORTCUT_GROUP_NETWORK_HEADER)
@@ -83,13 +82,12 @@ enum _ThunarShortcutGroup
   THUNAR_SHORTCUT_GROUP_PLACES_HEADER      = (1 << 4),  /* places header */
   THUNAR_SHORTCUT_GROUP_PLACES_DEFAULT     = (1 << 5),  /* home and desktop */
   THUNAR_SHORTCUT_GROUP_PLACES_TRASH       = (1 << 6),  /* trash */
-  THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS   = (1 << 7),  /* local bookmarks */
+  THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS   = (1 << 7),  /* gtk-bookmarks */
 
   /* THUNAR_SHORTCUT_GROUP_NETWORK */
   THUNAR_SHORTCUT_GROUP_NETWORK_HEADER     = (1 << 8),  /* network header */
   THUNAR_SHORTCUT_GROUP_NETWORK_DEFAULT    = (1 << 9),  /* browse network */
   THUNAR_SHORTCUT_GROUP_NETWORK_MOUNTS     = (1 << 10), /* remote ThunarDevices */
-  THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS  = (1 << 11), /* remote bookmarks */
 };
 
 
diff --git a/thunar/thunar-shortcuts-view.c b/thunar/thunar-shortcuts-view.c
index 8e4c60d..70c77bc 100644
--- a/thunar/thunar-shortcuts-view.c
+++ b/thunar/thunar-shortcuts-view.c
@@ -1233,8 +1233,7 @@ thunar_shortcuts_view_context_menu (ThunarShortcutsView *view,
     }
 
   /* append the remove menu item */
-  if (group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS
-      || group == THUNAR_SHORTCUT_GROUP_NETWORK_BOOKMARKS)
+  if (group == THUNAR_SHORTCUT_GROUP_PLACES_BOOKMARKS)
     {
       /* append a menu separator */
       item = gtk_separator_menu_item_new ();


More information about the Xfce4-commits mailing list