From 8a5e95797f13a9a8dcb5f7b2cf1649cebb49f310 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 7 Aug 2006 13:29:46 +0000 Subject: add combobox to show only a subset of sinks/sources, replacing the old monitor expander git-svn-id: file:///home/lennart/svn/public/pavucontrol/trunk@38 c17c95f2-f111-0410-90bf-f30a9569010c --- src/pavucontrol.cc | 172 ++++++++++++++++++++----------- src/pavucontrol.glade | 277 ++++++++++++++++++++++++++++++++------------------ 2 files changed, 291 insertions(+), 158 deletions(-) diff --git a/src/pavucontrol.cc b/src/pavucontrol.cc index 4651db8..8397af5 100644 --- a/src/pavucontrol.cc +++ b/src/pavucontrol.cc @@ -35,7 +35,20 @@ #define GLADE_FILE "pavucontrol.glade" #endif -pa_context *context = NULL; +static pa_context *context = NULL; + +enum SinkType { + SINK_ALL, + SINK_HARDWARE, + SINK_VIRTUAL, +}; + +enum SourceType{ + SOURCE_ALL, + SOURCE_HARDWARE, + SOURCE_VIRTUAL, + SOURCE_MONITOR, +}; class StreamWidget; @@ -74,7 +87,7 @@ public: pa_channel_map channelMap; pa_cvolume volume; - + ChannelWidget *channelWidgets[PA_CHANNELS_MAX]; virtual void onMuteToggleButton(); @@ -91,6 +104,8 @@ public: SinkWidget(BaseObjectType* cobject, const Glib::RefPtr& x); static SinkWidget* create(); + SinkType type; + virtual void onMuteToggleButton(); uint32_t index; virtual void executeVolumeUpdate(); @@ -101,6 +116,8 @@ public: SourceWidget(BaseObjectType* cobject, const Glib::RefPtr& x); static SourceWidget* create(); + SourceType type; + virtual void onMuteToggleButton(); uint32_t index; virtual void executeVolumeUpdate(); @@ -131,17 +148,23 @@ public: void removeSinkInput(uint32_t index); void removeClient(uint32_t index); - Gtk::VBox *streamsVBox, *sinksVBox, *sourcesVBox, *monitorsVBox; + Gtk::VBox *streamsVBox, *sinksVBox, *sourcesVBox; Gtk::EventBox *titleEventBox; - Gtk::Label *noStreamsLabel, *noSinksLabel, *noSourcesLabel, *noMonitorsLabel; + Gtk::Label *noStreamsLabel, *noSinksLabel, *noSourcesLabel; + Gtk::ComboBox *sinkTypeComboBox, *sourceTypeComboBox; std::map sinkWidgets; std::map sourceWidgets; - std::map monitorWidgets; std::map streamWidgets; std::map clientNames; - void updateLabels(); + SinkType showSinkType; + SourceType showSourceType; + + virtual void onSinkTypeComboBoxChanged(); + virtual void onSourceTypeComboBoxChanged(); + + void updateDeviceVisibility(); }; void show_error(const char *txt) { @@ -375,22 +398,29 @@ void SinkInputWidget::executeVolumeUpdate() { /*** MainWindow ***/ MainWindow::MainWindow(BaseObjectType* cobject, const Glib::RefPtr& x) : - Gtk::Window(cobject) { + Gtk::Window(cobject), + showSinkType(SINK_HARDWARE), + showSourceType(SOURCE_HARDWARE) { x->get_widget("streamsVBox", streamsVBox); x->get_widget("sinksVBox", sinksVBox); x->get_widget("sourcesVBox", sourcesVBox); - x->get_widget("monitorsVBox", monitorsVBox); x->get_widget("titleEventBox", titleEventBox); x->get_widget("noStreamsLabel", noStreamsLabel); x->get_widget("noSinksLabel", noSinksLabel); x->get_widget("noSourcesLabel", noSourcesLabel); - x->get_widget("noMonitorsLabel", noMonitorsLabel); + x->get_widget("sinkTypeComboBox", sinkTypeComboBox); + x->get_widget("sourceTypeComboBox", sourceTypeComboBox); sourcesVBox->set_reallocate_redraws(true); - monitorsVBox->set_reallocate_redraws(true); streamsVBox->set_reallocate_redraws(true); sinksVBox->set_reallocate_redraws(true); + + sinkTypeComboBox->set_active((int) showSinkType); + sourceTypeComboBox->set_active((int) showSourceType); + + sinkTypeComboBox->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::onSinkTypeComboBoxChanged)); + sourceTypeComboBox->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::onSourceTypeComboBoxChanged)); Gdk::Color c("white"); titleEventBox->modify_bg(Gtk::STATE_NORMAL, c); @@ -420,6 +450,8 @@ void MainWindow::updateSink(const pa_sink_info &info) { w->index = info.index; } + w->type = info.flags & PA_SINK_HARDWARE ? SINK_HARDWARE : SINK_VIRTUAL; + gchar *txt; w->boldNameLabel->set_markup(txt = g_markup_printf_escaped("%s", info.name)); g_free(txt); @@ -428,27 +460,24 @@ void MainWindow::updateSink(const pa_sink_info &info) { w->setVolume(info.volume); w->muteToggleButton->set_active(info.mute); - w->onMuteToggleButton(); - updateLabels(); - w->queue_draw(); + updateDeviceVisibility(); } void MainWindow::updateSource(const pa_source_info &info) { SourceWidget *w; - std::map &l = info.monitor_of_sink != PA_INVALID_INDEX ? monitorWidgets : sourceWidgets; - Gtk::VBox *vbox = info.monitor_of_sink != PA_INVALID_INDEX ? monitorsVBox : sourcesVBox; - - if (l.count(info.index)) - w = l[info.index]; + if (sourceWidgets.count(info.index)) + w = sourceWidgets[info.index]; else { - l[info.index] = w = SourceWidget::create(); + sourceWidgets[info.index] = w = SourceWidget::create(); w->setChannelMap(info.channel_map); - vbox->pack_start(*w, false, false, 0); + sourcesVBox->pack_start(*w, false, false, 0); w->index = info.index; } + w->type = info.monitor_of_sink != PA_INVALID_INDEX ? SOURCE_MONITOR : (info.flags & PA_SOURCE_HARDWARE ? SOURCE_HARDWARE : SOURCE_VIRTUAL); + gchar *txt; w->boldNameLabel->set_markup(txt = g_markup_printf_escaped("%s", info.name)); g_free(txt); @@ -457,10 +486,8 @@ void MainWindow::updateSource(const pa_source_info &info) { w->setVolume(info.volume); w->muteToggleButton->set_active(info.mute); - w->onMuteToggleButton(); - updateLabels(); - w->queue_draw(); + updateDeviceVisibility(); } void MainWindow::updateSinkInput(const pa_sink_input_info &info) { @@ -490,8 +517,8 @@ void MainWindow::updateSinkInput(const pa_sink_input_info &info) { w->setVolume(info.volume); - updateLabels(); - w->queue_draw(); + w->show(); + updateDeviceVisibility(); } void MainWindow::updateClient(const pa_client_info &info) { @@ -513,64 +540,73 @@ void MainWindow::updateClient(const pa_client_info &info) { } } -void MainWindow::updateLabels() { +void MainWindow::updateDeviceVisibility() { + if (streamWidgets.empty()) noStreamsLabel->show(); else noStreamsLabel->hide(); - - if (sinkWidgets.empty()) + + sourcesVBox->hide_all(); + sinksVBox->hide_all(); + + bool is_empty = true; + + for (std::map::iterator i = sinkWidgets.begin(); i != sinkWidgets.end(); ++i) { + SinkWidget* w = i->second; + + if (showSinkType == SINK_ALL || w->type == showSinkType) { + w->show_all(); + is_empty = false; + } + } + + if (is_empty) noSinksLabel->show(); - else - noSinksLabel->hide(); + + is_empty = true; - if (sourceWidgets.empty()) + for (std::map::iterator i = sourceWidgets.begin(); i != sourceWidgets.end(); ++i) { + SourceWidget* w = i->second; + + if (showSourceType == SOURCE_ALL || w->type == showSourceType) { + w->show_all(); + is_empty = false; + } + } + + if (is_empty) noSourcesLabel->show(); - else - noSourcesLabel->hide(); - if (monitorWidgets.empty()) - noMonitorsLabel->show(); - else - noMonitorsLabel->hide(); + sourcesVBox->show(); + sinksVBox->show(); } void MainWindow::removeSink(uint32_t index) { - StreamWidget *w; - - if (!(w = sinkWidgets[index])) + if (!sinkWidgets.count(index)) return; + delete sinkWidgets[index]; sinkWidgets.erase(index); - delete w; - updateLabels(); + updateDeviceVisibility(); } void MainWindow::removeSource(uint32_t index) { - StreamWidget *w; - - if (sourceWidgets.count(index)) { - w = sourceWidgets[index]; - sourceWidgets.erase(index); - } else if (monitorWidgets.count(index)) { - w = monitorWidgets[index]; - monitorWidgets.erase(index); - } else + if (!sourceWidgets.count(index)) return; - delete w; - updateLabels(); + delete sourceWidgets[index]; + sourceWidgets.erase(index); + updateDeviceVisibility(); } void MainWindow::removeSinkInput(uint32_t index) { - StreamWidget *w; - - if (!(w = streamWidgets[index])) + if (!streamWidgets.count(index)) return; - + + delete streamWidgets[index]; streamWidgets.erase(index); - delete w; - updateLabels(); + updateDeviceVisibility(); } void MainWindow::removeClient(uint32_t index) { @@ -578,6 +614,24 @@ void MainWindow::removeClient(uint32_t index) { clientNames.erase(index); } +void MainWindow::onSinkTypeComboBoxChanged() { + showSinkType = (SinkType) sinkTypeComboBox->get_active_row_number(); + + if (showSinkType == (SinkType) -1) + sinkTypeComboBox->set_active((int) SINK_HARDWARE); + + updateDeviceVisibility(); +} + +void MainWindow::onSourceTypeComboBoxChanged() { + showSourceType = (SourceType) sourceTypeComboBox->get_active_row_number(); + + if (showSourceType == (SourceType) -1) + sourceTypeComboBox->set_active((int) SOURCE_HARDWARE); + + updateDeviceVisibility(); +} + void sink_cb(pa_context *, const pa_sink_info *i, int eol, void *userdata) { MainWindow *w = static_cast(userdata); diff --git a/src/pavucontrol.glade b/src/pavucontrol.glade index 2ac6b8a..f45ab5d 100644 --- a/src/pavucontrol.glade +++ b/src/pavucontrol.glade @@ -148,12 +148,12 @@ 12 - + True True True False - GTK_POS_RIGHT + GTK_POS_TOP False False @@ -217,7 +217,7 @@ True - _Streams + S_treams True False GTK_JUSTIFY_LEFT @@ -230,7 +230,7 @@ PANGO_ELLIPSIZE_NONE -1 False - 270 + 0 tab @@ -238,40 +238,100 @@ - - 12 + True - True - GTK_POLICY_NEVER - GTK_POLICY_AUTOMATIC - GTK_SHADOW_NONE - GTK_CORNER_TOP_LEFT + False + 0 - + + 12 True - GTK_SHADOW_IN + True + GTK_POLICY_NEVER + GTK_POLICY_AUTOMATIC + GTK_SHADOW_NONE + GTK_CORNER_TOP_LEFT + + + + True + GTK_SHADOW_IN + + + + True + False + 0 + + + + True + False + <i>No Sinks Available</i> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 16 + 16 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + + + + 0 + True + True + + + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 12 + 12 + 12 - + True False - 0 + 6 - + True - False - <i>No Sinks Available</i> - False + <b>S_how:</b> + True True GTK_JUSTIFY_LEFT False False - 0 + 0.5 0.5 - 16 - 16 + 0 + 0 PANGO_ELLIPSIZE_NONE -1 False @@ -283,9 +343,30 @@ False + + + + True + All Sinks +Hardware Sinks +Virtual Sinks + False + True + + + 0 + True + True + + + + 0 + False + True + @@ -297,7 +378,7 @@ True - _Sinks + S_inks True False GTK_JUSTIFY_LEFT @@ -310,7 +391,7 @@ PANGO_ELLIPSIZE_NONE -1 False - 270 + 0 tab @@ -318,25 +399,25 @@ - - 12 + True - True - GTK_POLICY_NEVER - GTK_POLICY_AUTOMATIC - GTK_SHADOW_NONE - GTK_CORNER_TOP_LEFT + False + 0 - + + 12 True - GTK_SHADOW_IN + True + GTK_POLICY_NEVER + GTK_POLICY_AUTOMATIC + GTK_SHADOW_NONE + GTK_CORNER_TOP_LEFT - + True - False - 0 + GTK_SHADOW_IN @@ -370,6 +451,53 @@ + + + + + + 0 + True + True + + + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 12 + 12 + 12 + + + + True + False + 6 + + + + True + <b>Sh_ow:</b> + True + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + 0 False @@ -378,68 +506,14 @@ - + True - True - False - 0 - - - - True - False - 0 - - - - True - False - <i>No Monitor Sources Available</i> - False - True - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 16 - 16 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - - - True - Monitor Sources - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - label_item - - + All Sources +Hardware Sources +Virtual Sources +Monitor Sources + False + True 0 @@ -450,6 +524,11 @@ + + 0 + False + True + @@ -461,7 +540,7 @@ True - _Sources + S_ources True False GTK_JUSTIFY_LEFT @@ -474,7 +553,7 @@ PANGO_ELLIPSIZE_NONE -1 False - 270 + 0 tab -- cgit