[easytag/wip/gsettings: 23/29] Store the file list sorting mode in GSettings



commit 20a371437e214f68a037b278264bc785466de9c0
Author: David King <amigadave amigadave com>
Date:   Sun Mar 3 22:17:16 2013 +0000

    Store the file list sorting mode in GSettings

 data/org.gnome.EasyTAG.gschema.xml |    2 -
 src/bar.c                          |   80 ++++++++++++++--------------
 src/browser.c                      |   83 +++++++++++++++---------------
 src/easytag.c                      |    8 ++-
 src/et_core.c                      |   99 ++++++++++++++++++-----------------
 src/et_core.h                      |   58 ++-------------------
 src/prefs.c                        |    9 ++--
 src/setting.c                      |   80 +++++++++++++++++++++++++++--
 src/setting.h                      |   54 +++++++++++++++++++-
 9 files changed, 277 insertions(+), 196 deletions(-)
---
diff --git a/data/org.gnome.EasyTAG.gschema.xml b/data/org.gnome.EasyTAG.gschema.xml
index 5cdfea9..65e2746 100644
--- a/data/org.gnome.EasyTAG.gschema.xml
+++ b/data/org.gnome.EasyTAG.gschema.xml
@@ -275,14 +275,12 @@
       <default>true</default>
     </key>
 
-    <!-- TODO: Generate enums with glib-mkenums.
     <key name="sort-mode" enum="org.gnome.EasyTAG.EtSortMode">
       <summary>How to sort audio files in the file list</summary>
       <description>Sort files in ascending or descending order for the selected
       type</description>
       <default>'ascending-track-number'</default>
     </key>
-    -->
 
     <key name="log-lines" type="u">
       <summary>Number of log lines</summary>
diff --git a/src/bar.c b/src/bar.c
index 9687981..32d2959 100644
--- a/src/bar.c
+++ b/src/bar.c
@@ -71,46 +71,46 @@ Menu_Sort_Action (GtkAction *item, gpointer data)
     const gchar *action = gtk_action_get_name(item);
     GQuark quark = g_quark_from_string(action);
 
