[gthumb/ext] organize imported files automatically
- From: Paolo Bacchilega <paobac src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gthumb/ext] organize imported files automatically
- Date: Sat, 19 Dec 2009 21:26:54 +0000 (UTC)
commit aa6a2345351714b9f5d3b4628b03e90daf016bbc
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sat Dec 19 22:12:19 2009 +0100
organize imported files automatically
and create a catalog with the imported files
extensions/catalogs/dlg-add-to-catalog.c | 8 +-
extensions/catalogs/dlg-catalog-properties.c | 2 +-
extensions/catalogs/gth-catalog.c | 361 ++++++++++++++++--------
extensions/catalogs/gth-catalog.h | 7 +-
extensions/catalogs/gth-file-source-catalogs.c | 24 +-
extensions/catalogs/gth-organize-task.c | 126 +--------
extensions/photo_importer/dlg-photo-importer.c | 2 +-
extensions/photo_importer/gth-import-task.c | 157 +++++++++--
gthumb/glib-utils.c | 23 ++
gthumb/glib-utils.h | 3 +
gthumb/gth-extensions.c | 14 +
gthumb/gth-extensions.h | 2 +
gthumb/gth-main.c | 10 +
gthumb/gth-main.h | 1 +
gthumb/gth-time.c | 13 +
gthumb/gth-time.h | 2 +
16 files changed, 482 insertions(+), 273 deletions(-)
---
diff --git a/extensions/catalogs/dlg-add-to-catalog.c b/extensions/catalogs/dlg-add-to-catalog.c
index c7977b8..fca98d2 100644
--- a/extensions/catalogs/dlg-add-to-catalog.c
+++ b/extensions/catalogs/dlg-add-to-catalog.c
@@ -159,10 +159,10 @@ catalog_ready_cb (GObject *catalog,
static void
add_data_exec (AddData *add_data)
{
- gth_catalog_load_from_file (add_data->catalog_file,
- NULL,
- catalog_ready_cb,
- add_data);
+ gth_catalog_load_from_file_async (add_data->catalog_file,
+ NULL,
+ catalog_ready_cb,
+ add_data);
}
diff --git a/extensions/catalogs/dlg-catalog-properties.c b/extensions/catalogs/dlg-catalog-properties.c
index 4df7e16..7a11842 100644
--- a/extensions/catalogs/dlg-catalog-properties.c
+++ b/extensions/catalogs/dlg-catalog-properties.c
@@ -243,5 +243,5 @@ dlg_catalog_properties (GthBrowser *browser,
gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (browser));
gtk_window_set_modal (GTK_WINDOW (data->dialog), TRUE);
- gth_catalog_load_from_file (file_data->file, NULL, catalog_ready_cb, data);
+ gth_catalog_load_from_file_async (file_data->file, NULL, catalog_ready_cb, data);
}
diff --git a/extensions/catalogs/gth-catalog.c b/extensions/catalogs/gth-catalog.c
index b475249..7dc37ab 100644
--- a/extensions/catalogs/gth-catalog.c
+++ b/extensions/catalogs/gth-catalog.c
@@ -363,6 +363,20 @@ gth_catalog_get_order (GthCatalog *catalog,
void
+gth_catalog_set_for_date (GthCatalog *catalog,
+ GthDateTime *date_time)
+{
+ GFile *catalog_file;
+
+ gth_catalog_set_date (catalog, date_time);
+ catalog_file = gth_catalog_get_file_for_date (date_time);
+ gth_catalog_set_file (catalog, catalog_file);
+
+ g_object_unref (catalog_file);
+}
+
+
+void
gth_catalog_load_from_data (GthCatalog *catalog,
const void *buffer,
gsize count,
@@ -605,6 +619,138 @@ gth_catalog_cancel (GthCatalog *catalog)
}
+static char *
+get_display_name (GFile *file,
+ const char *name,
+ GthDateTime *date_time)
+{
+ GString *display_name;
+ char *basename;
+
+ display_name = g_string_new ("");
+ basename = g_file_get_basename (file);
+ if ((basename == NULL) || (strcmp (basename, "/") == 0)) {
+ g_string_append (display_name, _("Catalogs"));
+ }
+ else {
+ if ((name == NULL) && ! gth_datetime_valid (date_time)) {
+ char *name;
+ char *utf8_name;
+
+ name = _g_uri_remove_extension (basename);
+ utf8_name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL);
+ g_string_append (display_name, utf8_name);
+
+ g_free (utf8_name);
+ g_free (name);
+ }
+ else {
+ if (name != NULL)
+ g_string_append (display_name, name);
+
+ if (gth_datetime_valid (date_time)) {
+ char *formatted;
+
+ formatted = gth_datetime_strftime (date_time, "%x");
+ if ((name == NULL) || (strstr (name, formatted) == NULL)) {
+ if (name != NULL)
+ g_string_append (display_name, " (");
+ g_string_append (display_name, formatted);
+ if (name != NULL)
+ g_string_append (display_name, ")");
+ }
+ g_free (formatted);
+ }
+ }
+ }
+
+ return g_string_free (display_name, FALSE);
+}
+
+
+static void
+update_standard_attributes (GFile *file,
+ GFileInfo *info,
+ const char *name,
+ GthDateTime *date_time)
+{
+ char *display_name;
+
+ if (gth_datetime_valid (date_time)) {
+ char *sort_order_s;
+ int sort_order;
+
+ sort_order_s = gth_datetime_strftime (date_time, "%Y%m%d");
+ sort_order = atoi (sort_order_s);
+ g_file_info_set_sort_order (info, sort_order);
+ }
+ else if (g_file_info_get_attribute_boolean (info, "gthumb::no-child"))
+ g_file_info_set_sort_order (info, 99999999);
+
+ display_name = get_display_name (file, name, date_time);
+ if (display_name != NULL)
+ g_file_info_set_display_name (info, display_name);
+}
+
+
+void
+gth_catalog_update_metadata (GthCatalog *catalog,
+ GthFileData *file_data)
+{
+ const char *sort_type;
+ gboolean sort_inverse;
+
+ /* sort::type,sort::inverse */
+
+ sort_type = gth_catalog_get_order (catalog, &sort_inverse);
+ if (sort_type != NULL) {
+ g_file_info_set_attribute_string (file_data->info, "sort::type", sort_type);
+ g_file_info_set_attribute_boolean (file_data->info, "sort::inverse", sort_inverse);
+ }
+ else {
+ g_file_info_remove_attribute (file_data->info, "sort::type");
+ g_file_info_remove_attribute (file_data->info, "sort::inverse");
+ }
+
+ /* general::event-date */
+
+ if (gth_datetime_valid (catalog->priv->date_time)) {
+ GObject *metadata;
+ char *raw;
+ char *formatted;
+ char *sort_order_s;
+ int sort_order;
+
+ metadata = (GObject *) gth_metadata_new ();
+ raw = gth_datetime_to_exif_date (catalog->priv->date_time);
+ formatted = gth_datetime_strftime (catalog->priv->date_time, "%x");
+ g_object_set (metadata,
+ "id", "general::event-date",
+ "raw", raw,
+ "formatted", formatted,
+ NULL);
+ g_file_info_set_attribute_object (file_data->info, "general::event-date", metadata);
+
+ sort_order_s = gth_datetime_strftime (catalog->priv->date_time, "%Y%m%d");
+ sort_order = atoi (sort_order_s);
+ g_file_info_set_sort_order (file_data->info, sort_order);
+
+ g_free (formatted);
+ g_free (raw);
+ g_object_unref (metadata);
+ }
+ else
+ g_file_info_remove_attribute (file_data->info, "general::event-date");
+
+ /* standard::display-name,standard::sort-order */
+
+ update_standard_attributes (file_data->file,
+ file_data->info,
+ catalog->priv->name,
+ catalog->priv->date_time);
+}
+
+
/* utils */
@@ -797,78 +943,6 @@ get_tag_value (const char *buffer,
}
-static char *
-get_display_name (GFile *file,
- const char *name,
- GthDateTime *date_time)
-{
- GString *display_name;
- char *basename;
-
- display_name = g_string_new ("");
- basename = g_file_get_basename (file);
- if ((basename == NULL) || (strcmp (basename, "/") == 0)) {
- g_string_append (display_name, _("Catalogs"));
- }
- else {
- if ((name == NULL) && ! gth_datetime_valid (date_time)) {
- char *name;
- char *utf8_name;
-
- name = _g_uri_remove_extension (basename);
- utf8_name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL);
- g_string_append (display_name, utf8_name);
-
- g_free (utf8_name);
- g_free (name);
- }
- else {
- if (name != NULL)
- g_string_append (display_name, name);
-
- if (gth_datetime_valid (date_time)) {
- char *formatted;
-
- if (name != NULL)
- g_string_append (display_name, " (");
- formatted = gth_datetime_strftime (date_time, "%x");
- g_string_append (display_name, formatted);
- if (name != NULL)
- g_string_append (display_name, ")");
-
- g_free (formatted);
- }
- }
- }
-
- return g_string_free (display_name, FALSE);
-}
-
-
-static void
-update_standard_attributes (GFile *file,
- GFileInfo *info,
- const char *name,
- GthDateTime *date_time)
-{
- char *display_name;
-
- display_name = get_display_name (file, name, date_time);
-
- if (gth_datetime_valid (date_time)) {
- char *sort_order_s;
- int sort_order;
-
- sort_order_s = gth_datetime_strftime (date_time, "%Y%m%d");
- sort_order = atoi (sort_order_s);
- g_file_info_set_sort_order (info, sort_order);
- }
-
- if (display_name != NULL)
- g_file_info_set_display_name (info, display_name);
-}
-
-
void
gth_catalog_update_standard_attributes (GFile *file,
GFileInfo *info)
@@ -958,10 +1032,10 @@ load__catalog_buffer_ready_cb (void *buffer,
void
-gth_catalog_load_from_file (GFile *file,
- GCancellable *cancellable,
- ReadyCallback ready_func,
- gpointer user_data)
+gth_catalog_load_from_file_async (GFile *file,
+ GCancellable *cancellable,
+ ReadyCallback ready_func,
+ gpointer user_data)
{
LoadData *load_data;
GFile *gio_file;
@@ -981,59 +1055,106 @@ gth_catalog_load_from_file (GFile *file,
}
-void
-gth_catalog_update_metadata (GthCatalog *catalog,
- GthFileData *file_data)
+GFile *
+gth_catalog_get_file_for_date (GthDateTime *date_time)
{
- const char *sort_type;
- gboolean sort_inverse;
+ char *year;
+ char *uri;
+ GFile *base;
+ char *display_name;
+ GFile *catalog_file;
- /* sort::type,sort::inverse */
+ year = gth_datetime_strftime (date_time, "%Y");
+ uri = g_strconcat ("catalog:///", year, "/", NULL);
+ base = g_file_new_for_uri (uri);
+ display_name = gth_datetime_strftime (date_time, "%Y-%m-%d");
+ catalog_file = _g_file_new_for_display_name (uri, display_name, ".catalog");
- sort_type = gth_catalog_get_order (catalog, &sort_inverse);
- if (sort_type != NULL) {
- g_file_info_set_attribute_string (file_data->info, "sort::type", sort_type);
- g_file_info_set_attribute_boolean (file_data->info, "sort::inverse", sort_inverse);
- }
- else {
- g_file_info_remove_attribute (file_data->info, "sort::type");
- g_file_info_remove_attribute (file_data->info, "sort::inverse");
- }
+ g_free (display_name);
+ g_object_unref (base);
+ g_free (uri);
+ g_free (year);
- /* general::event-date */
+ return catalog_file;
+}
- if (gth_datetime_valid (catalog->priv->date_time)) {
- GObject *metadata;
- char *raw;
- char *formatted;
- char *sort_order_s;
- int sort_order;
- metadata = (GObject *) gth_metadata_new ();
- raw = gth_datetime_to_exif_date (catalog->priv->date_time);
- formatted = gth_datetime_strftime (catalog->priv->date_time, "%x");
- g_object_set (metadata,
- "id", "general::event-date",
- "raw", raw,
- "formatted", formatted,
- NULL);
- g_file_info_set_attribute_object (file_data->info, "general::event-date", metadata);
+GthCatalog *
+gth_catalog_load_from_file (GFile *file)
+{
+ GthCatalog *catalog;
+ GFile *gio_file;
+ void *buffer;
+ gsize buffer_size;
- sort_order_s = gth_datetime_strftime (catalog->priv->date_time, "%Y%m%d");
- sort_order = atoi (sort_order_s);
- g_file_info_set_sort_order (file_data->info, sort_order);
+ gio_file = gth_catalog_file_to_gio_file (file);
+ if (! g_load_file_in_buffer (gio_file, &buffer, &buffer_size, NULL))
+ return NULL;
- g_free (formatted);
- g_free (raw);
- g_object_unref (metadata);
+ catalog = gth_hook_invoke_get ("gth-catalog-load-from-data", buffer);
+ if (catalog != NULL)
+ gth_catalog_load_from_data (catalog, buffer, buffer_size, NULL);
+
+ g_free (buffer);
+ g_object_unref (gio_file);
+
+ return catalog;
+}
+
+
+void
+gth_catalog_save (GthCatalog *catalog)
+{
+ GFile *file;
+ GFile *gio_file;
+ GFile *gio_parent;
+ char *data;
+ gsize size;
+ GError *error = NULL;
+
+ file = gth_catalog_get_file (catalog);
+ gio_file = gth_catalog_file_to_gio_file (file);
+ gio_parent = g_file_get_parent (gio_file);
+ g_file_make_directory_with_parents (gio_parent, NULL, NULL);
+ data = gth_catalog_to_data (catalog, &size);
+ if (! g_write_file (gio_file,
+ FALSE,
+ G_FILE_CREATE_NONE,
+ data,
+ size,
+ NULL,
+ &error))
+ {
+ g_warning ("%s", error->message);
+ g_clear_error (&error);
}
- else
- g_file_info_remove_attribute (file_data->info, "general::event-date");
+ else {
+ GFile *parent_parent;
+ GFile *parent;
+ GList *list;
+
+ parent = g_file_get_parent (file);
+ parent_parent = g_file_get_parent (parent);
+ if (parent_parent != NULL) {
+ list = g_list_append (NULL, parent);
+ gth_monitor_folder_changed (gth_main_get_default_monitor (),
+ parent_parent,
+ list,
+ GTH_MONITOR_EVENT_CREATED);
+ g_list_free (list);
+ }
- /* standard::display-name,standard::sort-order */
+ list = g_list_append (NULL, file);
+ gth_monitor_folder_changed (gth_main_get_default_monitor (),
+ parent,
+ list,
+ GTH_MONITOR_EVENT_CREATED);
- update_standard_attributes (file_data->file,
- file_data->info,
- catalog->priv->name,
- catalog->priv->date_time);
+ g_list_free (list);
+ g_object_unref (parent);
+ }
+
+ g_free (data);
+ g_object_unref (gio_parent);
+ g_object_unref (gio_file);
}
diff --git a/extensions/catalogs/gth-catalog.h b/extensions/catalogs/gth-catalog.h
index 3d16ce6..1edf0d2 100644
--- a/extensions/catalogs/gth-catalog.h
+++ b/extensions/catalogs/gth-catalog.h
@@ -87,6 +87,8 @@ void gth_catalog_set_order (GthCatalog *catalog,
gboolean inverse);
const char * gth_catalog_get_order (GthCatalog *catalog,
gboolean *inverse);
+void gth_catalog_set_for_date (GthCatalog *catalog,
+ GthDateTime *date_time);
void gth_catalog_load_from_data (GthCatalog *catalog,
const void *buffer,
gsize count,
@@ -124,9 +126,12 @@ char * gth_catalog_get_relative_path (GFile *file);
GIcon * gth_catalog_get_icon (GFile *file);
void gth_catalog_update_standard_attributes (GFile *file,
GFileInfo *info);
-void gth_catalog_load_from_file (GFile *file,
+void gth_catalog_load_from_file_async (GFile *file,
GCancellable *cancellable,
ReadyCallback ready_func,
gpointer user_data);
+GFile * gth_catalog_get_file_for_date (GthDateTime *date_time);
+GthCatalog * gth_catalog_load_from_file (GFile *file);
+void gth_catalog_save (GthCatalog *catalog);
#endif /*GTH_CATALOG_H*/
diff --git a/extensions/catalogs/gth-file-source-catalogs.c b/extensions/catalogs/gth-file-source-catalogs.c
index d833262..e690b63 100644
--- a/extensions/catalogs/gth-file-source-catalogs.c
+++ b/extensions/catalogs/gth-file-source-catalogs.c
@@ -371,10 +371,10 @@ read_metadata_info_ready_cb (GList *files,
GFile *gio_file;
gio_file = gth_catalog_file_to_gio_file (read_metadata->file_data->file);
- gth_catalog_load_from_file (gio_file,
- gth_file_source_get_cancellable (read_metadata->file_source),
- read_metadata_catalog_ready_cb,
- read_metadata);
+ gth_catalog_load_from_file_async (gio_file,
+ gth_file_source_get_cancellable (read_metadata->file_source),
+ read_metadata_catalog_ready_cb,
+ read_metadata);
g_object_unref (gio_file);
}
@@ -763,10 +763,10 @@ copy__file_list_info_ready_cb (GList *files,
}
cod->files = g_list_reverse (cod->files);
- gth_catalog_load_from_file (cod->destination->file,
- gth_file_source_get_cancellable (cod->file_source),
- catalog_ready_cb,
- cod);
+ gth_catalog_load_from_file_async (cod->destination->file,
+ gth_file_source_get_cancellable (cod->file_source),
+ catalog_ready_cb,
+ cod);
}
@@ -955,10 +955,10 @@ gth_file_source_catalogs_reorder (GthFileSource *file_source,
reorder_data->data = data;
gio_file = gth_file_source_to_gio_file (file_source, destination->file);
- gth_catalog_load_from_file (gio_file,
- gth_file_source_get_cancellable (file_source),
- reorder_catalog_ready_cb,
- reorder_data);
+ gth_catalog_load_from_file_async (gio_file,
+ gth_file_source_get_cancellable (file_source),
+ reorder_catalog_ready_cb,
+ reorder_data);
g_object_unref (gio_file);
}
diff --git a/extensions/catalogs/gth-organize-task.c b/extensions/catalogs/gth-organize-task.c
index b5d04b9..7c05b99 100644
--- a/extensions/catalogs/gth-organize-task.c
+++ b/extensions/catalogs/gth-organize-task.c
@@ -85,60 +85,9 @@ save_catalog (gpointer key,
gpointer value,
gpointer user_data)
{
- GthOrganizeTask *self = user_data;
- GthCatalog *catalog = value;
- GFile *file;
- GFile *gio_file;
- GFile *gio_parent;
- char *data;
- gsize size;
- GError *error = NULL;
-
- file = gth_catalog_get_file (catalog);
- gio_file = gth_catalog_file_to_gio_file (file);
- gio_parent = g_file_get_parent (gio_file);
- g_file_make_directory_with_parents (gio_parent, NULL, NULL);
- data = gth_catalog_to_data (catalog, &size);
- if (! g_write_file (gio_file,
- FALSE,
- G_FILE_CREATE_NONE,
- data,
- size,
- gth_task_get_cancellable (GTH_TASK (self)),
- &error))
- {
- g_warning ("%s", error->message);
- g_clear_error (&error);
- }
- else {
- GFile *parent_parent;
- GFile *parent;
- GList *list;
-
- parent = g_file_get_parent (file);
- parent_parent = g_file_get_parent (parent);
- if (parent_parent != NULL) {
- list = g_list_append (NULL, parent);
- gth_monitor_folder_changed (gth_main_get_default_monitor (),
- parent_parent,
- list,
- GTH_MONITOR_EVENT_CREATED);
- g_list_free (list);
- }
-
- list = g_list_append (NULL, file);
- gth_monitor_folder_changed (gth_main_get_default_monitor (),
- parent,
- list,
- GTH_MONITOR_EVENT_CREATED);
-
- g_list_free (list);
- g_object_unref (parent);
- }
+ GthCatalog *catalog = value;
- g_free (data);
- g_object_unref (gio_parent);
- g_object_unref (gio_file);
+ gth_catalog_save (catalog);
}
@@ -183,7 +132,7 @@ save_catalogs (GthOrganizeTask *self)
}
while (gtk_tree_model_iter_next (GTK_TREE_MODEL (self->priv->results_liststore), &iter));
}
- g_hash_table_foreach (self->priv->catalogs, save_catalog, self);
+ g_hash_table_foreach (self->priv->catalogs, save_catalog, NULL);
gth_task_completed (GTH_TASK (self), NULL);
}
@@ -260,52 +209,6 @@ done_func (GError *error,
}
-static GFile *
-get_catalog_file (const char *base_uri,
- const char *display_name)
-{
- GFile *base;
- char *name;
- char *name_escaped;
- GFile *catalog_file;
-
- base = g_file_new_for_uri (base_uri);
- name = g_strdup_printf ("%s.catalog", display_name);
- name_escaped = _g_utf8_replace (name, "/", ".");
- catalog_file = g_file_get_child_for_display_name (base, name_escaped, NULL);
-
- g_free (name_escaped);
- g_free (name);
- g_object_unref (base);
-
- return catalog_file;
-}
-
-
-static GFile *
-get_catalog_file_for_time (GTimeVal *timeval)
-{
- char *year;
- char *uri;
- GFile *base;
- char *display_name;
- GFile *catalog_file;
-
- year = _g_time_val_strftime (timeval, "%Y");
- uri = g_strconcat ("catalog:///", year, "/", NULL);
- base = g_file_new_for_uri (uri);
- display_name = _g_time_val_strftime (timeval, "%Y-%m-%d");
- catalog_file = get_catalog_file (uri, display_name);
-
- g_free (display_name);
- g_object_unref (base);
- g_free (uri);
- g_free (year);
-
- return catalog_file;
-}
-
-
static void
for_each_file_func (GFile *file,
GFileInfo *info,
@@ -330,14 +233,13 @@ for_each_file_func (GFile *file,
metadata = g_file_info_get_attribute_object (info, "Embedded::Photo::DateTimeOriginal");
if (metadata != NULL) {
if (_g_time_val_from_exif_date (gth_metadata_get_raw (GTH_METADATA (metadata)), &timeval))
- key = g_strdup (_g_time_val_strftime (&timeval, KEY_FORMAT));
+ key = _g_time_val_strftime (&timeval, KEY_FORMAT);
}
}
break;
-
case GTH_GROUP_POLICY_MODIFIED_DATE:
timeval = *gth_file_data_get_modification_time (file_data);
- key = g_strdup (_g_time_val_strftime (&timeval, KEY_FORMAT));
+ key = _g_time_val_strftime (&timeval, KEY_FORMAT);
break;
}
@@ -347,18 +249,19 @@ for_each_file_func (GFile *file,
catalog = g_hash_table_lookup (self->priv->catalogs, key);
if (catalog == NULL) {
GthDateTime *date_time;
- char *exif_date;
GFile *catalog_file;
char *name;
GtkTreeIter iter;
- catalog = gth_catalog_new ();
date_time = gth_datetime_new ();
- exif_date = _g_time_val_to_exif_date (&timeval);
- gth_datetime_from_exif_date (date_time, exif_date);
- gth_catalog_set_date (catalog, date_time);
- catalog_file = get_catalog_file_for_time (&timeval);
- gth_catalog_set_file (catalog, catalog_file);
+ gth_datetime_from_timeval (date_time, &timeval);
+
+ catalog_file = gth_catalog_get_file_for_date (date_time);
+ catalog = gth_catalog_load_from_file (catalog_file);
+ if (catalog == NULL)
+ catalog = gth_catalog_new ();
+ gth_catalog_set_for_date (catalog, date_time);
+
g_hash_table_insert (self->priv->catalogs, g_strdup (key), catalog);
name = gth_datetime_strftime (date_time, "%x");
@@ -374,7 +277,6 @@ for_each_file_func (GFile *file,
g_free (name);
g_object_unref (catalog_file);
- g_free (exif_date);
gth_datetime_free (date_time);
}
@@ -796,7 +698,7 @@ gth_organize_task_set_singletons_catalog (GthOrganizeTask *self,
return;
self->priv->singletons_catalog = gth_catalog_new ();
- file = get_catalog_file ("catalog:///", catalog_name);
+ file = _g_file_new_for_display_name ("catalog:///", catalog_name, ".catalog");
gth_catalog_set_file (self->priv->singletons_catalog, file);
gth_catalog_set_name (self->priv->singletons_catalog, catalog_name);
diff --git a/extensions/photo_importer/dlg-photo-importer.c b/extensions/photo_importer/dlg-photo-importer.c
index 54490aa..f72a3a8 100644
--- a/extensions/photo_importer/dlg-photo-importer.c
+++ b/extensions/photo_importer/dlg-photo-importer.c
@@ -503,7 +503,7 @@ create_example_file_data (void)
"raw", "2005:03:09 13:23:51",
"formatted", "2005:03:09 13:23:51",
NULL);
- g_file_info_set_attribute_object (info, "general::datetime", G_OBJECT (metadata));
+ g_file_info_set_attribute_object (info, "Embedded::Photo::DateTimeOriginal", G_OBJECT (metadata));
g_object_unref (metadata);
g_object_unref (info);
diff --git a/extensions/photo_importer/gth-import-task.c b/extensions/photo_importer/gth-import-task.c
index 2dd791b..969e6bc 100644
--- a/extensions/photo_importer/gth-import-task.c
+++ b/extensions/photo_importer/gth-import-task.c
@@ -21,27 +21,33 @@
*/
#include <config.h>
+#include <extensions/catalogs/gth-catalog.h>
#include <extensions/image_rotation/rotation-utils.h>
#include "gth-import-task.h"
+#define IMPORTED_KEY "imported"
+
+
struct _GthImportTaskPrivate {
- GthBrowser *browser;
- GList *files;
- GFile *destination;
- GthSubfolderType subfolder_type;
- GthSubfolderFormat subfolder_format;
- gboolean single_subfolder;
- char **tags;
- gboolean delete_imported;
- gboolean overwrite_files;
- gboolean adjust_orientation;
-
- gsize tot_size;
- gsize copied_size;
- gsize current_file_size;
- GList *current;
- GthFileData *destination_file;
+ GthBrowser *browser;
+ GList *files;
+ GFile *destination;
+ GthSubfolderType subfolder_type;
+ GthSubfolderFormat subfolder_format;
+ gboolean single_subfolder;
+ char **tags;
+ gboolean delete_imported;
+ gboolean overwrite_files;
+ gboolean adjust_orientation;
+
+ GHashTable *catalogs;
+ gsize tot_size;
+ gsize copied_size;
+ gsize current_file_size;
+ GList *current;
+ GthFileData *destination_file;
+ GFile *imported_catalog;
};
@@ -62,6 +68,8 @@ gth_import_task_finalize (GObject *object)
g_object_unref (self->priv->destination);
_g_object_unref (self->priv->destination_file);
g_strfreev (self->priv->tags);
+ g_hash_table_destroy (self->priv->catalogs);
+ g_object_unref (self->priv->imported_catalog);
g_object_unref (self->priv->browser);
G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -81,6 +89,105 @@ import_next_file (GthImportTask *self)
static void
+save_catalog (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ GthCatalog *catalog = value;
+
+ gth_catalog_save (catalog);
+}
+
+
+static void
+save_catalogs (GthImportTask *self)
+{
+ g_hash_table_foreach (self->priv->catalogs, save_catalog, self);
+}
+
+
+static void
+catalog_imported_file (GthImportTask *self)
+{
+ char *key;
+ GObject *metadata;
+ GTimeVal timeval;
+ GthCatalog *catalog;
+
+ if (! gth_main_extension_is_active ("catalogs")) {
+ import_next_file (self);
+ return;
+ }
+
+ key = NULL;
+ metadata = g_file_info_get_attribute_object (self->priv->destination_file->info, "Embedded::Photo::DateTimeOriginal");
+ if (metadata != NULL) {
+ if (_g_time_val_from_exif_date (gth_metadata_get_raw (GTH_METADATA (metadata)), &timeval))
+ key = _g_time_val_strftime (&timeval, "%Y.%m.%d");
+ }
+
+ if (key == NULL) {
+ g_free (key);
+ import_next_file (self);
+ return;
+ }
+
+ catalog = g_hash_table_lookup (self->priv->catalogs, key);
+ if (catalog == NULL) {
+ GthDateTime *date_time;
+ GFile *catalog_file;
+
+ date_time = gth_datetime_new ();
+ gth_datetime_from_timeval (date_time, &timeval);
+
+ catalog_file = gth_catalog_get_file_for_date (date_time);
+ catalog = gth_catalog_load_from_file (catalog_file);
+ if (catalog == NULL)
+ catalog = gth_catalog_new ();
+ gth_catalog_set_for_date (catalog, date_time);
+
+ g_hash_table_insert (self->priv->catalogs, g_strdup (key), catalog);
+
+ g_object_unref (catalog_file);
+ gth_datetime_free (date_time);
+ }
+ gth_catalog_append_file (catalog, self->priv->destination_file->file);
+
+ catalog = g_hash_table_lookup (self->priv->catalogs, IMPORTED_KEY);
+ if (catalog == NULL) {
+ GthDateTime *date_time;
+ char *name;
+ char *display_name;
+
+ date_time = gth_datetime_new ();
+ gth_datetime_from_timeval (date_time, &timeval);
+
+ name = gth_datetime_strftime (date_time, "%Y.%m.%d-%H.%M.%S");
+ self->priv->imported_catalog = _g_file_new_for_display_name ("catalog://", name, ".catalog");
+ catalog = gth_catalog_load_from_file (self->priv->imported_catalog);
+ if (catalog == NULL)
+ catalog = gth_catalog_new ();
+
+ gth_catalog_set_file (catalog, self->priv->imported_catalog);
+ gth_catalog_set_date (catalog, date_time);
+ display_name = gth_datetime_strftime (date_time, _("Imported %x %X"));
+ gth_catalog_set_name (catalog, display_name);
+
+ g_hash_table_insert (self->priv->catalogs, g_strdup (IMPORTED_KEY), catalog);
+
+ g_free (display_name);
+ g_free (name);
+ gth_datetime_free (date_time);
+ }
+ gth_catalog_append_file (catalog, self->priv->destination_file->file);
+
+ import_next_file (self);
+
+ g_free (key);
+}
+
+
+static void
write_metadata_ready_func (GError *error,
gpointer user_data)
{
@@ -89,7 +196,7 @@ write_metadata_ready_func (GError *error,
if (error != NULL)
g_clear_error (&error);
- import_next_file (self);
+ catalog_imported_file (self);
}
@@ -102,7 +209,7 @@ transformation_ready_cb (GError *error,
GList *file_list;
if (self->priv->tags[0] == NULL) {
- import_next_file (self);
+ catalog_imported_file (self);
return;
}
@@ -140,7 +247,7 @@ copy_ready_cb (GError *error,
if (self->priv->adjust_orientation) {
GthMetadata *metadata;
- metadata = (GthMetadata *) g_file_info_get_attribute_object (self->priv->destination_file->info, "Exif::Image::Orientation");
+ metadata = (GthMetadata *) g_file_info_get_attribute_object (self->priv->destination_file->info, "Embedded::Image::Orientation");
if (metadata != NULL) {
const char *value;
@@ -186,6 +293,7 @@ copy_progress_cb (GObject *object,
s1 = g_format_size_for_display (((double) self->priv->current_file_size * fraction) + self->priv->copied_size);
s2 = g_format_size_for_display (self->priv->tot_size);
+ /* translators: this a copy progress message, for example: 1.2MB of 12MB */
local_details = g_strdup_printf (_("%s of %s"), s1, s2);
details = local_details;
@@ -277,7 +385,11 @@ import_current_file (GthImportTask *self)
GList *list;
if (self->priv->current == NULL) {
- gth_browser_go_to (self->priv->browser, self->priv->destination, NULL);
+ save_catalogs (self);
+ if (self->priv->imported_catalog != NULL)
+ gth_browser_go_to (self->priv->browser, self->priv->imported_catalog, NULL);
+ else
+ gth_browser_go_to (self->priv->browser, self->priv->destination, NULL);
gth_task_completed (GTH_TASK (self), NULL);
return;
}
@@ -285,7 +397,7 @@ import_current_file (GthImportTask *self)
file_data = self->priv->current->data;
list = g_list_prepend (NULL, file_data);
_g_query_metadata_async (list,
- "Exif::Image::DateTime,Exif::Image::Orientation",
+ "Embedded::Photo::DateTimeOriginal,Embedded::Image::Orientation",
gth_task_get_cancellable (GTH_TASK (self)),
file_info_ready_cb,
self);
@@ -332,6 +444,7 @@ static void
gth_import_task_init (GthImportTask *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_IMPORT_TASK, GthImportTaskPrivate);
+ self->priv->catalogs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
}
@@ -412,7 +525,7 @@ gth_import_task_get_file_destination (GthFileData *file_data,
else if (subfolder_type == GTH_SUBFOLDER_TYPE_FILE_DATE) {
GthMetadata *metadata;
- metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::datetime");
+ metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "Embedded::Photo::DateTimeOriginal");
if (metadata != NULL)
_g_time_val_from_exif_date (gth_metadata_get_raw (metadata), &timeval);
else
diff --git a/gthumb/glib-utils.c b/gthumb/glib-utils.c
index 53a5b85..216a78c 100644
--- a/gthumb/glib-utils.c
+++ b/gthumb/glib-utils.c
@@ -1663,6 +1663,29 @@ _g_build_uri (const char *base, ...)
/* GIO utils */
+GFile *
+_g_file_new_for_display_name (const char *base_uri,
+ const char *display_name,
+ const char *extension)
+{
+ GFile *base;
+ char *name;
+ char *name_escaped;
+ GFile *catalog_file;
+
+ base = g_file_new_for_uri (base_uri);
+ name = g_strdup_printf ("%s%s", display_name, extension);
+ name_escaped = _g_utf8_replace (name, "/", ".");
+ catalog_file = g_file_get_child_for_display_name (base, name_escaped, NULL);
+
+ g_free (name_escaped);
+ g_free (name);
+ g_object_unref (base);
+
+ return catalog_file;
+}
+
+
gboolean
_g_file_equal (GFile *file1,
GFile *file2)
diff --git a/gthumb/glib-utils.h b/gthumb/glib-utils.h
index 94bb22e..330f46c 100644
--- a/gthumb/glib-utils.h
+++ b/gthumb/glib-utils.h
@@ -218,6 +218,9 @@ char * _g_build_uri (const char *base,
/* GIO utils */
+GFile * _g_file_new_for_display_name (const char *base_uri,
+ const char *display_name,
+ const char *extension);
gboolean _g_file_equal (GFile *file1,
GFile *file2);
char * _g_file_get_display_name (GFile *file);
diff --git a/gthumb/gth-extensions.c b/gthumb/gth-extensions.c
index e05c156..a428d1f 100644
--- a/gthumb/gth-extensions.c
+++ b/gthumb/gth-extensions.c
@@ -825,6 +825,20 @@ gth_extension_manager_deactivate (GthExtensionManager *manager,
}
+gboolean
+gth_extension_manager_is_active (GthExtensionManager *manager,
+ const char *extension_name)
+{
+ GthExtensionDescription *description;
+
+ description = g_hash_table_lookup (manager->priv->extensions, extension_name);
+ if (description != NULL)
+ return gth_extension_description_is_active (description);
+ else
+ return NULL;
+}
+
+
GList *
gth_extension_manager_get_extensions (GthExtensionManager *manager)
{
diff --git a/gthumb/gth-extensions.h b/gthumb/gth-extensions.h
index b56aa73..b276fec 100644
--- a/gthumb/gth-extensions.h
+++ b/gthumb/gth-extensions.h
@@ -168,6 +168,8 @@ gboolean gth_extension_manager_activate (GthExtension
gboolean gth_extension_manager_deactivate (GthExtensionManager *manager,
const char *extension_name,
GError **error);
+gboolean gth_extension_manager_is_active (GthExtensionManager *manager,
+ const char *extension_name);
GList * gth_extension_manager_get_extensions (GthExtensionManager *manager);
GthExtensionDescription * gth_extension_manager_get_description (GthExtensionManager *manager,
const char *extension_name);
diff --git a/gthumb/gth-main.c b/gthumb/gth-main.c
index 53f535e..388903a 100644
--- a/gthumb/gth-main.c
+++ b/gthumb/gth-main.c
@@ -1247,6 +1247,16 @@ gth_main_activate_extensions (void)
}
+gboolean
+gth_main_extension_is_active (const char *extension_name)
+{
+ if (Main->priv->extension_manager == NULL)
+ return FALSE;
+ else
+ return gth_extension_manager_is_active (Main->priv->extension_manager, extension_name);
+}
+
+
/* utilities */
diff --git a/gthumb/gth-main.h b/gthumb/gth-main.h
index af6e158..d7612ac 100644
--- a/gthumb/gth-main.h
+++ b/gthumb/gth-main.h
@@ -122,6 +122,7 @@ void gth_main_register_default_types (void);
void gth_main_register_default_sort_types (void);
void gth_main_register_default_metadata (void);
void gth_main_activate_extensions (void);
+gboolean gth_main_extension_is_active (const char *extension_name);
/* utilities */
diff --git a/gthumb/gth-time.c b/gthumb/gth-time.c
index 0a7ee13..2ec4068 100644
--- a/gthumb/gth-time.c
+++ b/gthumb/gth-time.c
@@ -119,6 +119,19 @@ gth_datetime_valid (GthDateTime *dt)
}
+void
+gth_datetime_from_timeval (GthDateTime *dt,
+ GTimeVal *tv)
+{
+ char *exif_date;
+
+ exif_date = _g_time_val_to_exif_date (tv);
+ gth_datetime_from_exif_date (dt, exif_date);
+
+ g_free (exif_date);
+}
+
+
gboolean
gth_datetime_from_exif_date (GthDateTime *dt,
const char *exif_date)
diff --git a/gthumb/gth-time.h b/gthumb/gth-time.h
index d5eaabe..a9c9feb 100644
--- a/gthumb/gth-time.h
+++ b/gthumb/gth-time.h
@@ -53,6 +53,8 @@ GthDateTime * gth_datetime_new (void);
void gth_datetime_free (GthDateTime *dt);
void gth_datetime_clear (GthDateTime *dt);
gboolean gth_datetime_valid (GthDateTime *dt);
+void gth_datetime_from_timeval (GthDateTime *dt,
+ GTimeVal *tv);
gboolean gth_datetime_from_exif_date (GthDateTime *dt,
const char *exif_date);
void gth_datetime_from_struct_tm (GthDateTime *dt,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]