From 9216c7dfa8478d7428d57d6d01bb0f1088577372 Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Fri, 25 Nov 2005 06:09:47 +0000 Subject: [PATCH] r984@localhost: muntyan | 2005-11-24 18:06:00 -0600 moo_get_icon_for_path() --- moo/mooutils/moofileview/moofile.c | 50 ++++++++++++++++++++++++++---- moo/mooutils/moofileview/moofile.h | 5 +++ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/moo/mooutils/moofileview/moofile.c b/moo/mooutils/moofileview/moofile.c index 8ff8221d..8faab051 100644 --- a/moo/mooutils/moofileview/moofile.c +++ b/moo/mooutils/moofileview/moofile.c @@ -126,6 +126,9 @@ static guint8 get_blank_icon (void); static GdkPixbuf *render_icon (const MooFile *file, GtkWidget *widget, GtkIconSize size); +static GdkPixbuf *render_icon_for_path (const char *path, + GtkWidget *widget, + GtkIconSize size); #define FILE_PATH(folder,file) g_build_filename (folder->priv->path, file->name, NULL) #define MAKE_PATH(dirname,file) g_build_filename (dirname, file->name, NULL) @@ -1325,15 +1328,27 @@ gconstpointer moo_file_get_stat (const MooFile *file) #endif -GdkPixbuf *moo_file_get_icon (const MooFile *file, - GtkWidget *widget, - GtkIconSize size) +GdkPixbuf * +moo_file_get_icon (const MooFile *file, + GtkWidget *widget, + GtkIconSize size) { g_return_val_if_fail (file != NULL, NULL); + g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); return render_icon (file, widget, size); } +GdkPixbuf * +moo_get_icon_for_path (const char *path, + GtkWidget *widget, + GtkIconSize size) +{ + g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); + return render_icon_for_path (path, widget, size); +} + + #ifndef __WIN32__ const char *moo_file_link_get_target (const MooFile *file) { @@ -1822,9 +1837,10 @@ static GdkPixbuf *_render_icon (MooIconType icon, } -static GdkPixbuf *render_icon (const MooFile *file, - GtkWidget *widget, - GtkIconSize size) +static GdkPixbuf * +render_icon (const MooFile *file, + GtkWidget *widget, + GtkIconSize size) { GdkPixbuf *pixbuf = _render_icon (file->icon, file->mime_type, _get_icon_flags (file), widget, size); @@ -1833,6 +1849,28 @@ static GdkPixbuf *render_icon (const MooFile *file, } +static GdkPixbuf * +render_icon_for_path (const char *path, + GtkWidget *widget, + GtkIconSize size) +{ + MooIconType icon = MOO_ICON_BLANK; + const char *mime_type = xdg_mime_type_unknown; + + if (path) + { + mime_type = xdg_mime_get_mime_type_for_file (path); + + if (mime_type != xdg_mime_type_unknown) + { + icon = MOO_ICON_MIME; + } + } + + return _render_icon (icon, mime_type, 0, widget, size); +} + + static GdkPixbuf *_create_icon_simple (GtkIconTheme *icon_theme, MooIconType icon, const char *mime_type, diff --git a/moo/mooutils/moofileview/moofile.h b/moo/mooutils/moofileview/moofile.h index 5d41bc8c..0d8c87f7 100644 --- a/moo/mooutils/moofileview/moofile.h +++ b/moo/mooutils/moofileview/moofile.h @@ -155,9 +155,14 @@ gboolean moo_file_test (const MooFile *file, const char *moo_file_name (const MooFile *file); const char *moo_file_get_mime_type (const MooFile *file); + +/* returned pixbuf is owned by icon cache */ GdkPixbuf *moo_file_get_icon (const MooFile *file, GtkWidget *widget, GtkIconSize size); +GdkPixbuf *moo_get_icon_for_path (const char *path, + GtkWidget *widget, + GtkIconSize size); const char *moo_file_display_name (const MooFile *file); const char *moo_file_collation_key (const MooFile *file);