#include "mainbar.hpp"
#include <pv/devicemanager.hpp>
+#include <pv/devices/hardwaredevice.hpp>
#include <pv/mainwindow.hpp>
#include <pv/popups/deviceoptions.hpp>
#include <pv/popups/channels.hpp>
#include <pv/util.hpp>
#include <pv/widgets/exportmenu.hpp>
+#include <pv/widgets/importmenu.hpp>
#include <libsigrokcxx/libsigrokcxx.hpp>
using sigrok::Capability;
using sigrok::ConfigKey;
-using sigrok::Device;
using sigrok::Error;
+using sigrok::InputFormat;
namespace pv {
namespace toolbars {
setFloatable(false);
setContextMenuPolicy(Qt::PreventContextMenu);
+ // Open button
+ QToolButton *const open_button = new QToolButton(this);
+
+ widgets::ImportMenu *import_menu = new widgets::ImportMenu(this,
+ session.device_manager().context(),
+ main_window.action_open());
+ connect(import_menu,
+ SIGNAL(format_selected(std::shared_ptr<sigrok::InputFormat>)),
+ &main_window_,
+ SLOT(import_file(std::shared_ptr<sigrok::InputFormat>)));
+
+ open_button->setMenu(import_menu);
+ open_button->setDefaultAction(main_window.action_open());
+ open_button->setPopupMode(QToolButton::MenuButtonPopup);
+
// Save button
QToolButton *const save_button = new QToolButton(this);
QIcon(":/icons/menu.svg")));
// Setup the toolbar
- addAction(main_window.action_open());
+ addWidget(open_button);
addWidget(save_button);
addSeparator();
addAction(main_window.action_view_zoom_in());
void MainBar::update_device_list()
{
DeviceManager &mgr = session_.device_manager();
- shared_ptr<Device> selected_device = session_.device();
- list< shared_ptr<Device> > devs;
+ shared_ptr<devices::Device> selected_device = session_.device();
+ list< shared_ptr<devices::Device> > devs;
copy(mgr.devices().begin(), mgr.devices().end(), back_inserter(devs));
GVariant *gvar_list;
const uint64_t *elements = NULL;
gsize num_elements;
+ map< const ConfigKey*, std::set<Capability> > keys;
if (updating_sample_rate_)
return;
- const shared_ptr<Device> device = device_selector_.selected_device();
+ const shared_ptr<devices::Device> 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<sigrok::Device> sr_dev = device->device();
+
+ try {
+ keys = sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS);
+ } catch (Error) {}
+
const auto iter = keys.find(ConfigKey::SAMPLERATE);
if (iter != keys.end() &&
(*iter).second.find(sigrok::LIST) != (*iter).second.end()) {
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 (updating_sample_rate_)
return;
- const shared_ptr<Device> device = device_selector_.selected_device();
+ const shared_ptr<devices::Device> 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<Glib::Variant<guint64>>(gvar).get();
assert(!updating_sample_rate_);
if (updating_sample_count_)
return;
- const shared_ptr<Device> device = device_selector_.selected_device();
+ const shared_ptr<devices::Device> device =
+ device_selector_.selected_device();
if (!device)
return;
+ const shared_ptr<sigrok::Device> sr_dev = device->device();
+
assert(!updating_sample_count_);
updating_sample_count_ = true;
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);
+ sr_dev->config_list(ConfigKey::LIMIT_SAMPLES);
if (gvar.gobj())
g_variant_get(gvar.gobj(), "(tt)",
&min_sample_count, &max_sample_count);
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;
{
using namespace pv::popups;
- const shared_ptr<Device> device = device_selector_.selected_device();
+ const shared_ptr<devices::Device> device =
+ device_selector_.selected_device();
if (!device)
return;
+ const shared_ptr<sigrok::Device> 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);
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;
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<guint64>::create(1));
on_config_changed();
}
if (updating_sample_count_)
return;
- const shared_ptr<Device> device = device_selector_.selected_device();
+ const shared_ptr<devices::Device> device =
+ device_selector_.selected_device();
if (!device)
return;
+ const shared_ptr<sigrok::Device> sr_dev = device->device();
+
sample_count = sample_count_.value();
// Set the sample count
if (sample_count_supported_)
{
try {
- device->config_set(ConfigKey::LIMIT_SAMPLES,
+ sr_dev->config_set(ConfigKey::LIMIT_SAMPLES,
Glib::Variant<guint64>::create(sample_count));
on_config_changed();
} catch (Error error) {
if (updating_sample_rate_)
return;
- const shared_ptr<Device> device = device_selector_.selected_device();
+ const shared_ptr<devices::Device> device =
+ device_selector_.selected_device();
if (!device)
return;
+ const shared_ptr<sigrok::Device> sr_dev = device->device();
+
sample_rate = sample_rate_.value();
if (sample_rate == 0)
return;
assert(!updating_sample_rate_);
updating_sample_rate_ = true;
try {
- device->config_set(ConfigKey::SAMPLERATE,
+ sr_dev->config_set(ConfigKey::SAMPLERATE,
Glib::Variant<guint64>::create(sample_rate));
on_config_changed();
} catch (Error error) {
void MainBar::on_device_selected()
{
- shared_ptr<Device> device = device_selector_.selected_device();
+ shared_ptr<devices::Device> device = device_selector_.selected_device();
if (!device)
return;