[gnome-photos/wip/flickr: 2/2] flickr



commit d8bcba13e5d60a20ecb1b5e8b2cffb3afa76b608
Author: Marek Chalupa <mchalupa redhat com>
Date:   Fri Jun 28 19:23:28 2013 +0200

    flickr

 src/Makefile.am             |    2 +
 src/photos-base-item.c      |   30 +++++++++-
 src/photos-flickr-item.c    |  141 +++++++++++++++++++++++++++++++++++++++++++
 src/photos-flickr-item.h    |   77 +++++++++++++++++++++++
 src/photos-item-manager.c   |   17 +++++
 src/photos-query-builder.c  |    8 +++
 src/photos-query.c          |    1 +
 src/photos-query.h          |    1 +
 src/photos-source-manager.c |    7 +-
 src/photos-source.c         |    8 ++-
 10 files changed, 284 insertions(+), 8 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 200afb5..d0f8ef7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -92,6 +92,8 @@ gnome_photos_SOURCES = \
        photos-fetch-collections-job.h \
        photos-filterable.c \
        photos-filterable.h \
+       photos-flickr-item.c \
+       photos-flickr-item.h \
        photos-header-bar.c \
        photos-header-bar.h \
        photos-indexing-notification.c \
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 50e7b12..23f4866 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -476,12 +476,38 @@ photos_base_item_update_icon_from_type (PhotosBaseItem *self)
   GtkIconTheme *theme;
   gint icon_size;
 
-  if (priv->mime_type != NULL)
+  if (priv->mime_type != NULL && priv->collection == FALSE)
     icon = g_content_type_get_icon (priv->mime_type);
 
   if (icon == NULL)
     icon = photos_utils_icon_from_rdf_type (priv->rdf_type);
 
+  if (icon == NULL)
+  {
+    gchar *file_type = NULL;
+    gchar *mime = NULL;
+
+    /* try guess mime type from uri */
+    file_type = g_content_type_guess (priv->uri, NULL, 0, NULL);
+
+    if (file_type != NULL)
+    {
+      mime = g_content_type_get_mime_type (file_type);
+
+      if (mime != NULL)
+      {
+        icon = g_content_type_get_icon (mime);
+        g_free (mime);
+      }
+
+      g_free (file_type);
+    }
+  }
+
+  /* if we still dont have icon, hardcode jpeg icon (or some other image) */
+  if (icon == NULL)
+    icon = g_content_type_get_icon ("image/jpeg");
+
   theme = gtk_icon_theme_get_default ();
   icon_size = photos_utils_get_icon_size ();
   info = gtk_icon_theme_lookup_by_gicon (theme,
@@ -736,6 +762,8 @@ photos_base_item_init (PhotosBaseItem *self)
   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, PHOTOS_TYPE_BASE_ITEM, PhotosBaseItemPrivate);
   priv = self->priv;
 
+  priv->icon = NULL;
+
   g_mutex_init (&priv->mutex);
 }
 
