[gnome-photos] base-item: Add some rudimentary icon creation code



commit c9393092699d67792110769ac989457365b9729b
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Apr 30 16:08:16 2012 +0200

    base-item: Add some rudimentary icon creation code
    
    Added gdk-pixbuf-2.0 to the list of build requirements.

 configure.ac           |    1 +
 src/Makefile.am        |    2 +
 src/photos-base-item.c |   64 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/photos-base-item.h |    3 ++
 4 files changed, 70 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0494c49..c17df5d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,7 @@ LT_INIT
 
 PKG_CHECK_MODULES(CLUTTER, [clutter-1.0])
 PKG_CHECK_MODULES(CLUTTER_GTK, [clutter-gtk-1.0])
+PKG_CHECK_MODULES(GDK_PIXBUF, [gdk-pixbuf-2.0])
 PKG_CHECK_MODULES(GLIB, [glib-2.0 >= $GLIB_MIN_VERSION])
 PKG_CHECK_MODULES(GIO, [gio-2.0])
 PKG_CHECK_MODULES(GTK, [gtk+-3.0])
diff --git a/src/Makefile.am b/src/Makefile.am
index 491fbc0..8bc6a13 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -73,6 +73,7 @@ AM_CPPFLAGS = \
 	-DPACKAGE_LOCALE_DIR=\""${datadir}/locale"\" \
 	$(CLUTTER_CFLAGS) \
 	$(CLUTTER_GTK_CFLAGS) \
+	$(GDK_PIXBUF_CFLAGS) \
 	$(GIO_CFLAGS) \
 	$(GLIB_CFLAGS) \
 	$(GTK_CFLAGS) \
@@ -84,6 +85,7 @@ gnome_photos_LDFLAGS =
 gnome_photos_LDADD = \
 	$(CLUTTER_LIBS) \
 	$(CLUTTER_GTK_LIBS) \
+	$(GDK_PIXBUF_LIBS) \
 	$(GIO_LIBS) \
 	$(GLIB_LIBS) \
 	$(GTK_LIBS) \
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index cca3238..17cff68 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -32,6 +32,7 @@
 
 struct _PhotosBaseItemPrivate
 {
+  GdkPixbuf *icon;
   gboolean favorite;
   gchar *author;
   gchar *id;
@@ -56,6 +57,47 @@ G_DEFINE_TYPE (PhotosBaseItem, photos_base_item, G_TYPE_OBJECT);
 
 
 static void
+photos_base_item_check_effects_and_update_info (PhotosBaseItem *self)
+{
+}
+
+
+static void
+photos_base_item_update_icon_from_type (PhotosBaseItem *self)
+{
+  PhotosBaseItemPrivate *priv = self->priv;
+  GIcon *icon = NULL;
+  GtkIconInfo *info;
+  GtkIconTheme *theme;
+
+  if (priv->mime_type != NULL)
+    icon = g_content_type_get_icon (priv->mime_type);
+
+  /* TODO: Get icon from RDF type */
+
+  theme = gtk_icon_theme_get_default ();
+  info = gtk_icon_theme_lookup_by_gicon (theme,
+                                         icon,
+                                         128,
+                                         GTK_ICON_LOOKUP_FORCE_SIZE | GTK_ICON_LOOKUP_GENERIC_FALLBACK);
+  if (info != NULL)
+    {
+      priv->icon = gtk_icon_info_load_icon (info, NULL);
+      /* TODO: use a GError */
+    }
+
+  photos_base_item_check_effects_and_update_info (self);
+}
+
+
+static void
+photos_base_item_refresh_icon (PhotosBaseItem *self)
+{
+  photos_base_item_update_icon_from_type (self);
+}
+
+
+static void
 photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor *cursor)
 {
   PhotosBaseItemPrivate *priv = self->priv;
@@ -89,6 +131,8 @@ photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor
       title = photos_utils_filename_strip_extension (title);
     }
   priv->name = g_strdup (title);
+
+  photos_base_item_refresh_icon (self);
 }
 
 
@@ -105,6 +149,18 @@ photos_base_item_update_type_description (PhotosBaseItem *self)
 
 
 static void
+photos_base_item_dispose (GObject *object)
+{
+  PhotosBaseItem *self = PHOTOS_BASE_ITEM (object);
+  PhotosBaseItemPrivate *priv = self->priv;
+
+  g_clear_object (&priv->icon);
+
+  G_OBJECT_CLASS (photos_base_item_parent_class)->dispose (object);
+}
+
+
+static void
 photos_base_item_finalize (GObject *object)
 {
   PhotosBaseItem *self = PHOTOS_BASE_ITEM (object);
@@ -155,6 +211,7 @@ photos_base_item_class_init (PhotosBaseItemClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
 
+  object_class->dispose = photos_base_item_dispose;
   object_class->finalize = photos_base_item_finalize;
   object_class->set_property = photos_base_item_set_property;
   class->update_type_description = photos_base_item_update_type_description;
@@ -178,6 +235,13 @@ photos_base_item_get_author (PhotosBaseItem *self)
 }
 
 
+GdkPixbuf *
+photos_base_item_get_icon (PhotosBaseItem *self)
+{
+  return self->priv->icon;
+}
+
+
 const gchar *
 photos_base_item_get_id (PhotosBaseItem *self)
 {
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index b95f0e5..adba45e 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -21,6 +21,7 @@
 #ifndef PHOTOS_BASE_ITEM_H
 #define PHOTOS_BASE_ITEM_H
 
+#include <gdk-pixbuf/gdk-pixbuf.h>
 #include <glib-object.h>
 
 G_BEGIN_DECLS
@@ -67,6 +68,8 @@ GType               photos_base_item_get_type           (void) G_GNUC_CONST;
 
 const gchar        *photos_base_item_get_author         (PhotosBaseItem *self);
 
+GdkPixbuf          *photos_base_item_get_icon           (PhotosBaseItem *self);
+
 const gchar        *photos_base_item_get_id             (PhotosBaseItem *self);
 
 glong               photos_base_item_get_mtime          (PhotosBaseItem *self);



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