]> sigrok.org Git - pulseview.git/commitdiff
Fix #1183 by adding a workaround for srzip handling
authorSoeren Apel <redacted>
Thu, 25 Jun 2020 22:06:25 +0000 (00:06 +0200)
committerSoeren Apel <redacted>
Thu, 25 Jun 2020 22:06:25 +0000 (00:06 +0200)
pv/session.cpp
pv/toolbars/mainbar.cpp

index ec8082eb7cf0158ec0c85954a1bcc99e12227b86..a71ad1c56d2b2001bf0e65cdb2e706613ba09f1a 100644 (file)
@@ -25,6 +25,7 @@
 #include <sys/stat.h>
 
 #include <QDebug>
+#include <QDir>
 #include <QFileInfo>
 
 #include "devicemanager.hpp"
@@ -322,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);
index b798683c33a0fee228553501cadd528c48704a41..28ea0042227a6119890329208bdeedacc5277def 100644 (file)
@@ -689,11 +689,10 @@ void MainBar::export_file(shared_ptr<OutputFormat> format, bool selection_only,
        }
 
        if (!selection_only) {
-               session_.set_name(QFileInfo(file_name).fileName());
-
-               if (format == session_.device_manager().context()->output_formats()["srzip"])
+               if (format == session_.device_manager().context()->output_formats()["srzip"]) {
                        session_.set_save_path(QFileInfo(file_name).absolutePath());
-               else
+                       session_.set_name(QFileInfo(file_name).fileName());
+               } else
                        session_.set_save_path("");
        }
 
@@ -825,7 +824,7 @@ void MainBar::on_actionSave_triggered()
                return;
        }
 
-       QFileInfo fi = QFileInfo(session_.save_path(), session_.name());
+       QFileInfo fi = QFileInfo(QDir(session_.save_path()), session_.name());
        export_file(session_.device_manager().context()->output_formats()["srzip"], false,
                fi.absoluteFilePath());
 }