From 6fd0b63971f179a28c2c558055da760c2c44231a Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 15 Mar 2014 09:28:33 +0100 Subject: [PATCH] Revert back to the default device if a session file failed to load This fixes #331 --- pv/mainwindow.cpp | 3 +++ pv/sigsession.cpp | 44 ++++++++++++++++++++++---------------------- pv/sigsession.h | 4 ++-- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index fcc929e9..7a7a1b12 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -316,6 +316,9 @@ void MainWindow::load_file(QString file_name) _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(); diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index b93ecc85..c152481e 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -126,6 +126,28 @@ void SigSession::set_file(const string &name) throw(QString) set_device(shared_ptr(device::File::create(name))); } +void SigSession::set_default_device() +{ + shared_ptr default_device; + const list< shared_ptr > &devices = + _device_manager.devices(); + + if (!devices.empty()) { + // Fall back to the first device in the list. + default_device = devices.front(); + + // Try and find the demo device and select that by default + BOOST_FOREACH (shared_ptr dev, devices) + if (strcmp(dev->dev_inst()->driver->name, + "demo") == 0) { + default_device = dev; + break; + } + } + + set_device(default_device); +} + void SigSession::release_device(device::DevInst *dev_inst) { (void)dev_inst; @@ -290,28 +312,6 @@ void SigSession::set_capture_state(capture_state state) capture_state_changed(state); } -void SigSession::set_default_device() -{ - shared_ptr default_device; - const list< shared_ptr > &devices = - _device_manager.devices(); - - if (!devices.empty()) { - // Fall back to the first device in the list. - default_device = devices.front(); - - // Try and find the demo device and select that by default - BOOST_FOREACH (shared_ptr dev, devices) - if (strcmp(dev->dev_inst()->driver->name, - "demo") == 0) { - default_device = dev; - break; - } - } - - set_device(default_device); -} - void SigSession::update_signals(shared_ptr dev_inst) { assert(dev_inst); diff --git a/pv/sigsession.h b/pv/sigsession.h index 1dacc099..5953902d 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -87,6 +87,8 @@ public: void set_file(const std::string &name) throw(QString); + void set_default_device(); + void release_device(device::DevInst *dev_inst); capture_state get_capture_state() const; @@ -114,8 +116,6 @@ private: void update_signals(boost::shared_ptr dev_inst); - void set_default_device(); - boost::shared_ptr signal_from_probe( const sr_probe *probe) const; -- 2.30.2