[gnome-photos/wip/rishi/collection: 46/46] Add PhotosImportDialog
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/collection: 46/46] Add PhotosImportDialog
- Date: Mon, 5 Feb 2018 17:27:09 +0000 (UTC)
commit 0075ac971cdfb0c734fd69e22257d0321323053e
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 | 312 ++++++++++++++++++++++++++++++++++++++++++++
src/photos-import-dialog.h | 37 ++++++
src/photos-import-dialog.ui | 148 +++++++++++++++++++++
5 files changed, 501 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..f951b617
--- /dev/null
+++ b/src/photos-import-dialog.c
@@ -0,0 +1,312 @@
+/*
+ * 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 <glib.h>
+#include <glib/gi18n.h>
+
+#include "photos-import-dialog.h"
+
+
+struct _PhotosImportDialog
+{
+ GtkDialog parent_instance;
+ GCancellable *cancellable;
+ GtkWidget *dir_entry;
+ GtkWidget *folder_name_label;
+ GtkWidget *full_button;
+ GtkWidget *full_label;
+ GtkWidget *progress_label;
+ GtkWidget *reduced_button;
+ GtkWidget *reduced_label;
+ GtkWidget *size_label;
+ PhotosBaseItem *item;
+ gdouble reduced_zoom;
+};
+
+enum
+{
+ PROP_0,
+ PROP_ITEM
+};
+
+
+G_DEFINE_TYPE (PhotosImportDialog, photos_import_dialog, GTK_TYPE_DIALOG);
+
+
+static gchar *
+photos_import_dialog_create_size_str (gint height, gint width, guint64 size)
+{
+ g_autofree gchar *size_str = NULL;
+ gchar *ret_val;
+
+ size_str = g_format_size (size);
+
+ /* Translators: this is the estimated size of the imported image in
+ * the form "1600×1067 (0.6 GB)".
+ */
+ ret_val = g_strdup_printf (_("%d×%d (%s)"), width, height, size_str);
+
+ return ret_val;
+}
+
+
+static void
+photos_import_dialog_show_size_options (PhotosImportDialog *self, gboolean size_options, gboolean progress)
+{
+ GtkStyleContext *context;
+ const gchar *class_name;
+ const gchar *invert_class_name;
+
+ gtk_widget_set_margin_bottom (self->dir_entry, 6);
+ gtk_widget_set_margin_bottom (self->folder_name_label, 6);
+
+ class_name = progress ? "photos-fade-in" : "photos-fade-out";
+ invert_class_name = !progress ? "photos-fade-in" : "photos-fade-out";
+
+ gtk_widget_show (self->progress_label);
+ context = gtk_widget_get_style_context (self->progress_label);
+ gtk_style_context_remove_class (context, invert_class_name);
+ gtk_style_context_add_class (context, class_name);
+
+ class_name = size_options ? "photos-fade-in" : "photos-fade-out";
+ invert_class_name = !size_options ? "photos-fade-in" : "photos-fade-out";
+
+ gtk_widget_show (self->full_label);
+ context = gtk_widget_get_style_context (self->full_label);
+ gtk_style_context_remove_class (context, invert_class_name);
+ gtk_style_context_add_class (context, class_name);
+
+ gtk_widget_show (self->full_button);
+ context = gtk_widget_get_style_context (self->full_button);
+ gtk_style_context_remove_class (context, invert_class_name);
+ gtk_style_context_add_class (context, class_name);
+
+ gtk_widget_show (self->reduced_button);
+ context = gtk_widget_get_style_context (self->reduced_button);
+ gtk_style_context_remove_class (context, invert_class_name);
+ gtk_style_context_add_class (context, class_name);
+
+ gtk_widget_show (self->reduced_label);
+ context = gtk_widget_get_style_context (self->reduced_label);
+ gtk_style_context_remove_class (context, invert_class_name);
+ gtk_style_context_add_class (context, class_name);
+
+ gtk_widget_show (self->size_label);
+ context = gtk_widget_get_style_context (self->size_label);
+ gtk_style_context_remove_class (context, invert_class_name);
+ gtk_style_context_add_class (context, class_name);
+}
+
+
+static void
+photos_import_dialog_guess_sizes (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ PhotosImportDialog *self;
+ PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
+ PhotosBaseItemSize full;
+ PhotosBaseItemSize reduced;
+ gboolean success;
+
+ {
+ g_autoptr (GError) error = NULL;
+
+ success = photos_base_item_guess_save_sizes_finish (item, res, &full, &reduced, &error);
+ if (error != NULL)
+ {
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ goto out;
+
+ g_warning ("Unable to guess sizes: %s", error->message);
+ }
+ }
+
+ self = PHOTOS_IMPORT_DIALOG (user_data);
+
+ if (success)
+ {
+ {
+ g_autofree gchar *size_str = NULL;
+ g_autofree gchar *size_str_markup = NULL;
+
+ size_str = photos_import_dialog_create_size_str (full.height, full.width, (guint64) full.bytes);
+ size_str_markup = g_strdup_printf ("<small>%s</small>", size_str);
+ gtk_label_set_markup (GTK_LABEL (self->full_label), size_str_markup);
+ }
+
+ self->reduced_zoom = reduced.zoom;
+ if (self->reduced_zoom > 0.0)
+ {
+ g_autofree gchar *size_str = NULL;
+ g_autofree gchar *size_str_markup = NULL;
+
+ size_str = photos_import_dialog_create_size_str (reduced.height, reduced.width, (guint64)
reduced.bytes);
+ size_str_markup = g_strdup_printf ("<small>%s</small>", size_str);
+ gtk_label_set_markup (GTK_LABEL (self->reduced_label), size_str_markup);
+ }
+ }
+
+ photos_import_dialog_show_size_options (self, self->reduced_zoom > 0.0, FALSE);
+
+ out:
+ 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);
+
+ if (photos_base_item_is_collection (self->item))
+ {
+ const gchar *name;
+
+ name = photos_base_item_get_name_with_fallback (self->item);
+ gtk_entry_set_text (GTK_ENTRY (self->dir_entry), name);
+ }
+ else
+ {
+ g_autoptr (GDateTime) now = NULL;
+ g_autofree gchar *now_str = NULL;
+
+ now = g_date_time_new_now_local ();
+
+ /* Translators: this is the default sub-directory where photos
+ * will be imported.
+ */
+ now_str = g_date_time_format (now, _("%-d %B %Y"));
+
+ gtk_entry_set_text (GTK_ENTRY (self->dir_entry), now_str);
+
+ photos_import_dialog_show_size_options (self, FALSE, TRUE);
+ photos_base_item_guess_save_sizes_async (self->item,
+ self->cancellable,
+ photos_import_dialog_guess_sizes,
+ self);
+ }
+}
+
+
+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);
+
+ G_OBJECT_CLASS (photos_import_dialog_parent_class)->dispose (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_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_import_dialog_init (PhotosImportDialog *self)
+{
+ g_autofree gchar *progress_str_markup = NULL;
+
+ gtk_widget_init_template (GTK_WIDGET (self));
+
+ self->cancellable = g_cancellable_new ();
+
+ progress_str_markup = g_strdup_printf ("<small>%s</small>", _("Calculating import size…"));
+ gtk_label_set_markup (GTK_LABEL (self->progress_label), progress_str_markup);
+
+ self->reduced_zoom = -1.0;
+}
+
+
+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->set_property = photos_import_dialog_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_ITEM,
+ g_param_spec_object ("item",
+ "PhotosBaseItem object",
+ "The item to import",
+ PHOTOS_TYPE_BASE_ITEM,
+ 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, dir_entry);
+ gtk_widget_class_bind_template_child (widget_class, PhotosImportDialog, folder_name_label);
+ gtk_widget_class_bind_template_child (widget_class, PhotosImportDialog, full_button);
+ gtk_widget_class_bind_template_child (widget_class, PhotosImportDialog, full_label);
+ gtk_widget_class_bind_template_child (widget_class, PhotosImportDialog, progress_label);
+ gtk_widget_class_bind_template_child (widget_class, PhotosImportDialog, reduced_button);
+ gtk_widget_class_bind_template_child (widget_class, PhotosImportDialog, reduced_label);
+ gtk_widget_class_bind_template_child (widget_class, PhotosImportDialog, size_label);
+}
+
+
+GtkWidget *
+photos_import_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_IMPORT_DIALOG,
+ "item", item,
+ "transient-for", parent,
+ "use-header-bar", TRUE,
+ NULL);
+}
+
+
+const gchar *
+photos_import_dialog_get_dir_name (PhotosImportDialog *self)
+{
+ const gchar *dir_name;
+
+ g_return_val_if_fail (PHOTOS_IS_IMPORT_DIALOG (self), NULL);
+
+ dir_name = gtk_entry_get_text (GTK_ENTRY (self->dir_entry));
+ return dir_name;
+}
diff --git a/src/photos-import-dialog.h b/src/photos-import-dialog.h
new file mode 100644
index 00000000..6f26bb4c
--- /dev/null
+++ b/src/photos-import-dialog.h
@@ -0,0 +1,37 @@
+/*
+ * 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, PhotosBaseItem *item);
+
+const gchar *photos_import_dialog_get_dir_name (PhotosImportDialog *self);
+
+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..790332a6
--- /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_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>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]