]> sigrok.org Git - pulseview.git/commitdiff
Revert back to the default device if a session file failed to load
authorJoel Holdsworth <redacted>
Sat, 15 Mar 2014 08:28:33 +0000 (09:28 +0100)
committerJoel Holdsworth <redacted>
Sat, 15 Mar 2014 08:28:33 +0000 (09:28 +0100)
This fixes #331

pv/mainwindow.cpp
pv/sigsession.cpp
pv/sigsession.h

index fcc929e988c12d8f1755be8b436c1b348b77447f..7a7a1b12baddf2ee85acdf65ee2cd64b3db09e86 100644 (file)
@@ -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();
index b93ecc85952ecc4053169782bd666bdd06cd968f..c152481e9841814d93669c8c85e3cccf2176e94c 100644 (file)
@@ -126,6 +126,28 @@ void SigSession::set_file(const string &name) throw(QString)
        set_device(shared_ptr<device::DevInst>(device::File::create(name)));
 }
 
+void SigSession::set_default_device()
+{
+       shared_ptr<pv::device::DevInst> default_device;
+       const list< shared_ptr<device::Device> > &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<pv::device::Device> 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<pv::device::DevInst> default_device;
-       const list< shared_ptr<device::Device> > &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<pv::device::Device> 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<device::DevInst> dev_inst)
 {
        assert(dev_inst);
index 1dacc0996cfea447785848f30411d04c5028a28f..5953902df02750714df9dc944bd0b802439d49b7 100644 (file)
@@ -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<device::DevInst> dev_inst);
 
-       void set_default_device();
-
        boost::shared_ptr<view::Signal> signal_from_probe(
                const sr_probe *probe) const;