From 577469a06aa48310ec5cd9a6428f32c35fca5fcb Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 18 Jan 2012 18:43:43 +0000 Subject: colinf's 2011-12-08 patch for freesound mootcher (add stop, remove URI, clear barberpole, etc) git-svn-id: svn://localhost/ardour2/branches/3.0@11265 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/sfdb_freesound_mootcher.cc | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'gtk2_ardour/sfdb_freesound_mootcher.cc') diff --git a/gtk2_ardour/sfdb_freesound_mootcher.cc b/gtk2_ardour/sfdb_freesound_mootcher.cc index 69c13794f6..3b558e17e1 100644 --- a/gtk2_ardour/sfdb_freesound_mootcher.cc +++ b/gtk2_ardour/sfdb_freesound_mootcher.cc @@ -139,7 +139,7 @@ void Mootcher::setcUrlOptions() // Allow connections to time out (without using signals) curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10); + curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30); } @@ -295,7 +295,7 @@ int audioFileWrite(void *buffer, size_t size, size_t nmemb, void *file) }; //------------------------------------------------------------------------ -std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID, std::string audioURL, Gtk::ProgressBar *progress_bar) +std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller) { ensureWorkingDir(); std::string audioFileName = basePath + "snd/" + ID + "-" + originalFileName; @@ -332,17 +332,20 @@ std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID, curl_easy_setopt(curl, CURLOPT_WRITEDATA, theFile); std::cerr << "downloading " << audioFileName << " from " << audioURL << "..." << std::endl; + /* hack to get rid of the barber-pole stripes */ + caller->progress_bar.hide(); + caller->progress_bar.show(); curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 0); // turn on the progress bar curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION, progress_callback); - curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, progress_bar); + curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, caller); CURLcode res = curl_easy_perform(curl); fclose(theFile); curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 1); // turn off the progress bar - progress_bar->set_fraction(0.0); - + caller->progress_bar.set_fraction(0.0); + if( res != 0 ) { std::cerr << "curl error " << res << " (" << curl_easy_strerror(res) << ")" << std::endl; remove( audioFileName.c_str() ); @@ -359,14 +362,18 @@ std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID, } //--------- -int Mootcher::progress_callback(void *bar, double dltotal, double dlnow, double ultotal, double ulnow) +int Mootcher::progress_callback(void *caller, double dltotal, double dlnow, double ultotal, double ulnow) { +SoundFileBrowser *sfb = (SoundFileBrowser *) caller; //XXX I hope it's OK to do GTK things in this callback. Otherwise // I'll have to do stuff like in interthread_progress_window. + if (sfb->freesound_stop) { + return -1; + } + - Gtk::ProgressBar *progress_bar = (Gtk::ProgressBar *) bar; - progress_bar->set_fraction(dlnow/dltotal); + sfb->progress_bar.set_fraction(dlnow/dltotal); /* Make sure the progress widget gets updated */ while (Glib::MainContext::get_default()->iteration (false)) { /* do nothing */ -- cgit v1.2.3