[gthumb] rename series: use the new template API to get the new names



commit e0e98fc38ffdde98fdfd2ac84869ffa71648be04
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon May 17 13:27:28 2021 +0200

    rename series: use the new template API to get the new names

 extensions/rename_series/data/ui/rename-series.ui | 273 +---------------
 extensions/rename_series/dlg-rename-series.c      | 368 +++++++++-------------
 2 files changed, 158 insertions(+), 483 deletions(-)
---
diff --git a/extensions/rename_series/data/ui/rename-series.ui 
b/extensions/rename_series/data/ui/rename-series.ui
index 08d778f8..b3173e13 100644
--- a/extensions/rename_series/data/ui/rename-series.ui
+++ b/extensions/rename_series/data/ui/rename-series.ui
@@ -28,7 +28,7 @@
             <property name="label" translatable="yes">Start _at:</property>
             <property name="use-underline">True</property>
             <property name="mnemonic-widget">start_at_spinbutton</property>
-            <property name="xalign">0</property>
+            <property name="xalign">1</property>
           </object>
           <packing>
             <property name="left-attach">0</property>
@@ -41,7 +41,7 @@
             <property name="can-focus">False</property>
             <property name="label" translatable="yes">_Sort by:</property>
             <property name="use-underline">True</property>
-            <property name="xalign">0</property>
+            <property name="xalign">1</property>
           </object>
           <packing>
             <property name="left-attach">0</property>
@@ -54,7 +54,7 @@
             <property name="can-focus">False</property>
             <property name="label" translatable="yes" comments="Translators: this is the text case (upper or 
lower case).">Cas_e:</property>
             <property name="use-underline">True</property>
-            <property name="xalign">0</property>
+            <property name="xalign">1</property>
           </object>
           <packing>
             <property name="left-attach">0</property>
@@ -155,7 +155,7 @@
                     <property name="can-focus">False</property>
                     <property name="label" translatable="yes">_Template:</property>
                     <property name="use-underline">True</property>
-                    <property name="xalign">0</property>
+                    <property name="xalign">1</property>
                   </object>
                   <packing>
                     <property name="expand">False</property>
@@ -188,9 +188,7 @@
                 <property name="can-focus">True</property>
                 <property name="invisible-char">●</property>
                 <property name="activates-default">True</property>
-                <property name="secondary-icon-name">help-browser-symbolic</property>
                 <property name="secondary-icon-tooltip-text">Help</property>
-                <property name="secondary-icon-tooltip-markup" translatable="yes">Help</property>
               </object>
               <packing>
                 <property name="expand">True</property>
@@ -209,7 +207,7 @@
                   <object class="GtkImage" id="image2">
                     <property name="visible">True</property>
                     <property name="can-focus">False</property>
-                    <property name="icon-name">edit-symbolic</property>
+                    <property name="icon-name">document-edit-symbolic</property>
                   </object>
                 </child>
               </object>
@@ -277,7 +275,7 @@
         </child>
         <child>
           <object class="GtkScrolledWindow" id="preview_scrolledwindow">
-            <property name="width-request">550</property>
+            <property name="width-request">650</property>
             <property name="height-request">300</property>
             <property name="visible">True</property>
             <property name="can-focus">True</property>
@@ -322,263 +320,4 @@
       <widget name="template_label"/>
     </widgets>
   </object>
