[easytag/wip/gsettings: 24/29] Store the scanner window mode in GSettings



commit 182d10ee3664b0b95aef9f35ab3870552b8d75a7
Author: David King <amigadave amigadave com>
Date:   Thu Mar 7 21:49:15 2013 +0000

    Store the scanner window mode in GSettings

 data/org.gnome.EasyTAG.gschema.xml |    2 -
 src/easytag.c                      |    5 +-
 src/scan.c                         |   78 +++++++++++++++++------------------
 src/scan.h                         |    9 +----
 src/setting.c                      |    2 -
 src/setting.h                      |   11 +++++-
 6 files changed, 52 insertions(+), 55 deletions(-)
---
diff --git a/data/org.gnome.EasyTAG.gschema.xml b/data/org.gnome.EasyTAG.gschema.xml
index 65e2746..56f6094 100644
--- a/data/org.gnome.EasyTAG.gschema.xml
+++ b/data/org.gnome.EasyTAG.gschema.xml
@@ -832,13 +832,11 @@
       <default>false</default>
     </key>
 
-    <!-- TODO: Generate enums with glib-mkenums.
     <key name="scan-type" enum="org.gnome.EasyTAG.EtScanType">
       <summary>The scan type</summary>
       <description>Which type of scan to show in the scanner</description>
       <default>'rename-file'</default>
     </key>
-    -->
 
     <key name="flac-write-id3" type="b">
       <summary>Write ID3 tags to FLAC files</summary>
diff --git a/src/easytag.c b/src/easytag.c
index 0682df9..16db440 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -1925,7 +1925,7 @@ void Action_Scan_Selected_Files (void)
     /* Check if scanner window is opened */
     if (!ScannerWindow)
     {
-        Open_ScannerWindow(SCANNER_TYPE);
+        Open_ScannerWindow ();
         Statusbar_Message(_("Select Mode and Mask, and redo the same action"),TRUE);
         return;
     }
@@ -4497,7 +4497,8 @@ Init_Load_Default_Dir (void)
 
     // Open the scanner window
     if (g_settings_get_boolean (ETSettings, "scan-startup"))
-        Open_ScannerWindow(SCANNER_TYPE); // Open the last selected scanner
+        /* Open the last selected scanner. */
+        Open_ScannerWindow ();
 
     if (INIT_DIRECTORY)
     {
diff --git a/src/scan.c b/src/scan.c
index e7c4aad..a0ee236 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -31,6 +31,7 @@
 #include "gtk2_compat.h"
 #include "scan.h"
 #include "easytag.h"
+#include "enums.h"
 #include "prefs.h"
 #include "setting.h"
 #include "id3_tag.h"
@@ -277,7 +278,6 @@ static GList *Scan_Generate_New_Tag_From_Mask (ET_File *ETFile, gchar *mask);
 static void Scan_Set_Scanner_Window_Init_Position (void);
 
 
-
 /*************
  * Functions *
  *************/
@@ -579,7 +579,7 @@ void Scan_Fill_Tag_Generate_Preview (void)
 
     if (!ETCore->ETFileDisplayedList
     ||  !ScannerWindow || !RenameFileMaskCombo || !FillTagPreviewLabel
-    ||  gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) != SCANNER_FILL_TAG)
+    ||  gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) != ET_SCAN_TYPE_FILL_TAG)
         return;
 
     mask = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(ScanTagMaskCombo)))));
@@ -956,7 +956,7 @@ void Scan_Rename_File_Generate_Preview (void)
     ||  !ScannerWindow || !RenameFileMaskCombo || !RenameFilePreviewLabel)
         return;
 
-    if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) != SCANNER_RENAME_FILE)
+    if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) != ET_SCAN_TYPE_RENAME_FILE)
         return;
 
     mask = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(RenameFileMaskCombo)))));
@@ -2312,7 +2312,8 @@ static gchar
 /******************
  * Scanner Window *
  ******************/
