[easytag/wip/gsettings: 26/29] Store the playlist content mode in GSettings



commit 9eb408af12f1a665983499c1e37afb0ef1921f1d
Author: David King <amigadave amigadave com>
Date:   Wed Mar 27 00:09:50 2013 +0000

    Store the playlist content mode in GSettings

 data/org.gnome.EasyTAG.gschema.xml |    2 -
 src/misc.c                         |  148 +++++++++++++++++++++++-------------
 src/misc.h                         |    3 -
 src/setting.c                      |    6 --
 src/setting.h                      |   13 +++-
 5 files changed, 106 insertions(+), 66 deletions(-)
---
diff --git a/data/org.gnome.EasyTAG.gschema.xml b/data/org.gnome.EasyTAG.gschema.xml
index a6c59f2..05e4821 100644
--- a/data/org.gnome.EasyTAG.gschema.xml
+++ b/data/org.gnome.EasyTAG.gschema.xml
@@ -688,7 +688,6 @@
       <default>false</default>
     </key>
 
-    <!-- TODO: Generate enums with glib-mkenums.
     <key name="playlist-content" enum="org.gnome.EasyTAG.EtPlaylistContent">
       <summary>Content of generated playlists</summary>
       <description>Write a plain list of files, include extended information
@@ -696,7 +695,6 @@
       mask</description>
       <default>'extended'</default>
     </key>
-    -->
 
     <key name="playlist-default-mask" type="s">
       <summary>Playlist default mask</summary>
diff --git a/src/misc.c b/src/misc.c
index 9ff17f1..8fc1fc7 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -53,6 +53,9 @@
  * Declaration *
  ***************/
 /* Playlist window defined in misc.h */
+static GtkWidget *playlist_content_filenames;
+static GtkWidget *playlist_content_extended;
+static GtkWidget *playlist_content_mask;
 
 /* Search file window. */
 static GtkWidget *SearchFileWindow = NULL;
@@ -1381,14 +1384,23 @@ void Open_Write_Playlist_Window (void)
     gtk_container_add(GTK_CONTAINER(Frame),vbox);
     gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
 
-    playlist_content_none = gtk_radio_button_new_with_label(NULL,_("Write only list of files"));
-    gtk_box_pack_start(GTK_BOX(vbox),playlist_content_none,FALSE,FALSE,0);
-
-    playlist_content_filename = gtk_radio_button_new_with_label_from_widget(
-        GTK_RADIO_BUTTON(playlist_content_none),_("Write info using filename"));
-    gtk_box_pack_start(GTK_BOX(vbox),playlist_content_filename,FALSE,FALSE,0);
-
-    playlist_content_mask = 
gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(playlist_content_none), _("Write info using:"));
+    playlist_content_filenames = gtk_radio_button_new_with_label (NULL,
+                                                                  _("Filenames only"));
+    gtk_widget_set_name (playlist_content_filenames, "filenames");
+    gtk_box_pack_start (GTK_BOX (vbox), playlist_content_filenames, FALSE,
+                        FALSE, 0);
+
+    playlist_content_extended = gtk_radio_button_new_with_label_from_widget(
+        GTK_RADIO_BUTTON (playlist_content_filenames),
+                         _("Filenames with extended information"));
+    gtk_widget_set_name (playlist_content_extended, "extended");
+    gtk_box_pack_start (GTK_BOX (vbox), playlist_content_extended, FALSE,
+                        FALSE, 0);
+
+    playlist_content_mask = gtk_radio_button_new_with_label_from_widget(
+        GTK_RADIO_BUTTON (playlist_content_filenames),
+                          _("Filenames and information mask:"));
+    gtk_widget_set_name (playlist_content_mask, "extended-mask");
     hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0);
     gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,0);
     gtk_box_pack_start(GTK_BOX(hbox),playlist_content_mask,FALSE,FALSE,0);
