[easytag/wip/application-window: 15/15] WIP Move browser to EtBrowser object



commit 2ac2a03435932eb280f7ff89086e8a6ed15dc56f
Author: David King <amigadave amigadave com>
Date:   Wed Feb 12 23:06:30 2014 +0000

    WIP Move browser to EtBrowser object
    
    No browser is shown in the main window :-(

 src/application_window.c |   38 +++++-
 src/application_window.h |    2 +
 src/bar.c                |    4 +-
 src/browser.c            |  357 +++++++++++++++++++++++++++++-----------------
 src/browser.h            |   38 +++++-
 5 files changed, 298 insertions(+), 141 deletions(-)
---
diff --git a/src/application_window.c b/src/application_window.c
index 2387ad5..401dc3f 100644
--- a/src/application_window.c
+++ b/src/application_window.c
@@ -46,6 +46,8 @@ G_DEFINE_TYPE (EtApplicationWindow, et_application_window, GTK_TYPE_WINDOW)
 
 struct _EtApplicationWindowPrivate
 {
+    GtkWidget *browser;
+
     GtkWidget *file_area;
     GtkWidget *log_area;
     GtkWidget *tag_area;
@@ -938,16 +940,18 @@ et_tag_field_on_key_press_event (GtkEntry *entry, GdkEventKey *event,
 }
 
 static GtkWidget *
-create_browser_area (void)
+create_browser_area (EtApplicationWindow *self)
 {
+    EtApplicationWindowPrivate *priv;
     GtkWidget *frame;
-    GtkWidget *tree;
+
+    priv = et_application_window_get_instance_private (self);
 
     frame = gtk_frame_new (_("Browser"));
     gtk_container_set_border_width (GTK_CONTAINER (frame), 2);
 
-    tree = Create_Browser_Items (MainWindow);
-    gtk_container_add (GTK_CONTAINER (frame), tree);
+    priv->browser = GTK_WIDGET (et_browser_new ());
+    gtk_container_add (GTK_CONTAINER (frame), priv->browser);
 
     /* 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 */
@@ -1707,7 +1711,7 @@ et_application_window_init (EtApplicationWindow *self)
     priv->hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
 
     /* Browser (Tree + File list + Entry) */
-    widget = create_browser_area ();
+    widget = create_browser_area (self);
     gtk_paned_pack1 (GTK_PANED (priv->hpaned), widget, TRUE, TRUE);
 
     /* Vertical box for FileArea + TagArea */
@@ -1978,6 +1982,30 @@ et_application_window_search_cddb_for_selection (G_GNUC_UNUSED GtkAction *action
     et_cddb_dialog_search_from_selection (ET_CDDB_DIALOG (priv->cddb_dialog));
 }
 
+void
+et_application_window_show_open_directory_with_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);
+
+    et_browser_show_open_directory_with_dialog (ET_BROWSER (priv->browser));
+}
+
+void
+et_application_window_show_open_files_with_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);
+
+    et_browser_show_open_files_with_dialog (ET_BROWSER (priv->browser));
+}
+
 GtkWidget *
 et_application_window_get_scan_dialog (EtApplicationWindow *self)
 {
diff --git a/src/application_window.h b/src/application_window.h
index d4976dd..e51eba5 100644
--- a/src/application_window.h
+++ b/src/application_window.h
@@ -62,6 +62,8 @@ void et_application_window_show_preferences_dialog (GtkAction *action, gpointer
 GtkWidget * et_application_window_get_cddb_dialog (EtApplicationWindow *self);
 void et_application_window_show_cddb_dialog (GtkAction *action, gpointer user_data);
 void et_application_window_search_cddb_for_selection (GtkAction *action, gpointer user_data);
+void et_application_window_show_open_directory_with_dialog (GtkAction *action, gpointer user_data);
+void et_application_window_show_open_files_with_dialog (GtkAction *action, gpointer user_data);
 GtkWidget * et_application_window_get_scan_dialog (EtApplicationWindow *self);
 void et_application_window_show_scan_dialog (GtkAction *action, gpointer user_data);
 void et_application_window_scan_selected_files (GtkAction *action, gpointer user_data);
diff --git a/src/bar.c b/src/bar.c
index 17af974..f2906d6 100644
--- a/src/bar.c
+++ b/src/bar.c
@@ -205,7 +205,7 @@ Create_UI (GtkWindow *window, GtkWidget **ppmenubar, GtkWidget **pptoolbar)
 
         { AM_OPEN_FILE_WITH, GTK_STOCK_OPEN, _("Open Files With…"),
           "<Primary><Shift>O", _("Run a command on the selected files"),
-          G_CALLBACK (Browser_Open_Run_Program_List_Window) },
+          G_CALLBACK (et_application_window_show_open_files_with_dialog) },
         { AM_SELECT_ALL, GTK_STOCK_SELECT_ALL, NULL, "<Primary>A",
           _("Select all"), G_CALLBACK (et_application_window_select_all) },
         { AM_UNSELECT_ALL, "easytag-unselect-all", _("Unselect All"),
@@ -280,7 +280,7 @@ Create_UI (GtkWindow *window, GtkWidget **ppmenubar, GtkWidget **pptoolbar)
         { AM_BROWSE_DIRECTORY_WITH, GTK_STOCK_EXECUTE,
           _("Browse Directory With…"), NULL,
           _("Run a command on the directory"),
-          G_CALLBACK (Browser_Open_Run_Program_Tree_Window) },
+          G_CALLBACK (et_application_window_show_open_directory_with_dialog) },
         { AM_COLLAPSE_TREE, NULL, _("_Collapse Tree"), "<Primary><Shift>C",
           _("Collapse directory tree"), G_CALLBACK (Browser_Tree_Collapse) },
         { AM_INITIALIZE_TREE, GTK_STOCK_REFRESH, _("_Reload Tree"),
diff --git a/src/browser.c b/src/browser.c
index 1366686..9ad390e 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -24,7 +24,9 @@
  * Thomas Nilsson and 4Front Technologies
  */
 
-#include <config.h>
+#include "config.h"
+
+#include "browser.h"
 
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
@@ -41,7 +43,6 @@
 #include "application_window.h"
 #include "gtk2_compat.h"
 #include "easytag.h"
-#include "browser.h"
 #include "et_core.h"
 #include "scan_dialog.h"
 #include "bar.h"
@@ -55,6 +56,19 @@
 
 #include "win32/win32dep.h"
 
+/* TODO: Use G_DEFINE_TYPE_WITH_PRIVATE. */
+G_DEFINE_TYPE (EtBrowser, et_browser, GTK_TYPE_BIN)
+
+#define et_browser_get_instance_private(browser) (browser->priv)
+
+struct _EtBrowserPrivate
+{
+    GtkWidget *open_directory_with_dialog;
+    GtkWidget *open_directory_with_combobox;
+
+    GtkWidget *open_files_with_dialog;
+    GtkWidget *open_files_with_combobox;
+};
 
 /****************
  * Declarations *
@@ -73,9 +87,6 @@ static gchar        *BrowserCurrentPath = NULL;
 
 static GtkListStore *RunProgramModel;
 
-static GtkWidget *RunProgramTreeWindow = NULL;
-static GtkWidget *RunProgramListWindow = NULL;
-
 /* The Rename Directory window. */
 GtkWidget *RenameDirectoryWindow = NULL;
 static GtkWidget *RenameDirectoryCombo;
@@ -184,12 +195,11 @@ static void Rename_Directory (void);
 static void Rename_Directory_With_Mask_Toggled (void);
 
 /* For window to run a program with the directory */
-static void Destroy_Run_Program_Tree_Window (void);
-static void Run_Program_With_Directory (GtkWidget *combobox);
+static void Destroy_Run_Program_Tree_Window (EtBrowser *self);
+static void Run_Program_With_Directory (EtBrowser *self);
 
 /* For window to run a program with the file */
-static void Destroy_Run_Program_List_Window (void);
-static void Run_Program_With_Selected_Files (GtkWidget *combobox);
+static void Destroy_Run_Program_List_Window (EtBrowser *self);
 
 static gboolean Run_Program (const gchar *program_name, GList *args_list);
 
@@ -3080,9 +3090,10 @@ static void collapse_cb (GtkWidget *tree, GtkTreeIter *iter, GtkTreePath *treePa
 /*
  * Create item of the browser (Entry + Tree + List).
  */
-GtkWidget *Create_Browser_Items (GtkWidget *parent)
+static GtkWidget *
+create_browser (EtBrowser *self)
 {
-       GtkWidget *VerticalBox;
+    GtkWidget *VerticalBox;
     GtkWidget *HBox;
     GtkWidget *ScrollWindowDirectoryTree;
     GtkWidget *ScrollWindowFileList;
@@ -3109,7 +3120,6 @@ GtkWidget *Create_Browser_Items (GtkWidget *parent)
     VerticalBox = gtk_box_new(GTK_ORIENTATION_VERTICAL,2);
     gtk_container_set_border_width(GTK_CONTAINER(VerticalBox),2);
 
-
     // HBox for BrowserEntry + BrowserLabel
     HBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0);
     gtk_box_pack_start(GTK_BOX(VerticalBox),HBox,FALSE,TRUE,0);
@@ -3977,18 +3987,23 @@ Rename_Directory_With_Mask_Toggled (void)
  * Window where is typed the name of the program to run, which
  * receives the current directory as parameter.
  */
-void Browser_Open_Run_Program_Tree_Window (void)
+void
+et_browser_show_open_directory_with_dialog (EtBrowser *self)
 {
+    EtBrowserPrivate *priv;
     GtkWidget *VBox;
     GtkWidget *HBox;
     GtkWidget *Label;
-    GtkWidget *RunProgramComboBox;
     GtkWidget *Button;
     gchar *current_directory = NULL;
 
-    if (RunProgramTreeWindow != NULL)
+    g_return_if_fail (ET_BROWSER (self));
+
+    priv = et_browser_get_instance_private (self);
+
+    if (priv->open_directory_with_dialog != NULL)
     {
-        gtk_window_present(GTK_WINDOW(RunProgramTreeWindow));
+        gtk_window_present(GTK_WINDOW(priv->open_directory_with_dialog));
         return;
     }
 
@@ -3997,7 +4012,7 @@ void Browser_Open_Run_Program_Tree_Window (void)
     if (!current_directory || strlen(current_directory)==0)
         return;
 
-    RunProgramTreeWindow = gtk_dialog_new_with_buttons (_("Browse Directory With"),
+    priv->open_directory_with_dialog = gtk_dialog_new_with_buttons (_("Browse Directory With"),
                                                         GTK_WINDOW (MainWindow),
                                                         GTK_DIALOG_DESTROY_WITH_PARENT,
                                                         GTK_STOCK_CANCEL,
@@ -4005,12 +4020,12 @@ void Browser_Open_Run_Program_Tree_Window (void)
                                                         GTK_STOCK_EXECUTE,
                                                         GTK_RESPONSE_OK, NULL);
 
-    gtk_dialog_set_default_response (GTK_DIALOG (RunProgramTreeWindow),
+    gtk_dialog_set_default_response (GTK_DIALOG (priv->open_directory_with_dialog),
                                      GTK_RESPONSE_OK);
-    g_signal_connect (RunProgramTreeWindow, "response",
-                      G_CALLBACK (et_run_program_tree_on_response), NULL);
-    VBox = gtk_dialog_get_content_area (GTK_DIALOG (RunProgramTreeWindow));
-    gtk_container_set_border_width (GTK_CONTAINER (RunProgramTreeWindow),
+    g_signal_connect (priv->open_directory_with_dialog, "response",
+                      G_CALLBACK (et_run_program_tree_on_response), self);
+    VBox = gtk_dialog_get_content_area (GTK_DIALOG (priv->open_directory_with_dialog));
+    gtk_container_set_border_width (GTK_CONTAINER (priv->open_directory_with_dialog),
                                     BOX_SPACING);
 
     Label = gtk_label_new(_("Program to run:"));
@@ -4021,62 +4036,72 @@ void Browser_Open_Run_Program_Tree_Window (void)
     gtk_box_pack_start(GTK_BOX(VBox),HBox,FALSE,FALSE,2);
 
     /* The combobox to enter the program to run */
-    RunProgramComboBox = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(RunProgramModel));
-    gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(RunProgramComboBox), MISC_COMBO_TEXT);
-    gtk_box_pack_start(GTK_BOX(HBox),RunProgramComboBox,TRUE,TRUE,0);
-    gtk_widget_set_size_request(GTK_WIDGET(RunProgramComboBox),250,-1);
-    
gtk_widget_set_tooltip_text(GTK_WIDGET(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(RunProgramComboBox)))),_("Enter 
the program to run. "
+    priv->open_directory_with_combobox = 
gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(RunProgramModel));
+    gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(priv->open_directory_with_combobox), MISC_COMBO_TEXT);
+    gtk_box_pack_start(GTK_BOX(HBox),priv->open_directory_with_combobox,TRUE,TRUE,0);
+    gtk_widget_set_size_request(GTK_WIDGET(priv->open_directory_with_combobox),250,-1);
+    
gtk_widget_set_tooltip_text(GTK_WIDGET(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(priv->open_directory_with_combobox)))),_("Enter
 the program to run. "
         "It will receive the current directory as parameter."));
 
     /* History list */
     gtk_list_store_clear(RunProgramModel);
     Load_Run_Program_With_Directory_List(RunProgramModel, MISC_COMBO_TEXT);
-    g_signal_connect_swapped(G_OBJECT(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(RunProgramComboBox)))),"activate",
-        G_CALLBACK(Run_Program_With_Directory),G_OBJECT(RunProgramComboBox));
+    g_signal_connect_swapped (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->open_directory_with_combobox))),
+                              "activate",
+                              G_CALLBACK (Run_Program_With_Directory),
+                              self);
 
     /* The button to 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(RunProgramComboBox))));
+                             
G_CALLBACK(File_Selection_Window_For_File),G_OBJECT(gtk_bin_get_child(GTK_BIN(priv->open_directory_with_combobox))));
 
     /* We attach useful data to the combobox (into Run_Program_With_Directory) */
