[easytag/wip/application-window: 14/21] Move preferences dialog to EtPreferencesDialog



commit c115d040fde9f4bfd225012293b49315b58b47ee
Author: David King <amigadave amigadave com>
Date:   Sat Dec 28 13:02:10 2013 +0000

    Move preferences dialog to EtPreferencesDialog

 Makefile.am                           |    4 +-
 src/application_window.c              |   35 +++
 src/application_window.h              |    2 +
 src/bar.c                             |    5 +-
 src/easytag.c                         |    4 +-
 src/misc.c                            |    3 +-
 src/{prefs.c => preferences_dialog.c} |  365 ++++++++++++++++++---------------
 src/{prefs.h => preferences_dialog.h} |   81 ++++----
 src/scan.c                            |   11 +-
 src/scan.h                            |    2 +
 src/setting.c                         |   15 +-
 11 files changed, 303 insertions(+), 224 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 4549ee9..13e6639 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -63,7 +63,7 @@ easytag_SOURCES = \
        src/ogg_tag.c \
        src/picture.c \
        src/playlist_dialog.c \
-       src/prefs.c \
+       src/preferences_dialog.c \
        src/scan.c \
        src/search_dialog.c \
        src/setting.c \
@@ -106,7 +106,7 @@ easytag_headers = \
        src/ogg_tag.h \
        src/picture.h \
        src/playlist_dialog.h \
-       src/prefs.h \
+       src/preferences_dialog.h \
        src/scan.h \
        src/search_dialog.h \
        src/setting.h \
diff --git a/src/application_window.c b/src/application_window.c
index dc4bf14..a272623 100644
--- a/src/application_window.c
+++ b/src/application_window.c
@@ -32,6 +32,7 @@
 #include "misc.h"
 #include "picture.h"
 #include "playlist_dialog.h"
+#include "preferences_dialog.h"
 #include "search_dialog.h"
 #include "scan.h"
 #include "setting.h"
@@ -48,6 +49,7 @@ struct _EtApplicationWindowPrivate
     GtkWidget *tag_area;
     GtkWidget *load_files_dialog;
     GtkWidget *playlist_dialog;
+    GtkWidget *preferences_dialog;
     GtkWidget *search_dialog;
 
     /* Tag area labels. */
@@ -1642,6 +1644,7 @@ et_application_window_finalize (GObject *object)
 
     g_clear_object (&priv->load_files_dialog);
     g_clear_object (&priv->playlist_dialog);
+    g_clear_object (&priv->preferences_dialog);
     g_clear_object (&priv->search_dialog);
 
     G_OBJECT_CLASS (et_application_window_parent_class)->finalize (object);
@@ -1662,6 +1665,7 @@ et_application_window_init (EtApplicationWindow *self)
 
     priv->load_files_dialog = NULL;
     priv->playlist_dialog = NULL;
+    priv->preferences_dialog = NULL;
     priv->search_dialog = NULL;
 
     window = GTK_WINDOW (self);
@@ -1883,6 +1887,37 @@ et_application_window_show_search_dialog (G_GNUC_UNUSED GtkAction *action,
     }
 }
 
+GtkWidget *
+et_application_window_get_preferences_dialog (EtApplicationWindow *self)
+{
+    EtApplicationWindowPrivate *priv;
+
+    g_return_val_if_fail (self != NULL, NULL);
+
+    priv = et_application_window_get_instance_private (self);
+
+    return priv->preferences_dialog;
+}
+
+void
+et_application_window_show_preferences_dialog (G_GNUC_UNUSED GtkAction *action,
+                                               gpointer user_data)
+{
+    EtApplicationWindowPrivate *priv;
+    EtApplicationWindow *self = ET_APPLICATION_WINDOW (user_data);
+
+    priv = et_application_window_get_instance_private (self);
+
+    if (priv->preferences_dialog)
+    {
+        gtk_widget_show (priv->preferences_dialog);
+    }
+    else
+    {
+        priv->preferences_dialog = GTK_WIDGET (et_preferences_dialog_new ());
+    }
+}
+
 /*
  * Disable (FALSE) / Enable (TRUE) all user widgets in the tag area
  */
