[gnome-photos/wip/rishi/share-point] Add PhotosSharePointManager



commit 7e37d0581201a124234cdc80502a06bab86da28c
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Jun 29 09:52:55 2016 +0200

    Add PhotosSharePointManager

 src/Makefile.am                  |    2 +
 src/photos-share-point-manager.c |  150 ++++++++++++++++++++++++++++++++++++++
 src/photos-share-point-manager.h |   47 ++++++++++++
 3 files changed, 199 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 0cb21e6..85c631e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -200,6 +200,8 @@ gnome_photos_SOURCES = \
        photos-set-collection-job.h \
        photos-settings.c \
        photos-settings.h \
+       photos-share-point-manager.c \
+       photos-share-point-manager.h \
        photos-single-item-job.c \
        photos-single-item-job.h \
        photos-source.c \
diff --git a/src/photos-share-point-manager.c b/src/photos-share-point-manager.c
new file mode 100644
index 0000000..956af5c
--- /dev/null
+++ b/src/photos-share-point-manager.c
@@ -0,0 +1,150 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2016 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 <glib.h>
+#include <gio/gio.h>
+
+#include "photos-filterable.h"
+#include "photos-search-context.h"
+#include "photos-share-point.h"
+#include "photos-share-point-manager.h"
+#include "photos-source.h"
+
+
+struct _PhotosSharePointManager
+{
+  PhotosBaseManager parent_instance;
+  PhotosBaseManager *src_mngr;
+};
+
+struct _PhotosSharePointManagerClass
+{
+  PhotosBaseManagerClass parent_class;
+};
+
+
+G_DEFINE_TYPE (PhotosSharePointManager, photos_share_point_manager, PHOTOS_TYPE_BASE_MANAGER);
+
+
+static void
+photos_share_point_manager_refresh_sources (PhotosSharePointManager *self)
+{
+  GHashTable *new_share_points;
+  GHashTable *sources;
+  GHashTableIter iter;
+  PhotosSource *source;
+
+  sources = photos_base_manager_get_objects (self->src_mngr);
+  new_share_points = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+
+  g_hash_table_iter_init (&iter, sources);
+  while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &source))
+    {
+      PhotosSharePoint *share_point;
+      const gchar *id;
+
+      if (/* source is not suitable for sharing */)
+        continue;
+
+      share_point = photos_share_point_new_from_source (source);
+      id = photos_filterable_get_id (PHOTOS_FILTERABLE (share_point));
+      g_hash_table_insert (new_share_points, g_strdup (id), g_object_ref (share_point));
+      g_object_unref (share_point);
+    }
+
+  photos_base_manager_process_new_objects (PHOTOS_BASE_MANAGER (self), new_share_points);
+  g_hash_table_unref (new_share_points);
+}
+
+
+static GObject *
+photos_share_point_manager_constructor (GType type,
+                                        guint n_construct_params,
+                                        GObjectConstructParam *construct_params)
+{
+  static GObject *self = NULL;
+
+  if (self == NULL)
+    {
+      self = G_OBJECT_CLASS (photos_share_point_manager_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_share_point_manager_dispose (GObject *object)
+{
+  PhotosSharePointManager *self = PHOTOS_SHARE_POINT_MANAGER (object);
+
+  g_clear_object (&self->src_mngr);
+
+  G_OBJECT_CLASS (photos_share_point_manager_parent_class)->dispose (object);
+}
+
+
+static void
+photos_share_point_manager_init (PhotosSharePointManager *self)
+{
+  GApplication *app;
+  PhotosSearchContextState *state;
+
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  self->src_mngr = g_object_ref (state->src_mngr);
+  g_signal_connect_object (self->src_mngr,
+                           "object-added",
+                           G_CALLBACK (photos_share_point_manager_refresh_sources),
+                           self,
+                           G_CONNECT_SWAPPED);
+  g_signal_connect_object (self->src_mngr,
+                           "object-removed",
+                           G_CALLBACK (photos_share_point_manager_refresh_sources),
+                           self,
+                           G_CONNECT_SWAPPED);
+
+  photos_share_point_manager_refresh_sources (self);
+}
+
+
+static void
+photos_share_point_manager_class_init (PhotosSharePointManagerClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->constructor = photos_share_point_manager_constructor;
+  object_class->dispose = photos_share_point_manager_dispose;
+}
+
+
+PhotosBaseManager *
+photos_share_point_manager_dup_singleton (void)
+{
+  return g_object_new (PHOTOS_TYPE_SHARE_POINT_MANAGER, NULL);
+}
diff --git a/src/photos-share-point-manager.h b/src/photos-share-point-manager.h
new file mode 100644
index 0000000..3ce5776
--- /dev/null
+++ b/src/photos-share-point-manager.h
@@ -0,0 +1,47 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2016 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_SHARE_POINT_MANAGER_H
+#define PHOTOS_SHARE_POINT_MANAGER_H
+
+#include "photos-base-manager.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_SHARE_POINT_MANAGER (photos_share_point_manager_get_type ())
+
+#define PHOTOS_SHARE_POINT_MANAGER(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_SHARE_POINT_MANAGER, PhotosSharePointManager))
+
+#define PHOTOS_IS_SHARE_POINT_MANAGER(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_SHARE_POINT_MANAGER))
+
+typedef struct _PhotosSharePointManager      PhotosSharePointManager;
+typedef struct _PhotosSharePointManagerClass PhotosSharePointManagerClass;
+
+GType                     photos_share_point_manager_get_type           (void) G_GNUC_CONST;
+
+PhotosBaseManager        *photos_share_point_manager_dup_singleton      (void);
+
+G_END_DECLS
+
+#endif /* PHOTOS_SHARE_POINT_MANAGER_H */


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