From: Soeren Apel Date: Thu, 25 Jun 2020 22:06:25 +0000 (+0200) Subject: Fix #1183 by adding a workaround for srzip handling X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=73d5a9bbc2f32ed84077ca4e75a125a6b0fc1921;p=pulseview.git Fix #1183 by adding a workaround for srzip handling --- diff --git a/pv/session.cpp b/pv/session.cpp index ec8082eb..a71ad1c5 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include "devicemanager.hpp" @@ -322,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); diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index b798683c..28ea0042 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -689,11 +689,10 @@ void MainBar::export_file(shared_ptr 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()); }