summaryrefslogtreecommitdiff
path: root/gtk2_ardour/sfdb_freesound_mootcher.cc
diff options
context:
space:
mode:
authorColin Fletcher <colin.m.fletcher@googlemail.com>2013-06-16 15:43:43 +0100
committerColin Fletcher <colin.m.fletcher@googlemail.com>2013-06-21 21:30:52 +0100
commit8ad4924b7f6d12037753e0a93b5f861b443614ae (patch)
treec42f03fc81fe5cb9090f3cd80d5dad1de28b2f1c /gtk2_ardour/sfdb_freesound_mootcher.cc
parent0483803186c83e27db708f77189a4dc9974f1712 (diff)
Use connect(..., gui_thread()) rather than g_idle_add().
Use the proper functions to ensure things happen in the main gui thread, instead of fudging around with g_idle_add().
Diffstat (limited to 'gtk2_ardour/sfdb_freesound_mootcher.cc')
-rw-r--r--gtk2_ardour/sfdb_freesound_mootcher.cc43
1 files changed, 15 insertions, 28 deletions
diff --git a/gtk2_ardour/sfdb_freesound_mootcher.cc b/gtk2_ardour/sfdb_freesound_mootcher.cc
index 38d53aaa70..e6861cd1f4 100644
--- a/gtk2_ardour/sfdb_freesound_mootcher.cc
+++ b/gtk2_ardour/sfdb_freesound_mootcher.cc
@@ -55,6 +55,7 @@
#include "ardour/audio_library.h"
#include "ardour/rc_configuration.h"
#include "pbd/pthread_utils.h"
+#include "gui_thread.h"
using namespace PBD;
@@ -331,17 +332,15 @@ CURLcode res;
return (void *) res;
}
-
-static int
-donewithMootcher(void *arg)
+
+void
+Mootcher::doneWithMootcher()
{
- Mootcher *thisMootcher = (Mootcher *) arg;
// update the sound info pane if the selection in the list box is still us
- thisMootcher->sfb->refresh_display(thisMootcher->ID, thisMootcher->audioFileName);
+ sfb->refresh_display(ID, audioFileName);
- delete(thisMootcher);
- return 0;
+ delete this; // XXX is this a good idea?
}
static void *
@@ -352,8 +351,8 @@ freesound_download_thread_func(void *arg)
// std::cerr << "freesound_download_thread_func(" << arg << ")" << std::endl;
res = thisMootcher->threadFunc();
- g_idle_add(donewithMootcher, thisMootcher);
+ thisMootcher->Finished(); /* EMIT SIGNAL */
return res;
}
@@ -421,6 +420,8 @@ bool Mootcher::fetchAudioFile(std::string originalFileName, std::string theID, s
curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, this);
+ Progress.connect(*this, invalidator (*this), boost::bind(&Mootcher::updateProgress, this, _1, _2), gui_context());
+ Finished.connect(*this, invalidator (*this), boost::bind(&Mootcher::doneWithMootcher, this), gui_context());
pthread_t freesound_download_thread;
pthread_create_and_store("freesound_import", &freesound_download_thread, freesound_download_thread_func, this);
@@ -428,29 +429,20 @@ bool Mootcher::fetchAudioFile(std::string originalFileName, std::string theID, s
}
//---------
-struct progressInfo {
- Gtk::ProgressBar *bar;
- double dltotal;
- double dlnow;
-};
-static int
-updateProgress(void *arg)
+void
+Mootcher::updateProgress(double dlnow, double dltotal)
{
- struct progressInfo *progress = (struct progressInfo *) arg;
- if (progress->dltotal > 0) {
- double fraction = progress->dlnow / progress->dltotal;
+ if (dltotal > 0) {
+ double fraction = dlnow / dltotal;
// std::cerr << "progress idle: " << progress->bar->get_text() << ". " << progress->dlnow << " / " << progress->dltotal << " = " << fraction << std::endl;
if (fraction > 1.0) {
fraction = 1.0;
} else if (fraction < 0.0) {
fraction = 0.0;
}
- progress->bar->set_fraction(fraction);
+ progress_bar.set_fraction(fraction);
}
-
- delete progress;
- return 0;
}
int
@@ -466,12 +458,7 @@ Mootcher::progress_callback(void *caller, double dltotal, double dlnow, double /
return -1;
}
- struct progressInfo *progress = new struct progressInfo;
- progress->bar = &thisMootcher->progress_bar;
- progress->dltotal = dltotal;
- progress->dlnow = dlnow;
-
- g_idle_add(updateProgress, progress);
+ thisMootcher->Progress(dlnow, dltotal); /* EMIT SIGNAL */
return 0;
}