]> sigrok.org Git - pulseview.git/commitdiff
MainBar: Make sure session save path is reset on non-srzip save
authorSoeren Apel <redacted>
Thu, 25 Jun 2020 18:26:47 +0000 (20:26 +0200)
committerSoeren Apel <redacted>
Thu, 25 Jun 2020 19:05:46 +0000 (21:05 +0200)
pv/session.cpp
pv/session.hpp
pv/toolbars/mainbar.cpp
pv/toolbars/mainbar.hpp

index 840773d1aa7115bd4dcc7594496c776231bcdd15..ec8082eb7cf0158ec0c85954a1bcc99e12227b86 100644 (file)
@@ -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<views::ViewBase> > 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<devices::SessionFile>(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<devices::File>(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<devices::SessionFile>(device_))
+               set_save_path(QFileInfo(file_name).absolutePath());
+
+       set_name(QFileInfo(file_name).fileName());
 }
 
 Session::capture_state Session::get_capture_state() const
index 871dcba85f334eecb7be37f93a6e1c0271adf625..54a7444c405e1edefa4f8b410f039f9c75c61e04 100644 (file)
@@ -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::ViewBase> > views() const;
 
@@ -273,7 +273,7 @@ private:
 
        DeviceManager &device_manager_;
        shared_ptr<devices::Device> device_;
-       QString default_name_, name_, path_;
+       QString default_name_, name_, save_path_;
 
        vector< shared_ptr<views::ViewBase> > views_;
        shared_ptr<pv::views::ViewBase> main_view_;
index a2a20fb62a93aafe4956d0a6b52b4742099e7dfc..b798683c33a0fee228553501cadd528c48704a41 100644 (file)
@@ -608,7 +608,7 @@ void MainBar::show_session_error(const QString text, const QString info_text)
        msg.exec();
 }
 
-void MainBar::export_file(shared_ptr<OutputFormat> format, bool selection_only, QString path)
+void MainBar::export_file(shared_ptr<OutputFormat> format, bool selection_only, QString file_name)
 {
        using pv::dialogs::StoreProgress;
 
@@ -667,9 +667,8 @@ void MainBar::export_file(shared_ptr<OutputFormat> 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<OutputFormat> 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()
index fca6acabcd7e5045aa519419f085a1a6673c4343..eae43fa586a12aa9cebd1fcb52a68c24c6324147 100644 (file)
@@ -121,8 +121,7 @@ private Q_SLOTS:
        void show_session_error(const QString text, const QString info_text);
 
        void export_file(shared_ptr<sigrok::OutputFormat> format,
-               bool selection_only = false,
-               QString path = QString{});
+               bool selection_only = false, QString file_name = "");
        void import_file(shared_ptr<sigrok::InputFormat> format);
 
        void on_device_selected();