[gnome-photos/wip/search: 7/23] photos-utils: Add photo_utils_get_icon_from_cursor



commit 99cecf600cd54087601e490793e874ba0b491047
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Feb 16 13:00:55 2014 +0100

    photos-utils: Add photo_utils_get_icon_from_cursor

 src/photos-utils.c |   83 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/photos-utils.h |    5 ++-
 2 files changed, 87 insertions(+), 1 deletions(-)
---
diff --git a/src/photos-utils.c b/src/photos-utils.c
index f44b725..c2aff36 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -34,6 +34,7 @@
 #include <tracker-sparql.h>
 #include <libgd/gd.h>
 
+#include "photos-query.h"
 #include "photos-tracker-queue.h"
 #include "photos-utils.h"
 
@@ -259,6 +260,88 @@ photos_utils_create_thumbnail (GFile *file, GCancellable *cancellable, GError **
 }
 
 
+static GIcon *
+photos_utils_get_thumbnail_icon (const gchar *uri)
+{
+  GError *error;
+  GFile *file = NULL;
+  GFile *thumb_file = NULL;
+  GFileInfo *info = NULL;
+  GIcon *icon = NULL;
+  const gchar *thumb_path;
+
+  file = g_file_new_for_uri (uri);
+
+  error = NULL;
+  info = g_file_query_info (file, G_FILE_ATTRIBUTE_THUMBNAIL_PATH, G_FILE_QUERY_INFO_NONE, NULL, &error);
+  if (error != NULL)
+    {
+      g_warning ("Unable to fetch thumbnail path for %s: %s", uri, error->message);
+      g_error_free (error);
+      goto out;
+    }
+
+  thumb_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
+  thumb_file = g_file_new_for_path (thumb_path);
+  icon = g_file_icon_new (thumb_file);
+
+ out:
+  g_clear_object (&thumb_file);
+  g_clear_object (&info);
+  g_clear_object (&file);
+  return icon;
+}
+
+
+GIcon *
+photos_utils_get_icon_from_cursor (TrackerSparqlCursor *cursor)
+{
+  GIcon *icon = NULL;
+  gboolean is_remote = FALSE;
+  const gchar *identifier;
+  const gchar *mime_type;
+  const gchar *rdf_type;
+
+  identifier = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_IDENTIFIER, NULL);
+  if (identifier != NULL)
+    {
+      if (g_str_has_prefix (identifier, "facebook:") || g_str_has_prefix (identifier, "flickr:"))
+        is_remote = TRUE;
+    }
+
+  if (!is_remote)
+    {
+      const gchar *uri;
+
+      uri = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URI, NULL);
+      if (uri != NULL)
+        icon = photos_utils_get_thumbnail_icon (uri);
+    }
+
+  if (icon != NULL)
+    goto out;
+
+  mime_type = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_MIME_TYPE, NULL);
+  if (mime_type != NULL)
+    icon = g_content_type_get_icon (mime_type);
+
+  if (icon != NULL)
+    goto out;
+
+  rdf_type = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_RDF_TYPE, NULL);
+  if (mime_type != NULL)
+    icon = photos_utils_icon_from_rdf_type (rdf_type);
+
+  if (icon != NULL)
+    goto out;
+
+  icon = g_themed_icon_new ("image-x-generic");
+
+ out:
+  return icon;
+}
+
+
 const gchar *
 photos_utils_dot_dir (void)
 {
diff --git a/src/photos-utils.h b/src/photos-utils.h
index 838b844..e61f8e0 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2012, 2013 Red Hat, Inc.
+ * Copyright © 2012, 2013, 2014 Red Hat, Inc.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -31,6 +31,7 @@
 #include <gio/gio.h>
 #include <glib.h>
 #include <gtk/gtk.h>
+#include <tracker-sparql.h>
 
 G_BEGIN_DECLS
 
@@ -49,6 +50,8 @@ GIcon           *photos_utils_create_symbolic_icon        (const gchar *name, gi
 
 gboolean         photos_utils_create_thumbnail            (GFile *file, GCancellable *cancellable, GError 
**error);
 
+GIcon           *photos_utils_get_icon_from_cursor        (TrackerSparqlCursor *cursor);
+
 const gchar     *photos_utils_dot_dir                     (void);
 
 GQuark           photos_utils_error_quark                 (void);


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