#include "ardour/audio_library.h"\r
#include "ardour/rc_configuration.h"\r
#include "pbd/pthread_utils.h"\r
+#include "gui_thread.h"\r
\r
using namespace PBD;\r
\r
\r
return (void *) res;\r
}\r
-\r
-static int \r
-donewithMootcher(void *arg) \r
+ \r
+void\r
+Mootcher::doneWithMootcher()\r
{\r
- Mootcher *thisMootcher = (Mootcher *) arg;\r
\r
// update the sound info pane if the selection in the list box is still us \r
- thisMootcher->sfb->refresh_display(thisMootcher->ID, thisMootcher->audioFileName);\r
+ sfb->refresh_display(ID, audioFileName);\r
\r
- delete(thisMootcher);\r
- return 0;\r
+ delete this; // XXX is this a good idea?\r
}\r
\r
static void *\r
\r
// std::cerr << "freesound_download_thread_func(" << arg << ")" << std::endl;\r
res = thisMootcher->threadFunc();\r
- g_idle_add(donewithMootcher, thisMootcher);\r
\r
+ thisMootcher->Finished(); /* EMIT SIGNAL */\r
return res;\r
}\r
\r
curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION, progress_callback);\r
curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, this);\r
\r
+ Progress.connect(*this, invalidator (*this), boost::bind(&Mootcher::updateProgress, this, _1, _2), gui_context());\r
+ Finished.connect(*this, invalidator (*this), boost::bind(&Mootcher::doneWithMootcher, this), gui_context());\r
pthread_t freesound_download_thread;\r
pthread_create_and_store("freesound_import", &freesound_download_thread, freesound_download_thread_func, this);\r
\r
}\r
\r
//---------\r
-struct progressInfo {\r
- Gtk::ProgressBar *bar;\r
- double dltotal;\r
- double dlnow;\r
-};\r
\r
-static int \r
-updateProgress(void *arg) \r
+void \r
+Mootcher::updateProgress(double dlnow, double dltotal) \r
{\r
- struct progressInfo *progress = (struct progressInfo *) arg;\r
- if (progress->dltotal > 0) {\r
- double fraction = progress->dlnow / progress->dltotal;\r
+ if (dltotal > 0) {\r
+ double fraction = dlnow / dltotal;\r
// std::cerr << "progress idle: " << progress->bar->get_text() << ". " << progress->dlnow << " / " << progress->dltotal << " = " << fraction << std::endl;\r
if (fraction > 1.0) {\r
fraction = 1.0;\r
} else if (fraction < 0.0) {\r
fraction = 0.0;\r
}\r
- progress->bar->set_fraction(fraction);\r
+ progress_bar.set_fraction(fraction);\r
}\r
-\r
- delete progress;\r
- return 0;\r
}\r
\r
int \r
return -1;\r
}\r
\r
- struct progressInfo *progress = new struct progressInfo;\r
- progress->bar = &thisMootcher->progress_bar;\r
- progress->dltotal = dltotal;\r
- progress->dlnow = dlnow;\r
-\r
- g_idle_add(updateProgress, progress);\r
+ thisMootcher->Progress(dlnow, dltotal); /* EMIT SIGNAL */\r
return 0;\r
}\r
\r
};
-class Mootcher
+class Mootcher: public sigc::trackable, public PBD::ScopedConnectionList
{
public:
Mootcher();
std::string audioFileName;
std::string ID;
+ /** signal emitted when mootcher reports progress updates during download.
+ * The parameters are current and total numbers of bytes downloaded.
+ */
+ PBD::Signal2<void, double, double> Progress;
+ /** signal emitted when the mootcher has finished downloading. */
+ PBD::Signal0<void> Finished;
+
+
private:
void ensureWorkingDir();
FILE* theFile;
+ void updateProgress(double dlnow, double dltotal);
+ void doneWithMootcher();
+
Gtk::HBox progress_hbox;
Gtk::ProgressBar progress_bar;
Gtk::Button cancel_download_btn;