[gthumb] [importer] use a single import time when creating subfolders



commit 053c112ecf64da228dede76f5f0b4364a556e9e5
Author: Marcel Stimberg <marcelcoding googlemail com>
Date:   Sat Mar 13 13:31:33 2010 +0100

    [importer] use a single import time when creating subfolders
    
    while gthumb-2.10 calculated a folder name once for an import, the new
    gthumb calculates the destination for every file individually. This
    can lead to possibly unexpected behavior if you use "current time" and
    "custom" with an format like the old one (%Y-%m-%d--%H.%M.%S), because
    you now get a new folder every second... The attached patch tries to
    change this (hopefully in a sane way...) by setting an
    import_start_time at the beginning of the import and using this as the
    "current time" for the complete import.

 .../importer/gth-import-preferences-dialog.c       |    6 +++++-
 extensions/importer/gth-import-task.c              |    9 ++++++---
 extensions/importer/utils.c                        |    5 +++--
 extensions/importer/utils.h                        |    3 ++-
 4 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/extensions/importer/gth-import-preferences-dialog.c b/extensions/importer/gth-import-preferences-dialog.c
index dc9a6f5..e2b1ae1 100644
--- a/extensions/importer/gth-import-preferences-dialog.c
+++ b/extensions/importer/gth-import-preferences-dialog.c
@@ -175,6 +175,7 @@ update_destination (GthImportPreferencesDialog *self)
 	gboolean            single_subfolder;
 	const char         *custom_format;
 	GthFileData        *example_data;
+	GTimeVal            timeval;
 	GFile              *destination_example;
 	char               *uri;
 	char               *example;
@@ -189,13 +190,16 @@ update_destination (GthImportPreferencesDialog *self)
 	custom_format = gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("custom_format_entry")));
 
 	example_data = create_example_file_data ();
+	g_get_current_time (&timeval);
+
 	destination_example = gth_import_utils_get_file_destination (example_data,
 								     destination,
 								     subfolder_type,
 								     subfolder_format,
 								     single_subfolder,
 								     custom_format,
-								     self->priv->event);
+								     self->priv->event,
+								     timeval);
 
 	uri = g_file_get_parse_name (destination_example);
 	example = g_strdup_printf (_("example: %s"), uri);
diff --git a/extensions/importer/gth-import-task.c b/extensions/importer/gth-import-task.c
index 1fb082c..7d031fa 100644
--- a/extensions/importer/gth-import-task.c
+++ b/extensions/importer/gth-import-task.c
@@ -42,6 +42,7 @@ struct _GthImportTaskPrivate {
 	char                *custom_format;
 	char                *event_name;
 	char               **tags;
+	GTimeVal             import_start_time;
 	gboolean             delete_imported;
 	gboolean             overwrite_files;
 	gboolean             adjust_orientation;
@@ -306,7 +307,8 @@ file_buffer_ready_cb (void     **buffer,
 							     self->priv->subfolder_format,
 							     self->priv->single_subfolder,
 							     self->priv->custom_format,
-							     self->priv->event_name);
+							     self->priv->event_name,
+							     self->priv->import_start_time);
 	if (! g_file_make_directory_with_parents (destination, gth_task_get_cancellable (GTH_TASK (self)), &error)) {
 		if (! g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
 			gth_task_completed (GTH_TASK (self), error);
@@ -416,6 +418,7 @@ static void
 gth_import_task_exec (GthTask *base)
 {
 	GthImportTask *self = (GthImportTask *) base;
+	GTimeVal       timeval;
 	GList         *scan;
 
 	self->priv->n_imported = 0;
@@ -424,16 +427,16 @@ gth_import_task_exec (GthTask *base)
 		GthFileData *file_data = scan->data;
 		self->priv->tot_size += g_file_info_get_size (file_data->info);
 	}
+	g_get_current_time (&timeval);
+	self->priv->import_start_time = timeval;
 
 	/* create the imported files catalog */
 
 	if (gth_main_extension_is_active ("catalogs")) {
-		GTimeVal    timeval;
 		GthDateTime *date_time;
 		char        *display_name;
 		GthCatalog  *catalog = NULL;
 
-		g_get_current_time (&timeval);
 		date_time = gth_datetime_new ();
 		gth_datetime_from_timeval (date_time, &timeval);
 
diff --git a/extensions/importer/utils.c b/extensions/importer/utils.c
index c17b14c..ab6bf19 100644
--- a/extensions/importer/utils.c
+++ b/extensions/importer/utils.c
@@ -57,7 +57,8 @@ gth_import_utils_get_file_destination (GthFileData        *file_data,
 				       GthSubfolderFormat  subfolder_format,
 				       gboolean            single_subfolder,
 				       const char         *custom_format,
-				       const char         *event_name)
+				       const char         *event_name,
+				       GTimeVal            import_start_time)
 {
 	GTimeVal  timeval;
 	char     *child;
@@ -74,7 +75,7 @@ gth_import_utils_get_file_destination (GthFileData        *file_data,
 	}
 
 	if (subfolder_type == GTH_SUBFOLDER_TYPE_CURRENT_DATE)
-		g_get_current_time (&timeval);
+		timeval = import_start_time;
 
 	switch (subfolder_type) {
 	case GTH_SUBFOLDER_TYPE_FILE_DATE:
diff --git a/extensions/importer/utils.h b/extensions/importer/utils.h
index ec37f75..4d9952e 100644
--- a/extensions/importer/utils.h
+++ b/extensions/importer/utils.h
@@ -47,7 +47,8 @@ GFile *   gth_import_utils_get_file_destination   (GthFileData        *file_data
 						   GthSubfolderFormat  subfolder_format,
 						   gboolean            single_subfolder,
 						   const char         *custom_format,
-						   const char         *event_name);
+						   const char         *event_name,
+						   GTimeVal            import_start_time);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]