diff --git a/src/application_window.h b/src/application_window.h
index 36771d1..4044fbe 100644
--- a/src/application_window.h
+++ b/src/application_window.h
@@ -57,6 +57,8 @@ GtkWidget * et_application_window_get_load_files_dialog (EtApplicationWindow *se
 void et_application_window_show_load_files_dialog (GtkAction *action, gpointer user_data);
 GtkWidget * et_application_window_get_search_dialog (EtApplicationWindow *self);
 void et_application_window_show_search_dialog (GtkAction *action, gpointer user_data);
+GtkWidget * et_application_window_get_preferences_dialog (EtApplicationWindow *self);
+void et_application_window_show_preferences_dialog (GtkAction *action, gpointer user_data);
 void et_application_window_hide_log_area (EtApplicationWindow *self);
 void et_application_window_show_log_area (EtApplicationWindow *self);
 
diff --git a/src/bar.c b/src/bar.c
index dc20442..7d6eb83 100644
--- a/src/bar.c
+++ b/src/bar.c
@@ -27,7 +27,7 @@
 #include "bar.h"
 #include "easytag.h"
 #include "about.h"
-#include "prefs.h"
+#include "preferences_dialog.h"
 #include "setting.h"
 #include "browser.h"
 #include "scan.h"
@@ -301,7 +301,8 @@ Create_UI (GtkWindow *window, GtkWidget **ppmenubar, GtkWidget **pptoolbar)
 
         { MENU_EDIT, NULL, _("_Edit"), NULL, NULL, NULL },
         { AM_OPEN_OPTIONS_WINDOW, GTK_STOCK_PREFERENCES, _("_Preferences"),
-          NULL, _("Preferences"), G_CALLBACK (Open_OptionsWindow) },
+          NULL, _("Preferences"),
+          G_CALLBACK (et_application_window_show_preferences_dialog) },
 
         { MENU_VIEW, NULL, _("_View"), NULL, NULL, NULL },
         { MENU_GO, NULL, _("_Go"), NULL, NULL, NULL },
diff --git a/src/easytag.c b/src/easytag.c
index e46b1d7..28a4926 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -1,4 +1,3 @@
-/* easytag.c - 2000/04/28 */
 /*
  *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
  *  Copyright (C) 2000-2003  Jerome Couderc <easytag gmail com>
@@ -44,7 +43,7 @@
 #include "log.h"
 #include "misc.h"
 #include "bar.h"
-#include "prefs.h"
+#include "preferences_dialog.h"
 #include "setting.h"
 #include "scan.h"
 #include "mpeg_header.h"
@@ -135,7 +134,6 @@ common_init (GApplication *application)
     Main_Stop_Button_Pressed = FALSE;
     Init_Custom_Icons();
     Init_Mouse_Cursor();
-    Init_OptionsWindow();
     Init_ScannerWindow();
     Init_CddbWindow();
     BrowserEntryModel    = NULL;
diff --git a/src/misc.c b/src/misc.c
index b39497b..1a6f754 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -1,4 +1,3 @@
-/* misc.c - 2000/06/28 */
 /*
  *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
  *  Copyright (C) 2000-2003  Jerome Couderc <easytag gmail com>
@@ -34,7 +33,7 @@
 #include "browser.h"
 #include "setting.h"
 #include "bar.h"
-#include "prefs.h"
+#include "preferences_dialog.h"
 #include "scan.h"
 #include "genres.h"
 #include "log.h"
diff --git a/src/prefs.c b/src/preferences_dialog.c
similarity index 92%
rename from src/prefs.c
rename to src/preferences_dialog.c
index 301438a..5fe1f55 100644
--- a/src/prefs.c
+++ b/src/preferences_dialog.c
@@ -1,30 +1,30 @@
-/* prefs.c - 2000/05/06 */
 /*
- *  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) 2000-2003  Jerome Couderc <easytag gmail com>
+ * Copyright (C) 2013  David King <amigadave amigadave 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.
  */
 
-#include <config.h>
+#include "config.h"
+
+#include "preferences_dialog.h"
 
-#include <gtk/gtk.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <gdk/gdkkeysyms.h>
-#include <gdk/gdk.h>
 #include <glib/gi18n.h>
 #include <stdio.h>
 #include <string.h>
@@ -32,7 +32,6 @@
 #include <unistd.h>
 
 #include "gtk2_compat.h"
-#include "prefs.h"
 #include "setting.h"
 #include "bar.h"
 #include "misc.h"
@@ -43,17 +42,25 @@
 #include "charset.h"
 #include "win32/win32dep.h"
 
+/* TODO: Use G_DEFINE_TYPE_WITH_PRIVATE. */
+G_DEFINE_TYPE (EtPreferencesDialog, et_preferences_dialog, GTK_TYPE_DIALOG)
+
+#define et_preferences_dialog_get_instance_private(dialog) (dialog->priv)
+
 static const guint BOX_SPACING = 6;
 
+struct _EtPreferencesDialogPrivate
+{
+    GtkListStore *cddb_local_path_model;
+    GtkListStore *default_comment_model;
+    GtkListStore *default_path_model;
+    GtkListStore *file_player_model;
+};
+
 /**************
  * Prototypes *
  **************/
 /* Options window */