-    g_object_set_data(G_OBJECT(RunProgramComboBox), "Current_Directory", current_directory);
+    g_object_set_data(G_OBJECT(priv->open_directory_with_combobox), "Current_Directory", current_directory);
 
     /* Button to execute */
-    Button = gtk_dialog_get_widget_for_response (GTK_DIALOG (RunProgramTreeWindow),
+    Button = gtk_dialog_get_widget_for_response (GTK_DIALOG (priv->open_directory_with_dialog),
                                                  GTK_RESPONSE_OK);
-    g_signal_connect_swapped(G_OBJECT(Button),"clicked", 
G_CALLBACK(Run_Program_With_Directory),G_OBJECT(RunProgramComboBox));
-    g_signal_connect_swapped (gtk_bin_get_child (GTK_BIN (RunProgramComboBox)),
+    g_signal_connect_swapped (Button, "clicked",
+                              G_CALLBACK (Run_Program_With_Directory),
+                              self);
+    g_signal_connect_swapped (gtk_bin_get_child (GTK_BIN (priv->open_directory_with_combobox)),
                               "changed",
                               G_CALLBACK (empty_entry_disable_widget),
                               G_OBJECT (Button));
-    
g_signal_emit_by_name(G_OBJECT(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(RunProgramComboBox)))),"changed",NULL);
+    
g_signal_emit_by_name(G_OBJECT(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(priv->open_directory_with_combobox)))),"changed",NULL);
 