diff --git a/src/photos-flickr-item.c b/src/photos-flickr-item.c
new file mode 100644
index 0000000..a6c6ff5
--- /dev/null
+++ b/src/photos-flickr-item.c
@@ -0,0 +1,141 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2013 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/* Based on code from:
+ *   + Documents
+ */
+
+
+#include "config.h"
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <libgnome-desktop/gnome-desktop-thumbnail.h>
+
+#include <gio/gio.h>
+#include <glib.h>
+
+#include "photos-flickr-item.h"
+#include "photos-base-item.h"
+
+
+G_DEFINE_TYPE (PhotosFlickrItem, photos_flickr_item, PHOTOS_TYPE_BASE_ITEM);
+
+
+static gchar *
+photos_flickr_item_download (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
+{
+  GFile *local_file = NULL;
+  GFile *remote_file = NULL;
+  const gchar *cache_dir;
+  const gchar *uri;
+  gchar *local_dir = NULL;
+  gchar *local_filename = NULL;
+  gchar *local_path = NULL;
+  gchar *ret_val = NULL;
+
+  uri = photos_base_item_get_uri (item);
+  remote_file = g_file_new_for_uri (uri);
+  cache_dir = g_get_user_cache_dir ();
+
+  local_dir = g_build_filename (cache_dir, PACKAGE_TARNAME, "flickr", NULL);
+  g_mkdir_with_parents (local_dir, 0700);
+
+  local_filename = g_file_get_basename (remote_file);
+  local_path = g_build_filename (local_dir, local_filename, NULL);
+  local_file = g_file_new_for_path (local_path);
+
+  if (!g_file_test (local_path, G_FILE_TEST_EXISTS))
+    {
+      g_debug ("Downloading %s from Flickr to %s", uri, local_path);
+      if (!g_file_copy (remote_file,
+                        local_file,
+                        G_FILE_COPY_ALL_METADATA | G_FILE_COPY_OVERWRITE,
+                        cancellable,
+                        NULL,
+                        NULL,
+                        error))
+        goto out;
+    }
+
+  ret_val = local_path;
+  local_path = NULL;
+
+ out:
+  g_free (local_path);
+  g_free (local_filename);
+  g_free (local_dir);
+  g_object_unref (local_file);
+  g_object_unref (remote_file);
+  return ret_val;
+}
+
+
+static void
+photos_flickr_item_constructed (GObject *object)
+{
+  PhotosFlickrItem *self = PHOTOS_FLICKR_ITEM (object);
+  PhotosFlickrItemPrivate *priv = self->priv;
+  GAppInfo *default_app = NULL;
+  const gchar *default_app_name;
+  const gchar *mime_type;
+
+  G_OBJECT_CLASS (photos_flickr_item_parent_class)->constructed (object);
+
+  mime_type = photos_base_item_get_mime_type (PHOTOS_BASE_ITEM (self));
+  if (mime_type == NULL)
+    return;
+
+  default_app = g_app_info_get_default_for_type (mime_type, TRUE);
+  if (default_app == NULL)
+    return;
+
+  default_app_name = g_app_info_get_name (default_app);
+  photos_base_item_set_default_app_name (PHOTOS_BASE_ITEM (self), default_app_name);
+
+  g_object_unref (default_app);
+}
+
+
+static void
+photos_flickr_item_init (PhotosFlickrItem *self)
+{
+}
+
+
+static void
+photos_flickr_item_class_init (PhotosFlickrItemClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+  PhotosBaseItemClass *base_item_class = PHOTOS_BASE_ITEM_CLASS (class);
+
+  object_class->constructed= photos_flickr_item_constructed;
+  base_item_class->download = photos_flickr_item_download;
+}
+
+
+PhotosBaseItem *
+photos_flickr_item_new (TrackerSparqlCursor *cursor)
+{
+  return g_object_new (PHOTOS_TYPE_FLICKR_ITEM,
+                       "cursor", cursor,
+                       "failed-thumbnailing", FALSE,
+                       "tried-thumbnailing", FALSE,
+                       NULL);
+}
diff --git a/src/photos-flickr-item.h b/src/photos-flickr-item.h
new file mode 100644
index 0000000..0d26b56
--- /dev/null
+++ b/src/photos-flickr-item.h
@@ -0,0 +1,77 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2012 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
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/* Based on code from:
+ *   + Documents
+ */
+
+#ifndef PHOTOS_FLICKR_ITEM_H
+#define PHOTOS_FLICKR_ITEM_H
+
+#include <tracker-sparql.h>
+
+#include "photos-base-item.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_FLICKR_ITEM (photos_flickr_item_get_type ())
+
+#define PHOTOS_FLICKR_ITEM(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_FLICKR_ITEM, PhotosFlickrItem))
+
+#define PHOTOS_FLICKR_ITEM_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_FLICKR_ITEM, PhotosFlickrItemClass))
+
+#define PHOTOS_IS_FLICKR_ITEM(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_FLICKR_ITEM))
+
+#define PHOTOS_IS_FLICKR_ITEM_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_FLICKR_ITEM))
+
+#define PHOTOS_FLICKR_ITEM_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_FLICKR_ITEM, PhotosFlickrItemClass))
+
+typedef struct _PhotosFlickrItem        PhotosFlickrItem;
+typedef struct _PhotosFlickrItemClass   PhotosFlickrItemClass;
+typedef struct _PhotosFlickrItemPrivate PhotosFlickrItemPrivate;
+
+struct _PhotosFlickrItem
+{
+  PhotosBaseItem parent_instance;
+  PhotosFlickrItemPrivate *priv;
+};
+
+struct _PhotosFlickrItemClass
+{
+  PhotosBaseItemClass parent_class;
+};
+
+GType               photos_flickr_item_get_type           (void) G_GNUC_CONST;
+
+PhotosBaseItem     *photos_flickr_item_new                (TrackerSparqlCursor *cursor);
+
+G_END_DECLS
+
+#endif /* PHOTOS_LOCAL_ITEM_H */
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index b20943a..075fcc5 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -30,6 +30,7 @@
 #include "photos-collection-manager.h"
 #include "photos-item-manager.h"
 #include "photos-local-item.h"
+#include "photos-flickr-item.h"
 #include "photos-query.h"
 #include "photos-single-item-job.h"
 #include "photos-tracker-change-event.h"
@@ -265,5 +266,21 @@ photos_item_manager_add_item (PhotosItemManager *self, TrackerSparqlCursor *curs
 PhotosBaseItem *
 photos_item_manager_create_item (PhotosItemManager *self, TrackerSparqlCursor *cursor)
 {
+  PhotosBaseItem *retval = NULL;
+
+  gchar *id = g_strdup (tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_IDENTIFIER, NULL));
+
+  if (id != NULL)
+  {
+    if (g_str_has_prefix (id, "flickr:"))
+      retval = photos_flickr_item_new (cursor);
+    else
+      retval = photos_local_item_new (cursor);
+
+    g_free (id);
+
+    return retval;
+  }
+
   return photos_local_item_new (cursor);
 }
diff --git a/src/photos-query-builder.c b/src/photos-query-builder.c
index 44f9cfe..914eb8e 100644
--- a/src/photos-query-builder.c
+++ b/src/photos-query-builder.c
@@ -385,3 +385,11 @@ photos_query_builder_filter_local (void)
 
   return filter;
 }