-    QCASE_DATA(AM_SORT_ASCENDING_FILENAME,         ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_FILENAME);
-    QCASE_DATA(AM_SORT_DESCENDING_FILENAME,        ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_FILENAME);
-    QCASE_DATA(AM_SORT_ASCENDING_CREATION_DATE,    ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_CREATION_DATE);
-    QCASE_DATA(AM_SORT_DESCENDING_CREATION_DATE,   ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_CREATION_DATE);
-    QCASE_DATA(AM_SORT_ASCENDING_TRACK_NUMBER,     ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_TRACK_NUMBER);
-    QCASE_DATA(AM_SORT_DESCENDING_TRACK_NUMBER,    ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_TRACK_NUMBER);
-    QCASE_DATA(AM_SORT_ASCENDING_TITLE,            ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_TITLE);
-    QCASE_DATA(AM_SORT_DESCENDING_TITLE,           ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_TITLE);
-    QCASE_DATA(AM_SORT_ASCENDING_ARTIST,           ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_ARTIST);
-    QCASE_DATA(AM_SORT_DESCENDING_ARTIST,          ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_ARTIST);
-    QCASE_DATA(AM_SORT_ASCENDING_ALBUM_ARTIST,     ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_ALBUM_ARTIST);
-    QCASE_DATA(AM_SORT_DESCENDING_ALBUM_ARTIST,    ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_ALBUM_ARTIST);
-    QCASE_DATA(AM_SORT_ASCENDING_ALBUM,            ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_ALBUM);
-    QCASE_DATA(AM_SORT_DESCENDING_ALBUM,           ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_ALBUM);
-    QCASE_DATA(AM_SORT_ASCENDING_YEAR,             ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_YEAR);
-    QCASE_DATA(AM_SORT_DESCENDING_YEAR,            ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_YEAR);
-    QCASE_DATA(AM_SORT_ASCENDING_GENRE,            ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_GENRE);
-    QCASE_DATA(AM_SORT_DESCENDING_GENRE,           ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_GENRE);
-    QCASE_DATA(AM_SORT_ASCENDING_COMMENT,          ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_COMMENT);
-    QCASE_DATA(AM_SORT_DESCENDING_COMMENT,         ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_COMMENT);
-    QCASE_DATA(AM_SORT_ASCENDING_COMPOSER,         ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_COMPOSER);
-    QCASE_DATA(AM_SORT_DESCENDING_COMPOSER,        ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_COMPOSER);
-    QCASE_DATA(AM_SORT_ASCENDING_ORIG_ARTIST,      ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_ORIG_ARTIST);
-    QCASE_DATA(AM_SORT_DESCENDING_ORIG_ARTIST,     ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_ORIG_ARTIST);
-    QCASE_DATA(AM_SORT_ASCENDING_COPYRIGHT,        ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_COPYRIGHT);
-    QCASE_DATA(AM_SORT_DESCENDING_COPYRIGHT,       ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_COPYRIGHT);
-    QCASE_DATA(AM_SORT_ASCENDING_URL,              ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_URL);
-    QCASE_DATA(AM_SORT_DESCENDING_URL,             ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_URL);
-    QCASE_DATA(AM_SORT_ASCENDING_ENCODED_BY,       ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_ENCODED_BY);
-    QCASE_DATA(AM_SORT_DESCENDING_ENCODED_BY,      ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_ENCODED_BY);
-    QCASE_DATA(AM_SORT_ASCENDING_FILE_TYPE,        ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_FILE_TYPE);
-    QCASE_DATA(AM_SORT_DESCENDING_FILE_TYPE,       ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_FILE_TYPE);
-    QCASE_DATA(AM_SORT_ASCENDING_FILE_SIZE,        ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_FILE_SIZE);
-    QCASE_DATA(AM_SORT_DESCENDING_FILE_SIZE,       ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_FILE_SIZE);
-    QCASE_DATA(AM_SORT_ASCENDING_FILE_DURATION,    ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_FILE_DURATION);
-    QCASE_DATA(AM_SORT_DESCENDING_FILE_DURATION,   ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_FILE_DURATION);
-    QCASE_DATA(AM_SORT_ASCENDING_FILE_BITRATE,     ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_FILE_BITRATE);
-    QCASE_DATA(AM_SORT_DESCENDING_FILE_BITRATE,    ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_FILE_BITRATE);
-    QCASE_DATA(AM_SORT_ASCENDING_FILE_SAMPLERATE,  ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_ASCENDING_FILE_SAMPLERATE);
-    QCASE_DATA(AM_SORT_DESCENDING_FILE_SAMPLERATE, ET_Sort_Displayed_File_List_And_Update_UI, 
SORTING_BY_DESCENDING_FILE_SAMPLERATE);
+    QCASE_DATA(AM_SORT_ASCENDING_FILENAME,         ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_FILENAME);
+    QCASE_DATA(AM_SORT_DESCENDING_FILENAME,        ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_FILENAME);
+    QCASE_DATA(AM_SORT_ASCENDING_CREATION_DATE,    ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_CREATION_DATE);
+    QCASE_DATA(AM_SORT_DESCENDING_CREATION_DATE,   ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_CREATION_DATE);
+    QCASE_DATA(AM_SORT_ASCENDING_TRACK_NUMBER,     ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_TRACK_NUMBER);
+    QCASE_DATA(AM_SORT_DESCENDING_TRACK_NUMBER,    ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_TRACK_NUMBER);
+    QCASE_DATA(AM_SORT_ASCENDING_TITLE,            ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_TITLE);
+    QCASE_DATA(AM_SORT_DESCENDING_TITLE,           ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_TITLE);
+    QCASE_DATA(AM_SORT_ASCENDING_ARTIST,           ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_ARTIST);
+    QCASE_DATA(AM_SORT_DESCENDING_ARTIST,          ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_ARTIST);
+    QCASE_DATA(AM_SORT_ASCENDING_ALBUM_ARTIST,     ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_ALBUM_ARTIST);
+    QCASE_DATA(AM_SORT_DESCENDING_ALBUM_ARTIST,    ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_ALBUM_ARTIST);
+    QCASE_DATA(AM_SORT_ASCENDING_ALBUM,            ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_ALBUM);
+    QCASE_DATA(AM_SORT_DESCENDING_ALBUM,           ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_ALBUM);
+    QCASE_DATA(AM_SORT_ASCENDING_YEAR,             ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_YEAR);
+    QCASE_DATA(AM_SORT_DESCENDING_YEAR,            ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_YEAR);
+    QCASE_DATA(AM_SORT_ASCENDING_GENRE,            ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_GENRE);
+    QCASE_DATA(AM_SORT_DESCENDING_GENRE,           ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_GENRE);
+    QCASE_DATA(AM_SORT_ASCENDING_COMMENT,          ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_COMMENT);
+    QCASE_DATA(AM_SORT_DESCENDING_COMMENT,         ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_COMMENT);
+    QCASE_DATA(AM_SORT_ASCENDING_COMPOSER,         ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_COMPOSER);
+    QCASE_DATA(AM_SORT_DESCENDING_COMPOSER,        ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_COMPOSER);
+    QCASE_DATA(AM_SORT_ASCENDING_ORIG_ARTIST,      ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_ORIG_ARTIST);
+    QCASE_DATA(AM_SORT_DESCENDING_ORIG_ARTIST,     ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_ORIG_ARTIST);
+    QCASE_DATA(AM_SORT_ASCENDING_COPYRIGHT,        ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_COPYRIGHT);
+    QCASE_DATA(AM_SORT_DESCENDING_COPYRIGHT,       ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_COPYRIGHT);
+    QCASE_DATA(AM_SORT_ASCENDING_URL,              ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_URL);
+    QCASE_DATA(AM_SORT_DESCENDING_URL,             ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_URL);
+    QCASE_DATA(AM_SORT_ASCENDING_ENCODED_BY,       ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_ENCODED_BY);
+    QCASE_DATA(AM_SORT_DESCENDING_ENCODED_BY,      ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_ENCODED_BY);
+    QCASE_DATA(AM_SORT_ASCENDING_FILE_TYPE,        ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_FILE_TYPE);
+    QCASE_DATA(AM_SORT_DESCENDING_FILE_TYPE,       ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_FILE_TYPE);
+    QCASE_DATA(AM_SORT_ASCENDING_FILE_SIZE,        ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_FILE_SIZE);
+    QCASE_DATA(AM_SORT_DESCENDING_FILE_SIZE,       ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_FILE_SIZE);
+    QCASE_DATA(AM_SORT_ASCENDING_FILE_DURATION,    ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_FILE_DURATION);
+    QCASE_DATA(AM_SORT_DESCENDING_FILE_DURATION,   ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_FILE_DURATION);
+    QCASE_DATA(AM_SORT_ASCENDING_FILE_BITRATE,     ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_FILE_BITRATE);
+    QCASE_DATA(AM_SORT_DESCENDING_FILE_BITRATE,    ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_FILE_BITRATE);
+    QCASE_DATA(AM_SORT_ASCENDING_FILE_SAMPLERATE,  ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_ASCENDING_FILE_SAMPLERATE);
+    QCASE_DATA(AM_SORT_DESCENDING_FILE_SAMPLERATE, ET_Sort_Displayed_File_List_And_Update_UI, 
ET_SORT_MODE_DESCENDING_FILE_SAMPLERATE);
     QCASE_DATA(AM_INITIALIZE_TREE,                 Browser_Tree_Rebuild,                      NULL);
 
     if (quark == g_quark_from_string(AM_TREE_OR_ARTISTALBUM_VIEW))
