[gnome-photos] Add PhotosSearchController



commit 43b0287c028fdb226a02b9a6153b32893279370c
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Dec 1 02:05:58 2013 +0100

    Add PhotosSearchController

 src/Makefile.am                |    2 +
 src/photos-search-controller.c |  153 ++++++++++++++++++++++++++++++++++++++++
 src/photos-search-controller.h |   84 ++++++++++++++++++++++
 3 files changed, 239 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 93a0d1f..4e12c8d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -152,6 +152,8 @@ gnome_photos_SOURCES = \
        photos-query-builder.c \
        photos-remote-display-manager.c \
        photos-remote-display-manager.h \
+       photos-search-controller.c \
+       photos-search-controller.h \
        photos-search-type.c \
        photos-search-type.h \
        photos-search-type-manager.c \
diff --git a/src/photos-search-controller.c b/src/photos-search-controller.c
new file mode 100644
index 0000000..658d413
--- /dev/null
+++ b/src/photos-search-controller.c
@@ -0,0 +1,153 @@
+/*
+ * 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 <glib.h>
+#include <tracker-sparql.h>
+
+#include "photos-search-controller.h"
+
+
+struct _PhotosSearchControllerPrivate
+{
+  gchar *str;
+};
+
+enum
+{
+  SEARCH_STRING_CHANGED,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+
+G_DEFINE_TYPE_WITH_PRIVATE (PhotosSearchController, photos_search_controller, G_TYPE_OBJECT);
+
+
+static GObject *
+photos_search_controller_constructor (GType type, guint n_construct_params, GObjectConstructParam 
*construct_params)
+{
+  static GObject *self = NULL;
+
+  if (self == NULL)
+    {
+      self = G_OBJECT_CLASS (photos_search_controller_parent_class)->constructor (type,
+                                                                                  n_construct_params,
+                                                                                  construct_params);
+      g_object_add_weak_pointer (self, (gpointer) &self);
+      return self;
+    }
+
+  return g_object_ref (self);
+}
+
+
+static void
+photos_search_controller_finalize (GObject *object)
+{
+  PhotosSearchController *self = PHOTOS_SEARCH_CONTROLLER (object);
+
+  g_free (self->priv->str);
+
+  G_OBJECT_CLASS (photos_search_controller_parent_class)->finalize (object);
+}
+
+
+static void
+photos_search_controller_init (PhotosSearchController *self)
+{
+  PhotosSearchControllerPrivate *priv;
+
+  self->priv = photos_search_controller_get_instance_private (self);
+  priv = self->priv;
+
+  priv->str = g_strdup ("");
+}
+
+
+static void
+photos_search_controller_class_init (PhotosSearchControllerClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->constructor = photos_search_controller_constructor;
+  object_class->finalize = photos_search_controller_finalize;
+
+  signals[SEARCH_STRING_CHANGED] = g_signal_new ("search-string-changed",
+                                                  G_TYPE_FROM_CLASS (class),
+                                                  G_SIGNAL_RUN_LAST,
+                                                  G_STRUCT_OFFSET (PhotosSearchControllerClass,
+                                                                   search_string_changed),
+                                                  NULL, /*accumulator */
+                                                  NULL, /*accu_data */
+                                                  g_cclosure_marshal_VOID__STRING,
+                                                  G_TYPE_NONE,
+                                                  1,
+                                                  G_TYPE_STRING);
+}
+
+
+PhotosSearchController *
+photos_search_controller_dup_singleton (void)
+{
+  return g_object_new (PHOTOS_TYPE_SEARCH_CONTROLLER, NULL);
+}
+
+
+const gchar *
+photos_search_controller_get_string (PhotosSearchController *self)
+{
+  return self->priv->str;
+}
+
+
+gchar **
+photos_search_controller_get_terms (PhotosSearchController *self)
+{
+  gchar *str;
+  gchar **terms;
+
+  str = tracker_sparql_escape_string (self->priv->str);
+  /* TODO: find out what str.replace(/ + /g, ' ') does */
+  terms = g_strsplit (str, " ", -1);
+  g_free (str);
+  return terms;
+}
+
+
+void
+photos_search_controller_set_string (PhotosSearchController *self, const gchar *str)
+{
+  PhotosSearchControllerPrivate *priv = self->priv;
+
+  if (g_strcmp0 (priv->str, str) == 0)
+    return;
+
+  g_free (priv->str);
+  priv->str = g_strdup (str);
+  g_signal_emit (self, signals[SEARCH_STRING_CHANGED], 0, priv->str);
+}
diff --git a/src/photos-search-controller.h b/src/photos-search-controller.h
new file mode 100644
index 0000000..e2337a2
--- /dev/null
+++ b/src/photos-search-controller.h
@@ -0,0 +1,84 @@
+/*
+ * 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
+ */
+
+#ifndef PHOTOS_SEARCH_CONTROLLER_H
+#define PHOTOS_SEARCH_CONTROLLER_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_SEARCH_CONTROLLER (photos_search_controller_get_type ())
+
+#define PHOTOS_SEARCH_CONTROLLER(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_SEARCH_CONTROLLER, PhotosSearchController))
+
+#define PHOTOS_SEARCH_CONTROLLER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_SEARCH_CONTROLLER, PhotosSearchControllerClass))
+
+#define PHOTOS_IS_SEARCH_CONTROLLER(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_SEARCH_CONTROLLER))
+
+#define PHOTOS_IS_SEARCH_CONTROLLER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_SEARCH_CONTROLLER))
+
+#define PHOTOS_SEARCH_CONTROLLER_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_SEARCH_CONTROLLER, PhotosSearchControllerClass))
+
+typedef struct _PhotosSearchController        PhotosSearchController;
+typedef struct _PhotosSearchControllerClass   PhotosSearchControllerClass;
+typedef struct _PhotosSearchControllerPrivate PhotosSearchControllerPrivate;
+
+struct _PhotosSearchController
+{
+  GObject parent_instance;
+  PhotosSearchControllerPrivate *priv;
+};
+
+struct _PhotosSearchControllerClass
+{
+  GObjectClass parent_class;
+
+  /* signals */
+  void (*search_string_changed) (PhotosSearchController *self, const gchar *str);
+};
+
+GType                      photos_search_controller_get_type       (void) G_GNUC_CONST;
+
+PhotosSearchController    *photos_search_controller_dup_singleton  (void);
+
+const gchar               *photos_search_controller_get_string     (PhotosSearchController *self);
+
+gchar                    **photos_search_controller_get_terms      (PhotosSearchController *self);
+
+void                       photos_search_controller_set_string     (PhotosSearchController *self, const 
gchar *str);
+
+G_END_DECLS
+
+#endif /* PHOTOS_SEARCH_CONTROLLER_H */


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