colinf's 2011-12-08 patch for freesound mootcher (add stop, remove URI, clear barberp...
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 18 Jan 2012 18:43:43 +0000 (18:43 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 18 Jan 2012 18:43:43 +0000 (18:43 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@11265 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/sfdb_freesound_mootcher.cc
gtk2_ardour/sfdb_freesound_mootcher.h
gtk2_ardour/sfdb_ui.cc
gtk2_ardour/sfdb_ui.h

index 69c13794f6270e20c94289fae5fe32f4c85fb15e..3b558e17e14ee75ccccaddb8b271464cd097f403 100644 (file)
@@ -139,7 +139,7 @@ void Mootcher::setcUrlOptions()
        \r
        // Allow connections to time out (without using signals)\r
        curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);\r
-       curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);\r
+       curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30);\r
 \r
 \r
 }\r
@@ -295,7 +295,7 @@ int audioFileWrite(void *buffer, size_t size, size_t nmemb, void *file)
 };\r
 \r
 //------------------------------------------------------------------------\r
-std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID, std::string audioURL, Gtk::ProgressBar *progress_bar)\r
+std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller)\r
 {\r
        ensureWorkingDir();\r
        std::string audioFileName = basePath + "snd/" + ID + "-" + originalFileName;\r
@@ -332,17 +332,20 @@ std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID,
                        curl_easy_setopt(curl, CURLOPT_WRITEDATA, theFile);\r
 \r
                        std::cerr << "downloading " << audioFileName << " from " << audioURL << "..." << std::endl;\r
+                       /* hack to get rid of the barber-pole stripes */\r
+                       caller->progress_bar.hide();\r
+                       caller->progress_bar.show();\r
 \r
                        curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 0); // turn on the progress bar\r
                        curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION, progress_callback);\r
-                       curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, progress_bar);\r
+                       curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, caller);\r
 \r
                        CURLcode res = curl_easy_perform(curl);\r
                        fclose(theFile);\r
 \r
                        curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 1); // turn off the progress bar\r
-                       progress_bar->set_fraction(0.0);\r
-\r
+                       caller->progress_bar.set_fraction(0.0);\r
+                       \r
                        if( res != 0 ) {\r
                                std::cerr <<  "curl error " << res << " (" << curl_easy_strerror(res) << ")" << std::endl;\r
                                remove( audioFileName.c_str() );  \r
@@ -359,14 +362,18 @@ std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID,
 }\r
 \r
 //---------\r
-int Mootcher::progress_callback(void *bar, double dltotal, double dlnow, double ultotal, double ulnow)\r
+int Mootcher::progress_callback(void *caller, double dltotal, double dlnow, double ultotal, double ulnow)\r
 {\r
 \r
+SoundFileBrowser *sfb = (SoundFileBrowser *) caller;\r
        //XXX I hope it's OK to do GTK things in this callback. Otherwise\r
        // I'll have to do stuff like in interthread_progress_window.\r
+       if (sfb->freesound_stop) {\r
+               return -1;\r
+       }\r
+       \r
        \r
-       Gtk::ProgressBar *progress_bar = (Gtk::ProgressBar *) bar;\r
-       progress_bar->set_fraction(dlnow/dltotal);\r
+       sfb->progress_bar.set_fraction(dlnow/dltotal);\r
        /* Make sure the progress widget gets updated */\r
        while (Glib::MainContext::get_default()->iteration (false)) {\r
                /* do nothing */\r
index 9f5c38c0fd6619c86114b79cc83e45f569dd3bc4..3de05570151bc56816faaadbe20e5e23fffd340a 100644 (file)
@@ -23,6 +23,8 @@
 #include <gtkmm/progressbar.h>\r
 //#include <ctime>\r
 \r
+#include "sfdb_ui.h"\r
+\r
 #include "curl/curl.h"\r
 \r
 //--- struct to store XML file\r
@@ -50,7 +52,7 @@ public:
        Mootcher(const char *saveLocation);\r
        ~Mootcher();\r
 \r
-       std::string     getAudioFile(std::string originalFileName, std::string ID, std::string audioURL, Gtk::ProgressBar *progress_bar);\r
+       std::string     getAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller);\r
        std::string     searchText(std::string query, int page, std::string filter, enum sortMethod sort);\r
 \r
 private:\r
index cc9f734b491087703db660668bd6d7f1e1c27986..8d8c10b350568195d13633ea34e13e41e3666efd 100644 (file)
@@ -548,6 +548,8 @@ SoundFileBrowser::SoundFileBrowser (Gtk::Window& parent, string title, ARDOUR::S
                
                passbox->pack_start (freesound_search_btn, false, false);
                passbox->pack_start (progress_bar);
+               passbox->pack_end   (freesound_stop_btn, false, false);
+               freesound_stop_btn.set_label(_("Stop"));
                
                Gtk::ScrolledWindow *scroll = manage(new ScrolledWindow);
                scroll->add(freesound_list_view);
@@ -559,13 +561,14 @@ SoundFileBrowser::SoundFileBrowser (Gtk::Window& parent, string title, ARDOUR::S
 
                freesound_list_view.append_column(_("ID")      , freesound_list_columns.id);
                freesound_list_view.append_column(_("Filename"), freesound_list_columns.filename);
-               freesound_list_view.append_column(_("URI")     , freesound_list_columns.uri);
+               // freesound_list_view.append_column(_("URI")     , freesound_list_columns.uri);
                freesound_list_view.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_list_view_selected));
 
                freesound_list_view.get_selection()->set_mode (SELECTION_MULTIPLE);
                freesound_list_view.signal_row_activated().connect (sigc::mem_fun (*this, &SoundFileBrowser::freesound_list_view_activated));
                freesound_search_btn.signal_clicked().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_search_clicked));
                freesound_entry.signal_activate().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_search_clicked));
