[gnome-photos/wip/rishi/collection: 17/19] Add PhotosImportDialog



commit 9eb404ef35b020cc6a528de008179776e20df2bf
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Feb 5 13:12:40 2018 +0100

    Add PhotosImportDialog
    
    https://gitlab.gnome.org/GNOME/gnome-photos/issues/29

 po/POTFILES.in              |   1 +
 src/Makefile.am             |   3 +
 src/photos-import-dialog.c  | 272 ++++++++++++++++++++++++++++++++++++++++++++
 src/photos-import-dialog.h  |  35 ++++++
 src/photos-import-dialog.ui | 148 ++++++++++++++++++++++++
 src/photos.gresource.xml    |   1 +
 6 files changed, 460 insertions(+)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 7859510e..fa44a457 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -17,6 +17,7 @@ src/photos-facebook-item.c
 src/photos-flickr-item.c
 src/photos-google-item.c
 src/photos-help-overlay.ui
+src/photos-import-dialog.ui
 src/photos-indexing-notification.c
 src/photos-local-item.c
 src/photos-main-toolbar.c
diff --git a/src/Makefile.am b/src/Makefile.am
index fbbf7f8b..22a33274 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -124,6 +124,8 @@ gnome_photos_SOURCES = \
        photos-image-view.h \
        photos-image-view-helper.c \
        photos-image-view-helper.h \
+       photos-import-dialog.c \
+       photos-import-dialog.h \
        photos-indexing-notification.c \
        photos-indexing-notification.h \
        photos-item-manager.c \
@@ -383,6 +385,7 @@ EXTRA_DIST = \
        photos-embed.ui \
        photos-export-dialog.ui \
        photos-help-overlay.ui \
+       photos-import-dialog.ui \
        photos-main-toolbar.ui \
        photos-main-window.ui \
        photos-marshalers.list \
