[easytag/wip/application-window: 5/13] Store the scanner window mode in GSettings



commit 108e7aa77ff7a5f90b28b0f761736daf787434d0
Author: David King <amigadave amigadave com>
Date:   Thu May 8 23:18:31 2014 +0100

    Store the scanner window mode in GSettings

 data/org.gnome.EasyTAG.gschema.xml |    2 -
 src/application_window.c           |    7 +-
 src/bar.c                          |    6 +-
 src/scan_dialog.c                  |  107 ++++++++++++++++++-----------------
 src/scan_dialog.h                  |   12 +----
 src/setting.c                      |    2 -
 src/setting.h                      |   10 +++-
 7 files changed, 72 insertions(+), 74 deletions(-)
---
diff --git a/data/org.gnome.EasyTAG.gschema.xml b/data/org.gnome.EasyTAG.gschema.xml
index 9375823..7addb72 100644
--- a/data/org.gnome.EasyTAG.gschema.xml
+++ b/data/org.gnome.EasyTAG.gschema.xml
@@ -742,13 +742,11 @@
       <default>false</default>
     </key>
 
-    <!-- TODO: Generate enums with glib-mkenums.
     <key name="scan-mode" enum="org.gnome.EasyTAG.EtScanMode">
       <summary>The scan mode</summary>
       <description>Which type of scan to show in the scanner</description>
       <default>'rename-file'</default>
     </key>
-    -->
 
     <key name="ogg-split-title" type="b">
       <summary>Split Ogg title fields</summary>
diff --git a/src/application_window.c b/src/application_window.c
index 3294a85..fb50753 100644
--- a/src/application_window.c
+++ b/src/application_window.c
@@ -2378,6 +2378,7 @@ et_application_window_scan_selected_files (G_GNUC_UNUSED GtkAction *action,
     et_scan_dialog_scan_selected_files (ET_SCAN_DIALOG (priv->scan_dialog));
 }
 
+/* FIXME: Is this still necessary with the GSettings port? */
 /*
  * et_on_action_select_scan_mode:
  * @action: the action on which the signal was emitted
@@ -2398,12 +2399,12 @@ et_on_action_select_scan_mode (GtkRadioAction *action, GtkRadioAction *current,
 
     active_value = gtk_radio_action_get_current_value (action);
 
-    if (SCANNER_TYPE != active_value)
+    if (g_settings_get_enum (MainSettings, "scan-mode") != active_value)
     {
-        SCANNER_TYPE = active_value;
+        g_settings_set_enum (MainSettings, "scan-mode", active_value);
     }
 
-    et_scan_dialog_open (ET_SCAN_DIALOG (priv->scan_dialog), SCANNER_TYPE);
+    et_scan_dialog_open (ET_SCAN_DIALOG (priv->scan_dialog), active_value);
 }
 
 void
diff --git a/src/bar.c b/src/bar.c
index 9c25937..83587c6 100644
--- a/src/bar.c
+++ b/src/bar.c
@@ -400,13 +400,13 @@ Create_UI (GtkWindow *window, GtkWidget **ppmenubar, GtkWidget **pptoolbar)
     GtkRadioActionEntry scanner_mode_entries[] =
     {
         { AM_SCANNER_FILL_TAG, "document-properties", _("_Fill Tags…"), NULL,
-          _("Fill tags"), ET_SCAN_TYPE_FILL_TAG },
+          _("Fill tags"), ET_SCAN_MODE_FILL_TAG },
         { AM_SCANNER_RENAME_FILE, "document-properties",
           _("_Rename Files and Directories…"), NULL,
-          _("Rename files and directories"), ET_SCAN_TYPE_RENAME_FILE },
+          _("Rename files and directories"), ET_SCAN_MODE_RENAME_FILE },
         { AM_SCANNER_PROCESS_FIELDS, "document-properties",
           _("_Process Fields…"), NULL, _("Process Fields"),
-          ET_SCAN_TYPE_PROCESS_FIELDS }
+          ET_SCAN_MODE_PROCESS_FIELDS }
     };
 
     GError *error = NULL;
diff --git a/src/scan_dialog.c b/src/scan_dialog.c
index c77e488..77dbff6 100644
--- a/src/scan_dialog.c
+++ b/src/scan_dialog.c
@@ -1,20 +1,20 @@
-/*
- *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
- *  Copyright (C) 2000-2003  Jerome Couderc <easytag gmail com>
+/* EasyTAG - Tag editor for audio files
+ * Copyright (C) 2014  David King <amigadave amigadave com>
+ * Copyright (C) 2000-2003  Jerome Couderc <easytag gmail com>
  *
- *  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 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.
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #include "config.h"
@@ -31,6 +31,7 @@
 #include "application_window.h"
 #include "gtk2_compat.h"
 #include "easytag.h"
+#include "enums.h"
 #include "preferences_dialog.h"
 #include "scan.h"
 #include "setting.h"
@@ -56,7 +57,7 @@ struct _EtScanDialogPrivate
     GtkWidget *mask_editor_entry;
     GtkWidget *mask_editor_view;
 
-    GtkWidget *type_combo;
+    GtkWidget *mode_combo;
     GtkWidget *scan_tag_mask_combo;
     GtkWidget *rename_file_mask_combo;
 
@@ -541,7 +542,7 @@ Scan_Fill_Tag_Generate_Preview (EtScanDialog *self)
     priv = et_scan_dialog_get_instance_private (self);
 
     if (!ETCore->ETFileDisplayedList
-        || gtk_combo_box_get_active (GTK_COMBO_BOX (priv->type_combo)) != ET_SCAN_TYPE_FILL_TAG)
+        || gtk_combo_box_get_active (GTK_COMBO_BOX (priv->mode_combo)) != ET_SCAN_MODE_FILL_TAG)
         return;
 
     mask = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(priv->scan_tag_mask_combo)))));
@@ -602,7 +603,7 @@ Scan_Rename_File_Generate_Preview (EtScanDialog *self)
     || !priv->rename_file_mask_combo || !priv->rename_file_preview_label)
         return;
 
-    if (gtk_combo_box_get_active(GTK_COMBO_BOX(priv->type_combo)) != ET_SCAN_TYPE_RENAME_FILE)
+    if (gtk_combo_box_get_active(GTK_COMBO_BOX(priv->mode_combo)) != ET_SCAN_MODE_RENAME_FILE)
         return;
 
     mask = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(priv->rename_file_mask_combo)))));
@@ -1733,14 +1734,16 @@ Scanner_Option_Menu_Activate_Item (EtScanDialog *self, GtkWidget *combo)
 
     priv = et_scan_dialog_get_instance_private (self);
 
+    /* FIXME: Still needed after GSettings port? */
     radio_action = GTK_RADIO_ACTION (gtk_ui_manager_get_action (UIManager,
                                                                 "/MenuBar/ViewMenu/ScannerMenu/FillTag"));
