]> sigrok.org Git - pulseview.git/blobdiff - pv/session.cpp
Fix #540 by introducing a method to reset the view state
[pulseview.git] / pv / session.cpp
index 50e89e567041c2ec186e47e0d387457808f452a3..fba49be8900139f5405b7e4f6d461d235004aa8f 100644 (file)
@@ -207,7 +207,7 @@ void Session::save_settings(QSettings &settings) const
                }
 
                shared_ptr<devices::SessionFile> sessionfile_device =
-                       dynamic_pointer_cast< devices::SessionFile >(device_);
+                       dynamic_pointer_cast<devices::SessionFile>(device_);
 
                if (sessionfile_device) {
                        settings.setValue("device_type", "sessionfile");
@@ -217,6 +217,16 @@ void Session::save_settings(QSettings &settings) const
                        settings.endGroup();
                }
 
+               shared_ptr<devices::InputFile> inputfile_device =
+                       dynamic_pointer_cast<devices::InputFile>(device_);
+
+               if (inputfile_device) {
+                       settings.setValue("device_type", "inputfile");
+                       settings.beginGroup("device");
+                       inputfile_device->save_meta_to_settings(settings);
+                       settings.endGroup();
+               }
+
                // Save channels and decoders
                for (shared_ptr<data::SignalBase> base : signalbases_) {
 #ifdef ENABLE_DECODE
@@ -290,21 +300,34 @@ void Session::restore_settings(QSettings &settings)
                settings.endGroup();
        }
 
-       if (device_type == "sessionfile") {
-               settings.beginGroup("device");
-               QString filename = settings.value("filename").toString();
-               settings.endGroup();
+       if ((device_type == "sessionfile") || (device_type == "inputfile")) {
+               if (device_type == "sessionfile") {
+                       settings.beginGroup("device");
+                       QString filename = settings.value("filename").toString();
+                       settings.endGroup();
 
-               if (QFileInfo(filename).isReadable()) {
-                       device = make_shared<devices::SessionFile>(device_manager_.context(),
-                               filename.toStdString());
+                       if (QFileInfo(filename).isReadable()) {
+                               device = make_shared<devices::SessionFile>(device_manager_.context(),
+                                       filename.toStdString());
+                       }
+               }
+
+               if (device_type == "inputfile") {
+                       settings.beginGroup("device");
+                       device = make_shared<devices::InputFile>(device_manager_.context(),
+                               settings);
+                       settings.endGroup();
+               }
+
+               if (device) {
                        set_device(device);
 
                        start_capture([](QString infoMessage) {
                                // TODO Emulate noquote()
                                qDebug() << "Session error:" << infoMessage; });
 
-                       set_name(QFileInfo(filename).fileName());
+                       set_name(QString::fromStdString(
+                               dynamic_pointer_cast<devices::File>(device)->display_name(device_manager_)));
                }
        }
 
@@ -374,12 +397,13 @@ void Session::set_device(shared_ptr<devices::Device> device)
        name_ = default_name_;
        name_changed();
 
-       // Remove all stored data
+       // Remove all stored data and reset all views
        for (shared_ptr<views::ViewBase> view : views_) {
                view->clear_signals();
 #ifdef ENABLE_DECODE
                view->clear_decode_signals();
 #endif
+               view->reset_view_state();
        }
        for (const shared_ptr<data::SignalData> d : all_signal_data_)
                d->clear();
@@ -483,7 +507,6 @@ void Session::load_init_file(const string &file_name, const string &format)
        map<string, Glib::VariantBase> input_opts;
 
        if (!format.empty()) {
-               // Got a user provided input format spec.
                const map<string, shared_ptr<InputFormat> > formats =
                        device_manager_.context()->input_formats();
                auto user_opts = pv::util::split_string(format, ":");
@@ -500,11 +523,6 @@ void Session::load_init_file(const string &file_name, const string &format)
                input_format = (*iter).second;
                input_opts = input_format_options(user_opts,
                        input_format->options());
-       } else {
-               // (Try to) auto detect the input format. Lookup failure
-               // is not fatal, when no input module claimed responsibility,
-               // then a session file gets loaded.
-               input_format = device_manager_.context()->input_format_match(file_name);
        }
 
        load_file(QString::fromStdString(file_name), input_format, input_opts);
@@ -517,6 +535,10 @@ void Session::load_file(QString file_name,
        const QString errorMessage(
                QString("Failed to load file %1").arg(file_name));
 
+       // In the absence of a caller's format spec, try to auto detect.
+       // Assume "sigrok session file" upon lookup miss.
+       if (!format)
+               format = device_manager_.context()->input_format_match(file_name.toStdString());
        try {
                if (format)
                        set_device(shared_ptr<devices::Device>(
@@ -1050,15 +1072,10 @@ void Session::feed_in_meta(shared_ptr<Meta> meta)
        for (auto entry : meta->config()) {
                switch (entry.first->id()) {
                case SR_CONF_SAMPLERATE:
-                       // We can't rely on the header to always contain the sample rate,
-                       // so in case it's supplied via a meta packet, we use it.
-                       if (!cur_samplerate_)
-                               cur_samplerate_ = g_variant_get_uint64(entry.second.gobj());
-
-                       /// @todo handle samplerate changes
+                       cur_samplerate_ = g_variant_get_uint64(entry.second.gobj());
                        break;
                default:
-                       // Unknown metadata is not an error.
+                       qDebug() << "Received meta data key" << entry.first->id() << ", ignoring.";
                        break;
                }
        }