X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fsession.cpp;h=a71ad1c56d2b2001bf0e65cdb2e706613ba09f1a;hb=c8e2f09bf04bd3cab27b6152bcd92c7a85af424f;hp=9ec8bd07264036e85c052c05695749f4bccf797b;hpb=554af71bf515d2763ca13c3829dbeb2064cc4c83;p=pulseview.git diff --git a/pv/session.cpp b/pv/session.cpp index 9ec8bd07..a71ad1c5 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include "devicemanager.hpp" @@ -176,6 +177,16 @@ void Session::set_name(QString name) name_changed(); } +QString Session::save_path() const +{ + return save_path_; +} + +void Session::set_save_path(QString path) +{ + save_path_ = path; +} + const vector< shared_ptr > Session::views() const { return views_; @@ -312,25 +323,36 @@ void Session::save_settings(QSettings &settings) const settings.endGroup(); } - shared_ptr sessionfile_device = - dynamic_pointer_cast(device_); - - if (sessionfile_device) { + // Having saved the data to srzip overrides the current device. This is + // a crappy hack around the fact that saving e.g. an imported file to + // srzip would require changing the underlying libsigrok device + if (!save_path_.isEmpty()) { + QFileInfo fi = QFileInfo(QDir(save_path_), name_); settings.setValue("device_type", "sessionfile"); settings.beginGroup("device"); - settings.setValue("filename", QString::fromStdString( - sessionfile_device->full_name())); + settings.setValue("filename", fi.absoluteFilePath()); settings.endGroup(); - } + } else { + shared_ptr sessionfile_device = + dynamic_pointer_cast(device_); + + if (sessionfile_device) { + settings.setValue("device_type", "sessionfile"); + settings.beginGroup("device"); + settings.setValue("filename", QString::fromStdString( + sessionfile_device->full_name())); + settings.endGroup(); + } - shared_ptr inputfile_device = - dynamic_pointer_cast(device_); + shared_ptr inputfile_device = + dynamic_pointer_cast(device_); - if (inputfile_device) { - settings.setValue("device_type", "inputfile"); - settings.beginGroup("device"); - inputfile_device->save_meta_to_settings(settings); - settings.endGroup(); + if (inputfile_device) { + settings.setValue("device_type", "inputfile"); + settings.beginGroup("device"); + inputfile_device->save_meta_to_settings(settings); + settings.endGroup(); + } } save_setup(settings); @@ -444,16 +466,17 @@ void Session::restore_settings(QSettings &settings) settings.endGroup(); } + + QString filename; if ((device_type == "sessionfile") || (device_type == "inputfile")) { if (device_type == "sessionfile") { settings.beginGroup("device"); - const QString filename = settings.value("filename").toString(); + filename = settings.value("filename").toString(); settings.endGroup(); - if (QFileInfo(filename).isReadable()) { + if (QFileInfo(filename).isReadable()) device = make_shared(device_manager_.context(), filename.toStdString()); - } } if (device_type == "inputfile") { @@ -472,6 +495,14 @@ void Session::restore_settings(QSettings &settings) set_name(QString::fromStdString( dynamic_pointer_cast(device)->display_name(device_manager_))); + + if (!filename.isEmpty()) { + // Only set the save path if we load an srzip file + if (device_type == "sessionfile") + set_save_path(QFileInfo(filename).absolutePath()); + + set_name(QFileInfo(filename).fileName()); + } } } @@ -621,8 +652,12 @@ Session::input_format_options(vector user_spec, * data type. */ auto found = fmt_opts.find(key); - if (found == fmt_opts.end()) + if (found == fmt_opts.end()) { + qCritical() << "Supplied input option" << QString::fromStdString(key) << + "is not a valid option for this input module, it will be ignored!"; continue; + } + shared_ptr