-    gtk_widget_show_all(RunProgramTreeWindow);
+    gtk_widget_show_all(priv->open_directory_with_dialog);
 }
 
 static void
-Destroy_Run_Program_Tree_Window (void)
+Destroy_Run_Program_Tree_Window (EtBrowser *self)
 {
-    if (RunProgramTreeWindow)
+    EtBrowserPrivate *priv;
+
+    priv = et_browser_get_instance_private (self);
+
+    if (priv->open_directory_with_dialog)
     {
-        gtk_widget_destroy(RunProgramTreeWindow);
-        RunProgramTreeWindow = NULL;
+        gtk_widget_hide (priv->open_directory_with_dialog);
     }
 }
 
-void Run_Program_With_Directory (GtkWidget *combobox)
+void
+Run_Program_With_Directory (EtBrowser *self)
 {
+    EtBrowserPrivate *priv;
     gchar *program_name;
     gchar *current_directory;
     GList *args_list = NULL;
     gboolean program_ran;
 
-    g_return_if_fail (GTK_IS_COMBO_BOX (combobox));
+    priv = et_browser_get_instance_private (self);
 
-    program_name      = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combobox)))));
-    current_directory = g_object_get_data(G_OBJECT(combobox), "Current_Directory");
+    program_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN 
(priv->open_directory_with_combobox)))));
+    current_directory = g_object_get_data (G_OBJECT (priv->open_directory_with_combobox),
+                                           "Current_Directory");
 #ifdef G_OS_WIN32
     /* On win32 : 'winamp.exe "c:\path\to\dir"' succeed, while 'winamp.exe "c:\path\to\dir\"' fails */
     ET_Win32_Path_Remove_Trailing_Backslash(current_directory);
