From: Devan Lai Date: Fri, 19 Apr 2019 04:38:15 +0000 (-0700) Subject: Add -s / --settings parameter to load a session setup file X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=611c86259f66dd1766b10b1e1b671b0fadd51fe2;ds=sidebyside Add -s / --settings parameter to load a session setup file --- diff --git a/doc/pulseview.1 b/doc/pulseview.1 index 8289eaa8..d5ec926d 100644 --- a/doc/pulseview.1 +++ b/doc/pulseview.1 @@ -64,6 +64,10 @@ file. .BR "\-I, \-\-input\-format " Specifies the format of the input file to be loaded. .TP +.BR "\-s, \-\-settings " +Load PulseView session setup to use with the input file. The setup file must be +in the "PulseView session setup" format (.pvs). +.TP .BR "\-c, \-\-clean" Prevents the previously used sessions to be restored from settings storage. This is useful if you want only a single session with the file given on the diff --git a/main.cpp b/main.cpp index 28c0a41f..1e4fe577 100644 --- a/main.cpp +++ b/main.cpp @@ -159,6 +159,7 @@ void usage() " -d, --driver Specify the device driver to use\n" " -D, --dont-scan Don't auto-scan for devices, use -d spec only\n" " -i, --input-file Load input from file\n" + " -s, --settings Load PulseView session setup from file\n" " -I, --input-format Input format\n" " -c, --clean Don't restore previous sessions on startup\n" "\n", PV_BIN_NAME); @@ -168,7 +169,7 @@ int main(int argc, char *argv[]) { int ret = 0; shared_ptr context; - string open_file_format, driver; + string open_file_format, open_setup_file, driver; vector open_files; bool restore_sessions = true; bool do_scan = true; @@ -199,6 +200,7 @@ int main(int argc, char *argv[]) {"driver", required_argument, nullptr, 'd'}, {"dont-scan", no_argument, nullptr, 'D'}, {"input-file", required_argument, nullptr, 'i'}, + {"settings", required_argument, nullptr, 's'}, {"input-format", required_argument, nullptr, 'I'}, {"clean", no_argument, nullptr, 'c'}, {"log-to-stdout", no_argument, nullptr, 's'}, @@ -206,7 +208,7 @@ int main(int argc, char *argv[]) }; const int c = getopt_long(argc, argv, - "h?VDcl:d:i:I:", long_options, nullptr); + "h?VDcl:d:i:s:I:", long_options, nullptr); if (c == -1) break; @@ -253,6 +255,10 @@ int main(int argc, char *argv[]) open_files.emplace_back(optarg); break; + case 's': + open_setup_file = optarg; + break; + case 'I': open_file_format = optarg; break; @@ -334,7 +340,8 @@ int main(int argc, char *argv[]) w.add_default_session(); else for (string& open_file : open_files) - w.add_session_with_file(open_file, open_file_format); + w.add_session_with_file(open_file, open_file_format, + open_setup_file); #ifdef ENABLE_SIGNALS if (SignalHandler::prepare_signals()) { diff --git a/manual/cli.txt b/manual/cli.txt index 001b6e9f..6187dbb9 100644 --- a/manual/cli.txt +++ b/manual/cli.txt @@ -23,6 +23,14 @@ Example: pulseview -i data.csv -I csv:samplerate=3000000 +If you previously saved a PulseView session setup alongside your input file, PulseView will +automatically load those settings so long as the setup file (.pvs) has the same base name +as your input file. +You can also manually specify a PulseView session setup file to load with -s / --settings. +Example: + + pulseview -s settings.pvs data.sr + The remaining parameters are mostly for debug purposes: -V / --version Shows the release version diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index aa0bf948..638d75b5 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -399,10 +399,13 @@ void MainWindow::remove_session(shared_ptr session) } void MainWindow::add_session_with_file(string open_file_name, - string open_file_format) + string open_file_format, + string open_setup_file_name) { shared_ptr session = add_session(); - session->load_init_file(open_file_name, open_file_format); + session->load_init_file(open_file_name, + open_file_format, + open_setup_file_name); } void MainWindow::add_default_session() diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index 2a2dabcd..bf8be0ad 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -92,7 +92,9 @@ public: void remove_session(shared_ptr session); - void add_session_with_file(string open_file_name, string open_file_format); + void add_session_with_file(string open_file_name, + string open_file_format, + string open_setup_file_name); void add_default_session(); diff --git a/pv/session.cpp b/pv/session.cpp index 245889d6..91e39756 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -525,7 +525,9 @@ Session::input_format_options(vector user_spec, return result; } -void Session::load_init_file(const string &file_name, const string &format) +void Session::load_init_file(const string &file_name, + const string &format, + const string &setup_file_name) { shared_ptr input_format; map input_opts; @@ -549,10 +551,13 @@ void Session::load_init_file(const string &file_name, const string &format) input_format->options()); } - load_file(QString::fromStdString(file_name), input_format, input_opts); + load_file(QString::fromStdString(file_name), + QString::fromStdString(setup_file_name), + input_format, input_opts); } void Session::load_file(QString file_name, + QString setup_file_name, shared_ptr format, const map &options) { @@ -582,10 +587,13 @@ void Session::load_file(QString file_name, return; } + // Default the setup filename with a .pvs extension if none is provided + if (setup_file_name.isEmpty() || setup_file_name.isNull()) { + setup_file_name = file_name; + setup_file_name.truncate(setup_file_name.lastIndexOf('.')); + setup_file_name.append(".pvs"); + } // Auto-load the setup if one exists - QString setup_file_name = file_name; - setup_file_name.truncate(setup_file_name.lastIndexOf('.')); - setup_file_name.append(".pvs"); if (QFileInfo::exists(setup_file_name) && QFileInfo(setup_file_name).isReadable()) { QSettings settings_storage(setup_file_name, QSettings::IniFormat); restore_setup(settings_storage); diff --git a/pv/session.hpp b/pv/session.hpp index 1dd48c95..7d9375a7 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -172,9 +172,12 @@ public: void set_default_device(); - void load_init_file(const string &file_name, const string &format); + void load_init_file(const string &file_name, + const string &format, + const string &setup_file_name); void load_file(QString file_name, + QString setup_file_name = nullptr, shared_ptr format = nullptr, const map &options = map()); diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index 85e55fb3..02661023 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -705,7 +705,7 @@ void MainBar::import_file(shared_ptr format) options = dlg.options(); } - session_.load_file(file_name, format, options); + session_.load_file(file_name, nullptr, format, options); const QString abs_path = QFileInfo(file_name).absolutePath(); settings.setValue(SettingOpenDirectory, abs_path);