-    SCANNER_TYPE = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
-    gtk_radio_action_set_current_value (radio_action, SCANNER_TYPE);
+    gtk_radio_action_set_current_value (radio_action,
+                                        g_settings_get_enum (MainSettings,
+                                                             "scan-mode"));
 
-    switch (SCANNER_TYPE)
+    switch (g_settings_get_enum (MainSettings, "scan-mode"))
     {
-        case ET_SCAN_TYPE_FILL_TAG:
+        case ET_SCAN_MODE_FILL_TAG:
             gtk_widget_show(priv->mask_editor_toggle);
             gtk_widget_show(priv->legend_toggle);
             gtk_widget_show(priv->scan_tag_frame);
@@ -1752,7 +1755,7 @@ Scanner_Option_Menu_Activate_Item (EtScanDialog *self, GtkWidget *combo)
             g_signal_emit_by_name(G_OBJECT(priv->mask_editor_toggle),"toggled");    /* To hide or show mask 
editor frame */
             break;
 
-        case ET_SCAN_TYPE_RENAME_FILE:
+        case ET_SCAN_MODE_RENAME_FILE:
             gtk_widget_show(priv->mask_editor_toggle);
             gtk_widget_show(priv->legend_toggle);
             gtk_widget_hide(priv->scan_tag_frame);
@@ -1764,7 +1767,7 @@ Scanner_Option_Menu_Activate_Item (EtScanDialog *self, GtkWidget *combo)
             g_signal_emit_by_name(G_OBJECT(priv->mask_editor_toggle),"toggled");    /* To hide or show mask 
editor frame */
             break;
 
-        case ET_SCAN_TYPE_PROCESS_FIELDS:
+        case ET_SCAN_MODE_PROCESS_FIELDS:
             gtk_widget_hide(priv->mask_editor_toggle);
             gtk_widget_hide(priv->legend_toggle);
             gtk_widget_hide(priv->scan_tag_frame);
@@ -1782,17 +1785,17 @@ Scanner_Option_Menu_Activate_Item (EtScanDialog *self, GtkWidget *combo)
 }
 
 void
