[gimp] app: add gimp_imagegile_get_gicon() which uses async API and can't block
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: add gimp_imagegile_get_gicon() which uses async API and can't block
- Date: Sun, 19 Jun 2011 21:07:30 +0000 (UTC)
commit ab607a0adcdca6fe88833937b429f731b4c4bc11
Author: Michael Natterer <mitch gimp org>
Date: Sun Jun 19 23:06:33 2011 +0200
app: add gimp_imagegile_get_gicon() which uses async API and can't block
and use it in gimp_view_renderer_imagefile_get_icon().
app/core/gimpimagefile.c | 93 +++++++++++++++++++++++++++++++
app/core/gimpimagefile.h | 1 +
app/widgets/gimpviewrendererimagefile.c | 38 +++----------
3 files changed, 102 insertions(+), 30 deletions(-)
---
diff --git a/app/core/gimpimagefile.c b/app/core/gimpimagefile.c
index daa1a0f..47d2d1e 100644
--- a/app/core/gimpimagefile.c
+++ b/app/core/gimpimagefile.c
@@ -63,6 +63,8 @@ struct _GimpImagefilePrivate
Gimp *gimp;
GimpThumbnail *thumbnail;
+ GIcon *icon;
+ GCancellable *icon_cancellable;
gchar *description;
gboolean static_desc;
@@ -73,6 +75,7 @@ struct _GimpImagefilePrivate
GimpImagefilePrivate)
+static void gimp_imagefile_dispose (GObject *object);
static void gimp_imagefile_finalize (GObject *object);
static void gimp_imagefile_name_changed (GimpObject *object);
@@ -97,6 +100,10 @@ static gboolean gimp_imagefile_save_thumb (GimpImagefile *imagefile,
static gchar * gimp_imagefile_get_description (GimpViewable *viewable,
gchar **tooltip);
+static void gimp_imagefile_icon_callback (GObject *source_object,
+ GAsyncResult *result,
+ gpointer data);
+
static void gimp_thumbnail_set_info_from_image (GimpThumbnail *thumbnail,
const gchar *mime_type,
GimpImage *image);
@@ -132,6 +139,7 @@ gimp_imagefile_class_init (GimpImagefileClass *klass)
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+ object_class->dispose = gimp_imagefile_dispose;
object_class->finalize = gimp_imagefile_finalize;
gimp_object_class->name_changed = gimp_imagefile_name_changed;
@@ -165,6 +173,21 @@ gimp_imagefile_init (GimpImagefile *imagefile)
}
static void
+gimp_imagefile_dispose (GObject *object)
+{
+ GimpImagefilePrivate *private = GET_PRIVATE (object);
+
+ if (private->icon_cancellable)
+ {
+ g_cancellable_cancel (private->icon_cancellable);
+ g_object_unref (private->icon_cancellable);
+ private->icon_cancellable = NULL;
+ }
+
+ G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
gimp_imagefile_finalize (GObject *object)
{
GimpImagefilePrivate *private = GET_PRIVATE (object);
@@ -183,6 +206,12 @@ gimp_imagefile_finalize (GObject *object)
private->thumbnail = NULL;
}
+ if (private->icon)
+ {
+ g_object_unref (private->icon);
+ private->icon = NULL;
+ }
+
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -212,6 +241,39 @@ gimp_imagefile_get_thumbnail (GimpImagefile *imagefile)
return GET_PRIVATE (imagefile)->thumbnail;
}
+GIcon *
+gimp_imagefile_get_gicon (GimpImagefile *imagefile)
+{
+ GimpImagefilePrivate *private;
+
+ g_return_val_if_fail (GIMP_IS_IMAGEFILE (imagefile), NULL);
+
+ private = GET_PRIVATE (imagefile);
+
+ if (private->icon)
+ return private->icon;
+
+ if (! private->icon_cancellable)
+ {
+ GFile *file;
+
+ file = g_file_new_for_uri (gimp_object_get_name (imagefile));
+
+ private->icon_cancellable = g_cancellable_new ();
+
+ g_file_query_info_async (file, "standard::icon",
+ G_FILE_QUERY_INFO_NONE,
+ G_PRIORITY_DEFAULT,
+ private->icon_cancellable,
+ gimp_imagefile_icon_callback,
+ imagefile);
+
+ g_object_unref (file);
+ }
+
+ return NULL;
+}
+
void
gimp_imagefile_set_mime_type (GimpImagefile *imagefile,
const gchar *mime_type)
@@ -559,6 +621,37 @@ gimp_imagefile_get_description (GimpViewable *viewable,
return basename;
}
+static void
+gimp_imagefile_icon_callback (GObject *source_object,
+ GAsyncResult *result,
+ gpointer data)
+{
+ GimpImagefile *imagefile = GIMP_IMAGEFILE (data);
+ GimpImagefilePrivate *private = GET_PRIVATE (imagefile);
+ GFile *file = G_FILE (source_object);
+ GError *error = NULL;
+ GFileInfo *file_info;
+
+ file_info = g_file_query_info_finish (file, result, &error);
+
+ if (file_info)
+ {
+ private->icon = g_object_ref (g_file_info_get_icon (file_info));
+ g_object_unref (file_info);
+ }
+
+ g_clear_error (&error);
+
+ if (private->icon_cancellable)
+ {
+ g_object_unref (private->icon_cancellable);
+ private->icon_cancellable = NULL;
+ }
+
+ if (private->icon)
+ gimp_viewable_invalidate_preview (GIMP_VIEWABLE (imagefile));
+}
+
const gchar *
gimp_imagefile_get_desc_string (GimpImagefile *imagefile)
{
diff --git a/app/core/gimpimagefile.h b/app/core/gimpimagefile.h
index d85fcaa..20a62f2 100644
--- a/app/core/gimpimagefile.h
+++ b/app/core/gimpimagefile.h
@@ -59,6 +59,7 @@ GimpImagefile * gimp_imagefile_new (Gimp *gimp,
const gchar *uri);
GimpThumbnail * gimp_imagefile_get_thumbnail (GimpImagefile *imagefile);
+GIcon * gimp_imagefile_get_gicon (GimpImagefile *imagefile);
void gimp_imagefile_set_mime_type (GimpImagefile *imagefile,
const gchar *mime_type);
diff --git a/app/widgets/gimpviewrendererimagefile.c b/app/widgets/gimpviewrendererimagefile.c
index 8c9e37e..36a62a1 100644
--- a/app/widgets/gimpviewrendererimagefile.c
+++ b/app/widgets/gimpviewrendererimagefile.c
@@ -164,42 +164,20 @@ gimp_view_renderer_imagefile_get_icon (GimpImagefile *imagefile,
if (! gimp_object_get_name (imagefile))
return NULL;
-#if 0
if (! pixbuf)
{
- GFile *file;
- GFileInfo *file_info;
+ GIcon *icon = gimp_imagefile_get_gicon (imagefile);
- file = g_file_new_for_uri (gimp_object_get_name (imagefile));
- file_info = g_file_query_info (file, "standard::icon", 0, NULL, NULL);
-
- if (file_info)
+ if (icon)
{
- GIcon *icon = g_file_info_get_icon (file_info);
-
- if (icon)
- {
- GtkIconInfo *info;
-
- info = gtk_icon_theme_lookup_by_gicon (icon_theme, icon, size, 0);
-
- if (info)
- pixbuf = gtk_icon_info_load_icon (info, NULL);
- }
- else
- {
-#ifdef GIMP_UNSTABLE
- g_printerr ("no icon for: %s\n",
- gimp_object_get_name (imagefile));
-#endif
- }
-
- g_object_unref (file_info);
- }
+ GtkIconInfo *info;
- g_object_unref (file);
+ info = gtk_icon_theme_lookup_by_gicon (icon_theme, icon, size, 0);
+
+ if (info)
+ pixbuf = gtk_icon_info_load_icon (info, NULL);
+ }
}
-#endif
if (! pixbuf && thumbnail->image_mimetype)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]