From c760edaf24263c5f7772e4c32c064ec4ac5d1e4b Mon Sep 17 00:00:00 2001 From: Tanu Kaskinen Date: Wed, 21 Nov 2018 11:06:51 +0200 Subject: [PATCH] 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. --- src/devicewidget.cc | 10 +++++++++- src/minimalstreamwidget.cc | 18 +++++++++++++----- src/minimalstreamwidget.h | 11 ++++++++++- src/pavucontrol.glade | 16 ++++++++-------- src/streamwidget.cc | 10 +++++++++- 5 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/devicewidget.cc b/src/devicewidget.cc index 18d6714..b4cf9dd 100644 --- a/src/devicewidget.cc +++ b/src/devicewidget.cc @@ -32,9 +32,15 @@ /*** DeviceWidget ***/ DeviceWidget::DeviceWidget(BaseObjectType* cobject, const Glib::RefPtr& 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& 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(); } diff --git a/src/minimalstreamwidget.h b/src/minimalstreamwidget.h index e4f7e19..e5d774c 100644 --- a/src/minimalstreamwidget.h +++ b/src/minimalstreamwidget.h @@ -25,11 +25,15 @@ class MinimalStreamWidget : public Gtk::VBox { public: - MinimalStreamWidget(BaseObjectType* cobject, const Glib::RefPtr& 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; diff --git a/src/pavucontrol.glade b/src/pavucontrol.glade index a9c86b2..c8497a1 100644 --- a/src/pavucontrol.glade +++ b/src/pavucontrol.glade @@ -222,7 +222,7 @@ False 6 - + True False gtk-missing-image @@ -238,7 +238,7 @@ True False - + True False True @@ -250,7 +250,7 @@ - + True False 0 @@ -393,7 +393,7 @@ - + True False 6 @@ -1437,7 +1437,7 @@ False 6 - + True False gtk-missing-image @@ -1454,7 +1454,7 @@ False 2 - + True False True @@ -1466,7 +1466,7 @@ - + True False 0 @@ -1583,7 +1583,7 @@ - + True False 6 diff --git a/src/streamwidget.cc b/src/streamwidget.cc index 6085550..1682a70 100644 --- a/src/streamwidget.cc +++ b/src/streamwidget.cc @@ -30,9 +30,15 @@ /*** StreamWidget ***/ StreamWidget::StreamWidget(BaseObjectType* cobject, const Glib::RefPtr& 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