-static void OptionsWindow_Quit (void);
-static void OptionsWindow_Save_Button (void);
-static void OptionsWindow_Cancel_Button (void);
-static gboolean Check_Config (void);
-
 static void Set_Default_Comment_Check_Button_Toggled (void);
 static void Number_Track_Formatted_Toggled (void);
 static void Number_Track_Formatted_Spin_Button_Changed (GtkWidget *Label,
@@ -68,7 +75,6 @@ static void Scanner_Convert_Check_Button_Toggled_1 (GtkWidget *object_rec,
                                                     GtkWidget *object_emi);
 static void Cddb_Use_Proxy_Toggled (void);
 
-static void DefaultPathToMp3_Combo_Add_String (void);
 static void CddbLocalPath_Combo_Add_String (void);
 
 static void et_preferences_on_response (GtkDialog *dialog, gint response_id,
@@ -78,16 +84,25 @@ static void et_preferences_on_response (GtkDialog *dialog, gint response_id,
 /*************
  * Functions *
  *************/
-void Init_OptionsWindow (void)
+static void
+DefaultPathToMp3_Combo_Add_String (EtPreferencesDialog *self)
 {
-    OptionsWindow = NULL;
+    EtPreferencesDialogPrivate *priv;
+    const gchar *path;
+
+    priv = et_preferences_dialog_get_instance_private (self);
+
+    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);
 }
 
 /*
  * The window for options
  */
-void Open_OptionsWindow (void)
+static void
+create_preferences_dialog (EtPreferencesDialog *self)
 {
+    EtPreferencesDialogPrivate *priv;
     GtkWidget *OptionsVBox;
     GtkWidget *Button;
     GtkWidget *Label;
@@ -99,34 +114,27 @@ void Open_OptionsWindow (void)
     gchar *path_utf8;
     gchar *program_path;
 
-    /* Check if already opened */
-    if (OptionsWindow)
-    {
-        gtk_window_present(GTK_WINDOW(OptionsWindow));
-        return;
-    }
+    priv = et_preferences_dialog_get_instance_private (self);
 
     /* The window */
-    OptionsWindow = gtk_dialog_new_with_buttons (_("Preferences"),
-                                                 GTK_WINDOW (MainWindow),
-                                                 GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                 GTK_STOCK_CANCEL,
-                                                 GTK_RESPONSE_REJECT,
-                                                 GTK_STOCK_OK,
-                                                 GTK_RESPONSE_ACCEPT, NULL);
-
-    gtk_container_set_border_width (GTK_CONTAINER (OptionsWindow), 6);
-
-    /* Signals connection */
-    gtk_dialog_set_default_response (GTK_DIALOG (OptionsWindow),
-                                     GTK_RESPONSE_ACCEPT);
-    g_signal_connect (OptionsWindow, "response",
+    gtk_window_set_title (GTK_WINDOW (self), _("Preferences"));
+    gtk_window_set_transient_for (GTK_WINDOW (self), GTK_WINDOW (MainWindow));
+    gtk_window_set_destroy_with_parent (GTK_WINDOW (self), TRUE);
+    gtk_dialog_add_buttons (GTK_DIALOG (self), GTK_STOCK_CANCEL,
+                            GTK_RESPONSE_REJECT, GTK_STOCK_OK,
+                            GTK_RESPONSE_ACCEPT, NULL);
+    gtk_dialog_set_default_response (GTK_DIALOG (self), GTK_RESPONSE_ACCEPT);
+    g_signal_connect (self, "response",
                       G_CALLBACK (et_preferences_on_response), NULL);
+    g_signal_connect (self, "delete-event",
+                      G_CALLBACK (gtk_widget_hide_on_delete), NULL);
+
+    gtk_container_set_border_width (GTK_CONTAINER (self), BOX_SPACING);
 
      /* Options */
      /* The vbox */
-    OptionsVBox = gtk_dialog_get_content_area (GTK_DIALOG (OptionsWindow));
-    gtk_box_set_spacing (GTK_BOX (OptionsVBox), 12);
+    OptionsVBox = gtk_dialog_get_content_area (GTK_DIALOG (self));
+    gtk_box_set_spacing (GTK_BOX (OptionsVBox), BOX_SPACING);
 
      /* Options NoteBook */
     OptionsNoteBook = gtk_notebook_new();
@@ -152,26 +160,28 @@ void Open_OptionsWindow (void)
     Label = gtk_label_new(_("Default directory:"));
     gtk_box_pack_start(GTK_BOX(HBox),Label,FALSE,FALSE,0);
 
-    // Combo
-    if (DefaultPathModel != NULL)
-        gtk_list_store_clear(DefaultPathModel);
-    else
-        DefaultPathModel = gtk_list_store_new(MISC_COMBO_COUNT, G_TYPE_STRING);
+    /* 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(DefaultPathModel));
+    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(G_OBJECT(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(DefaultPathToMp3)))),"activate",G_CALLBACK(DefaultPathToMp3_Combo_Add_String),NULL);
+    g_signal_connect_swapped (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (DefaultPathToMp3))),
+                              "activate",
+                              G_CALLBACK (DefaultPathToMp3_Combo_Add_String),
+                              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(DefaultPathModel, MISC_COMBO_TEXT);
+    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(DefaultPathModel, path_utf8);
+    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);
@@ -348,18 +358,17 @@ void Open_OptionsWindow (void)
     Frame = gtk_frame_new (_("File Audio Player"));
     gtk_box_pack_start(GTK_BOX(VBox),Frame,FALSE,FALSE,0);
 
-    // Player name with params
-    if (FilePlayerModel == NULL)
-        FilePlayerModel = gtk_list_store_new(MISC_COMBO_COUNT, G_TYPE_STRING);
-    else
-        gtk_list_store_clear(FilePlayerModel);
+    /* 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(FilePlayerModel));
+    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);
@@ -367,8 +376,8 @@ void Open_OptionsWindow (void)
         "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(FilePlayerModel, MISC_COMBO_TEXT);
-    Add_String_To_Combo_List(FilePlayerModel, AUDIO_FILE_PLAYER);
+    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);
@@ -1081,11 +1090,9 @@ void Open_OptionsWindow (void)
     gtk_widget_set_tooltip_text(OverwriteTagField,_("If activated, the scanner will replace existing text "
         "in fields by the new one. If deactivated, only blank fields of the tag will be filled."));
 
-    // Set a default comment text or CRC-32 checksum
-    if (!DefaultCommentModel)
-        DefaultCommentModel = gtk_list_store_new(MISC_COMBO_COUNT, G_TYPE_STRING);
-    else
-        gtk_list_store_clear(DefaultCommentModel);
+    /* Set a default comment text or CRC-32 checksum. */
+    priv->default_comment_model = gtk_list_store_new (MISC_COMBO_COUNT,
+                                                      G_TYPE_STRING);
 
     hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BOX_SPACING);
     gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,0);
@@ -1094,7 +1101,8 @@ void Open_OptionsWindow (void)
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(SetDefaultComment),SET_DEFAULT_COMMENT);
     gtk_widget_set_tooltip_text(SetDefaultComment,_("Activate this option if you want to put the "
         "following string into the comment field when using the 'Fill Tag' scanner."));
-    DefaultComment = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(DefaultCommentModel));
+    DefaultComment = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(priv->default_comment_model));
+    g_object_unref (priv->default_comment_model);
     gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(DefaultComment),MISC_COMBO_TEXT);
     gtk_box_pack_start(GTK_BOX(hbox),DefaultComment,FALSE,FALSE,0);
     gtk_widget_set_size_request(GTK_WIDGET(DefaultComment), 250, -1);
