Use emblems for some folder icons
authorColin Clark <colin.clark@cclark.uk>
Mon, 8 May 2023 15:36:15 +0000 (16:36 +0100)
committerColin Clark <colin.clark@cclark.uk>
Mon, 8 May 2023 15:36:15 +0000 (16:36 +0100)
- Use emblems for read-only, symlink and no-access folder icons
- Use standard folder icon for shortcuts and bookmarks
- Remove redundant GQview icons

n.b. It was not possible to get g_emblemed_icon_new() to work, so the
interim solution is to use gdk_pixbuf_composite()

14 files changed:
src/icons/geeqie_logo.png [deleted file]
src/icons/gq-folder-closed.png [deleted file]
src/icons/gq-folder-locked.png [deleted file]
src/icons/gq-folder-open.png [deleted file]
src/icons/gq-folder-up.png [deleted file]
src/icons/gqview_icon.png [deleted file]
src/icons/icons.gresource.xml
src/pixbuf-util.cc
src/pixbuf-util.h
src/typedefs.h
src/ui-bookmark.cc
src/view-dir-list.cc
src/view-dir-tree.cc
src/view-dir.cc

diff --git a/src/icons/geeqie_logo.png b/src/icons/geeqie_logo.png
deleted file mode 100644 (file)
index db19b16..0000000
Binary files a/src/icons/geeqie_logo.png and /dev/null differ
diff --git a/src/icons/gq-folder-closed.png b/src/icons/gq-folder-closed.png
deleted file mode 100644 (file)
index 6a181fa..0000000
Binary files a/src/icons/gq-folder-closed.png and /dev/null differ
diff --git a/src/icons/gq-folder-locked.png b/src/icons/gq-folder-locked.png
deleted file mode 100644 (file)
index 83e3948..0000000
Binary files a/src/icons/gq-folder-locked.png and /dev/null differ
diff --git a/src/icons/gq-folder-open.png b/src/icons/gq-folder-open.png
deleted file mode 100644 (file)
index 5e9675f..0000000
Binary files a/src/icons/gq-folder-open.png and /dev/null differ
diff --git a/src/icons/gq-folder-up.png b/src/icons/gq-folder-up.png
deleted file mode 100644 (file)
index a2b4382..0000000
Binary files a/src/icons/gq-folder-up.png and /dev/null differ
diff --git a/src/icons/gqview_icon.png b/src/icons/gqview_icon.png
deleted file mode 100644 (file)
index 1529f5d..0000000
Binary files a/src/icons/gqview_icon.png and /dev/null differ
index 545a0da..4d63e4f 100644 (file)
     <file>geeqie-logo.png</file>
     <file>gq-archive-file.png</file>
     <file>gq-collection.png</file>
-    <file>gq-folder-closed.png</file>
-    <file>gq-folder-locked.png</file>
-    <file>gq-folder-open.png</file>
-    <file>gq-folder-up.png</file>
     <file>gq-icon-book.png</file>
     <file>gq-icon-config.png</file>
     <file>gq-icon-draw-rectangle.png</file>
