From bc9177b394e33bfec1f3fc85fb09c2f74c1c7de3 Mon Sep 17 00:00:00 2001 From: Soeren Apel Date: Sat, 27 May 2017 16:31:15 +0200 Subject: [PATCH] DeviceManager: Show progress dialog while scanning for devices 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 | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/pv/devicemanager.cpp b/pv/devicemanager.cpp index a51148b..58f507c 100644 --- a/pv/devicemanager.cpp +++ b/pv/devicemanager.cpp @@ -22,12 +22,17 @@ #include #include +#include #include #include #include #include +#include +#include +#include + #include #include @@ -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) { - for (auto entry : context->drivers()) + unique_ptr 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()); + + progress->setValue(entry_num++); + QApplication::processEvents(); + if (progress->wasCanceled()) + break; + } } const shared_ptr& DeviceManager::context() const -- 2.30.2