@@ -1104,8 +1112,8 @@ void Open_OptionsWindow (void)
         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(SetDefaultComment),FALSE);
     Set_Default_Comment_Check_Button_Toggled();
     /* History list */
-    Load_Default_Tag_Comment_Text_List(DefaultCommentModel, MISC_COMBO_TEXT);
-    Add_String_To_Combo_List(DefaultCommentModel, DEFAULT_COMMENT);
+    Load_Default_Tag_Comment_Text_List(priv->default_comment_model, MISC_COMBO_TEXT);
+    Add_String_To_Combo_List(priv->default_comment_model, DEFAULT_COMMENT);
     if (DEFAULT_COMMENT)
         gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(DefaultComment))), DEFAULT_COMMENT);
 
@@ -1238,7 +1246,7 @@ void Open_OptionsWindow (void)
     if (CDDB_SERVER_CGI_PATH_MANUAL_SEARCH)
         gtk_entry_set_text(GTK_ENTRY(CddbServerCgiPathManualSearch) ,CDDB_SERVER_CGI_PATH_MANUAL_SEARCH);
 
-    // Local access for CDDB (Automatic Search)
+    /* Local access for CDDB (Automatic Search). */
     Frame = gtk_frame_new (_("Local CDDB"));
     gtk_box_pack_start(GTK_BOX(VBox),Frame,FALSE,FALSE,0);
     vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, BOX_SPACING);
@@ -1250,12 +1258,11 @@ void Open_OptionsWindow (void)
     Label = gtk_label_new(_("Path:"));
     gtk_box_pack_start(GTK_BOX(hbox),Label,FALSE,FALSE,2);
 
