[easytag/wip/application-window: 42/72] Remove main configuration file handling



commit d4c2a21fadfa064e74eba19a15b2c4a4df381892
Author: David King <amigadave amigadave com>
Date:   Sat Jul 5 22:51:39 2014 +0100

    Remove main configuration file handling
    
    All user pereferences are now stored in GSettings. Mask lists and combo
    box histories are still stored in files.

 TODO                               |    1 -
 data/org.gnome.EasyTAG.gschema.xml |    6 -
 src/easytag.c                      |    1 -
 src/preferences_dialog.c           |  108 +---------------
 src/preferences_dialog.h           |    5 -
 src/setting.c                      |  261 ------------------------------------
 src/setting.h                      |    3 -
 7 files changed, 1 insertions(+), 384 deletions(-)
---
diff --git a/TODO b/TODO
index acb0d56..0ae2059 100644
--- a/TODO
+++ b/TODO
@@ -6,7 +6,6 @@ General tidying
 
 * Use PNG icons and drop the XPM ones
 * Use GProxyResolver for proxy settings
-* Port configuration settings to use GSettings
 * Port file I/O to use GFile from GIO
 ** Additionally, make I/O asynchronous
 ** Always use the GLib encoding for filenames (convert for display)
diff --git a/data/org.gnome.EasyTAG.gschema.xml b/data/org.gnome.EasyTAG.gschema.xml
index c9f52a5..9628873 100644
--- a/data/org.gnome.EasyTAG.gschema.xml
+++ b/data/org.gnome.EasyTAG.gschema.xml
@@ -404,12 +404,6 @@
       <default>true</default>
     </key>
 
-    <key name="audio-file-player" type="s">
-      <summary>Audio file player</summary>
-      <description>The audio file player command-line</description>
-      <default>'xdg-open'</default>
-    </key>
-
     <key name="fill-convert-spaces" enum="org.gnome.EasyTAG.EtConvertSpaces">
       <summary>Convert spaces and underscores when filling tag fields</summary>
       <description>Whether to convert to spaces (and %20) or underscores when
diff --git a/src/easytag.c b/src/easytag.c
index d07598e..9d974bf 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -119,7 +119,6 @@ common_init (GApplication *application)
 
     /* Load Config */
     Init_Config_Variables();
-    Read_Config();
     /* Display_Config(); // <- for debugging */
 
     /* Initialization */
diff --git a/src/preferences_dialog.c b/src/preferences_dialog.c
index 24cd101..10c5d65 100644
--- a/src/preferences_dialog.c
+++ b/src/preferences_dialog.c
@@ -220,7 +220,6 @@ create_preferences_dialog (EtPreferencesDialog *self)
 {
     EtPreferencesDialogPrivate *priv;
     GtkWidget *OptionsVBox;
-    GtkWidget *Button;
     GtkWidget *Label;
     GtkWidget *Frame;
     GtkWidget *Table;
@@ -298,7 +297,6 @@ create_preferences_dialog (EtPreferencesDialog *self)
     GtkWidget *FilenameExtensionLowerCase;
     GtkWidget *FilenameExtensionUpperCase;
     GtkWidget *default_path_button;
-    gchar *program_path;
 
     priv = et_preferences_dialog_get_instance_private (self);
 
@@ -455,41 +453,6 @@ create_preferences_dialog (EtPreferencesDialog *self)
     gtk_widget_set_tooltip_text(SortingFileCaseSensitive,_("If activated, the "
         "sorting of the list will be dependent on the case."));
 
-    /* File Player */
-    Frame = gtk_frame_new (_("File Audio Player"));
-    gtk_box_pack_start(GTK_BOX(VBox),Frame,FALSE,FALSE,0);
-
-    /* Player name with params. */
-    priv->file_player_model = gtk_list_store_new (MISC_COMBO_COUNT,
-                                                  G_TYPE_STRING);
-
-    hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BOX_SPACING);
-    gtk_container_add(GTK_CONTAINER(Frame),hbox);
-    gtk_container_set_border_width (GTK_CONTAINER (hbox), BOX_SPACING);
-    Label = gtk_label_new (_("Player to run:"));
-    gtk_box_pack_start(GTK_BOX(hbox),Label,FALSE,FALSE,0);
-    FilePlayerCombo = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(priv->file_player_model));
-    g_object_unref (priv->file_player_model);
-    gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(FilePlayerCombo),MISC_COMBO_TEXT);
-    gtk_widget_set_size_request(GTK_WIDGET(FilePlayerCombo), 300, -1);
-    gtk_box_pack_start(GTK_BOX(hbox),FilePlayerCombo,FALSE,FALSE,0);
-    gtk_widget_set_tooltip_text(gtk_bin_get_child(GTK_BIN(FilePlayerCombo)),_("Enter the program used to "
-        "play the files. Some arguments can be passed for the program (as 'xmms -p') before "
-        "to receive files as other arguments."));
-    // History List
-    Load_Audio_File_Player_List(priv->file_player_model, MISC_COMBO_TEXT);
-    Add_String_To_Combo_List(priv->file_player_model, AUDIO_FILE_PLAYER);
-    // Don't load the parameter if XMMS not found, else user can't save the preference
-    if ( (program_path=Check_If_Executable_Exists(AUDIO_FILE_PLAYER)))
-        gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(FilePlayerCombo))), AUDIO_FILE_PLAYER);
-    g_free(program_path);
-
-    // 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_File), G_OBJECT(gtk_bin_get_child(GTK_BIN(FilePlayerCombo))));
-
     /* Log options */
     Frame = gtk_frame_new (_("Log Options"));
     gtk_box_pack_start(GTK_BOX(VBox),Frame,FALSE,FALSE,0);
