]> sigrok.org Git - pulseview.git/blobdiff - pv/session.cpp
Fix #1183 by adding a workaround for srzip handling
[pulseview.git] / pv / session.cpp
index 9ec8bd07264036e85c052c05695749f4bccf797b..a71ad1c56d2b2001bf0e65cdb2e706613ba09f1a 100644 (file)
@@ -25,6 +25,7 @@
 #include <sys/stat.h>
 
 #include <QDebug>
+#include <QDir>
 #include <QFileInfo>
 
 #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<views::ViewBase> > Session::views() const
 {
        return views_;
@@ -312,25 +323,36 @@ void Session::save_settings(QSettings &settings) const
                        settings.endGroup();
                }
 
-               shared_ptr<devices::SessionFile> sessionfile_device =
-                       dynamic_pointer_cast<devices::SessionFile>(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<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();
+                       }
 
-               shared_ptr<devices::InputFile> inputfile_device =
-                       dynamic_pointer_cast<devices::InputFile>(device_);
+                       shared_ptr<devices::InputFile> inputfile_device =
+                               dynamic_pointer_cast<devices::InputFile>(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<devices::SessionFile>(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<devices::File>(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<string> 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<Option> opt = found->second;
                result[key] = opt->parse_string(val);
        }
@@ -647,7 +682,7 @@ void Session::load_init_file(const string &file_name,
                                return f.first == user_name; });
                if (iter == formats.end()) {
                        MainWindow::show_session_error(tr("Error"),
-                               tr("Unexpected input format: %s").arg(QString::fromStdString(format)));
+                               tr("Unexpected input format: %1").arg(QString::fromStdString(format)));
                        return;
                }
                input_format = (*iter).second;
@@ -705,6 +740,10 @@ void Session::load_file(QString file_name, QString setup_file_name,
        start_capture([&, errorMessage](QString infoMessage) {
                MainWindow::show_session_error(errorMessage, infoMessage); });
 
+       // Only set save path if we loaded an srzip file
+       if (dynamic_pointer_cast<devices::SessionFile>(device_))
+               set_save_path(QFileInfo(file_name).absolutePath());
+
        set_name(QFileInfo(file_name).fileName());
 }