-    if (CddbLocalPathModel != NULL)
-        gtk_list_store_clear(CddbLocalPathModel);
-    else
-        CddbLocalPathModel = gtk_list_store_new(MISC_COMBO_COUNT, G_TYPE_STRING);
+    priv->cddb_local_path_model = gtk_list_store_new (MISC_COMBO_COUNT,
+                                                      G_TYPE_STRING);
 
-    CddbLocalPath = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(CddbLocalPathModel));
+    CddbLocalPath = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(priv->cddb_local_path_model));
+    g_object_unref (priv->cddb_local_path_model);
     gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(CddbLocalPath),MISC_COMBO_TEXT);
     gtk_box_pack_start(GTK_BOX(hbox),CddbLocalPath,FALSE,FALSE,0);
     gtk_widget_set_size_request(GTK_WIDGET(CddbLocalPath), 450, -1);
@@ -1267,13 +1274,13 @@ void Open_OptionsWindow (void)
     
//g_signal_connect(G_OBJECT(GTK_ENTRY(GTK_BIN(CddbLocalPath)->child)),"focus_out_event",G_CALLBACK(CddbLocalPath_Combo_Add_String),NULL);
 
     // History list
-    Load_Cddb_Local_Path_List(CddbLocalPathModel, MISC_COMBO_TEXT);
+    Load_Cddb_Local_Path_List(priv->cddb_local_path_model, MISC_COMBO_TEXT);
 
     // If default path hasn't been added already, add it now..
     if (CDDB_LOCAL_PATH)
     {
         path_utf8 = filename_to_display(CDDB_LOCAL_PATH);
-        Add_String_To_Combo_List(CddbLocalPathModel, path_utf8);
+        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);
         g_free(path_utf8);
@@ -1402,9 +1409,6 @@ void Open_OptionsWindow (void)
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ConfirmWhenUnsavedFiles),CONFIRM_WHEN_UNSAVED_FILES);
 
 
-    /* Show all in the options window */
-    gtk_widget_show_all(OptionsWindow);
-
     /* Load the default page */
     gtk_notebook_set_current_page(GTK_NOTEBOOK(OptionsNoteBook), OPTIONS_NOTEBOOK_PAGE);
 }
@@ -1593,70 +1597,14 @@ Cddb_Use_Proxy_Toggled (void)
     gtk_widget_set_sensitive(CddbProxyUserPassword,active);
 }
 
-/* Callback from Open_OptionsWindow */
+/* Callback from et_preferences_dialog_on_response. */
 static void
-OptionsWindow_Save_Button (void)
+OptionsWindow_Quit (EtPreferencesDialog *self)
 {
-    if (!Check_Config()) return;
-
-#ifndef G_OS_WIN32
-    /* FIXME : make gtk crash on win32 */
-    Add_String_To_Combo_List(DefaultPathModel,      
gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(DefaultPathToMp3)))));
-    Add_String_To_Combo_List(FilePlayerModel,       
gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(FilePlayerCombo)))));
-    Add_String_To_Combo_List(DefaultCommentModel,   
gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(DefaultComment)))));
-    Add_String_To_Combo_List(CddbLocalPathModel,    
gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(CddbLocalPath)))));
-#endif /* !G_OS_WIN32 */
-
-    Save_Changes_Of_Preferences_Window();
-
-    OptionsWindow_Quit();
-    Statusbar_Message(_("Configuration saved"),TRUE);
-}
-
-/* Callback from Open_OptionsWindow */
-static void
-OptionsWindow_Cancel_Button (void)
-{
-    OptionsWindow_Quit();
-    Statusbar_Message(_("Configuration unchanged"),TRUE);
-}
-
-/* Callback from Open_OptionsWindow */
-static void
-OptionsWindow_Quit (void)
-{
-    if (OptionsWindow)
-    {
-        OptionsWindow_Apply_Changes();
-
-        /* Now quit */
-        gtk_widget_destroy(OptionsWindow);
-        OptionsWindow = NULL;
-        gtk_widget_set_sensitive(MainWindow, TRUE);
-    }
+    et_preferences_dialog_apply_changes (self);
 }
 
 /*
- * For the configuration file...
- */
-void OptionsWindow_Apply_Changes (void)
-{
-    if (OptionsWindow)
-    {
-        /* Get the last visible notebook page */
-        OPTIONS_NOTEBOOK_PAGE = gtk_notebook_get_current_page(GTK_NOTEBOOK(OptionsNoteBook));
-
-        /* Save combobox history lists before exit */
-        Save_Default_Path_To_MP3_List     (DefaultPathModel, MISC_COMBO_TEXT);
-        Save_Default_Tag_Comment_Text_List(DefaultCommentModel, MISC_COMBO_TEXT);
-        Save_Audio_File_Player_List       (FilePlayerModel, MISC_COMBO_TEXT);
-        Save_Cddb_Local_Path_List         (CddbLocalPathModel, MISC_COMBO_TEXT);
-    }
-}
-
-
-
-/*
  * Check_Config: Check if config information are correct
  * dsd: Check this... going from utf8 to raw is dodgy stuff
  *
@@ -1670,7 +1618,7 @@ void OptionsWindow_Apply_Changes (void)
  *  - try to convert to system encoding (path_real) : ?????
  */
 static gboolean
