]> sigrok.org Git - pulseview.git/blobdiff - pv/devicemanager.cpp
CMakeLists.txt: Install the AppData/AppStream file.
[pulseview.git] / pv / devicemanager.cpp
index 883175c7752eb8cf27767a254d285da3760eb539..540f88150e4cf117be1ca1fa12762e8b734f3943 100644 (file)
 
 #include <cassert>
 #include <functional>
-#include <stdexcept>
+#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,37 @@ namespace pv {
 DeviceManager::DeviceManager(shared_ptr<Context> context) :
        context_(context)
 {
-       for (auto entry : context->drivers())
-               driver_scan(entry.second, map<const ConfigKey *, VariantBase>());
+       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)));
+
+               /**
+                * We currently only support devices that can deliver
+                * samples at a fixed samplerate i.e. oscilloscopes and
+                * logic analysers.
+                * @todo Add support for non-monotonic devices i.e. DMMs
+                * and sensors.
+                */
+               const auto keys = (entry.second)->config_keys();
+
+               bool supported_device = keys.count(ConfigKey::LOGIC_ANALYZER) |
+                       keys.count(ConfigKey::OSCILLOSCOPE);
+
+               if (supported_device)
+                       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