]> sigrok.org Git - pulseview.git/commitdiff
MainWindow: Remember directory of last file that was opened/saved.
authorJens Steinhauser <redacted>
Fri, 23 May 2014 15:29:49 +0000 (17:29 +0200)
committerJens Steinhauser <redacted>
Sat, 24 May 2014 16:04:06 +0000 (18:04 +0200)
pv/mainwindow.cpp
pv/mainwindow.h

index 145d7d997db6cfe089d1fc18b4bafd3874e9e22c..165d3a705db17551fcc1070da6a559c1daea2577 100644 (file)
@@ -32,6 +32,7 @@
 #include <QMessageBox>
 #include <QMenu>
 #include <QMenuBar>
+#include <QSettings>
 #include <QStatusBar>
 #include <QVBoxLayout>
 #include <QWidget>
@@ -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();
 }
index 22df24cfe4278ce1c271accfbf80db97bda09f6a..f026e8f3f38e0326304283c62164d76638c32803 100644 (file)
@@ -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;