]> sigrok.org Git - pulseview.git/blobdiff - pv/mainwindow.cpp
MainWindow: Try to use any available device aside from demo
[pulseview.git] / pv / mainwindow.cpp
index 272dac234374c9f4e69e825100520e81010644d4..65071330da07e1d24c5955448ad44efe3f929383 100644 (file)
@@ -177,6 +177,11 @@ QAction* MainWindow::action_view_sticky_scrolling() const
        return action_view_sticky_scrolling_;
 }
 
+QAction* MainWindow::action_view_coloured_bg() const
+{
+       return action_view_coloured_bg_;
+}
+
 QAction* MainWindow::action_view_show_cursors() const
 {
        return action_view_show_cursors_;
@@ -476,12 +481,14 @@ void MainWindow::setup_ui()
 
        action_view_coloured_bg_->setCheckable(true);
        action_view_coloured_bg_->setChecked(true);
-       action_view_coloured_bg_->setShortcut(QKeySequence(Qt::Key_S));
+       action_view_coloured_bg_->setShortcut(QKeySequence(Qt::Key_B));
        action_view_coloured_bg_->setObjectName(
                QString::fromUtf8("actionViewColouredBg"));
        action_view_coloured_bg_->setText(tr("Use &coloured backgrounds"));
        menu_view->addAction(action_view_coloured_bg_);
 
+       view_->enable_coloured_bg(action_view_coloured_bg_->isChecked());
+
        menu_view->addSeparator();
 
        action_view_show_cursors_->setCheckable(true);
@@ -560,8 +567,9 @@ void MainWindow::select_init_device()
        QSettings settings;
        map<string, string> dev_info;
        list<string> key_list;
+       shared_ptr<devices::HardwareDevice> device;
 
-       // Re-select last used device if possible.
+       // Re-select last used device if possible but only if it's not demo
        settings.beginGroup("Device");
        key_list.push_back("vendor");
        key_list.push_back("model");
@@ -579,8 +587,24 @@ void MainWindow::select_init_device()
                        dev_info.insert(std::make_pair(key, value));
        }
 
-       const shared_ptr<devices::HardwareDevice> device =
-               device_manager_.find_device_from_info(dev_info);
+       if (dev_info.count("model") > 0)
+               if (dev_info.at("model").find("Demo device") == std::string::npos)
+                       device = device_manager_.find_device_from_info(dev_info);
+
+       // When we can't find a device similar to the one we used last
+       // time and there is at least one device aside from demo, use it
+       if (!device) {
+               for (shared_ptr<devices::HardwareDevice> dev : device_manager_.devices()) {
+                       dev_info = device_manager_.get_device_info(dev);
+
+                       if (dev_info.count("model") > 0)
+                               if (dev_info.at("model").find("Demo device") == std::string::npos) {
+                                       device = dev;
+                                       break;
+                               }
+               }
+       }
+
        select_device(device);
        update_device_list();
 
@@ -807,6 +831,7 @@ void MainWindow::on_actionViewStickyScrolling_triggered()
 
 void MainWindow::on_actionViewColouredBg_triggered()
 {
+       view_->enable_coloured_bg(action_view_coloured_bg_->isChecked());
 }
 
 void MainWindow::on_actionViewShowCursors_triggered()