move some widget initializations from MinimalStreamWidget to subclasses

Current Glade versions want object IDs to be unique, but currently
pavucontrol.glade shares some IDs between the top-level windows. I guess
this used to be OK in the past, and the "interface-naming-policy
toplevel-contextual" comment in the beginning of the .glade file
probably has something to do with this. I want to update the .glade file
to be easy to work with current Glade versions, so I will remove the
duplicated object IDs.

The first IDs to change are the "channelsVBox", "nameLabel",
"boldNameLabel" and "iconImage" IDs. These were used by
MinimalStreamWidget to create widgets for both devices and streams, but
now that the IDs are different for devices and streams, the widgets have
to be created by the subclasses.

MinimalStreamWidget doesn't need the Gtk::Builder in its constructor any
more, so remove that parameter to avoid warnings about an unused
variable.
This commit is contained in:
Tanu Kaskinen 2018-11-21 11:06:51 +02:00
parent d3b3bee378
commit c760edaf24
5 changed files with 49 additions and 16 deletions

View File

@ -32,9 +32,15 @@
/*** DeviceWidget ***/
DeviceWidget::DeviceWidget(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& x) :
MinimalStreamWidget(cobject, x),
MinimalStreamWidget(cobject),
offsetButtonEnabled(false) {
/* MinimalStreamWidget member variables. */
x->get_widget("deviceChannelsVBox", channelsVBox);
x->get_widget("deviceNameLabel", nameLabel);
x->get_widget("deviceBoldNameLabel", boldNameLabel);
x->get_widget("deviceIconImage", iconImage);
x->get_widget("lockToggleButton", lockToggleButton);
x->get_widget("muteToggleButton", muteToggleButton);
x->get_widget("defaultToggleButton", defaultToggleButton);
@ -76,6 +82,8 @@ DeviceWidget::DeviceWidget(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Buil
void DeviceWidget::init(MainWindow* mainWindow, Glib::ustring deviceType) {
mpMainWindow = mainWindow;
mDeviceType = deviceType;
MinimalStreamWidget::init();
}
void DeviceWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) {

View File

@ -25,23 +25,31 @@
#include "minimalstreamwidget.h"
/*** MinimalStreamWidget ***/
MinimalStreamWidget::MinimalStreamWidget(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& x) :
MinimalStreamWidget::MinimalStreamWidget(BaseObjectType* cobject) :
Gtk::VBox(cobject),
channelsVBox(NULL),
nameLabel(NULL),
boldNameLabel(NULL),
iconImage(NULL),
peakProgressBar(),
lastPeak(0),
peak(NULL),
updating(false),
volumeMeterEnabled(false),
volumeMeterVisible(true) {
}
x->get_widget("channelsVBox", channelsVBox);
x->get_widget("nameLabel", nameLabel);
x->get_widget("boldNameLabel", boldNameLabel);
x->get_widget("iconImage", iconImage);
void MinimalStreamWidget::init() {
/* Set up the peak meter. This is not done in the constructor, because
* channelsVBox is initialized by the subclasses, so it's not yet available
* in the constructor. */
peakProgressBar.set_size_request(-1, 10);
channelsVBox->pack_end(peakProgressBar, false, false);
/* XXX: Why is the peak meter hidden by default? Maybe the idea is that if
* setting up the monitoring stream fails for whatever reason, then we
* shouldn't show the peak meter at all. */
peakProgressBar.hide();
}

View File

@ -25,11 +25,15 @@
class MinimalStreamWidget : public Gtk::VBox {
public:
MinimalStreamWidget(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& x);
MinimalStreamWidget(BaseObjectType* cobject);
/* Subclass constructors are expected to initialize these variables.
* MinimalStreamWidget can't initialize these, because the glade object
* id's depend on the subclass type. */
Gtk::VBox *channelsVBox;
Gtk::Label *nameLabel, *boldNameLabel;
Gtk::Image *iconImage;
Gtk::ProgressBar peakProgressBar;
double lastPeak;
pa_stream *peak;
@ -45,6 +49,11 @@ public:
void updatePeak(double v);
void setVolumeMeterVisible(bool v);
protected:
/* Subclasses must call this after the constructor to finalize the initial
* layout. */
virtual void init();
private :
bool volumeMeterVisible;

View File

@ -222,7 +222,7 @@
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkImage" id="iconImage">
<object class="GtkImage" id="deviceIconImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
@ -238,7 +238,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="boldNameLabel">
<object class="GtkLabel" id="deviceBoldNameLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_markup">True</property>
@ -250,7 +250,7 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="nameLabel">
<object class="GtkLabel" id="deviceNameLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
@ -393,7 +393,7 @@
</packing>
</child>
<child>
<object class="GtkVBox" id="channelsVBox">
<object class="GtkVBox" id="deviceChannelsVBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
@ -1437,7 +1437,7 @@
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkImage" id="iconImage">
<object class="GtkImage" id="streamIconImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
@ -1454,7 +1454,7 @@
<property name="can_focus">False</property>
<property name="spacing">2</property>
<child>
<object class="GtkLabel" id="boldNameLabel">
<object class="GtkLabel" id="streamBoldNameLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_markup">True</property>
@ -1466,7 +1466,7 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="nameLabel">
<object class="GtkLabel" id="streamNameLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
@ -1583,7 +1583,7 @@
</packing>
</child>
<child>
<object class="GtkVBox" id="channelsVBox">
<object class="GtkVBox" id="streamChannelsVBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>

View File

@ -30,9 +30,15 @@
/*** StreamWidget ***/
StreamWidget::StreamWidget(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& x) :
MinimalStreamWidget(cobject, x),
MinimalStreamWidget(cobject),
mpMainWindow(NULL) {
/* MinimalStreamWidget member variables. */
x->get_widget("streamChannelsVBox", channelsVBox);
x->get_widget("streamNameLabel", nameLabel);
x->get_widget("streamBoldNameLabel", boldNameLabel);
x->get_widget("streamIconImage", iconImage);
x->get_widget("lockToggleButton", lockToggleButton);
x->get_widget("muteToggleButton", muteToggleButton);
x->get_widget("directionLabel", directionLabel);
@ -55,6 +61,8 @@ StreamWidget::StreamWidget(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Buil
void StreamWidget::init(MainWindow* mainWindow) {
mpMainWindow = mainWindow;
MinimalStreamWidget::init();
}
bool StreamWidget::onContextTriggerEvent(GdkEventButton* event) {