* cleanup icon handling a bit
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Wed, 11 Apr 2007 07:21:39 +0000 (07:21 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Wed, 11 Apr 2007 07:21:39 +0000 (07:21 +0000)
pmo-trunk-r1538

src/gnome/modest-platform.c
src/maemo/modest-platform.c
src/modest-platform.h
src/widgets/modest-folder-view.c
src/widgets/modest-header-view-render.c

index 1877709..de8ae08 100644 (file)
@@ -77,3 +77,24 @@ modest_platform_get_file_icon_name (const gchar* name, const gchar* mime_type,
 
        return icon_name;
 }
+
+
+GdkPixbuf*
+modest_platform_get_icon (const gchar *name)
+{
+       GError *err = NULL;
+       GdkPixbuf* pixbuf;
+
+       g_return_val_if_fail (name, NULL);
+
+       pixbuf = gdk_pixbuf_new_from_file (name, &err);
+
+       if (!pixbuf) {
+               g_printerr ("modest: error while loading icon '%s': %s\n",
+                           name, err->message);
+               g_error_free (err);
+       }
+       
+       return pixbuf;
+}
+
index 01a908b..0456da6 100644 (file)
@@ -129,3 +129,27 @@ modest_platform_get_file_icon_name (const gchar* name, const gchar* mime_type,
 
        return icon_name;
 }
+
+
+GdkPixbuf*
+modest_platform_get_icon (const gchar *name)
+{
+       GError *err = NULL;
+       GdkPixbuf* pixbuf;
+       GtkIconTheme *current_theme;
+
+       g_return_val_if_fail (name, NULL);
+
+       current_theme = gtk_icon_theme_get_default ();
+       pixbuf = gtk_icon_theme_load_icon (current_theme, name, 26,
+                                          GTK_ICON_LOOKUP_NO_SVG,
+                                          &err);
+       if (!pixbuf) {
+               g_printerr ("modest: error while loading icon '%s': %s\n",
+                           name, err->message);
+               g_error_free (err);
+       }
+       
+       return pixbuf;
+}
+
index e4d4b15..f839513 100644 (file)
@@ -31,6 +31,7 @@
 #define __MODEST_PLATFORM_H__
 
 #include <glib.h>
+#include <gtk/gtk.h>
 #include <tny-device.h>
 
 /**
@@ -54,7 +55,7 @@ TnyDevice*  modest_platform_get_new_device (void);
 
 
 /**
- * modest_platform_get_file_icon:
+ * modest_platform_get_file_icon_name:
  * @name: the name of the file, or NULL
  * @mime_type: the mime-type, or NULL
  * @effective_mime_type: out-param which receives the 'effective mime-type', ie., the mime type
@@ -72,4 +73,14 @@ TnyDevice*  modest_platform_get_new_device (void);
 gchar*  modest_platform_get_file_icon_name (const gchar* name, const gchar* mime_type,
                                            gchar **effective_mime_type);
 
+/**
+ * modest_platform_get_icon:
+ * @name: the name of the icon
+ *
+ * this function returns an icon, or NULL in case of error 
+ */
+GdkPixbuf* modest_platform_get_icon (const gchar *name);
+
+
+
 #endif /* __MODEST_PLATFORM_UTILS_H__ */
index c2c3760..bfce187 100644 (file)
@@ -48,6 +48,7 @@
 #include <modest-runtime.h>
 #include "modest-folder-view.h"
 #include <modest-dnd.h>
+#include <modest-platform.h>
 
 /* 'private'/'protected' functions */
 static void modest_folder_view_class_init  (ModestFolderViewClass *klass);
@@ -243,33 +244,6 @@ text_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
 }
 
 
-static GdkPixbuf*
-get_cached_icon (const gchar *name)
-{
-       GError *err = NULL;
-       GdkPixbuf* pixbuf;
-               
-#ifdef MODEST_PLATFORM_GNOME  
-       pixbuf = gdk_pixbuf_new_from_file (name, &err);
-#else
-       GtkIconTheme *current_theme;
-       current_theme = gtk_icon_theme_get_default ();
-       pixbuf = gtk_icon_theme_load_icon (current_theme,
-                                          name,
-                                          26,
-                                          GTK_ICON_LOOKUP_NO_SVG,
-                                          &err);
-#endif /*MODEST_PLATFORM_GNOME*/
-
-       if (!pixbuf) {
-               g_printerr ("modest: error in icon factory while loading '%s': %s\n",
-                           name, err->message);
-               g_error_free (err);
-       }
-       
-       return pixbuf;
-}
-
 
 static void
 icon_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
