[easytag/wip/gsettings: 21/22] Store the scanner window mode in GSettings
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/gsettings: 21/22] Store the scanner window mode in GSettings
- Date: Sun, 24 Mar 2013 23:35:15 +0000 (UTC)
commit 8b39f06bfac025f87bac6a06f68622946aac80e0
Author: David King <amigadave amigadave com>
Date: Thu Mar 7 21:49:15 2013 +0000
Store the scanner window mode in GSettings
src/easytag.c | 5 ++-
src/scan.c | 89 ++++++++++++++++++++++++++++++++++++++++++++------------
src/scan.h | 6 ++--
src/setting.c | 2 -
src/setting.h | 1 -
5 files changed, 76 insertions(+), 27 deletions(-)
---
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..e786bfb 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -276,6 +276,11 @@ static void Scan_Convert_Character (gchar **string);
static GList *Scan_Generate_New_Tag_From_Mask (ET_File *ETFile, gchar *mask);
static void Scan_Set_Scanner_Window_Init_Position (void);
+static gboolean et_scan_scantype_get (GValue *value, GVariant *variant,
+ gpointer user_data);
+static GVariant *et_scan_scantype_set (const GValue *value,
+ const GVariantType *expected_type,
+ gpointer user_data);
/*************
@@ -2312,7 +2317,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 +2338,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 */
@@ -2399,7 +2396,14 @@ void Open_ScannerWindow (gint scanner_type)
/* 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_scan_scantype_get,
+ et_scan_scantype_set, NULL, 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 +3046,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
@@ -3089,7 +3094,7 @@ 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);
+ Open_ScannerWindow ();
else
Action_Scan_Selected_Files();
}
@@ -3098,7 +3103,7 @@ 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);
+ Open_ScannerWindow ();
else
Action_Scan_Selected_Files();
}
@@ -3106,7 +3111,7 @@ void Scan_Use_Rename_File_Scanner (void)
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);
+ Open_ScannerWindow ();
else
Action_Scan_Selected_Files();
}
@@ -3163,9 +3168,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));
@@ -4117,3 +4119,52 @@ Scan_Set_Scanner_Window_Init_Position (void)
gtk_window_move (GTK_WINDOW (ScannerWindow), x, y);
}
}
+
+/*
+ * et_scan_scantype_get:
+ * @value: the property value to be set (active item on combo box)
+ * @variant: the variant to set the @value from
+ * @user_data: user data set when the binding was created (unused)
+ *
+ * Wrapper function to convert the "scan-type" GSettings key to the active item
+ * of the combo box.
+ *
+ * Returns: %TRUE if the mapping was successful, %FALSE otherwise
+ */
+static gboolean
+et_scan_scantype_get (GValue *value, GVariant *variant, gpointer user_data)
+{
+ g_value_set_int (value, g_settings_get_enum (ETSettings, "scan-type"));
+ return TRUE;
+}
+
+/*
+ * et_scan_scantype_set:
+ * @value: the property value to set the @variant from
+ * @expected_type: the expected type of the returned variant
+ * @user_data: user data set when the binding was created (unused)
+ *
+ * Wrapper function to convert the active item of the combo box to the
+ * "scan-type" GSettings key.
+ *
+ * Returns: a new GVariant containing the mapped value, or %NULL upon failure
+ */
+static GVariant *
+et_scan_scantype_set (const GValue *value, const GVariantType *expected_type,
+ gpointer user_data)
+{
+ gint active;
+ const gchar *nick;
+
+ active = g_value_get_int (value);
+ switch (active)
+ {
+ /* TODO: Generate the lookup values from the schema. */
+ case 0: nick = "fill"; break;
+ case 1: nick = "rename"; break;
+ case 2: nick = "process"; break;
+ default: nick = "rename"; break;
+ }
+
+ return g_variant_new (g_variant_type_peek_string (expected_type), nick);
+}
diff --git a/src/scan.h b/src/scan.h
index 9f6aa2b..e96591f 100644
--- a/src/scan.h
+++ b/src/scan.h
@@ -32,12 +32,12 @@ GtkWidget *ScannerWindow;
GtkWidget *SWScanButton; // To enable/disable it in easytag.c
-enum
+typedef enum
{
SCANNER_FILL_TAG = 0,
SCANNER_RENAME_FILE,
SCANNER_PROCESS_FIELDS
-}; // Add a new item : Min and Max values used in Open_ScannerWindow
+} ETScanType;
enum {
MASK_EDITOR_TEXT,
@@ -77,7 +77,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 3cdcb40..0b49857 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 2dbb9f2..cad6b4a 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -84,7 +84,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]