[PATCH 3/7] Add infrastructure to emit progress from threads

Anton Lundin glance at acc.umu.se
Tue Jan 20 13:40:51 PST 2015


Signed-off-by: Anton Lundin <glance at acc.umu.se>
---
 configuredivecomputerthreads.cpp | 20 ++++++++++++++++++++
 configuredivecomputerthreads.h   |  3 +++
 2 files changed, 23 insertions(+)

diff --git a/configuredivecomputerthreads.cpp b/configuredivecomputerthreads.cpp
index b2dc8c8..2e69e53 100644
--- a/configuredivecomputerthreads.cpp
+++ b/configuredivecomputerthreads.cpp
@@ -1393,6 +1393,26 @@ DeviceThread::DeviceThread(QObject *parent, device_data_t *data) : QThread(paren
 {
 }
 
+void DeviceThread::progressCB(int percent)
+{
+	emit progress(percent);
+}
+
+void DeviceThread::event_cb(dc_device_t *device, dc_event_type_t event, const void *data, void *userdata)
+{
+	const dc_event_progress_t *progress = (dc_event_progress_t *) data;
+	DeviceThread *dt = static_cast<DeviceThread*>(userdata);
+
+	switch (event) {
+	case DC_EVENT_PROGRESS:
+		dt->progressCB(100.0 * (double)progress->current / (double)progress->maximum);
+		break;
+	default:
+		emit dt->error("Unexpected event recived");
+		break;
+	}
+}
+
 ReadSettingsThread::ReadSettingsThread(QObject *parent, device_data_t *data) : DeviceThread(parent, data)
 {
 }
diff --git a/configuredivecomputerthreads.h b/configuredivecomputerthreads.h
index bc35caf..254d286 100644
--- a/configuredivecomputerthreads.h
+++ b/configuredivecomputerthreads.h
@@ -18,8 +18,11 @@ public:
 signals:
 	void error(QString err);
 	void message(QString msg);
+	void progress(int value);
 protected:
 	device_data_t *m_data;
+	void progressCB(int value);
+	static void event_cb(dc_device_t *device, dc_event_type_t event, const void *data, void *userdata);
 };
 
 class ReadSettingsThread : public DeviceThread {
-- 
2.1.0



More information about the subsurface mailing list