From: Soeren Apel Date: Mon, 29 Aug 2016 19:41:17 +0000 (+0200) Subject: Session: Implement .sr file save/restore X-Git-Tag: pulseview-0.4.0~256 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=43017494e4cca1f2a0470b57ad3aceb977aced6b Session: Implement .sr file save/restore --- diff --git a/pv/devices/file.cpp b/pv/devices/file.cpp index 5e1cb859..f8ec998d 100644 --- a/pv/devices/file.cpp +++ b/pv/devices/file.cpp @@ -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 diff --git a/pv/session.cpp b/pv/session.cpp index 8bb1cb0d..38e862cf 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include #include #include @@ -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 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 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 dev_info; - list key_list; - shared_ptr 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 device; + + QString device_type = settings.value("device_type").toString(); + + if (device_type == "hardware") { + map dev_info; + list 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(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 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 device)