[easytag/wip/application-window: 4/13] Store the file list sorting mode in GSettings



commit 480139a97325e3d92980516cebc37eaab766bb1d
Author: David King <amigadave amigadave com>
Date:   Thu May 8 08:26:21 2014 +0100

    Store the file list sorting mode in GSettings

 Makefile.am                        |    1 +
 data/org.gnome.EasyTAG.gschema.xml |    2 -
 src/application_window.c           |    8 ++-
 src/bar.c                          |   80 +++++++++++++-------------
 src/browser.c                      |   96 ++++++++++++++++----------------
 src/et_core.c                      |  110 ++++++++++++++++++-----------------
 src/et_core.h                      |   94 +++++++------------------------
 src/preferences_dialog.c           |    6 ++-
 src/setting.c                      |   98 +++++++++++++++++++++++++++++---
 src/setting.h                      |   88 ++++++++++++++++++++++------
 10 files changed, 335 insertions(+), 248 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 5685f4f..6e0df0c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -21,6 +21,7 @@ localedir = $(prefix)/$(DATADIRNAME)/locale
 easytag_CPPFLAGS = \
        -I$(top_srcdir) \
        -I$(top_builddir) \
+       -I$(top_builddir)/src \
        $(DEPRECATED_CPPFLAGS) \
        -DLOCALEDIR=\"$(localedir)\"
 
diff --git a/data/org.gnome.EasyTAG.gschema.xml b/data/org.gnome.EasyTAG.gschema.xml
index 7fb6bfb..9375823 100644
--- a/data/org.gnome.EasyTAG.gschema.xml
+++ b/data/org.gnome.EasyTAG.gschema.xml
@@ -230,14 +230,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/application_window.c b/src/application_window.c
index 99d8509..3294a85 100644
--- a/src/application_window.c
+++ b/src/application_window.c
@@ -640,6 +640,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;
@@ -647,9 +648,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 (MainSettings, "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/bar.c b/src/bar.c
index aae600d..9c25937 100644
--- a/src/bar.c
+++ b/src/bar.c
@@ -96,46 +96,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, reload_browser, data);
     et_application_window_browser_refresh_sort (ET_APPLICATION_WINDOW (data));
 }
diff --git a/src/browser.c b/src/browser.c
index d964a3c..ef555d6 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -2059,7 +2059,7 @@ et_browser_clear (EtBrowser *self)
 }
 
 /*
- * Refresh the list sorting (call me after SORTING_FILE_MODE has changed)
+ * Refresh the list sorting (call me after sort-mode has changed)
  */
 void
 et_browser_refresh_sort (EtBrowser *self)