diff --git a/src/browser.c b/src/browser.c
index 5f4153e..6a43a4f 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -1743,127 +1743,126 @@ 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:
+        case ET_SORT_MODE_ASCENDING_FILENAME:
             result = ET_Comp_Func_Sort_File_By_Ascending_Filename(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_FILENAME:
+        case ET_SORT_MODE_DESCENDING_FILENAME:
             result = ET_Comp_Func_Sort_File_By_Descending_Filename(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_TRACK_NUMBER:
+        case ET_SORT_MODE_ASCENDING_TRACK_NUMBER:
             result = ET_Comp_Func_Sort_File_By_Ascending_Track_Number(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_TRACK_NUMBER:
+        case ET_SORT_MODE_DESCENDING_TRACK_NUMBER:
             result = ET_Comp_Func_Sort_File_By_Descending_Track_Number(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_CREATION_DATE:
+        case ET_SORT_MODE_ASCENDING_CREATION_DATE:
             result = ET_Comp_Func_Sort_File_By_Ascending_Creation_Date(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_CREATION_DATE:
+        case ET_SORT_MODE_DESCENDING_CREATION_DATE:
             result = ET_Comp_Func_Sort_File_By_Descending_Creation_Date(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_TITLE:
+        case ET_SORT_MODE_ASCENDING_TITLE:
             result = ET_Comp_Func_Sort_File_By_Ascending_Title(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_TITLE:
+        case ET_SORT_MODE_DESCENDING_TITLE:
             result = ET_Comp_Func_Sort_File_By_Descending_Title(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_ARTIST:
+        case ET_SORT_MODE_ASCENDING_ARTIST:
             result = ET_Comp_Func_Sort_File_By_Ascending_Artist(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_ARTIST:
+        case ET_SORT_MODE_DESCENDING_ARTIST:
             result = ET_Comp_Func_Sort_File_By_Descending_Artist(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_ALBUM_ARTIST:
+        case ET_SORT_MODE_ASCENDING_ALBUM_ARTIST:
             result = ET_Comp_Func_Sort_File_By_Ascending_Album_Artist(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_ALBUM_ARTIST:
+        case ET_SORT_MODE_DESCENDING_ALBUM_ARTIST:
             result = ET_Comp_Func_Sort_File_By_Descending_Album_Artist(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_ALBUM:
+        case ET_SORT_MODE_ASCENDING_ALBUM:
             result = ET_Comp_Func_Sort_File_By_Ascending_Album(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_ALBUM:
+        case ET_SORT_MODE_DESCENDING_ALBUM:
             result = ET_Comp_Func_Sort_File_By_Descending_Album(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_YEAR:
+        case ET_SORT_MODE_ASCENDING_YEAR:
             result = ET_Comp_Func_Sort_File_By_Ascending_Year(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_YEAR:
+        case ET_SORT_MODE_DESCENDING_YEAR:
             result = ET_Comp_Func_Sort_File_By_Descending_Year(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_GENRE:
+        case ET_SORT_MODE_ASCENDING_GENRE:
             result = ET_Comp_Func_Sort_File_By_Ascending_Genre(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_GENRE:
+        case ET_SORT_MODE_DESCENDING_GENRE:
             result = ET_Comp_Func_Sort_File_By_Descending_Genre(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_COMMENT:
+        case ET_SORT_MODE_ASCENDING_COMMENT:
             result = ET_Comp_Func_Sort_File_By_Ascending_Comment(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_COMMENT:
+        case ET_SORT_MODE_DESCENDING_COMMENT:
             result = ET_Comp_Func_Sort_File_By_Descending_Comment(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_COMPOSER:
+        case ET_SORT_MODE_ASCENDING_COMPOSER:
             result = ET_Comp_Func_Sort_File_By_Ascending_Composer(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_COMPOSER:
+        case ET_SORT_MODE_DESCENDING_COMPOSER:
             result = ET_Comp_Func_Sort_File_By_Descending_Composer(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_ORIG_ARTIST:
+        case ET_SORT_MODE_ASCENDING_ORIG_ARTIST:
             result = ET_Comp_Func_Sort_File_By_Ascending_Orig_Artist(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_ORIG_ARTIST:
+        case ET_SORT_MODE_DESCENDING_ORIG_ARTIST:
             result = ET_Comp_Func_Sort_File_By_Descending_Orig_Artist(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_COPYRIGHT:
+        case ET_SORT_MODE_ASCENDING_COPYRIGHT:
             result = ET_Comp_Func_Sort_File_By_Ascending_Copyright(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_COPYRIGHT:
+        case ET_SORT_MODE_DESCENDING_COPYRIGHT:
             result = ET_Comp_Func_Sort_File_By_Descending_Copyright(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_URL:
+        case ET_SORT_MODE_ASCENDING_URL:
             result = ET_Comp_Func_Sort_File_By_Ascending_Url(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_URL:
+        case ET_SORT_MODE_DESCENDING_URL:
             result = ET_Comp_Func_Sort_File_By_Descending_Url(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_ENCODED_BY:
+        case ET_SORT_MODE_ASCENDING_ENCODED_BY:
             result = ET_Comp_Func_Sort_File_By_Ascending_Encoded_By(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_ENCODED_BY:
+        case ET_SORT_MODE_DESCENDING_ENCODED_BY:
             result = ET_Comp_Func_Sort_File_By_Descending_Encoded_By(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_FILE_TYPE:
+        case ET_SORT_MODE_ASCENDING_FILE_TYPE:
             result = ET_Comp_Func_Sort_File_By_Ascending_File_Type(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_FILE_TYPE:
+        case ET_SORT_MODE_DESCENDING_FILE_TYPE:
             result = ET_Comp_Func_Sort_File_By_Descending_File_Type(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_FILE_SIZE:
+        case ET_SORT_MODE_ASCENDING_FILE_SIZE:
             result = ET_Comp_Func_Sort_File_By_Ascending_File_Size(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_FILE_SIZE:
+        case ET_SORT_MODE_DESCENDING_FILE_SIZE:
             result = ET_Comp_Func_Sort_File_By_Descending_File_Size(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_FILE_DURATION:
+        case ET_SORT_MODE_ASCENDING_FILE_DURATION:
             result = ET_Comp_Func_Sort_File_By_Ascending_File_Duration(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_FILE_DURATION:
+        case ET_SORT_MODE_DESCENDING_FILE_DURATION:
             result = ET_Comp_Func_Sort_File_By_Descending_File_Duration(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_FILE_BITRATE:
+        case ET_SORT_MODE_ASCENDING_FILE_BITRATE:
             result = ET_Comp_Func_Sort_File_By_Ascending_File_Bitrate(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_FILE_BITRATE:
+        case ET_SORT_MODE_DESCENDING_FILE_BITRATE:
             result = ET_Comp_Func_Sort_File_By_Descending_File_Bitrate(ETFile1, ETFile2);
             break;
-        case SORTING_BY_ASCENDING_FILE_SAMPLERATE:
+        case ET_SORT_MODE_ASCENDING_FILE_SAMPLERATE:
             result = ET_Comp_Func_Sort_File_By_Ascending_File_Samplerate(ETFile1, ETFile2);
             break;
-        case SORTING_BY_DESCENDING_FILE_SAMPLERATE:
+        case ET_SORT_MODE_DESCENDING_FILE_SAMPLERATE:
             result = ET_Comp_Func_Sort_File_By_Descending_File_Samplerate(ETFile1, ETFile2);
             break;
     }
diff --git a/src/easytag.c b/src/easytag.c
index 4021978..0682df9 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -1419,6 +1419,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;
@@ -1426,9 +1427,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 e0269d3..b5dd02f 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -887,143 +887,144 @@ ET_Remove_File_From_Artist_Album_List (ET_File *ETFile)
  * Note : Add also new sorting in 'Browser_List_Sort_Func'
  */
 static void
-ET_Sort_Displayed_File_List (ET_Sorting_Type Sorting_Type)
+ET_Sort_Displayed_File_List (EtSortMode Sorting_Type)
 {
     ETCore->ETFileDisplayedList = ET_Sort_File_List(ETCore->ETFileDisplayedList,Sorting_Type);
 }
+
 /*
  * Sort an 'ETFileList'
  */
-GList *ET_Sort_File_List (GList *ETFileList, ET_Sorting_Type Sorting_Type)
+GList *
+ET_Sort_File_List (GList *ETFileList, EtSortMode 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)
     {
-        case SORTING_UNKNOWN:
-        case SORTING_BY_ASCENDING_FILENAME:
+        case ET_SORT_MODE_ASCENDING_FILENAME:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_Filename);
             break;
-        case SORTING_BY_DESCENDING_FILENAME:
+        case ET_SORT_MODE_DESCENDING_FILENAME:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_Filename);
             break;
-        case SORTING_BY_ASCENDING_TRACK_NUMBER:
+        case ET_SORT_MODE_ASCENDING_TRACK_NUMBER:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_Track_Number);
             break;
-        case SORTING_BY_DESCENDING_TRACK_NUMBER:
+        case ET_SORT_MODE_DESCENDING_TRACK_NUMBER:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_Track_Number);
             break;
-        case SORTING_BY_ASCENDING_CREATION_DATE:
+        case ET_SORT_MODE_ASCENDING_CREATION_DATE:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_Creation_Date);
             break;
-        case SORTING_BY_DESCENDING_CREATION_DATE:
+        case ET_SORT_MODE_DESCENDING_CREATION_DATE:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_Creation_Date);
             break;
-        case SORTING_BY_ASCENDING_TITLE:
+        case ET_SORT_MODE_ASCENDING_TITLE:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_Title);
             break;
-        case SORTING_BY_DESCENDING_TITLE:
+        case ET_SORT_MODE_DESCENDING_TITLE:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_Title);
             break;
-        case SORTING_BY_ASCENDING_ARTIST:
+        case ET_SORT_MODE_ASCENDING_ARTIST:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_Artist);
             break;
-        case SORTING_BY_DESCENDING_ARTIST:
+        case ET_SORT_MODE_DESCENDING_ARTIST:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_Artist);
             break;
-        case SORTING_BY_ASCENDING_ALBUM_ARTIST:
+        case ET_SORT_MODE_ASCENDING_ALBUM_ARTIST:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_Album_Artist);
             break;
-        case SORTING_BY_DESCENDING_ALBUM_ARTIST:
+        case ET_SORT_MODE_DESCENDING_ALBUM_ARTIST:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_Album_Artist);
             break;
-               case SORTING_BY_ASCENDING_ALBUM:
+               case ET_SORT_MODE_ASCENDING_ALBUM:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_Album);
             break;
-        case SORTING_BY_DESCENDING_ALBUM:
+        case ET_SORT_MODE_DESCENDING_ALBUM:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_Album);
             break;
-        case SORTING_BY_ASCENDING_YEAR:
+        case ET_SORT_MODE_ASCENDING_YEAR:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_Year);
             break;
-        case SORTING_BY_DESCENDING_YEAR:
+        case ET_SORT_MODE_DESCENDING_YEAR:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_Year);
             break;
-        case SORTING_BY_ASCENDING_GENRE:
+        case ET_SORT_MODE_ASCENDING_GENRE:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_Genre);
             break;
-        case SORTING_BY_DESCENDING_GENRE:
+        case ET_SORT_MODE_DESCENDING_GENRE:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_Genre);
             break;
-        case SORTING_BY_ASCENDING_COMMENT:
+        case ET_SORT_MODE_ASCENDING_COMMENT:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_Comment);
             break;
-        case SORTING_BY_DESCENDING_COMMENT:
+        case ET_SORT_MODE_DESCENDING_COMMENT:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_Comment);
             break;
-        case SORTING_BY_ASCENDING_COMPOSER:
+        case ET_SORT_MODE_ASCENDING_COMPOSER:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_Composer);
             break;
-        case SORTING_BY_DESCENDING_COMPOSER:
+        case ET_SORT_MODE_DESCENDING_COMPOSER:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_Composer);
             break;
-        case SORTING_BY_ASCENDING_ORIG_ARTIST:
+        case ET_SORT_MODE_ASCENDING_ORIG_ARTIST:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_Orig_Artist);
             break;
-        case SORTING_BY_DESCENDING_ORIG_ARTIST:
+        case ET_SORT_MODE_DESCENDING_ORIG_ARTIST:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_Orig_Artist);
             break;
-        case SORTING_BY_ASCENDING_COPYRIGHT:
+        case ET_SORT_MODE_ASCENDING_COPYRIGHT:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_Copyright);
             break;
-        case SORTING_BY_DESCENDING_COPYRIGHT:
+        case ET_SORT_MODE_DESCENDING_COPYRIGHT:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_Copyright);
             break;
-        case SORTING_BY_ASCENDING_URL:
+        case ET_SORT_MODE_ASCENDING_URL:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_Url);
             break;
-        case SORTING_BY_DESCENDING_URL:
+        case ET_SORT_MODE_DESCENDING_URL:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_Url);
             break;
-        case SORTING_BY_ASCENDING_ENCODED_BY:
+        case ET_SORT_MODE_ASCENDING_ENCODED_BY:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_Encoded_By);
             break;
-        case SORTING_BY_DESCENDING_ENCODED_BY:
+        case ET_SORT_MODE_DESCENDING_ENCODED_BY:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_Encoded_By);
             break;
-        case SORTING_BY_ASCENDING_FILE_TYPE:
+        case ET_SORT_MODE_ASCENDING_FILE_TYPE:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_File_Type);
             break;
-        case SORTING_BY_DESCENDING_FILE_TYPE:
+        case ET_SORT_MODE_DESCENDING_FILE_TYPE:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_File_Type);
             break;
-        case SORTING_BY_ASCENDING_FILE_SIZE:
+        case ET_SORT_MODE_ASCENDING_FILE_SIZE:
             etfilelist = g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_File_Size);
             break;
-        case SORTING_BY_DESCENDING_FILE_SIZE:
+        case ET_SORT_MODE_DESCENDING_FILE_SIZE:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_File_Size);
             break;
-        case SORTING_BY_ASCENDING_FILE_DURATION:
+        case ET_SORT_MODE_ASCENDING_FILE_DURATION:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_File_Duration);
             break;
-        case SORTING_BY_DESCENDING_FILE_DURATION:
+        case ET_SORT_MODE_DESCENDING_FILE_DURATION:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_File_Duration);
             break;
-        case SORTING_BY_ASCENDING_FILE_BITRATE:
+        case ET_SORT_MODE_ASCENDING_FILE_BITRATE:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_File_Bitrate);
             break;
