[gnome-photos] Add a PhotosBaseItem skeleton



commit 567d67869f214da2f28a77c7a84246d34b3ab82f
Author: Debarshi Ray <debarshir gnome org>
Date:   Sat Apr 28 01:17:28 2012 +0200

    Add a PhotosBaseItem skeleton

 src/Makefile.am        |    2 +
 src/photos-base-item.c |  171 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/photos-base-item.h |   70 ++++++++++++++++++++
 3 files changed, 243 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 7c297e3..7f17457 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,6 +17,8 @@ gnome_photos_SOURCES = \
 	photos-application.h \
 	photos-base-manager.c \
 	photos-base-manager.h \
+	photos-base-item.c \
+	photos-base-item.h \
 	photos-collection-manager.c \
 	photos-collection-manager.h \
 	photos-view-embed.c \
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
new file mode 100644
index 0000000..d6b62e2
--- /dev/null
+++ b/src/photos-base-item.c
@@ -0,0 +1,171 @@
+/*
+ * 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"
+
+#include <gio/gio.h>
+#include <glib.h>
+#include <tracker-sparql.h>
+
+#include "photos-base-item.h"
+#include "photos-query.h"
+#include "photos-utils.h"
+
+
+struct _PhotosBaseItemPrivate
+{
+  gboolean favorite;
+  gchar *author;
+  gchar *id;
+  gchar *identifier;
+  gchar *mime_type;
+  gchar *name;
+  gchar *rdf_type;
+  gchar *resource_urn;
+  gchar *type_description;
+  gchar *uri;
+  gulong mtime;
+};
+
+enum
+{
+  PROP_0,
+  PROP_CURSOR
+};
+
+
+G_DEFINE_TYPE (PhotosBaseItem, photos_base_item, G_TYPE_OBJECT);
+
+
+static void
+photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor *cursor)
+{
+  PhotosBaseItemPrivate *priv = self->priv;
+  GTimeVal timeval;
+  const gchar *mtime;
+  const gchar *title;
+  const gchar *uri;
+
+  uri = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URI, NULL);
+  priv->uri = g_strdup ((uri == NULL) ? "" : uri);
+
+  priv->id = g_strdup (tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL));
+  priv->identifier = g_strdup (tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_IDENTIFIER, NULL));
+  priv->author = g_strdup (tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_AUTHOR, NULL));
+  priv->resource_urn = g_strdup (tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_RESOURCE_URN, NULL));
+  priv->favorite = tracker_sparql_cursor_get_boolean (cursor, PHOTOS_QUERY_COLUMNS_RESOURCE_FAVORITE);
+
+  mtime = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_MTIME, NULL);
+  g_time_val_from_iso8601 (mtime, &timeval);
+  priv->mtime = timeval.tv_sec;
+
+  priv->mime_type = g_strdup (tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_MIME_TYPE, NULL));
+  priv->rdf_type = g_strdup (tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_RDF_TYPE, NULL));
+
+  PHOTOS_BASE_ITEM_GET_CLASS (self)->update_type_description (self);
+
+  title = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_TITLE, NULL);
+  if (title == NULL || title[0] == '\0')
+    {
+      title = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_FILENAME, NULL);
+      title = photos_utils_filename_strip_extension (title);
+    }
+  priv->name = g_strdup (title);
+}
+
+
+static void
+photos_base_item_update_type_description (PhotosBaseItem *self)
+{
+  PhotosBaseItemPrivate *priv = self->priv;
+
+  if (priv->mime_type == NULL)
+    return;
+
+  priv->type_description = g_content_type_get_description (priv->mime_type);
+}
+
+
+static void
+photos_base_item_finalize (GObject *object)
+{
+  PhotosBaseItem *self = PHOTOS_BASE_ITEM (object);
+  PhotosBaseItemPrivate *priv = self->priv;
+
+  g_free (priv->author);
+  g_free (priv->id);
+  g_free (priv->identifier);
+  g_free (priv->mime_type);
+  g_free (priv->name);
+  g_free (priv->rdf_type);
+  g_free (priv->resource_urn);
+  g_free (priv->type_description);
+  g_free (priv->uri);
+}
+
+
+static void
+photos_base_item_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+  PhotosBaseItem *self = PHOTOS_BASE_ITEM (object);
+
+  switch (prop_id)
+    {
+    case PROP_CURSOR:
+      photos_base_item_populate_from_cursor (self, TRACKER_SPARQL_CURSOR (g_value_get_object (value)));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_base_item_init (PhotosBaseItem *self)
+{
+  PhotosBaseItemPrivate *priv;
+
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, PHOTOS_TYPE_BASE_ITEM, PhotosBaseItemPrivate);
+  priv = self->priv;
+}
+
+
+static void
+photos_base_item_class_init (PhotosBaseItemClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  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;
+
+  g_object_class_install_property (object_class,
+                                   PROP_CURSOR,
+                                   g_param_spec_object ("cursor",
+                                                        "TrackerSparqlCursor object",
+                                                        "A cursor to iterate over the results of a query",
+                                                        TRACKER_SPARQL_TYPE_CURSOR,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+  g_type_class_add_private (class, sizeof (PhotosBaseItemPrivate));
+}
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
new file mode 100644
index 0000000..d5327b1
--- /dev/null
+++ b/src/photos-base-item.h
@@ -0,0 +1,70 @@
+/*
+ * 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_BASE_ITEM_H
+#define PHOTOS_BASE_ITEM_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_BASE_ITEM (photos_base_item_get_type ())
+#define PHOTOS_BASE_ITEM(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_BASE_ITEM, PhotosBaseItem))
+
+#define PHOTOS_BASE_ITEM_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_BASE_ITEM, PhotosBaseItemClass))
+
+#define PHOTOS_IS_BASE_ITEM(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_BASE_ITEM))
+
+#define PHOTOS_IS_BASE_ITEM_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_BASE_ITEM))
+
+#define PHOTOS_BASE_ITEM_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_BASE_ITEM, PhotosBaseItemClass))
+
+typedef struct _PhotosBaseItem        PhotosBaseItem;
+typedef struct _PhotosBaseItemClass   PhotosBaseItemClass;
+typedef struct _PhotosBaseItemPrivate PhotosBaseItemPrivate;
+
+struct _PhotosBaseItem
+{
+  GObject parent_instance;
+  PhotosBaseItemPrivate *priv;
+};
+
+struct _PhotosBaseItemClass
+{
+  GObjectClass parent_class;
+
+  void (*update_type_description) (PhotosBaseItem *self);
+};
+
+GType               photos_base_item_get_type           (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* PHOTOS_BASE_ITEM_H */



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