[gnome-photos] Add PhotosSource



commit ae02f72d54b4ac3067c113947924ecb8c914d6ad
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue May 1 03:02:13 2012 +0200

    Add PhotosSource

 configure.ac        |    1 +
 src/Makefile.am     |    4 +
 src/photos-source.c |  223 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/photos-source.h |   78 ++++++++++++++++++
 4 files changed, 306 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c17df5d..ccc4531 100644
--- a/configure.ac
+++ b/configure.ac
@@ -44,6 +44,7 @@ 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(GOA, [goa-1.0])
 PKG_CHECK_MODULES(GTK, [gtk+-3.0])
 PKG_CHECK_MODULES(TRACKER, [tracker-sparql-0.14])
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 507e2f1..5bd4c66 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -56,6 +56,8 @@ gnome_photos_SOURCES = \
 	photos-selection-controller.h \
 	photos-selection-toolbar.c \
 	photos-selection-toolbar.h \
+	photos-source.c \
+	photos-source.h \
 	photos-utils.c \
 	photos-utils.h \
 	photos-view.c \
@@ -80,6 +82,7 @@ AM_CPPFLAGS = \
 	$(GDK_PIXBUF_CFLAGS) \
 	$(GIO_CFLAGS) \
 	$(GLIB_CFLAGS) \
+	$(GOA_CFLAGS) \
 	$(GTK_CFLAGS) \
 	$(TRACKER_CFLAGS) \
 	$(NULL)
@@ -92,6 +95,7 @@ gnome_photos_LDADD = \
 	$(GDK_PIXBUF_LIBS) \
 	$(GIO_LIBS) \
 	$(GLIB_LIBS) \
+	$(GOA_LIBS) \
 	$(GTK_LIBS) \
 	$(TRACKER_LIBS) \
 	$(LIBM) \