@@ -2089,136 +2089,136 @@ Browser_List_Sort_Func (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b,
     gtk_tree_model_get(model, a, LIST_FILE_POINTER, &ETFile1, -1);
     gtk_tree_model_get(model, b, LIST_FILE_POINTER, &ETFile2, -1);
 
-    switch (SORTING_FILE_MODE)
+    switch (g_settings_get_enum (MainSettings, "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_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_DISC_NUMBER:
+        case ET_SORT_MODE_ASCENDING_DISC_NUMBER:
             result = et_comp_func_sort_file_by_ascending_disc_number (ETFile1,
                                                                       ETFile2);
             break;
-        case SORTING_BY_DESCENDING_DISC_NUMBER:
+        case ET_SORT_MODE_DESCENDING_DISC_NUMBER:
             result = et_comp_func_sort_file_by_descending_disc_number (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_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_CREATION_DATE:
-            result = ET_Comp_Func_Sort_File_By_Ascending_Creation_Date (ETFile1,                             
                                           ETFile2);
+        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_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;
     }
@@ -3938,7 +3938,7 @@ et_browser_set_sorting_file_mode (GtkTreeViewColumn *column, gpointer data)
     self = ET_BROWSER (g_object_get_data (G_OBJECT (column), "browser"));
 
     if (gtk_tree_view_column_get_sort_indicator (column) == FALSE
-        && SORTING_FILE_MODE < SORTING_BY_ASCENDING_CREATION_DATE)
+        && SORTING_FILE_MODE < ET_SORT_MODE_ASCENDING_CREATION_DATE)
     {
         if (et_browser_get_sort_order_for_column_id (self, SORTING_FILE_MODE / 2) == GTK_SORT_DESCENDING)
         {
@@ -3957,7 +3957,7 @@ et_browser_set_sorting_file_mode (GtkTreeViewColumn *column, gpointer data)
         gtk_tree_view_column_set_sort_order (column, GTK_SORT_ASCENDING);
     }
 
-    if (SORTING_FILE_MODE > SORTING_BY_DESCENDING_ENCODED_BY)
+    if (SORTING_FILE_MODE > ET_SORT_MODE_DESCENDING_ENCODED_BY)
     {
         gtk_tree_view_column_set_sort_indicator (column, TRUE);
         gtk_tree_view_column_set_sort_order (column, GTK_SORT_ASCENDING);
diff --git a/src/et_core.c b/src/et_core.c
index 8b12d97..3101b47 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -201,7 +201,7 @@ static gchar *ET_File_Name_Format_Extension (ET_File *ETFile);
 
 static void set_sort_order_for_column_id (gint column_id,
                                           GtkTreeViewColumn *column,
-                                          ET_Sorting_Type sort_type);
+                                          EtSortMode sort_type);
 
 
 /*******************
@@ -992,14 +992,16 @@ 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)
 {
     EtApplicationWindow *window;
     GtkTreeViewColumn *column;
@@ -1013,142 +1015,142 @@ GList *ET_Sort_File_List (GList *ETFileList, ET_Sorting_Type Sorting_Type)
     /* Important to rewind before. */
     etfilelist = g_list_first (ETFileList);
 
+    /* FIXME: Port to sort-mode? */
     set_sort_order_for_column_id (column_id, column, Sorting_Type);
 
-    // Sort...
+    /* 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_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_DISC_NUMBER:
+        case ET_SORT_MODE_ASCENDING_DISC_NUMBER:
             etfilelist = g_list_sort (etfilelist,
                                       (GCompareFunc)et_comp_func_sort_file_by_ascending_disc_number);
             break;
-        case SORTING_BY_DESCENDING_DISC_NUMBER:
+        case ET_SORT_MODE_DESCENDING_DISC_NUMBER:
             etfilelist = g_list_sort (etfilelist,
                                       (GCompareFunc)et_comp_func_sort_file_by_descending_disc_number);
             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_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_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_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;
     }
@@ -1163,7 +1165,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);
 
@@ -2170,8 +2173,9 @@ gboolean ET_Set_Displayed_File_List (GList *ETFileList)
         ETCore->ETFileDisplayedList_TotalDuration += ((ET_File_Info *)((ET_File 
*)l->data)->ETFileInfo)->duration;
     }
 
-    // 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 (MainSettings,
+                                 "sort-mode"));
 
     // Should renums ETCore->ETFileDisplayedList only!
     ET_Displayed_File_List_Number();
@@ -5058,7 +5062,7 @@ ET_Get_Number_Of_Files_In_Directory (const gchar *path_utf8)
  */
 static void
 set_sort_order_for_column_id (gint column_id, GtkTreeViewColumn *column,
-                              ET_Sorting_Type sort_type)
+                              EtSortMode sort_type)
 {
     EtApplicationWindow *window;
 
@@ -5066,13 +5070,13 @@ set_sort_order_for_column_id (gint column_id, GtkTreeViewColumn *column,
 
     /* Removing the sort indicator for the currently selected treeview
      * column. */
-    if (SORTING_FILE_MODE < SORTING_BY_ASCENDING_CREATION_DATE)
+    if (SORTING_FILE_MODE < ET_SORT_MODE_ASCENDING_CREATION_DATE)
     {
         gtk_tree_view_column_set_sort_indicator (et_application_window_browser_get_column_for_column_id 
(window, SORTING_FILE_MODE / 2),
                                                  FALSE);
     }
 
-    if (sort_type < SORTING_BY_ASCENDING_CREATION_DATE)
+    if (sort_type < ET_SORT_MODE_ASCENDING_CREATION_DATE)
     {
         gtk_tree_view_column_clicked (et_application_window_browser_get_column_for_column_id (window, 
column_id));
 
diff --git a/src/et_core.h b/src/et_core.h
index 5476550..8e5bd23 100644
--- a/src/et_core.h
+++ b/src/et_core.h
@@ -1,31 +1,31 @@
-/* et_core.h - 2001/10/21 */
-/*
- *  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.
  */
 
+#ifndef ET_CORE_H_
+#define ET_CORE_H_
 
-#ifndef __ET_CORE_H__
-#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, ...
 
 G_BEGIN_DECLS
 
@@ -40,58 +40,6 @@ extern GdkColor LIGHT_GREY;
 extern GdkColor YELLOW;
 extern 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_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_DISC_NUMBER,
-    SORTING_BY_DESCENDING_DISC_NUMBER,
-    SORTING_BY_ASCENDING_TRACK_NUMBER,
-    SORTING_BY_DESCENDING_TRACK_NUMBER,
-    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_CREATION_DATE,
-    SORTING_BY_DESCENDING_CREATION_DATE,
-    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
  */
@@ -364,8 +312,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);
@@ -414,4 +362,4 @@ gint ET_Comp_Func_Sort_File_By_Descending_File_Samplerate (ET_File *ETFile1, ET_
 
 G_END_DECLS
 
-#endif /* __ET_CORE_H__ */
+#endif /* ET_CORE_H_ */
diff --git a/src/preferences_dialog.c b/src/preferences_dialog.c
index 2e7f3b9..169bbf5 100644
--- a/src/preferences_dialog.c
+++ b/src/preferences_dialog.c
@@ -37,6 +37,7 @@
 #include "misc.h"
 #include "scan_dialog.h"
 #include "easytag.h"
+#include "enums.h"
 #include "browser.h"
 #include "cddb_dialog.h"
 #include "charset.h"
@@ -406,7 +407,10 @@ create_preferences_dialog (EtPreferencesDialog *self)
     gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (SortingFileCombo),
                                     _("Descending creation date"));
 
-    gtk_combo_box_set_active(GTK_COMBO_BOX(SortingFileCombo), SORTING_FILE_MODE);
+    g_settings_bind_with_mapping (MainSettings, "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."));
diff --git a/src/setting.c b/src/setting.c
index 5415d7a..fbed0d9 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -105,7 +105,7 @@ static void Save_Config_To_File (void);
 static gboolean Create_Easytag_Directory (void);
 static void set_sorting_indicator_for_column_id (EtApplicationWindow *self,
                                                  gint column_id,
-                                                 ET_Sorting_Type temp_sort,
+                                                 EtSortMode temp_sort,
                                                  GtkTreeViewColumn *column);
 
 
@@ -119,7 +119,6 @@ static const tConfigVariable Config_Variables[] =
 
     {"pad_disc_number", CV_TYPE_BOOL, &PAD_DISC_NUMBER },
     {"pad_disc_number_digits", CV_TYPE_INT, &PAD_DISC_NUMBER_DIGITS },
-    {"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       
     },
@@ -232,7 +231,6 @@ void Init_Config_Variables (void)
      */
     PAD_DISC_NUMBER = 1;
     PAD_DISC_NUMBER_DIGITS = 1;
-    SORTING_FILE_MODE                       = SORTING_BY_ASCENDING_FILENAME;
 #ifdef G_OS_WIN32
     SORTING_FILE_CASE_SENSITIVE             = 1;
 #else /* !G_OS_WIN32 */
@@ -368,7 +366,7 @@ Apply_Changes_Of_Preferences_Window (void)
     GtkWidget *dialog;
     gchar *temp;
     int active;
-    ET_Sorting_Type temp_sort;
+    EtSortMode temp_sort;
     gint column_id;
     GtkTreeViewColumn * column;
 
@@ -392,19 +390,25 @@ Apply_Changes_Of_Preferences_Window (void)
 
         temp_sort = gtk_combo_box_get_active (GTK_COMBO_BOX (SortingFileCombo));
         column_id = temp_sort / 2;
-        if (SORTING_FILE_MODE < SORTING_BY_ASCENDING_CREATION_DATE)
+        /* FIXME: Port to GSettings? */
+        /* Is this needed any more? */
+#if 0
+        if (g_settings_get_enum (MainSettings, "sort-mode")
+            < ET_SORT_MODE_ASCENDING_CREATION_DATE)
         {
-            gtk_tree_view_column_set_sort_indicator (et_application_window_browser_get_column_for_column_id 
(window, SORTING_FILE_MODE / 2),
+            gtk_tree_view_column_set_sort_indicator (et_application_window_browser_get_column_for_column_id 
(window, g_settings_get_enum (MainSettings, "sort-mode") / 2),
                                                      FALSE);
         }
-        if (temp_sort < SORTING_BY_ASCENDING_CREATION_DATE)
+        if (temp_sort < ET_SORT_MODE_ASCENDING_CREATION_DATE)
         {
             column = et_application_window_browser_get_column_for_column_id (window, column_id);
             set_sorting_indicator_for_column_id (window, column_id, temp_sort,
                                                  column);
         }
-        SORTING_FILE_MODE = temp_sort;
+
+        g_settings_set_enum (MainSettings, "sort-mode", temp_sort);
         et_application_window_browser_refresh_sort (ET_APPLICATION_WINDOW (MainWindow));
+#endif
 
         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)))));
