[gthumb] gThumb hangs when some mount point is unavailable



commit bfdd47305d9d91e6f32776e6f1614e30118525ef
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Fri Nov 29 19:04:46 2019 +0100

    gThumb hangs when some mount point is unavailable
    
    Do not query mount points and bookmark/history entries
    on start-up.
    
    See https://gitlab.gnome.org/GNOME/gthumb/issues/75

 extensions/bookmarks/callbacks.c |  6 +----
 gthumb/glib-utils.c              | 21 +++++++++++++++++
 gthumb/glib-utils.h              |  1 +
 gthumb/gth-browser.c             | 51 ++++++++++++++++++++++++++++++----------
 gthumb/gth-browser.h             |  1 +
 gthumb/gth-file-source-vfs.c     | 13 +++++-----
 6 files changed, 69 insertions(+), 24 deletions(-)
---
diff --git a/extensions/bookmarks/callbacks.c b/extensions/bookmarks/callbacks.c
index 25250a74..a94f0b15 100644
--- a/extensions/bookmarks/callbacks.c
+++ b/extensions/bookmarks/callbacks.c
@@ -118,10 +118,6 @@ update_system_bookmark_list_from_content (GthBrowser *browser,
                file = g_file_new_for_uri (uri);
                first_space = strchr (lines[i], ' ');
                name = (first_space != NULL) ? g_strdup (first_space + 1) : NULL;
-               if (name == NULL)
-                       name = _g_file_get_display_name (file);
-               if (name == NULL)
-                       name = g_file_get_parse_name (file);
                item = _g_menu_item_new_for_file (file, name);
                g_menu_item_set_action_and_target (item, "win.go-to-location", "s", uri);
                g_menu_append_item (data->system_bookmarks_menu, item);
@@ -282,7 +278,7 @@ _gth_browser_update_entry_point_list (GthBrowser *browser)
                GMenuItem   *item;
                char        *uri;
 
-               item = _g_menu_item_new_for_file (file_data->file, NULL);
+               item = _g_menu_item_new_for_file_data (file_data);
                uri = g_file_get_uri (file_data->file);
                g_menu_item_set_action_and_target (item, "win.go-to-location", "s", uri);
                g_menu_append_item (data->entry_points_menu, item);
diff --git a/gthumb/glib-utils.c b/gthumb/glib-utils.c
index 13777548..e2c179f1 100644
--- a/gthumb/glib-utils.c
+++ b/gthumb/glib-utils.c
@@ -2126,6 +2126,27 @@ _g_file_equal (GFile *file1,
 }
 
 
+char *
+_g_file_get_display_name_no_io (GFile *file)
+{
+       char       *name;
+       char       *uri;
+       const char *basename;
+
+       name = NULL;
+       uri = g_file_get_uri (file);
+       basename = _g_uri_get_basename (uri);
+       if (basename != NULL)
+               name = g_uri_unescape_string (basename, NULL);
+       else
+               name = g_strdup ("/");
+
+       g_free (uri);
+
+       return name;
+}
+
+
 char *
 _g_file_get_display_name (GFile *file)
 {
diff --git a/gthumb/glib-utils.h b/gthumb/glib-utils.h
index 4cbc5872..17472263 100644
--- a/gthumb/glib-utils.h
+++ b/gthumb/glib-utils.h
@@ -280,6 +280,7 @@ GFile *         _g_file_new_for_display_name     (const char *base_uri,
                                                  const char *extension);
 gboolean        _g_file_equal                    (GFile      *file1,
                                                  GFile      *file2);
+char *          _g_file_get_display_name_no_io   (GFile      *file);
 char *          _g_file_get_display_name         (GFile      *file);
 GFileType      _g_file_get_standard_type        (GFile      *file);
 GFile *         _g_file_get_destination          (GFile      *source,
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 013a63ab..aaca5182 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -39,6 +39,7 @@
 #include "gth-file-list.h"
 #include "gth-file-view.h"
 #include "gth-file-selection.h"
+#include "gth-file-source-vfs.h"
 #include "gth-file-tool.h"
 #include "gth-filter.h"
 #include "gth-filterbar.h"
@@ -6939,31 +6940,55 @@ _g_menu_item_new_for_file (GFile      *file,
                           const char *custom_label)
 {
        GMenuItem     *item;
+       gboolean       updated;
        GthFileSource *file_source;
-       GFileInfo     *info;
 
        item = g_menu_item_new (NULL, NULL);
+
+       updated = FALSE;
        file_source = gth_main_get_file_source (file);
-       info = gth_file_source_get_file_info (file_source, file, GFILE_DISPLAY_ATTRIBUTES);
-       if (info != NULL) {
-               g_menu_item_set_label (item, (custom_label != NULL) ? custom_label : 
g_file_info_get_display_name (info));
-               g_menu_item_set_icon (item, g_file_info_get_symbolic_icon (info));
+       if (! GTH_IS_FILE_SOURCE_VFS (file_source)) {
+               GFileInfo *info;
+
+               info = gth_file_source_get_file_info (file_source, file, GFILE_DISPLAY_ATTRIBUTES);
+               if (info != NULL) {
+                       g_menu_item_set_label (item, (custom_label != NULL) ? custom_label : 
g_file_info_get_display_name (info));
+                       g_menu_item_set_icon (item, g_file_info_get_symbolic_icon (info));
+                       updated = TRUE;
+               }
+
+               _g_object_unref (info);
        }
-       else {
-               char  *label;
+
+       if (! updated) {
+               char  *name;
+               char  *uri;
                GIcon *icon;
 
-               label = _g_file_get_display_name (file);
-               icon = _g_file_get_symbolic_icon (file);
-               g_menu_item_set_label (item, (custom_label != NULL) ? custom_label : label);
+               name = _g_file_get_display_name_no_io (file);
+               uri = g_file_get_uri (file);
+               icon = g_themed_icon_new (g_str_has_prefix (uri, "file://") ? "folder-symbolic" : 
"folder-remote-symbolic");
+               g_menu_item_set_label (item, (custom_label != NULL) ? custom_label : name);
                g_menu_item_set_icon (item, icon);
 
-               g_object_unref (icon);
-               g_free (label);
+               g_free (uri);
+               g_free (name);
        }
 
-       _g_object_unref (info);
        _g_object_unref (file_source);
 
        return item;
 }
+
+
+GMenuItem *
+_g_menu_item_new_for_file_data (GthFileData *file_data)
+{
+       GMenuItem *item;
+
+       item = g_menu_item_new (NULL, NULL);
+       g_menu_item_set_label (item, g_file_info_get_display_name (file_data->info));
+       g_menu_item_set_icon (item, g_file_info_get_symbolic_icon (file_data->info));
+
+       return item;
+}
diff --git a/gthumb/gth-browser.h b/gthumb/gth-browser.h
index 17890e20..34462125 100644
--- a/gthumb/gth-browser.h
+++ b/gthumb/gth-browser.h
@@ -291,6 +291,7 @@ void             gth_browser_keep_mouse_visible     (GthBrowser           *browser,
 
 GMenuItem *    _g_menu_item_new_for_file           (GFile            *file,
                                                     const char       *custom_label);
+GMenuItem *    _g_menu_item_new_for_file_data      (GthFileData      *file_data);
 
 G_END_DECLS
 
diff --git a/gthumb/gth-file-source-vfs.c b/gthumb/gth-file-source-vfs.c
index dcc1c4e7..3780c581 100644
--- a/gthumb/gth-file-source-vfs.c
+++ b/gthumb/gth-file-source-vfs.c
@@ -151,12 +151,6 @@ gth_file_source_vfs_get_entry_points (GthFileSource *file_source)
                        continue;
                }
 
-               info = g_file_query_info (file, GFILE_BASIC_ATTRIBUTES ",access::*", G_FILE_QUERY_INFO_NONE, 
NULL, NULL);
-               if (info == NULL) {
-                       g_object_unref (file);
-                       continue;
-               }
-
                icon = g_mount_get_symbolic_icon (mount);
                name = g_mount_get_name (mount);
 
@@ -174,8 +168,15 @@ gth_file_source_vfs_get_entry_points (GthFileSource *file_source)
                        g_free (drive_name);
                }
 
+               info = g_file_info_new ();
+               g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY);
+               g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ, TRUE);
+               g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, FALSE);
+               g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE, FALSE);
+               g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH, FALSE);
                g_file_info_set_symbolic_icon (info, icon);
                g_file_info_set_display_name (info, name);
+               g_file_info_set_name (info, name);
 
                list = g_list_append (list, gth_file_data_new (file, info));
                g_object_unref (info);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]