+               freesound_stop_btn.signal_clicked().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_stop_clicked));
                notebook.append_page (*vbox, _("Search Freesound"));
        }
 #endif
@@ -756,12 +759,15 @@ SoundFileBrowser::freesound_list_view_selected ()
                        gdk_window_set_cursor (get_window()->gobj(), gdk_cursor_new(GDK_WATCH));
                        gdk_flush();
 
-                       file = theMootcher.getAudioFile(ofn, id, uri, &progress_bar);
+                       freesound_stop = false;
+                       file = theMootcher.getAudioFile(ofn, id, uri, this);
 
                        gdk_window_set_cursor (get_window()->gobj(), prev_cursor);
 
-                       chooser.set_filename (file);
-                       set_response_sensitive (RESPONSE_OK, true);
+                       if (file != "") {
+                               chooser.set_filename (file);
+                               set_response_sensitive (RESPONSE_OK, true);
+                       }
                } else {
                        set_response_sensitive (RESPONSE_OK, false);
                }
@@ -801,6 +807,12 @@ SoundFileBrowser::freesound_search_clicked ()
        freesound_search();
 }
 
+void
+SoundFileBrowser::freesound_stop_clicked ()
+{
+       freesound_stop = true;
+}
+
 
 void
 SoundFileBrowser::freesound_search()
@@ -940,8 +952,11 @@ SoundFileBrowser::get_paths ()
                        gdk_window_set_cursor (get_window()->gobj(), gdk_cursor_new(GDK_WATCH));
                        gdk_flush();
 
-                       string str = theMootcher.getAudioFile(ofn, id, uri, &progress_bar);
-                       results.push_back (str);
+                       freesound_stop = false;
+                       string str = theMootcher.getAudioFile(ofn, id, uri, this);
+                       if (str != "") {
+                               results.push_back (str);
+                       }
                        
                        gdk_window_set_cursor (get_window()->gobj(), prev_cursor);
 
index 4a4bdf9c7d2aa84de8fd85493c54f6fec4c11047..45ee3e9b649ce0c81de17f3b859d2caee8fe2479 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <sigc++/signal.h>
 
+#include <gtkmm/stock.h>
 #include <gtkmm/box.h>
 #include <gtkmm/button.h>
 #include <gtkmm/checkbutton.h>
 #include <gtkmm/frame.h>
 #include <gtkmm/label.h>
 #include <gtkmm/textview.h>
+#include <gtkmm/table.h>
+#include <gtkmm/liststore.h>
+#include <gtkmm/spinbutton.h>
+#include <gtkmm/notebook.h>
+
 
 #include "ardour/audiofilesource.h"
 #include "ardour/session_handle.h"
@@ -130,7 +136,7 @@ class SoundFileBrowser : public ArdourDialog
        FreesoundColumns freesound_list_columns;
        Glib::RefPtr<Gtk::ListStore> freesound_list;
 
-       Gtk::ProgressBar progress_bar;
+       Gtk::Button freesound_stop_btn;
 
   public:
        SoundFileBrowser (Gtk::Window& parent, std::string title, ARDOUR::Session* _s, bool persistent);
@@ -155,6 +161,9 @@ class SoundFileBrowser : public ArdourDialog
        
        Gtk::Button freesound_search_btn;
        Gtk::TreeView freesound_list_view;
+       Gtk::ProgressBar progress_bar;
+
+       bool freesound_stop;
 
        void freesound_search();
 
@@ -189,7 +198,8 @@ class SoundFileBrowser : public ArdourDialog
        void freesound_list_view_selected ();
        void freesound_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*);
        void freesound_search_clicked ();
-
+       void freesound_stop_clicked ();
+       
        void chooser_file_activated ();
 
        bool on_audio_filter (const Gtk::FileFilter::Info& filter_info);