@@ -1764,7 +1727,6 @@ Change_Id3_Settings_Toggled (GtkWidget *blah, EtPreferencesDialog *self)
 static void
 OptionsWindow_Quit (EtPreferencesDialog *self)
 {
-    et_preferences_dialog_apply_changes (self);
 }
 
 /*
@@ -1900,53 +1862,10 @@ gint Check_CharacterSetTranslation (void)
 }
 *************/
 
-/*
- * Check if player binary is found
- */
 static gboolean
-Check_FilePlayerCombo (EtPreferencesDialog *self)
-{
-    gchar *program_path = NULL;
-    gchar *program_path_validated = NULL;
-
-#ifdef G_OS_WIN32
-    return TRUE; /* FIXME see Check_If_Executable_Exists */
-    /* Note : Check_If_Executable_Exists crashes when player is 'winamp.exe' with g_find_program_in_path */
-#endif /* G_OS_WIN32 */
-
-    // The program typed
-    program_path = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(FilePlayerCombo)))));
-    g_strstrip(program_path);
-    // The program file validated
-    if (program_path && strlen(program_path)>0)
-        program_path_validated = Check_If_Executable_Exists(program_path);
-
-    if ( program_path && strlen(program_path)>0 && !program_path_validated ) // A file is typed but it is 
invalid!
-    {
-        GtkWidget *msgdialog = gtk_message_dialog_new (GTK_WINDOW (self),
-                                                      GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                      GTK_MESSAGE_ERROR,
-                                                      GTK_BUTTONS_CLOSE,
-                                                      _("The audio file player '%s' cannot be found"),
-                                                      program_path);
-        gtk_window_set_title(GTK_WINDOW(msgdialog),_("Audio Player Error"));
-
-        gtk_dialog_run(GTK_DIALOG(msgdialog));
-        gtk_widget_destroy(msgdialog);
-
-        g_free(program_path);
-        return FALSE;
-    } else
-    {
-        g_free(program_path);
-        g_free(program_path_validated);
-        return TRUE;
-    }
-}static gboolean
 Check_Config (EtPreferencesDialog *self)
 {
-    if (Check_DefaultPathToMp3 (self)
-        && Check_FilePlayerCombo (self))
+    if (Check_DefaultPathToMp3 (self))
         return TRUE; /* No problem detected */
     else
         return FALSE; /* Oops! */
@@ -1956,17 +1875,8 @@ Check_Config (EtPreferencesDialog *self)
 static void
 OptionsWindow_Save_Button (EtPreferencesDialog *self)
 {
-    EtPreferencesDialogPrivate *priv;
-
-    priv = et_preferences_dialog_get_instance_private (self);
-
     if (!Check_Config (self)) return;
 
-#ifndef G_OS_WIN32
-    /* FIXME : make gtk crash on win32 */
-    Add_String_To_Combo_List(priv->file_player_model,       
gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(FilePlayerCombo)))));
-#endif /* !G_OS_WIN32 */
-
     Save_Changes_Of_Preferences_Window();
 
     OptionsWindow_Quit (self);
@@ -1981,22 +1891,6 @@ OptionsWindow_Cancel_Button (EtPreferencesDialog *self)
     Statusbar_Message(_("Configuration unchanged"),TRUE);
 }
 
