[gnome-photos] Add PhotosExportDialog
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Add PhotosExportDialog
- Date: Wed, 30 Dec 2015 20:42:06 +0000 (UTC)
commit 24d44bf68c993bb33c2c2fe56ec312c3f5c48ca7
Author: Debarshi Ray <debarshir gnome org>
Date: Mon Dec 21 18:45:03 2015 +0100
Add PhotosExportDialog
https://bugzilla.gnome.org/show_bug.cgi?id=759363
po/POTFILES.in | 2 +
src/Makefile.am | 3 +
src/photos-export-dialog.c | 281 +++++++++++++++++++++++++++++++++++++++++++
src/photos-export-dialog.h | 65 ++++++++++
src/photos-export-dialog.ui | 162 +++++++++++++++++++++++++
src/photos.gresource.xml | 1 +
6 files changed, 514 insertions(+), 0 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c809317..4aea560 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -9,6 +9,8 @@ src/photos-delete-notification.c
[type: gettext/glade]src/photos-dlna-renderers-dialog.ui
src/photos-embed.c
src/photos-empty-results-box.c
+[type: gettext/glade]src/photos-export-dialog.ui
+src/photos-export-dialog.c
src/photos-facebook-item.c
src/photos-fetch-metas-job.c
src/photos-flickr-item.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 7c2fb8f..559c1a4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -70,6 +70,8 @@ gnome_photos_SOURCES = \
photos-dlna-renderers-manager.h \
photos-dropdown.c \
photos-dropdown.h \
+ photos-export-dialog.c \
+ photos-export-dialog.h \
photos-edit-palette.c \
photos-edit-palette.h \
photos-edit-palette-row.c \
@@ -249,6 +251,7 @@ EXTRA_DIST = \
photos-generate-about \
photos.gresource.xml \
photos-dlna-renderers-dialog.ui \
+ photos-export-dialog.ui \
photos-help-overlay.ui \
photos-marshalers.list \
photos-menus.ui \
diff --git a/src/photos-export-dialog.c b/src/photos-export-dialog.c
new file mode 100644
index 0000000..8ce9eda
--- /dev/null
+++ b/src/photos-export-dialog.c
@@ -0,0 +1,281 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2015 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"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "photos-export-dialog.h"
+#include "photos-utils.h"
+
+
+struct _PhotosExportDialog
+{
+ GtkDialog parent_instance;
+ GCancellable *cancellable;
+ GtkWidget *dir_entry;
+ GtkWidget *folder_name_label;
+ GtkWidget *full_button;
+ GtkWidget *full_label;
+ GtkWidget *reduced_button;
+ GtkWidget *reduced_label;
+ GtkWidget *size_label;
+ PhotosBaseItem *item;
+ gdouble reduced_zoom;
+};
+
+struct _PhotosExportDialogClass
+{
+ GtkDialogClass parent_class;
+};
+
+
+enum
+{
+ PROP_0,
+ PROP_ITEM
+};
+
+
+G_DEFINE_TYPE (PhotosExportDialog, photos_export_dialog, GTK_TYPE_DIALOG);
+
+
+static const gint PIXEL_SIZES[] = {2048, 1024};
+
+
+static void
+photos_export_dialog_guess_sizes (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ PhotosExportDialog *self;
+ PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
+ GError *error;
+ gchar *size_str;
+ gsize sizes[2];
+
+ error = NULL;
+ if (!photos_base_item_save_guess_sizes_finish (item, res, &sizes[0], &sizes[1], &error))
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("Unable to guess sizes: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ self = PHOTOS_EXPORT_DIALOG (user_data);
+
+ size_str = g_format_size ((guint64) sizes[0]);
+ gtk_label_set_text (GTK_LABEL (self->full_label), size_str);
+ g_free (size_str);
+
+ if (self->reduced_zoom > 0.0)
+ {
+ gsize reduced_size;
+
+ reduced_size = (gsize) (sizes[1] + (sizes[0] - sizes[1]) * (self->reduced_zoom - 0.5) / (1.0 - 0.5) +
0.5);
+ size_str = g_format_size ((guint64) reduced_size);
+ gtk_label_set_text (GTK_LABEL (self->reduced_label), size_str);
+ g_free (size_str);
+ }
+}
+
+
+static void
+photos_export_dialog_show_size_options (PhotosExportDialog *self)
+{
+ gtk_widget_set_margin_bottom (self->dir_entry, 6);
+ gtk_widget_set_margin_bottom (self->folder_name_label, 6);
+ gtk_widget_show (self->full_label);
+ gtk_widget_show (self->full_button);
+ gtk_widget_show (self->reduced_button);
+ gtk_widget_show (self->reduced_label);
+ gtk_widget_show (self->size_label);
+}
+
+
+static void
+photos_export_dialog_constructed (GObject *object)
+{
+ PhotosExportDialog *self = PHOTOS_EXPORT_DIALOG (object);
+
+ G_OBJECT_CLASS (photos_export_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
+ {
+ GDateTime *now;
+ GeglRectangle bbox;
+ gboolean got_bbox_edited;
+ gchar *now_str;
+ gint max_dimension;
+ guint i;
+
+ got_bbox_edited = photos_base_item_get_bbox_edited (self->item, &bbox);
+ g_return_if_fail (got_bbox_edited);
+
+ max_dimension = MAX (bbox.height, bbox.width);
+ for (i = 0; i < G_N_ELEMENTS (PIXEL_SIZES); i++)
+ {
+ if (max_dimension > PIXEL_SIZES[i])
+ {
+ self->reduced_zoom = (gdouble) PIXEL_SIZES[i] / (gdouble) max_dimension;
+ photos_export_dialog_show_size_options (self);
+ photos_base_item_save_guess_sizes_async (self->item,
+ self->cancellable,
+ photos_export_dialog_guess_sizes,
+ self);
+ break;
+ }
+ }
+
+ now = g_date_time_new_now_local ();
+
+ /* Translators: this is the default sub-directory where photos
+ * will be exported.
+ */
+ now_str = g_date_time_format (now, _("%e %B %Y"));
+
+ gtk_entry_set_text (GTK_ENTRY (self->dir_entry), now_str);
+
+ g_free (now_str);
+ g_date_time_unref (now);
+ }
+}
+
+
+static void
+photos_export_dialog_dispose (GObject *object)
+{
+ PhotosExportDialog *self = PHOTOS_EXPORT_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_export_dialog_parent_class)->dispose (object);
+}
+
+
+static void
+photos_export_dialog_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+ PhotosExportDialog *self = PHOTOS_EXPORT_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_export_dialog_init (PhotosExportDialog *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+
+ self->cancellable = g_cancellable_new ();
+ self->reduced_zoom = -1.0;
+}
+
+
+static void
+photos_export_dialog_class_init (PhotosExportDialogClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+
+ object_class->constructed = photos_export_dialog_constructed;
+ object_class->dispose = photos_export_dialog_dispose;
+ object_class->set_property = photos_export_dialog_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_ITEM,
+ g_param_spec_object ("item",
+ "PhotosBaseItem object",
+ "The item to export",
+ PHOTOS_TYPE_BASE_ITEM,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Photos/export-dialog.ui");
+ gtk_widget_class_bind_template_child (widget_class, PhotosExportDialog, dir_entry);
+ gtk_widget_class_bind_template_child (widget_class, PhotosExportDialog, folder_name_label);
+ gtk_widget_class_bind_template_child (widget_class, PhotosExportDialog, full_button);
+ gtk_widget_class_bind_template_child (widget_class, PhotosExportDialog, full_label);
+ gtk_widget_class_bind_template_child (widget_class, PhotosExportDialog, reduced_button);
+ gtk_widget_class_bind_template_child (widget_class, PhotosExportDialog, reduced_label);
+ gtk_widget_class_bind_template_child (widget_class, PhotosExportDialog, size_label);
+}
+
+
+GtkWidget *
+photos_export_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_EXPORT_DIALOG,
+ "item", item,
+ "transient-for", parent,
+ "use-header-bar", TRUE,
+ NULL);
+}
+
+
+const gchar *
+photos_export_dialog_get_dir_name (PhotosExportDialog *self)
+{
+ const gchar *dir_name;
+
+ g_return_val_if_fail (PHOTOS_IS_EXPORT_DIALOG (self), NULL);
+
+ dir_name = gtk_entry_get_text (GTK_ENTRY (self->dir_entry));
+ return dir_name;
+}
+
+
+gdouble
+photos_export_dialog_get_zoom (PhotosExportDialog *self)
+{
+ gdouble ret_val = 1.0;
+
+ g_return_val_if_fail (PHOTOS_IS_EXPORT_DIALOG (self), 1.0);
+
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->reduced_button)))
+ {
+ g_return_val_if_fail (self->reduced_zoom > 0.0, 1.0);
+ ret_val = self->reduced_zoom;
+ }
+
+ return ret_val;
+}
diff --git a/src/photos-export-dialog.h b/src/photos-export-dialog.h
new file mode 100644
index 0000000..572ddfe
--- /dev/null
+++ b/src/photos-export-dialog.h
@@ -0,0 +1,65 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2015 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_EXPORT_DIALOG_H
+#define PHOTOS_EXPORT_DIALOG_H
+
+#include <gtk/gtk.h>
+
+#include "photos-base-item.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_EXPORT_DIALOG (photos_export_dialog_get_type ())
+
+#define PHOTOS_EXPORT_DIALOG(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ PHOTOS_TYPE_EXPORT_DIALOG, PhotosExportDialog))
+
+#define PHOTOS_EXPORT_DIALOG_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ PHOTOS_TYPE_EXPORT_DIALOG, PhotosExportDialogClass))
+
+#define PHOTOS_IS_EXPORT_DIALOG(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ PHOTOS_TYPE_EXPORT_DIALOG))
+
+#define PHOTOS_IS_EXPORT_DIALOG_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ PHOTOS_TYPE_EXPORT_DIALOG))
+
+#define PHOTOS_EXPORT_DIALOG_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ PHOTOS_TYPE_EXPORT_DIALOG, PhotosExportDialogClass))
+
+typedef struct _PhotosExportDialog PhotosExportDialog;
+typedef struct _PhotosExportDialogClass PhotosExportDialogClass;
+
+GType photos_export_dialog_get_type (void) G_GNUC_CONST;
+
+GtkWidget *photos_export_dialog_new (GtkWindow *parent, PhotosBaseItem *item);
+
+const gchar *photos_export_dialog_get_dir_name (PhotosExportDialog *self);
+
+gdouble photos_export_dialog_get_zoom (PhotosExportDialog *self);
+
+G_END_DECLS
+
+#endif /* PHOTOS_EXPORT_DIALOG_H */
diff --git a/src/photos-export-dialog.ui b/src/photos-export-dialog.ui
new file mode 100644
index 0000000..9f9bda9
--- /dev/null
+++ b/src/photos-export-dialog.ui
@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Photos - access, organize and share your photos on GNOME
+ Copyright © 2015 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.
+-->
+<interface domain="gnome-photos">
+ <template class="PhotosExportDialog" parent="GtkDialog">
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Export</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">6</property>
+ <child>
+ <object class="GtkLabel" id="folder_name_label">
+ <property name="halign">end</property>
+ <property name="label" translatable="yes">_Folder Name</property>
+ <property name="mnemonic_widget">dir_entry</property>
+ <property name="use_underline">1</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="dir_entry">
+ <property name="activates_default">1</property>
+ <property name="width_chars">30</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="size_label">
+ <property name="halign">end</property>
+ <property name="label" translatable="yes">Size</property>
+ <property name="margin_top">6</property>
+ <property name="no_show_all">1</property>
+ <property name="valign">baseline</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="full_button">
+ <property name="active">1</property>
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">F_ull</property>
+ <property name="margin_top">6</property>
+ <property name="no_show_all">1</property>
+ <property name="use_underline">1</property>
+ <property name="valign">baseline</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="full_label">
+ <property name="halign">end</property>
+ <property name="margin_top">6</property>
+ <property name="no_show_all">1</property>
+ <property name="valign">baseline</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="top_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="reduced_button">
+ <property name="halign">start</property>
+ <property name="group">full_button</property>
+ <property name="label" translatable="yes">_Reduced</property>
+ <property name="no_show_all">1</property>
+ <property name="use_underline">1</property>
+ <property name="valign">baseline</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="reduced_label">
+ <property name="halign">end</property>
+ <property name="no_show_all">1</property>
+ <property name="valign">baseline</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="top_attach">3</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">_Export</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>
+</interface>
diff --git a/src/photos.gresource.xml b/src/photos.gresource.xml
index 7fa7693..54daa09 100644
--- a/src/photos.gresource.xml
+++ b/src/photos.gresource.xml
@@ -4,6 +4,7 @@
<file alias="Adwaita.css">../data/Adwaita.css</file>
<file alias="dlna-renderers-dialog.ui" preprocess="xml-stripblanks"
compressed="true">photos-dlna-renderers-dialog.ui</file>
<file alias="dnd-counter.svg" preprocess="to-pixdata">../data/dnd-counter.svg</file>
+ <file alias="export-dialog.ui" preprocess="xml-stripblanks"
compressed="true">photos-export-dialog.ui</file>
<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>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]