[gnome-photos/wip/rishi/misc-fixes: 19/25] Add PhotosExportDialog



commit 6cea1a8e699f3f2a681328c0a8e3e040d9243e14
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  |  183 +++++++++++++++++++++++++++++++++++++++++++
 src/photos-export-dialog.h  |   63 +++++++++++++++
 src/photos-export-dialog.ui |  107 +++++++++++++++++++++++++
 src/photos.gresource.xml    |    1 +
 6 files changed, 359 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 fa4773e..070f321 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -72,6 +72,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 \
@@ -247,6 +249,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..04a2b30
--- /dev/null
+++ b/src/photos-export-dialog.c
@@ -0,0 +1,183 @@
+/*
+ * 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;
+  GtkWidget *dir_entry;
+  GtkWidget *msg_label;
+  PhotosBaseItem *item;
+};
+
+struct _PhotosExportDialogClass
+{
+  GtkDialogClass parent_class;
+};
+
+
+enum
+{
+  PROP_0,
+  PROP_ITEM
+};
+
+
+G_DEFINE_TYPE (PhotosExportDialog, photos_export_dialog, GTK_TYPE_DIALOG);
+
+
+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;
+      gchar *now_str;
+
+      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);
+
+  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)
+{
+  const gchar *pictures_path;
+  gchar *msg;
+  gchar *pictures_path_basename;
+
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  pictures_path = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
+  pictures_path_basename = g_path_get_basename (pictures_path);
+  msg = g_strdup_printf (_("Photos are exported to the %s ▶ %s folder."),
+                         pictures_path_basename,
+                         PHOTOS_EXPORT_SUBPATH);
+  gtk_label_set_label (GTK_LABEL (self->msg_label), msg);
+
+  g_free (msg);
+  g_free (pictures_path_basename);
+}
+
+
+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, msg_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;
+
+  dir_name = gtk_entry_get_text (GTK_ENTRY (self->dir_entry));
+  return dir_name;
+}
diff --git a/src/photos-export-dialog.h b/src/photos-export-dialog.h
new file mode 100644
index 0000000..37149bf
--- /dev/null
+++ b/src/photos-export-dialog.h
@@ -0,0 +1,63 @@
+/*
+ * 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);
+
+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..57fc60e
--- /dev/null
+++ b/src/photos-export-dialog.ui
@@ -0,0 +1,107 @@
+<?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_homogeneous">1</property>
+            <property name="row_spacing">12</property>
+            <child>
+              <object class="GtkLabel" id="msg_label">
+                <property name="halign">start</property>
+                <style>
+                  <class name="dim-label" />
+                </style>
+              </object>
+              <packing>
+                <property name="height">1</property>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel">
+                <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="height">1</property>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+                <property name="width">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="height">1</property>
+                <property name="left_attach">1</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">_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]