@@ -296,29 +270,29 @@ icon_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
 
        switch (type) {
        case TNY_FOLDER_TYPE_ROOT:
-               pixbuf = get_cached_icon (MODEST_FOLDER_ICON_ACCOUNT);
+               pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_ACCOUNT);
                 break;
        case TNY_FOLDER_TYPE_INBOX:
-                pixbuf = get_cached_icon (MODEST_FOLDER_ICON_INBOX);
+                pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_INBOX);
                 break;
         case TNY_FOLDER_TYPE_OUTBOX:
-                pixbuf = get_cached_icon (MODEST_FOLDER_ICON_OUTBOX);
+                pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_OUTBOX);
                 break;
         case TNY_FOLDER_TYPE_JUNK:
-                pixbuf = get_cached_icon (MODEST_FOLDER_ICON_JUNK);
+                pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_JUNK);
                 break;
         case TNY_FOLDER_TYPE_SENT:
-                pixbuf = get_cached_icon (MODEST_FOLDER_ICON_SENT);
+                pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_SENT);
                 break;
        case TNY_FOLDER_TYPE_TRASH:
-               pixbuf = get_cached_icon (MODEST_FOLDER_ICON_TRASH);
+               pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_TRASH);
                 break;
        case TNY_FOLDER_TYPE_DRAFTS:
-               pixbuf = get_cached_icon (MODEST_FOLDER_ICON_DRAFTS);
+               pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_DRAFTS);
                 break;
        case TNY_FOLDER_TYPE_NORMAL:
         default:
-                pixbuf = get_cached_icon (MODEST_FOLDER_ICON_NORMAL);
+                pixbuf = modest_platform_get_icon (MODEST_FOLDER_ICON_NORMAL);
                break;
         }
        g_object_set (rendobj, "pixbuf", pixbuf, NULL);
index 70bcb2e..cdb94ae 100644 (file)
 #include <modest-text-utils.h>
 #include <modest-runtime.h>
 #include <glib/gi18n.h>
+#include <modest-platform.h>
 
 
 static GdkPixbuf*
-get_cached_icon (const gchar *name)
-{
-       GError *err = NULL;
-       GdkPixbuf* pixbuf;
-               
-#ifdef MODEST_PLATFORM_GNOME  
-       pixbuf = gdk_pixbuf_new_from_file (name, &err);
-#else
-       GtkIconTheme *current_theme;
-       current_theme = gtk_icon_theme_get_default ();
-       pixbuf = gtk_icon_theme_load_icon (current_theme,
-                                          name,
-                                          26,
-                                          GTK_ICON_LOOKUP_NO_SVG,
-                                          &err);
-#endif /*MODEST_PLATFORM_GNOME*/
-
-       if (!pixbuf) {
-               g_printerr ("modest: error in icon factory while loading '%s': %s\n",
-                           name, err->message);
-               g_error_free (err);
-       }
-       
-       return pixbuf;
-}
-
-
-/*
- * optimization
- */
-static GdkPixbuf*
 get_pixbuf_for_flag (TnyHeaderFlags flag)
 {
        /* optimization */
@@ -78,19 +48,19 @@ get_pixbuf_for_flag (TnyHeaderFlags flag)
        switch (flag) {
        case TNY_HEADER_FLAG_DELETED:
                if (G_UNLIKELY(!deleted_pixbuf))
-                       deleted_pixbuf = get_cached_icon (MODEST_HEADER_ICON_DELETED);
+                       deleted_pixbuf = modest_platform_get_icon (MODEST_HEADER_ICON_DELETED);
                return deleted_pixbuf;
        case TNY_HEADER_FLAG_SEEN:
                if (G_UNLIKELY(!seen_pixbuf))
-                       seen_pixbuf = get_cached_icon (MODEST_HEADER_ICON_READ);
+                       seen_pixbuf = modest_platform_get_icon (MODEST_HEADER_ICON_READ);
                return seen_pixbuf;
        case TNY_HEADER_FLAG_ATTACHMENTS:
                if (G_UNLIKELY(!attachments_pixbuf))
-                       attachments_pixbuf = get_cached_icon (MODEST_HEADER_ICON_ATTACH);
+                       attachments_pixbuf = modest_platform_get_icon (MODEST_HEADER_ICON_ATTACH);
                return attachments_pixbuf;
        default:
                if (G_UNLIKELY(!unread_pixbuf))
-                       unread_pixbuf = get_cached_icon (MODEST_HEADER_ICON_UNREAD);
+                       unread_pixbuf = modest_platform_get_icon (MODEST_HEADER_ICON_UNREAD);
                return unread_pixbuf;
        }
 }