]> sigrok.org Git - pulseview.git/commitdiff
Session: Implement .sr file save/restore
authorSoeren Apel <redacted>
Mon, 29 Aug 2016 19:41:17 +0000 (21:41 +0200)
committerSoeren Apel <redacted>
Mon, 29 Aug 2016 19:41:17 +0000 (21:41 +0200)
pv/devices/file.cpp
pv/session.cpp

index 5e1cb859d45073a1c63eb33d3b97be4ef22e09e3..f8ec998d8b7310749ac5e201979750af71f3581f 100644 (file)
@@ -32,12 +32,12 @@ File::File(const std::string &file_name) :
 
 std::string File::full_name() const
 {
-       return boost::filesystem::path(file_name_).filename().string();
+       return file_name_;
 }
 
 std::string File::display_name(const DeviceManager&) const
 {
-       return File::full_name();
+       return boost::filesystem::path(file_name_).filename().string();
 }
 
 } // namespace devices
index 8bb1cb0d5741161217ea8608607efe3eb589f955..38e862cf30fff42732c3396a26eebd6e07ae914d 100644 (file)
@@ -26,6 +26,8 @@
 #include <boost/thread/locks.hpp>
 #include <boost/thread/shared_mutex.hpp>
 
+#include <QFileInfo>
+
 #include <cassert>
 #include <mutex>
 #include <stdexcept>
@@ -168,21 +170,41 @@ void Session::save_settings(QSettings &settings) const
        int stacks = 0;
 
        if (device_) {
-               settings.beginGroup("Device");
-               key_list.push_back("vendor");
-               key_list.push_back("model");
-               key_list.push_back("version");
-               key_list.push_back("serial_num");
-               key_list.push_back("connection_id");
+               shared_ptr<devices::HardwareDevice> hw_device =
+                       dynamic_pointer_cast< devices::HardwareDevice >(device_);
+
+               if (hw_device) {
+                       settings.setValue("device_type", "hardware");
+                       settings.beginGroup("device");
+
+                       key_list.push_back("vendor");
+                       key_list.push_back("model");
+                       key_list.push_back("version");
+                       key_list.push_back("serial_num");
+                       key_list.push_back("connection_id");
+
+                       dev_info = device_manager_.get_device_info(device_);
+
+                       for (string key : key_list) {
+                               if (dev_info.count(key))
+                                       settings.setValue(QString::fromUtf8(key.c_str()),
+                                                       QString::fromUtf8(dev_info.at(key).c_str()));
+                               else
+                                       settings.remove(QString::fromUtf8(key.c_str()));
+                       }
 
-               dev_info = device_manager_.get_device_info(device_);
+                       settings.endGroup();
+               }
 
-               for (string key : key_list) {
-                       if (dev_info.count(key))
-                               settings.setValue(QString::fromUtf8(key.c_str()),
-                                               QString::fromUtf8(dev_info.at(key).c_str()));
-                       else
-                               settings.remove(QString::fromUtf8(key.c_str()));
+               shared_ptr<devices::SessionFile> sessionfile_device =
+                       dynamic_pointer_cast< devices::SessionFile >(device_);
+
+               if (sessionfile_device) {
+                       settings.setValue("device_type", "sessionfile");
+                       settings.beginGroup("device");
+                       settings.setValue("filename", QString::fromStdString(
+                               sessionfile_device->full_name()));
+                       settings.endGroup();
                }
 
                // Save channels and decoders
@@ -208,40 +230,63 @@ void Session::save_settings(QSettings &settings) const
                }
 
                settings.setValue("decoder_stacks", stacks);
-               settings.endGroup();
        }
 }
 
 void Session::restore_settings(QSettings &settings)
 {
-       map<string, string> dev_info;
-       list<string> key_list;
-       shared_ptr<devices::HardwareDevice> device;
-
-       // 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");
-       key_list.push_back("version");
-       key_list.push_back("serial_num");
-       key_list.push_back("connection_id");
-
-       for (string key : key_list) {
-               const QString k = QString::fromStdString(key);
-               if (!settings.contains(k))
-                       continue;
-
-               const string value = settings.value(k).toString().toStdString();
-               if (!value.empty())
-                       dev_info.insert(std::make_pair(key, value));
+       shared_ptr<devices::Device> device;
+
+       QString device_type = settings.value("device_type").toString();
+
+       if (device_type == "hardware") {
+               map<string, string> dev_info;
+               list<string> key_list;
+
+               // 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");
+               key_list.push_back("version");
+               key_list.push_back("serial_num");
+               key_list.push_back("connection_id");
+
+               for (string key : key_list) {
+                       const QString k = QString::fromStdString(key);
+                       if (!settings.contains(k))
+                               continue;
+
+                       const string value = settings.value(k).toString().toStdString();
+                       if (!value.empty())
+                               dev_info.insert(std::make_pair(key, value));
+               }
+
+               if (dev_info.count("model") > 0)
+                       device = device_manager_.find_device_from_info(dev_info);
+
+               if (device)
+                       set_device(device);
+
+               settings.endGroup();
        }
 
-       if (dev_info.count("model") > 0)
-               device = device_manager_.find_device_from_info(dev_info);
+       if (device_type == "sessionfile") {
+               settings.beginGroup("device");
+               QString filename = settings.value("filename").toString();
+               settings.endGroup();
 
-       if (device) {
-               set_device(device);
+               if (QFileInfo(filename).isReadable()) {
+                       device = std::make_shared<devices::SessionFile>(device_manager_.context(),
+                               filename.toStdString());
+                       set_device(device);
+                       set_name(filename);
 
+                       // TODO Perform error handling
+                       start_capture([](QString infoMessage) { (void)infoMessage; });
+               }
+       }
+
+       if (device) {
                // Restore channels
                for (shared_ptr<data::SignalBase> base : signalbases_) {
                        settings.beginGroup(base->internal_name());
@@ -263,8 +308,6 @@ void Session::restore_settings(QSettings &settings)
                }
 #endif
        }
-
-       settings.endGroup();
 }
 
 void Session::set_device(shared_ptr<devices::Device> device)