]> sigrok.org Git - pulseview.git/commitdiff
DeviceManager: Show progress dialog while scanning for devices
authorSoeren Apel <redacted>
Sat, 27 May 2017 14:31:15 +0000 (16:31 +0200)
committerUwe Hermann <redacted>
Sat, 27 May 2017 17:39:27 +0000 (19:39 +0200)
We don't want users to wonder why nothing happens when they
start PV and no window shows up. Providing this dialog lets
them know that PV is starting and doing something.

pv/devicemanager.cpp

index a51148b1d3ad2851a55888749312cb12b837e523..58f507c92fae06c2cd2b84dfce474a5dfc5638de 100644 (file)
 
 #include <cassert>
 #include <functional>
+#include <memory>
 #include <sstream>
 #include <stdexcept>
 #include <string>
 
 #include <libsigrokcxx/libsigrokcxx.hpp>
 
+#include <QApplication>
+#include <QObject>
+#include <QProgressDialog>
+
 #include <boost/filesystem.hpp>
 
 #include <pv/devices/hardwaredevice.hpp>
@@ -39,6 +44,7 @@ using std::placeholders::_1;
 using std::placeholders::_2;
 using std::shared_ptr;
 using std::string;
+using std::unique_ptr;
 
 using Glib::VariantBase;
 
@@ -51,8 +57,24 @@ namespace pv {
 DeviceManager::DeviceManager(shared_ptr<Context> context) :
        context_(context)
 {
-       for (auto entry : context->drivers())
+       unique_ptr<QProgressDialog> progress(new QProgressDialog("",
+               QObject::tr("Cancel"), 0, context->drivers().size()));
+       progress->setWindowModality(Qt::WindowModal);
+       progress->setMinimumDuration(1);  // To show the dialog immediately
+
+       int entry_num = 1;
+
+       for (auto entry : context->drivers()) {
+               progress->setLabelText(QObject::tr("Scanning for %1...")
+                       .arg(QString::fromStdString(entry.first)));
+
                driver_scan(entry.second, map<const ConfigKey *, VariantBase>());
+
+               progress->setValue(entry_num++);
+               QApplication::processEvents();
+               if (progress->wasCanceled())
+                       break;
+       }
 }
 
 const shared_ptr<sigrok::Context>& DeviceManager::context() const