-/*
- * For the configuration file...
- */
-void
-et_preferences_dialog_apply_changes (EtPreferencesDialog *self)
-{
-    EtPreferencesDialogPrivate *priv;
-
-    g_return_if_fail (ET_PREFERENCES_DIALOG (self));
-
-    priv = et_preferences_dialog_get_instance_private (self);
-
-    /* Save combobox history lists before exit */
-    Save_Audio_File_Player_List (priv->file_player_model, MISC_COMBO_TEXT);
-}
-
 void
 et_preferences_dialog_show_scanner (EtPreferencesDialog *self)
 {
diff --git a/src/preferences_dialog.h b/src/preferences_dialog.h
index f6f7863..154bb2a 100644
--- a/src/preferences_dialog.h
+++ b/src/preferences_dialog.h
@@ -47,13 +47,8 @@ struct _EtPreferencesDialogClass
 
 GType et_preferences_dialog_get_type (void);
 EtPreferencesDialog *et_preferences_dialog_new (void);
-void et_preferences_dialog_apply_changes (EtPreferencesDialog *self);
 void et_preferences_dialog_show_scanner (EtPreferencesDialog *self);
 
 G_END_DECLS
 
-/* FIXME: Remove widget declarations when switching to GSettings. */
-/* Misc */
-GtkWidget *FilePlayerCombo;
-
 #endif /* ET_PREFERENCES_DIALOG_H_ */
diff --git a/src/setting.c b/src/setting.c
index ce436d8..a7ee8bf 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -72,8 +72,6 @@ static const gchar PATH_ENTRY_HISTORY_FILE[] = "browser_path.history";
 static const gchar RUN_PROGRAM_WITH_DIRECTORY_HISTORY_FILE[] = "run_program_with_directory.history";
 // File for history of run program combobox for files
 static const gchar RUN_PROGRAM_WITH_FILE_HISTORY_FILE[] = "run_program_with_file.history";
-// File for history of run player combobox
-static const gchar AUDIO_FILE_PLAYER_HISTORY_FILE[] = "audio_file_player.history";
 // File for history of search string combobox
 static const gchar SEARCH_FILE_HISTORY_FILE[] = "search_file.history";
 // File for history of FileToLoad combobox
@@ -89,23 +87,8 @@ static const gchar CDDB_SEARCH_STRING_IN_RESULT_HISTORY_FILE[] = "cddb_search_st
  * Prototypes *
  **************/
 
-static void Save_Config_To_File (void);
 static gboolean Create_Easytag_Directory (void);
 
-
-
-/********************
- * Config Variables *
- ********************/
-static const tConfigVariable Config_Variables[] =
-{
-
-    {"audio_file_player",                       CV_TYPE_STRING,&AUDIO_FILE_PLAYER                        }
-};
-
-
-
-
 /*************
  * Functions *
  *************/
@@ -141,15 +124,6 @@ void Init_Config_Variables (void)
      * Common
      */
     check_default_path ();
-
-    /*
-     * Misc
-     */
-#ifdef G_OS_WIN32
-    AUDIO_FILE_PLAYER                       = ET_Win32_Get_Audio_File_Player();
-#else /* !G_OS_WIN32 */
-    AUDIO_FILE_PLAYER                       = g_strdup("xdg-open");
-#endif /* !G_OS_WIN32 */
 }
 
 
@@ -170,9 +144,6 @@ Apply_Changes_Of_Preferences_Window (void)
 
     if (dialog)
     {
-        /* Misc */
-        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)))));
 
         /* Tag Settings */
 #ifdef ENABLE_ID3LIB
@@ -200,10 +171,6 @@ Apply_Changes_Of_UI (void)
      * Changes in user interface
      */
 
-    /* Configuration of the preference window (see preferences_dialog.c).
-     * Function also called when destroying the window. */
-    et_preferences_dialog_apply_changes (ET_PREFERENCES_DIALOG (et_application_window_get_preferences_dialog 
(ET_APPLICATION_WINDOW (MainWindow))));
-
     /* Configuration of the scanner window (see scan_dialog.c).
      * Function also called when destroying the window. */
     et_scan_dialog_apply_changes (ET_SCAN_DIALOG (et_application_window_get_scan_dialog 
(ET_APPLICATION_WINDOW (MainWindow))));
@@ -220,13 +187,11 @@ Apply_Changes_Of_UI (void)
 void Save_Changes_Of_UI (void)
 {
     Apply_Changes_Of_UI();
-    Save_Config_To_File();
 }
 
 void Save_Changes_Of_Preferences_Window (void)
 {
     Apply_Changes_Of_Preferences_Window();
-    Save_Config_To_File();
 
     Statusbar_Message(_("Configuration saved"),TRUE);
 }
