[gnome-photos/wip/uajain/de_dup: 2/11] Add PhotosSharePointManager



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

    Add PhotosSharePointManager
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751181

 src/Makefile.am                  |    2 +
 src/photos-share-point-manager.c |  186 ++++++++++++++++++++++++++++++++++++++
 src/photos-share-point-manager.h |   51 +++++++++++
 3 files changed, 239 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 201a308..ced64c9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -204,6 +204,8 @@ gnome_photos_SOURCES = \
        photos-settings.h \
        photos-share-point.c \
        photos-share-point.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..b0044c3
--- /dev/null
+++ b/src/photos-share-point-manager.c
@@ -0,0 +1,186 @@
+/*
+ * 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.
+ */
+
+/* Based on code from:
+ *   + Documents
+ */
+
+
+#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"
+#include "photos-utils.h"
+
+
+struct _PhotosSharePointManager
+{
+  PhotosBaseManager parent_instance;
+  GIOExtensionPoint *extension_point;
+  PhotosBaseManager *src_mngr;
+};
+
+struct _PhotosSharePointManagerClass
+{
+  PhotosBaseManagerClass parent_class;
+};
+
+
+G_DEFINE_TYPE (PhotosSharePointManager, photos_share_point_manager, PHOTOS_TYPE_BASE_MANAGER);
+
+
+static PhotosSharePoint *
+photos_share_point_manager_create_share_point (PhotosSharePointManager *self, PhotosSource *source)
+{
+  GIOExtension *extension;
+  GType type;
+  GoaAccount *account;
+  GoaObject *object;
+  PhotosSharePoint *ret_val = NULL;
+  const gchar *provider_type;
+
+  object = photos_source_get_goa_object (source);
+  if (object == NULL)
+    goto out;
+
+  account = goa_object_peek_account (object);
+  provider_type = goa_account_get_provider_type (account);
+  extension = g_io_extension_point_get_extension_by_name (self->extension_point, provider_type);
+  if (extension == NULL)
+    goto out;
+
+  type = g_io_extension_get_type (extension);
+  ret_val = PHOTOS_SHARE_POINT (g_object_new (type, "source", source, NULL));
+
+ out:
+  return ret_val;
+}
+
+
+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;
+
+      share_point = photos_share_point_manager_create_share_point (self, source);
+      if (share_point == NULL)
+        continue;
+
+      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->extension_point = g_io_extension_point_lookup (PHOTOS_SHARE_POINT_EXTENSION_POINT_NAME);
+
+  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..3344ee8
--- /dev/null
+++ b/src/photos-share-point-manager.h
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+/* Based on code from:
+ *   + Documents
+ */
+
+#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]