[easytag/wip/application-window: 37/42] Store default browse path in GSettings WIP



commit fae2f6ad4dd86adbcc02b442d9607152c0ae279b
Author: David King <amigadave amigadave com>
Date:   Fri May 9 22:43:47 2014 +0100

    Store default browse path in GSettings WIP
    
    Still TODO: checking for a valid path. Consolidating validity checks
    into one place.

 data/org.gnome.EasyTAG.gschema.xml |    4 +-
 src/application_window.c           |    1 -
 src/browser.c                      |   35 +++++---------
 src/preferences_dialog.c           |   89 +++++++++++++++++++----------------
 src/preferences_dialog.h           |    1 -
 src/setting.c                      |   52 ++++++++------------
 src/setting.h                      |    7 ---
 7 files changed, 84 insertions(+), 105 deletions(-)
---
diff --git a/data/org.gnome.EasyTAG.gschema.xml b/data/org.gnome.EasyTAG.gschema.xml
index d4f530e..f31d873 100644
--- a/data/org.gnome.EasyTAG.gschema.xml
+++ b/data/org.gnome.EasyTAG.gschema.xml
@@ -9,10 +9,10 @@
       <default>true</default>
     </key>
 
-    <key name="default-path" type="s">
+    <key name="default-path" type="ay">
       <summary>Default path</summary>
       <description>The default path to search for music files</description>
-      <default>''</default>
+      <default>b''</default>
     </key>
 
     <key name="browse-subdir" type="b">
diff --git a/src/application_window.c b/src/application_window.c
index 89e7f56..0267d1e 100644
--- a/src/application_window.c
+++ b/src/application_window.c
@@ -1012,7 +1012,6 @@ create_browser_area (EtApplicationWindow *self)
 
     /* Don't load init dir here because Tag area hasn't been yet created!.
      * It will be load at the end of the main function */
-    //Browser_Tree_Select_Dir(DEFAULT_PATH_TO_MP3);
 
     return frame;
 }
diff --git a/src/browser.c b/src/browser.c
index 7df88ff..01c7ff9 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -319,29 +319,18 @@ void
 et_browser_load_default_dir (EtBrowser *self)
 {
     GFile **files;
-    gchar *path_utf8;
-    gchar *path;
+    GVariant *default_path;
+    const gchar *path;
 
-    path_utf8 = g_strdup(DEFAULT_PATH_TO_MP3);
-    if (!path_utf8 || strlen(path_utf8)<=0)
-    {
-        g_free(path_utf8);
-        path_utf8 = g_strdup (g_get_home_dir ());
-    }
-
-    /* FIXME: only in UTF-8 if coming from the config file, when it should be
-     * in GLib filename encoding in all cases. */
-    /* 'DEFAULT_PATH_TO_MP3' is stored in UTF-8, we must convert it to the file
-     * system encoding before... */
-    path = filename_from_display(path_utf8);
+    default_path = g_settings_get_value (MainSettings, "default-path");
+    path = g_variant_get_bytestring (default_path);
 
     files = g_new (GFile *, 1);
     files[0] = g_file_new_for_path (path);
     g_application_open (g_application_get_default (), files, 1, "");
 
     g_object_unref (files[0]);
-    g_free(path);
-    g_free(path_utf8);
+    g_variant_unref (default_path);
     g_free (files);
 }
 
@@ -567,12 +556,9 @@ et_browser_set_current_path_default (EtBrowser *self)
 
     priv = et_browser_get_instance_private (self);
 
-    if (DEFAULT_PATH_TO_MP3 != NULL)
-    {
-        g_free (DEFAULT_PATH_TO_MP3);
-    }
+    g_settings_set_value (MainSettings, "default-path",
+                          g_variant_new_bytestring (priv->current_path));
 
-    DEFAULT_PATH_TO_MP3 = g_strdup (priv->current_path);
     Statusbar_Message (_("New default path for files selected"),TRUE);
 }
 