-void Open_ScannerWindow (gint scanner_type)
+void
+Open_ScannerWindow ()
 {
     GtkWidget *ScanVBox;
     GtkWidget *HBox1, *HBox2, *HBox4, *VBox, *hbox, *vbox;
@@ -2332,19 +2333,10 @@ void Open_ScannerWindow (gint scanner_type)
     /* Check if already opened */
     if (ScannerWindow)
     {
-        //gdk_window_show(ScannerWindow->window);
         gtk_window_present(GTK_WINDOW(ScannerWindow));
-        if (ScannerOptionCombo)
-        {
-            gtk_combo_box_set_active(GTK_COMBO_BOX(ScannerOptionCombo), scanner_type);
-        }
         return;
     }
 
-    if ( scanner_type < SCANNER_FILL_TAG
-    ||   scanner_type > SCANNER_PROCESS_FIELDS)
-        scanner_type = SCANNER_FILL_TAG;
-
     /* The window */
     ScannerWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
     /* Config */
@@ -2386,20 +2378,28 @@ void Open_ScannerWindow (gint scanner_type)
 
     /* Option for Tag */
     gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ScannerOptionCombo),
-                                   _(Scanner_Option_Menu_Items[SCANNER_FILL_TAG]));
+                                   _(Scanner_Option_Menu_Items[ET_SCAN_TYPE_FILL_TAG]));
 
     /* Option for FileName */
     gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ScannerOptionCombo),
-                                   _(Scanner_Option_Menu_Items[SCANNER_RENAME_FILE]));
+                                   _(Scanner_Option_Menu_Items[ET_SCAN_TYPE_RENAME_FILE]));
 
     /* Option for ProcessFields */
     gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ScannerOptionCombo),
-                              _(Scanner_Option_Menu_Items[SCANNER_PROCESS_FIELDS]));
+                              _(Scanner_Option_Menu_Items[ET_SCAN_TYPE_PROCESS_FIELDS]));
 
     /* Selection of the item made at the end of the function. */
     gtk_widget_set_tooltip_text (ScannerOptionCombo,
                                  _("Select the type of scanner to use"));
-    g_signal_connect(G_OBJECT(ScannerOptionCombo), "changed", G_CALLBACK(Scanner_Option_Menu_Activate_Item), 
NULL);
+    /* The selected scanner. */
+    g_settings_bind_with_mapping (ETSettings, "scan-type",
+                                  ScannerOptionCombo, "active",
+                                  G_SETTINGS_BIND_DEFAULT,
+                                  et_settings_enum_get,
+                                  et_settings_enum_set,
+                                  GSIZE_TO_POINTER (ET_TYPE_SCAN_TYPE), NULL);
+    g_signal_connect (G_OBJECT (ScannerOptionCombo), "changed",
+                      G_CALLBACK (Scanner_Option_Menu_Activate_Item), NULL);
 
     /* 'Scan selected files' button */
     SWScanButton = gtk_button_new();
@@ -3042,8 +3042,9 @@ void Open_ScannerWindow (gint scanner_type)
     g_signal_emit_by_name(G_OBJECT(ProcessFieldsConvert),"toggled");/* To enable / disable entries */
     g_signal_emit_by_name(G_OBJECT(ProcessFieldsDetectRomanNumerals),"toggled");/* To enable / disable 
entries */
 
-    // Activate the current menu in the option menu
-    gtk_combo_box_set_active(GTK_COMBO_BOX(ScannerOptionCombo), scanner_type);
+    /* Set the active item after the necessary widgets have been
+     * instantiated. */
+    Scanner_Option_Menu_Activate_Item (ScannerOptionCombo, NULL);
 }
 
 static gboolean
@@ -3071,15 +3072,15 @@ void Scan_Select_Mode_And_Run_Scanner (ET_File *ETFile)
 {
     g_return_if_fail (ScannerWindow != NULL || ETFile != NULL);
 
-    if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == SCANNER_FILL_TAG)
+    if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == ET_SCAN_TYPE_FILL_TAG)
     {
         /* Run Scanner Type: Scan Tag */
         Scan_Tag_With_Mask(ETFile);
-    } else if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == SCANNER_RENAME_FILE)
+    } else if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == ET_SCAN_TYPE_RENAME_FILE)
     {
         /* Run Scanner Type: Rename File */
         Scan_Rename_File_With_Mask(ETFile);
-    } else if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == SCANNER_PROCESS_FIELDS)
+    } else if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == ET_SCAN_TYPE_PROCESS_FIELDS)
     {
         /* Run Scanner Type: Process Fields */
         Scan_Process_Fields(ETFile);
@@ -3088,8 +3089,8 @@ void Scan_Select_Mode_And_Run_Scanner (ET_File *ETFile)
 
 void Scan_Use_Fill_Tag_Scanner (void)
 {
-    if (!ScannerWindow || gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) != SCANNER_FILL_TAG)
-        Open_ScannerWindow(SCANNER_FILL_TAG);
+    if (!ScannerWindow || gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) != 
ET_SCAN_TYPE_FILL_TAG)
+        Open_ScannerWindow ();
     else
         Action_Scan_Selected_Files();
 }