-et_scan_dialog_open (EtScanDialog *self, EtScanType scanner_type)
+et_scan_dialog_open (EtScanDialog *self, EtScanMode scanner_type)
 {
     EtScanDialogPrivate *priv;
 
     g_return_if_fail (ET_SCAN_DIALOG (self));
-    g_return_if_fail (scanner_type >= ET_SCAN_TYPE_FILL_TAG
-                      && scanner_type <= ET_SCAN_TYPE_PROCESS_FIELDS);
+    g_return_if_fail (scanner_type >= ET_SCAN_MODE_FILL_TAG
+                      && scanner_type <= ET_SCAN_MODE_PROCESS_FIELDS);
 
     priv = et_scan_dialog_get_instance_private (self);
 
-    gtk_combo_box_set_active (GTK_COMBO_BOX (priv->type_combo), scanner_type);
+    gtk_combo_box_set_active (GTK_COMBO_BOX (priv->mode_combo), scanner_type);
 }
 
 static void
@@ -1807,7 +1810,7 @@ Mask_Editor_List_Add (EtScanDialog *self)
 
     treemodel = gtk_tree_view_get_model(GTK_TREE_VIEW(priv->mask_editor_view));
 
-    if (gtk_combo_box_get_active(GTK_COMBO_BOX(priv->type_combo)) == ET_SCAN_TYPE_FILL_TAG)
+    if (gtk_combo_box_get_active(GTK_COMBO_BOX(priv->mode_combo)) == ET_SCAN_MODE_FILL_TAG)
     {
         while(Scan_Masks[i])
         {
@@ -1823,7 +1826,7 @@ Mask_Editor_List_Add (EtScanDialog *self)
             g_free(temp);
             i++;
         }
-    } else if (gtk_combo_box_get_active(GTK_COMBO_BOX(priv->type_combo)) == ET_SCAN_TYPE_RENAME_FILE)
+    } else if (gtk_combo_box_get_active(GTK_COMBO_BOX(priv->mode_combo)) == ET_SCAN_MODE_RENAME_FILE)
     {
         while(Rename_File_Masks[i])
         {
@@ -1924,10 +1927,10 @@ Mask_Editor_List_Save_Button (EtScanDialog *self)
 
     Mask_Editor_Clean_Up_Masks_List (self);
 
-    if (gtk_combo_box_get_active(GTK_COMBO_BOX(priv->type_combo)) == ET_SCAN_TYPE_FILL_TAG)
+    if (gtk_combo_box_get_active(GTK_COMBO_BOX(priv->mode_combo)) == ET_SCAN_MODE_FILL_TAG)
     {
         Save_Scan_Tag_Masks_List(priv->scan_tag_masks_model, MASK_EDITOR_TEXT);
-    } else if (gtk_combo_box_get_active(GTK_COMBO_BOX(priv->type_combo)) == ET_SCAN_TYPE_RENAME_FILE)
+    } else if (gtk_combo_box_get_active(GTK_COMBO_BOX(priv->mode_combo)) == ET_SCAN_MODE_RENAME_FILE)
     {
         Save_Rename_File_Masks_List(priv->rename_masks_model, MASK_EDITOR_TEXT);
     }
@@ -2556,26 +2559,30 @@ create_scan_dialog (EtScanDialog *self)
     Label = gtk_label_new(_("Scanner:"));
     gtk_box_pack_start(GTK_BOX(HBox1),Label,FALSE,FALSE,0);
 
-    priv->type_combo = gtk_combo_box_text_new();
-    gtk_box_pack_start(GTK_BOX (HBox1), priv->type_combo, TRUE, TRUE, 2);
-    gtk_widget_set_size_request(priv->type_combo, 160, -1);
+    priv->mode_combo = gtk_combo_box_text_new();
+    gtk_box_pack_start(GTK_BOX (HBox1), priv->mode_combo, TRUE, TRUE, 2);
+    gtk_widget_set_size_request(priv->mode_combo, 160, -1);
 
     /* Option for Tag */
-    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(priv->type_combo),
-                                   _(Scanner_Option_Menu_Items[ET_SCAN_TYPE_FILL_TAG]));
+    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(priv->mode_combo),
+                                   _(Scanner_Option_Menu_Items[ET_SCAN_MODE_FILL_TAG]));
 
     /* Option for FileName */
-    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(priv->type_combo),
-                                   _(Scanner_Option_Menu_Items[ET_SCAN_TYPE_RENAME_FILE]));
+    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(priv->mode_combo),
+                                   _(Scanner_Option_Menu_Items[ET_SCAN_MODE_RENAME_FILE]));
 
     /* Option for ProcessFields */
-    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(priv->type_combo),
-                              _(Scanner_Option_Menu_Items[ET_SCAN_TYPE_PROCESS_FIELDS]));
+    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(priv->mode_combo),
+                              _(Scanner_Option_Menu_Items[ET_SCAN_MODE_PROCESS_FIELDS]));
 
     /* Selection of the item made at the end of the function. */
