X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fmainwindow.cpp;h=d4c5f1f79ed27111c17bcbe9bee6a97902d4a7e8;hb=6842b5fc481eb43d9aeea81f17e211820d6dc405;hp=1a6dabd4b01f2ef11242b50ca2f9ee1f3e35a2d6;hpb=0a9fdca5f3874231414882a6bbf87a333a317711;p=pulseview.git diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 1a6dabd..d4c5f1f 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #ifdef ENABLE_DECODE #include #endif @@ -28,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -60,7 +63,9 @@ #include using std::list; +using std::map; using std::shared_ptr; +using std::string; namespace pv { @@ -79,6 +84,7 @@ MainWindow::MainWindow(DeviceManager &device_manager, _session(device_manager) { setup_ui(); + restore_ui_settings(); if (open_file_name) { const QString s(QString::fromUtf8(open_file_name)); QMetaObject::invokeMethod(this, "load_file", @@ -91,8 +97,6 @@ void MainWindow::setup_ui() { setObjectName(QString::fromUtf8("MainWindow")); - resize(1024, 768); - // Set the window icon QIcon icon; icon.addFile(QString::fromUtf8(":/icons/sigrok-logo-notext.png"), @@ -238,6 +242,7 @@ void MainWindow::setup_ui() // Setup the toolbar QToolBar *const toolbar = new QToolBar(tr("Main Toolbar"), this); + toolbar->setObjectName(QString::fromUtf8("MainToolbar")); toolbar->addAction(action_open); toolbar->addAction(action_save_as); toolbar->addSeparator(); @@ -263,7 +268,89 @@ 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")) { + restoreGeometry(settings.value("geometry").toByteArray()); + restoreState(settings.value("state").toByteArray()); + } else + 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( @@ -280,6 +367,10 @@ void MainWindow::update_device_list() shared_ptr selected_device = _session.get_device(); list< shared_ptr > devices; + + if (_device_manager.devices().size() == 0) + return; + std::copy(_device_manager.devices().begin(), _device_manager.devices().end(), std::back_inserter(devices)); @@ -291,6 +382,12 @@ void MainWindow::update_device_list() _sampling_bar->set_device_list(devices, selected_device); } +void MainWindow::closeEvent(QCloseEvent *event) +{ + save_ui_settings(); + event->accept(); +} + void MainWindow::load_file(QString file_name) { const QString errorMessage(