@@ -3097,16 +3098,16 @@ void Scan_Use_Fill_Tag_Scanner (void)
 
 void Scan_Use_Rename_File_Scanner (void)
 {
-    if (!ScannerWindow || gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) != SCANNER_RENAME_FILE)
-        Open_ScannerWindow(SCANNER_RENAME_FILE);
+    if (!ScannerWindow || gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) != 
ET_SCAN_TYPE_RENAME_FILE)
+        Open_ScannerWindow ();
     else
         Action_Scan_Selected_Files();
 }
 
 void Scan_Use_Process_Fields_Scanner (void)
 {
-    if (!ScannerWindow || gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) != 
SCANNER_PROCESS_FIELDS)
-        Open_ScannerWindow(SCANNER_PROCESS_FIELDS);
+    if (!ScannerWindow || gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) != 
ET_SCAN_TYPE_PROCESS_FIELDS)
+        Open_ScannerWindow ();
     else
         Action_Scan_Selected_Files();
 }
@@ -3163,9 +3164,6 @@ void ScannerWindow_Apply_Changes (void)
                             height);
         }
 
-        // The scanner selected
-        SCANNER_TYPE = gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo));
-
         /* Group: select entries to process */
         PROCESS_FILENAME_FIELD    = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ProcessFileNameField));
         PROCESS_TITLE_FIELD       = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ProcessTitleField));
@@ -3345,10 +3343,10 @@ Scan_Check_Editor_Mask (GtkWidget *widget_to_show_hide,
                         GtkEntry *widget_source)
 {
     /* Select and get result of check scanner */
-    if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == SCANNER_FILL_TAG)
+    if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == ET_SCAN_TYPE_FILL_TAG)
     {
         return Scan_Check_Scan_Tag_Mask(widget_to_show_hide,widget_source);
-    } else if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == SCANNER_RENAME_FILE)
+    } else if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == ET_SCAN_TYPE_RENAME_FILE)
     {
         return Scan_Check_Rename_File_Mask(widget_to_show_hide,widget_source);
     } else
@@ -3705,7 +3703,7 @@ Mask_Editor_List_Add (void)
 
     treemodel = gtk_tree_view_get_model(GTK_TREE_VIEW(MaskEditorList));
 
-    if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == SCANNER_FILL_TAG)
+    if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == ET_SCAN_TYPE_FILL_TAG)
     {
         while(Scan_Masks[i])
         {
@@ -3721,7 +3719,7 @@ Mask_Editor_List_Add (void)
             g_free(temp);
             i++;
         }
-    } else if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == SCANNER_RENAME_FILE)
+    } else if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == ET_SCAN_TYPE_RENAME_FILE)
     {
         while(Rename_File_Masks[i])
         {
@@ -3914,10 +3912,10 @@ Mask_Editor_List_Save_Button (void)
 {
     Mask_Editor_Clean_Up_Masks_List();
 
-    if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == SCANNER_FILL_TAG)
+    if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == ET_SCAN_TYPE_FILL_TAG)
     {
         Save_Scan_Tag_Masks_List(ScanTagListModel, MASK_EDITOR_TEXT);
-    } else if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == SCANNER_RENAME_FILE)
+    } else if (gtk_combo_box_get_active(GTK_COMBO_BOX(ScannerOptionCombo)) == ET_SCAN_TYPE_RENAME_FILE)
     {
         Save_Rename_File_Masks_List(RenameFileListModel, MASK_EDITOR_TEXT);
     }
