[gnome-photos] Add PhotosSearchType



commit 5948f7db68523dc703f2a53d817c3c9dd11db0bc
Author: Debarshi Ray <debarshir gnome org>
Date:   Sat May 12 18:01:32 2012 +0200

    Add PhotosSearchType

 src/Makefile.am          |    2 +
 src/photos-search-type.c |  184 ++++++++++++++++++++++++++++++++++++++++++++++
 src/photos-search-type.h |   78 +++++++++++++++++++
 3 files changed, 264 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 098a977..88c65be 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -61,6 +61,8 @@ gnome_photos_SOURCES = \
 	photos-query.h \
 	photos-query-builder.h \
 	photos-query-builder.c \
+	photos-search-type.c \
+	photos-search-type.h \
 	photos-selection-controller.c \
 	photos-selection-controller.h \
 	photos-selection-toolbar.c \
diff --git a/src/photos-search-type.c b/src/photos-search-type.c
new file mode 100644
index 0000000..dd5d4e7
--- /dev/null
+++ b/src/photos-search-type.c
@@ -0,0 +1,184 @@
+/*
+ * 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 "photos-filterable.h"
+#include "photos-search-type.h"
+
+
+struct _PhotosSearchTypePrivate
+{
+  gchar *filter;
+  gchar *id;
+  gchar *name;
+};
+
+enum
+{
+  PROP_0,
+  PROP_FILTER,
+  PROP_ID,
+  PROP_NAME
+};
+
+static void photos_filterable_interface_init (PhotosFilterableInterface *iface);
+
+
+G_DEFINE_TYPE_WITH_CODE (PhotosSearchType, photos_search_type, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (PHOTOS_TYPE_FILTERABLE,
+                                                photos_filterable_interface_init));
+
+
+static gchar *
+photos_search_type_get_filter (PhotosFilterable *iface)
+{
+  PhotosSearchType *self = PHOTOS_SEARCH_TYPE (iface);
+  PhotosSearchTypePrivate *priv = self->priv;
+  const gchar *filter;
+
+  filter = (priv->filter != NULL && priv->filter[0] != '\0') ? priv->filter : "";
+  return g_strdup (filter);
+}
+
+
+static void
+photos_search_type_finalize (GObject *object)
+{
+  PhotosSearchType *self = PHOTOS_SEARCH_TYPE (object);
+  PhotosSearchTypePrivate *priv = self->priv;
+
+  g_free (priv->filter);
+  g_free (priv->id);
+  g_free (priv->name);
+
+  G_OBJECT_CLASS (photos_search_type_parent_class)->finalize (object);
+}
+
+
+static void
+photos_search_type_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+  PhotosSearchType *self = PHOTOS_SEARCH_TYPE (object);
+
+  switch (prop_id)
+    {
+    case PROP_ID:
+      g_value_set_string (value, self->priv->id);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_search_type_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+  PhotosSearchType *self = PHOTOS_SEARCH_TYPE (object);
+  PhotosSearchTypePrivate *priv = self->priv;
+
+  switch (prop_id)
+    {
+    case PROP_FILTER:
+      priv->filter = g_value_dup_string (value);
+      break;
+
+    case PROP_ID:
+      priv->id = g_value_dup_string (value);
+      break;
+
+    case PROP_NAME:
+      priv->name = g_value_dup_string (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_search_type_init (PhotosSearchType *self)
+{
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, PHOTOS_TYPE_SEARCH_TYPE, PhotosSearchTypePrivate);
+}
+
+
+static void
+photos_search_type_class_init (PhotosSearchTypeClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->finalize = photos_search_type_finalize;
+  object_class->get_property = photos_search_type_get_property;
+  object_class->set_property = photos_search_type_set_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_FILTER,
+                                   g_param_spec_string ("filter",
+                                                        "",
+                                                        "",
+                                                        NULL,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_ID,
+                                   g_param_spec_string ("id",
+                                                        "",
+                                                        "",
+                                                        NULL,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_NAME,
+                                   g_param_spec_string ("name",
+                                                        "",
+                                                        "",
+                                                        NULL,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+  g_type_class_add_private (class, sizeof (PhotosSearchTypePrivate));
+}
+
+
+static void
+photos_filterable_interface_init (PhotosFilterableInterface *iface)
+{
+  iface->get_filter = photos_search_type_get_filter;
+}
+
+
+PhotosSearchType *
+photos_search_type_new (const gchar *id, const gchar *name)
+{
+  return g_object_new (PHOTOS_TYPE_SEARCH_TYPE, "id", id, "name", name, NULL);
+}
+
+
+PhotosSearchType *
+photos_search_type_new_with_filter (const gchar *id, const gchar *name, const gchar *filter)
+{
+  return g_object_new (PHOTOS_TYPE_SEARCH_TYPE, "id", id, "name", name, "filter", filter, NULL);
+}
diff --git a/src/photos-search-type.h b/src/photos-search-type.h
new file mode 100644
index 0000000..75e3867
--- /dev/null
+++ b/src/photos-search-type.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_SEARCH_TYPE_H
+#define PHOTOS_SEARCH_TYPE_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_SEARCH_TYPE (photos_search_type_get_type ())
+
+#define PHOTOS_SEARCH_TYPE(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_SEARCH_TYPE, PhotosSearchType))
+
+#define PHOTOS_SEARCH_TYPE_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_SEARCH_TYPE, PhotosSearchTypeClass))
+
+#define PHOTOS_IS_SEARCH_TYPE(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_SEARCH_TYPE))
+
+#define PHOTOS_IS_SEARCH_TYPE_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_SEARCH_TYPE))
+
+#define PHOTOS_SEARCH_TYPE_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_SEARCH_TYPE, PhotosSearchTypeClass))
+
+#define PHOTOS_SEARCH_TYPE_STOCK_ALL    "all"
+#define PHOTOS_SEARCH_TYPE_STOCK_PHOTOS "photos"
+
+typedef struct _PhotosSearchType        PhotosSearchType;
+typedef struct _PhotosSearchTypeClass   PhotosSearchTypeClass;
+typedef struct _PhotosSearchTypePrivate PhotosSearchTypePrivate;
+
+struct _PhotosSearchType
+{
+  GObject parent_instance;
+  PhotosSearchTypePrivate *priv;
+};
+
+struct _PhotosSearchTypeClass
+{
+  GObjectClass parent_class;
+};
+
+GType                photos_search_type_get_type           (void) G_GNUC_CONST;
+
+PhotosSearchType    *photos_search_type_new                (const gchar *id, const gchar *name);
+
+PhotosSearchType    *photos_search_type_new_with_filter    (const gchar *id,
+                                                            const gchar *name,
+                                                            const gchar *filter);
+
+G_END_DECLS
+
+#endif /* PHOTOS_SEARCH_TYPE_H */



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