[gnome-photos/wip/rishi/share-point: 13/18] Add PhotosShareDialog



commit 34cdf2e3634059967c836217bd6246c1c6a4140f
Author: Umang Jain <mailumangjain gmail com>
Date:   Fri Jul 15 18:41:51 2016 +0530

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

 src/Makefile.am            |    2 +
 src/photos-share-dialog.c  |  192 ++++++++++++++++++++++++++++++++++++++++++++
 src/photos-share-dialog.h  |   64 +++++++++++++++
 src/photos-share-dialog.ui |   51 ++++++++++++
 src/photos.gresource.xml   |    1 +
 5 files changed, 310 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index ec35ab7..2fd11b1 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-dialog.c \
+       photos-share-dialog.h \
        photos-share-point.c \
        photos-share-point.h \
        photos-share-point-email.c \
diff --git a/src/photos-share-dialog.c b/src/photos-share-dialog.c
new file mode 100644
index 0000000..61c78bf
--- /dev/null
+++ b/src/photos-share-dialog.c
@@ -0,0 +1,192 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * 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.
+ */
+
+
+#include "config.h"
+
+#include <glib.h>
+
+#include "photos-share-dialog.h"
+#include "photos-share-point-manager.h"
+
+
+struct _PhotosShareDialog
+{
+  GtkDialog parent_instance;
+  PhotosBaseManager *shr_pnt_mngr;
+  PhotosSharePoint *selected;
+  GtkWidget *flow_box;
+  PhotosBaseItem *item;
+};
+
+struct _PhotosShareDialogClass
+{
+  GtkDialogClass parent_class;
+};
+
+enum
+{
+  PROP_0,
+  PROP_ITEM
+};
+
+
+G_DEFINE_TYPE (PhotosShareDialog, photos_share_dialog, GTK_TYPE_DIALOG);
+
+
+static void
+photos_share_dialog_child_activated (PhotosShareDialog *self, GtkFlowBoxChild *child)
+{
+  g_return_if_fail (PHOTOS_IS_SHARE_DIALOG (self));
+  g_return_if_fail (GTK_IS_FLOW_BOX_CHILD (child));
+
+  self->selected = PHOTOS_SHARE_POINT (g_object_get_data (G_OBJECT (child), "share-point"));
+  g_return_if_fail (PHOTOS_IS_SHARE_POINT (self->selected));
+
+  gtk_dialog_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
+}
+
+
+static void
+photos_share_dialog_constructed (GObject *object)
+{
+  PhotosShareDialog *self = PHOTOS_SHARE_DIALOG (object);
+  GHashTable *share_points;
+  GHashTableIter iter;
+  PhotosSharePoint *share_point;
+
+  G_OBJECT_CLASS (photos_share_dialog_parent_class)->constructed (object);
+
+  share_points = photos_base_manager_get_objects (PHOTOS_BASE_MANAGER (self->shr_pnt_mngr));
+
+  g_hash_table_iter_init (&iter, share_points);
+  while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &share_point))
+    {
+      GIcon *icon;
+      GtkWidget *child;
+      GtkWidget *grid;
+      GtkWidget *image;
+      GtkWidget *label;
+      const gchar *name;
+
+      child = gtk_flow_box_child_new ();
+      gtk_widget_set_halign (child, GTK_ALIGN_START);
+      gtk_container_set_border_width (GTK_CONTAINER (child), 18);
+      gtk_container_add (GTK_CONTAINER (self->flow_box), child);
+
+      grid = gtk_grid_new ();
+      gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
+      gtk_grid_set_row_spacing (GTK_GRID (grid), 18);
+      gtk_container_add (GTK_CONTAINER (child), grid);
+
+      icon = photos_share_point_get_icon (share_point);
+      image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
+      gtk_container_add (GTK_CONTAINER (grid), image);
+
+      name = photos_share_point_get_name (share_point);
+      label = gtk_label_new (name);
+      gtk_container_add (GTK_CONTAINER (grid), label);
+
+      g_object_set_data_full (G_OBJECT (child), "share-point", g_object_ref (share_point), g_object_unref);
+    }
+}
+
+
+static void
+photos_share_dialog_dispose (GObject *object)
+{
+  PhotosShareDialog *self = PHOTOS_SHARE_DIALOG (object);
+
+  g_clear_object (&self->item);
+  g_clear_object (&self->shr_pnt_mngr);
+
+  G_OBJECT_CLASS (photos_share_dialog_parent_class)->dispose (object);
+}
+
+
+static void
+photos_share_dialog_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+  PhotosShareDialog *self = PHOTOS_SHARE_DIALOG (object);
+
+  switch (prop_id)
+    {
+    case PROP_ITEM:
+      self->item = PHOTOS_BASE_ITEM (g_value_dup_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_share_dialog_init (PhotosShareDialog *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+  self->shr_pnt_mngr = photos_share_point_manager_dup_singleton ();
+}
+
+
+static void
+photos_share_dialog_class_init (PhotosShareDialogClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+
+  object_class->constructed = photos_share_dialog_constructed;
+  object_class->dispose = photos_share_dialog_dispose;
+  object_class->set_property = photos_share_dialog_set_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_ITEM,
+                                   g_param_spec_object ("item",
+                                                        "PhotosBaseItem object",
+                                                        "The item to share",
+                                                        PHOTOS_TYPE_BASE_ITEM,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Photos/share-dialog.ui");
+  gtk_widget_class_bind_template_child (widget_class, PhotosShareDialog, flow_box);
+  gtk_widget_class_bind_template_callback (widget_class, photos_share_dialog_child_activated);
+}
+
+
+GtkWidget *
+photos_share_dialog_new (GtkWindow *parent, PhotosBaseItem *item)
+{
+  g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
+  g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (item), NULL);
+
+  return g_object_new (PHOTOS_TYPE_SHARE_DIALOG,
+                       "item", item,
+                       "transient-for", parent,
+                       "use-header-bar", TRUE,
+                       NULL);
+}
+
+
+PhotosSharePoint *
+photos_share_dialog_get_selected_share_point (PhotosShareDialog *self)
+{
+  return self->selected;
+}
diff --git a/src/photos-share-dialog.h b/src/photos-share-dialog.h
new file mode 100644
index 0000000..0ecbb89
--- /dev/null
+++ b/src/photos-share-dialog.h
@@ -0,0 +1,64 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * 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.
+ */
+
+#ifndef PHOTOS_SHARE_DIALOG_H
+#define PHOTOS_SHARE_DIALOG_H
+
+#include <gtk/gtk.h>
+
+#include "photos-base-item.h"
+#include "photos-share-point.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_SHARE_DIALOG (photos_share_dialog_get_type ())
+
+#define PHOTOS_SHARE_DIALOG(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_SHARE_DIALOG, PhotosShareDialog))
+
+#define PHOTOS_SHARE_DIALOG_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+   PHOTOS_TYPE_SHARE_DIALOG, PhotosShareDialogClass))
+
+#define PHOTOS_IS_SHARE_DIALOG(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_SHARE_DIALOG))
+
+#define PHOTOS_IS_SHARE_DIALOG_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+   PHOTOS_TYPE_SHARE_DIALOG))
+
+#define PHOTOS_SHARE_DIALOG_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+   PHOTOS_TYPE_SHARE_DIALOG, PhotosShareDialogClass))
+
+typedef struct _PhotosShareDialog      PhotosShareDialog;
+typedef struct _PhotosShareDialogClass PhotosShareDialogClass;
+
+GType               photos_share_dialog_get_type                 (void) G_GNUC_CONST;
+
+GtkWidget          *photos_share_dialog_new                      (GtkWindow *parent, PhotosBaseItem *item);
+
+PhotosSharePoint   *photos_share_dialog_get_selected_share_point (PhotosShareDialog *self);
+
+G_END_DECLS
+
+#endif /* PHOTOS_SHARE_DIALOG_H */
diff --git a/src/photos-share-dialog.ui b/src/photos-share-dialog.ui
new file mode 100644
index 0000000..611073e
--- /dev/null
+++ b/src/photos-share-dialog.ui
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Photos - access, organize and share your photos on GNOME
+ 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.
+-->
+<interface>
+  <template class="PhotosShareDialog" parent="GtkDialog">
+    <property name="border_width">24</property>
+    <property name="modal">1</property>
+    <property name="resizable">0</property>
+    <property name="skip_taskbar_hint">1</property>
+    <property name="title" translatable="yes" context="dialog title">Share</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkFlowBox" id="flow_box">
+            <property name="can_focus">1</property>
+            <property name="column_spacing">18</property>
+            <property name="homogeneous">1</property>
+            <property name="row_spacing">18</property>
+            <property name="selection_mode">none</property>
+            <signal name="child-activated"
+                    object="PhotosShareDialog"
+                    swapped="yes"
+                    handler="photos_share_dialog_child_activated" />
+          </object>
+          <packing>
+            <property name="expand">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/photos.gresource.xml b/src/photos.gresource.xml
index 8669a0c..34ed09c 100644
--- a/src/photos.gresource.xml
+++ b/src/photos.gresource.xml
@@ -8,6 +8,7 @@
     <file alias="preview-menu.ui" preprocess="xml-stripblanks" 
compressed="true">photos-preview-menu.ui</file>
     <file alias="selection-menu.ui" preprocess="xml-stripblanks" 
compressed="true">photos-selection-menu.ui</file>
     <file alias="selection-toolbar.ui" preprocess="xml-stripblanks" 
compressed="true">photos-selection-toolbar.ui</file>
+    <file alias="share-dialog.ui" preprocess="xml-stripblanks" 
compressed="true">photos-share-dialog.ui</file>
     <file alias="sidebar-radio-checked.svg" preprocess="to-pixdata">../data/sidebar-radio-checked.svg</file>
     <file alias="sidebar-radio-prelight.svg" 
preprocess="to-pixdata">../data/sidebar-radio-prelight.svg</file>
     <file alias="sidebar-radio-selected.svg" 
preprocess="to-pixdata">../data/sidebar-radio-selected.svg</file>


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