Commit 675bd823 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

[organize_files] create a library for each year

parent 189074ff
......@@ -114,8 +114,8 @@
</packing>
</child>
<child>
<object class="GtkCheckButton" id="create_singletons_checkbutton">
<property name="label" translatable="yes">Do not create catalogs with a single file</property>
<object class="GtkCheckButton" id="ignore_singletons_checkbutton">
<property name="label" translatable="yes">Ignore groups with a single file</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
......@@ -130,7 +130,7 @@
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<object class="GtkHBox" id="hbox1">
<object class="GtkHBox" id="single_catalog_box">
<property name="visible">True</property>
<property name="spacing">6</property>
<child>
......@@ -139,7 +139,6 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="inconsistent">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
......
......@@ -55,7 +55,7 @@ start_button_clicked_cb (GtkWidget *widget,
task = gth_organize_task_new (data->browser, data->folder, gtk_combo_box_get_active (GTK_COMBO_BOX (GET_WIDGET ("group_by_combobox"))));
gth_organize_task_set_recursive (GTH_ORGANIZE_TASK (task), gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("include_subfolders_checkbutton"))));
gth_organize_task_set_create_singletons (GTH_ORGANIZE_TASK (task), gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("create_singletons_checkbutton"))));
gth_organize_task_set_create_singletons (GTH_ORGANIZE_TASK (task), ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("ignore_singletons_checkbutton"))));
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("use_singletons_catalog_checkbutton"))))
gth_organize_task_set_singletons_catalog (GTH_ORGANIZE_TASK (task), gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("single_catalog_entry"))));
gth_browser_exec_task (data->browser, task, FALSE);
......@@ -73,6 +73,29 @@ help_button_clicked_cb (GtkWidget *widget,
}
static void
ignore_singletons_checkbutton_clicked_cb (GtkToggleButton *button,
DialogData *data)
{
if (gtk_toggle_button_get_active (button)) {
gtk_widget_set_sensitive (GET_WIDGET ("single_catalog_box"), TRUE);
gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (GET_WIDGET ("use_singletons_catalog_checkbutton")), FALSE);
}
else {
gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (GET_WIDGET ("use_singletons_catalog_checkbutton")), TRUE);
gtk_widget_set_sensitive (GET_WIDGET ("single_catalog_box"), FALSE);
}
}
static void
use_singletons_catalog_checkbutton_clicked_cb (GtkToggleButton *button,
DialogData *data)
{
gtk_widget_set_sensitive (GET_WIDGET ("single_catalog_entry"), gtk_toggle_button_get_active (button));
}
void
dlg_organize_files (GthBrowser *browser,
GFile *folder)
......@@ -107,6 +130,18 @@ dlg_organize_files (GthBrowser *browser,
"clicked",
G_CALLBACK (start_button_clicked_cb),
data);
g_signal_connect (G_OBJECT (GET_WIDGET ("ignore_singletons_checkbutton")),
"clicked",
G_CALLBACK (ignore_singletons_checkbutton_clicked_cb),
data);
g_signal_connect (G_OBJECT (GET_WIDGET ("use_singletons_catalog_checkbutton")),
"clicked",
G_CALLBACK (use_singletons_catalog_checkbutton_clicked_cb),
data);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("include_subfolders_checkbutton")), TRUE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("ignore_singletons_checkbutton")), FALSE);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("use_singletons_catalog_checkbutton")), FALSE);
/* run dialog. */
......
......@@ -29,7 +29,7 @@
#define GET_WIDGET(name) _gtk_builder_get_widget (self->priv->builder, (name))
#define KEY_FORMAT ("%Y.%m.%d")
enum {
NAME_COLUMN = 0,
......@@ -79,6 +79,7 @@ save_catalog (gpointer key,
GthOrganizeTask *self = user_data;
GthCatalog *catalog = value;
GFile *gio_file;
GFile *gio_parent;
char *data;
gsize size;
GError *error = NULL;
......@@ -90,6 +91,8 @@ save_catalog (gpointer key,
}
gio_file = gth_catalog_file_to_gio_file (gth_catalog_get_file (catalog));
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,
......@@ -104,6 +107,7 @@ save_catalog (gpointer key,
}
g_free (data);
g_object_unref (gio_parent);
g_object_unref (gio_file);
}
......@@ -163,14 +167,15 @@ done_func (GError *error,
static GFile *
get_catalog_file (const char *display_name)
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 ("catalog:///");
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);
......@@ -183,6 +188,30 @@ get_catalog_file (const char *display_name)
}
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, "%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,
......@@ -200,20 +229,21 @@ for_each_file_func (GFile *file,
key = NULL;
file_data = gth_file_data_new (file, info);
switch (self->priv->group_policy) {
case GTH_GROUP_POLICY_DIGITALIZED_DATE: {
GObject *metadata;
metadata = g_file_info_get_attribute_object (info, "Embedded::Image::DateTime");
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, "%x"));
case GTH_GROUP_POLICY_DIGITALIZED_DATE:
{
GObject *metadata;
metadata = g_file_info_get_attribute_object (info, "Embedded::Image::DateTime");
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));
}
}
}
break;
break;
case GTH_GROUP_POLICY_MODIFIED_DATE:
timeval = *gth_file_data_get_modification_time (file_data);
key = g_strdup (_g_time_val_strftime (&timeval, "%x"));
key = g_strdup (_g_time_val_strftime (&timeval, KEY_FORMAT));
break;
}
......@@ -232,7 +262,7 @@ for_each_file_func (GFile *file,
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 (key);
catalog_file = get_catalog_file_for_time (&timeval);
gth_catalog_set_file (catalog, catalog_file);
g_hash_table_insert (self->priv->catalogs, g_strdup (key), catalog);
......@@ -413,13 +443,13 @@ gth_organize_task_set_singletons_catalog (GthOrganizeTask *self,
{
GFile *file;
g_object_unref (self->priv->singletons_catalog);
_g_object_unref (self->priv->singletons_catalog);
self->priv->singletons_catalog = NULL;
if (catalog_name == NULL)
return;
self->priv->singletons_catalog = gth_catalog_new ();
file = get_catalog_file (catalog_name);
file = get_catalog_file ("catalog:///", catalog_name);
gth_catalog_set_file (self->priv->singletons_catalog, file);
g_object_unref (file);
......
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