diff options
author | Colin Guthrie <cguthrie@mandriva.org> | 2009-06-13 19:15:02 +0100 |
---|---|---|
committer | Colin Guthrie <cguthrie@mandriva.org> | 2009-06-17 08:54:14 +0100 |
commit | 02b316fcba8a112e528a0bddfcb93cf6f3179168 (patch) | |
tree | 96471135e9d83af7ebb275d77e71c9d0c0b6033d /src/sinkinputwidget.cc | |
parent | e71562619a67fa6823ba5d14c3df411b12fe192b (diff) |
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 <device>" or " from <device>"
where the <device> 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.
Diffstat (limited to 'src/sinkinputwidget.cc')
-rw-r--r-- | src/sinkinputwidget.cc | 87 |
1 files changed, 60 insertions, 27 deletions
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::RefPtr<Gno StreamWidget(cobject, x), mpMainWindow(NULL) { - directionLabel->set_label(_("<i>Playing on </i> ")); + gchar *txt; + directionLabel->set_label(txt = g_markup_printf_escaped("<i>%s</i>", _("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("<a href=\"\">%s</a>", w->description.c_str()); + } + else + txt = g_markup_printf_escaped("<a href=\"\">%s</a>", _("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<uint32_t, SinkMenuItem*>::iterator i = sinkMenuItems.begin(); + delete i->second; + sinkMenuItems.erase(i); + } +} - if (updating || mSuppressDeviceChange) - return; +void SinkInputWidget::buildMenu() { + for (std::map<uint32_t, SinkWidget*>::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; } |