-        case SORTING_BY_DESCENDING_FILE_BITRATE:
+        case ET_SORT_MODE_DESCENDING_FILE_BITRATE:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_File_Bitrate);
             break;
-        case SORTING_BY_ASCENDING_FILE_SAMPLERATE:
+        case ET_SORT_MODE_ASCENDING_FILE_SAMPLERATE:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Ascending_File_Samplerate);
             break;
-        case SORTING_BY_DESCENDING_FILE_SAMPLERATE:
+        case ET_SORT_MODE_DESCENDING_FILE_SAMPLERATE:
             etfilelist = 
g_list_sort(etfilelist,(GCompareFunc)ET_Comp_Func_Sort_File_By_Descending_File_Samplerate);
             break;
     }
@@ -1035,7 +1036,8 @@ GList *ET_Sort_File_List (GList *ETFileList, ET_Sorting_Type Sorting_Type)
 /*
  * Sort the list of files following the 'Sorting_Type' value. The new sorting is displayed in the UI.
  */
-void ET_Sort_Displayed_File_List_And_Update_UI (ET_Sorting_Type Sorting_Type)
+void
+ET_Sort_Displayed_File_List_And_Update_UI (EtSortMode Sorting_Type)
 {
     g_return_if_fail (ETCore->ETFileList != NULL);
 
@@ -1969,8 +1971,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 524cd4a..6a5aa92 100644
--- a/src/et_core.h
+++ b/src/et_core.h
@@ -23,9 +23,12 @@
 #define __ET_CORE_H__
 
 
+#include "config.h" /* For definition of ENABLE_OGG and so on. */
+
+#include "setting.h"
+
 #include <glib.h>
 #include <gdk/gdk.h>
-#include <config.h> // For definition of ENABLE_OGG, ...
 
 
 /***************
@@ -45,55 +48,6 @@ GdkColor BLACK;
 
 
 /*
- * Types of sorting (discontinuous value to avoid separators in SortingFileOptionMenu).
- */
-typedef enum
-{
-    SORTING_BY_ASCENDING_FILENAME,
-    SORTING_BY_DESCENDING_FILENAME,
-    SORTING_BY_ASCENDING_TRACK_NUMBER,
-    SORTING_BY_DESCENDING_TRACK_NUMBER,
-    SORTING_BY_ASCENDING_CREATION_DATE,
-    SORTING_BY_DESCENDING_CREATION_DATE,
-    SORTING_BY_ASCENDING_TITLE,
-    SORTING_BY_DESCENDING_TITLE,
-    SORTING_BY_ASCENDING_ARTIST,
-    SORTING_BY_DESCENDING_ARTIST,
-    SORTING_BY_ASCENDING_ALBUM_ARTIST,
-    SORTING_BY_DESCENDING_ALBUM_ARTIST,
-    SORTING_BY_ASCENDING_ALBUM,
-    SORTING_BY_DESCENDING_ALBUM,
-    SORTING_BY_ASCENDING_YEAR,
-    SORTING_BY_DESCENDING_YEAR,
-    SORTING_BY_ASCENDING_GENRE,
-    SORTING_BY_DESCENDING_GENRE,
-    SORTING_BY_ASCENDING_COMMENT,
-    SORTING_BY_DESCENDING_COMMENT,
-    SORTING_BY_ASCENDING_COMPOSER,
-    SORTING_BY_DESCENDING_COMPOSER,
-    SORTING_BY_ASCENDING_ORIG_ARTIST,
-    SORTING_BY_DESCENDING_ORIG_ARTIST,
-    SORTING_BY_ASCENDING_COPYRIGHT,
-    SORTING_BY_DESCENDING_COPYRIGHT,
-    SORTING_BY_ASCENDING_URL,
-    SORTING_BY_DESCENDING_URL,
-    SORTING_BY_ASCENDING_ENCODED_BY,
-    SORTING_BY_DESCENDING_ENCODED_BY,
-    SORTING_BY_ASCENDING_FILE_TYPE,
-    SORTING_BY_DESCENDING_FILE_TYPE,
-    SORTING_BY_ASCENDING_FILE_SIZE,
-    SORTING_BY_DESCENDING_FILE_SIZE,
-    SORTING_BY_ASCENDING_FILE_DURATION,
-    SORTING_BY_DESCENDING_FILE_DURATION,
-    SORTING_BY_ASCENDING_FILE_BITRATE,
-    SORTING_BY_DESCENDING_FILE_BITRATE,
-    SORTING_BY_ASCENDING_FILE_SAMPLERATE,
-    SORTING_BY_DESCENDING_FILE_SAMPLERATE,
-    SORTING_UNKNOWN
-} ET_Sorting_Type;
-
-
-/*
  * Types of files
  */
 typedef enum
@@ -395,8 +349,8 @@ guint ET_Get_Number_Of_Files_In_Directory (const gchar *path_utf8);
 
 gboolean ET_Detect_Changes_Of_File_Tag          (File_Tag  *FileTag1,  File_Tag  *FileTag2);
 
-GList *ET_Sort_File_List                                  (GList *ETFileList, ET_Sorting_Type Sorting_Type);
-void   ET_Sort_Displayed_File_List_And_Update_UI          (ET_Sorting_Type Sorting_Type);
+GList *ET_Sort_File_List (GList *ETFileList, EtSortMode Sorting_Type);
+void ET_Sort_Displayed_File_List_And_Update_UI (EtSortMode Sorting_Type);
 gint ET_Comp_Func_Sort_File_By_Ascending_Filename         (ET_File *ETFile1, ET_File *ETFile2);
 gint ET_Comp_Func_Sort_File_By_Descending_Filename        (ET_File *ETFile1, ET_File *ETFile2);
 gint ET_Comp_Func_Sort_File_By_Ascending_Creation_Date    (ET_File *ETFile1, ET_File *ETFile2);
diff --git a/src/prefs.c b/src/prefs.c
index 91e48a4..2e65b62 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -38,6 +38,7 @@
 #include "misc.h"
 #include "scan.h"
 #include "easytag.h"
+#include "enums.h"
 #include "browser.h"
 #include "cddb.h"
 #include "charset.h"
@@ -68,7 +69,6 @@ static void DefaultPathToMp3_Combo_Add_String (void);
 static void CddbLocalPath_Combo_Add_String (void);
 
 
-
 /*************
  * Functions *
  *************/
@@ -323,7 +323,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_settings_enum_get, et_settings_enum_set,
+                                  GSIZE_TO_POINTER (ET_TYPE_SORT_MODE), NULL);
     gtk_widget_set_tooltip_text(SortingFileCombo,
                                 _("Select the type of file sorting when "
                                 "loading a directory."));
