GQview patch for multiple rename
Davide Capodaglio <[email protected]> Wed, 18 Jan 2006 23:28:49 +0100
| Newsgroups | gmane.comp.gnome.apps.gqview.user |
|---|---|
| Message-ID | <[email protected]> |
--Boundary-00=_hEszD8imZzCw0l6
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hi all,
I would like to submit a patch to GQview that I find extremely useful.
I oftern use GQview to rename pictures taken with digital cameras with the
"multiple rename": I modified it in this way:
- auto select the "auto rename" function
- propose the "end text" according to the filename extension
- calculate automatically the start# and padding by searching how many
pictures already start with the "begin text"
It made it to work in this way. If I have 5 pictures like this:
1.jpg
2.jpg
3.jpg
4.jpg
5.jpg
Then I rename:
1.jpg -> davide1.jpg
2.jpg -> davide2.jpg
3.jpg -> xxx.jpg
When I select 4.jpg and 5.jpg for multiple rename and type "davide" as begin
text, it will automatically propose "3" as start#.
I used a simple call to "find -regex | wc -l" to count the number of existing
files with the same pattern.
Hope someone will find this useful...
Bye
Davide
--Boundary-00=_hEszD8imZzCw0l6
Content-Type: text/x-diff;
charset="us-ascii";
name="gqview.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="gqview.patch"
--- utilops.c 2005-05-19 01:32:33.000000000 +0200
+++ utilops.c.new 2005-11-27 16:54:14.000000000 +0100
@@ -1636,6 +1636,7 @@
ImageWindow *imd;
gint update_idle_id;
+ gint numitems;
};
static void file_util_rename_multiple(RenameDataMult *rd);
@@ -1994,9 +1995,56 @@
}
}
+static int calc_padding(int i)
+{
+ if (i <= 9)
+ return 1;
+ else if (i <= 99)
+ return 2;
+ else if (i <= 999)
+ return 3;
+ else if (i <= 9999)
+ return 4;
+ else if (i <= 99999)
+ return 5;
+ else
+ return 1;
+}
+
static void file_util_rename_multiple_preview_entry_cb(GtkWidget *entry, gpointer data)
{
RenameDataMult *rd = data;
+ const gchar *start;
+ const gchar *end;
+ gchar *path;
+ char s[10];
+ FILE *f;
+ int i;
+ GString *cmdline;
+
+
+ path = remove_level_from_path(rd->fd->source_path);
+ start = gtk_entry_get_text(GTK_ENTRY(rd->auto_entry_front));
+ end = gtk_entry_get_text(GTK_ENTRY(rd->auto_entry_end));
+
+ cmdline = g_string_new(NULL);
+ g_string_sprintf(cmdline, "cd \"%s\"; find -maxdepth 1 -iregex \"\\./%s[0-9]*%s\"|wc -l", path, start, end);
+
+ f = popen(cmdline->str, "r");
+ fgets(s, sizeof(s), f);
+ pclose(f);
+ i = atoi(s);
+
+ //printf("GQVIEW: %s -> %i\n", cmdline->str, i); //debug
+ g_string_free(cmdline, TRUE);
+ g_free(path);
+
+ if (i >= 0)
+ {
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(rd->auto_spin_start), i+1);
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(rd->auto_spin_pad), calc_padding(rd->numitems + i));
+ }
+
file_util_rename_multiple_preview_update(rd);
}
@@ -2086,6 +2134,8 @@
GtkWidget *combo;
GList *work;
const gchar *name;
+ const gchar *pos;
+ gchar *ext;
rd = g_new0(RenameDataMult, 1);
@@ -2137,6 +2187,16 @@
gtk_widget_show(rd->listview);
work = source_list;
+
+ //extract extension from the 1st item
+ ext = NULL;
+ if (work)
+ {
+ pos = extension_from_path(work->data);
+ if (pos) ext = strdup(pos);
+ }
+ rd->numitems= 0;
+
while (work)
{
gchar *path = work->data;
@@ -2146,10 +2206,12 @@
gtk_list_store_set(store, &iter, RENAME_COLUMN_PATH, path, RENAME_COLUMN_NAME, filename_from_path(path), -1);
work = work->next;
+ rd->numitems++;
}
path_list_free(source_list);
-
+
+
rd->imd = image_new(TRUE);
gtk_widget_set_size_request(rd->imd->widget, DIALOG_DEF_IMAGE_DIM_X, DIALOG_DEF_IMAGE_DIM_Y);
gtk_paned_pack2(GTK_PANED(pane), rd->imd->widget, FALSE, TRUE);
@@ -2199,20 +2261,24 @@
box2 = furm_simple_vlabel(hbox, _("Start #"), FALSE);
+ //start from 1
rd->auto_spin_start = pref_spin_new(box2, NULL, NULL,
- 0.0, 1000000.0, 1.0, 0, 0.0,
+ 0.0, 1000000.0, 1.0, 0, 1.0,
G_CALLBACK(file_util_rename_multiple_preview_adj_cb), rd);
box2 = furm_simple_vlabel(hbox, _("End text"), TRUE);
- combo = history_combo_new(&rd->auto_entry_end, "", "numerical_rename_suffix", -1);
+ //end text = extension
+ combo = history_combo_new(&rd->auto_entry_end, ext, "numerical_rename_suffix", -1);
g_signal_connect(G_OBJECT(rd->auto_entry_end), "changed",
G_CALLBACK(file_util_rename_multiple_preview_entry_cb), rd);
- gtk_box_pack_start(GTK_BOX(box2), combo, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(box2), combo, TRUE, TRUE, 0);
gtk_widget_show(combo);
-
+ free(ext);
+
+ //calc padding according to the number of items
rd->auto_spin_pad = pref_spin_new(rd->auto_box, _("Padding:"), NULL,
- 1.0, 8.0, 1.0, 0, 1.0,
+ 1.0, 8.0, 1.0, 0, calc_padding(rd->numitems),
G_CALLBACK(file_util_rename_multiple_preview_adj_cb), rd);
image_change_path(rd->imd, rd->fd->source_path, 0.0);
@@ -2220,7 +2286,11 @@
g_signal_connect(G_OBJECT(GENERIC_DIALOG(rd->fd)->dialog), "destroy",
G_CALLBACK(file_util_rename_multiple_destroy_cb), rd);
- gtk_widget_show(GENERIC_DIALOG(rd->fd)->dialog);
+ //autorename is the default
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rd->button_auto), TRUE);
+ gtk_widget_grab_focus(rd->auto_entry_front);
+
+ gtk_widget_show(GENERIC_DIALOG(rd->fd)->dialog);
}
/*
--Boundary-00=_hEszD8imZzCw0l6--
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642