X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;ds=sidebyside;f=pv%2Fmainwindow.cpp;h=d4c5f1f79ed27111c17bcbe9bee6a97902d4a7e8;hb=6842b5fc481eb43d9aeea81f17e211820d6dc405;hp=c3747e0256f945f81ce94fa5298ad7ce4c0c2904;hpb=858ae630aec11f2f1300897cc3ca127a4537e598;p=pulseview.git diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index c3747e0..d4c5f1f 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -63,7 +63,9 @@ #include using std::list; +using std::map; using std::shared_ptr; +using std::string; namespace pv { @@ -266,23 +268,53 @@ void MainWindow::setup_ui() // Setup _session events connect(&_session, SIGNAL(capture_state_changed(int)), this, SLOT(capture_state_changed(int))); - } void MainWindow::save_ui_settings() { QSettings settings; + map dev_info; + list key_list; + settings.beginGroup("MainWindow"); settings.setValue("state", saveState()); settings.setValue("geometry", saveGeometry()); settings.endGroup(); + + if (_session.get_device()) { + 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"); + + dev_info = _session.get_device()->get_device_info(); + + for (string key : key_list) { + + if (dev_info.count(key)) + settings.setValue(QString::fromUtf8(key.c_str()), + QString::fromUtf8(dev_info.at(key).c_str())); + else + settings.remove(QString::fromUtf8(key.c_str())); + } + + settings.endGroup(); + } } void MainWindow::restore_ui_settings() { QSettings settings; + shared_ptr device; + + map dev_info; + list key_list; + string value; + settings.beginGroup("MainWindow"); if (settings.contains("geometry")) { @@ -292,6 +324,33 @@ void MainWindow::restore_ui_settings() resize(1000, 720); settings.endGroup(); + + // Re-select last used device if possible. + 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) { + if (!settings.contains(QString::fromUtf8(key.c_str()))) + continue; + + value = settings.value(QString::fromUtf8(key.c_str())).toString().toStdString(); + + if (value.size() > 0) + dev_info.insert(std::make_pair(key, value)); + } + + device = _device_manager.find_device_from_info(dev_info); + + if (device) { + _session.set_device(device); + update_device_list(); + } + + settings.endGroup(); } void MainWindow::session_error(