X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fmainwindow.cpp;h=0089b112a721f1585a9813134328cfd30c360ccb;hp=ddaeeda977c5ba8ad42769179fd084fa78d889c0;hb=8bd26d8b9c831b509ee3241ea4dac6f50c023622;hpb=0fbda3c2dda9357776afa15e99c037eb0cc97214 diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index ddaeeda9..0089b112 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -25,6 +25,9 @@ #include #include +#include +#include + #include #include #include @@ -39,6 +42,7 @@ #include "mainwindow.h" #include "devicemanager.h" +#include "device/device.h" #include "dialogs/about.h" #include "dialogs/connect.h" #include "dialogs/storeprogress.h" @@ -57,6 +61,7 @@ #include #include +using boost::shared_ptr; using std::list; namespace pv { @@ -159,6 +164,8 @@ void MainWindow::setup_ui() "MainWindow", "Zoom &In", 0, QApplication::UnicodeUTF8)); action_view_zoom_in->setIcon(QIcon::fromTheme("zoom-in", QIcon(":/icons/zoom-in.png"))); + // simply using Qt::Key_Plus shows no + in the menu + action_view_zoom_in->setShortcut(QKeySequence::ZoomIn); action_view_zoom_in->setObjectName( QString::fromUtf8("actionViewZoomIn")); menu_view->addAction(action_view_zoom_in); @@ -168,6 +175,7 @@ void MainWindow::setup_ui() "MainWindow", "Zoom &Out", 0, QApplication::UnicodeUTF8)); action_view_zoom_out->setIcon(QIcon::fromTheme("zoom-out", QIcon(":/icons/zoom-out.png"))); + action_view_zoom_out->setShortcut(QKeySequence::ZoomOut); action_view_zoom_out->setObjectName( QString::fromUtf8("actionViewZoomOut")); menu_view->addAction(action_view_zoom_out); @@ -212,7 +220,7 @@ void MainWindow::setup_ui() "MainWindow", "&Decoders", 0, QApplication::UnicodeUTF8)); pv::widgets::DecoderMenu *const menu_decoders_add = - new pv::widgets::DecoderMenu(menu_decoders); + new pv::widgets::DecoderMenu(menu_decoders, true); menu_decoders_add->setTitle(QApplication::translate( "MainWindow", "&Add", 0, QApplication::UnicodeUTF8)); connect(menu_decoders_add, SIGNAL(decoder_selected(srd_decoder*)), @@ -279,28 +287,21 @@ void MainWindow::session_error( Q_ARG(QString, info_text)); } -void MainWindow::update_device_list(struct sr_dev_inst *selected_device) +void MainWindow::update_device_list() { assert(_sampling_bar); - const list &devices = _device_manager.devices(); - _sampling_bar->set_device_list(devices); - - if (!selected_device && !devices.empty()) { - // Fall back to the first device in the list. - selected_device = devices.front(); + shared_ptr selected_device = _session.get_device(); + list< shared_ptr > devices; + std::copy(_device_manager.devices().begin(), + _device_manager.devices().end(), std::back_inserter(devices)); - // Try and find the demo device and select that by default - BOOST_FOREACH (struct sr_dev_inst *sdi, devices) - if (strcmp(sdi->driver->name, "demo") == 0) { - selected_device = sdi; - } - } + if (std::find(devices.begin(), devices.end(), selected_device) == + devices.end()) + devices.push_back(selected_device); + assert(selected_device); - if (selected_device) { - _sampling_bar->set_selected_device(selected_device); - _session.set_device(selected_device); - } + _sampling_bar->set_device_list(devices, selected_device); } void MainWindow::load_file(QString file_name) @@ -308,9 +309,20 @@ void MainWindow::load_file(QString file_name) const QString errorMessage( QString("Failed to load file %1").arg(file_name)); const QString infoMessage; - _session.load_file(file_name.toStdString(), - boost::bind(&MainWindow::session_error, this, - errorMessage, infoMessage)); + + try { + _session.set_file(file_name.toStdString()); + } catch(QString e) { + show_session_error(tr("Failed to load ") + file_name, e); + _session.set_default_device(); + update_device_list(); + return; + } + + update_device_list(); + + _session.start_capture(boost::bind(&MainWindow::session_error, this, + errorMessage, infoMessage)); } void MainWindow::show_session_error( @@ -326,13 +338,11 @@ void MainWindow::show_session_error( void MainWindow::on_actionOpen_triggered() { - // Enumerate the file formats - QString filters(tr("Sigrok Sessions (*.sr)")); - filters.append(tr(";;All Files (*.*)")); - // Show the dialog const QString file_name = QFileDialog::getOpenFileName( - this, tr("Open File"), "", filters); + this, tr("Open File"), "", tr( + "Sigrok Sessions (*.sr);;" + "All Files (*.*)")); if (!file_name.isEmpty()) load_file(file_name); } @@ -364,10 +374,10 @@ void MainWindow::on_actionConnect_triggered() // If the user selected a device, select it in the device list. Select the // current device otherwise. - struct sr_dev_inst *const sdi = dlg.exec() ? - dlg.get_selected_device() : _session.get_device(); + if (dlg.exec()) + _session.set_device(dlg.get_selected_device()); - update_device_list(sdi); + update_device_list(); } void MainWindow::on_actionQuit_triggered() @@ -426,8 +436,8 @@ void MainWindow::run_stop() { switch(_session.get_capture_state()) { case SigSession::Stopped: - _session.start_capture(_sampling_bar->get_record_length(), - boost::bind(&MainWindow::session_error, this, + _session.start_capture( + boost::bind(&MainWindow::session_error, this, QString("Capture failed"), _1)); break;