channelwidget: refactor to reduce repetition
DeviceWidget and StreamWidget had some duplicate code to initialize ChannelWidgets. This patch moves some of the duplicated initialization code into ChannelWidgets to reduce repetition and to improve encapsulation.
This commit is contained in:
parent
46ce3e418e
commit
f200a10d98
|
@ -47,16 +47,32 @@ ChannelWidget::ChannelWidget(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Bu
|
||||||
volumeScale->signal_value_changed().connect(sigc::mem_fun(*this, &ChannelWidget::onVolumeScaleValueChanged));
|
volumeScale->signal_value_changed().connect(sigc::mem_fun(*this, &ChannelWidget::onVolumeScaleValueChanged));
|
||||||
}
|
}
|
||||||
|
|
||||||
ChannelWidget* ChannelWidget::create() {
|
ChannelWidget* ChannelWidget::createOne(MinimalStreamWidget *owner, int channelIndex, pa_channel_position channelPosition, bool can_decibel) {
|
||||||
ChannelWidget* w;
|
ChannelWidget* w;
|
||||||
Glib::RefPtr<Gtk::Builder> x = Gtk::Builder::create();
|
Glib::RefPtr<Gtk::Builder> x = Gtk::Builder::create();
|
||||||
x->add_from_file(GLADE_FILE, "adjustment1");
|
x->add_from_file(GLADE_FILE, "adjustment1");
|
||||||
x->add_from_file(GLADE_FILE, "channelWidget");
|
x->add_from_file(GLADE_FILE, "channelWidget");
|
||||||
x->get_widget_derived("channelWidget", w);
|
x->get_widget_derived("channelWidget", w);
|
||||||
w->reference();
|
w->reference();
|
||||||
|
|
||||||
|
w->channel = channelIndex;
|
||||||
|
w->can_decibel = can_decibel;
|
||||||
|
w->minimalStreamWidget = owner;
|
||||||
|
|
||||||
|
char text[64];
|
||||||
|
snprintf(text, sizeof(text), "<b>%s</b>", pa_channel_position_to_pretty_string(channelPosition));
|
||||||
|
w->channelLabel->set_markup(text);
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChannelWidget::create(MinimalStreamWidget *owner, const pa_channel_map &m, bool can_decibel, ChannelWidget *widgets[PA_CHANNELS_MAX]) {
|
||||||
|
for (int i = 0; i < m.channels; i++)
|
||||||
|
widgets[i] = ChannelWidget::createOne(owner, i, m.map[i], can_decibel);
|
||||||
|
|
||||||
|
widgets[m.channels - 1]->last = true;
|
||||||
|
}
|
||||||
|
|
||||||
void ChannelWidget::setVolume(pa_volume_t volume) {
|
void ChannelWidget::setVolume(pa_volume_t volume) {
|
||||||
double v;
|
double v;
|
||||||
char txt[64];
|
char txt[64];
|
||||||
|
|
|
@ -28,7 +28,11 @@ class MinimalStreamWidget;
|
||||||
class ChannelWidget : public Gtk::EventBox {
|
class ChannelWidget : public Gtk::EventBox {
|
||||||
public:
|
public:
|
||||||
ChannelWidget(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& x);
|
ChannelWidget(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& x);
|
||||||
static ChannelWidget* create();
|
|
||||||
|
/* This creates multiple ChannelWidgets based on the given channel map. The
|
||||||
|
* widgets are stored in the caller-provided array. */
|
||||||
|
static void create(MinimalStreamWidget *owner, const pa_channel_map &m, bool can_decibel,
|
||||||
|
ChannelWidget *widgets[PA_CHANNELS_MAX]);
|
||||||
|
|
||||||
void setVolume(pa_volume_t volume);
|
void setVolume(pa_volume_t volume);
|
||||||
|
|
||||||
|
@ -47,7 +51,10 @@ public:
|
||||||
|
|
||||||
virtual void set_sensitive(bool enabled);
|
virtual void set_sensitive(bool enabled);
|
||||||
virtual void setBaseVolume(pa_volume_t);
|
virtual void setBaseVolume(pa_volume_t);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static ChannelWidget *createOne(MinimalStreamWidget *owner, int channelIndex, pa_channel_position channelPosition,
|
||||||
|
bool can_decibel);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -83,19 +83,13 @@ void DeviceWidget::init(MainWindow* mainWindow, Glib::ustring deviceType) {
|
||||||
|
|
||||||
void DeviceWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) {
|
void DeviceWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) {
|
||||||
channelMap = m;
|
channelMap = m;
|
||||||
|
ChannelWidget::create(this, m, can_decibel, channelWidgets);
|
||||||
|
|
||||||
for (int i = 0; i < m.channels; i++) {
|
for (int i = 0; i < m.channels; i++) {
|
||||||
ChannelWidget *cw = channelWidgets[i] = ChannelWidget::create();
|
ChannelWidget *cw = channelWidgets[i];
|
||||||
cw->channel = i;
|
|
||||||
cw->can_decibel = can_decibel;
|
|
||||||
cw->minimalStreamWidget = this;
|
|
||||||
char text[64];
|
|
||||||
snprintf(text, sizeof(text), "<b>%s</b>", pa_channel_position_to_pretty_string(m.map[i]));
|
|
||||||
cw->channelLabel->set_markup(text);
|
|
||||||
channelsVBox->pack_start(*cw, false, false, 0);
|
channelsVBox->pack_start(*cw, false, false, 0);
|
||||||
cw->unreference();
|
cw->unreference();
|
||||||
}
|
}
|
||||||
channelWidgets[m.channels-1]->last = true;
|
|
||||||
|
|
||||||
lockToggleButton->set_sensitive(m.channels > 1);
|
lockToggleButton->set_sensitive(m.channels > 1);
|
||||||
hideLockedChannels(lockToggleButton->get_active());
|
hideLockedChannels(lockToggleButton->get_active());
|
||||||
|
|
|
@ -76,18 +76,14 @@ bool StreamWidget::onContextTriggerEvent(GdkEventButton* event) {
|
||||||
void StreamWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) {
|
void StreamWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) {
|
||||||
channelMap = m;
|
channelMap = m;
|
||||||
|
|
||||||
|
ChannelWidget::create(this, m, can_decibel, channelWidgets);
|
||||||
|
|
||||||
for (int i = 0; i < m.channels; i++) {
|
for (int i = 0; i < m.channels; i++) {
|
||||||
ChannelWidget *cw = channelWidgets[i] = ChannelWidget::create();
|
ChannelWidget *cw = channelWidgets[i];
|
||||||
cw->channel = i;
|
|
||||||
cw->can_decibel = can_decibel;
|
|
||||||
cw->minimalStreamWidget = this;
|
|
||||||
char text[64];
|
|
||||||
snprintf(text, sizeof(text), "<b>%s</b>", pa_channel_position_to_pretty_string(m.map[i]));
|
|
||||||
cw->channelLabel->set_markup(text);
|
|
||||||
channelsVBox->pack_start(*cw, false, false, 0);
|
channelsVBox->pack_start(*cw, false, false, 0);
|
||||||
cw->unreference();
|
cw->unreference();
|
||||||
}
|
}
|
||||||
channelWidgets[m.channels-1]->last = true;
|
|
||||||
channelWidgets[m.channels-1]->setBaseVolume(PA_VOLUME_NORM);
|
channelWidgets[m.channels-1]->setBaseVolume(PA_VOLUME_NORM);
|
||||||
|
|
||||||
lockToggleButton->set_sensitive(m.channels > 1);
|
lockToggleButton->set_sensitive(m.channels > 1);
|
||||||
|
|
Loading…
Reference in New Issue