@@ -1421,10 +1433,24 @@ void Open_Write_Playlist_Window (void)
     // FIX ME : edit the masks
     gtk_widget_set_sensitive(GTK_WIDGET(Button),FALSE);
 
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(playlist_content_none),    PLAYLIST_CONTENT_NONE);
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(playlist_content_filename),PLAYLIST_CONTENT_FILENAME);
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(playlist_content_mask),    PLAYLIST_CONTENT_MASK);
-
+    g_settings_bind_with_mapping (ETSettings, "playlist-content",
+                                  playlist_content_filenames, "active",
+                                  G_SETTINGS_BIND_DEFAULT,
+                                  et_settings_enum_radio_get,
+                                  et_settings_enum_radio_set,
+                                  playlist_content_filenames, NULL);
+    g_settings_bind_with_mapping (ETSettings, "playlist-content",
+                                  playlist_content_extended, "active",
+                                  G_SETTINGS_BIND_DEFAULT,
+                                  et_settings_enum_radio_get,
+                                  et_settings_enum_radio_set,
+                                  playlist_content_extended, NULL);
+    g_settings_bind_with_mapping (ETSettings, "playlist-content",
+                                  playlist_content_mask, "active",
+                                  G_SETTINGS_BIND_DEFAULT,
+                                  et_settings_enum_radio_get,
+                                  et_settings_enum_radio_set,
+                                  playlist_content_mask, NULL);
 
     /* Separator line */
     Separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
@@ -1504,10 +1530,6 @@ void Write_Playlist_Window_Apply_Changes (void)
         if (PLAYLIST_NAME) g_free(PLAYLIST_NAME);
         PLAYLIST_NAME                 = 
g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(PlayListNameMaskCombo)))));
 
-        PLAYLIST_CONTENT_NONE         = 
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(playlist_content_none));
-        PLAYLIST_CONTENT_FILENAME     = 
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(playlist_content_filename));
-        PLAYLIST_CONTENT_MASK         = 
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(playlist_content_mask));
-        
         if (PLAYLIST_CONTENT_MASK_VALUE) g_free(PLAYLIST_CONTENT_MASK_VALUE);
         PLAYLIST_CONTENT_MASK_VALUE   = 
g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(PlayListContentMaskCombo)))));
 
@@ -1780,6 +1802,7 @@ Write_Playlist (const gchar *playlist_name)
     gchar *basedir;
     gchar *temp;
     gint   duration;