@@ -4096,7 +4121,66 @@ void Run_Program_With_Directory (GtkWidget *combobox)
         // Save list attached to the combobox
         Save_Run_Program_With_Directory_List(RunProgramModel, MISC_COMBO_TEXT);
 
-        Destroy_Run_Program_Tree_Window();
+        Destroy_Run_Program_Tree_Window (self);
+    }
+    g_free(program_name);
+}
+
+static void
+Run_Program_With_Selected_Files (EtBrowser *self)
+{
+    EtBrowserPrivate *priv;
+    gchar   *program_name;
+    ET_File *ETFile;
+    GList   *selected_paths;
+    GList *l;
+    GList   *args_list = NULL;
+    GtkTreeIter iter;
+    gboolean program_ran;
+
+    priv = et_browser_get_instance_private (self);
+
+    if (!GTK_IS_COMBO_BOX (priv->open_files_with_combobox) || !ETCore->ETFileDisplayedList)
+        return;
+
+    // Programe name to run
+    program_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN 
(priv->open_files_with_combobox)))));
+
+    // List of files to pass as parameters
+    selected_paths = 
gtk_tree_selection_get_selected_rows(gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList)), NULL);
+
+    for (l = selected_paths; l != NULL; l = g_list_next (l))
+    {
+        if (gtk_tree_model_get_iter (GTK_TREE_MODEL (fileListModel), &iter,
+                                     (GtkTreePath *)l->data))
+        {
+            gtk_tree_model_get(GTK_TREE_MODEL(fileListModel), &iter,
+                               LIST_FILE_POINTER, &ETFile,
+                               -1);
+
+            args_list = g_list_prepend (args_list,
+                                        ((File_Name *)ETFile->FileNameCur->data)->value);
+            //args_list = g_list_append(args_list,((File_Name *)ETFile->FileNameCur->data)->value_utf8);
+        }
+    }
+
+    args_list = g_list_reverse (args_list);
+    program_ran = Run_Program(program_name,args_list);
+
+    g_list_free_full (selected_paths, (GDestroyNotify)gtk_tree_path_free);
+    g_list_free(args_list);
+
+    if (program_ran)
+    {
+        // Append newest choice to the drop down list
+        //gtk_list_store_prepend(GTK_LIST_STORE(RunProgramModel), &iter);
+        //gtk_list_store_set(RunProgramModel, &iter, MISC_COMBO_TEXT, program_name, -1);
+        Add_String_To_Combo_List(GTK_LIST_STORE(RunProgramModel), program_name);
+
+        // Save list attached to the combobox
+        Save_Run_Program_With_File_List(RunProgramModel, MISC_COMBO_TEXT);
+
+        Destroy_Run_Program_List_Window (self);
     }
     g_free(program_name);
 }
