[gthumb] Attach preferences to the "Rename files" dialog



commit f93b1cf021bcdb9d1b02897fb654f9f629f0c8ed
Author: Christophe Bisière <bisiere univ-tlse1 fr>
Date:   Mon May 10 22:30:12 2010 +0200

    Attach preferences to the "Rename files" dialog
    
    [bug #618182]

 extensions/rename_series/Makefile.am               |    3 +-
 extensions/rename_series/data/Makefile.am          |   16 ++++
 .../data/gthumb_rename_series.schemas.in           |   65 +++++++++++++++
 extensions/rename_series/dlg-rename-series.c       |   83 +++++++++++++++++---
 extensions/rename_series/preferences.h             |   36 +++++++++
 5 files changed, 190 insertions(+), 13 deletions(-)
---
diff --git a/extensions/rename_series/Makefile.am b/extensions/rename_series/Makefile.am
index 907b7e5..ddddbb4 100644
--- a/extensions/rename_series/Makefile.am
+++ b/extensions/rename_series/Makefile.am
@@ -12,7 +12,8 @@ librename_series_la_SOURCES = 		\
 	dlg-rename-series.h		\
 	gth-rename-task.c		\
 	gth-rename-task.h		\
-	main.c
+	main.c				\
+	preferences.h
 
 librename_series_la_CFLAGS = $(GTHUMB_CFLAGS) -I$(top_srcdir) -I$(top_builddir)/gthumb 
 librename_series_la_LDFLAGS = $(EXTENSION_LIBTOOL_FLAGS)
diff --git a/extensions/rename_series/data/Makefile.am b/extensions/rename_series/data/Makefile.am
index 4d5385d..bd2a3f0 100644
--- a/extensions/rename_series/data/Makefile.am
+++ b/extensions/rename_series/data/Makefile.am
@@ -1,2 +1,18 @@
 SUBDIRS = ui
+
+schemadir = @GCONF_SCHEMA_FILE_DIR@
+schema_in_files = gthumb_rename_series.schemas.in
+schema_DATA = $(schema_in_files:.schemas.in=.schemas)
+
+ INTLTOOL_SCHEMAS_RULE@
+
+if GCONF_SCHEMAS_INSTALL
+install-data-local:
+	GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule $(top_builddir)/extensions/rename_series/data/$(schema_DATA)
+endif
+
+EXTRA_DIST = $(schema_in_files)
+
+CLEANFILES = $(schema_DATA)
+
 -include $(top_srcdir)/git.mk
diff --git a/extensions/rename_series/data/gthumb_rename_series.schemas.in b/extensions/rename_series/data/gthumb_rename_series.schemas.in
new file mode 100644
index 0000000..0a8fa0b
--- /dev/null
+++ b/extensions/rename_series/data/gthumb_rename_series.schemas.in
@@ -0,0 +1,65 @@
+<gconfschemafile>
+    <schemalist>
+
+      <schema>
+	<key>/schemas/apps/gthumb/ext/rename_series/template</key>
+	<applyto>/apps/gthumb/ext/rename_series/template</applyto>
+	<owner>gthumb</owner>
+	<type>string</type>
+	<default>####%E</default>
+	<locale name="C">
+	  <short></short>
+	  <long></long>
+	</locale>
+      </schema>
+
+       <schema>
+	<key>/schemas/apps/gthumb/ext/rename_series/start_at</key>
+	<applyto>/apps/gthumb/ext/rename_series/start_at</applyto>
+	<owner>gthumb</owner>
+	<type>int</type>
+	<default>1</default>
+	<locale name="C">
+	  <short></short>
+	  <long></long>
+	</locale>
+      </schema>
+
+      <schema>
+	<key>/schemas/apps/gthumb/ext/rename_series/sort_by</key>
+	<applyto>/apps/gthumb/ext/rename_series/sort_by</applyto>
+	<owner>gthumb</owner>
+	<type>string</type>
+	<default>general::unsorted</default>
+	<locale name="C">
+	  <short>Possible values include: general::unsorted, file::name, file::size, file::mtime, exif::photo::datetimeoriginal</short>
+	  <long></long>
+	</locale>
+      </schema>
+ 
+      <schema>
+	<key>/schemas/apps/gthumb/ext/rename_series/reverse_order</key>
+	<applyto>/apps/gthumb/ext/rename_series/reverse_order</applyto>
+	<owner>gthumb</owner>
+	<type>bool</type>
+	<default>false</default>
+	<locale name="C">
+	  <short></short>
+	  <long></long>
+	</locale>
+      </schema>
+
+      <schema>
+	<key>/schemas/apps/gthumb/ext/rename_series/change_case</key>
+	<applyto>/apps/gthumb/ext/rename_series/change_case</applyto>
+	<owner>gthumb</owner>
+	<type>int</type>
+	<default>0</default>
+	<locale name="C">
+	  <short>Possible values: 0 (none), 1 (lower), 2 (upper)</short>
+	  <long></long>
+	</locale>
+      </schema>
+
+    </schemalist>
+</gconfschemafile>
diff --git a/extensions/rename_series/dlg-rename-series.c b/extensions/rename_series/dlg-rename-series.c
index 76caf74..5abe0f7 100644
--- a/extensions/rename_series/dlg-rename-series.c
+++ b/extensions/rename_series/dlg-rename-series.c
@@ -25,9 +25,7 @@
 #include <gthumb.h>
 #include "dlg-rename-series.h"
 #include "gth-rename-task.h"
-
-
-#define GET_WIDGET(name) _gtk_builder_get_widget (data->builder, (name))
+#include "preferences.h"
 
 
 enum {
@@ -49,6 +47,15 @@ enum {
 };
 
 
+#define GET_WIDGET(name) _gtk_builder_get_widget (data->builder, (name))
+
+#define DEFAULT_TEMPLATE       "####%E"
+#define DEFAULT_START_AT       1
+#define DEFAULT_SORT_BY        "general::unsorted"
+#define DEFAULT_REVERSE_ORDER  FALSE
+#define DEFAULT_CHANGE_CASE    GTH_CHANGE_CASE_NONE
+
+
 typedef struct {
 	GthBrowser    *browser;
 	GList         *file_list;
@@ -84,11 +91,36 @@ static void
 ok_clicked_cb (GtkWidget  *widget,
 	       DialogData *data)
 {
-	GList   *old_files;
-	GList   *new_files;
-	GList   *scan1;
-	GList   *scan2;
-	GthTask *task;
+        GtkTreeIter   iter;
+	GList        *old_files;
+	GList        *new_files;
+	GList        *scan1;
+	GList        *scan2;
+	GthTask      *task;
+
+	/* -- save preferences -- */
+
+	if (data->file_list->next != NULL)
+		eel_gconf_set_string (PREF_RENAME_SERIES_TEMPLATE, gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("template_entry"))));
+
+         eel_gconf_set_integer (PREF_RENAME_SERIES_START_AT, gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET ("start_at_spinbutton"))));
+
+        if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (data->sort_combobox), &iter)) {
+                GthFileDataSort *sort_type;
+
+                gtk_tree_model_get (GTK_TREE_MODEL (data->sort_model),
+                                    &iter,
+                                    SORT_DATA_COLUMN, &sort_type,
+                                    -1);
+
+                eel_gconf_set_string (PREF_RENAME_SERIES_SORT_BY, sort_type->name);
+        }
+
+        eel_gconf_set_boolean (PREF_RENAME_SERIES_REVERSE_ORDER, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("reverse_order_checkbutton"))));
+        eel_gconf_set_integer (PREF_RENAME_SERIES_CHANGE_CASE, gtk_combo_box_get_active (GTK_COMBO_BOX (data->change_case_combobox)));
+
+
+        /* -- prepare and exec rename task -- */
 
 	old_files = NULL;
 	new_files = NULL;