diff --git a/src/photos-source.c b/src/photos-source.c
new file mode 100644
index 0000000..4746243
--- /dev/null
+++ b/src/photos-source.c
@@ -0,0 +1,223 @@
+/*
+ * 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.
+ */
+
+
+#include "config.h"
+#define GOA_API_IS_SUBJECT_TO_CHANGE
+
+#include <gio/gio.h>
+
+#include "photos-query-builder.h"
+#include "photos-source.h"
+
+
+struct _PhotosSourcePrivate
+{
+  GIcon *icon;
+  gboolean builtin;
+  gchar *id;
+  gchar *name;
+};
+
+enum
+{
+  PROP_0,
+  PROP_BUILTIN,
+  PROP_ID,
+  PROP_NAME,
+  PROP_OBJECT
+};
+
+
+G_DEFINE_TYPE (PhotosSource, photos_source, G_TYPE_OBJECT);
+
+
+static gchar *
+photos_source_build_filter_resource (PhotosSource *self)
+{
+  PhotosSourcePrivate *priv = self->priv;
+  gchar *filter;
+
+  if (!priv->builtin)
+    filter = g_strdup_printf ("(nie:dataSource (?urn) = \"%s\")", priv->id);
+  else
+    filter = g_strdup ("(false)");
+
+  return filter;
+}
+
+
+static void
+photos_source_dispose (GObject *object)
+{
+  PhotosSource *self = PHOTOS_SOURCE (object);
+  PhotosSourcePrivate *priv = self->priv;
+
+  g_clear_object (&priv->icon);
+
+  G_OBJECT_CLASS (photos_source_parent_class)->dispose (object);
+}
+
+
+static void
+photos_source_finalize (GObject *object)
+{
+  PhotosSource *self = PHOTOS_SOURCE (object);
+  PhotosSourcePrivate *priv = self->priv;
+
+  g_free (priv->id);
+  g_free (priv->name);
+
+  G_OBJECT_CLASS (photos_source_parent_class)->finalize (object);
+}
+
+
+static void
+photos_source_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+  PhotosSource *self = PHOTOS_SOURCE (object);
+  PhotosSourcePrivate *priv = self->priv;
+
+  switch (prop_id)
+    {
+    case PROP_BUILTIN:
+      priv->builtin = g_value_get_boolean (value);
+      break;
+
+    case PROP_ID:
+      priv->id = g_value_dup_string (value);
+      break;
+
+    case PROP_NAME:
+      priv->name = g_value_dup_string (value);
+      break;
+
+    case PROP_OBJECT:
+      {
+        GoaAccount *account;
+        GoaObject *object;
+        const gchar *id;
+        const gchar *provider_icon;
+        const gchar *provider_name;
+
+        object = GOA_OBJECT (g_value_get_object (value));
+        account = goa_object_peek_account (object);
+
+        id = goa_account_get_id (account);
+        priv->id = g_strdup_printf ("gp:goa-account:%s", id);
+
+        provider_icon = goa_account_get_provider_icon (account);
+        priv->icon = g_icon_new_for_string (provider_icon, NULL); /* TODO: use a GError */
+
+        provider_name = goa_account_get_provider_name (account);
+        priv->name = g_strdup (provider_name);
+        break;
+      }
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_source_init (PhotosSource *self)
+{
+  PhotosSourcePrivate *priv;
+
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, PHOTOS_TYPE_SOURCE, PhotosSourcePrivate);
+  priv = self->priv;
+}
+
+
+static void
+photos_source_class_init (PhotosSourceClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->dispose = photos_source_dispose;
+  object_class->finalize = photos_source_finalize;
+  object_class->set_property = photos_source_set_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_BUILTIN,
+                                   g_param_spec_boolean ("builtin",
+                                                         "",
+                                                         "",
+                                                         FALSE,
+                                                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_ID,
+                                   g_param_spec_string ("id",
+                                                        "",
+                                                        "",
+                                                        "",
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_NAME,
+                                   g_param_spec_string ("name",
+                                                        "",
+                                                        "",
+                                                        "",
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_OBJECT,
+                                   g_param_spec_object ("object",
+                                                        "GoaObject instance",
+                                                        "A GOA configured account from which the source was created",
+                                                        GOA_TYPE_OBJECT,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+  g_type_class_add_private (class, sizeof (PhotosSourcePrivate));
+}
+
+
+PhotosSource *
+photos_source_new (const gchar *id, const gchar *name, gboolean builtin)
+{
+  return g_object_new (PHOTOS_TYPE_SOURCE, "id", id, "name", name, "builtin", builtin, NULL);
+}
+
+
+PhotosSource *
+photos_source_new_from_goa_object (GoaObject *object)
+{
+  g_return_val_if_fail (GOA_IS_OBJECT (object), NULL);
+  return g_object_new (PHOTOS_TYPE_SOURCE, "object", object, NULL);
+}
+
+
+gchar *
+photos_source_get_filter (PhotosSource *self)
+{
+  PhotosSourcePrivate *priv = self->priv;
+
+  if (g_strcmp0 (priv->id, PHOTOS_SOURCE_STOCK_LOCAL) == 0)
+    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_source_build_filter_resource (self);
+}
diff --git a/src/photos-source.h b/src/photos-source.h
new file mode 100644
index 0000000..6487a86
--- /dev/null
+++ b/src/photos-source.h
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+
+#ifndef PHOTOS_SOURCE_H
+#define PHOTOS_SOURCE_H
+
+#include <glib-object.h>
+#include <goa/goa.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_SOURCE (photos_source_get_type ())
+#define PHOTOS_SOURCE(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_SOURCE, PhotosSource))
+
+#define PHOTOS_SOURCE_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_SOURCE, PhotosSourceClass))
+
+#define PHOTOS_IS_SOURCE(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_SOURCE))
+
+#define PHOTOS_IS_SOURCE_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_SOURCE))
+
+#define PHOTOS_SOURCE_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_SOURCE, PhotosSourceClass))
+
+#define PHOTOS_SOURCE_STOCK_ALL   "all"
+#define PHOTOS_SOURCE_STOCK_LOCAL "local"
+
+typedef struct _PhotosSource        PhotosSource;
+typedef struct _PhotosSourceClass   PhotosSourceClass;
+typedef struct _PhotosSourcePrivate PhotosSourcePrivate;
+
+struct _PhotosSource
+{
+  GObject parent_instance;
+  PhotosSourcePrivate *priv;
+};
+
+struct _PhotosSourceClass
+{
+  GObjectClass parent_class;
+};
+
+GType               photos_source_get_type               (void) G_GNUC_CONST;
+
+PhotosSource       *photos_source_new                    (const gchar *id, const gchar *name, gboolean builtin);
+
+PhotosSource       *photos_source_new_from_goa_object    (GoaObject *object);
+
+gchar              *photos_source_get_filter             (PhotosSource *self);
+
+G_END_DECLS
+
+#endif /* PHOTOS_SOURCE_H */



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