@@ -4105,21 +4189,26 @@ void Run_Program_With_Directory (GtkWidget *combobox)
  * Window where is typed the name of the program to run, which
  * receives the current file as parameter.
  */
-void Browser_Open_Run_Program_List_Window (void)
+void
+et_browser_show_open_files_with_dialog (EtBrowser *self)
 {
+    EtBrowserPrivate *priv;
     GtkWidget *VBox;
     GtkWidget *HBox;
     GtkWidget *Label;
-    GtkWidget *RunProgramComboBox;
     GtkWidget *Button;
 
-    if (RunProgramListWindow != NULL)
+    g_return_if_fail (ET_BROWSER (self));
+
+    priv = et_browser_get_instance_private (self);
+
+    if (priv->open_files_with_dialog != NULL)
     {
-        gtk_window_present(GTK_WINDOW(RunProgramListWindow));
+        gtk_window_present(GTK_WINDOW(priv->open_files_with_dialog));
         return;
     }
 
-    RunProgramListWindow = gtk_dialog_new_with_buttons (_("Open Files With"),
+    priv->open_files_with_dialog = gtk_dialog_new_with_buttons (_("Open Files With"),
                                                         GTK_WINDOW (MainWindow),
                                                         GTK_DIALOG_DESTROY_WITH_PARENT,
                                                         GTK_STOCK_CANCEL,
@@ -4128,15 +4217,15 @@ void Browser_Open_Run_Program_List_Window (void)
                                                         GTK_RESPONSE_OK,
                                                         NULL);
 
-    gtk_dialog_set_default_response (GTK_DIALOG (RunProgramListWindow),
+    gtk_dialog_set_default_response (GTK_DIALOG (priv->open_files_with_dialog),
                                      GTK_RESPONSE_OK);
-    g_signal_connect ((RunProgramListWindow), "response",
-                      G_CALLBACK (et_run_program_list_on_response), NULL);
+    g_signal_connect ((priv->open_files_with_dialog), "response",
+                      G_CALLBACK (et_run_program_list_on_response), self);
 
-    gtk_container_set_border_width (GTK_CONTAINER (RunProgramListWindow),
+    gtk_container_set_border_width (GTK_CONTAINER (priv->open_files_with_dialog),
                                     BOX_SPACING);
 
-    VBox = gtk_dialog_get_content_area (GTK_DIALOG (RunProgramListWindow));
+    VBox = gtk_dialog_get_content_area (GTK_DIALOG (priv->open_files_with_dialog));
     gtk_container_set_border_width (GTK_CONTAINER(VBox), BOX_SPACING);
 
     Label = gtk_label_new(_("Program to run:"));
@@ -4147,102 +4236,57 @@ void Browser_Open_Run_Program_List_Window (void)
     gtk_box_pack_start(GTK_BOX(VBox),HBox,FALSE,FALSE,0);
 
     /* The combobox to enter the program to run */
-    RunProgramComboBox = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(RunProgramModel));
-    gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(RunProgramComboBox),MISC_COMBO_TEXT);
-    gtk_box_pack_start(GTK_BOX(HBox),RunProgramComboBox,TRUE,TRUE,0);
-    gtk_widget_set_size_request(GTK_WIDGET(RunProgramComboBox),250,-1);
-    
gtk_widget_set_tooltip_text(GTK_WIDGET(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(RunProgramComboBox)))),_("Enter 
the program to run. "
-        "It will receive the current file as parameter."));
+    priv->open_files_with_combobox = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(RunProgramModel));
+    gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (priv->open_files_with_combobox),
+                                         MISC_COMBO_TEXT);
+    gtk_box_pack_start (GTK_BOX (HBox), priv->open_files_with_combobox, TRUE,
+                        TRUE, 0);
+    gtk_widget_set_size_request (GTK_WIDGET (priv->open_files_with_combobox),
+                                 250, -1);
+    gtk_widget_set_tooltip_text (GTK_WIDGET (gtk_bin_get_child (GTK_BIN (priv->open_files_with_combobox))),
+                                 _("Enter the program to run. It will receive the current file as 
parameter."));
 
     /* History list */
     gtk_list_store_clear(RunProgramModel);
     Load_Run_Program_With_File_List(RunProgramModel, MISC_COMBO_TEXT);
-    g_signal_connect_swapped(G_OBJECT(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(RunProgramComboBox)))),"activate",
-        G_CALLBACK(Run_Program_With_Selected_Files),G_OBJECT(RunProgramComboBox));
+    g_signal_connect_swapped (gtk_bin_get_child (GTK_BIN (priv->open_files_with_combobox)),
+                              "activate",
+                              G_CALLBACK (Run_Program_With_Selected_Files),
+                             self);
 
     /* The button to 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(RunProgramComboBox))));
+                             
G_CALLBACK(File_Selection_Window_For_File),G_OBJECT(gtk_bin_get_child(GTK_BIN(priv->open_files_with_combobox))));
 
     /* Button to execute */