+    EtPlaylistContent playlist_content;
 
     if ((file = fopen(playlist_name,"wb")) == NULL)
     {
@@ -1793,8 +1816,9 @@ Write_Playlist (const gchar *playlist_name)
      */
     basedir = g_path_get_dirname(playlist_name);
 
+    playlist_content = g_settings_get_enum (ETSettings, "playlist-content");
     // 1) First line of the file (if playlist content is not set to "write only list of files")
-    if (!PLAYLIST_CONTENT_NONE)
+    if (playlist_content != ET_PLAYLIST_CONTENT_FILENAMES)
     {
         fprintf(file,"#EXTM3U\r\n");
     }
@@ -1820,6 +1844,7 @@ Write_Playlist (const gchar *playlist_name)
     {
         etfilelist = g_list_first(ETCore->ETFileList);
     }
+    /* TODO: Restructure to avid the duplicated code. */
     while (etfilelist)
     {
         etfile   = (ET_File *)etfilelist->data;
@@ -1832,25 +1857,34 @@ Write_Playlist (const gchar *playlist_name)
             if ( strncmp(filename,basedir,strlen(basedir))==0 )
             {
                 // 2) Write the header
-                if (PLAYLIST_CONTENT_NONE)
-                {
-                    // No header written
-                }else if (PLAYLIST_CONTENT_FILENAME)
-                {
-                    // Header uses only filename
-                    temp = g_path_get_basename(filename);
-                    fprintf(file,"#EXTINF:%d,%s\r\n",duration,temp); // Must be written in system encoding 
(not UTF-8)
-                    g_free(temp);
-                }else if (PLAYLIST_CONTENT_MASK)
+                switch (playlist_content)
                 {
-                    // Header uses generated filename from a mask
-                    gchar *mask = 
filename_from_display(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(PlayListContentMaskCombo)))));
-                    // Special case : we don't replace illegal characters and don't check if there is a 
directory separator in the mask.
-                    gchar *filename_generated_utf8 = Scan_Generate_New_Filename_From_Mask(etfile,mask,TRUE);
-                    gchar *filename_generated = filename_from_display(filename_generated_utf8);
-                    fprintf(file,"#EXTINF:%d,%s\r\n",duration,filename_generated); // Must be written in 
system encoding (not UTF-8)
-                    g_free(mask);
-                    g_free(filename_generated_utf8);
+                    case ET_PLAYLIST_CONTENT_FILENAMES:
+                        /* No header written. */
+                        break;
+                    case ET_PLAYLIST_CONTENT_EXTENDED:
+                        /* Header has extended information. */
+                        temp = g_path_get_basename (filename);
+                        /* Must be written in system encoding (not UTF-8). */
+                        fprintf (file, "#EXTINF:%d,%s\r\n", duration, temp);
+                        g_free (temp);
+                        break;
+                    case ET_PLAYLIST_CONTENT_EXTENDED_MASK:
+                    {
+                        /* Header uses information generated from a mask. */
+                        gchar *mask = filename_from_display (gtk_entry_get_text (GTK_ENTRY 
(gtk_bin_get_child (GTK_BIN (PlayListContentMaskCombo)))));
+                        /* Special case: do not replace illegal characters and
+                         * do not check if there is a directory separator in
+                         * the mask.
+                         */
+                        gchar *filename_generated_utf8 = Scan_Generate_New_Filename_From_Mask (etfile, mask, 
TRUE);
+                        gchar *filename_generated = filename_from_display (filename_generated_utf8);
+                        /* Must be written in system encoding (not UTF-8). */
+                        fprintf (file, "#EXTINF:%d,%s\r\n", duration,
+                                 filename_generated);
+                        g_free (mask);
+                        g_free (filename_generated_utf8);
+                    }
                 }
 
                 // 3) Write the file path
@@ -1869,24 +1903,34 @@ Write_Playlist (const gchar *playlist_name)
         } else /* !ETSettings:playlist-relative */
         {
             // 2) Write the header
-            if (PLAYLIST_CONTENT_NONE)
+            switch (playlist_content)
             {
-                // No header written
-            }else if (PLAYLIST_CONTENT_FILENAME)
-            {
-                // Header uses only filename
-                temp = g_path_get_basename(filename);
-                fprintf(file,"#EXTINF:%d,%s\r\n",duration,temp); // Must be written in system encoding (not 
UTF-8)
-                g_free(temp);
-            }else if (PLAYLIST_CONTENT_MASK)
-            {
-                // Header uses generated filename from a mask
-                gchar *mask = 
filename_from_display(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(PlayListContentMaskCombo)))));
-                gchar *filename_generated_utf8 = Scan_Generate_New_Filename_From_Mask(etfile,mask,TRUE);
-                gchar *filename_generated = filename_from_display(filename_generated_utf8);
-                fprintf(file,"#EXTINF:%d,%s\r\n",duration,filename_generated); // Must be written in system 
encoding (not UTF-8)
-                g_free(mask);
-                g_free(filename_generated_utf8);
+                case ET_PLAYLIST_CONTENT_FILENAMES:
+                    /* No header written. */
+                    break;
+                case ET_PLAYLIST_CONTENT_EXTENDED:
+                    /* Header has extended information. */
+                    temp = g_path_get_basename (filename);
+                    /* Must be written in system encoding (not UTF-8). */
+                    fprintf (file, "#EXTINF:%d,%s\r\n", duration, temp);
+                    g_free (temp);
+                    break;
+                case ET_PLAYLIST_CONTENT_EXTENDED_MASK:
+                {
+                    /* Header uses information generated from a mask. */
+                    gchar *mask = filename_from_display (gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child 
(GTK_BIN (PlayListContentMaskCombo)))));
+                    /* Special case: do not replace illegal characters and
+                     * do not check if there is a directory separator in
+                     * the mask.
+                     */
+                    gchar *filename_generated_utf8 = Scan_Generate_New_Filename_From_Mask (etfile, mask, 
TRUE);
+                    gchar *filename_generated = filename_from_display (filename_generated_utf8);
+                    /* Must be written in system encoding (not UTF-8). */
+                    fprintf (file, "#EXTINF:%d,%s\r\n", duration,
+                             filename_generated);
+                    g_free (mask);
+                    g_free (filename_generated_utf8);
+                }
             }
 
             // 3) Write the file path