-  <object class="GtkPopover" id="template_help_popover">
-    <property name="can-focus">False</property>
-    <property name="relative-to">template_entry</property>
-    <property name="position">bottom</property>
-    <child>
-      <!-- n-columns=2 n-rows=8 -->
-      <object class="GtkGrid" id="template_help_table">
-        <property name="visible">True</property>
-        <property name="can-focus">False</property>
-        <property name="margin-start">15</property>
-        <property name="margin-end">15</property>
-        <property name="margin-top">10</property>
-        <property name="margin-bottom">10</property>
-        <property name="row-spacing">6</property>
-        <property name="column-spacing">12</property>
-        <child>
-          <object class="GtkLabel" id="label14">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="label" translatable="yes">Special code</property>
-            <property name="xalign">0</property>
-            <attributes>
-              <attribute name="weight" value="bold"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left-attach">0</property>
-            <property name="top-attach">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label3">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="label">#</property>
-            <property name="xalign">0</property>
-            <attributes>
-              <attribute name="size" value="12000"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left-attach">0</property>
-            <property name="top-attach">1</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label2">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="label">%F</property>
-            <property name="xalign">0</property>
-            <attributes>
-              <attribute name="size" value="12000"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left-attach">0</property>
-            <property name="top-attach">2</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label6">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="label">%E</property>
-            <property name="xalign">0</property>
-            <attributes>
-              <attribute name="size" value="12000"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left-attach">0</property>
-            <property name="top-attach">3</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label18">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="label">%N</property>
-            <property name="xalign">0</property>
-            <attributes>
-              <attribute name="size" value="12000"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left-attach">0</property>
-            <property name="top-attach">4</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label4">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="label" translatable="yes" comments="translate only the text in the curly 
brackets">%M{ format }</property>
-            <property name="xalign">0</property>
-            <attributes>
-              <attribute name="size" value="12000"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left-attach">0</property>
-            <property name="top-attach">5</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label12">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="label" translatable="yes" comments="translate only the text in the curly 
brackets">%D{ format }</property>
-            <property name="xalign">0</property>
-            <attributes>
-              <attribute name="size" value="12000"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left-attach">0</property>
-            <property name="top-attach">6</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label16">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="label" translatable="yes" comments="translate only the text in the curly 
brackets">%A{ identifier }</property>
-            <property name="xalign">0</property>
-            <attributes>
-              <attribute name="size" value="12000"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left-attach">0</property>
-            <property name="top-attach">7</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label15">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="label" translatable="yes">Description</property>
-            <property name="xalign">0</property>
-            <attributes>
-              <attribute name="weight" value="bold"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left-attach">1</property>
-            <property name="top-attach">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label9">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="label" translatable="yes">New enumerator digit</property>
-            <property name="xalign">0</property>
-            <attributes>
-              <attribute name="size" value="12000"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left-attach">1</property>
-            <property name="top-attach">1</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label10">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="label" translatable="yes">The original filename</property>
-            <property name="xalign">0</property>
-            <attributes>
-              <attribute name="size" value="12000"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left-attach">1</property>
-            <property name="top-attach">2</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label11">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="label" translatable="yes">The original extension</property>
-            <property name="xalign">0</property>
-            <attributes>
-              <attribute name="size" value="12000"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left-attach">1</property>
-            <property name="top-attach">3</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label19">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="label" translatable="yes">The original enumerator</property>
-            <property name="xalign">0</property>
-            <attributes>
-              <attribute name="size" value="12000"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left-attach">1</property>
-            <property name="top-attach">4</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label8">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="label" translatable="yes">The modification date</property>
-            <property name="wrap">True</property>
-            <property name="xalign">0</property>
-            <attributes>
-              <attribute name="size" value="12000"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left-attach">1</property>
-            <property name="top-attach">5</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label13">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="label" translatable="yes">The digitalization date</property>
-            <property name="xalign">0</property>
-            <attributes>
-              <attribute name="size" value="12000"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left-attach">1</property>
-            <property name="top-attach">6</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkLabel" id="label17">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <property name="label" translatable="yes">A file attribute</property>
-            <property name="xalign">0</property>
-            <attributes>
-              <attribute name="size" value="12000"/>
-            </attributes>
-          </object>
-          <packing>
-            <property name="left-attach">1</property>
-            <property name="top-attach">7</property>
-          </packing>
-        </child>
-      </object>
-    </child>
-  </object>
 </interface>
diff --git a/extensions/rename_series/dlg-rename-series.c b/extensions/rename_series/dlg-rename-series.c
index 9b6973e1..a9a881f5 100644
--- a/extensions/rename_series/dlg-rename-series.c
+++ b/extensions/rename_series/dlg-rename-series.c
@@ -44,24 +44,19 @@ 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
-#define UPDATE_DELAY           500
+#define DEFAULT_START_AT 1
+#define DEFAULT_CHANGE_CASE GTH_CHANGE_CASE_NONE
+#define UPDATE_DELAY 250
 
 
 static GthTemplateCode Rename_Special_Codes[] = {
-       { GTH_TEMPLATE_CODE_TYPE_TEXT, N_("Text"), 0 },
-       { GTH_TEMPLATE_CODE_TYPE_ENUMERATOR, N_("Enumerator"), '#' },
-       { GTH_TEMPLATE_CODE_TYPE_SIMPLE, N_("Original filename"), 'F' },
-       { GTH_TEMPLATE_CODE_TYPE_SIMPLE, N_("Original extension"), 'E' },
-       { GTH_TEMPLATE_CODE_TYPE_SIMPLE, N_("Original enumerator"), 'N' },
-       { GTH_TEMPLATE_CODE_TYPE_DATE, N_("Modification date"), 'M' },
-       { GTH_TEMPLATE_CODE_TYPE_DATE, N_("Digitalization date"), 'D' },
-       { GTH_TEMPLATE_CODE_TYPE_FILE_ATTRIBUTE, N_("File attribute"), 'A' }
+       { GTH_TEMPLATE_CODE_TYPE_ENUMERATOR, N_("Enumerator") },
+       { GTH_TEMPLATE_CODE_TYPE_SIMPLE, N_("Original filename"), 'F', 0 },
+       { GTH_TEMPLATE_CODE_TYPE_SIMPLE, N_("Original extension"), 'E', 0 },
+       { GTH_TEMPLATE_CODE_TYPE_SIMPLE, N_("Original enumerator"), 'N', 0 },
+       { GTH_TEMPLATE_CODE_TYPE_DATE, N_("Modification date"), 'M', 0 },
+       { GTH_TEMPLATE_CODE_TYPE_DATE, N_("Digitalization date"), 'D', 0 },
+       { GTH_TEMPLATE_CODE_TYPE_FILE_ATTRIBUTE, N_("File attribute"), 'A', 0 }
 };
 
 
@@ -114,30 +109,20 @@ destroy_dialog (DialogData *data)
 
 
 typedef struct {
-       const char   *template;
-       GthFileData  *file_data;
-       int           n;
-       GError      **error;
+       GthFileData *file_data;
+       int          n;
 } TemplateData;
 
 
 static char *
-get_original_enum (GthFileData *file_data,
-                  char        *match)
+get_original_enum (GthFileData *file_data)
 {
-       char    *basename;
-       GRegex  *re;
-       char   **a;
-       char    *value = NULL;
+       char *basename;
+       char  *value = NULL;
 
        basename = g_file_get_basename (file_data->file);
-       re = g_regex_new ("([0-9]+)", 0, 0, NULL);
-       a = g_regex_split (re, basename, 0);
-       if (g_strv_length (a) >= 2)
-               value = g_strdup (g_strstrip (a[1]));
+       value = _g_utf8_find_expr (basename, "[0-9]+");
 
-       g_strfreev (a);
-       g_regex_unref (re);
        g_free (basename);
 
        return value;
@@ -146,115 +131,104 @@ get_original_enum (GthFileData *file_data,
 
 static char *
 get_attribute_value (GthFileData *file_data,
-                    char        *match)
+                    const char  *attribute)
 {
-       GRegex    *re;
-       char     **a;
-       char      *attribute = NULL;
-       char      *value = NULL;
-
-       re = g_regex_new ("%A\\{([^}]+)\\}", 0, 0, NULL);
-       a = g_regex_split (re, match, 0);
-       if (g_strv_length (a) >= 2)
-               attribute = g_strstrip (a[1]);
-
-       if ((attribute != NULL) && (*attribute != '\0')) {
-               value = gth_file_data_get_attribute_as_string (file_data, attribute);
-               if (value != NULL) {
-                       char *tmp_value;
-
-                       tmp_value = _g_utf8_replace_pattern (value, "[\r\n]", " ");
-                       g_free (value);
-                       value = tmp_value;
-               }
-       }
+       char *value;
+
+       if (_g_str_empty (attribute))
+               return NULL;
 
-       g_strfreev (a);
-       g_regex_unref (re);
+       value = gth_file_data_get_attribute_as_string (file_data, attribute);
+       if (value != NULL) {
+               char *tmp = _g_utf8_replace_pattern (value, "[\r\n]", " ");
+               g_free (value);
+               value = tmp;
+       }
 
        return value;
 }
 
 
 static gboolean
-template_eval_cb (const GMatchInfo *info,
-                 GString          *res,
-                 gpointer          data)
+template_eval_cb (gunichar     root_code,
+                 gunichar     parent_code,
+                 gunichar     code,
+                 char       **args,
+                 GString     *result,
+                 gpointer     user_data)
 {
-       TemplateData *template_data = data;
-       char         *r = NULL;
-       char         *match;
+       TemplateData *template_data = user_data;
+       char         *text = NULL;
+       char         *path;
+       GTimeVal      timeval;
+
+       switch (code) {
+       case '#':
+               text = _g_template_replace_enumerator (args[0], template_data->n);
+               break;
 
-       match = g_match_info_fetch (info, 0);
+       case 'A':
+               text = get_attribute_value (template_data->file_data, args[0]);
+               break;
 
-       if (strncmp (match, "#", 1) == 0) {
-               char *format;
+       case 'E':
+               path = g_file_get_path (template_data->file_data->file);
+               text = g_strdup (_g_path_get_extension (path));
+               g_free (path);
+               break;
 
-               format = g_strdup_printf ("%%0%" G_GSIZE_FORMAT "d", strlen (match));
-               r = g_strdup_printf (format, template_data->n);
+       case 'F':
+               path = g_file_get_path (template_data->file_data->file);
+               text = g_strdup (_g_path_get_basename (path));
+               g_free (path);
+               break;
 
-               g_free (format);
-       }
-       else if (strncmp (match, "%A", 2) == 0) {
-               r = get_attribute_value (template_data->file_data, match);
-               /*if (r == NULL)
-                       *template_data->error = g_error_new_literal (GTH_TASK_ERROR, GTH_TASK_ERROR_FAILED, 
_("Malformed template"));*/
-       }
-       else if (strcmp (match, "%E") == 0) {
-               char *uri;
+       case 'N':
+               text = get_original_enum (template_data->file_data);
+               break;
 
-               uri = g_file_get_uri (template_data->file_data->file);
-               r = _g_uri_get_extension (uri);
+       case 'D':
+               if (gth_file_data_get_digitalization_time (template_data->file_data, &timeval))
+                       text = _g_time_val_strftime (&timeval, (args[0] != NULL) ? args[0] : 
DEFAULT_STRFTIME_FORMAT);
+               break;
 
-               g_free (uri);
+       case 'M':
+               timeval = *gth_file_data_get_modification_time (template_data->file_data);
+               text = _g_time_val_strftime (&timeval, (args[0] != NULL) ? args[0] : DEFAULT_STRFTIME_FORMAT);
+               break;
        }
-       else if (strcmp (match, "%F") == 0) {
-               char *basename;
 
-               basename = g_file_get_basename (template_data->file_data->file);
-               r = _g_path_remove_extension (basename);
+       if (text != NULL)
+               g_string_append (result, text);
 
-               g_free (basename);
-       }
-       else if (strcmp (match, "%N") == 0) {
-               r = get_original_enum (template_data->file_data, match);
-       }
-       else if ((strncmp (match, "%D", 2) == 0) || (strncmp (match, "%M", 2) == 0)) {
-               gboolean value_available = FALSE;
-               GTimeVal timeval;
+       return FALSE;
+}
 
-               if (strncmp (match, "%D", 2) == 0) {
-                       value_available = gth_file_data_get_digitalization_time (template_data->file_data, 
&timeval);
-               }
-               else if (strncmp (match, "%M", 2) == 0) {
-                       timeval = *gth_file_data_get_modification_time (template_data->file_data);
-                       value_available = TRUE;
-               }
 
-               if (value_available) {
-                       GRegex  *re;
-                       char   **a;
-                       char    *format = NULL;
+static gboolean
+collect_file_attributes_cb (gunichar   parent_code,
+                           gunichar   code,
+                           char     **args,
+                           gpointer   user_data)
+{
+       GHashTable *attributes = user_data;
+       int         i;
 
-                       /* Get the date format */
+       switch (code) {
+       case 'A':
+               g_hash_table_add (attributes, g_strdup (args[0]));
+               break;
 
-                       re = g_regex_new ("%[A-Z]\\{([^}]+)\\}", 0, 0, NULL);
-                       a = g_regex_split (re, match, 0);
-                       if (g_strv_length (a) >= 2)
-                               format = g_strstrip (a[1]);
-                       r = _g_time_val_strftime (&timeval, format);
+       case 'D':
+               for (i = 0; FileDataDigitalizationTags[i] != NULL; i++)
+                       g_hash_table_add (attributes, g_strdup (FileDataDigitalizationTags[i]));
+               break;
 
-                       g_strfreev (a);
-                       g_regex_unref (re);
-               }
+       case 'M':
+               g_hash_table_add (attributes, g_strdup (G_FILE_ATTRIBUTE_TIME_MODIFIED "," 
G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC));
+               break;
        }
 
-       if (r != NULL)
-               g_string_append (res, r);
-
-       g_free (r);
-       g_free (match);
-
        return FALSE;
 }
 
@@ -262,11 +236,13 @@ template_eval_cb (const GMatchInfo *info,
 static char *
 get_required_attributes (DialogData *data)
 {
-       GtkTreeIter  iter;
-       GString     *required_attributes;
-       const char  *template;
+       GHashTable   *attributes;
+       GtkTreeIter   iter;
+       char        **attributev;
+       char         *result;
 
-       required_attributes = g_string_new (GFILE_STANDARD_ATTRIBUTES);
+       attributes = g_hash_table_new (g_str_hash, g_str_equal);
+       g_hash_table_add (attributes, g_strdup (GFILE_STANDARD_ATTRIBUTES));
 
        /* attributes required for sorting */
 
@@ -278,52 +254,24 @@ get_required_attributes (DialogData *data)
                                    SORT_DATA_COLUMN, &sort_type,
                                    -1);
 
-               if ((sort_type->required_attributes != NULL) && ! g_str_equal 
(sort_type->required_attributes, "")) {
-                       g_string_append (required_attributes, ",");
-                       g_string_append (required_attributes, sort_type->required_attributes);
-               }
+               if (! _g_str_empty (sort_type->required_attributes))
+                       g_hash_table_add (attributes, g_strdup (sort_type->required_attributes));
        }
 
        /* attributes required for renaming */
 
-       template = gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("template_entry")));
+       _g_template_for_each_token (gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("template_entry"))),
+                                   0,
+                                   collect_file_attributes_cb,
+                                   attributes);
 
-       if (g_strstr_len (template, -1, "%A") != NULL) {
-               GRegex  *re;
-               char   **a;
-               int      i;
+       attributev = (char **) g_hash_table_get_keys_as_array (attributes, NULL);
+       result = g_strjoinv (",", attributev);
 
-               re = g_regex_new ("%A\\{([^}]+)\\}", 0, 0, NULL);
-               a = g_regex_split (re, template, 0);
-               for (i = 1; i < g_strv_length (a); i += 2) {
-                       char *id;
+       g_free (attributev);
+       g_hash_table_unref (attributes);
 
-                       id = g_strstrip (g_strdup (a[i]));
-                       g_string_append (required_attributes, ",");
-                       g_string_append (required_attributes, id);
-
-                       g_free (id);
-               }
-
-               g_strfreev (a);
-               g_regex_unref (re);
-       }
-
-       if (g_strstr_len (template, -1, "%D") != NULL) {
-               int i;
-
-               for (i = 0; FileDataDigitalizationTags[i] != NULL; i++) {
-                       g_string_append (required_attributes, ",");
-                       g_string_append (required_attributes, FileDataDigitalizationTags[i]);
-               }
-       }
-
-       if (g_strstr_len (template, -1, "%M") != NULL) {
-               g_string_append (required_attributes, ",");
-               g_string_append (required_attributes, G_FILE_ATTRIBUTE_TIME_MODIFIED "," 
G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
-       }
-
-       return g_string_free (required_attributes, FALSE);
+       return result;
 }
 
 
