+void SamplingBar::update_sample_count_selector()
+{
+ GVariant *gvar;
+
+ if (_updating_sample_count)
+ return;
+
+ const shared_ptr<device::DevInst> dev_inst = get_selected_device();
+ if (!dev_inst)
+ return;
+
+ assert(!_updating_sample_count);
+ _updating_sample_count = true;
+
+ if (_sample_count_supported)
+ {
+ uint64_t sample_count = _sample_count.value();
+ uint64_t min_sample_count = 0;
+ uint64_t max_sample_count = MaxSampleCount;
+
+ if (sample_count == 0)
+ sample_count = DefaultSampleCount;
+
+ if ((gvar = dev_inst->list_config(NULL, SR_CONF_LIMIT_SAMPLES)))
+ {
+ g_variant_get(gvar, "(tt)",
+ &min_sample_count, &max_sample_count);
+ g_variant_unref(gvar);
+ }
+
+ min_sample_count = min(max(min_sample_count, MinSampleCount),
+ max_sample_count);
+
+ _sample_count.show_125_list(
+ min_sample_count, max_sample_count);
+
+ if ((gvar = dev_inst->get_config(NULL, SR_CONF_LIMIT_SAMPLES)))
+ {
+ sample_count = g_variant_get_uint64(gvar);
+ if (sample_count == 0)
+ sample_count = DefaultSampleCount;
+ sample_count = min(max(sample_count, MinSampleCount),
+ max_sample_count);
+
+ g_variant_unref(gvar);
+ }
+
+ _sample_count.set_value(sample_count);
+ }
+ else
+ _sample_count.show_none();
+
+ _updating_sample_count = false;
+}
+
+void SamplingBar::update_device_config_widgets()
+{
+ GVariant *gvar;
+
+ using namespace pv::popups;
+
+ const shared_ptr<device::DevInst> dev_inst = get_selected_device();
+ if (!dev_inst)
+ return;
+
+ // Update the configure popup
+ DeviceOptions *const opts = new DeviceOptions(dev_inst, this);
+ _configure_button_action->setVisible(
+ !opts->binding().properties().empty());
+ _configure_button.set_popup(opts);
+
+ // Update the channels popup
+ Channels *const channels = new Channels(_session, this);
+ _channels_button.set_popup(channels);
+
+ // Update supported options.
+ _sample_count_supported = false;
+
+ if ((gvar = dev_inst->list_config(NULL, SR_CONF_DEVICE_OPTIONS)))
+ {
+ gsize num_opts;
+ const int *const options =
+ (const int32_t *)g_variant_get_fixed_array(
+ gvar, &num_opts, sizeof(int32_t));
+ for (unsigned int i = 0; i < num_opts; i++)
+ {
+ switch (options[i] & SR_CONF_MASK) {
+ case SR_CONF_LIMIT_SAMPLES:
+ if (options[i] & SR_CONF_SET)
+ _sample_count_supported = true;
+ break;
+ case SR_CONF_LIMIT_FRAMES:
+ if (options[i] & SR_CONF_SET)
+ dev_inst->set_config(NULL, SR_CONF_LIMIT_FRAMES,
+ g_variant_new_uint64(1));
+ break;
+ }
+ }
+ }
+
+ // Add notification of reconfigure events
+ disconnect(this, SLOT(on_config_changed()));
+ connect(dev_inst.get(), SIGNAL(config_changed()),
+ this, SLOT(on_config_changed()));
+
+ // Update sweep timing widgets.
+ update_sample_count_selector();
+ update_sample_rate_selector();
+}
+
+void SamplingBar::commit_sample_count()
+{
+ uint64_t sample_count = 0;
+
+ if (_updating_sample_count)
+ return;
+
+ const shared_ptr<device::DevInst> dev_inst = get_selected_device();
+ if (!dev_inst)
+ return;
+
+ sample_count = _sample_count.value();
+
+ // Set the sample count
+ assert(!_updating_sample_count);
+ _updating_sample_count = true;
+ if (_sample_count_supported &&
+ !dev_inst->set_config(NULL, SR_CONF_LIMIT_SAMPLES,
+ g_variant_new_uint64(sample_count))) {
+ qDebug() << "Failed to configure sample count.";
+ return;
+ }
+ _updating_sample_count = false;
+}
+