From: Soeren Apel Date: Tue, 6 Jun 2017 14:14:54 +0000 (+0200) Subject: Fix #862 by implementing -c / --clean X-Git-Tag: pulseview-0.4.0~28 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=156f06e95f10587063b97b6b453a603751a0007c;p=pulseview.git Fix #862 by implementing -c / --clean --- diff --git a/main.cpp b/main.cpp index d0ca64a2..9c27f7b7 100644 --- 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 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 diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 86a01553..9286a06c 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -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 = 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 = 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 = add_session(); + session->restore_settings(settings); + settings.endGroup(); + } } } diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index 6541ccc6..ab0f871e 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -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 get_tab_session(int index) const;