@@ -1961,5 +1964,3 @@ CddbLocalPath_Combo_Add_String (void)
     path = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(CddbLocalPath))));
     Add_String_To_Combo_List(GTK_LIST_STORE(CddbLocalPath), path);
 }
-
-
diff --git a/src/setting.c b/src/setting.c
index 910594f..86e5774 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       
     },
@@ -222,7 +221,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 */
@@ -372,8 +370,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)))));
 
@@ -1189,3 +1185,79 @@ Create_Easytag_Directory (void)
         return TRUE;
     }
 }
+
+/*
+ * et_settings_enum_get:
+ * @value: the property value to be set (active item on combo box)
+ * @variant: the variant to set the @value from
+ * @user_data: the #GType of the #GSettings enum
+ *
+ * Wrapper function to convert an enum-type GSettings key into an integer
+ * value.
+ *
+ * Returns: %TRUE if the mapping was successful, %FALSE otherwise
+ */
+gboolean
+et_settings_enum_get (GValue *value, GVariant *variant, gpointer user_data)
+{
+    GType enum_type;
+    GEnumClass *enum_class;
+    GEnumValue *enum_value;
+    const gchar *nick;
+
+    g_return_val_if_fail (user_data != NULL, FALSE);
+
+    enum_type = (GType)GPOINTER_TO_SIZE (user_data);
+    enum_class = g_type_class_ref (enum_type);
+    nick = g_variant_get_string (variant, NULL);
+    enum_value = g_enum_get_value_by_nick (enum_class, nick);
+    g_type_class_unref (enum_class);
+
+    if (!enum_value)
+    {
+        g_warning ("Unable to lookup %s enum nick '%s' from GType",
+                   g_type_name (enum_type),
+                   nick);
+        return FALSE;
+    }
+
+    g_value_set_int (value, enum_value->value);
+    return TRUE;
+}
+
+/*
+ * et_settings_enum_set:
+ * @value: the property value to set the @variant from
+ * @expected_type: the expected type of the returned variant
+ * @user_data: the #GType of the #GSettings enum
+ *
+ * Wrapper function to convert an integer value into a string suitable for
+ * storing into an enum-type GSettings key.
+ *
+ * Returns: a new GVariant containing the mapped value, or %NULL upon failure
+ */
+GVariant *
+et_settings_enum_set (const GValue *value, const GVariantType *expected_type,
+                      gpointer user_data)
+{
+    GType enum_type;
+    GEnumClass *enum_class;
+    GEnumValue *enum_value;
+
+    g_return_val_if_fail (user_data != NULL, NULL);
+
+    enum_type = (GType)GPOINTER_TO_SIZE (user_data);
+    enum_class = g_type_class_ref (enum_type);
+    enum_value = g_enum_get_value (enum_class, g_value_get_int (value));
+    g_type_class_unref (enum_class);
+
+    if (!enum_value)
+    {
+        g_warning ("Unable to lookup %s enum value '%d' from GType",
+                   g_type_name (enum_type), g_value_get_int (value));
+        return NULL;
+    }
+
+    return g_variant_new (g_variant_type_peek_string (expected_type),
+                          enum_value->value_nick);
+}
diff --git a/src/setting.h b/src/setting.h
index 6befea0..7b7f830 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -46,6 +46,54 @@ struct _tConfigVariable
 
 
 /*
+ * Types of sorting. See the GSettings key "sort-mode".
+ */
+typedef enum
+{
+    ET_SORT_MODE_ASCENDING_FILENAME,
+    ET_SORT_MODE_DESCENDING_FILENAME,
+    ET_SORT_MODE_ASCENDING_TRACK_NUMBER,
+    ET_SORT_MODE_DESCENDING_TRACK_NUMBER,
+    ET_SORT_MODE_ASCENDING_CREATION_DATE,
+    ET_SORT_MODE_DESCENDING_CREATION_DATE,
+    ET_SORT_MODE_ASCENDING_TITLE,
+    ET_SORT_MODE_DESCENDING_TITLE,
+    ET_SORT_MODE_ASCENDING_ARTIST,
+    ET_SORT_MODE_DESCENDING_ARTIST,
+    ET_SORT_MODE_ASCENDING_ALBUM_ARTIST,
+    ET_SORT_MODE_DESCENDING_ALBUM_ARTIST,
+    ET_SORT_MODE_ASCENDING_ALBUM,
+    ET_SORT_MODE_DESCENDING_ALBUM,
+    ET_SORT_MODE_ASCENDING_YEAR,
+    ET_SORT_MODE_DESCENDING_YEAR,
+    ET_SORT_MODE_ASCENDING_GENRE,
+    ET_SORT_MODE_DESCENDING_GENRE,
+    ET_SORT_MODE_ASCENDING_COMMENT,
+    ET_SORT_MODE_DESCENDING_COMMENT,
+    ET_SORT_MODE_ASCENDING_COMPOSER,
+    ET_SORT_MODE_DESCENDING_COMPOSER,
+    ET_SORT_MODE_ASCENDING_ORIG_ARTIST,
+    ET_SORT_MODE_DESCENDING_ORIG_ARTIST,
+    ET_SORT_MODE_ASCENDING_COPYRIGHT,
+    ET_SORT_MODE_DESCENDING_COPYRIGHT,
+    ET_SORT_MODE_ASCENDING_URL,
+    ET_SORT_MODE_DESCENDING_URL,
+    ET_SORT_MODE_ASCENDING_ENCODED_BY,
+    ET_SORT_MODE_DESCENDING_ENCODED_BY,
+    ET_SORT_MODE_ASCENDING_FILE_TYPE,
+    ET_SORT_MODE_DESCENDING_FILE_TYPE,
+    ET_SORT_MODE_ASCENDING_FILE_SIZE,
+    ET_SORT_MODE_DESCENDING_FILE_SIZE,
+    ET_SORT_MODE_ASCENDING_FILE_DURATION,
+    ET_SORT_MODE_DESCENDING_FILE_DURATION,
+    ET_SORT_MODE_ASCENDING_FILE_BITRATE,
+    ET_SORT_MODE_DESCENDING_FILE_BITRATE,
+    ET_SORT_MODE_ASCENDING_FILE_SAMPLERATE,
+    ET_SORT_MODE_DESCENDING_FILE_SAMPLERATE
+} EtSortMode;
+
+
+/*
  * Config variables
  */
 GSettings *ETSettings;
@@ -55,7 +103,6 @@ gchar  *DEFAULT_PATH_TO_MP3;
 
 /* Misc */
 /* User Interface. */
-gint    SORTING_FILE_MODE;
 gint    SORTING_FILE_CASE_SENSITIVE;
 
 gchar  *AUDIO_FILE_PLAYER;
@@ -228,6 +275,11 @@ void Save_Cddb_Search_String_In_Result_List (GtkListStore *liststore, gint colnu
 void Load_Cddb_Local_Path_List (GtkListStore *liststore, gint colnum);
 void Save_Cddb_Local_Path_List (GtkListStore *liststore, gint colnum);
 
+gboolean et_settings_enum_get (GValue *value, GVariant *variant,
+                               gpointer user_data);
+GVariant *et_settings_enum_set (const GValue *value,
+                                const GVariantType *expected_type,
+                                gpointer user_data);
 
 
 #endif /* __CONFIG_H__ */



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