@@ -355,8 +303,8 @@ update_file_list__step2 (gpointer user_data)
        DialogData   *data = update_data->data;
        GtkTreeIter   iter;
        int           change_case;
-       TemplateData *template_data;
-       GRegex       *re;
+       const char   *template;
+       TemplateData  template_data;
        GList        *scan;
        GError       *error = NULL;
 
@@ -416,38 +364,39 @@ update_file_list__step2 (gpointer user_data)
 
        change_case = gtk_combo_box_get_active (GTK_COMBO_BOX (data->change_case_combobox));
 
-       template_data = g_new0 (TemplateData, 1);
-       template_data->error = &error;
-       template_data->n = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET 
("start_at_spinbutton")));
-       template_data->template = gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("template_entry")));
-       re = g_regex_new ("#+|%[ADEFMN](\\{[^}]+\\})?", 0, 0, NULL);
+       template = gtk_entry_get_text (GTK_ENTRY (GET_WIDGET ("template_entry")));
+       template_data.n = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (GET_WIDGET 
("start_at_spinbutton")));
+
        for (scan = data->new_file_list; scan; scan = scan->next) {
                char *new_name;
-               char *new_name2;
+               char *tmp;
 
-               template_data->file_data = scan->data;
-               new_name = g_regex_replace_eval (re, template_data->template, -1, 0, 0, template_eval_cb, 
template_data, &error);
-               if (error != NULL)
-                       break;
+               template_data.file_data = (GthFileData *) scan->data;
+               new_name = _g_template_eval (template,
+                                            0,
+                                            template_eval_cb,
+                                            &template_data);
 
                switch (change_case) {
                case GTH_CHANGE_CASE_LOWER:
-                       new_name2 = g_utf8_strdown (new_name, -1);
+                       tmp = g_utf8_strdown (new_name, -1);
+                       g_free (new_name);
+                       new_name = tmp;
                        break;
+
                case GTH_CHANGE_CASE_UPPER:
-                       new_name2 = g_utf8_strup (new_name, -1);
+                       tmp = g_utf8_strup (new_name, -1);
+                       g_free (new_name);
+                       new_name = tmp;
                        break;
+
                default:
-                       new_name2 = g_strdup (new_name);
                        break;
                }
 
-               data->new_names_list = g_list_prepend (data->new_names_list, new_name2);
-               template_data->n = template_data->n + 1;
-
-               g_free (new_name);
+               data->new_names_list = g_list_prepend (data->new_names_list, new_name);
+               template_data.n++;
        }
-       g_regex_unref (re);
        data->new_names_list = g_list_reverse (data->new_names_list);
 
        if (update_data->ready_func)
@@ -510,6 +459,7 @@ update_file_list (DialogData *data,
 
                required_attributes = get_required_attributes (data);
                reload_required = attribute_list_reload_required (data->required_attributes, 
required_attributes);
+
                g_free (data->required_attributes);
                data->required_attributes = required_attributes;
 
@@ -718,17 +668,6 @@ dlg_rename_series_update_preview (DialogData *data)
 }
 
 
