From: Soeren Apel Date: Thu, 25 Jun 2020 18:26:47 +0000 (+0200) Subject: MainBar: Make sure session save path is reset on non-srzip save X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e6d85b8936b5b7aee80b03834f095fd5b52fe6f4;p=pulseview.git MainBar: Make sure session save path is reset on non-srzip save --- diff --git a/pv/session.cpp b/pv/session.cpp index 840773d1..ec8082eb 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -176,15 +176,14 @@ void Session::set_name(QString name) name_changed(); } -QString Session::path() const +QString Session::save_path() const { - return path_; + return save_path_; } -void Session::set_path(QString path) +void Session::set_save_path(QString path) { - path_ = path; - set_name(QFileInfo(path).fileName()); + save_path_ = path; } const vector< shared_ptr > Session::views() const @@ -456,18 +455,16 @@ void Session::restore_settings(QSettings &settings) } - QString path; + 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()) { - path = filename; + if (QFileInfo(filename).isReadable()) device = make_shared(device_manager_.context(), filename.toStdString()); - } } if (device_type == "inputfile") { @@ -487,8 +484,13 @@ void Session::restore_settings(QSettings &settings) set_name(QString::fromStdString( dynamic_pointer_cast(device)->display_name(device_manager_))); - if (!path.isEmpty()) - set_path(path); + 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()); + } } } @@ -726,7 +728,11 @@ void Session::load_file(QString file_name, QString setup_file_name, start_capture([&, errorMessage](QString infoMessage) { MainWindow::show_session_error(errorMessage, infoMessage); }); - set_path(file_name); + // Only set save path if we loaded an srzip file + if (dynamic_pointer_cast(device_)) + set_save_path(QFileInfo(file_name).absolutePath()); + + set_name(QFileInfo(file_name).fileName()); } Session::capture_state Session::get_capture_state() const diff --git a/pv/session.hpp b/pv/session.hpp index 871dcba8..54a7444c 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -141,8 +141,8 @@ public: QString name() const; void set_name(QString name); - QString path() const; - void set_path(QString path); + QString save_path() const; + void set_save_path(QString path); const vector< shared_ptr > views() const; @@ -273,7 +273,7 @@ private: DeviceManager &device_manager_; shared_ptr device_; - QString default_name_, name_, path_; + QString default_name_, name_, save_path_; vector< shared_ptr > views_; shared_ptr main_view_; diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index a2a20fb6..b798683c 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -608,7 +608,7 @@ void MainBar::show_session_error(const QString text, const QString info_text) msg.exec(); } -void MainBar::export_file(shared_ptr format, bool selection_only, QString path) +void MainBar::export_file(shared_ptr format, bool selection_only, QString file_name) { using pv::dialogs::StoreProgress; @@ -667,9 +667,8 @@ void MainBar::export_file(shared_ptr format, bool selection_only, tr("All Files")); // Show the file dialog - const QString file_name = path.isEmpty() ? - QFileDialog::getSaveFileName(this, tr("Save File"), dir, filter) : - path; + if (file_name.isEmpty()) + file_name = QFileDialog::getSaveFileName(this, tr("Save File"), dir, filter); if (file_name.isEmpty()) return; @@ -689,9 +688,14 @@ void MainBar::export_file(shared_ptr format, bool selection_only, options = dlg.options(); } - if (!selection_only && - format == session_.device_manager().context()->output_formats()["srzip"]) - session_.set_path(file_name); + if (!selection_only) { + session_.set_name(QFileInfo(file_name).fileName()); + + if (format == session_.device_manager().context()->output_formats()["srzip"]) + session_.set_save_path(QFileInfo(file_name).absolutePath()); + else + session_.set_save_path(""); + } StoreProgress *dlg = new StoreProgress(file_name, format, options, sample_range, session_, this); @@ -815,7 +819,15 @@ void MainBar::on_actionOpen_triggered() void MainBar::on_actionSave_triggered() { - export_file(session_.device_manager().context()->output_formats()["srzip"], false, session_.path()); + // A path is only set if we loaded/saved an srzip file before + if (session_.save_path().isEmpty()) { + on_actionSaveAs_triggered(); + return; + } + + QFileInfo fi = QFileInfo(session_.save_path(), session_.name()); + export_file(session_.device_manager().context()->output_formats()["srzip"], false, + fi.absoluteFilePath()); } void MainBar::on_actionSaveAs_triggered() diff --git a/pv/toolbars/mainbar.hpp b/pv/toolbars/mainbar.hpp index fca6acab..eae43fa5 100644 --- a/pv/toolbars/mainbar.hpp +++ b/pv/toolbars/mainbar.hpp @@ -121,8 +121,7 @@ private Q_SLOTS: void show_session_error(const QString text, const QString info_text); void export_file(shared_ptr format, - bool selection_only = false, - QString path = QString{}); + bool selection_only = false, QString file_name = ""); void import_file(shared_ptr format); void on_device_selected();