]> sigrok.org Git - pulseview.git/commitdiff
Fix #862 by implementing -c / --clean
authorSoeren Apel <redacted>
Tue, 6 Jun 2017 14:14:54 +0000 (16:14 +0200)
committerSoeren Apel <redacted>
Tue, 6 Jun 2017 14:17:26 +0000 (16:17 +0200)
main.cpp
pv/mainwindow.cpp
pv/mainwindow.hpp

index d0ca64a2483a85fb7cdac23c5a7170c1c3f02d34..9c27f7b745d8e81b083025beb3a8bf7b6e364a44 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -68,6 +68,7 @@ void usage()
                "  -l, --loglevel                  Set libsigrok/libsigrokdecode loglevel\n"
                "  -i, --input-file                Load input from file\n"
                "  -I, --input-format              Input format\n"
+               "  -c, --clean                     Don't restore previous sessions on startup\n"
                "\n", PV_BIN_NAME, PV_DESCRIPTION);
 }
 
@@ -76,6 +77,7 @@ int main(int argc, char *argv[])
        int ret = 0;
        shared_ptr<sigrok::Context> context;
        string open_file, open_file_format;
+       bool restore_sessions = true;
 
        Application a(argc, argv);
 
@@ -93,11 +95,12 @@ int main(int argc, char *argv[])
                        {"loglevel", required_argument, nullptr, 'l'},
                        {"input-file", required_argument, nullptr, 'i'},
                        {"input-format", required_argument, nullptr, 'I'},
+                       {"clean", no_argument, nullptr, 'c'},
                        {nullptr, 0, nullptr, 0}
                };
 
                const int c = getopt_long(argc, argv,
-                       "l:Vh?i:I:", long_options, nullptr);
+                       "l:Vhc?i:I:", long_options, nullptr);
                if (c == -1)
                        break;
 
@@ -136,6 +139,10 @@ int main(int argc, char *argv[])
                case 'I':
                        open_file_format = optarg;
                        break;
+
+               case 'c':
+                       restore_sessions = false;
+                       break;
                }
        }
 
@@ -170,8 +177,8 @@ int main(int argc, char *argv[])
                        pv::DeviceManager device_manager(context);
 
                        // Initialise the main window
-                       pv::MainWindow w(device_manager,
-                               open_file, open_file_format);
+                       pv::MainWindow w(device_manager, open_file, open_file_format,
+                               restore_sessions);
                        w.show();
 
 #ifdef ENABLE_SIGNALS
index 86a015533f824cb8483e7ef7b456d080266d9ebc..9286a06cea256bae5d24d51d930658bd5fd99167 100644 (file)
@@ -70,7 +70,7 @@ const QString MainWindow::WindowTitle = tr("PulseView");
 
 MainWindow::MainWindow(DeviceManager &device_manager,
        string open_file_name, string open_file_format,
-       QWidget *parent) :
+       bool restore_sessions, QWidget *parent) :
        QMainWindow(parent),
        device_manager_(device_manager),
        session_selector_(this),
@@ -92,7 +92,7 @@ MainWindow::MainWindow(DeviceManager &device_manager,
                bind(&MainWindow::on_settingViewShowAnalogMinorGrid_changed, this, _1));
 
        setup_ui();
-       restore_ui_settings();
+       restore_ui_settings(restore_sessions);
 
        if (!open_file_name.empty()) {
                shared_ptr<Session> session = add_session();
@@ -455,10 +455,9 @@ void MainWindow::save_ui_settings()
        settings.setValue("sessions", id);
 }
 
-void MainWindow::restore_ui_settings()
+void MainWindow::restore_ui_settings(bool restore_sessions)
 {
        QSettings settings;
-       int i, session_count;
 
        settings.beginGroup("MainWindow");
 
@@ -470,13 +469,17 @@ void MainWindow::restore_ui_settings()
 
        settings.endGroup();
 
-       session_count = settings.value("sessions", 0).toInt();
+       if (restore_sessions) {
+               int i, session_count;
 
-       for (i = 0; i < session_count; i++) {
-               settings.beginGroup("Session" + QString::number(i));
-               shared_ptr<Session> session = add_session();
-               session->restore_settings(settings);
-               settings.endGroup();
+               session_count = settings.value("sessions", 0).toInt();
+
+               for (i = 0; i < session_count; i++) {
+                       settings.beginGroup("Session" + QString::number(i));
+                       shared_ptr<Session> session = add_session();
+                       session->restore_settings(settings);
+                       settings.endGroup();
+               }
        }
 }
 
index 6541ccc6dff181e2cf386ed75657f5c0ecf11d1c..ab0f871e924ad7d90c7203ab91a502f32ea3344d 100644 (file)
@@ -72,6 +72,7 @@ public:
        explicit MainWindow(DeviceManager &device_manager,
                string open_file_name = string(),
                string open_file_format = string(),
+               bool restore_sessions = true,
                QWidget *parent = nullptr);
 
        ~MainWindow();
@@ -92,7 +93,7 @@ private:
 
        void save_ui_settings();
 
-       void restore_ui_settings();
+       void restore_ui_settings(bool restore_sessions);
 
        shared_ptr<Session> get_tab_session(int index) const;