[easytag/wip/application-window: 29/79] Store default browse path in GSettings
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/application-window: 29/79] Store default browse path in GSettings
- Date: Wed, 6 Aug 2014 06:35:13 +0000 (UTC)
commit c897617ebdcbde2a8598c7f03abe269d729c5e75
Author: David King <amigadave amigadave com>
Date: Fri May 9 22:43:47 2014 +0100
Store default browse path in GSettings
src/application_window.c | 1 -
src/browser.c | 35 ++++-------
src/preferences_dialog.c | 146 +++++++++++++++++++++++++---------------------
src/preferences_dialog.h | 1 -
src/setting.c | 51 +++++++----------
src/setting.h | 7 --
6 files changed, 113 insertions(+), 128 deletions(-)
---
diff --git a/src/application_window.c b/src/application_window.c
index d6f0751..71f8fe0 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 b54e32c..962c197 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -320,29 +320,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);
}
@@ -2993,7 +2979,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);
+ }
}
/* Select again the memorized path without loading files */
diff --git a/src/preferences_dialog.c b/src/preferences_dialog.c
index d45bde1..76f3bad 100644
--- a/src/preferences_dialog.c
+++ b/src/preferences_dialog.c
@@ -101,15 +101,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
@@ -218,7 +240,7 @@ create_preferences_dialog (EtPreferencesDialog *self)
GtkWidget *FilenameExtensionNoChange;
GtkWidget *FilenameExtensionLowerCase;
GtkWidget *FilenameExtensionUpperCase;
- gchar *path_utf8;
+ GtkWidget *default_path_button;
gchar *program_path;
priv = et_preferences_dialog_get_instance_private (self);
@@ -263,41 +285,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"));
@@ -1417,7 +1425,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);
@@ -1693,7 +1701,6 @@ OptionsWindow_Quit (EtPreferencesDialog *self)
/*
* Check_Config: Check if config information are correct
- * dsd: Check this... going from utf8 to raw is dodgy stuff
*
* Problem noted : if a character is escaped (like : 'C\351line DION') in
* gtk_file_chooser it will converted to UTF-8. So after, there
@@ -1707,54 +1714,61 @@ OptionsWindow_Quit (EtPreferencesDialog *self)
static gboolean
Check_DefaultPathToMp3 (EtPreferencesDialog *self)
{
- gchar *path_utf8;
- gchar *path_real;
+ GVariant *default_path;
+ const gchar *path_real;
GFile *file;
GFileInfo *fileinfo;
- GtkWidget *msgdialog;
- path_utf8 = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(DefaultPathToMp3)))));
- if (!path_utf8 || g_utf8_strlen(path_utf8, -1) < 1)
+ default_path = g_settings_get_value (MainSettings, "default-path");
+ path_real = g_variant_get_bytestring (default_path);
+
+ if (!*path_real)
{
- g_free(path_utf8);
+ g_variant_unref (default_path);
return TRUE;
}
- path_real = filename_from_display (path_utf8);
file = g_file_new_for_path (path_real);
- fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE,
+ fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE ","
+ G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
G_FILE_QUERY_INFO_NONE, NULL, NULL);
+ g_variant_unref (default_path);
g_object_unref (file);
if (fileinfo)
{
if (g_file_info_get_file_type (fileinfo) == G_FILE_TYPE_DIRECTORY)
{
- g_free (path_real);
- g_free (path_utf8);
g_object_unref (fileinfo);
return TRUE; /* Path is good */
}
+ else
+ {
+ GtkWidget *msgdialog;
+ const gchar *path_utf8;
+
+ path_utf8 = g_file_info_get_display_name (fileinfo);
+ msgdialog = gtk_message_dialog_new (GTK_WINDOW (self),
+ GTK_DIALOG_MODAL
+ | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "%s",
+ _("The selected path for 'Default path to files' is
invalid"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (msgdialog),
+ _("Path: '%s'\nError: %s"),
+ path_utf8,
+ g_strerror (errno));
+ gtk_window_set_title (GTK_WINDOW (msgdialog),
+ _("Invalid Path Error"));
+
+ gtk_dialog_run (GTK_DIALOG (msgdialog));
+ gtk_widget_destroy (msgdialog);
+ }
g_object_unref (fileinfo);
}
- msgdialog = gtk_message_dialog_new (GTK_WINDOW (self),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- "%s",
- _("The selected path for 'Default path to files' is invalid"));
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (msgdialog),
- _("Path: '%s'\nError: %s"),
- path_utf8, g_strerror (errno));
- gtk_window_set_title (GTK_WINDOW (msgdialog), _("Invalid Path Error"));
-
- gtk_dialog_run (GTK_DIALOG (msgdialog));
- gtk_widget_destroy (msgdialog);
- g_free (path_real);
- g_free (path_utf8);
-
return FALSE;
}
@@ -1887,7 +1901,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 */
@@ -1919,7 +1932,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_Audio_File_Player_List (priv->file_player_model, MISC_COMBO_TEXT);
Save_Cddb_Local_Path_List (priv->cddb_local_path_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 bf22762..7f7e367 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 BrowserEntry combobox
static const gchar PATH_ENTRY_HISTORY_FILE[] = "browser_path.history";
// File for history of run program combobox for directories
@@ -109,8 +107,6 @@ static gboolean Create_Easytag_Directory (void);
********************/
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},
@@ -172,21 +168,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
@@ -293,14 +305,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));
@@ -652,7 +656,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 (PATH_ENTRY_HISTORY_FILE);
check_or_create_file (PLAY_LIST_NAME_MASKS_FILE);
check_or_create_file (RUN_PROGRAM_WITH_DIRECTORY_HISTORY_FILE);
@@ -863,17 +866,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 'BrowserEntry' combobox
@@ -1027,7 +1019,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,
PATH_ENTRY_HISTORY_FILE,
PLAY_LIST_NAME_MASKS_FILE,
RUN_PROGRAM_WITH_DIRECTORY_HISTORY_FILE,
diff --git a/src/setting.h b/src/setting.h
index 9cf1d49..a06b210 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_CASE_SENSITIVE;
@@ -246,10 +243,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]