@@ -396,6 +428,10 @@ dlg_rename_series (GthBrowser *browser,
 	GtkTreeViewColumn *column;
 	int                i;
 	GList             *scan;
+	int                change_case;
+	int                start_at;
+	char              *sort_by;
+	gboolean           found;
 
 	if (gth_browser_get_dialog (browser, "rename_series") != NULL) {
 		gtk_window_present (GTK_WINDOW (gth_browser_get_dialog (browser, "rename_series")));
@@ -447,9 +483,12 @@ dlg_rename_series (GthBrowser *browser,
 		gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("template_entry")), g_file_info_get_attribute_string (file_data->info, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME));
 	}
 	else
-		gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("template_entry")), "####%E");
+		gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("template_entry")), eel_gconf_get_string (PREF_RENAME_SERIES_TEMPLATE, DEFAULT_TEMPLATE));
 
-	gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("start_at_spinbutton")), 1.0);
+	start_at = eel_gconf_get_integer (PREF_RENAME_SERIES_START_AT, DEFAULT_START_AT);
+	if (start_at < 0)
+		start_at = DEFAULT_START_AT;
+	gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("start_at_spinbutton")),  start_at * 1.0);
 
 	/* sort by */
 
@@ -465,6 +504,9 @@ dlg_rename_series (GthBrowser *browser,
 					"text", SORT_NAME_COLUMN,
 					NULL);
 
