From 643f65f96d3996c32569e9ee7cd4aa29adc2819a Mon Sep 17 00:00:00 2001 From: Jens Steinhauser Date: Fri, 23 May 2014 17:29:49 +0200 Subject: [PATCH] MainWindow: Remember directory of last file that was opened/saved. --- pv/mainwindow.cpp | 24 +++++++++++++++++++++--- pv/mainwindow.h | 12 ++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 145d7d99..165d3a70 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -67,6 +68,9 @@ namespace view { class SelectableItem; } +const char *MainWindow::SettingOpenDirectory = "MainWindow/OpenDirectory"; +const char *MainWindow::SettingSaveDirectory = "MainWindow/SaveDirectory"; + MainWindow::MainWindow(DeviceManager &device_manager, const char *open_file_name, QWidget *parent) : @@ -339,13 +343,21 @@ void MainWindow::show_session_error( void MainWindow::on_actionOpen_triggered() { + QSettings settings; + const QString dir = settings.value(SettingOpenDirectory).toString(); + // Show the dialog const QString file_name = QFileDialog::getOpenFileName( - this, tr("Open File"), "", tr( + this, tr("Open File"), dir, tr( "Sigrok Sessions (*.sr);;" "All Files (*.*)")); - if (!file_name.isEmpty()) + + if (!file_name.isEmpty()) { load_file(file_name); + + const QString abs_path = QFileInfo(file_name).absolutePath(); + settings.setValue(SettingOpenDirectory, abs_path); + } } void MainWindow::on_actionSaveAs_triggered() @@ -355,13 +367,19 @@ void MainWindow::on_actionSaveAs_triggered() // Stop any currently running capture session _session.stop_capture(); + QSettings settings; + const QString dir = settings.value(SettingSaveDirectory).toString(); + // Show the dialog const QString file_name = QFileDialog::getSaveFileName( - this, tr("Save File"), "", tr("Sigrok Sessions (*.sr)")); + this, tr("Save File"), dir, tr("Sigrok Sessions (*.sr)")); if (file_name.isEmpty()) return; + const QString abs_path = QFileInfo(file_name).absolutePath(); + settings.setValue(SettingSaveDirectory, abs_path); + StoreProgress *dlg = new StoreProgress(file_name, _session, this); dlg->run(); } diff --git a/pv/mainwindow.h b/pv/mainwindow.h index 22df24cf..f026e8f3 100644 --- a/pv/mainwindow.h +++ b/pv/mainwindow.h @@ -104,6 +104,18 @@ private slots: void capture_state_changed(int state); private: + /** + * Name of the setting used to remember the directory + * containing the last file that was opened. + */ + static const char *SettingOpenDirectory; + + /** + * Name of the setting used to remember the directory + * containing the last file that was saved. + */ + static const char *SettingSaveDirectory; + DeviceManager &_device_manager; SigSession _session; -- 2.30.2