From 02b316fcba8a112e528a0bddfcb93cf6f3179168 Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Sat, 13 Jun 2009 19:15:02 +0100 Subject: More changes in the UI to try and make things neater. This abandons the combo box approach an instead partially reverts to the popup. We now display a suffix after the stream title saying " on " or " from " where the part looks like a hyperlink and, when clicked, shows the popup to change the device. If there is only one device available, we suppress the whole thing and thus avoid confusion. --- src/sinkinputwidget.cc | 87 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 27 deletions(-) (limited to 'src/sinkinputwidget.cc') diff --git a/src/sinkinputwidget.cc b/src/sinkinputwidget.cc index 012e834..e5307b7 100644 --- a/src/sinkinputwidget.cc +++ b/src/sinkinputwidget.cc @@ -32,13 +32,13 @@ SinkInputWidget::SinkInputWidget(BaseObjectType* cobject, const Glib::RefPtrset_label(_("Playing on ")); + gchar *txt; + directionLabel->set_label(txt = g_markup_printf_escaped("%s", _("on"))); + g_free(txt); } void SinkInputWidget::init(MainWindow* mainWindow) { mpMainWindow = mainWindow; - deviceCombo->set_model(mpMainWindow->sinkTree); - deviceCombo->pack_start(mpMainWindow->deviceColumns.name); } SinkInputWidget* SinkInputWidget::create(MainWindow* mainWindow) { @@ -49,12 +49,22 @@ SinkInputWidget* SinkInputWidget::create(MainWindow* mainWindow) { return w; } +SinkInputWidget::~SinkInputWidget(void) { + clearMenu(); +} + void SinkInputWidget::setSinkIndex(uint32_t idx) { mSinkIndex = idx; - mSuppressDeviceChange = true; - deviceCombo->set_active(mpMainWindow->sinkTreeIndexes[idx]); - mSuppressDeviceChange = false; + gchar *txt; + if (mpMainWindow->sinkWidgets.count(idx)) { + SinkWidget *w = mpMainWindow->sinkWidgets[idx]; + txt = g_markup_printf_escaped("%s", w->description.c_str()); + } + else + txt = g_markup_printf_escaped("%s", _("Unknown output")); + deviceLabel->set_label(txt); + g_free(txt); } uint32_t SinkInputWidget::sinkIndex() { @@ -97,27 +107,50 @@ void SinkInputWidget::onKill() { pa_operation_unref(o); } -void SinkInputWidget::onDeviceChange() { - Gtk::TreeModel::iterator iter; +void SinkInputWidget::clearMenu() { + while (!sinkMenuItems.empty()) { + std::map::iterator i = sinkMenuItems.begin(); + delete i->second; + sinkMenuItems.erase(i); + } +} - if (updating || mSuppressDeviceChange) - return; +void SinkInputWidget::buildMenu() { + for (std::map::iterator i = mpMainWindow->sinkWidgets.begin(); i != mpMainWindow->sinkWidgets.end(); ++i) { + SinkMenuItem *m; + sinkMenuItems[i->second->index] = m = new SinkMenuItem(this, i->second->description.c_str(), i->second->index, i->second->index == mSinkIndex); + menu.append(m->menuItem); + } + menu.show_all(); +} - iter = deviceCombo->get_active(); - if (iter) - { - Gtk::TreeModel::Row row = *iter; - if (row) - { - pa_operation* o; - uint32_t sink_index = row[mpMainWindow->deviceColumns.index]; - - if (!(o = pa_context_move_sink_input_by_index(get_context(), index, sink_index, NULL, NULL))) { - show_error(_("pa_context_move_sink_input_by_index() failed")); - return; - } - - pa_operation_unref(o); - } - } +void SinkInputWidget::SinkMenuItem::onToggle() { + if (widget->updating) + return; + + if (!menuItem.get_active()) + return; + + /*if (!mpMainWindow->sinkWidgets.count(widget->index)) + return;*/ + + pa_operation* o; + if (!(o = pa_context_move_sink_input_by_index(get_context(), widget->index, index, NULL, NULL))) { + show_error(_("pa_context_move_sink_input_by_index() failed")); + return; + } + + pa_operation_unref(o); +} + +bool SinkInputWidget::onDeviceChangePopup(GdkEventButton* event) { + if (GDK_BUTTON_PRESS == event->type && 1 == event->button) + { + clearMenu(); + buildMenu(); + menu.popup(event->button, event->time); + return true; + } + else + return false; } -- cgit