[gthumb] [photo_importer] added ability to specify a custom format
- From: Paolo Bacchilega <paobac src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gthumb] [photo_importer] added ability to specify a custom format
- Date: Sat, 16 Jan 2010 16:15:33 +0000 (UTC)
commit 3b43d7b3efd35fa486673abd01007c9f06d62047
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sat Jan 16 17:13:17 2010 +0100
[photo_importer] added ability to specify a custom format
the custom format consists of the strftime format plus the %E code
which is used to specify the event name.
.../data/gthumb_photo_importer.schemas.in | 13 ++++
.../photo_importer/data/ui/photo-importer.ui | 58 +++++++++++++++++--
extensions/photo_importer/dlg-photo-importer.c | 61 ++++++++++++++++++--
extensions/photo_importer/gth-import-task.c | 61 ++++++++++++++------
extensions/photo_importer/gth-import-task.h | 5 +-
extensions/photo_importer/preferences.h | 20 ++++---
6 files changed, 178 insertions(+), 40 deletions(-)
---
diff --git a/extensions/photo_importer/data/gthumb_photo_importer.schemas.in b/extensions/photo_importer/data/gthumb_photo_importer.schemas.in
index 0e5e99e..ea9852b 100644
--- a/extensions/photo_importer/data/gthumb_photo_importer.schemas.in
+++ b/extensions/photo_importer/data/gthumb_photo_importer.schemas.in
@@ -54,6 +54,19 @@
</schema>
<schema>
+ <key>/schemas/apps/gthumb/ext/photo_importer/subfolder_custom_format</key>
+ <applyto>/apps/gthumb/ext/photo_importer/subfolder_custom_format</applyto>
+ <owner>gthumb</owner>
+ <type>string</type>
+ <default></default>
+ <locale name="C">
+ <short></short>
+ <long>
+ </long>
+ </locale>
+ </schema>
+
+ <schema>
<key>/schemas/apps/gthumb/ext/photo_importer/delete_from_camera</key>
<applyto>/apps/gthumb/ext/photo_importer/delete_from_camera</applyto>
<owner>gthumb</owner>
diff --git a/extensions/photo_importer/data/ui/photo-importer.ui b/extensions/photo_importer/data/ui/photo-importer.ui
index fcf703d..c77115a 100644
--- a/extensions/photo_importer/data/ui/photo-importer.ui
+++ b/extensions/photo_importer/data/ui/photo-importer.ui
@@ -416,13 +416,43 @@
<placeholder/>
</child>
<child>
- <object class="GtkCheckButton" id="single_subfolder_checkbutton">
- <property name="label" translatable="yes">as _single subfolder</property>
+ <object class="GtkNotebook" id="subfolder_options_notebook">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="use_underline">True</property>
- <property name="draw_indicator">True</property>
+ <property name="show_tabs">False</property>
+ <property name="show_border">False</property>
+ <child>
+ <object class="GtkCheckButton" id="single_subfolder_checkbutton">
+ <property name="label" translatable="yes">as _single subfolder</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ </child>
+ <child type="tab">
+ <placeholder/>
+ </child>
+ <child>
+ <object class="GtkEntry" id="custom_format_entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">●</property>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child type="tab">
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child type="tab">
+ <placeholder/>
+ </child>
</object>
<packing>
<property name="pack_type">end</property>
@@ -445,7 +475,7 @@
<object class="GtkLabel" id="example_label">
<property name="visible">True</property>
<property name="xalign">0</property>
- <property name="label" translatable="yes">example: file:///home/paolo/images/2009/08/12</property>
+ <property name="label">example: file:///home/paolo/images/2009/08/12</property>
<attributes>
<attribute name="size" value="8500"/>
</attributes>
@@ -546,6 +576,21 @@
<property name="position">0</property>
</packing>
</child>
+ <child>
+ <object class="GtkButton" id="help_button">
+ <property name="label">gtk-help</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ <property name="secondary">True</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
@@ -557,6 +602,7 @@
</child>
<action-widgets>
<action-widget response="0">p_close_button</action-widget>
+ <action-widget response="0">help_button</action-widget>
</action-widgets>
</object>
</interface>
diff --git a/extensions/photo_importer/dlg-photo-importer.c b/extensions/photo_importer/dlg-photo-importer.c
index 8eda3be..ce09f13 100644
--- a/extensions/photo_importer/dlg-photo-importer.c
+++ b/extensions/photo_importer/dlg-photo-importer.c
@@ -82,6 +82,7 @@ destroy_dialog (gpointer user_data)
gboolean single_subfolder;
GthSubfolderType subfolder_type;
GthSubfolderFormat subfolder_format;
+ const char *custom_format;
gboolean delete_imported;
gboolean overwrite_files;
gboolean adjust_orientation;
@@ -107,6 +108,9 @@ destroy_dialog (gpointer user_data)
subfolder_format = gtk_combo_box_get_active (GTK_COMBO_BOX (data->subfolder_format_list));
eel_gconf_set_enum (PREF_PHOTO_IMPORT_SUBFOLDER_FORMAT, GTH_TYPE_SUBFOLDER_FORMAT, subfolder_format);
+ custom_format = gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("custom_format_entry")));
+ eel_gconf_set_string (PREF_PHOTO_IMPORT_SUBFOLDER_CUSTOM_FORMAT, custom_format);
+
delete_imported = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("delete_checkbutton")));
eel_gconf_set_boolean (PREF_PHOTO_IMPORT_DELETE, delete_imported);
@@ -139,6 +143,7 @@ destroy_dialog (gpointer user_data)
subfolder_type,
subfolder_format,
single_subfolder,
+ custom_format,
gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("event_entry"))),
tags,
delete_imported,
@@ -210,9 +215,9 @@ close_dialog (gpointer unused,
static gboolean
-delete_event_cb (GtkWidget *widget,
- GdkEvent *event,
- gpointer user_data)
+dialog_delete_event_cb (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
{
close_dialog (NULL, (DialogData *) user_data);
return TRUE;
@@ -521,6 +526,7 @@ update_destination (DialogData *data)
GthSubfolderType subfolder_type;
GthSubfolderFormat subfolder_format;
gboolean single_subfolder;
+ const char *custom_format;
GthFileData *example_data;
GFile *destination_example;
char *uri;
@@ -533,9 +539,16 @@ update_destination (DialogData *data)
subfolder_type = get_subfolder_type (data);
subfolder_format = gtk_combo_box_get_active (GTK_COMBO_BOX (data->subfolder_format_list));
single_subfolder = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("single_subfolder_checkbutton")));
+ custom_format = gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("custom_format_entry")));
example_data = create_example_file_data ();
- destination_example = gth_import_task_get_file_destination (example_data, destination, subfolder_type, subfolder_format, single_subfolder);
+ destination_example = gth_import_task_get_file_destination (example_data,
+ destination,
+ subfolder_type,
+ subfolder_format,
+ single_subfolder,
+ custom_format,
+ gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("event_entry"))));
uri = g_file_get_parse_name (destination_example);
example = g_strdup_printf (_("example: %s"), uri);
@@ -544,6 +557,9 @@ update_destination (DialogData *data)
gtk_widget_set_sensitive (GET_WIDGET ("single_subfolder_checkbutton"), subfolder_type != GTH_SUBFOLDER_TYPE_NONE);
gtk_widget_set_sensitive (data->subfolder_type_list, subfolder_type != GTH_SUBFOLDER_TYPE_NONE);
gtk_widget_set_sensitive (data->subfolder_format_list, subfolder_type != GTH_SUBFOLDER_TYPE_NONE);
+ gtk_widget_set_sensitive (GET_WIDGET ("subfolder_options_notebook"), subfolder_type != GTH_SUBFOLDER_TYPE_NONE);
+
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (GET_WIDGET ("subfolder_options_notebook")), (subfolder_format == GTH_SUBFOLDER_FORMAT_CUSTOM) ? 1 : 0);
g_free (example);
g_free (uri);
@@ -553,6 +569,16 @@ update_destination (DialogData *data)
}
+static gboolean
+preferences_dialog_map_event_cb (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ update_destination ((DialogData *) user_data);
+ return FALSE;
+}
+
+
static void
subfolder_type_list_changed_cb (GtkWidget *widget,
DialogData *data)
@@ -601,6 +627,14 @@ autosubfolder_checkbutton_toggled_cb (GtkToggleButton *togglebutton,
}
+static void
+custom_format_entry_changed_cb (GtkEditable *editable,
+ DialogData *data)
+{
+ update_destination (data);
+}
+
+
void
dlg_photo_importer (GthBrowser *browser,
GFile *source)
@@ -613,6 +647,7 @@ dlg_photo_importer (GthBrowser *browser,
int i, active_filter;
int i_general;
GthSubfolderType subfolder_type;
+ char *custom_format;
if (gth_browser_get_dialog (browser, "photo_importer") != NULL) {
gtk_window_present (GTK_WINDOW (gth_browser_get_dialog (browser, "photo_importer")));
@@ -680,6 +715,7 @@ dlg_photo_importer (GthBrowser *browser,
data->subfolder_format_list = _gtk_combo_box_new_with_texts (_("year-month-day"),
_("year-month"),
_("year"),
+ _("custom format"),
NULL);
gtk_combo_box_set_active (GTK_COMBO_BOX (data->subfolder_format_list), 0);
gtk_widget_show (data->subfolder_format_list);
@@ -759,13 +795,19 @@ dlg_photo_importer (GthBrowser *browser,
gtk_combo_box_set_active (GTK_COMBO_BOX (data->subfolder_type_list), (subfolder_type == 0) ? 0 : subfolder_type - 1);
gtk_combo_box_set_active (GTK_COMBO_BOX (data->subfolder_format_list), eel_gconf_get_enum (PREF_PHOTO_IMPORT_SUBFOLDER_FORMAT, GTH_TYPE_SUBFOLDER_FORMAT, GTH_SUBFOLDER_FORMAT_YYYYMMDD));
+ custom_format = eel_gconf_get_string (PREF_PHOTO_IMPORT_SUBFOLDER_CUSTOM_FORMAT, "");
+ if (custom_format != NULL) {
+ gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("custom_format_entry")), custom_format);
+ g_free (custom_format);
+ }
+
update_destination (data);
/* Set the signals handlers. */
g_signal_connect (G_OBJECT (data->dialog),
"delete-event",
- G_CALLBACK (delete_event_cb),
+ G_CALLBACK (dialog_delete_event_cb),
data);
g_signal_connect (GET_WIDGET ("ok_button"),
"clicked",
@@ -812,6 +854,10 @@ dlg_photo_importer (GthBrowser *browser,
G_CALLBACK (preferences_button_clicked_cb),
data);
g_signal_connect (GET_WIDGET ("preferences_dialog"),
+ "map-event",
+ G_CALLBACK (preferences_dialog_map_event_cb),
+ data);
+ g_signal_connect (GET_WIDGET ("preferences_dialog"),
"delete-event",
G_CALLBACK (gtk_widget_hide_on_delete),
NULL);
@@ -823,7 +869,10 @@ dlg_photo_importer (GthBrowser *browser,
"toggled",
G_CALLBACK (autosubfolder_checkbutton_toggled_cb),
data);
-
+ g_signal_connect (GET_WIDGET ("custom_format_entry"),
+ "changed",
+ G_CALLBACK (custom_format_entry_changed_cb),
+ data);
data->monitor_event = g_signal_connect (gth_main_get_default_monitor (),
"entry_points_changed",
G_CALLBACK (entry_points_changed_cb),
diff --git a/extensions/photo_importer/gth-import-task.c b/extensions/photo_importer/gth-import-task.c
index 2c36e98..8683237 100644
--- a/extensions/photo_importer/gth-import-task.c
+++ b/extensions/photo_importer/gth-import-task.c
@@ -36,6 +36,7 @@ struct _GthImportTaskPrivate {
GthSubfolderType subfolder_type;
GthSubfolderFormat subfolder_format;
gboolean single_subfolder;
+ char *custom_format;
char *event_name;
char **tags;
gboolean delete_imported;
@@ -68,6 +69,7 @@ gth_import_task_finalize (GObject *object)
_g_object_list_unref (self->priv->files);
g_object_unref (self->priv->destination);
_g_object_unref (self->priv->destination_file);
+ g_free (self->priv->custom_format);
g_free (self->priv->event_name);
g_strfreev (self->priv->tags);
g_hash_table_destroy (self->priv->catalogs);
@@ -343,7 +345,9 @@ file_info_ready_cb (GList *files,
self->priv->destination,
self->priv->subfolder_type,
self->priv->subfolder_format,
- self->priv->single_subfolder);
+ self->priv->single_subfolder,
+ self->priv->custom_format,
+ self->priv->event_name);
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);
@@ -488,6 +492,7 @@ gth_import_task_new (GthBrowser *browser,
GthSubfolderType subfolder_type,
GthSubfolderFormat subfolder_format,
gboolean single_subfolder,
+ const char *custom_format,
const char *event_name,
char **tags,
gboolean delete_imported,
@@ -503,6 +508,10 @@ gth_import_task_new (GthBrowser *browser,
self->priv->subfolder_type = subfolder_type;
self->priv->subfolder_format = subfolder_format;
self->priv->single_subfolder = single_subfolder;
+ if (custom_format != NULL)
+ self->priv->custom_format = g_strdup (custom_format);
+ else
+ self->priv->custom_format = NULL;
self->priv->event_name = g_strdup (event_name);
self->priv->tags = g_strdupv (tags);
self->priv->delete_imported = delete_imported;
@@ -518,12 +527,13 @@ gth_import_task_get_file_destination (GthFileData *file_data,
GFile *destination,
GthSubfolderType subfolder_type,
GthSubfolderFormat subfolder_format,
- gboolean single_subfolder)
+ gboolean single_subfolder,
+ const char *custom_format,
+ const char *event_name)
{
- GFile *file_destination;
- GTimeVal timeval;
- char **parts;
- char *child;
+ GTimeVal timeval;
+ char *child;
+ GFile *file_destination;
if (subfolder_type == GTH_SUBFOLDER_TYPE_FILE_DATE) {
GthMetadata *metadata;
@@ -538,12 +548,12 @@ gth_import_task_get_file_destination (GthFileData *file_data,
if (subfolder_type == GTH_SUBFOLDER_TYPE_CURRENT_DATE)
g_get_current_time (&timeval);
- parts = NULL;
switch (subfolder_type) {
case GTH_SUBFOLDER_TYPE_FILE_DATE:
case GTH_SUBFOLDER_TYPE_CURRENT_DATE:
- {
- GDate *date;
+ if (subfolder_format != GTH_SUBFOLDER_FORMAT_CUSTOM) {
+ GDate *date;
+ char **parts;
date = g_date_new ();
g_date_set_time_val (date, &timeval);
@@ -556,25 +566,40 @@ gth_import_task_get_file_destination (GthFileData *file_data,
parts[2] = g_strdup_printf ("%02d", g_date_get_day (date));
}
+ if (single_subfolder)
+ child = g_strjoinv ("-", parts);
+ else
+ child = g_strjoinv ("/", parts);
+
+ g_strfreev (parts);
g_date_free (date);
}
+ else {
+ char *format = NULL;
+
+ if (event_name != NULL) {
+ GRegex *re;
+
+ re = g_regex_new ("%E", 0, 0, NULL);
+ format = g_regex_replace_literal (re, custom_format, -1, 0, event_name, 0, NULL);
+
+ g_regex_unref (re);
+ }
+ if (format == NULL)
+ format = g_strdup (custom_format);
+ child = _g_time_val_strftime (&timeval, format);
+
+ g_free (format);
+ }
break;
case GTH_SUBFOLDER_TYPE_NONE:
+ child = NULL;
break;
}
-
- if (parts == NULL)
- child = NULL;
- else if (single_subfolder)
- child = g_strjoinv ("-", parts);
- else
- child = g_strjoinv ("/", parts);
-
file_destination = _g_file_append_path (destination, child);
g_free (child);
- g_strfreev (parts);
return file_destination;
}
diff --git a/extensions/photo_importer/gth-import-task.h b/extensions/photo_importer/gth-import-task.h
index e3426e1..42825e3 100644
--- a/extensions/photo_importer/gth-import-task.h
+++ b/extensions/photo_importer/gth-import-task.h
@@ -56,6 +56,7 @@ GthTask * gth_import_task_new (GthBrowser *browser,
GthSubfolderType subfolder_type,
GthSubfolderFormat subfolder_format,
gboolean single_subfolder,
+ const char *custom_format,
const char *event_name,
char **tags,
gboolean delete_imported,
@@ -65,7 +66,9 @@ GFile * gth_import_task_get_file_destination (GthFileData *file_dat
GFile *destination,
GthSubfolderType subfolder_type,
GthSubfolderFormat subfolder_format,
- gboolean single_subfolder);
+ gboolean single_subfolder,
+ const char *custom_format,
+ const char *event_name);
G_END_DECLS
diff --git a/extensions/photo_importer/preferences.h b/extensions/photo_importer/preferences.h
index 9e9b3d2..3ff58d8 100644
--- a/extensions/photo_importer/preferences.h
+++ b/extensions/photo_importer/preferences.h
@@ -30,24 +30,26 @@ G_BEGIN_DECLS
typedef enum {
GTH_SUBFOLDER_TYPE_NONE = 0,
GTH_SUBFOLDER_TYPE_FILE_DATE,
- GTH_SUBFOLDER_TYPE_CURRENT_DATE
+ GTH_SUBFOLDER_TYPE_CURRENT_DATE,
} GthSubfolderType;
typedef enum {
GTH_SUBFOLDER_FORMAT_YYYYMMDD,
GTH_SUBFOLDER_FORMAT_YYYYMM,
- GTH_SUBFOLDER_FORMAT_YYYY
+ GTH_SUBFOLDER_FORMAT_YYYY,
+ GTH_SUBFOLDER_FORMAT_CUSTOM
} GthSubfolderFormat;
-#define PREF_PHOTO_IMPORT_DESTINATION "/apps/gthumb/ext/photo_importer/destination"
-#define PREF_PHOTO_IMPORT_SUBFOLDER_TYPE "/apps/gthumb/ext/photo_importer/subfolder_type"
-#define PREF_PHOTO_IMPORT_SUBFOLDER_FORMAT "/apps/gthumb/ext/photo_importer/subfolder_format"
-#define PREF_PHOTO_IMPORT_SUBFOLDER_SINGLE "/apps/gthumb/ext/photo_importer/subfolder_single"
-#define PREF_PHOTO_IMPORT_DELETE "/apps/gthumb/ext/photo_importer/delete_from_camera"
-#define PREF_PHOTO_IMPORT_OVERWRITE "/apps/gthumb/ext/photo_importer/overwrite_files"
-#define PREF_PHOTO_IMPORT_ADJUST_ORIENTATION "/apps/gthumb/ext/photo_importer/adjust_orientation"
+#define PREF_PHOTO_IMPORT_DESTINATION "/apps/gthumb/ext/photo_importer/destination"
+#define PREF_PHOTO_IMPORT_SUBFOLDER_TYPE "/apps/gthumb/ext/photo_importer/subfolder_type"
+#define PREF_PHOTO_IMPORT_SUBFOLDER_FORMAT "/apps/gthumb/ext/photo_importer/subfolder_format"
+#define PREF_PHOTO_IMPORT_SUBFOLDER_SINGLE "/apps/gthumb/ext/photo_importer/subfolder_single"
+#define PREF_PHOTO_IMPORT_SUBFOLDER_CUSTOM_FORMAT "/apps/gthumb/ext/photo_importer/subfolder_custom_format"
+#define PREF_PHOTO_IMPORT_DELETE "/apps/gthumb/ext/photo_importer/delete_from_camera"
+#define PREF_PHOTO_IMPORT_OVERWRITE "/apps/gthumb/ext/photo_importer/overwrite_files"
+#define PREF_PHOTO_IMPORT_ADJUST_ORIENTATION "/apps/gthumb/ext/photo_importer/adjust_orientation"
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]