Add -s / --settings parameter to load a session setup file
[pulseview.git] / pv / session.cpp
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);