[gnome-photos/wip/rishi/misc-fixes: 17/20] application: Rewrite app.save-current to match the design
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/misc-fixes: 17/20] application: Rewrite app.save-current to match the design
- Date: Sat, 26 Dec 2015 22:31:13 +0000 (UTC)
commit 0da6855d4f90937bbaac6691d1d7e76b4083557e
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Dec 22 20:41:12 2015 +0100
application: Rewrite app.save-current to match the design
https://bugzilla.gnome.org/show_bug.cgi?id=759363
src/photos-application.c | 94 +++++++++++++++++++++++++++++----------------
1 files changed, 60 insertions(+), 34 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index f99d56c..90a8a79 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -40,6 +40,7 @@
#include "photos-camera-cache.h"
#include "photos-debug.h"
#include "photos-dlna-renderers-dialog.h"
+#include "photos-export-dialog.h"
#include "photos-filterable.h"
#include "photos-gom-miner.h"
#include "photos-item-manager.h"
@@ -888,7 +889,7 @@ photos_application_save_save (GObject *source_object, GAsyncResult *res, gpointe
PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
GError *error = NULL;
- photos_base_item_save_finish (item, res, &error);
+ photos_base_item_save_to_dir_finish (item, res, &error);
if (error != NULL)
{
g_warning ("Unable to save: %s", error->message);
@@ -902,59 +903,84 @@ photos_application_save_save (GObject *source_object, GAsyncResult *res, gpointe
static void
-photos_application_save (PhotosApplication *self)
+photos_application_save_response (GtkDialog *dialog, gint response_id, gpointer user_data)
{
+ PhotosApplication *self = PHOTOS_APPLICATION (user_data);
PhotosApplicationPrivate *priv = self->priv;
- GDateTime *now = NULL;
- GError *error = NULL;
- GFile *parent = NULL;
+ GError *error;
+ GFile *export = NULL;
+ GFile *tmp;
PhotosBaseItem *item;
- const gchar *mime_type;
+ const gchar *export_dir_name;
const gchar *pictures_path;
- gchar *filename = NULL;
- gchar *extension = NULL;
- gchar *origin = NULL;
- gchar *parent_path = NULL;
- gchar *path = NULL;
- gchar *uri = NULL;
+ gchar *export_path = NULL;
+
+ if (response_id != GTK_RESPONSE_OK)
+ goto out;
item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (priv->state->item_mngr));
g_return_if_fail (item != NULL);
pictures_path = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
- parent_path = g_build_filename (pictures_path, PHOTOS_EXPORT_SUBPATH, NULL);
- parent = g_file_new_for_path (parent_path);
- if (!photos_utils_make_directory_with_parents (parent, NULL, &error))
+ export_path = g_build_filename (pictures_path, PHOTOS_EXPORT_SUBPATH, NULL);
+ export = g_file_new_for_path (export_path);
+
+ error = NULL;
+ if (!photos_utils_make_directory_with_parents (export, NULL, &error))
{
- g_warning ("Unable to create %s: %s", parent_path, error->message);
+ g_warning ("Unable to create %s: %s", export_path, error->message);
g_error_free (error);
goto out;
}
- now = g_date_time_new_now_local ();
- origin = g_date_time_format (now, "%Y-%m-%d %H-%M-%S");
+ export_dir_name = photos_export_dialog_get_dir_name (PHOTOS_EXPORT_DIALOG (dialog));
- mime_type = photos_base_item_get_mime_type (item);
- extension = photos_utils_get_extension_from_mime_type (mime_type);
+ error = NULL;
+ tmp = g_file_get_child_for_display_name (export, export_dir_name, &error);
+ if (error != NULL)
+ {
+ g_warning ("Unable to get a child for %s: %s", export_dir_name, error->message);
+ g_error_free (error);
+ goto out;
+ }
- filename = g_strdup_printf ("%s.%s", origin, extension);
- path = g_build_filename (parent_path, filename, NULL);
- uri = photos_utils_convert_path_to_uri (path);
+ g_object_unref (export);
+ export = tmp;
+
+ error = NULL;
+ if (!photos_utils_make_directory_with_parents (export, NULL, &error))
+ {
+ g_warning ("Unable to create %s: %s", export_path, error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ if (photos_base_item_is_collection (item))
+ goto out;
g_application_hold (G_APPLICATION (self));
- photos_base_item_save_async (item, uri, NULL, photos_application_save_save, self);
+ photos_base_item_save_to_dir_async (item, export, NULL, photos_application_save_save, self);
out:
- if (now != NULL)
- g_date_time_unref (now);
+ g_free (export_path);
+ g_clear_object (&export);
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+}
- g_free (extension);
- g_free (filename);
- g_free (origin);
- g_free (parent_path);
- g_free (path);
- g_free (uri);
- g_clear_object (&parent);
+
+static void
+photos_application_save (PhotosApplication *self)
+{
+ PhotosApplicationPrivate *priv = self->priv;
+ GtkWidget *dialog;
+ PhotosBaseItem *item;
+
+ item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (priv->state->item_mngr));
+ g_return_if_fail (item != NULL);
+
+ dialog = photos_export_dialog_new (GTK_WINDOW (priv->main_window), item);
+ gtk_widget_show_all (dialog);
+ g_signal_connect (dialog, "response", G_CALLBACK (photos_application_save_response), self);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]