-    Button = gtk_dialog_get_widget_for_response (GTK_DIALOG (RunProgramListWindow),
+    Button = gtk_dialog_get_widget_for_response (GTK_DIALOG (priv->open_files_with_dialog),
                                                  GTK_RESPONSE_OK);
-    g_signal_connect_swapped(G_OBJECT(Button),"clicked", 
G_CALLBACK(Run_Program_With_Selected_Files),G_OBJECT(RunProgramComboBox));
-    g_signal_connect_swapped (gtk_bin_get_child (GTK_BIN (RunProgramComboBox)),
+    g_signal_connect_swapped (Button, "clicked",
+                              G_CALLBACK (Run_Program_With_Selected_Files),
+                             self);
+    g_signal_connect_swapped (gtk_bin_get_child (GTK_BIN (priv->open_files_with_combobox)),
                               "changed",
                               G_CALLBACK (empty_entry_disable_widget),
                               G_OBJECT (Button));
-    
g_signal_emit_by_name(G_OBJECT(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(RunProgramComboBox)))),"changed",NULL);
-
-    gtk_widget_show_all(RunProgramListWindow);
-}
+    g_signal_emit_by_name (gtk_bin_get_child (GTK_BIN (priv->open_files_with_combobox)),
+                           "changed", NULL);
 
