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/sourceoutputwidget.cc | 84 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 25 deletions(-) (limited to 'src/sourceoutputwidget.cc') diff --git a/src/sourceoutputwidget.cc b/src/sourceoutputwidget.cc index 19ecda7..fb3f441 100644 --- a/src/sourceoutputwidget.cc +++ b/src/sourceoutputwidget.cc @@ -32,13 +32,13 @@ SourceOutputWidget::SourceOutputWidget(BaseObjectType* cobject, const Glib::RefP StreamWidget(cobject, x), mpMainWindow(NULL) { - directionLabel->set_label(_("Recording from ")); + gchar *txt; + directionLabel->set_label(txt = g_markup_printf_escaped("%s", _("from"))); + g_free(txt); } void SourceOutputWidget::init(MainWindow* mainWindow) { mpMainWindow = mainWindow; - deviceCombo->set_model(mpMainWindow->sourceTree); - deviceCombo->pack_start(mpMainWindow->deviceColumns.name); } SourceOutputWidget* SourceOutputWidget::create(MainWindow* mainWindow) { @@ -49,12 +49,22 @@ SourceOutputWidget* SourceOutputWidget::create(MainWindow* mainWindow) { return w; } +SourceOutputWidget::~SourceOutputWidget(void) { + clearMenu(); +} + void SourceOutputWidget::setSourceIndex(uint32_t idx) { mSourceIndex = idx; - mSuppressDeviceChange = true; - deviceCombo->set_active(mpMainWindow->sourceTreeIndexes[idx]); - mSuppressDeviceChange = false; + gchar *txt; + if (mpMainWindow->sourceWidgets.count(idx)) { + SourceWidget *w = mpMainWindow->sourceWidgets[idx]; + txt = g_markup_printf_escaped("%s", w->description.c_str()); + } + else + txt = g_markup_printf_escaped("%s", _("Unknown input")); + deviceLabel->set_label(txt); + g_free(txt); } uint32_t SourceOutputWidget::sourceIndex() { @@ -71,27 +81,51 @@ void SourceOutputWidget::onKill() { pa_operation_unref(o); } -void SourceOutputWidget::onDeviceChange() { - Gtk::TreeModel::iterator iter; - if (updating || mSuppressDeviceChange) - return; +void SourceOutputWidget::clearMenu() { + while (!sourceMenuItems.empty()) { + std::map::iterator i = sourceMenuItems.begin(); + delete i->second; + sourceMenuItems.erase(i); + } +} + +void SourceOutputWidget::buildMenu() { + for (std::map::iterator i = mpMainWindow->sourceWidgets.begin(); i != mpMainWindow->sourceWidgets.end(); ++i) { + SourceMenuItem *m; + sourceMenuItems[i->second->index] = m = new SourceMenuItem(this, i->second->description.c_str(), i->second->index, i->second->index == mSourceIndex); + menu.append(m->menuItem); + } + menu.show_all(); +} + +void SourceOutputWidget::SourceMenuItem::onToggle() { + if (widget->updating) + return; + + if (!menuItem.get_active()) + return; + + /*if (!mpMainWindow->sourceWidgets.count(widget->index)) + return;*/ + + pa_operation* o; + if (!(o = pa_context_move_source_output_by_index(get_context(), widget->index, index, NULL, NULL))) { + show_error(_("pa_context_move_source_output_by_index() failed")); + return; + } + + pa_operation_unref(o); +} - iter = deviceCombo->get_active(); - if (iter) +bool SourceOutputWidget::onDeviceChangePopup(GdkEventButton* event) { + if (GDK_BUTTON_PRESS == event->type && 1 == event->button) { - Gtk::TreeModel::Row row = *iter; - if (row) - { - pa_operation* o; - uint32_t source_index = row[mpMainWindow->deviceColumns.index]; - - if (!(o = pa_context_move_source_output_by_index(get_context(), source_index, index, NULL, NULL))) { - show_error(_("pa_context_move_source_output_by_index() failed")); - return; - } - - pa_operation_unref(o); - } + clearMenu(); + buildMenu(); + menu.popup(event->button, event->time); + return true; } + else + return false; } -- cgit