@@ -2992,7 +2978,12 @@ et_browser_reload (EtBrowser *self)
         else if (g_utf8_strlen(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(priv->entry_combo)))), 
-1) > 0)
             current_path = 
filename_from_display(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(priv->entry_combo)))));
         else
-            current_path = g_strdup(DEFAULT_PATH_TO_MP3);
+        {
+            GVariant *path = g_settings_get_value (MainSettings,
+                                                   "default-path");
+            current_path = g_variant_dup_bytestring (path, NULL);
+            g_variant_unref (path);
+        }
     }
 
     Browser_Tree_Initialize (self);
diff --git a/src/preferences_dialog.c b/src/preferences_dialog.c
index 1de0679..7efcc63 100644
--- a/src/preferences_dialog.c
+++ b/src/preferences_dialog.c
@@ -102,15 +102,37 @@ static void et_preferences_on_response (GtkDialog *dialog, gint response_id,
  * Functions *
  *************/
 static void
-DefaultPathToMp3_Combo_Add_String (EtPreferencesDialog *self)
+et_prefs_current_folder_changed (EtPreferencesDialog *self,
+                                 GtkFileChooser *default_path_button)
 {
-    EtPreferencesDialogPrivate *priv;
+    gchar *path;
+
+    /* The path that is currently selected, not that which is currently being
+     * displayed. */
+    path = gtk_file_chooser_get_filename (default_path_button);
+
+    if (path)
+    {
+        g_settings_set_value (MainSettings, "default-path",
+                              g_variant_new_bytestring (path));
+        g_free (path);
+    }
+}
+
+static void
+on_default_path_changed (GSettings *settings,
+                         const gchar *key,
+                         GtkFileChooserButton *default_path_button)
+{
+    GVariant *default_path;
     const gchar *path;
 
-    priv = et_preferences_dialog_get_instance_private (self);
+    default_path = g_settings_get_value (settings, "default-path");
+    path = g_variant_get_bytestring (default_path);
 
-    path = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(DefaultPathToMp3))));
-    Add_String_To_Combo_List(GTK_LIST_STORE(priv->default_path_model), path);
+    gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (default_path_button),
+                                         path);
+    g_variant_unref (default_path);
 }
 
 static gboolean
@@ -220,7 +242,7 @@ create_preferences_dialog (EtPreferencesDialog *self)
     GtkWidget *FilenameExtensionNoChange;
     GtkWidget *FilenameExtensionLowerCase;
     GtkWidget *FilenameExtensionUpperCase;
-    gchar *path_utf8;
+    GtkWidget *default_path_button;
     gchar *program_path;
     gchar *default_comment;
 
@@ -266,41 +288,27 @@ create_preferences_dialog (EtPreferencesDialog *self)
     HBox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BOX_SPACING);
     gtk_box_pack_start(GTK_BOX(vbox),HBox,FALSE,FALSE,0);
 
-    // Label
+    /* Label. */
     Label = gtk_label_new(_("Default directory:"));
     gtk_box_pack_start(GTK_BOX(HBox),Label,FALSE,FALSE,0);
 
