]> sigrok.org Git - pulseview.git/commitdiff
Add -s / --settings parameter to load a session setup file
authorDevan Lai <redacted>
Fri, 19 Apr 2019 04:38:15 +0000 (21:38 -0700)
committerSoeren Apel <redacted>
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 8289eaa85f858becb08069c3b67a4e742105402c..d5ec926daac232883a170c06b448138b67fa89c5 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 28c0a41f6da1e6800413e20b67f79ea9f3c617ca..1e4fe577dc11328b4b07167b3ce1c42d16fdd075 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 001b6e9f2eb1dc576305e7c0e813a25b0d64b116..6187dbb986be218e164fccd0d7e436efc06e23c8 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 aa0bf94894f156c303dd094e936cbed8d9704fc7..638d75b5179fbb63c2e0151d6c6d09ff215b95c5 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 2a2dabcdc542cfd0d71490c99f3842e6852dc0c6..bf8be0ade1caa3b40caa765c721ebd71bcffc8ca 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 245889d65488e5c54f41eff9f9e4664c26b98c41..91e39756456045ccc37dd46ae66c8c9f53b4c8f3 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 1dd48c95c5ea0e994204151fbd100c7593bd89a7..7d9375a7451f414b14975557f6c49a3705361171 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 85e55fb3b17aa3194ae481c0b5fde9a1f1c20ceb..026610233c131a5a74a1f6eec39c5e5eed2ff4ca 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);