[balsa/gtk4: 208/294] files: Implement libbalsa_icon_name_finder




commit d9cb6ec671e27f43a35788faa9cc0d6576882bdf
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Thu Oct 22 13:00:24 2020 -0400

    files: Implement libbalsa_icon_name_finder
    
    Returns the icon-name for a mime type; use with the "icon-name" property
    of GtkCellRendererPixbuf.

 libbalsa/files.c | 35 +++++++++++++++++++++++++++++++++++
 libbalsa/files.h |  3 +++
 2 files changed, 38 insertions(+)
---
diff --git a/libbalsa/files.c b/libbalsa/files.c
index eb6c1c391..fd16a32fe 100644
--- a/libbalsa/files.c
+++ b/libbalsa/files.c
@@ -125,3 +125,38 @@ libbalsa_icon_finder(const char        * mime_type,
 
     return gicon;
 }
+
+
+/* libbalsa_icon_name_finder:
+ *   locate a suitable icon based on 'mime-type' and/or
+ *   'filename', either of which can be NULL.  If both arguments are
+ *   non-NULL, 'mime-type' has priority.  If both are NULL, the default
+ *   "attachment" icon name will be returned.
+ */
+char *
+libbalsa_icon_name_finder(const char        * mime_type,
+                          const LibbalsaVfs * for_file,
+                          char             ** used_type)
+{
+    const char *content_type;
+    char *content_icon;
+
+    if (mime_type)
+        content_type = mime_type;
+    else if (for_file) {
+        content_type = libbalsa_vfs_get_mime_type((LibbalsaVfs *) for_file);
+    } else
+        content_type = "application/octet-stream";
+
+    content_icon = g_content_type_get_generic_icon_name(content_type);
+
+    if (content_icon == NULL) {
+        /* load the default icon */
+        content_icon = g_strdup("attachment");
+    }
+
+    if (used_type)
+        *used_type = g_strdup(content_type);
+
+    return content_icon;
+}
diff --git a/libbalsa/files.h b/libbalsa/files.h
index 5309f3408..415de7e0b 100644
--- a/libbalsa/files.h
+++ b/libbalsa/files.h
@@ -42,5 +42,8 @@ gchar *balsa_file_finder(const char * filename,
 GIcon * libbalsa_icon_finder(const char        * mime_type,
                              const LibbalsaVfs * for_file,
                              gchar            ** used_type);
+char * libbalsa_icon_name_finder(const char        * mime_type,
+                                 const LibbalsaVfs * for_file,
+                                 char             ** used_type);
 
 #endif


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