@@ -1264,7 +1268,7 @@ Create_Easytag_Directory (void)
 static void
 set_sorting_indicator_for_column_id (EtApplicationWindow *window,
                                      gint column_id,
-                                     ET_Sorting_Type temp_sort,
+                                     EtSortMode temp_sort,
                                      GtkTreeViewColumn *column)
 {
     GtkSortType current_sort;
@@ -1282,3 +1286,79 @@ set_sorting_indicator_for_column_id (EtApplicationWindow *window,
         gtk_tree_view_column_clicked (column);
     }
 }
+
+/*
+ * 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 eeba9ea..7cb5423 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -1,26 +1,25 @@
-/* config.h - 2000/06/21 */
-/*
- *  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.
  */
 
 
-#ifndef __CONFIG_H__
-#define __CONFIG_H__
+#ifndef ET_SETTINGS_H_
+#define ET_SETTINGS_H_
 
 #include <gtk/gtk.h>
 
@@ -45,6 +44,53 @@ 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_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_DISC_NUMBER,
+    ET_SORT_MODE_DESCENDING_DISC_NUMBER,
+    ET_SORT_MODE_ASCENDING_TRACK_NUMBER,
+    ET_SORT_MODE_DESCENDING_TRACK_NUMBER,
+    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_CREATION_DATE,
+    ET_SORT_MODE_DESCENDING_CREATION_DATE,
+    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
  */
@@ -231,6 +277,10 @@ 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__ */
+#endif /* ET_SETTINGS_H_ */


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