Commit fcf2550d authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

[photo importer] added ability to choose the subfolder format

parent 4e427329
......@@ -27,6 +27,19 @@
</locale>
</schema>
<schema>
<key>/schemas/apps/gthumb/ext/photo_importer/subfolder_format</key>
<applyto>/apps/gthumb/ext/photo_importer/subfolder_format</applyto>
<owner>gthumb</owner>
<type>string</type>
<default>yyyymmdd</default>
<locale name="C">
<short></short>
<long>Possible values are: yyyymmdd, yyyymm, yyyy
</long>
</locale>
</schema>
<schema>
<key>/schemas/apps/gthumb/ext/photo_importer/subfolder_single</key>
<applyto>/apps/gthumb/ext/photo_importer/subfolder_single</applyto>
......
......@@ -370,51 +370,13 @@
<child>
<object class="GtkFileChooserButton" id="destination_filechooserbutton">
<property name="visible">True</property>
<property name="action">select-folder</property>
<property name="local_only">False</property>
<property name="action">select-folder</property>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">+</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="subfolder_type_box">
<property name="visible">True</property>
<property name="spacing">6</property>
<child>
<placeholder/>
</child>
<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>
<packing>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
......@@ -422,18 +384,10 @@
</packing>
</child>
<child>
<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>
<attributes>
<attribute name="size" value="8500"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
......@@ -455,6 +409,83 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbox6">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkCheckButton" id="autosubfolder_checkbutton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="label" translatable="yes">_Automatic subfolder</property>
<property name="use_underline">True</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
</child>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
<property name="top_padding">6</property>
<property name="left_padding">14</property>
<child>
<object class="GtkHBox" id="subfolder_type_box">
<property name="visible">True</property>
<property name="spacing">6</property>
<child>
<placeholder/>
</child>
<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>
<packing>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<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>
<attributes>
<attribute name="size" value="8500"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
......
......@@ -48,6 +48,7 @@ typedef struct {
GtkListStore *source_store;
GtkWidget *source_list;
GtkWidget *subfolder_type_list;
GtkWidget *subfolder_format_list;
GtkWidget *file_list;
GCancellable *cancellable;
GList *files;
......@@ -63,15 +64,26 @@ typedef struct {
} DialogData;
static GthSubfolderType
get_subfolder_type (DialogData *data)
{
if (! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("autosubfolder_checkbutton"))))
return GTH_SUBFOLDER_TYPE_NONE;
else
return gtk_combo_box_get_active (GTK_COMBO_BOX (data->subfolder_type_list)) + 1;
}
static void
destroy_dialog (gpointer user_data)
{
DialogData *data = user_data;
GFile *destination;
gboolean single_subfolder;
GthSubfolderType subfolder_type;
gboolean delete_imported;
gboolean adjust_orientation;
DialogData *data = user_data;
GFile *destination;
gboolean single_subfolder;
GthSubfolderType subfolder_type;
GthSubfolderFormat subfolder_format;
gboolean delete_imported;
gboolean adjust_orientation;
g_signal_handler_disconnect (gth_main_get_default_monitor (), data->monitor_event);
......@@ -88,9 +100,12 @@ destroy_dialog (gpointer user_data)
single_subfolder = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("single_subfolder_checkbutton")));
eel_gconf_set_boolean (PREF_PHOTO_IMPORT_SUBFOLDER_SINGLE, single_subfolder);
subfolder_type = gtk_combo_box_get_active (GTK_COMBO_BOX (data->subfolder_type_list));
subfolder_type = get_subfolder_type (data);
eel_gconf_set_enum (PREF_PHOTO_IMPORT_SUBFOLDER_TYPE, GTH_TYPE_SUBFOLDER_TYPE, subfolder_type);
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);
delete_imported = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("delete_checkbutton")));
eel_gconf_set_boolean (PREF_PHOTO_IMPORT_DELETE, delete_imported);
......@@ -110,6 +125,7 @@ destroy_dialog (gpointer user_data)
files,
destination,
subfolder_type,
subfolder_format,
single_subfolder,
tags,
delete_imported,
......@@ -512,29 +528,33 @@ create_example_file_data (void)
static void
update_destination (DialogData *data)
{
GFile *destination;
GthSubfolderType subfolder_type;
gboolean single_subfolder;
GthFileData *example_data;
GFile *destination_example;
char *uri;
char *example;
GFile *destination;
GthSubfolderType subfolder_type;
GthSubfolderFormat subfolder_format;
gboolean single_subfolder;
GthFileData *example_data;
GFile *destination_example;
char *uri;
char *example;
destination = gtk_file_chooser_get_current_folder_file (GTK_FILE_CHOOSER (GET_WIDGET ("destination_filechooserbutton")));
if (destination == NULL)
return;
subfolder_type = gtk_combo_box_get_active (GTK_COMBO_BOX (data->subfolder_type_list));
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")));
example_data = create_example_file_data ();
destination_example = gth_import_task_get_file_destination (example_data, destination, subfolder_type, single_subfolder);
destination_example = gth_import_task_get_file_destination (example_data, destination, subfolder_type, subfolder_format, single_subfolder);
uri = g_file_get_uri (destination_example);
example = g_strdup_printf (_("example: %s"), uri);
gtk_label_set_text (GTK_LABEL (GET_WIDGET ("example_label")), example);
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);
g_free (example);
g_free (uri);
......@@ -552,6 +572,14 @@ subfolder_type_list_changed_cb (GtkWidget *widget,
}
static void
subfolder_format_list_changed_cb (GtkWidget *widget,
DialogData *data)
{
update_destination (data);
}
static void
destination_selection_changed_cb (GtkWidget *widget,
DialogData *data)
......@@ -576,17 +604,26 @@ preferences_button_clicked_cb (GtkWidget *widget,
}
static void
autosubfolder_checkbutton_toggled_cb (GtkToggleButton *togglebutton,
DialogData *data)
{
update_destination (data);
}
void
dlg_photo_importer (GthBrowser *browser,
GFile *source)
{
DialogData *data;
GtkCellRenderer *renderer;
GthFileDataSort *sort_type;
GList *tests, *scan;
char *general_filter;
int i, active_filter;
int i_general;
DialogData *data;
GtkCellRenderer *renderer;
GthFileDataSort *sort_type;
GList *tests, *scan;
char *general_filter;
int i, active_filter;
int i_general;
GthSubfolderType subfolder_type;
if (gth_browser_get_dialog (browser, "photo_importer") != NULL) {
gtk_window_present (GTK_WINDOW (gth_browser_get_dialog (browser, "photo_importer")));
......@@ -630,8 +667,7 @@ dlg_photo_importer (GthBrowser *browser,
"text", SOURCE_LIST_COLUMN_NAME,
NULL);
data->subfolder_type_list = _gtk_combo_box_new_with_texts (_("No subfolder"),
_("File date"),
data->subfolder_type_list = _gtk_combo_box_new_with_texts (_("File date"),
_("Current date"),
NULL);
gtk_combo_box_set_active (GTK_COMBO_BOX (data->subfolder_type_list), 0);
......@@ -652,6 +688,14 @@ dlg_photo_importer (GthBrowser *browser,
/*gtk_label_set_mnemonic_widget (GTK_LABEL (GET_WIDGET ("files_label")), data->file_list);*/
data->subfolder_format_list = _gtk_combo_box_new_with_texts (_("year-month-day"),
_("year-month"),
_("year"),
NULL);
gtk_combo_box_set_active (GTK_COMBO_BOX (data->subfolder_format_list), 0);
gtk_widget_show (data->subfolder_format_list);
gtk_box_pack_start (GTK_BOX (GET_WIDGET ("subfolder_type_box")), data->subfolder_format_list, TRUE, TRUE, 0);
/**/
tests = gth_main_get_registered_objects_id (GTH_TYPE_TEST);
......@@ -720,7 +764,11 @@ dlg_photo_importer (GthBrowser *browser,
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("delete_checkbutton")), eel_gconf_get_boolean (PREF_PHOTO_IMPORT_DELETE, FALSE));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("adjust_orientation_checkbutton")), eel_gconf_get_boolean (PREF_PHOTO_IMPORT_ADJUST_ORIENTATION, TRUE));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("single_subfolder_checkbutton")), eel_gconf_get_boolean (PREF_PHOTO_IMPORT_SUBFOLDER_SINGLE, TRUE));
gtk_combo_box_set_active (GTK_COMBO_BOX (data->subfolder_type_list), eel_gconf_get_enum (PREF_PHOTO_IMPORT_SUBFOLDER_TYPE, GTH_TYPE_SUBFOLDER_TYPE, GTH_SUBFOLDER_TYPE_FILE_DATE));
subfolder_type = eel_gconf_get_enum (PREF_PHOTO_IMPORT_SUBFOLDER_TYPE, GTH_TYPE_SUBFOLDER_TYPE, GTH_SUBFOLDER_TYPE_FILE_DATE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("autosubfolder_checkbutton")), subfolder_type != GTH_SUBFOLDER_TYPE_NONE);
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));
update_destination (data);
/* Set the signals handlers. */
......@@ -765,6 +813,10 @@ dlg_photo_importer (GthBrowser *browser,
"changed",
G_CALLBACK (subfolder_type_list_changed_cb),
data);
g_signal_connect (data->subfolder_format_list,
"changed",
G_CALLBACK (subfolder_format_list_changed_cb),
data);
g_signal_connect (GET_WIDGET ("destination_filechooserbutton"),
"selection_changed",
G_CALLBACK (destination_selection_changed_cb),
......@@ -785,6 +837,10 @@ dlg_photo_importer (GthBrowser *browser,
"clicked",
G_CALLBACK (gtk_widget_hide_on_delete),
GET_WIDGET ("preferences_dialog"));
g_signal_connect (GET_WIDGET ("autosubfolder_checkbutton"),
"toggled",
G_CALLBACK (autosubfolder_checkbutton_toggled_cb),
data);
data->monitor_event = g_signal_connect (gth_main_get_default_monitor (),
"entry_points_changed",
......
......@@ -26,21 +26,22 @@
struct _GthImportTaskPrivate {
GthBrowser *browser;
GList *files;
GFile *destination;
GthSubfolderType subfolder_type;
gboolean single_subfolder;
char **tags;
gboolean delete_imported;
gboolean adjust_orientation;
GCancellable *cancellable;
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 adjust_orientation;
GCancellable *cancellable;
gsize tot_size;
gsize copied_size;
gsize current_file_size;
GList *current;
GthFileData *destination_file;
};
......@@ -214,6 +215,7 @@ file_info_ready_cb (GList *files,
destination = gth_import_task_get_file_destination (file_data,
self->priv->destination,
self->priv->subfolder_type,
self->priv->subfolder_format,
self->priv->single_subfolder);
if (! g_file_make_directory_with_parents (destination, self->priv->cancellable, &error)) {
if (! g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
......@@ -345,14 +347,15 @@ gth_import_task_get_type (void)
GthTask *
gth_import_task_new (GthBrowser *browser,
GList *files,
GFile *destination,
GthSubfolderType subfolder_type,
gboolean single_subfolder,
char **tags,
gboolean delete_imported,
gboolean adjust_orientation)
gth_import_task_new (GthBrowser *browser,
GList *files,
GFile *destination,
GthSubfolderType subfolder_type,
GthSubfolderFormat subfolder_format,
gboolean single_subfolder,
char **tags,
gboolean delete_imported,
gboolean adjust_orientation)
{
GthImportTask *self;
......@@ -361,6 +364,7 @@ gth_import_task_new (GthBrowser *browser,
self->priv->files = _g_object_list_ref (files);
self->priv->destination = g_file_dup (destination);
self->priv->subfolder_type = subfolder_type;
self->priv->subfolder_format = subfolder_format;
self->priv->single_subfolder = single_subfolder;
self->priv->tags = g_strdupv (tags);
self->priv->delete_imported = delete_imported;
......@@ -371,10 +375,11 @@ gth_import_task_new (GthBrowser *browser,
GFile *
gth_import_task_get_file_destination (GthFileData *file_data,
GFile *destination,
GthSubfolderType subfolder_type,
gboolean single_subfolder)
gth_import_task_get_file_destination (GthFileData *file_data,
GFile *destination,
GthSubfolderType subfolder_type,
GthSubfolderFormat subfolder_format,
gboolean single_subfolder)
{
GFile *file_destination;
GTimeVal timeval;
......@@ -404,8 +409,11 @@ gth_import_task_get_file_destination (GthFileData *file_data,
parts = g_new0 (char *, 4);
parts[0] = g_strdup_printf ("%04d", g_date_get_year (date));
parts[1] = g_strdup_printf ("%02d", g_date_get_month (date));
parts[2] = g_strdup_printf ("%02d", g_date_get_day (date));
if (subfolder_format != GTH_SUBFOLDER_FORMAT_YYYY) {
parts[1] = g_strdup_printf ("%02d", g_date_get_month (date));
if (subfolder_format != GTH_SUBFOLDER_FORMAT_YYYYMM)
parts[2] = g_strdup_printf ("%02d", g_date_get_day (date));
}
break;
case GTH_SUBFOLDER_TYPE_NONE:
......
......@@ -50,18 +50,20 @@ struct _GthImportTaskClass {
};
GType gth_import_task_get_type (void);
GthTask * gth_import_task_new (GthBrowser *browser,
GList *files, /* GthFileData list */
GFile *destination,
GthSubfolderType subfolder_type,
gboolean single_subfolder,
char **tags,
gboolean delete_imported,
gboolean adjust_orientation);
GFile * gth_import_task_get_file_destination (GthFileData *file_data,
GFile *destination,
GthSubfolderType subfolder_type,
gboolean single_subfolder);
GthTask * gth_import_task_new (GthBrowser *browser,
GList *files, /* GthFileData list */
GFile *destination,
GthSubfolderType subfolder_type,
GthSubfolderFormat subfolder_format,
gboolean single_subfolder,
char **tags,
gboolean delete_imported,
gboolean adjust_orientation);
GFile * gth_import_task_get_file_destination (GthFileData *file_data,
GFile *destination,
GthSubfolderType subfolder_type,
GthSubfolderFormat subfolder_format,
gboolean single_subfolder);
G_END_DECLS
......
......@@ -33,12 +33,22 @@ typedef enum {
GTH_SUBFOLDER_TYPE_CURRENT_DATE
} GthSubfolderType;
typedef enum {
GTH_SUBFOLDER_FORMAT_YYYYMMDD,
GTH_SUBFOLDER_FORMAT_YYYYMM,
GTH_SUBFOLDER_FORMAT_YYYY
} 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_ADJUST_ORIENTATION "/apps/gthumb/ext/photo_importer/adjust_orientation"
G_END_DECLS
#endif /* PREFERENCES_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment