[easytag/wip/application-window: 24/60] Remove rename directory mask history



commit 4d71cd0ba06b7b39baf6ae878c344903a8f4c413
Author: David King <amigadave amigadave com>
Date:   Sat Jun 28 22:50:22 2014 +0100

    Remove rename directory mask history
    
    Use a single default mask instead.

 src/browser.c |   85 ++++++++++++++++++---------------------------------------
 src/setting.c |   36 ------------------------
 src/setting.h |    1 -
 3 files changed, 27 insertions(+), 95 deletions(-)
---
diff --git a/src/browser.c b/src/browser.c
index 914521e..e5b35dc 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -95,8 +95,7 @@ struct _EtBrowserPrivate
     GtkWidget *rename_directory_dialog;
     GtkWidget *rename_directory_combo;
     GtkWidget *rename_directory_mask_toggle;
-    GtkWidget *rename_directory_mask_combo;
-    GtkListStore *rename_directory_mask_model;
+    GtkWidget *rename_directory_mask_entry;
     GtkWidget *rename_directory_preview_label;
 
     gchar *current_path;
@@ -112,17 +111,6 @@ struct _EtBrowserPrivate
 
 static const guint BOX_SPACING = 6;
 
-static gchar *Rename_Directory_Masks [] =
-{
-    "%a - %b",
-    "%a_-_%b",
-    "%a - %b (%y) - %g",
-    "%a_-_%b_(%y)_-_%g",
-    "VA - %b (%y)",
-    "VA_-_%b_(%y)",
-    NULL
-};
-
 /*
  * EtPathState:
  * @ET_PATH_STATE_OPEN: the path is open or has been read
@@ -4085,10 +4073,12 @@ rename_directory_generate_preview (EtBrowser *self)
     priv = et_browser_get_instance_private (self);
 
     if (!ETCore->ETFileDisplayed
-    ||  !priv->rename_directory_dialog || !priv->rename_directory_mask_combo || 
!priv->rename_directory_preview_label)
+    ||  !priv->rename_directory_dialog || !priv->rename_directory_mask_entry || 
!priv->rename_directory_preview_label)
         return;
 
-    mask = 
g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(priv->rename_directory_mask_combo)))));
+    mask = g_settings_get_string (MainSettings,
+                                  "rename-directory-default-mask");
+
     if (!mask)
         return;
 
@@ -4218,45 +4208,28 @@ et_browser_show_rename_directory_dialog (EtBrowser *self)
                               G_CALLBACK (Rename_Directory_With_Mask_Toggled),
                               self);
 
-    // Set up list model which is used by the combobox
-    /* Rename directory from mask */
-    if (!priv->rename_directory_mask_model)
-        priv->rename_directory_mask_model = gtk_list_store_new(MASK_EDITOR_COUNT, G_TYPE_STRING);
-    else
-        gtk_list_store_clear(priv->rename_directory_mask_model);
-
-    // The combo box to select the mask to apply
-    priv->rename_directory_mask_combo = gtk_combo_box_new_with_entry();
-    gtk_combo_box_set_model(GTK_COMBO_BOX(priv->rename_directory_mask_combo), 
GTK_TREE_MODEL(priv->rename_directory_mask_model));
-    gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(priv->rename_directory_mask_combo), MASK_EDITOR_TEXT);
-    gtk_widget_set_size_request(priv->rename_directory_mask_combo, 80, -1);
+    /* The entry to enter the mask to apply. */
+    priv->rename_directory_mask_entry = gtk_entry_new ();
+    gtk_widget_set_size_request(priv->rename_directory_mask_entry, 80, -1);
 
-    gtk_box_pack_start(GTK_BOX(HBox),priv->rename_directory_mask_combo,TRUE,TRUE,0);
-    
gtk_widget_set_tooltip_text(GTK_WIDGET(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(priv->rename_directory_mask_combo)))),
+    gtk_box_pack_start(GTK_BOX(HBox),priv->rename_directory_mask_entry,TRUE,TRUE,0);
+    gtk_widget_set_tooltip_text (priv->rename_directory_mask_entry,
         _("Select or type in a mask using codes (see Legend in Scanner Window) to rename "
         "the directory from tag fields."));
-    // Signal to generate preview (preview of the new directory)
-    g_signal_connect_swapped (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->rename_directory_mask_combo))),
+    /* Signal to generate preview (preview of the new directory). */
+    g_signal_connect_swapped (priv->rename_directory_mask_entry,
                               "changed",
                               G_CALLBACK (rename_directory_generate_preview),
                               self);
 
-    // Load masks into the combobox from a file
-    Load_Rename_Directory_Masks_List(priv->rename_directory_mask_model, MASK_EDITOR_TEXT, 
Rename_Directory_Masks);
-    if (RENAME_DIRECTORY_DEFAULT_MASK)
-    {
-        Add_String_To_Combo_List(priv->rename_directory_mask_model, RENAME_DIRECTORY_DEFAULT_MASK);
-        gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(priv->rename_directory_mask_combo))), 
RENAME_DIRECTORY_DEFAULT_MASK);
-    }else
-    {
-        gtk_combo_box_set_active(GTK_COMBO_BOX(priv->rename_directory_mask_combo), 0);
-    }
+    g_settings_bind (MainSettings, "rename-directory-default-mask",
+                     priv->rename_directory_mask_entry, "text",
+                     G_SETTINGS_BIND_DEFAULT);
 
-    // Mask status icon
-    // Signal connection to check if mask is correct into the mask entry
-    g_signal_connect (gtk_bin_get_child (GTK_BIN (priv->rename_directory_mask_combo)),
-                      "changed", G_CALLBACK (entry_check_rename_file_mask),
-                      NULL);
+    /* Mask status icon. Signal connection to check if mask is correct to the
+     * mask entry. */
+    g_signal_connect (priv->rename_directory_mask_entry, "changed",
+                      G_CALLBACK (entry_check_rename_file_mask), NULL);
 
     // Preview label
     priv->rename_directory_preview_label = gtk_label_new (_("Rename directory preview"));
@@ -4277,8 +4250,8 @@ et_browser_show_rename_directory_dialog (EtBrowser *self)
     // To initialize the 'Use mask' check button state
     g_signal_emit_by_name(G_OBJECT(priv->rename_directory_mask_toggle),"toggled");
 
-    // To initialize PreviewLabel + MaskStatusIconBox
-    g_signal_emit_by_name(G_OBJECT(gtk_bin_get_child(GTK_BIN(priv->rename_directory_mask_combo))),"changed");
+    /* To initialize PreviewLabel + MaskStatusIconBox. */
+    g_signal_emit_by_name (priv->rename_directory_mask_entry, "changed");
 
     g_free(directory_name_utf8);
 }
@@ -4295,13 +4268,6 @@ Destroy_Rename_Directory_Window (EtBrowser *self)
         g_free(g_object_get_data(G_OBJECT(priv->rename_directory_dialog),"Parent_Directory"));
         g_free(g_object_get_data(G_OBJECT(priv->rename_directory_dialog),"Current_Directory"));
 
-        if (RENAME_DIRECTORY_DEFAULT_MASK) g_free(RENAME_DIRECTORY_DEFAULT_MASK);
-        RENAME_DIRECTORY_DEFAULT_MASK = 
g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(priv->rename_directory_mask_combo)))));
-        Add_String_To_Combo_List(priv->rename_directory_mask_model, RENAME_DIRECTORY_DEFAULT_MASK);
-        Save_Rename_Directory_Masks_List(priv->rename_directory_mask_model, MASK_EDITOR_TEXT);
-
-        gtk_list_store_clear(priv->rename_directory_mask_model);
-
         gtk_widget_destroy(priv->rename_directory_dialog);
         priv->rename_directory_preview_label = NULL;
         priv->rename_directory_dialog = NULL;
@@ -4334,8 +4300,11 @@ Rename_Directory (EtBrowser *self)
 
     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->rename_directory_mask_toggle)))
     {
-        // Renamed from mask
-        gchar *mask = 
g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(priv->rename_directory_mask_combo)))));
+        /* Renamed from mask. */
+        gchar *mask;
+
+        mask = g_settings_get_string (MainSettings,
+                                      "rename-directory-default-mask");
         directory_new_name = Scan_Generate_New_Directory_Name_From_Mask(ETCore->ETFileDisplayed,mask,FALSE);
         g_free(mask);
 
@@ -4563,7 +4532,7 @@ Rename_Directory_With_Mask_Toggled (EtBrowser *self)
     priv = et_browser_get_instance_private (self);
 
     gtk_widget_set_sensitive(GTK_WIDGET(priv->rename_directory_combo),            
!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->rename_directory_mask_toggle)));
-    gtk_widget_set_sensitive(GTK_WIDGET(priv->rename_directory_mask_combo),         
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->rename_directory_mask_toggle)));
+    gtk_widget_set_sensitive(GTK_WIDGET(priv->rename_directory_mask_entry),         
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->rename_directory_mask_toggle)));
     gtk_widget_set_sensitive(GTK_WIDGET(priv->rename_directory_preview_label),      
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->rename_directory_mask_toggle)));
 }
 
diff --git a/src/setting.c b/src/setting.c
index 2896deb..c69089f 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -66,8 +66,6 @@ static const gchar CONFIG_FILE[] = "easytagrc";
 static const gchar SCAN_TAG_MASKS_FILE[] = "scan_tag.mask";
 // File of masks for rename file scanner
 static const gchar RENAME_FILE_MASKS_FILE[] = "rename_file.mask";
-// File for history of RenameDirectoryMaskCombo combobox
-static const gchar RENAME_DIRECTORY_MASKS_FILE[] = "rename_directory.mask";
 // File for history of BrowserEntry combobox
 static const gchar PATH_ENTRY_HISTORY_FILE[] = "browser_path.history";
 // File for history of run program combobox for directories
@@ -106,7 +104,6 @@ static const tConfigVariable Config_Variables[] =
 
     {"scan_tag_default_mask",                   CV_TYPE_STRING,  &SCAN_TAG_DEFAULT_MASK                  },
     {"rename_file_default_mask",                CV_TYPE_STRING,  &RENAME_FILE_DEFAULT_MASK               },
-    {"rename_directory_default_mask",           CV_TYPE_STRING,  &RENAME_DIRECTORY_DEFAULT_MASK          },
 };
 
 
@@ -162,7 +159,6 @@ void Init_Config_Variables (void)
      */
     SCAN_TAG_DEFAULT_MASK           = NULL;
     RENAME_FILE_DEFAULT_MASK        = NULL;
-    RENAME_DIRECTORY_DEFAULT_MASK   = NULL;
 }
 
 
@@ -500,7 +496,6 @@ gboolean Setting_Create_Files (void)
 
     check_or_create_file (SCAN_TAG_MASKS_FILE);
     check_or_create_file (RENAME_FILE_MASKS_FILE);
-    check_or_create_file (RENAME_DIRECTORY_MASKS_FILE);
     check_or_create_file (PATH_ENTRY_HISTORY_FILE);
     check_or_create_file (RUN_PROGRAM_WITH_DIRECTORY_HISTORY_FILE);
     check_or_create_file (RUN_PROGRAM_WITH_FILE_HISTORY_FILE);
@@ -680,36 +675,6 @@ void Save_Rename_File_Masks_List (GtkListStore *liststore, gint colnum)
 }
 
 /*
- * Functions for writing and reading list of 'Rename Directory' masks
- */
-void Load_Rename_Directory_Masks_List (GtkListStore *liststore, gint colnum, gchar **fallback)
-{
-    gint i = 0;
-
-    if (!Populate_List_Store_From_File(RENAME_DIRECTORY_MASKS_FILE, liststore, colnum))
-    {
-        // Fall back to defaults
-        Log_Print(LOG_OK,_("Loading default 'Rename Directory' masks…"));
-
-        while(fallback[i])
-        {
-            gtk_list_store_insert_with_values (liststore, NULL, G_MAXINT,
-                                               colnum, fallback[i], -1);
-            i++;
-        }
-    }
-}
-
-void Save_Rename_Directory_Masks_List (GtkListStore *liststore, gint colnum)
-{
-    Save_List_Store_To_File(RENAME_DIRECTORY_MASKS_FILE, liststore, colnum);
-}
-
-
-
-
-
-/*
  * Functions for writing and reading list of 'BrowserEntry' combobox
  */
 void Load_Path_Entry_List (GtkListStore *liststore, gint colnum)
@@ -820,7 +785,6 @@ migrate_config_file_dir (const gchar *old_path, const gchar *new_path)
     static const gchar *filenames[] = { CONFIG_FILE,
                                         SCAN_TAG_MASKS_FILE,
                                         RENAME_FILE_MASKS_FILE,
-                                        RENAME_DIRECTORY_MASKS_FILE,
                                         PATH_ENTRY_HISTORY_FILE,
                                         RUN_PROGRAM_WITH_DIRECTORY_HISTORY_FILE,
                                         RUN_PROGRAM_WITH_FILE_HISTORY_FILE,
diff --git a/src/setting.h b/src/setting.h
index c891d1a..00c5d11 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -263,7 +263,6 @@ gchar  *AUDIO_FILE_PLAYER;
 /* Default mask */
 gchar  *SCAN_TAG_DEFAULT_MASK;
 gchar  *RENAME_FILE_DEFAULT_MASK;
-gchar  *RENAME_DIRECTORY_DEFAULT_MASK;
 
 /**************
  * Prototypes *


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