diff --git a/src/photos-import-dialog.c b/src/photos-import-dialog.c
new file mode 100644
index 00000000..b6abba31
--- /dev/null
+++ b/src/photos-import-dialog.c
@@ -0,0 +1,272 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2018 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "config.h"
+
+#include <gio/gio.h>
+#include <tracker-sparql.h>
+
+#include "photos-import-dialog.h"
+#include "photos-item-manager.h"
+#include "photos-query-builder.h"
+#include "photos-search-context.h"
+#include "photos-tracker-queue.h"
+
+
+struct _PhotosImportDialog
+{
+  GtkDialog parent_instance;
+  GCancellable *cancellable;
+  GtkWidget *add_existing_button;
+  GtkWidget *add_existing_collection_name_button;
+  GtkWidget *add_existing_label;
+  GtkWidget *collections_popover;
+  GtkWidget *collections_popover_grid;
+  GtkWidget *collections_popover_search_entry;
+  GtkWidget *create_new_button;
+  GtkWidget *create_new_entry;
+  GtkWidget *create_new_label;
+  PhotosBaseManager *item_mngr;
+  PhotosTrackerQueue *queue;
+  gint64 time;
+};
+
+enum
+{
+  PROP_0,
+  PROP_TIME
+};
+
+
+G_DEFINE_TYPE (PhotosImportDialog, photos_import_dialog, GTK_TYPE_DIALOG);
+
+
+static void
+photos_import_dialog_fetch_collections_local_cursor_next (GObject *source_object,
+                                                          GAsyncResult *res,
+                                                          gpointer user_data)
+{
+  PhotosImportDialog *self;
+  g_autoptr (PhotosBaseItem) item = NULL;
+  TrackerSparqlCursor *cursor = TRACKER_SPARQL_CURSOR (source_object);
+  gboolean success;
+
+  {
+    g_autoptr (GError) error = NULL;
+
+    /* Note that tracker_sparql_cursor_next_finish can return FALSE even
+     * without an error.
+     */
+    success = tracker_sparql_cursor_next_finish (cursor, res, &error);
+    if (error != NULL)
+      {
+        if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+          g_warning ("Unable to fetch local collections: %s", error->message);
+
+        goto out;
+      }
+  }
+
+  self = PHOTOS_IMPORT_DIALOG (user_data);
+
+  if (!success)
+    goto out;
+
+  item = photos_item_manager_create_item (self->item_mngr, G_TYPE_NONE, cursor, FALSE);
+
+ out:
+  return;
+}
+
+
+static void
+photos_import_dialog_fetch_collections_local_query_executed (GObject *source_object,
+                                                             GAsyncResult *res,
+                                                             gpointer user_data)
+{
+  PhotosImportDialog *self;
+  TrackerSparqlConnection *connection = TRACKER_SPARQL_CONNECTION (source_object);
+  TrackerSparqlCursor *cursor = NULL; /* TODO: use g_autoptr */
+
+  {
+    g_autoptr (GError) error = NULL;
+
+    cursor = tracker_sparql_connection_query_finish (connection, res, &error);
+    if (error != NULL)
+      {
+        if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+          g_warning ("Unable to fetch local collections: %s", error->message);
+
+        goto out;
+      }
+  }
+
+  self = PHOTOS_IMPORT_DIALOG (user_data);
+
+  if (cursor == NULL)
+    goto out;
+
+  tracker_sparql_cursor_next_async (cursor,
+                                    self->cancellable,
+                                    photos_import_dialog_fetch_collections_local_cursor_next,
+                                    self);
+
+ out:
+  g_clear_object (&cursor);
+  return;
+}
+
+
+static void
+photos_import_dialog_constructed (GObject *object)
+{
+  PhotosImportDialog *self = PHOTOS_IMPORT_DIALOG (object);
+
+  G_OBJECT_CLASS (photos_import_dialog_parent_class)->constructed (object);
+}
+
+
+static void
+photos_import_dialog_dispose (GObject *object)
+{
+  PhotosImportDialog *self = PHOTOS_IMPORT_DIALOG (object);
+
+  if (self->cancellable != NULL)
+    {
+      g_cancellable_cancel (self->cancellable);
+      g_clear_object (&self->cancellable);
+    }
+
+  g_clear_object (&self->item_mngr);
+  g_clear_object (&self->queue);
+
+  G_OBJECT_CLASS (photos_import_dialog_parent_class)->dispose (object);
+}
+
+
+static void
+photos_import_dialog_finalize (GObject *object)
+{
+  PhotosImportDialog *self = PHOTOS_IMPORT_DIALOG (object);
+
+  G_OBJECT_CLASS (photos_import_dialog_parent_class)->finalize (object);
+}
+
+
+static void
+photos_import_dialog_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+  PhotosImportDialog *self = PHOTOS_IMPORT_DIALOG (object);
+
+  switch (prop_id)
+    {
+    case PROP_TIME:
+      self->time = g_value_get_int64 (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_import_dialog_init (PhotosImportDialog *self)
+{
+  GApplication *app;
+  PhotosSearchContextState *state;
+
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  app = g_application_get_default ();
+  state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
+
+  self->cancellable = g_cancellable_new ();
+  self->item_mngr = g_object_ref (state->item_mngr);
+
+  {
+    g_autoptr (GError) error = NULL;
+
+    self->queue = photos_tracker_queue_dup_singleton (NULL, &error);
+    if (G_UNLIKELY (error != NULL))
+      g_warning ("Unable to create PhotosTrackerQueue: %s", error->message);
+  }
+
+  if (G_LIKELY (self->queue != NULL))
+    {
+      g_autoptr (PhotosQuery) query = NULL;
+
+      query = photos_query_builder_fetch_collections_local (state);
+      photos_tracker_queue_select (self->queue,
+                                   query,
+                                   self->cancellable,
+                                   photos_import_dialog_fetch_collections_local_query_executed,
+                                   self,
+                                   NULL);
+    }
+}
+
+
+static void
+photos_import_dialog_class_init (PhotosImportDialogClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+
+  object_class->constructed = photos_import_dialog_constructed;
+  object_class->dispose = photos_import_dialog_dispose;
+  object_class->finalize = photos_import_dialog_finalize;
+  object_class->set_property = photos_import_dialog_set_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_TIME,
+                                   g_param_spec_int64 ("time",
+                                                       "Time",
+                                                       "The timestamp for the default new collection name",
+                                                       0,
+                                                       G_MAXINT64,
+                                                       0,
+                                                       G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Photos/import-dialog.ui");
+  gtk_widget_class_bind_template_child (widget_class, PhotosImportDialog, add_existing_button);
+  gtk_widget_class_bind_template_child (widget_class, PhotosImportDialog, 
add_existing_collection_name_button);
+  gtk_widget_class_bind_template_child (widget_class, PhotosImportDialog, add_existing_label);
+  gtk_widget_class_bind_template_child (widget_class, PhotosImportDialog, collections_popover);
+  gtk_widget_class_bind_template_child (widget_class, PhotosImportDialog, collections_popover_grid);
+  gtk_widget_class_bind_template_child (widget_class, PhotosImportDialog, collections_popover_search_entry);
+  gtk_widget_class_bind_template_child (widget_class, PhotosImportDialog, create_new_button);
+  gtk_widget_class_bind_template_child (widget_class, PhotosImportDialog, create_new_entry);
+  gtk_widget_class_bind_template_child (widget_class, PhotosImportDialog, create_new_label);
+}
+
+
+GtkWidget *
+photos_import_dialog_new (GtkWindow *parent, gint64 time)
+{
+  g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
+  g_return_val_if_fail (time >= 0, NULL);
+
+  return g_object_new (PHOTOS_TYPE_IMPORT_DIALOG,
+                       "time", time,
+                       "transient-for", parent,
+                       "use-header-bar", TRUE,
+                       NULL);
+}
diff --git a/src/photos-import-dialog.h b/src/photos-import-dialog.h
new file mode 100644
index 00000000..a1683568
--- /dev/null
+++ b/src/photos-import-dialog.h
@@ -0,0 +1,35 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2018 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PHOTOS_IMPORT_DIALOG_H
+#define PHOTOS_IMPORT_DIALOG_H
+
+#include <gtk/gtk.h>
+
+#include "photos-base-item.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_IMPORT_DIALOG (photos_import_dialog_get_type ())
+G_DECLARE_FINAL_TYPE (PhotosImportDialog, photos_import_dialog, PHOTOS, IMPORT_DIALOG, GtkDialog);
+
+GtkWidget          *photos_import_dialog_new                (GtkWindow *parent, gint64 time);
+
+G_END_DECLS
+
+#endif /* PHOTOS_IMPORT_DIALOG_H */
diff --git a/src/photos-import-dialog.ui b/src/photos-import-dialog.ui
new file mode 100644
index 00000000..d8db0ad8
--- /dev/null
+++ b/src/photos-import-dialog.ui
@@ -0,0 +1,148 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Photos - access, organize and share your photos on GNOME
+ Copyright © 2018 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 3 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, see <http://www.gnu.org/licenses/>.
+-->
+<interface domain="gnome-photos">
+  <template class="PhotosImportDialog" parent="GtkDialog">
+    <property name="border_width">18</property>
+    <property name="title" translatable="yes" context="dialog title">Name Album</property>
+    <property name="resizable">0</property>
+    <property name="modal">1</property>
+    <property name="type_hint">dialog</property>
+    <property name="skip_taskbar_hint">1</property>
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkGrid">
+            <property name="column_spacing">12</property>
+            <property name="margin">12</property>
+            <property name="row_spacing">12</property>
+            <child>
+              <object class="GtkRadioButton" id="create_new_button">
+                <property name="active">1</property>
+                <property name="halign">start</property>
+                <property name="no_show_all">1</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="create_new_label">
+                <property name="halign">end</property>
+                <property name="label" translatable="yes">_Create New</property>
+                <property name="mnemonic_widget">create_new_entry</property>
+                <property name="use_underline">1</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkEntry" id="create_new_entry">
+                <property name="activates_default">1</property>
+                <property name="width_chars">30</property>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="top_attach">0</property>
+                <property name="width">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkRadioButton" id="add_existing_button">
+                <property name="halign">start</property>
+                <property name="group">create_new_button</property>
+                <property name="no_show_all">1</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="add_existing_label">
+                <property name="halign">end</property>
+                <property name="label" translatable="yes">Add to _Existing</property>
+                <property name="mnemonic_widget">add_existing_button</property>
+                <property name="no_show_all">1</property>
+                <property name="use_underline">1</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkMenuButton" id="add_existing_collection_name_button">
+                <property name="no_show_all">1</property>
+                <property name="popover">collections_popover</property>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="top_attach">1</property>
+                <property name="width">2</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <child type="action">
+      <object class="GtkButton" id="cancel_button">
+        <property name="label" translatable="yes">_Cancel</property>
+        <property name="use_underline">1</property>
+      </object>
+    </child>
+    <child type="action">
+      <object class="GtkButton" id="ok_button">
+        <property name="can_default">1</property>
+        <property name="label" translatable="yes">_Add</property>
+        <property name="use_underline">1</property>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="cancel">cancel_button</action-widget>
+      <action-widget response="ok" default="true">ok_button</action-widget>
+    </action-widgets>
+  </template>
+  <object class="GtkPopoverMenu" id="collections_popover">
+    <child>
+      <object class="GtkGrid">
+        <property name="margin">10</property>
+        <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
+        <property name="row_spacing">0</property>
+        <child>
+          <object class="GtkSearchEntry" id="collections_popover_search_entry">
+            <property name="width_chars">30</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkGrid" id="collections_popover_grid">
+            <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/src/photos.gresource.xml b/src/photos.gresource.xml
index dc959b8d..76a81df4 100644
--- a/src/photos.gresource.xml
+++ b/src/photos.gresource.xml
@@ -24,6 +24,7 @@
     <file alias="dropdown.ui" preprocess="xml-stripblanks" compressed="true">photos-dropdown.ui</file>
     <file alias="embed.ui" preprocess="xml-stripblanks" compressed="true">photos-embed.ui</file>
     <file alias="export-dialog.ui" preprocess="xml-stripblanks" 
compressed="true">photos-export-dialog.ui</file>
+    <file alias="import-dialog.ui" preprocess="xml-stripblanks" 
compressed="true">photos-import-dialog.ui</file>
     <file alias="main-toolbar.ui" preprocess="xml-stripblanks" 
compressed="true">photos-main-toolbar.ui</file>
     <file alias="main-window.ui" preprocess="xml-stripblanks" compressed="true">photos-main-window.ui</file>
     <file alias="preview-menu.ui" preprocess="xml-stripblanks" 
compressed="true">photos-preview-menu.ui</file>


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