-static void
-template_entry_icon_release_cb (GtkEntry             *entry,
-                                GtkEntryIconPosition  icon_pos,
-                               GdkEvent             *event,
-                               gpointer              user_data)
-{
-       DialogData *data = user_data;
-       gtk_popover_popup (GTK_POPOVER (GET_WIDGET("template_help_popover")));
-}
-
-
 static gboolean
 update_preview_after_delay_cb (gpointer user_data)
 {
@@ -763,24 +702,19 @@ template_editor_dialog_response_cb (GtkDialog *dialog,
 {
        DialogData *data = user_data;
        char       *template;
-       GError     *error = NULL;
 
        if (response_id != GTK_RESPONSE_OK) {
                gtk_widget_destroy (GTK_WIDGET (dialog));
                return;
        }
 
-       template = gth_template_editor_dialog_get_template (GTH_TEMPLATE_EDITOR_DIALOG (dialog), &error);
-       if (error != NULL) {
-               _gtk_error_dialog_from_gerror_show (GTK_WINDOW (dialog), _("Could not save the template"), 
error);
-               g_clear_error (&error);
-               return;
-       }
-
-       gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("template_entry")), template);
-       gtk_widget_destroy (GTK_WIDGET (dialog));
+       template = gth_template_editor_dialog_get_template (GTH_TEMPLATE_EDITOR_DIALOG (dialog));
+       if (template != NULL) {
+               gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("template_entry")), template);
+               gtk_widget_destroy (GTK_WIDGET (dialog));
 
-       g_free (template);
+               g_free (template);
+       }
 }
 
 
@@ -790,7 +724,11 @@ edit_template_button_clicked_cb (GtkWidget  *widget,
 {
        GtkWidget *dialog;
 
-       dialog = gth_template_editor_dialog_new (Rename_Special_Codes, G_N_ELEMENTS (Rename_Special_Codes), 
_("Edit Template"), GTK_WINDOW (data->dialog));
+       dialog = gth_template_editor_dialog_new (Rename_Special_Codes,
+                                                G_N_ELEMENTS (Rename_Special_Codes),
+                                                0,
+                                                _("Edit Template"),
+                                                GTK_WINDOW (data->dialog));
        gth_template_editor_dialog_set_template (GTH_TEMPLATE_EDITOR_DIALOG (dialog),
                                                 gtk_entry_get_text (GTK_ENTRY (GET_WIDGET 
("template_entry"))));
        g_signal_connect (dialog,
@@ -801,6 +739,7 @@ edit_template_button_clicked_cb (GtkWidget  *widget,
        gtk_window_present (GTK_WINDOW (dialog));
 }
 
+
 static void
 revert_template_button_clicked_cb (GtkWidget  *widget,
                                   DialogData *data)
@@ -817,6 +756,7 @@ return_pressed_callback (GtkDialog *dialog,
        ok_button_clicked (user_data);
 }
 
+
 void
 dlg_rename_series (GthBrowser *browser,
                   GList      *file_list)
@@ -984,10 +924,6 @@ dlg_rename_series (GthBrowser *browser,
                          "response",
                          G_CALLBACK (dialog_response_cb),
                          data);
-       g_signal_connect (GET_WIDGET ("template_entry"),
-                         "icon-release",
-                         G_CALLBACK (template_entry_icon_release_cb),
-                         data);
        g_signal_connect (GET_WIDGET ("template_entry"),
                          "changed",
                          G_CALLBACK (update_preview_cb),
@@ -1005,21 +941,21 @@ dlg_rename_series (GthBrowser *browser,
                          G_CALLBACK (update_preview_cb),
                          data);
        g_signal_connect (data->change_case_combobox,
-                          "changed",
-                          G_CALLBACK (update_preview_cb),
-                          data);
+                         "changed",
+                         G_CALLBACK (update_preview_cb),
+                         data);
        g_signal_connect (GET_WIDGET ("reverse_order_checkbutton"),
                          "toggled",
                          G_CALLBACK (update_preview_cb),
                          data);
-        g_signal_connect (GET_WIDGET ("edit_template_button"),
-                          "clicked",
-                          G_CALLBACK (edit_template_button_clicked_cb),
-                          data);
-        g_signal_connect (GET_WIDGET ("revert_template_button"),
-                          "clicked",
-                          G_CALLBACK (revert_template_button_clicked_cb),
-                          data);
+       g_signal_connect (GET_WIDGET ("edit_template_button"),
+                         "clicked",
+                         G_CALLBACK (edit_template_button_clicked_cb),
+                         data);
+       g_signal_connect (GET_WIDGET ("revert_template_button"),
+                         "clicked",
+                         G_CALLBACK (revert_template_button_clicked_cb),
+                         data);
 
        /* Run dialog. */
 


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