@@ -4061,7 +4059,7 @@ Scanner_Option_Menu_Activate_Item (GtkWidget *combo, gpointer data)
 {
     switch (gtk_combo_box_get_active(GTK_COMBO_BOX(combo)))
     {
-        case SCANNER_FILL_TAG:
+        case ET_SCAN_TYPE_FILL_TAG:
             gtk_widget_show(MaskEditorButton);
             gtk_widget_show(LegendButton);
             gtk_widget_show(ScanTagFrame);
@@ -4073,7 +4071,7 @@ Scanner_Option_Menu_Activate_Item (GtkWidget *combo, gpointer data)
             g_signal_emit_by_name(G_OBJECT(MaskEditorButton),"toggled");    /* To hide or show mask editor 
frame */
             break;
 
-        case SCANNER_RENAME_FILE:
+        case ET_SCAN_TYPE_RENAME_FILE:
             gtk_widget_show(MaskEditorButton);
             gtk_widget_show(LegendButton);
             gtk_widget_hide(ScanTagFrame);
@@ -4085,7 +4083,7 @@ Scanner_Option_Menu_Activate_Item (GtkWidget *combo, gpointer data)
             g_signal_emit_by_name(G_OBJECT(MaskEditorButton),"toggled");    /* To hide or show mask editor 
frame */
             break;
 
-        case SCANNER_PROCESS_FIELDS:
+        case ET_SCAN_TYPE_PROCESS_FIELDS:
             gtk_widget_hide(MaskEditorButton);
             gtk_widget_hide(LegendButton);
             gtk_widget_hide(ScanTagFrame);
diff --git a/src/scan.h b/src/scan.h
index 9f6aa2b..fd3d15a 100644
--- a/src/scan.h
+++ b/src/scan.h
@@ -32,13 +32,6 @@ GtkWidget *ScannerWindow;
 GtkWidget *SWScanButton;    // To enable/disable it in easytag.c
 
 
-enum
-{
-    SCANNER_FILL_TAG = 0,
-    SCANNER_RENAME_FILE,
-    SCANNER_PROCESS_FIELDS
-}; // Add a new item : Min and Max values used in Open_ScannerWindow
-
 enum {
     MASK_EDITOR_TEXT,
     MASK_EDITOR_COUNT
@@ -77,7 +70,7 @@ void Scan_Convert_Space_Into_Undescore  (gchar *string);
 void Scan_Remove_Spaces                 (gchar *string);
 
 void Init_ScannerWindow (void);
-void Open_ScannerWindow (gint scanner_type);
+void Open_ScannerWindow (void);
 void ScannerWindow_Apply_Changes (void);
 
 #endif /* __SCAN_H__ */
diff --git a/src/setting.c b/src/setting.c
index 86e5774..e08eb0b 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -134,7 +134,6 @@ tConfigVariable Config_Variables[] =
 
     {"audio_file_player",                       CV_TYPE_STRING,&AUDIO_FILE_PLAYER                        },
 
-    {"scanner_type",                             CV_TYPE_INT, &SCANNER_TYPE                              },
     {"fts_convert_underscore_and_p20_into_space",CV_TYPE_BOOL,&FTS_CONVERT_UNDERSCORE_AND_P20_INTO_SPACE },
     {"fts_convert_space_into_underscore",        CV_TYPE_BOOL,&FTS_CONVERT_SPACE_INTO_UNDERSCORE         },
     {"rfs_convert_underscore_and_p20_into_space",CV_TYPE_BOOL,&RFS_CONVERT_UNDERSCORE_AND_P20_INTO_SPACE },
@@ -270,7 +269,6 @@ void Init_Config_Variables (void)
     /*
      * Scanner
      */
-    SCANNER_TYPE                              = SCANNER_FILL_TAG;
     FTS_CONVERT_UNDERSCORE_AND_P20_INTO_SPACE = 1;
     FTS_CONVERT_SPACE_INTO_UNDERSCORE         = 0;
     RFS_CONVERT_UNDERSCORE_AND_P20_INTO_SPACE = 1;
diff --git a/src/setting.h b/src/setting.h
index 7b7f830..53c8c32 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -46,6 +46,16 @@ struct _tConfigVariable
 
 
 /*
+ * The mode for the scanner window. See the GSettings key "scanner-type".
+ */
+typedef enum
+{
+    ET_SCAN_TYPE_FILL_TAG,
+    ET_SCAN_TYPE_RENAME_FILE,
+    ET_SCAN_TYPE_PROCESS_FIELDS
+} EtScanType;
+
+/*
  * Types of sorting. See the GSettings key "sort-mode".
  */
 typedef enum
@@ -132,7 +142,6 @@ gint    FILE_WRITING_ID3V1_ICONV_OPTIONS_TRANSLIT;
 gint    FILE_WRITING_ID3V1_ICONV_OPTIONS_IGNORE;
 
 /* Scanner */
-gint    SCANNER_TYPE;
 gint    FTS_CONVERT_UNDERSCORE_AND_P20_INTO_SPACE;
 gint    FTS_CONVERT_SPACE_INTO_UNDERSCORE;
 gint    RFS_CONVERT_UNDERSCORE_AND_P20_INTO_SPACE;


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