From: Dirk-Jan C. Binnema Date: Wed, 11 Apr 2007 07:21:39 +0000 (+0000) Subject: * cleanup icon handling a bit X-Git-Tag: git_migration_finished~3914 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=6754695adb4d12d3c2db5f7f819d2d7a78c07334 * cleanup icon handling a bit pmo-trunk-r1538 --- diff --git a/src/gnome/modest-platform.c b/src/gnome/modest-platform.c index 1877709..de8ae08 100644 --- a/src/gnome/modest-platform.c +++ b/src/gnome/modest-platform.c @@ -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; +} + diff --git a/src/maemo/modest-platform.c b/src/maemo/modest-platform.c index 01a908b..0456da6 100644 --- a/src/maemo/modest-platform.c +++ b/src/maemo/modest-platform.c @@ -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; +} + diff --git a/src/modest-platform.h b/src/modest-platform.h index e4d4b15..f839513 100644 --- a/src/modest-platform.h +++ b/src/modest-platform.h @@ -31,6 +31,7 @@ #define __MODEST_PLATFORM_H__ #include +#include #include /** @@ -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__ */ diff --git a/src/widgets/modest-folder-view.c b/src/widgets/modest-folder-view.c index c2c3760..bfce187 100644 --- a/src/widgets/modest-folder-view.c +++ b/src/widgets/modest-folder-view.c @@ -48,6 +48,7 @@ #include #include "modest-folder-view.h" #include +#include /* '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); diff --git a/src/widgets/modest-header-view-render.c b/src/widgets/modest-header-view-render.c index 70bcb2e..cdb94ae 100644 --- a/src/widgets/modest-header-view-render.c +++ b/src/widgets/modest-header-view-render.c @@ -33,40 +33,10 @@ #include #include #include +#include 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; } }