Add -s / --settings parameter to load a session setup file
authorDevan Lai <devan.lai@gmail.com>
Fri, 19 Apr 2019 04:38:15 +0000 (21:38 -0700)
committerSoeren Apel <soeren@apelpie.net>
Mon, 22 Apr 2019 12:19:47 +0000 (14:19 +0200)
doc/pulseview.1
main.cpp
manual/cli.txt
pv/mainwindow.cpp
pv/mainwindow.hpp
pv/session.cpp
pv/session.hpp
pv/toolbars/mainbar.cpp

index 8289eaa..d5ec926 100644 (file)
@@ -64,6 +64,10 @@ file.
 .BR "\-I, \-\-input\-format " <format>
 Specifies the format of the input file to be loaded.
 .TP
+.BR "\-s, \-\-settings " <filename>
+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
index 28c0a41..1e4fe57 100644 (file)
--- 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<sigrok::Context> context;
-       string open_file_format, driver;
+       string open_file_format, open_setup_file, driver;
        vector<string> 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()) {
index 001b6e9..6187dbb 100644 (file)
@@ -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
index aa0bf94..638d75b 100644 (file)
@@ -399,10 +399,13 @@ void MainWindow::remove_session(shared_ptr<Session> 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> 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()
index 2a2dabc..bf8be0a 100644 (file)
@@ -92,7 +92,9 @@ public:
 
        void remove_session(shared_ptr<Session> 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();
 
index 245889d..91e3975 100644 (file)
@@ -525,7 +525,9 @@ Session::input_format_options(vector<string> 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<InputFormat> input_format;
        map<string, Glib::VariantBase> 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<sigrok::InputFormat> format,
        const map<string, Glib::VariantBase> &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);
index 1dd48c9..7d9375a 100644 (file)
@@ -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<sigrok::InputFormat> format = nullptr,
                const map<string, Glib::VariantBase> &options =
                        map<string, Glib::VariantBase>());
index 85e55fb..0266102 100644 (file)
@@ -705,7 +705,7 @@ void MainBar::import_file(shared_ptr<InputFormat> 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);