-Check_DefaultPathToMp3 (void)
+Check_DefaultPathToMp3 (EtPreferencesDialog *self)
 {
     gchar *path_utf8;
     gchar *path_real;
@@ -1704,7 +1652,7 @@ Check_DefaultPathToMp3 (void)
         g_object_unref (fileinfo);
     }
 
-    msgdialog = gtk_message_dialog_new (GTK_WINDOW (OptionsWindow),
+    msgdialog = gtk_message_dialog_new (GTK_WINDOW (self),
                                         GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                         GTK_MESSAGE_ERROR,
                                         GTK_BUTTONS_CLOSE,
@@ -1789,7 +1737,7 @@ gint Check_CharacterSetTranslation (void)
 *************/
 
 static gboolean
-Check_DefaultComment (void)
+Check_DefaultComment (EtPreferencesDialog *self)
 {
     const gchar *file;
 
@@ -1804,7 +1752,7 @@ Check_DefaultComment (void)
  * Check if player binary is found
  */
 static gboolean
-Check_FilePlayerCombo (void)
+Check_FilePlayerCombo (EtPreferencesDialog *self)
 {
     gchar *program_path = NULL;
     gchar *program_path_validated = NULL;
@@ -1823,7 +1771,7 @@ Check_FilePlayerCombo (void)
 
     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(OptionsWindow),
+        GtkWidget *msgdialog = gtk_message_dialog_new (GTK_WINDOW (self),
                                                       GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                                       GTK_MESSAGE_ERROR,
                                                       GTK_BUTTONS_CLOSE,
@@ -1842,20 +1790,71 @@ Check_FilePlayerCombo (void)
         g_free(program_path_validated);
         return TRUE;
     }
-}
-
-static gboolean
-Check_Config (void)
+}static gboolean
+Check_Config (EtPreferencesDialog *self)
 {
-    if (Check_DefaultPathToMp3 ()
-        && Check_DefaultComment ()
-        && Check_FilePlayerCombo ())
+    if (Check_DefaultPathToMp3 (self)
+        && Check_DefaultComment (self)
+        && Check_FilePlayerCombo (self))
         return TRUE; /* No problem detected */
     else
         return FALSE; /* Oops! */
 }
 
+/* Callback from et_preferences_dialog_on_response. */
+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->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->default_comment_model,   
gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(DefaultComment)))));
+    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 */
+
+    Save_Changes_Of_Preferences_Window();
+
+    OptionsWindow_Quit (self);
+    Statusbar_Message(_("Configuration saved"),TRUE);
+}
+
+/* Callback from et_preferences_dialog_on_response. */
+static void
+OptionsWindow_Cancel_Button (EtPreferencesDialog *self)
+{
+    OptionsWindow_Quit (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);
+
+    /* Get the last visible notebook page */
+    OPTIONS_NOTEBOOK_PAGE = gtk_notebook_get_current_page (GTK_NOTEBOOK (OptionsNoteBook));
+
+    /* 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);
+    Save_Cddb_Local_Path_List (priv->cddb_local_path_model, MISC_COMBO_TEXT);
+}
 
 /*
  * Manage Check buttons into Scanner tab: conversion group
@@ -1872,15 +1871,6 @@ Scanner_Convert_Check_Button_Toggled_1 (GtkWidget *object_rec,
 }
 
 static void
-DefaultPathToMp3_Combo_Add_String (void)
-{
-    const gchar *path;
-
-    path = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(DefaultPathToMp3))));
-    Add_String_To_Combo_List(GTK_LIST_STORE(DefaultPathModel), path);
-}
-
-static void
 CddbLocalPath_Combo_Add_String (void)
 {
     const gchar *path;
@@ -1905,14 +1895,53 @@ et_preferences_on_response (GtkDialog *dialog, gint response_id,
     switch (response_id)
     {
         case GTK_RESPONSE_ACCEPT:
-            OptionsWindow_Save_Button ();
+            OptionsWindow_Save_Button (ET_PREFERENCES_DIALOG (dialog));
             break;
         case GTK_RESPONSE_DELETE_EVENT:
-            OptionsWindow_Quit ();
+            OptionsWindow_Quit (ET_PREFERENCES_DIALOG (dialog));
         case GTK_RESPONSE_REJECT:
-            OptionsWindow_Cancel_Button ();
+            OptionsWindow_Cancel_Button (ET_PREFERENCES_DIALOG (dialog));
+            gtk_widget_hide (GTK_WIDGET (dialog));
             break;
         default:
             g_assert_not_reached ();
     }
 }
+
+static void
+et_preferences_dialog_finalize (GObject *object)
+{
+    G_OBJECT_CLASS (et_preferences_dialog_parent_class)->finalize (object);
+}
+
+static void
+et_preferences_dialog_init (EtPreferencesDialog *self)
+{
+    self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ET_TYPE_PREFERENCES_DIALOG,
+                                              EtPreferencesDialogPrivate);
+
+    create_preferences_dialog (self);
+
+    gtk_widget_show_all (GTK_WIDGET (self));
+}
+
+static void
+et_preferences_dialog_class_init (EtPreferencesDialogClass *klass)
+{
+    G_OBJECT_CLASS (klass)->finalize = et_preferences_dialog_finalize;
+
+    g_type_class_add_private (klass, sizeof (EtPreferencesDialogPrivate));
+}
+
+/*
+ * et_preferences_dialog_new:
+ *
+ * Create a new EtPreferencesDialog instance.
+ *
+ * Returns: a new #EtPreferencesDialog
+ */
+EtPreferencesDialog *
+et_preferences_dialog_new (void)
+{
+    return g_object_new (ET_TYPE_PREFERENCES_DIALOG, NULL);
+}
diff --git a/src/prefs.h b/src/preferences_dialog.h
similarity index 70%
rename from src/prefs.h
rename to src/preferences_dialog.h
index 5e8442e..27faee7 100644
--- a/src/prefs.h
+++ b/src/preferences_dialog.h
@@ -1,33 +1,57 @@
-/* prefs.h - 2000/05/06 */
 /*
- *  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) 2000-2003  Jerome Couderc <easytag gmail com>
+ * Copyright (C) 2013  David King <amigadave amigadave 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_PREFERENCES_DIALOG_H_
+#define ET_PREFERENCES_DIALOG_H_
 
-#ifndef __PREFS_H__
-#define __PREFS_H__
+#include <gtk/gtk.h>
 
+G_BEGIN_DECLS
 
-/***************
- * Declaration *
- ***************/
+#define ET_TYPE_PREFERENCES_DIALOG (et_preferences_dialog_get_type ())
+#define ET_PREFERENCES_DIALOG(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), ET_TYPE_PREFERENCES_DIALOG, 
EtPreferencesDialog))
 