+
+gchar *
+photos_query_builder_filter_flickr (void)
+{
+  return g_strdup_printf ("(fn:starts-with (nao:identifier (?urn), \"%s\"))"
+                          "|| (fn:starts-with (nao:identifier (?urn), \"flickr:\"))",
+                          PHOTOS_QUERY_FLICKR_COLLECTIONS_IDENTIFIER);
+}
diff --git a/src/photos-query.c b/src/photos-query.c
index 06d9b2e..58c9173 100644
--- a/src/photos-query.c
+++ b/src/photos-query.c
@@ -31,6 +31,7 @@
 
 const gchar *PHOTOS_QUERY_COLLECTIONS_IDENTIFIER = "photos:collection:";
 const gchar *PHOTOS_QUERY_LOCAL_COLLECTIONS_IDENTIFIER = "photos:collection:local:";
+const gchar *PHOTOS_QUERY_FLICKR_COLLECTIONS_IDENTIFIER = "photos:collection:flickr:";
 
 
 PhotosQuery *
diff --git a/src/photos-query.h b/src/photos-query.h
index 7d5f7c9..67141ba 100644
--- a/src/photos-query.h
+++ b/src/photos-query.h
@@ -59,6 +59,7 @@ typedef enum
 
 extern const gchar *PHOTOS_QUERY_COLLECTIONS_IDENTIFIER;
 extern const gchar *PHOTOS_QUERY_LOCAL_COLLECTIONS_IDENTIFIER;
+extern const gchar *PHOTOS_QUERY_FLICKR_COLLECTIONS_IDENTIFIER;
 
 typedef struct _PhotosQuery PhotosQuery;
 
diff --git a/src/photos-source-manager.c b/src/photos-source-manager.c
index 9651aab..b1b2346 100644
--- a/src/photos-source-manager.c
+++ b/src/photos-source-manager.c
@@ -91,10 +91,9 @@ photos_source_manager_refresh_accounts (PhotosSourceManager *self)
       if (goa_object_peek_account (GOA_OBJECT (l->data)) == NULL)
         continue;
 
-      /* TODO: uncomment when we start supporting online providers */
-      /* source = photos_source_new_from_goa_object (GOA_OBJECT (l->data)); */
-      /* photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (source)); */
-      /* g_object_unref (source); */
+      source = photos_source_new_from_goa_object (GOA_OBJECT (l->data));
+      photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (source));
+      g_object_unref (source);
     }
 
   g_list_free_full (accounts, g_object_unref);
diff --git a/src/photos-source.c b/src/photos-source.c
index de08266..47dbaa4 100644
--- a/src/photos-source.c
+++ b/src/photos-source.c
@@ -31,7 +31,6 @@
 #include "photos-query-builder.h"
 #include "photos-source.h"
 
-
 struct _PhotosSourcePrivate
 {
   GIcon *icon;
@@ -82,7 +81,10 @@ photos_source_get_filter (PhotosFilterable *iface)
     return photos_query_builder_filter_local ();
 
   if (g_strcmp0 (priv->id, PHOTOS_SOURCE_STOCK_ALL) == 0)
-    return photos_query_builder_filter_local (); /* TODO: Add non local query */
+    return photos_query_builder_filter_local ();
+
+  if (g_strcmp0 (priv->id, PHOTOS_SOURCE_STOCK_FLICKR) == 0)
+    return photos_query_builder_filter_flickr ();
 
   return photos_source_build_filter_resource (self);
 }
@@ -163,7 +165,7 @@ photos_source_set_property (GObject *object, guint prop_id, const GValue *value,
           break;
 
         account = goa_object_peek_account (object);
-        priv->id = goa_account_dup_id (account);
+        priv->id = g_strdup_printf ("gd:goa-account:%s", goa_account_get_id (account));
 
         provider_icon = goa_account_get_provider_icon (account);
         priv->icon = g_icon_new_for_string (provider_icon, NULL); /* TODO: use a GError */


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