diff --git a/src/misc.h b/src/misc.h
index b74140c..2f7044f 100644
--- a/src/misc.h
+++ b/src/misc.h
@@ -37,9 +37,6 @@ GtkWidget *playlist_full_path;
 GtkWidget *playlist_relative_path;
 GtkWidget *playlist_create_in_parent_dir;
 GtkWidget *playlist_use_dos_separator;
-GtkWidget *playlist_content_none;
-GtkWidget *playlist_content_filename;
-GtkWidget *playlist_content_mask;
 GtkWidget *PlayListContentMaskCombo;
 GtkListStore *PlayListNameMaskModel;
 GtkListStore *PlayListContentMaskModel;
diff --git a/src/setting.c b/src/setting.c
index 66024f6..65c02e2 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -153,9 +153,6 @@ tConfigVariable Config_Variables[] =
     {"pf_convert_space",                        CV_TYPE_BOOL,    &PF_CONVERT_SPACE                       },
 
     {"playlist_name",                           CV_TYPE_STRING,  &PLAYLIST_NAME                          },
-    {"playlist_content_none",                   CV_TYPE_BOOL,    &PLAYLIST_CONTENT_NONE                  },
-    {"playlist_content_filename",               CV_TYPE_BOOL,    &PLAYLIST_CONTENT_FILENAME              },
-    {"playlist_content_mask",                   CV_TYPE_BOOL,    &PLAYLIST_CONTENT_MASK                  },
     {"playlist_content_mask_value",             CV_TYPE_STRING,  &PLAYLIST_CONTENT_MASK_VALUE            },
 
     {"cddb_local_path",                         CV_TYPE_STRING,  &CDDB_LOCAL_PATH                        },
@@ -290,9 +287,6 @@ void Init_Config_Variables (void)
      * Playlist window
      */
     PLAYLIST_NAME                   = g_strdup("playlist_%a_-_%b");
-    PLAYLIST_CONTENT_NONE           = 0;
-    PLAYLIST_CONTENT_FILENAME       = 1;
-    PLAYLIST_CONTENT_MASK           = 0;
     PLAYLIST_CONTENT_MASK_VALUE     = g_strdup("%n/%l - %a - %b - %t");
 
     /*
diff --git a/src/setting.h b/src/setting.h
index 88a7b83..55b96e9 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -52,6 +52,16 @@ typedef enum
 } EtFilenameExtensionMode;
 
 /*
+ * Content of generated playlists.
+ */
+typedef enum
+{
+    ET_PLAYLIST_CONTENT_FILENAMES,
+    ET_PLAYLIST_CONTENT_EXTENDED,
+    ET_PLAYLIST_CONTENT_EXTENDED_MASK
+} EtPlaylistContent;
+
+/*
  * The mode for the scanner window. See the GSettings key "scanner-type".
  */
 typedef enum
@@ -168,9 +178,6 @@ gint    PF_CONVERT_SPACE;
 
 /* Playlist window */
 gchar  *PLAYLIST_NAME;
-gint    PLAYLIST_CONTENT_NONE;
-gint    PLAYLIST_CONTENT_FILENAME;
-gint    PLAYLIST_CONTENT_MASK;
 gchar  *PLAYLIST_CONTENT_MASK_VALUE;
 
 /* CDDB in preferences window */


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