X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Ftoolbars%2Fmainbar.cpp;h=68f36ba367a7720eabd367d20e68f2bcfa2297c5;hb=474e817a724fdad4db635ba59202283fbcc22ef9;hp=61a467281520de949664fb15b41746e7b8a54c8a;hpb=bdf57963233028b4a01d87e706a575b85a45cbf5;p=pulseview.git diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index 61a46728..68f36ba3 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -1,7 +1,7 @@ /* * This file is part of the PulseView project. * - * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2012-2015 Joel Holdsworth * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,8 @@ #include -#include +#include +#include #include #include @@ -31,23 +32,27 @@ #include "mainbar.hpp" #include +#include #include #include #include #include +#include -#include +#include +using std::back_inserter; +using std::copy; +using std::list; using std::map; -using std::vector; using std::max; using std::min; using std::shared_ptr; using std::string; +using std::vector; using sigrok::Capability; using sigrok::ConfigKey; -using sigrok::Device; using sigrok::Error; namespace pv { @@ -61,8 +66,8 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : QToolBar("Sampling Bar", &main_window), session_(session), main_window_(main_window), - device_selector_(this), - updating_device_selector_(false), + device_selector_(this, session.device_manager(), + main_window.action_connect()), configure_button_(this), configure_button_action_(NULL), channels_button_(this), @@ -81,6 +86,35 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : setMovable(false); setFloatable(false); + setContextMenuPolicy(Qt::PreventContextMenu); + + // Save button + QToolButton *const save_button = new QToolButton(this); + + widgets::ExportMenu *export_menu = new widgets::ExportMenu(this, + session.device_manager().context(), + main_window.action_save_as()); + connect(export_menu, + SIGNAL(format_selected(std::shared_ptr)), + &main_window_, + SLOT(export_file(std::shared_ptr))); + + save_button->setMenu(export_menu); + save_button->setDefaultAction(main_window.action_save_as()); + save_button->setPopupMode(QToolButton::MenuButtonPopup); + + // Device selector menu + connect(&device_selector_, SIGNAL(device_selected()), + this, SLOT(on_device_selected())); + + // Setup the decoder button +#ifdef ENABLE_DECODE + QToolButton *add_decoder_button = new QToolButton(this); + add_decoder_button->setIcon(QIcon::fromTheme("add-decoder", + QIcon(":/icons/add-decoder.svg"))); + add_decoder_button->setPopupMode(QToolButton::InstantPopup); + add_decoder_button->setMenu(main_window_.menu_decoder_add()); +#endif // Setup the menu QMenu *const menu = new QMenu(this); @@ -100,7 +134,7 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : // Setup the toolbar addAction(main_window.action_open()); - addAction(main_window.action_save_as()); + addWidget(save_button); addSeparator(); addAction(main_window.action_view_zoom_in()); addAction(main_window.action_view_zoom_out()); @@ -112,8 +146,6 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : connect(&run_stop_button_, SIGNAL(clicked()), this, SLOT(on_run_stop())); - connect(&device_selector_, SIGNAL(currentIndexChanged (int)), - this, SLOT(on_device_selected())); connect(&sample_count_, SIGNAL(value_changed()), this, SLOT(on_sample_count_changed())); connect(&sample_rate_, SIGNAL(value_changed()), @@ -137,6 +169,10 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : addWidget(&sample_count_); addWidget(&sample_rate_); addWidget(&run_stop_button_); +#ifdef ENABLE_DECODE + addSeparator(); + addWidget(add_decoder_button); +#endif QWidget *const spacer = new QWidget(); spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -148,48 +184,22 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : sample_rate_.installEventFilter(this); } -void MainBar::set_device_list( - const std::list< std::shared_ptr > &devices, - shared_ptr selected) +void MainBar::update_device_list() { - int selected_index = -1; - - assert(selected); - - updating_device_selector_ = true; - - device_selector_.clear(); - - for (auto device : devices) { - assert(device); + DeviceManager &mgr = session_.device_manager(); + shared_ptr selected_device = session_.device(); + list< shared_ptr > devs; - string display_name = - session_.device_manager().get_display_name(device); + copy(mgr.devices().begin(), mgr.devices().end(), back_inserter(devs)); - if (selected == device) - selected_index = device_selector_.count(); - - device_selector_.addItem(display_name.c_str(), - qVariantFromValue(device)); - } - - // The selected device should have been in the list - assert(selected_index != -1); - device_selector_.setCurrentIndex(selected_index); + if (std::find(devs.begin(), devs.end(), selected_device) == devs.end()) + devs.push_back(selected_device); + assert(selected_device); + device_selector_.set_device_list(devs, selected_device); update_device_config_widgets(); - - updating_device_selector_ = false; } -shared_ptr MainBar::get_selected_device() const -{ - const int index = device_selector_.currentIndex(); - if (index < 0) - return shared_ptr(); - - return device_selector_.itemData(index).value>(); -} void MainBar::set_capture_state(pv::Session::capture_state state) { @@ -210,28 +220,28 @@ void MainBar::update_sample_rate_selector() if (updating_sample_rate_) return; - const shared_ptr device = get_selected_device(); + const shared_ptr device = + device_selector_.selected_device(); if (!device) return; assert(!updating_sample_rate_); updating_sample_rate_ = true; - const auto keys = device->config_keys(ConfigKey::DEVICE_OPTIONS); + const shared_ptr sr_dev = device->device(); + const auto keys = sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS); const auto iter = keys.find(ConfigKey::SAMPLERATE); if (iter != keys.end() && (*iter).second.find(sigrok::LIST) != (*iter).second.end()) { - const auto keys = device->config_keys( - ConfigKey::DEVICE_OPTIONS); try { - gvar_dict = device->config_list(ConfigKey::SAMPLERATE); + gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE); } catch(const sigrok::Error &e) { // Failed to enunmerate samplerate (void)e; } } - if (!gvar_dict) { + if (!gvar_dict.gobj()) { sample_rate_.show_none(); updating_sample_rate_ = false; return; @@ -283,12 +293,13 @@ void MainBar::update_sample_rate_selector_value() if (updating_sample_rate_) return; - const shared_ptr device = get_selected_device(); + const shared_ptr device = + device_selector_.selected_device(); if (!device) return; try { - auto gvar = device->config_get(ConfigKey::SAMPLERATE); + auto gvar = device->device()->config_get(ConfigKey::SAMPLERATE); uint64_t samplerate = Glib::VariantBase::cast_dynamic>(gvar).get(); assert(!updating_sample_rate_); @@ -306,10 +317,13 @@ void MainBar::update_sample_count_selector() if (updating_sample_count_) return; - const shared_ptr device = get_selected_device(); + const shared_ptr device = + device_selector_.selected_device(); if (!device) return; + const shared_ptr sr_dev = device->device(); + assert(!updating_sample_count_); updating_sample_count_ = true; @@ -327,14 +341,14 @@ void MainBar::update_sample_count_selector() if (sample_count == 0) sample_count = DefaultSampleCount; - const auto keys = device->config_keys(ConfigKey::DEVICE_OPTIONS); + const auto keys = sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS); const auto iter = keys.find(ConfigKey::LIMIT_SAMPLES); if (iter != keys.end() && (*iter).second.find(sigrok::LIST) != (*iter).second.end()) { try { auto gvar = - device->config_list(ConfigKey::LIMIT_SAMPLES); - if (gvar) + sr_dev->config_list(ConfigKey::LIMIT_SAMPLES); + if (gvar.gobj()) g_variant_get(gvar.gobj(), "(tt)", &min_sample_count, &max_sample_count); } catch(const sigrok::Error &e) { @@ -350,7 +364,7 @@ void MainBar::update_sample_count_selector() min_sample_count, max_sample_count); try { - auto gvar = device->config_get(ConfigKey::LIMIT_SAMPLES); + auto gvar = sr_dev->config_get(ConfigKey::LIMIT_SAMPLES); sample_count = g_variant_get_uint64(gvar.gobj()); if (sample_count == 0) sample_count = DefaultSampleCount; @@ -367,12 +381,17 @@ void MainBar::update_device_config_widgets() { using namespace pv::popups; - const shared_ptr device = get_selected_device(); + const shared_ptr device = + device_selector_.selected_device(); if (!device) return; + const shared_ptr sr_dev = device->device(); + if (!sr_dev) + return; + // Update the configure popup - DeviceOptions *const opts = new DeviceOptions(device, this); + DeviceOptions *const opts = new DeviceOptions(sr_dev, this); configure_button_action_->setVisible( !opts->binding().properties().empty()); configure_button_.set_popup(opts); @@ -385,7 +404,7 @@ void MainBar::update_device_config_widgets() sample_count_supported_ = false; try { - for (auto entry : device->config_keys(ConfigKey::DEVICE_OPTIONS)) + for (auto entry : sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS)) { auto key = entry.first; auto capabilities = entry.second; @@ -397,7 +416,7 @@ void MainBar::update_device_config_widgets() case SR_CONF_LIMIT_FRAMES: if (capabilities.count(Capability::SET)) { - device->config_set(ConfigKey::LIMIT_FRAMES, + sr_dev->config_set(ConfigKey::LIMIT_FRAMES, Glib::Variant::create(1)); on_config_changed(); } @@ -425,10 +444,13 @@ void MainBar::commit_sample_count() if (updating_sample_count_) return; - const shared_ptr device = get_selected_device(); + const shared_ptr device = + device_selector_.selected_device(); if (!device) return; + const shared_ptr sr_dev = device->device(); + sample_count = sample_count_.value(); // Set the sample count @@ -437,7 +459,7 @@ void MainBar::commit_sample_count() if (sample_count_supported_) { try { - device->config_set(ConfigKey::LIMIT_SAMPLES, + sr_dev->config_set(ConfigKey::LIMIT_SAMPLES, Glib::Variant::create(sample_count)); on_config_changed(); } catch (Error error) { @@ -455,10 +477,13 @@ void MainBar::commit_sample_rate() if (updating_sample_rate_) return; - const shared_ptr device = get_selected_device(); + const shared_ptr device = + device_selector_.selected_device(); if (!device) return; + const shared_ptr sr_dev = device->device(); + sample_rate = sample_rate_.value(); if (sample_rate == 0) return; @@ -467,7 +492,7 @@ void MainBar::commit_sample_rate() assert(!updating_sample_rate_); updating_sample_rate_ = true; try { - device->config_set(ConfigKey::SAMPLERATE, + sr_dev->config_set(ConfigKey::SAMPLERATE, Glib::Variant::create(sample_rate)); on_config_changed(); } catch (Error error) { @@ -479,10 +504,7 @@ void MainBar::commit_sample_rate() void MainBar::on_device_selected() { - if (updating_device_selector_) - return; - - shared_ptr device = get_selected_device(); + shared_ptr device = device_selector_.selected_device(); if (!device) return;