-    /* Combo. */
-    priv->default_path_model = gtk_list_store_new (MISC_COMBO_COUNT,
-                                                   G_TYPE_STRING);
-
-    DefaultPathToMp3 = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(priv->default_path_model));
-    g_object_unref (priv->default_path_model);
-    gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(DefaultPathToMp3), MISC_COMBO_TEXT);
-    gtk_box_pack_start(GTK_BOX(HBox),DefaultPathToMp3,TRUE,TRUE,0);
-    gtk_widget_set_size_request(DefaultPathToMp3, 400, -1);
-    gtk_widget_set_tooltip_text(gtk_bin_get_child(GTK_BIN(DefaultPathToMp3)),_("Specify the directory where "
-        "your files are located. This path will be loaded when EasyTAG starts without parameter."));
-    g_signal_connect_swapped (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (DefaultPathToMp3))),
-                              "activate",
-                              G_CALLBACK (DefaultPathToMp3_Combo_Add_String),
+    default_path_button = gtk_file_chooser_button_new (_("Default Browser Path"),
+                                                       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+    on_default_path_changed (MainSettings, "changed::default-path",
+                             GTK_FILE_CHOOSER_BUTTON (default_path_button));
+    g_signal_connect_swapped (default_path_button, "current-folder-changed",
+                              G_CALLBACK (et_prefs_current_folder_changed),
                               self);
-    
//g_signal_connect(G_OBJECT(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(DefaultPathToMp3)))),"focus_out_event",G_CALLBACK(DefaultPathToMp3_Combo_Add_String),NULL);
-
-    // History list
-    Load_Default_Path_To_MP3_List(priv->default_path_model, MISC_COMBO_TEXT);
-    // If default path hasn't been added already, add it now..
-    path_utf8 = filename_to_display(DEFAULT_PATH_TO_MP3);
-    Add_String_To_Combo_List(priv->default_path_model, path_utf8);
-    if (path_utf8)
-        gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(DefaultPathToMp3))), path_utf8);
-    g_free(path_utf8);
-
-    // Button browse
-    Button = gtk_button_new_from_stock(GTK_STOCK_OPEN);
-    gtk_box_pack_start(GTK_BOX(HBox),Button,FALSE,FALSE,0);
-    g_signal_connect_swapped(G_OBJECT(Button),"clicked",
-                             
G_CALLBACK(File_Selection_Window_For_Directory),G_OBJECT(gtk_bin_get_child(GTK_BIN(DefaultPathToMp3))));
+    g_signal_connect (MainSettings, "changed::default-path",
+                      G_CALLBACK (on_default_path_changed),
+                      default_path_button);
+    gtk_box_pack_start (GTK_BOX (HBox), default_path_button, TRUE, TRUE, 0);
+    gtk_file_chooser_button_set_width_chars (GTK_FILE_CHOOSER_BUTTON (default_path_button),
+                                             30);
+    gtk_widget_set_tooltip_text (default_path_button,
+                                 _("Specify the directory where your files are"
+                                 " located. This path will be loaded when"
+                                 " EasyTAG starts without parameter."));
 
     /* Load directory on startup */
     LoadOnStartup = gtk_check_button_new_with_label(_("Load on startup the default directory or the 
directory passed as argument"));
@@ -1507,7 +1515,7 @@ create_preferences_dialog (EtPreferencesDialog *self)
     // If default path hasn't been added already, add it now..
     if (CDDB_LOCAL_PATH)
     {
-        path_utf8 = filename_to_display(CDDB_LOCAL_PATH);
+        gchar *path_utf8 = filename_to_display (CDDB_LOCAL_PATH);
         Add_String_To_Combo_List(priv->cddb_local_path_model, path_utf8);
         if (path_utf8)
             gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(CddbLocalPath))), path_utf8);
@@ -1803,7 +1811,8 @@ Check_DefaultPathToMp3 (EtPreferencesDialog *self)
     GFileInfo *fileinfo;
     GtkWidget *msgdialog;
 
-    path_utf8 = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(DefaultPathToMp3)))));
+    /* FIXME! */
+    path_utf8 = NULL;
     if (!path_utf8 || g_utf8_strlen(path_utf8, -1) < 1)
     {
         g_free(path_utf8);
@@ -1977,7 +1986,6 @@ OptionsWindow_Save_Button (EtPreferencesDialog *self)
 
 #ifndef G_OS_WIN32
     /* FIXME : make gtk crash on win32 */
-    Add_String_To_Combo_List(priv->default_path_model,      
gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(DefaultPathToMp3)))));
     Add_String_To_Combo_List(priv->file_player_model,       
gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(FilePlayerCombo)))));
     Add_String_To_Combo_List(priv->cddb_local_path_model,    
gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(CddbLocalPath)))));
 #endif /* !G_OS_WIN32 */
