X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fmainwindow.cpp;h=9fa4eee6baa2735281a4c3e4dbfda21cc7a3bb62;hp=d1418b5921befe0dfdf85b0ac5dedfa07fd6310c;hb=23e75650eba0491b2636de3cef87f893e38ae6f3;hpb=8dbbc7f0b9ea59d0f0d62225772f8a56eee125f5 diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index d1418b59..9fa4eee6 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -40,17 +40,17 @@ #include #include -#include "mainwindow.h" - -#include "devicemanager.h" -#include "dialogs/about.h" -#include "dialogs/connect.h" -#include "dialogs/storeprogress.h" -#include "toolbars/samplingbar.h" -#include "view/logicsignal.h" -#include "view/view.h" +#include "mainwindow.hpp" + +#include "devicemanager.hpp" +#include "dialogs/about.hpp" +#include "dialogs/connect.hpp" +#include "dialogs/storeprogress.hpp" +#include "toolbars/samplingbar.hpp" +#include "view/logicsignal.hpp" +#include "view/view.hpp" #ifdef ENABLE_DECODE -#include "widgets/decodermenu.h" +#include "widgets/decodermenu.hpp" #endif #include @@ -61,7 +61,6 @@ using std::list; using std::map; -using std::pair; using std::shared_ptr; using std::string; @@ -72,7 +71,7 @@ using sigrok::HardwareDevice; namespace pv { namespace view { -class SelectableItem; +class ViewItem; } const char *MainWindow::SettingOpenDirectory = "MainWindow/OpenDirectory"; @@ -95,6 +94,35 @@ MainWindow::MainWindow(DeviceManager &device_manager, } } +void MainWindow::run_stop() +{ + switch(session_.get_capture_state()) { + case Session::Stopped: + session_.start_capture([&](QString message) { + session_error("Capture failed", message); }); + break; + + case Session::AwaitingTrigger: + case Session::Running: + session_.stop_capture(); + break; + } +} + +void MainWindow::select_device(shared_ptr device) +{ + try { + session_.set_device(device); + } catch(const QString &e) { + QMessageBox msg(this); + msg.setText(e); + msg.setInformativeText(tr("Failed to Select Device")); + msg.setStandardButtons(QMessageBox::Ok); + msg.setIcon(QMessageBox::Warning); + msg.exec(); + } +} + void MainWindow::setup_ui() { setObjectName(QString::fromUtf8("MainWindow")); @@ -255,13 +283,11 @@ void MainWindow::setup_ui() addToolBar(toolbar); // Setup the sampling bar - sampling_bar_ = new toolbars::SamplingBar(session_, this); + sampling_bar_ = new toolbars::SamplingBar(session_, *this); // Populate the device list and select the initially selected device update_device_list(); - connect(sampling_bar_, SIGNAL(run_stop()), this, - SLOT(run_stop())); addToolBar(sampling_bar_); // Set the title @@ -270,6 +296,8 @@ void MainWindow::setup_ui() // Setup session_ events connect(&session_, SIGNAL(capture_state_changed(int)), this, SLOT(capture_state_changed(int))); + connect(&session_, SIGNAL(device_selected()), this, + SLOT(device_selected())); } void MainWindow::save_ui_settings() @@ -349,7 +377,7 @@ void MainWindow::restore_ui_settings() device = device_manager_.find_device_from_info(dev_info); if (device) { - session_.set_device(device); + select_device(device); update_device_list(); } @@ -382,13 +410,7 @@ void MainWindow::update_device_list() devices.push_back(selected_device); assert(selected_device); - list< pair< shared_ptr, string> > device_list; - - for (auto device : devices) - device_list.push_back(make_pair( - device, device_manager_.get_display_name(device))); - - sampling_bar_->set_device_list(device_list, selected_device); + sampling_bar_->set_device_list(devices, selected_device); } void MainWindow::closeEvent(QCloseEvent *event) @@ -482,7 +504,7 @@ void MainWindow::on_actionConnect_triggered() // If the user selected a device, select it in the device list. Select the // current device otherwise. if (dlg.exec()) - session_.set_device(dlg.get_selected_device()); + select_device(dlg.get_selected_device()); update_device_list(); } @@ -539,24 +561,20 @@ void MainWindow::add_decoder(srd_decoder *decoder) #endif } -void MainWindow::run_stop() +void MainWindow::capture_state_changed(int state) { - switch(session_.get_capture_state()) { - case SigSession::Stopped: - session_.start_capture([&](QString message) { - session_error("Capture failed", message); }); - break; - - case SigSession::AwaitingTrigger: - case SigSession::Running: - session_.stop_capture(); - break; - } + sampling_bar_->set_capture_state((pv::Session::capture_state)state); } -void MainWindow::capture_state_changed(int state) +void MainWindow::device_selected() { - sampling_bar_->set_capture_state((pv::SigSession::capture_state)state); + // Set the title to include the device/file name + const shared_ptr device = session_.device(); + if (!device) + return; + + const string display_name = device_manager_.get_display_name(device); + setWindowTitle(tr("%1 - PulseView").arg(display_name.c_str())); } } // namespace pv