-static void
-Destroy_Run_Program_List_Window (void)
-{
-    if (RunProgramListWindow)
-    {
-        gtk_widget_destroy(RunProgramListWindow);
-        RunProgramListWindow = NULL;
-    }
+    gtk_widget_show_all(priv->open_files_with_dialog);
 }
 
 static void
-Run_Program_With_Selected_Files (GtkWidget *combobox)
+Destroy_Run_Program_List_Window (EtBrowser *self)
 {
-    gchar   *program_name;
-    ET_File *ETFile;
-    GList   *selected_paths;
-    GList *l;
-    GList   *args_list = NULL;
-    GtkTreeIter iter;
-    gboolean program_ran;
+    EtBrowserPrivate *priv;
 
-    if (!GTK_IS_COMBO_BOX(combobox) || !ETCore->ETFileDisplayedList)
-        return;
-
-    // Programe name to run
-    program_name = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combobox)))));
+    priv = et_browser_get_instance_private (self);
 
-    // List of files to pass as parameters
-    selected_paths = 
gtk_tree_selection_get_selected_rows(gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList)), NULL);
-
-    for (l = selected_paths; l != NULL; l = g_list_next (l))
+    if (priv->open_files_with_dialog)
     {
-        if (gtk_tree_model_get_iter (GTK_TREE_MODEL (fileListModel), &iter,
-                                     (GtkTreePath *)l->data))
-        {
-            gtk_tree_model_get(GTK_TREE_MODEL(fileListModel), &iter,
-                               LIST_FILE_POINTER, &ETFile,
-                               -1);
-
-            args_list = g_list_prepend (args_list,
-                                        ((File_Name *)ETFile->FileNameCur->data)->value);
-            //args_list = g_list_append(args_list,((File_Name *)ETFile->FileNameCur->data)->value_utf8);
-        }
+        gtk_widget_hide (priv->open_files_with_dialog);
     }