index f6ee36b..b57ab10 100644 (file)
@@ -103,10 +103,6 @@ static PixbufInline inline_pixbuf_data[] = {
        { PIXBUF_INLINE_ARCHIVE,        "gq-archive-file.png" },
        { PIXBUF_INLINE_BROKEN, "gq-sheet-broken.png" },
        { PIXBUF_INLINE_COLLECTION,     "gq-collection.png" },
-       { PIXBUF_INLINE_FOLDER_CLOSED,  "gq-folder-closed.png" },
-       { PIXBUF_INLINE_FOLDER_LOCKED,  "gq-folder-locked.png" },
-       { PIXBUF_INLINE_FOLDER_OPEN,    "gq-folder-open.png" },
-       { PIXBUF_INLINE_FOLDER_UP,      "gq-folder-up.png" },
        { PIXBUF_INLINE_ICON,   "gqview-icon.png" },
        { PIXBUF_INLINE_ICON_180,       "gq-icon-rotate-180.png" },
        { PIXBUF_INLINE_ICON_BOOK,      "gq-icon-book.png" },
index 0e787cd..45aca5b 100644 (file)
@@ -37,10 +37,6 @@ gboolean pixbuf_scale_aspect(gint req_w, gint req_h, gint old_w, gint old_h, gin
 #define PIXBUF_INLINE_ARCHIVE          "gq-archive-file"
 #define PIXBUF_INLINE_BROKEN           "gq-sheet-broken"
 #define PIXBUF_INLINE_COLLECTION       "gq-collection"
-#define PIXBUF_INLINE_FOLDER_CLOSED    "gq-folder-closed"
-#define PIXBUF_INLINE_FOLDER_LOCKED    "gq-folder-locked"
-#define PIXBUF_INLINE_FOLDER_OPEN      "gq-folder-open"
-#define PIXBUF_INLINE_FOLDER_UP                "gq-folder-up"
 #define PIXBUF_INLINE_ICON             "gqview-icon"
 #define PIXBUF_INLINE_ICON_180 "gq-icon-rotate-180"
 #define PIXBUF_INLINE_ICON_BOOK                "gq-icon-book"
index 191d437..2494fa6 100644 (file)
@@ -1090,6 +1090,7 @@ struct _PixmapFolders
        GdkPixbuf *deny;
        GdkPixbuf *parent;
        GdkPixbuf *link;
+       GdkPixbuf *read_only;
 };
 
 struct _SecureSaveInfo {
index ac2798c..162f947 100644 (file)
@@ -187,7 +187,6 @@ static void bookmark_free(BookButtonData *b)
 static gchar *bookmark_string(const gchar *name, const gchar *path, const gchar *icon)
 {
        if (!name) name = _("New Bookmark");
-       if (icon && strncmp(icon, G_DIR_SEPARATOR_S, 1) != 0) icon = NULL;
 
        if (icon)
                {
@@ -621,11 +620,26 @@ static void bookmark_populate(BookMarkData *bm)
 
                        if (b->icon)
                                {
-                               GdkPixbuf *pixbuf;
+                               GdkPixbuf *pixbuf = NULL;
                                gchar *iconl;
 
                                iconl = path_from_utf8(b->icon);
                                pixbuf = gdk_pixbuf_new_from_file(iconl, NULL);
+
+                               if (isfile(b->icon))
+                                       {
+                                       pixbuf = gdk_pixbuf_new_from_file(iconl, NULL);
+                                       }
+                               else
+                                       {
+                                       gint w, h;
+
+                                       w = h = 16;
+                                       gtk_icon_size_lookup(GTK_ICON_SIZE_BUTTON, &w, &h);
+
+                                       pixbuf = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), b->icon, w, GTK_ICON_LOOKUP_NO_SVG, NULL);
+                                       }
+
                                g_free(iconl);
                                if (pixbuf)
                                        {
@@ -643,13 +657,13 @@ static void bookmark_populate(BookMarkData *bm)
                                        }
                                else
                                        {
-                                       b->image = gtk_image_new_from_stock(GTK_STOCK_MISSING_IMAGE,
+                                       b->image = gtk_image_new_from_stock(GTK_STOCK_DIRECTORY,
                                                                            GTK_ICON_SIZE_BUTTON);
                                        }
                                }
                        else
                                {
-                               b->image = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO, GTK_ICON_SIZE_BUTTON);
+                               b->image = gtk_image_new_from_stock(GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_BUTTON);
                                }
                        gtk_box_pack_start(GTK_BOX(box), b->image, FALSE, FALSE, 0);
                        gtk_widget_show(b->image);
@@ -711,6 +725,7 @@ static void bookmark_dnd_get_data(GtkWidget *UNUSED(widget),
        GList *list = NULL;
        GList *errors = NULL;
        GList *work;
+       gchar *real_path;
        gchar **uris;
 
        if (!bm->editable) return;
@@ -735,9 +750,24 @@ static void bookmark_dnd_get_data(GtkWidget *UNUSED(widget),
                        work = work->next;
 
                        if (bm->only_directories && !isdir(path)) continue;
-                       buf = bookmark_string(filename_from_path(path), path, NULL);
+
+                       real_path = realpath(path, NULL);
+
+                       if (strstr(real_path, get_collections_dir()) && isfile(path))
+                               {
+                               buf = bookmark_string(filename_from_path(path), path, "gq-collection");
+                               }
+                       else if (isfile(path))
+                               {
+                               buf = bookmark_string(filename_from_path(path), path, GTK_STOCK_FILE);
+                               }
+                       else
+                               {
+                               buf = bookmark_string(filename_from_path(path), path, NULL);
+                               }
                        history_list_add_to_key(bm->key, buf, 0);
                        g_free(buf);
+                       g_free(real_path);
                        }
 
                string_list_free(list);
@@ -861,13 +891,33 @@ void bookmark_list_add(GtkWidget *list, const gchar *name, const gchar *path)
 {
        BookMarkData *bm;
        gchar *buf;
+       gchar *real_path;
 
        bm = static_cast<BookMarkData *>(g_object_get_data(G_OBJECT(list), BOOKMARK_DATA_KEY));
        if (!bm) return;
 
        buf = bookmark_string(name, path, NULL);
+       real_path = realpath(path, NULL);
+
+       if (strstr(real_path, get_collections_dir()) && isfile(path))
+               {
+               buf = bookmark_string(name, path, "gq-collection");
+               }
+       else
+               {
+               if (isfile(path))
+                       {
+                       buf = bookmark_string(name, path, "gtk-file");
+                       }
+               else
+                       {
+                       buf = bookmark_string(name, path, NULL);
+                       }
+               }
+
        history_list_add_to_key(bm->key, buf, 0);
        g_free(buf);
+       g_free(real_path);
 
        bookmark_populate_all(bm->key);
 }
index e12d9bc..a513a05 100644 (file)
@@ -199,6 +199,10 @@ static gboolean vdlist_populate(ViewDir *vd, gboolean clear)
                                {
                                pixbuf = vd->pf->parent;
                                }
+                       else if (!access_file(fd->path, W_OK) )
+                               {
+                               pixbuf = vd->pf->read_only;
+                               }
                        else
                                {
                                pixbuf = vd->pf->close;
index 171d52a..af0dde8 100644 (file)
@@ -391,6 +391,10 @@ static void vdtree_add_by_data(ViewDir *vd, FileData *fd, GtkTreeIter *parent)
                        {
                        pixbuf = vd->pf->link;
                        }
+               else if (!access_file(fd->path, W_OK) )
+                       {
+                       pixbuf = vd->pf->read_only;
+                       }
                else
                        {
                        pixbuf = vd->pf->close;
index 3c78906..8dc22f5 100644 (file)
 static PixmapFolders *folder_icons_new(GtkWidget *widget)
 {
        PixmapFolders *pf = g_new0(PixmapFolders, 1);
+       GError *error = NULL;
+       GdkPixbuf *icon;
+       gint scale;
 
-#if 1
        GtkIconSize size = GTK_ICON_SIZE_MENU;
 
+/** @FIXME Emblems should be attached to icons via e.g.: \n
+ * GIcon *.... \n
+ * icon = g_themed_icon_new("folder"); \n
+ * emblem_icon = g_themed_icon_new("emblem_symbolic_link"); \n
+ * emblem = g_emblem_new(emblem_icon); \n
+ * emblemed = g_emblemed_icon_new(icon, emblem); \n
+ * gtk_icon_info_load_icon(icon_info, NULL) \n
+ * But there does not seem to be a way to get GtkIconInfo from a GIcon
+ */
+
        /* Attempt to use stock gtk icons */
        pf->close  = gtk_widget_render_icon(widget, GTK_STOCK_DIRECTORY, size, NULL);
        pf->open   = gtk_widget_render_icon(widget, GTK_STOCK_OPEN, size, NULL);
-       pf->deny   = gtk_widget_render_icon(widget, GTK_STOCK_STOP, size, NULL);
        pf->parent = gtk_widget_render_icon(widget, GTK_STOCK_GO_UP, size, NULL);
-       pf->link = gtk_widget_render_icon(widget, GTK_STOCK_REDO, size, NULL); /** @FIXME this is not a suitable icon */
-#else
-       /* GQView legacy icons */
-       pf->close  = pixbuf_inline(PIXBUF_INLINE_FOLDER_CLOSED);
-       pf->open   = pixbuf_inline(PIXBUF_INLINE_FOLDER_OPEN);
-       pf->deny   = pixbuf_inline(PIXBUF_INLINE_FOLDER_LOCKED);
-       pf->parent = pixbuf_inline(PIXBUF_INLINE_FOLDER_UP);
-#endif
+
+       if (gtk_icon_theme_has_icon(gtk_icon_theme_get_default(), "emblem-unreadable"))
+               {
+               icon = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), "emblem-unreadable", size, GTK_ICON_LOOKUP_USE_BUILTIN, &error);
+               if (error)
+                       {
+                       log_printf("Error: %s\n", error->message);
+                       g_error_free(error);
+
+                       pf->deny = gdk_pixbuf_copy(gtk_widget_render_icon(widget, GTK_STOCK_STOP, size, NULL));
+                       }
+               else
+                       {
+                       pf->deny = gdk_pixbuf_copy(gtk_widget_render_icon(widget, GTK_STOCK_DIRECTORY, size, NULL));
+                       scale = gdk_pixbuf_get_width(icon) / 2;
+                       gdk_pixbuf_composite(icon, pf->deny, scale, scale, scale, scale, scale, scale, 0.5, 0.5, GDK_INTERP_HYPER, 255);
+
+                       }
+               g_object_unref(icon);
+               }
+       else
+               {
+               pf->deny = gdk_pixbuf_copy(gtk_widget_render_icon(widget, GTK_STOCK_STOP, size, NULL));
+               }
+
+       if (gtk_icon_theme_has_icon(gtk_icon_theme_get_default(), "emblem-symbolic-link"))
+               {
+               icon = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), "emblem-symbolic-link", size, GTK_ICON_LOOKUP_USE_BUILTIN, &error);
+               if (error)
+                       {
+                       log_printf("Error: %s\n", error->message);
+                       g_error_free(error);
+
+                       pf->link = gdk_pixbuf_copy(gtk_widget_render_icon(widget, GTK_STOCK_REDO, size, NULL));
+                       }
+               else
+                       {
+                       pf->link = gdk_pixbuf_copy(gtk_widget_render_icon(widget, GTK_STOCK_DIRECTORY, size, NULL));
+                       scale = gdk_pixbuf_get_width(icon) / 2;
+                       gdk_pixbuf_composite(icon, pf->link, scale, scale, scale, scale, scale, scale, 0.5, 0.5, GDK_INTERP_HYPER, 255);
+                       }
+               g_object_unref(icon);
+               }
+       else
+               {
+               pf->link = gdk_pixbuf_copy(gtk_widget_render_icon(widget, GTK_STOCK_REDO, size, NULL));
+               }
+
+       pf->read_only = gdk_pixbuf_copy(gtk_widget_render_icon(widget, GTK_STOCK_DIRECTORY, size, NULL));
+
+       if (gtk_icon_theme_has_icon(gtk_icon_theme_get_default(), "emblem-readonly"))
+               {
+               icon = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), "emblem-readonly", size, GTK_ICON_LOOKUP_USE_BUILTIN, &error);
+               if (error)
+                       {
+                       log_printf("Error: %s\n", error->message);
+                       g_error_free(error);
+
+                       pf->read_only = gdk_pixbuf_copy(gtk_widget_render_icon(widget, GTK_STOCK_DIRECTORY, size, NULL));
+                       }
+               else
+                       {
+                       gint scale = gdk_pixbuf_get_width(icon) / 2;
+                       gdk_pixbuf_composite(icon, pf->read_only, scale, scale, scale, scale, scale, scale, 0.5, 0.5, GDK_INTERP_HYPER, 255);
+
+                       }
+               g_object_unref(icon);
+               }
+
        return pf;
 }
 
@@ -70,6 +142,7 @@ static void folder_icons_free(PixmapFolders *pf)
        g_object_unref(pf->deny);
        g_object_unref(pf->parent);
        g_object_unref(pf->link);
+       g_object_unref(pf->read_only);
 
        g_free(pf);
 }