@@ -234,218 +199,6 @@ void Save_Changes_Of_Preferences_Window (void)
 
 
 /*
- * Write the config file
- */
-static void
-Save_Config_To_File (void)
-{
-    gchar *file_path = NULL;
-    FILE *file;
-
-    file_path = g_build_filename (g_get_user_config_dir (), PACKAGE_TARNAME,
-                                  CONFIG_FILE, NULL);
-
-    if (!Create_Easytag_Directory () || (file = fopen (file_path, "w+")) == 0)
-    {
-        Log_Print (LOG_ERROR,
-                   _("Error: Cannot write configuration file: %s (%s)"),
-                   file_path, g_strerror(errno));
-    }
-    else
-    {
-        gint ConfigVarListLen = sizeof(Config_Variables)/sizeof(tConfigVariable);
-        gint i;
-        gchar *data = NULL;
-
-        for (i=0; i<ConfigVarListLen; i++)
-        {
-            switch (Config_Variables[i].type)
-            {
-                case CV_TYPE_INT:
-                {
-                    data = g_strdup_printf("%s=%i\n",Config_Variables[i].name,
-                                                     *(int *)Config_Variables[i].pointer);
-                    if (fwrite (data, strlen (data), 1, file) != 1)
-                    {
-                        Log_Print (LOG_ERROR,
-                                   _("Error while writing configuration file: %s"),
-                                   file_path);
-                        fclose (file);
-                        g_free (file_path);
-                        g_free (data);
-                        return;
-                    }
-                    g_free(data);
-                    break;
-                }
-                case CV_TYPE_BOOL:
-                {
-                    data = g_strdup_printf("%s=%i\n",Config_Variables[i].name,
-                                                     ( *(int *)Config_Variables[i].pointer ? 1 : 0 ));
-                    if (fwrite (data, strlen (data), 1, file) != 1)
-                    {
-                        Log_Print (LOG_ERROR,
-                                   _("Error while writing configuration file: %s"),
-                                   file_path);
-                        fclose (file);
-                        g_free (file_path);
-                        g_free (data);
-                        return;
-                    }
-                    g_free(data);
-                    break;
-                }
-                case CV_TYPE_STRING:
-                {
-                    /* Doesn't write datum if empty */
-                    if ( (*(char **)Config_Variables[i].pointer)==NULL ) break;
-
-                    data = g_strdup_printf("%s=%s\n",Config_Variables[i].name,
-                                                     *(char **)Config_Variables[i].pointer);
-                    if (fwrite (data, strlen (data), 1, file) != 1)
-                    {
-                        Log_Print (LOG_ERROR,
-                                   _("Error while writing configuration file: %s"),
-                                   file_path);
-                        fclose (file);
-                        g_free (file_path);
-                        g_free (data);
-                        return;
-                    }
-                    g_free(data);
-                    break;
-                }
-                default:
-                {
-                    Log_Print(LOG_ERROR,"ERROR: Can't save: type of config variable not supported "
-                              "for '%s'!",Config_Variables[i].name);
-                    break;
-                }
-            }
-        }
-        fclose(file);
-    }
-    g_free(file_path);
-}
-
-
-/*
- * Parse lines read (line as <var_description>=<value>) and load the values
- * into the corresponding config variables.
- */
-static void
-Set_Config (gchar *line)
-{
-    const gchar *var_descriptor;
-    const gchar *var_value;
-    gint ConfigVarListLen;
-    gint i;
-
-    g_return_if_fail (line != NULL);
-
-    if (*line=='\n' || *line=='#') return;
-
-    /* Cut string */
-    var_descriptor = strtok (line, "=");
-
-    if (!var_descriptor)
-    {
-        g_message ("Invalid configuration file line ā€˜%sā€™", line);
-        return;
-    }
-
-    var_value = strtok (NULL, "=");
-
-    if (!var_value)
-    {
-        g_message ("No value for configuration key ā€˜%sā€™", var_descriptor);
-        return;
-    }
-
-    ConfigVarListLen = sizeof(Config_Variables)/sizeof(tConfigVariable);
-    for (i=0; i<ConfigVarListLen; i++)
-    {
-        if (Config_Variables[i].name!=NULL && var_descriptor
-        && !strcmp(Config_Variables[i].name,var_descriptor))
-        {
-            switch (Config_Variables[i].type)
-            {
-                case CV_TYPE_INT:
-                {
-                    *(int *)Config_Variables[i].pointer = strtol(var_value, NULL, 10);
-                    break;
-                }
-
-                case CV_TYPE_BOOL:
-                {
-                    if (strtol(var_value, NULL, 10))
-                        *(int *)Config_Variables[i].pointer = 1;
-                    else
-                        *(int *)Config_Variables[i].pointer = 0;
-                    break;
-                }
-
-                case CV_TYPE_STRING:
-                {
-
-                    if (*(char **)Config_Variables[i].pointer != NULL)
-                    {
-                        g_free (*(char **)Config_Variables[i].pointer);
-                    }
-
-                    *(char **)Config_Variables[i].pointer = g_strdup (var_value);
-                    break;
-                }
-
-                default:
-                {
-                    Log_Print(LOG_ERROR,"ERROR: Can't read: type of config variable not supported "
-                              "for '%s'!",Config_Variables[i].name);
-                    break;
-                }
-            }
-        }
-    }
-}
-
-
-/*
- * Read config from config file
- */
-void Read_Config (void)
-{
-    gchar *file_path = NULL;
-    FILE *file;
-    gchar buffer[MAX_STRING_LEN];
-
-    /* The file to read */
-    file_path = g_build_filename (g_get_user_config_dir (), PACKAGE_TARNAME,
-                                  CONFIG_FILE, NULL);
-
-    if ((file = fopen (file_path,"r")) == 0)
-    {
-        Log_Print (LOG_ERROR, _("Cannot open configuration file '%s' (%s)"),
-                   file_path, g_strerror (errno));
-        Log_Print (LOG_OK, _("Loading default configuration"));
-    }else
-    {
-        while (fgets(buffer,sizeof(buffer),file))
-        {
-            if (buffer[strlen(buffer)-1]=='\n')
-                buffer[strlen(buffer)-1]='\0';
-            Set_Config(buffer);
-        }
-        fclose(file);
-
-        // Force this configuration! - Disabled as it is boring for russian people
-        //USE_ISO_8859_1_CHARACTER_SET_TRANSLATION = 1;
-        //USE_CHARACTER_SET_TRANSLATION            = 0;
-    }
-    g_free(file_path);
-}
-
-
-/*
  * check_or_create_file:
  * @filename: (type filename): the filename to create
  *
@@ -490,7 +243,6 @@ gboolean Setting_Create_Files (void)
     check_or_create_file (PATH_ENTRY_HISTORY_FILE);
     check_or_create_file (RUN_PROGRAM_WITH_DIRECTORY_HISTORY_FILE);
     check_or_create_file (RUN_PROGRAM_WITH_FILE_HISTORY_FILE);
-    check_or_create_file (AUDIO_FILE_PLAYER_HISTORY_FILE);
     check_or_create_file (SEARCH_FILE_HISTORY_FILE);
     check_or_create_file (FILE_TO_LOAD_HISTORY_FILE);
     check_or_create_file (CDDB_SEARCH_STRING_HISTORY_FILE);
@@ -702,18 +454,6 @@ void Save_Run_Program_With_File_List (GtkListStore *liststore, gint colnum)
 }
 
 /*
- * Functions for writing and reading list of combobox to run file audio player
- */
-void Load_Audio_File_Player_List (GtkListStore *liststore, gint colnum)
-{
-    Populate_List_Store_From_File(AUDIO_FILE_PLAYER_HISTORY_FILE, liststore, colnum);
-}
-void Save_Audio_File_Player_List (GtkListStore *liststore, gint colnum)
-{
-    Save_List_Store_To_File(AUDIO_FILE_PLAYER_HISTORY_FILE, liststore, colnum);
-}
-
-/*
  * Functions for writing and reading list of combobox to search a string into file (tag or filename)
  */
 void Load_Search_File_List (GtkListStore *liststore, gint colnum)
@@ -779,7 +519,6 @@ migrate_config_file_dir (const gchar *old_path, const gchar *new_path)
                                         PATH_ENTRY_HISTORY_FILE,
                                         RUN_PROGRAM_WITH_DIRECTORY_HISTORY_FILE,
                                         RUN_PROGRAM_WITH_FILE_HISTORY_FILE,
-                                        AUDIO_FILE_PLAYER_HISTORY_FILE,
                                         SEARCH_FILE_HISTORY_FILE,
                                         FILE_TO_LOAD_HISTORY_FILE,
                                         CDDB_SEARCH_STRING_HISTORY_FILE,
diff --git a/src/setting.h b/src/setting.h
index 0ff3ff2..96edd3a 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -257,9 +257,6 @@ typedef enum
 
 GSettings *MainSettings;
 
-/* Misc */
-gchar  *AUDIO_FILE_PLAYER;
-
 /**************
  * Prototypes *
  **************/


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