@@ -2009,7 +2017,6 @@ et_preferences_dialog_apply_changes (EtPreferencesDialog *self)
     priv = et_preferences_dialog_get_instance_private (self);
 
     /* Save combobox history lists before exit */
-    Save_Default_Path_To_MP3_List (priv->default_path_model, MISC_COMBO_TEXT);
     Save_Default_Tag_Comment_Text_List (priv->default_comment_model,
                                         MISC_COMBO_TEXT);
     Save_Audio_File_Player_List (priv->file_player_model, MISC_COMBO_TEXT);
diff --git a/src/preferences_dialog.h b/src/preferences_dialog.h
index f6494e1..4ef9e0b 100644
--- a/src/preferences_dialog.h
+++ b/src/preferences_dialog.h
@@ -55,7 +55,6 @@ G_END_DECLS
 /* FIXME: Remove widget declarations when switching to GSettings. */
 /* Widgets included in config */
 /* Common */
-GtkWidget *DefaultPathToMp3;
 GtkWidget *BrowseHiddendir;
 
 /* Misc */
diff --git a/src/setting.c b/src/setting.c
index 796a98a..1bffd89 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -72,8 +72,6 @@ static const gchar RENAME_DIRECTORY_MASKS_FILE[] = "rename_directory.mask";
 static const gchar PLAY_LIST_NAME_MASKS_FILE[] = "play_list_name.mask";
 // File for history of PlayListContentMaskEntry combobox
 static const gchar PLAYLIST_CONTENT_MASKS_FILE[] = "playlist_content.mask";
-// File for history of DefaultPathToMp3 combobox
-static const gchar DEFAULT_PATH_TO_MP3_HISTORY_FILE[] = "default_path_to_mp3.history";
 // File for history of DefaultComment combobox
 static const gchar DEFAULT_TAG_COMMENT_HISTORY_FILE[] = "default_tag_comment.history";
 // File for history of BrowserEntry combobox
@@ -115,8 +113,6 @@ static void set_sorting_indicator_for_column_id (EtApplicationWindow *self,
  ********************/
 static const tConfigVariable Config_Variables[] =
 {
-    {"default_path_to_mp3",                 CV_TYPE_STRING,  &DEFAULT_PATH_TO_MP3               },
-
     {"sorting_file_case_sensitive",          CV_TYPE_BOOL,    &SORTING_FILE_CASE_SENSITIVE              },
 
     {"file_reading_id3v1v2_character_set",             CV_TYPE_STRING,&FILE_READING_ID3V1V2_CHARACTER_SET},
@@ -178,21 +174,37 @@ static const tConfigVariable Config_Variables[] =
  * Functions *
  *************/
 
+static void
+check_default_path (void)
+{
+    GVariant *default_path;
+    const gchar *path;
+
+    default_path = g_settings_get_value (MainSettings, "default-path");
+    path = g_variant_get_bytestring (default_path);
+
+    if (!*path)
+    {
+        path = g_get_user_special_dir (G_USER_DIRECTORY_MUSIC);
+        g_settings_set_value (MainSettings, "default-path",
+                              g_variant_new_bytestring (path ? path
+                                                             : g_get_home_dir ()));
+    }
+
+    g_variant_unref (default_path);
+}
+
 /*
  * Define and Load default values into config variables
  */
 void Init_Config_Variables (void)
 {
-    const gchar *music_dir;
-
     MainSettings = g_settings_new ("org.gnome.EasyTAG");
 
     /*
      * Common
      */
-    music_dir = g_get_user_special_dir (G_USER_DIRECTORY_MUSIC);
-    DEFAULT_PATH_TO_MP3 = music_dir ? g_strdup (music_dir)
-                                    : g_strdup (g_get_home_dir ());
+    check_default_path ();
 
     /*
      * Misc
@@ -302,14 +314,6 @@ Apply_Changes_Of_Preferences_Window (void)
 
     if (dialog)
     {
-        /* Common */
-        if (DEFAULT_PATH_TO_MP3) g_free(DEFAULT_PATH_TO_MP3);
-        DEFAULT_PATH_TO_MP3           = 
g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(DefaultPathToMp3))))); // Saved in UTF-8
-#if 0
-#ifdef G_OS_WIN32
-        ET_Win32_Path_Replace_Backslashes(DEFAULT_PATH_TO_MP3);
-#endif /* G_OS_WIN32 */
-#endif
         /* Misc */
         SORTING_FILE_CASE_SENSITIVE            = 
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(SortingFileCaseSensitive));
 
