[gnome-photos] Add PhotosSourceManager
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Add PhotosSourceManager
- Date: Wed, 2 May 2012 12:17:41 +0000 (UTC)
commit b2f1864204a44dba71737a8b85606945be488ab5
Author: Debarshi Ray <debarshir gnome org>
Date: Wed May 2 14:15:38 2012 +0200
Add PhotosSourceManager
po/POTFILES.in | 1 +
src/Makefile.am | 2 +
src/photos-source-manager.c | 172 +++++++++++++++++++++++++++++++++++++++++++
src/photos-source-manager.h | 70 +++++++++++++++++
4 files changed, 245 insertions(+), 0 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index e672f3d..5b022cb 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -5,3 +5,4 @@ src/gd-main-toolbar.c
src/photos-application.c
src/photos-main-window.c
src/photos-selection-toolbar.c
+src/photos-source-manager.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 5bd4c66..3b745db 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -58,6 +58,8 @@ gnome_photos_SOURCES = \
photos-selection-toolbar.h \
photos-source.c \
photos-source.h \
+ photos-source-manager.c \
+ photos-source-manager.h \
photos-utils.c \
photos-utils.h \
photos-view.c \
diff --git a/src/photos-source-manager.c b/src/photos-source-manager.c
new file mode 100644
index 0000000..379c439
--- /dev/null
+++ b/src/photos-source-manager.c
@@ -0,0 +1,172 @@
+/*
+ * 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"
+#define GOA_API_IS_SUBJECT_TO_CHANGE
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <goa/goa.h>
+
+#include "photos-source.h"
+#include "photos-source-manager.h"
+
+
+struct _PhotosSourceManagerPrivate
+{
+ GoaClient *client;
+};
+
+
+G_DEFINE_TYPE (PhotosSourceManager, photos_source_manager, PHOTOS_TYPE_BASE_MANAGER);
+
+
+static void
+photos_source_manager_client_account_added (GoaClient *client, GoaObject *object, gpointer user_data)
+{
+ PhotosSourceManager *self = PHOTOS_SOURCE_MANAGER (user_data);
+ photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (object));
+}
+
+
+static void
+photos_source_manager_client_account_changed (GoaClient *client, GoaObject *object, gpointer user_data)
+{
+ PhotosSourceManager *self = PHOTOS_SOURCE_MANAGER (user_data);
+ photos_base_manager_remove_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (object));
+ photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (object));
+}
+
+
+static void
+photos_source_manager_client_account_removed (GoaClient *client, GoaObject *object, gpointer user_data)
+{
+ PhotosSourceManager *self = PHOTOS_SOURCE_MANAGER (user_data);
+ photos_base_manager_remove_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (object));
+}
+
+
+static void
+photos_source_manager_refresh_accounts (PhotosSourceManager *self)
+{
+ PhotosSourceManagerPrivate *priv = self->priv;
+ GList *accounts;
+ GList *l;
+
+ for (l = accounts; l != NULL; l = l->next)
+ {
+ if (goa_object_peek_account (GOA_OBJECT (l->data)) == NULL)
+ continue;
+
+ /* TODO: uncomment when we start supporting online providers */
+ /* photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (l->data)); */
+ }
+
+ g_list_free_full (accounts, g_object_unref);
+}
+
+
+static void
+photos_source_manager_client_new_ready (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ PhotosSourceManager *self = PHOTOS_SOURCE_MANAGER (user_data);
+ PhotosSourceManagerPrivate *priv = self->priv;
+
+ priv->client = goa_client_new_finish (res, NULL); /* TODO: use GError */
+ if (priv->client == NULL)
+ return;
+
+ g_signal_connect (priv->client, "account-added", G_CALLBACK (photos_source_manager_client_account_added), self);
+ g_signal_connect (priv->client, "account-changed", G_CALLBACK (photos_source_manager_client_account_changed), self);
+ g_signal_connect (priv->client, "account-removed", G_CALLBACK (photos_source_manager_client_account_removed), self);
+
+ photos_source_manager_refresh_accounts (self);
+ photos_base_manager_set_active_object_by_id (PHOTOS_BASE_MANAGER (self), PHOTOS_SOURCE_STOCK_ALL);
+}
+
+
+static GObject *
+photos_source_manager_constructor (GType type,
+ guint n_construct_params,
+ GObjectConstructParam *construct_params)
+{
+ static GObject *self = NULL;
+
+ if (self == NULL)
+ {
+ self = G_OBJECT_CLASS (photos_source_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_source_manager_dispose (GObject *object)
+{
+ PhotosSourceManager *self = PHOTOS_SOURCE_MANAGER (object);
+
+ g_clear_object (&self->priv->client);
+
+ G_OBJECT_CLASS (photos_source_manager_parent_class)->dispose (object);
+}
+
+
+static void
+photos_source_manager_init (PhotosSourceManager *self)
+{
+ PhotosSource *source;
+
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, PHOTOS_TYPE_SOURCE_MANAGER, PhotosSourceManagerPrivate);
+
+ source = photos_source_new (PHOTOS_SOURCE_STOCK_ALL, _("All"), TRUE);
+ photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (source));
+ g_object_unref (source);
+
+ source = photos_source_new (PHOTOS_SOURCE_STOCK_LOCAL, _("Local"), TRUE);
+ photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (source));
+ g_object_unref (source);
+
+ goa_client_new (NULL, photos_source_manager_client_new_ready, self);
+}
+
+
+static void
+photos_source_manager_class_init (PhotosSourceManagerClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->constructor = photos_source_manager_constructor;
+ object_class->dispose = photos_source_manager_dispose;
+
+ g_type_class_add_private (class, sizeof (PhotosSourceManagerPrivate));
+}
+
+
+PhotosBaseManager *
+photos_source_manager_new (void)
+{
+ return g_object_new (PHOTOS_TYPE_SOURCE_MANAGER, NULL);
+}
diff --git a/src/photos-source-manager.h b/src/photos-source-manager.h
new file mode 100644
index 0000000..ad50b05
--- /dev/null
+++ b/src/photos-source-manager.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_SOURCE_MANAGER_H
+#define PHOTOS_SOURCE_MANAGER_H
+
+#include "photos-base-manager.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_SOURCE_MANAGER (photos_base_manager_get_type ())
+#define PHOTOS_SOURCE_MANAGER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ PHOTOS_TYPE_SOURCE_MANAGER, PhotosSourceManager))
+
+#define PHOTOS_SOURCE_MANAGER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ PHOTOS_TYPE_SOURCE_MANAGER, PhotosSourceManagerClass))
+
+#define PHOTOS_IS_SOURCE_MANAGER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ PHOTOS_TYPE_SOURCE_MANAGER))
+
+#define PHOTOS_IS_SOURCE_MANAGER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ PHOTOS_TYPE_SOURCE_MANAGER))
+
+#define PHOTOS_SOURCE_MANAGER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ PHOTOS_TYPE_SOURCE_MANAGER, PhotosSourceManagerClass))
+
+typedef struct _PhotosSourceManager PhotosSourceManager;
+typedef struct _PhotosSourceManagerClass PhotosSourceManagerClass;
+typedef struct _PhotosSourceManagerPrivate PhotosSourceManagerPrivate;
+
+struct _PhotosSourceManager
+{
+ PhotosBaseManager parent_instance;
+ PhotosSourceManagerPrivate *priv;
+};
+
+struct _PhotosSourceManagerClass
+{
+ PhotosBaseManagerClass parent_class;
+};
+
+GType photos_source_manager_get_type (void) G_GNUC_CONST;
+
+PhotosBaseManager *photos_source_manager_new (void);
+
+G_END_DECLS
+
+#endif /* PHOTOS_SOURCE_MANAGER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]