-GtkWidget *OptionsWindow;
+typedef struct _EtPreferencesDialog EtPreferencesDialog;
+typedef struct _EtPreferencesDialogClass EtPreferencesDialogClass;
+typedef struct _EtPreferencesDialogPrivate EtPreferencesDialogPrivate;
+
+struct _EtPreferencesDialog
+{
+    /*< private >*/
+    GtkDialog parent_instance;
+    EtPreferencesDialogPrivate *priv;
+};
+
+struct _EtPreferencesDialogClass
+{
+    /*< private >*/
+    GtkDialogClass parent_class;
+};
+
+GType et_preferences_dialog_get_type (void);
+EtPreferencesDialog *et_preferences_dialog_new (void);
+void et_preferences_dialog_apply_changes (EtPreferencesDialog *self);
+
+G_END_DECLS
+
+/* FIXME: Remove widget declarations when switching to GSettings. */
 GtkWidget *OptionsNoteBook;
 gint OptionsNoteBook_Scanner_Page_Num;    /* Contains the number of the page "Scanner Option" */
 
@@ -42,8 +66,6 @@ GtkWidget *BrowseSubdir;
 GtkWidget *BrowseHiddendir;
 GtkWidget *OpenSelectedBrowserNode;
 
-GtkListStore *DefaultPathModel;
-
 /* User interface */
 GtkWidget *ShowHeaderInfos;
 GtkWidget *ChangedFilesDisplayedToRed;
@@ -59,7 +81,6 @@ GtkWidget *MessageBoxPositionMouse;
 GtkWidget *MessageBoxPositionCenterOnParent;
 
 GtkWidget *FilePlayerCombo;
-GtkListStore *FilePlayerModel;
 
 /* File Settings */
 GtkWidget *ReplaceIllegalCharactersInFilename;
