[gnome-photos/wip/rishi/collection: 3/3] app: import
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/collection: 3/3] app: import
- Date: Tue, 6 Feb 2018 20:41:15 +0000 (UTC)
commit f66d2ce2c6897f762d52e2df6b4c35313506f7af
Author: Debarshi Ray <debarshir gnome org>
Date: Sat Feb 3 13:05:50 2018 +0100
app: import
src/photos-application.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 143 insertions(+)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 98c483e6..c728936a 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -47,6 +47,7 @@
#include "photos-filterable.h"
#include "photos-gegl.h"
#include "photos-glib.h"
+#include "photos-import-dialog.h"
#include "photos-item-manager.h"
#include "photos-main-window.h"
#include "photos-properties-dialog.h"
@@ -174,6 +175,7 @@ static const gchar *DESKTOP_KEY_PRIMARY_COLOR = "primary-color";
static const gchar *DESKTOP_KEY_SECONDARY_COLOR = "secondary-color";
typedef struct _PhotosApplicationCreateData PhotosApplicationCreateData;
+typedef struct _PhotosApplicationImportData PhotosApplicationImportData;
typedef struct _PhotosApplicationRefreshData PhotosApplicationRefreshData;
typedef struct _PhotosApplicationSetBackgroundData PhotosApplicationSetBackgroundData;
@@ -184,6 +186,13 @@ struct _PhotosApplicationCreateData
gchar *miner_name;
};
+struct _PhotosApplicationImportData
+{
+ PhotosApplication *application;
+ GList *files;
+ gint64 ctime_latest;
+};
+
struct _PhotosApplicationRefreshData
{
PhotosApplication *application;
@@ -229,6 +238,32 @@ photos_application_create_data_free (PhotosApplicationCreateData *data)
}
+static PhotosApplicationImportData *
+photos_application_import_data_new (PhotosApplication *application, GList *files, gint64 ctime_latest)
+{
+ PhotosApplicationImportData *data;
+
+ data = g_slice_new0 (PhotosApplicationImportData);
+ g_application_hold (G_APPLICATION (application));
+ data->application = application;
+ data->files = g_list_copy_deep (files, (GCopyFunc) g_object_ref, NULL);
+ data->ctime_latest = ctime_latest;
+ return data;
+}
+
+
+static void
+photos_application_import_data_free (PhotosApplicationImportData *data)
+{
+ g_application_release (G_APPLICATION (data->application));
+ g_list_free_full (data->files, g_object_unref);
+ g_slice_free (PhotosApplicationImportData, data);
+}
+
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (PhotosApplicationImportData, photos_application_import_data_free);
+
+
static PhotosApplicationRefreshData *
photos_application_refresh_data_new (PhotosApplication *application, GomMiner *miner)
{
@@ -1046,17 +1081,125 @@ photos_application_get_state (PhotosSearchContext *context)
}
+static void
+photos_application_import_copy_files (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ PhotosApplication *self = PHOTOS_APPLICATION (user_data);
+
+ {
+ g_autoptr (GError) error = NULL;
+
+ if (!photos_utils_copy_files_finish (res, &error))
+ {
+ g_warning ("Unable to copy files: %s", error->message);
+ goto out;
+ }
+ }
+
+ out:
+ g_application_unmark_busy (G_APPLICATION (self));
+ g_application_release (G_APPLICATION (self));
+}
+
+
+static void
+photos_application_import_response (GtkDialog *dialog, gint response_id, gpointer user_data)
+{
+ g_autoptr (PhotosApplicationImportData) data = (PhotosApplicationImportData *) user_data;
+ PhotosApplication *self = data->application;
+ g_autoptr (GDateTime) date_created_latest = NULL;
+ g_autoptr (GFile) import_sub_dir = NULL;
+ const gchar *pictures_path;
+ g_autofree gchar *date_created_latest_str = NULL;
+ g_autofree gchar *import_sub_path = NULL;
+
+ if (response_id != GTK_RESPONSE_OK)
+ goto out;
+
+ date_created_latest = g_date_time_new_from_unix_local (data->ctime_latest);
+
+ /* Translators: this is the default sub-directory where photos will
+ * be imported.
+ */
+ date_created_latest_str = g_date_time_format (date_created_latest, _("%-d %B %Y"));
+
+ pictures_path = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
+ import_sub_path = g_build_filename (pictures_path, PHOTOS_IMPORT_SUBPATH, date_created_latest_str, NULL);
+ g_mkdir_with_parents (import_sub_path, 0777);
+
+ import_sub_dir = g_file_new_for_path (import_sub_path);
+
+ g_application_hold (G_APPLICATION (self));
+ g_application_mark_busy (G_APPLICATION (self));
+ photos_utils_copy_files_async (data->files,
+ import_sub_dir,
+ G_PRIORITY_DEFAULT,
+ NULL,
+ photos_application_import_copy_files,
+ self);
+
+ out:
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+
static void
photos_application_import (PhotosApplication *self)
{
+ GList *files = NULL;
+ GList *l;
+ GList *selection;
GMount *mount;
+ GtkWidget *dialog;
+ g_autoptr (PhotosApplicationImportData) data = NULL;
PhotosSource *source;
+ gint64 ctime_latest = -1;
source = PHOTOS_SOURCE (photos_base_manager_get_active_object (self->state->src_mngr));
g_return_if_fail (PHOTOS_IS_SOURCE (source));
mount = photos_source_get_mount (source);
g_return_if_fail (G_IS_MOUNT (mount));
+
+ g_return_if_fail (photos_utils_get_selection_mode ());
+
+ selection = photos_selection_controller_get_selection (self->sel_cntrlr);
+ g_return_if_fail (selection != NULL);
+
+ for (l = selection; l != NULL; l = l->next)
+ {
+ g_autoptr (GFile) file = NULL;
+ PhotosBaseItem *item;
+ const gchar *uri;
+ const gchar *urn = (gchar *) l->data;
+ gint64 ctime;
+
+ item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (self->state->item_mngr, urn));
+
+ ctime = photos_base_item_get_date_created (item);
+ if (ctime < 0)
+ ctime = photos_base_item_get_mtime (item);
+
+ if (ctime > ctime_latest)
+ ctime_latest = ctime;
+
+ uri = photos_base_item_get_uri (item);
+ file = g_file_new_for_uri (uri);
+ files = g_list_prepend (files, g_object_ref (file));
+ }
+
+ g_assert_cmpint (ctime_latest, >=, 0);
+
+ dialog = photos_import_dialog_new (GTK_WINDOW (self->main_window), ctime_latest);
+ gtk_widget_show_all (dialog);
+
+ data = photos_application_import_data_new (self, files, ctime_latest);
+ g_signal_connect (dialog,
+ "response",
+ G_CALLBACK (photos_application_import_response),
+ g_steal_pointer (&data));
+
+ g_list_free_full (files, g_object_unref);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]