[easytag/wip/gsettings: 24/25] Store the file list sorting mode in GSettings
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/gsettings: 24/25] Store the file list sorting mode in GSettings
- Date: Thu, 7 Mar 2013 21:56:20 +0000 (UTC)
commit 37c00b42bd0dde0d702008a975815a10353b322f
Author: David King <amigadave amigadave com>
Date: Sun Mar 3 22:17:16 2013 +0000
Store the file list sorting mode in GSettings
src/browser.c | 2 +-
src/easytag.c | 8 +++--
src/et_core.c | 9 +++--
src/et_core.h | 2 +-
src/prefs.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
src/setting.c | 4 --
src/setting.h | 1 -
7 files changed, 105 insertions(+), 15 deletions(-)
---
diff --git a/src/browser.c b/src/browser.c
index dee8544..a5363fe 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -1759,7 +1759,7 @@ Browser_List_Sort_Func (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b,
//gtk_tree_model_get(model, a, LIST_FILE_POINTER, &ETFile1, LIST_FILE_NAME, &text1, -1);
//gtk_tree_model_get(model, b, LIST_FILE_POINTER, &ETFile2, LIST_FILE_NAME, &text2, -1);
- switch (SORTING_FILE_MODE)
+ switch (g_settings_get_enum (ETSettings, "sort-mode"))
{
case SORTING_UNKNOWN:
case SORTING_BY_ASCENDING_FILENAME:
diff --git a/src/easytag.c b/src/easytag.c
index d46c74d..c0d3a86 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -1416,6 +1416,7 @@ Mini_Button_Clicked (GObject *object)
* So we must browse the whole 'etfilelistfull' to get position of each selected file.
* Note : 'etfilelistfull' and 'etfilelist' must be sorted in the same order */
GList *etfilelistfull = NULL;
+ gint sort_mode;
gchar *path = NULL;
gchar *path1 = NULL;
gint i = 0;
@@ -1423,9 +1424,10 @@ Mini_Button_Clicked (GObject *object)
/* FIX ME!: see to fill also the Total Track (it's a good idea?) */
etfilelistfull = g_list_first(ETCore->ETFileList);
- // Sort 'etfilelistfull' and 'etfilelist' in the same order
- etfilelist = ET_Sort_File_List(etfilelist,SORTING_FILE_MODE);
- etfilelistfull = ET_Sort_File_List(etfilelistfull,SORTING_FILE_MODE);
+ /* Sort 'etfilelistfull' and 'etfilelist' in the same order. */
+ sort_mode = g_settings_get_enum (ETSettings, "sort-mode");
+ etfilelist = ET_Sort_File_List (etfilelist, sort_mode);
+ etfilelistfull = ET_Sort_File_List (etfilelistfull, sort_mode);
while (etfilelist && etfilelistfull)
{
diff --git a/src/et_core.c b/src/et_core.c
index 7602053..e471914 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -899,8 +899,8 @@ GList *ET_Sort_File_List (GList *ETFileList, ET_Sorting_Type Sorting_Type)
// Important to rewind before
GList *etfilelist = g_list_first(ETFileList);
- // Save sorting mode (note: needed when called from UI)
- SORTING_FILE_MODE = Sorting_Type;
+ /* Save sorting mode (note: needed when called from UI). */
+ g_settings_set_enum (ETSettings, "sort-mode", Sorting_Type);
// Sort...
switch (Sorting_Type)
@@ -1969,8 +1969,9 @@ gboolean ET_Set_Displayed_File_List (GList *ETFileList)
list = list->next;
}
- // Sort the file list
- ET_Sort_Displayed_File_List(SORTING_FILE_MODE);
+ /* Sort the file list. */
+ ET_Sort_Displayed_File_List (g_settings_get_enum (ETSettings,
+ "sort-mode"));
// Should renums ETCore->ETFileDisplayedList only!
ET_Displayed_File_List_Number();
diff --git a/src/et_core.h b/src/et_core.h
index 43c6ee0..6976414 100644
--- a/src/et_core.h
+++ b/src/et_core.h
@@ -60,7 +60,7 @@ GdkColor BLACK;
/*
- * Types of sorting (discontinuous value to avoid separators in SortingFileOptionMenu).
+ * Types of sorting. See the GSettings key "sort-mode".
*/
typedef enum
{
diff --git a/src/prefs.c b/src/prefs.c
index 4395838..3e87242 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -67,6 +67,11 @@ static void Cddb_Use_Proxy_Toggled (void);
static void DefaultPathToMp3_Combo_Add_String (void);
static void CddbLocalPath_Combo_Add_String (void);
+static gboolean et_prefs_sortmode_get (GValue *value, GVariant *variant,
+ gpointer user_data);
+static GVariant * et_prefs_sortmode_set (const GValue *value,
+ const GVariantType *expected_type,
+ gpointer user_data);
/*************
@@ -323,7 +328,10 @@ void Open_OptionsWindow (void)
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(SortingFileCombo), _("Ascending comment"));
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(SortingFileCombo), _("Descending comment"));
- gtk_combo_box_set_active(GTK_COMBO_BOX(SortingFileCombo), SORTING_FILE_MODE);
+ g_settings_bind_with_mapping (ETSettings, "sort-mode", SortingFileCombo,
+ "active", G_SETTINGS_BIND_DEFAULT,
+ et_prefs_sortmode_get, et_prefs_sortmode_set,
+ NULL, NULL);
gtk_widget_set_tooltip_text(SortingFileCombo,
_("Select the type of file sorting when "
"loading a directory."));
@@ -1971,4 +1979,88 @@ CddbLocalPath_Combo_Add_String (void)
Add_String_To_Combo_List(GTK_LIST_STORE(CddbLocalPath), path);
}
+/*
+ * et_prefs_sortmode_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 "sort-mode" GSettings key to the active item
+ * of the combo box.
+ *
+ * Returns: %TRUE if the mapping was successful, %FALSE otherwise
+ */
+static gboolean
+et_prefs_sortmode_get (GValue *value, GVariant *variant, gpointer user_data)
+{
+ g_value_set_int (value, g_settings_get_enum (ETSettings, "sort-mode"));
+ return TRUE;
+}
+/*
+ * et_prefs_sortmode_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
+ * "sort-mode" GSettings key.
+ *
+ * Returns: a new GVariant containing the mapped value, or %NULL upon failure
+ */
+static GVariant *
+et_prefs_sortmode_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 = "ascending-filename"; break;
+ case 1: nick = "descending-filename"; break;
+ case 2: nick = "ascending-track-number"; break;
+ case 3: nick = "descending-track-number"; break;
+ case 4: nick = "ascending-creation-date"; break;
+ case 5: nick = "descending-creation-date"; break;
+ case 6: nick = "ascending-title"; break;
+ case 7: nick = "descending-title"; break;
+ case 8: nick = "ascending-artist"; break;
+ case 9: nick = "descending-artist"; break;
+ case 10: nick = "ascending-album-artist"; break;
+ case 11: nick = "descending-album-artist"; break;
+ case 12: nick = "ascending-album"; break;
+ case 13: nick = "descending-album"; break;
+ case 14: nick = "ascending-year"; break;
+ case 15: nick = "descending-year"; break;
+ case 16: nick = "ascending-genre"; break;
+ case 17: nick = "descending-genre"; break;
+ case 18: nick = "ascending-comment"; break;
+ case 19: nick = "descending-comment"; break;
+ case 20: nick = "ascending-composer"; break;
+ case 21: nick = "descending-composer"; break;
+ case 22: nick = "ascending-original-artist"; break;
+ case 23: nick = "descending-original-artist"; break;
+ case 24: nick = "ascending-copyright"; break;
+ case 25: nick = "descending-copyright"; break;
+ case 26: nick = "ascending-url"; break;
+ case 27: nick = "descending-url"; break;
+ case 28: nick = "ascending-encoded-by"; break;
+ case 29: nick = "descending-encoded-by"; break;
+ case 30: nick = "ascending-file-type"; break;
+ case 31: nick = "descending-file-type"; break;
+ case 32: nick = "ascending-file-size"; break;
+ case 33: nick = "descending-file-size"; break;
+ case 34: nick = "ascending-duration"; break;
+ case 35: nick = "descending-duration"; break;
+ case 36: nick = "ascending-bitrate"; break;
+ case 37: nick = "descending-bitrate"; break;
+ case 38: nick = "ascending-samplerate"; break;
+ case 39: nick = "descending-samplerate"; break;
+ default: nick = "ascending-track-number"; break;
+ }
+
+ return g_variant_new (g_variant_type_peek_string (expected_type), nick);
+}
diff --git a/src/setting.c b/src/setting.c
index 8b0fb2d..9f84199 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -111,7 +111,6 @@ tConfigVariable Config_Variables[] =
{
{"default_path_to_mp3", CV_TYPE_STRING, &DEFAULT_PATH_TO_MP3 },
- {"sorting_file_mode", CV_TYPE_INT, &SORTING_FILE_MODE },
{"sorting_file_case_sensitive", CV_TYPE_BOOL, &SORTING_FILE_CASE_SENSITIVE },
{"filename_extension_lower_case", CV_TYPE_BOOL, &FILENAME_EXTENSION_LOWER_CASE
},
@@ -223,7 +222,6 @@ void Init_Config_Variables (void)
/*
* Misc
*/
- SORTING_FILE_MODE = SORTING_BY_ASCENDING_FILENAME;
#ifdef G_OS_WIN32
SORTING_FILE_CASE_SENSITIVE = 1;
#else /* !G_OS_WIN32 */
@@ -373,8 +371,6 @@ Apply_Changes_Of_Preferences_Window (void)
/* Misc */
SORTING_FILE_CASE_SENSITIVE =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(SortingFileCaseSensitive));
- SORTING_FILE_MODE = gtk_combo_box_get_active(GTK_COMBO_BOX(SortingFileCombo));
-
if (AUDIO_FILE_PLAYER) g_free(AUDIO_FILE_PLAYER);
AUDIO_FILE_PLAYER =
g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(FilePlayerCombo)))));
diff --git a/src/setting.h b/src/setting.h
index 6befea0..2dbb9f2 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -55,7 +55,6 @@ gchar *DEFAULT_PATH_TO_MP3;
/* Misc */
/* User Interface. */
-gint SORTING_FILE_MODE;
gint SORTING_FILE_CASE_SENSITIVE;
gchar *AUDIO_FILE_PLAYER;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]