@@ -683,7 +687,6 @@ gboolean Setting_Create_Files (void)
     check_or_create_file (SCAN_TAG_MASKS_FILE);
     check_or_create_file (RENAME_FILE_MASKS_FILE);
     check_or_create_file (RENAME_DIRECTORY_MASKS_FILE);
-    check_or_create_file (DEFAULT_PATH_TO_MP3_HISTORY_FILE);
     check_or_create_file (DEFAULT_TAG_COMMENT_HISTORY_FILE);
     check_or_create_file (PATH_ENTRY_HISTORY_FILE);
     check_or_create_file (PLAY_LIST_NAME_MASKS_FILE);
@@ -896,18 +899,6 @@ void Save_Rename_Directory_Masks_List (GtkListStore *liststore, gint colnum)
 
 
 /*
- * Functions for writing and reading list of 'DefaultPathToMp3' combobox
- */
-void Load_Default_Path_To_MP3_List (GtkListStore *liststore, gint colnum)
-{
-    Populate_List_Store_From_File(DEFAULT_PATH_TO_MP3_HISTORY_FILE, liststore, colnum);
-}
-void Save_Default_Path_To_MP3_List (GtkListStore *liststore, gint colnum)
-{
-    Save_List_Store_To_File(DEFAULT_PATH_TO_MP3_HISTORY_FILE, liststore, colnum);
-}
-
-/*
  * Functions for writing and reading list of 'DefaultComment' combobox
  */
 void Load_Default_Tag_Comment_Text_List (GtkListStore *liststore, gint colnum)
@@ -1071,7 +1062,6 @@ migrate_config_file_dir (const gchar *old_path, const gchar *new_path)
                                         SCAN_TAG_MASKS_FILE,
                                         RENAME_FILE_MASKS_FILE,
                                         RENAME_DIRECTORY_MASKS_FILE,
-                                        DEFAULT_PATH_TO_MP3_HISTORY_FILE,
                                         DEFAULT_TAG_COMMENT_HISTORY_FILE,
                                         PATH_ENTRY_HISTORY_FILE,
                                         PLAY_LIST_NAME_MASKS_FILE,
diff --git a/src/setting.h b/src/setting.h
index b486dfa..24fe5a2 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -154,9 +154,6 @@ typedef enum
 
 GSettings *MainSettings;
 
-/* Common */
-gchar  *DEFAULT_PATH_TO_MP3;
-
 /* Misc */
 gint    SORTING_FILE_MODE;
 gint    SORTING_FILE_CASE_SENSITIVE;
@@ -247,10 +244,6 @@ void Save_Rename_File_Masks_List (GtkListStore *liststore, gint colnum);
 void Load_Rename_Directory_Masks_List (GtkListStore *liststore, gint colnum, gchar **fallback);
 void Save_Rename_Directory_Masks_List (GtkListStore *liststore, gint colnum);
 
-/* 'DefaultPathToMp3' combobox */
-void Load_Default_Path_To_MP3_List (GtkListStore *liststore, gint colnum);
-void Save_Default_Path_To_MP3_List (GtkListStore *liststore, gint colnum);
-
 /* 'DefaultComment' combobox */
 void Load_Default_Tag_Comment_Text_List (GtkListStore *liststore, gint colnum);
 void Save_Default_Tag_Comment_Text_List (GtkListStore *liststore, gint colnum);


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