+	sort_by = eel_gconf_get_string (PREF_RENAME_SERIES_SORT_BY, DEFAULT_SORT_BY);
+	found = FALSE;
+
 	for (i = 0, scan = gth_main_get_all_sort_types (); scan; scan = scan->next, i++) {
 		GthFileDataSort *sort_type = scan->data;
 		GtkTreeIter      iter;
@@ -474,19 +516,36 @@ dlg_rename_series (GthBrowser *browser,
 				    SORT_DATA_COLUMN, sort_type,
 				    SORT_NAME_COLUMN, sort_type->display_name,
 				    -1);
+
+                if (strcmp (sort_by, sort_type->name) == 0) {
+                	gtk_combo_box_set_active_iter (GTK_COMBO_BOX (data->sort_combobox), &iter);
+                	found = TRUE;
+                }
 	}
-	gtk_combo_box_set_active (GTK_COMBO_BOX (data->sort_combobox), 0);
+	g_free (sort_by);
+
+	if (!found)
+		gtk_combo_box_set_active (GTK_COMBO_BOX (data->sort_combobox), 0);
+
 	gtk_widget_show (data->sort_combobox);
 	gtk_container_add (GTK_CONTAINER (GET_WIDGET ("sort_by_box")), data->sort_combobox);
 	gtk_label_set_mnemonic_widget (GTK_LABEL (GET_WIDGET ("sort_by_label")), data->sort_combobox);
 
+	/* reverse order */
+
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("reverse_order_checkbutton")), eel_gconf_get_boolean (PREF_RENAME_SERIES_REVERSE_ORDER, DEFAULT_REVERSE_ORDER));
+
 	/* change case */
 
+        change_case = eel_gconf_get_integer (PREF_RENAME_SERIES_CHANGE_CASE, DEFAULT_CHANGE_CASE);
+        if ((change_case < GTH_CHANGE_CASE_NONE)  || (change_case > GTH_CHANGE_CASE_UPPER))
+                change_case = DEFAULT_CHANGE_CASE;
+
 	data->change_case_combobox = _gtk_combo_box_new_with_texts (_("Keep original case"),
 								    _("Convert to lower-case"),
 								    _("Convert to upper-case"),
 								    NULL);
-	gtk_combo_box_set_active (GTK_COMBO_BOX (data->change_case_combobox), 0);
+	gtk_combo_box_set_active (GTK_COMBO_BOX (data->change_case_combobox), change_case);
 	gtk_widget_show (data->change_case_combobox);
 	gtk_container_add (GTK_CONTAINER (GET_WIDGET ("change_case_box")), data->change_case_combobox);
 	gtk_label_set_mnemonic_widget (GTK_LABEL (GET_WIDGET ("change_case_label")), data->change_case_combobox);
diff --git a/extensions/rename_series/preferences.h b/extensions/rename_series/preferences.h
new file mode 100644
index 0000000..99741ea
--- /dev/null
+++ b/extensions/rename_series/preferences.h
@@ -0,0 +1,36 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef PREFERENCES_H
+#define PREFERENCES_H
+
+G_BEGIN_DECLS
+
+#define  PREF_RENAME_SERIES_TEMPLATE      "/apps/gthumb/ext/rename_series/template"
+#define  PREF_RENAME_SERIES_START_AT      "/apps/gthumb/ext/rename_series/start_at"
+#define  PREF_RENAME_SERIES_SORT_BY       "/apps/gthumb/ext/rename_series/sort_by"
+#define  PREF_RENAME_SERIES_REVERSE_ORDER "/apps/gthumb/ext/rename_series/reverse_order"
+#define  PREF_RENAME_SERIES_CHANGE_CASE   "/apps/gthumb/ext/rename_series/change_case"
+
+G_END_DECLS
+
+#endif /* PREFERENCES_H */



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