-
-    args_list = g_list_reverse (args_list);
-    program_ran = Run_Program(program_name,args_list);
-
-    g_list_free_full (selected_paths, (GDestroyNotify)gtk_tree_path_free);
-    g_list_free(args_list);
-
-    if (program_ran)
-    {
-        // Append newest choice to the drop down list
-        //gtk_list_store_prepend(GTK_LIST_STORE(RunProgramModel), &iter);
-        //gtk_list_store_set(RunProgramModel, &iter, MISC_COMBO_TEXT, program_name, -1);
-        Add_String_To_Combo_List(GTK_LIST_STORE(RunProgramModel), program_name);
-
-        // Save list attached to the combobox
-        Save_Run_Program_With_File_List(RunProgramModel, MISC_COMBO_TEXT);
-
-        Destroy_Run_Program_List_Window();
-    }
-    g_free(program_name);
 }
 
 /*
@@ -4468,6 +4512,10 @@ static void
 et_run_program_tree_on_response (GtkDialog *dialog, gint response_id,
                                  gpointer user_data)
 {
+    EtBrowser *self;
+
+    self = ET_BROWSER (user_data);
+
     switch (response_id)
     {
         case GTK_RESPONSE_OK:
@@ -4475,7 +4523,7 @@ et_run_program_tree_on_response (GtkDialog *dialog, gint response_id,
             break;
         case GTK_RESPONSE_CANCEL:
         case GTK_RESPONSE_DELETE_EVENT:
-            Destroy_Run_Program_Tree_Window ();
+            Destroy_Run_Program_Tree_Window (self);
             break;
         default:
             g_assert_not_reached ();
@@ -4493,6 +4541,10 @@ static void
 et_run_program_list_on_response (GtkDialog *dialog, gint response_id,
                                  gpointer user_data)
 {
+    EtBrowser *self;
+
+    self = ET_BROWSER (user_data);
+
     switch (response_id)
     {
         case GTK_RESPONSE_OK:
@@ -4500,7 +4552,7 @@ et_run_program_list_on_response (GtkDialog *dialog, gint response_id,
             break;
         case GTK_RESPONSE_CANCEL:
         case GTK_RESPONSE_DELETE_EVENT:
-            Destroy_Run_Program_List_Window ();
+            Destroy_Run_Program_List_Window (self);
             break;
         default:
             g_assert_not_reached ();
@@ -4535,3 +4587,50 @@ get_column_for_column_id (gint column_id)
 {
     return gtk_tree_view_get_column (GTK_TREE_VIEW (BrowserList), column_id);
 }
+
+static void
+et_browser_finalize (GObject *object)
+{
+    G_OBJECT_CLASS (et_browser_parent_class)->finalize (object);
+}
+
+static void
+et_browser_init (EtBrowser *self)
+{
+    EtBrowserPrivate *priv;
+    GtkWidget *browser;
+
+    priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ET_TYPE_BROWSER,
+                                                     EtBrowserPrivate);
+
+    priv->open_directory_with_dialog = NULL;
+    priv->open_directory_with_combobox = NULL;
+    priv->open_files_with_dialog = NULL;
+    priv->open_files_with_combobox = NULL;
+
+    browser = create_browser (self);
+    gtk_container_add (GTK_CONTAINER (self), browser);
+
+    gtk_widget_show_all (GTK_WIDGET (self));
+}
+
+static void
+et_browser_class_init (EtBrowserClass *klass)
+{
+    G_OBJECT_CLASS (klass)->finalize = et_browser_finalize;
+
+    g_type_class_add_private (klass, sizeof (EtBrowserPrivate));
+}
+
+/*
+ * et_browser_new:
+ *
+ * Create a new EtBrowser instance.
+ *
+ * Returns: a new #EtBrowser
+ */
+EtBrowser *
+et_browser_new (void)
+{
+    return g_object_new (ET_TYPE_BROWSER, NULL);
+}
diff --git a/src/browser.h b/src/browser.h
index 5965379..489fe81 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -1,4 +1,3 @@
-/* browser.h - 2000/04/28 */
 /*
  *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
  *  Copyright (C) 2000-2003  Jerome Couderc <easytag gmail com>
@@ -19,11 +18,41 @@
  */
 
 
-#ifndef __BROWSER_H__
-#define __BROWSER_H__
+#ifndef ET_BROWSER_H_
+#define ET_BROWSER_H_
 
 #include "et_core.h"
 
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define ET_TYPE_BROWSER (et_browser_get_type ())
+#define ET_BROWSER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), ET_TYPE_BROWSER, EtBrowser))
+
+typedef struct _EtBrowser EtBrowser;
+typedef struct _EtBrowserClass EtBrowserClass;
+typedef struct _EtBrowserPrivate EtBrowserPrivate;
+
+struct _EtBrowser
+{
+    /*< private >*/
+    GtkBin parent_instance;
+    EtBrowserPrivate *priv;
+};
+
+struct _EtBrowserClass
+{
+    /*< private >*/
+    GtkBinClass parent_class;
+};
+
+GType et_browser_get_type (void);
+EtBrowser *et_browser_new (void);
+void et_browser_show_open_directory_with_dialog (EtBrowser *self);
+void et_browser_show_open_files_with_dialog (EtBrowser *self);
+
+G_END_DECLS
 
 /****************
  * Declarations *
@@ -142,7 +171,6 @@ GtkWidget *RenameDirectoryPreviewLabel;
  * Prototypes *
  **************/
 
-GtkWidget   *Create_Browser_Items    (GtkWidget *parent);
 gboolean     Browser_Tree_Select_Dir (const gchar *current_path);
 void         Browser_Tree_Rebuild    (gchar *path_to_load);
 void         Browser_Tree_Collapse   (void);
@@ -189,4 +217,4 @@ void         Browser_Open_Run_Program_List_Window (void);
 GtkTreeViewColumn *get_column_for_column_id (gint column_id);
 GtkSortType get_sort_order_for_column_id (gint column_id);
 
-#endif /* __BROWSER_H__ */
+#endif /* ET_BROWSER_H_ */


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