@@ -131,12 +152,10 @@ GtkWidget *RFSRemoveSpaces;
 GtkWidget *PFSDontUpperSomeWords;
 GtkWidget *OverwriteTagField;
 GtkWidget *OpenScannerWindowOnStartup;
-GtkWidget *ScannerWindowOnTop;
 
 GtkWidget *SetDefaultComment;
 GtkWidget *DefaultComment;
 GtkWidget *Crc32Comment;
-GtkListStore *DefaultCommentModel;
 
 /* CDDB */
 GtkWidget *CddbServerNameAutomaticSearch;
@@ -155,7 +174,6 @@ GtkWidget *CddbProxyUserName;
 GtkWidget *CddbProxyUserPassword;
 
 GtkWidget *CddbLocalPath;
-GtkListStore *CddbLocalPathModel;
 
 GtkWidget *SetCddbWindowSize;
 GtkWidget *CddbWindowWidth;
@@ -177,13 +195,4 @@ GtkWidget *ConfirmDeleteFile;
 GtkWidget *ConfirmWritePlayList;
 GtkWidget *ConfirmWhenUnsavedFiles;
 
-
-/**************
- * Prototypes *
- **************/
-
-void Init_OptionsWindow (void);
-void Open_OptionsWindow (void);
-void OptionsWindow_Apply_Changes (void);
-
-#endif /* __PREFS_H__ */
+#endif /* ET_PREFERENCES_DIALOG_H_ */
diff --git a/src/scan.c b/src/scan.c
index 1a0bf52..326fd5f 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -1,4 +1,3 @@
-/* scan.c - 2000/06/16 */
 /*
  *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
  *  Copyright (C) 2000-2003  Jerome Couderc <easytag gmail com>
@@ -18,7 +17,9 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include <config.h>
+#include "config.h"
+
+#include "scan.h"
 
 #include <gtk/gtk.h>
 #include <string.h>
@@ -27,10 +28,10 @@
 #include <config.h>
 #include <glib/gi18n.h>
 
+#include "application_window.h"
 #include "gtk2_compat.h"
-#include "scan.h"
 #include "easytag.h"
-#include "prefs.h"
+#include "preferences_dialog.h"
 #include "setting.h"
 #include "id3_tag.h"
 #include "bar.h"
@@ -3163,7 +3164,7 @@ void ScannerWindow_Apply_Changes (void)
 static void
 Scan_Option_Button (void)
 {
-    Open_OptionsWindow();
+    et_application_window_show_preferences_dialog (NULL, ET_APPLICATION_WINDOW (MainWindow));
     gtk_notebook_set_current_page(GTK_NOTEBOOK(OptionsNoteBook), OptionsNoteBook_Scanner_Page_Num);
 }
 
diff --git a/src/scan.h b/src/scan.h
index 909f60d..ef95bc4 100644
--- a/src/scan.h
+++ b/src/scan.h
@@ -25,6 +25,8 @@
 
 #include "et_core.h"
 
+#include <gtk/gtk.h>
+
 /****************
  * Declarations *
  ****************/
diff --git a/src/setting.c b/src/setting.c
index 0a1428d..e62be3b 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -1,4 +1,3 @@
-/* config.c - 2000/06/21 */
 /*
  *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
  *  Copyright (C) 2000-2003  Jerome Couderc <easytag gmail com>
@@ -18,7 +17,7 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include <config.h>
+#include "config.h"
 
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
@@ -36,7 +35,7 @@
 #include "application_window.h"
 #include "load_files_dialog.h"
 #include "playlist_dialog.h"
-#include "prefs.h"
+#include "preferences_dialog.h"
 #include "search_dialog.h"
 #include "bar.h"
 #include "easytag.h"
@@ -599,13 +598,16 @@ void Init_Config_Variables (void)
 static void
 Apply_Changes_Of_Preferences_Window (void)
 {
+    GtkWidget *dialog;
     gchar *temp;
     int active;
     ET_Sorting_Type temp_sort;
     gint column_id;
     GtkTreeViewColumn * column;
 
-    if (OptionsWindow)
+    dialog = et_application_window_get_preferences_dialog (ET_APPLICATION_WINDOW (MainWindow));
+
+    if (dialog)
     {
         /* Common */
         LOAD_ON_STARTUP               = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(LoadOnStartup));
@@ -836,8 +838,9 @@ Apply_Changes_Of_UI (void)
      * Changes in user interface
      */
 
-    // Configuration of the preference window (see prefs.c) - Function also called when destroying the window
-    OptionsWindow_Apply_Changes();
+    /* 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.c) - Function also called when destroying the window
     ScannerWindow_Apply_Changes();



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