-    gtk_widget_set_tooltip_text (priv->type_combo,
+    gtk_widget_set_tooltip_text (priv->mode_combo,
                                  _("Select the type of scanner to use"));
-    g_signal_connect_swapped (priv->type_combo, "changed",
+    g_settings_bind_with_mapping (MainSettings, "scan-mode", priv->mode_combo,
+                                  "active", G_SETTINGS_BIND_DEFAULT,
+                                  et_settings_enum_get, et_settings_enum_set,
+                                  GSIZE_TO_POINTER (ET_TYPE_SCAN_MODE), NULL);
+    g_signal_connect_swapped (priv->mode_combo, "changed",
                               G_CALLBACK (Scanner_Option_Menu_Activate_Item),
                               self);
 
@@ -3214,8 +3221,7 @@ create_scan_dialog (EtScanDialog *self)
     gtk_widget_show_all (GTK_WIDGET (self));
 
     /* Activate the current menu in the option menu. */
-    gtk_combo_box_set_active (GTK_COMBO_BOX (priv->type_combo),
-                              SCANNER_TYPE);
+    Scanner_Option_Menu_Activate_Item (self, priv->mode_combo);
 }
 
 /*
@@ -3225,23 +3231,23 @@ void
 Scan_Select_Mode_And_Run_Scanner (EtScanDialog *self, ET_File *ETFile)
 {
     EtScanDialogPrivate *priv;
-    EtScanType mode;
+    EtScanMode mode;
 
     g_return_if_fail (ET_SCAN_DIALOG (self));
     g_return_if_fail (ETFile != NULL);
 
     priv = et_scan_dialog_get_instance_private (self);
-    mode = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->type_combo));
+    mode = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->mode_combo));
 
     switch (mode)
     {
-        case ET_SCAN_TYPE_FILL_TAG:
+        case ET_SCAN_MODE_FILL_TAG:
             Scan_Tag_With_Mask (self, ETFile);
             break;
-        case ET_SCAN_TYPE_RENAME_FILE:
+        case ET_SCAN_MODE_RENAME_FILE:
             Scan_Rename_File_With_Mask (self, ETFile);
             break;
-        case ET_SCAN_TYPE_PROCESS_FIELDS:
+        case ET_SCAN_MODE_PROCESS_FIELDS:
             Scan_Process_Fields (self, ETFile);
             break;
         default:
@@ -3261,9 +3267,6 @@ et_scan_dialog_apply_changes (EtScanDialog *self)
 
     priv = et_scan_dialog_get_instance_private (self);
 
-    /* The selected scanner type. */
-    SCANNER_TYPE = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->type_combo));
-
     /* Group: select entries to process */
     PROCESS_FILENAME_FIELD    = 
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->process_filename_toggle));
     PROCESS_TITLE_FIELD       = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->process_title_toggle));
diff --git a/src/scan_dialog.h b/src/scan_dialog.h
index 4998047..2a1cf8a 100644
--- a/src/scan_dialog.h
+++ b/src/scan_dialog.h
@@ -47,20 +47,10 @@ struct _EtScanDialogClass
     GtkDialogClass parent_class;
 };
 
-/*
- * The mode for the scanner window.
- */
-typedef enum
-{
-    ET_SCAN_TYPE_FILL_TAG,
-    ET_SCAN_TYPE_RENAME_FILE,
-    ET_SCAN_TYPE_PROCESS_FIELDS
-} EtScanType;
-
 GType et_scan_dialog_get_type (void);
 EtScanDialog *et_scan_dialog_new (void);
 void et_scan_dialog_apply_changes (EtScanDialog *self);
-void et_scan_dialog_open (EtScanDialog *self, EtScanType scanner_type);
+void et_scan_dialog_open (EtScanDialog *self, EtScanMode scanner_type);
 void et_scan_dialog_scan_selected_files (EtScanDialog *self);
 void et_scan_dialog_update_previews (EtScanDialog *self);
 
diff --git a/src/setting.c b/src/setting.c
index 2ad00a0..bca50f3 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -142,7 +142,6 @@ static const 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 },
@@ -280,7 +279,6 @@ void Init_Config_Variables (void)
     /*
      * Scanner
      */
-    SCANNER_TYPE                              = ET_SCAN_TYPE_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 7cb5423..63bd90e 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -43,6 +43,15 @@ struct _tConfigVariable
     void *pointer;              /* Pointer to our variable */
 };
 
+/*
+ * The mode for the scanner window.
+ */
+typedef enum
+{
+    ET_SCAN_MODE_FILL_TAG,
+    ET_SCAN_MODE_RENAME_FILE,
+    ET_SCAN_MODE_PROCESS_FIELDS
+} EtScanMode;
 
 /* Types of sorting. See the GSettings key "sort-mode". */
 typedef enum
@@ -134,7 +143,6 @@ gint PAD_DISC_NUMBER;
 gint PAD_DISC_NUMBER_DIGITS;
 
 /* 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]