+
+ shared_ptr<devices::SessionFile> sessionfile_device =
+ dynamic_pointer_cast< devices::SessionFile >(device_);
+
+ if (sessionfile_device) {
+ settings.setValue("device_type", "sessionfile");
+ settings.beginGroup("device");
+ settings.setValue("filename", QString::fromStdString(
+ sessionfile_device->full_name()));
+ settings.endGroup();
+ }
+
+ // Save channels and decoders
+ for (shared_ptr<data::SignalBase> base : signalbases_) {
+#ifdef ENABLE_DECODE
+ if (base->is_decode_signal()) {
+ shared_ptr<pv::data::DecoderStack> decoder_stack =
+ base->decoder_stack();
+ std::shared_ptr<data::decode::Decoder> top_decoder =
+ decoder_stack->stack().front();
+
+ settings.beginGroup("decoder_stack" + QString::number(stacks++));
+ settings.setValue("id", top_decoder->decoder()->id);
+ settings.setValue("name", top_decoder->decoder()->name);
+ settings.endGroup();
+ } else
+#endif
+ {
+ settings.beginGroup(base->internal_name());
+ base->save_settings(settings);
+ settings.endGroup();
+ }
+ }
+
+ settings.setValue("decoder_stacks", stacks);
+
+ // Save view states and their signal settings
+ // Note: main_view must be saved as view0
+ settings.beginGroup("view" + QString::number(views++));
+ main_view_->save_settings(settings);
+ settings.endGroup();
+
+ for (shared_ptr<view::View> view : views_) {
+ if (view != main_view_) {
+ settings.beginGroup("view" + QString::number(views++));
+ view->save_settings(settings);
+ settings.endGroup();
+ }
+ }
+
+ settings.setValue("views", views);
+ }
+}
+
+void Session::restore_settings(QSettings &settings)
+{
+ shared_ptr<devices::Device> device;
+
+ QString device_type = settings.value("device_type").toString();
+
+ if (device_type == "hardware") {
+ map<string, string> dev_info;
+ list<string> key_list;
+
+ // Re-select last used device if possible but only if it's not demo
+ settings.beginGroup("device");
+ key_list.push_back("vendor");
+ key_list.push_back("model");
+ key_list.push_back("version");
+ key_list.push_back("serial_num");
+ key_list.push_back("connection_id");
+
+ for (string key : key_list) {
+ const QString k = QString::fromStdString(key);
+ if (!settings.contains(k))
+ continue;
+
+ const string value = settings.value(k).toString().toStdString();
+ if (!value.empty())
+ dev_info.insert(std::make_pair(key, value));
+ }
+
+ if (dev_info.count("model") > 0)
+ device = device_manager_.find_device_from_info(dev_info);
+
+ if (device)
+ set_device(device);
+
+ settings.endGroup();