[gnome-photos/wip/rishi/share-point: 3/11] Add PhotosSharePoint



commit a3ee27003d11e80c07a96a10e6235ae5864b1ee4
Author: Umang Jain <mailumangjain gmail com>
Date:   Wed Jun 29 13:30:53 2016 +0200

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

 src/Makefile.am          |    2 +
 src/photos-share-point.c |  310 ++++++++++++++++++++++++++++++++++++++++++++++
 src/photos-share-point.h |  100 +++++++++++++++
 3 files changed, 412 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 8f5487b..201a308 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -202,6 +202,8 @@ gnome_photos_SOURCES = \
        photos-set-collection-job.h \
        photos-settings.c \
        photos-settings.h \
+       photos-share-point.c \
+       photos-share-point.h \
        photos-single-item-job.c \
        photos-single-item-job.h \
        photos-source.c \
diff --git a/src/photos-share-point.c b/src/photos-share-point.c
new file mode 100644
index 0000000..af50dd5
--- /dev/null
+++ b/src/photos-share-point.c
@@ -0,0 +1,310 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2016 Red Hat, Inc.
+ * Copyright © 2016 Umang Jain
+ *
+ * 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 "photos-filterable.h"
+#include "photos-share-point.h"
+
+
+struct _PhotosSharePointPrivate
+{
+  GIcon *icon;
+  PhotosSource *source;
+  gboolean builtin;
+  gchar *id;
+  gchar *name;
+};
+
+enum
+{
+  PROP_0,
+  PROP_BUILTIN,
+  PROP_ICON,
+  PROP_ID,
+  PROP_NAME,
+  PROP_SOURCE,
+};
+
+static void photos_filterable_interface_init (PhotosFilterableInterface *iface);
+
+
+G_DEFINE_ABSTRACT_TYPE_WITH_CODE (PhotosSharePoint, photos_share_point, G_TYPE_OBJECT,
+                                  G_ADD_PRIVATE (PhotosSharePoint)
+                                  G_IMPLEMENT_INTERFACE (PHOTOS_TYPE_FILTERABLE,
+                                                         photos_filterable_interface_init));
+
+
+static const gchar *
+photos_share_point_get_id (PhotosFilterable *filterable)
+{
+  PhotosSharePoint *self = PHOTOS_SHARE_POINT (filterable);
+  PhotosSharePointPrivate *priv;
+
+  priv = photos_share_point_get_instance_private (self);
+  return priv->id;
+}
+
+
+static void
+photos_share_point_dispose (GObject *object)
+{
+  PhotosSharePoint *self = PHOTOS_SHARE_POINT (object);
+  PhotosSharePointPrivate *priv;
+
+  priv = photos_share_point_get_instance_private (self);
+
+  g_clear_object (&priv->icon);
+  g_clear_object (&priv->source);
+
+  G_OBJECT_CLASS (photos_share_point_parent_class)->dispose (object);
+}
+
+
+static void
+photos_share_point_finalize (GObject *object)
+{
+  PhotosSharePoint *self = PHOTOS_SHARE_POINT (object);
+  PhotosSharePointPrivate *priv;
+
+  priv = photos_share_point_get_instance_private (self);
+
+  g_free (priv->id);
+  g_free (priv->name);
+
+  G_OBJECT_CLASS (photos_share_point_parent_class)->finalize (object);
+}
+
+
+static void
+photos_share_point_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+  PhotosSharePoint *self = PHOTOS_SHARE_POINT (object);
+  PhotosSharePointPrivate *priv;
+
+  priv = photos_share_point_get_instance_private (self);
+
+  switch (prop_id)
+    {
+    case PROP_BUILTIN:
+      g_value_set_boolean (value, priv->builtin);
+      break;
+
+    case PROP_ICON:
+      g_value_set_object (value, priv->icon);
+      break;
+
+    case PROP_ID:
+      g_value_set_string (value, priv->id);
+      break;
+
+    case PROP_NAME:
+      g_value_set_string (value, priv->name);
+      break;
+
+    case PROP_SOURCE:
+      g_value_set_object (value, priv->source);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_share_point_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+  PhotosSharePoint *self = PHOTOS_SHARE_POINT (object);
+  PhotosSharePointPrivate *priv;
+
+  priv = photos_share_point_get_instance_private (self);
+
+  switch (prop_id)
+    {
+    case PROP_BUILTIN:
+      priv->builtin = g_value_get_boolean (value);
+      break;
+
+    case PROP_ICON:
+      priv->icon = G_ICON (g_value_dup_object (value));
+      break;
+
+    case PROP_ID:
+      priv->id = g_value_dup_string (value);
+      break;
+
+    case PROP_NAME:
+      priv->name = g_value_dup_string (value);
+      break;
+
+    case PROP_SOURCE:
+      {
+        GIcon *icon;
+        const gchar *id;
+        const gchar *name;
+
+        priv->source = PHOTOS_SOURCE (g_value_dup_object (value));
+        if (priv->source == NULL)
+          break;
+
+        id = photos_filterable_get_id (PHOTOS_FILTERABLE (priv->source));
+        priv->id = g_strdup (id);
+
+        icon = photos_source_get_icon (priv->source);
+        priv->icon = g_object_ref (icon);
+
+        name = photos_source_get_name (priv->source);
+        priv->name = g_strdup (name);
+        break;
+      }
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_share_point_init (PhotosSharePoint *self)
+{
+}
+
+
+static void
+photos_share_point_class_init (PhotosSharePointClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->dispose = photos_share_point_dispose;
+  object_class->finalize = photos_share_point_finalize;
+  object_class->get_property = photos_share_point_get_property;
+  object_class->set_property = photos_share_point_set_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_BUILTIN,
+                                   g_param_spec_boolean ("builtin",
+                                                         "",
+                                                         "",
+                                                         FALSE,
+                                                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_ICON,
+                                   g_param_spec_object ("icon",
+                                                        "A GIcon",
+                                                        "An icon representing this share point",
+                                                        G_TYPE_ICON,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
+
+  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_READWRITE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_SOURCE,
+                                   g_param_spec_object ("source",
+                                                        "PhotosSource instance",
+                                                        "The online source corresponding to this share 
point",
+                                                        PHOTOS_TYPE_SOURCE,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
+}
+
+
+static void
+photos_filterable_interface_init (PhotosFilterableInterface *iface)
+{
+  iface->get_id = photos_share_point_get_id;
+}
+
+
+GIcon *
+photos_share_point_get_icon (PhotosSharePoint *self)
+{
+  PhotosSharePointPrivate *priv;
+
+  priv = photos_share_point_get_instance_private (self);
+  return priv->icon;
+}
+
+
+const gchar *
+photos_share_point_get_name (PhotosSharePoint *self)
+{
+  PhotosSharePointPrivate *priv;
+
+  priv = photos_share_point_get_instance_private (self);
+  return priv->name;
+}
+
+
+PhotosSource *
+photos_share_point_get_source (PhotosSharePoint *self)
+{
+  PhotosSharePointPrivate *priv;
+
+  priv = photos_share_point_get_instance_private (self);
+  return priv->source;
+}
+
+
+void
+photos_share_point_share_async (PhotosSharePoint *self,
+                                PhotosBaseItem *item,
+                                GCancellable *cancellable,
+                                GAsyncReadyCallback callback,
+                                gpointer user_data)
+{
+  g_return_if_fail (PHOTOS_IS_SHARE_POINT (self));
+  g_return_if_fail (PHOTOS_IS_BASE_ITEM (item));
+
+  PHOTOS_SHARE_POINT_GET_CLASS (self)->share_async (self, item, cancellable, callback, user_data);
+}
+
+
+gboolean
+photos_share_point_share_finish (PhotosSharePoint *self, GAsyncResult *res, GError **error)
+{
+  g_return_val_if_fail (PHOTOS_IS_SHARE_POINT (self), FALSE);
+  g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+  return PHOTOS_SHARE_POINT_GET_CLASS (self)->share_finish (self, res, error);
+}
diff --git a/src/photos-share-point.h b/src/photos-share-point.h
new file mode 100644
index 0000000..c545a46
--- /dev/null
+++ b/src/photos-share-point.h
@@ -0,0 +1,100 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2016 Red Hat, Inc.
+ * Copyright © 2016 Umang Jain
+ *
+ * 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_H
+#define PHOTOS_SHARE_POINT_H
+
+#include <gio/gio.h>
+
+#include "photos-base-item.h"
+#include "photos-source.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_SHARE_POINT (photos_share_point_get_type ())
+
+#define PHOTOS_SHARE_POINT(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_SHARE_POINT, PhotosSharePoint))
+
+#define PHOTOS_SHARE_POINT_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_SHARE_POINT, PhotosSharePointClass))
+
+#define PHOTOS_IS_SHARE_POINT(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_SHARE_POINT))
+
+#define PHOTOS_IS_SHARE_POINT_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_SHARE_POINT))
+
+#define PHOTOS_SHARE_POINT_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_SHARE_POINT, PhotosSharePointClass))
+
+typedef struct _PhotosSharePoint        PhotosSharePoint;
+typedef struct _PhotosSharePointClass   PhotosSharePointClass;
+typedef struct _PhotosSharePointPrivate PhotosSharePointPrivate;
+
+struct _PhotosSharePoint
+{
+  GObject parent_instance;
+};
+
+struct _PhotosSharePointClass
+{
+  GObjectClass parent_class;
+
+  /* virtual methods */
+  void        (*share_async)    (PhotosSharePoint *self,
+                                 PhotosBaseItem *item,
+                                 GCancellable *cancellable,
+                                 GAsyncReadyCallback callback,
+                                 gpointer user_data);
+  gboolean    (*share_finish)   (PhotosSharePoint *self, GAsyncResult *res, GError **error);
+};
+
+GType                   photos_share_point_get_type               (void) G_GNUC_CONST;
+
+GIcon                  *photos_share_point_get_icon               (PhotosSharePoint *self);
+
+const gchar            *photos_share_point_get_name               (PhotosSharePoint *self);
+
+PhotosSource           *photos_share_point_get_source             (PhotosSharePoint *self);
+
+void                    photos_share_point_share_async            (PhotosSharePoint *self,
+                                                                   PhotosBaseItem *item,
+                                                                   GCancellable *cancellable,
+                                                                   GAsyncReadyCallback callback,
+                                                                   gpointer user_data);
+
+gboolean                photos_share_point_share_finish           (PhotosSharePoint *self,
+                                                                   GAsyncResult *res,
+                                                                   GError **error);
+
+G_END_DECLS
+
+#endif /* PHOTOS_SHARE_POINT_H */


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