diff options
Diffstat (limited to 'src/pavucontrol.cc')
-rw-r--r-- | src/pavucontrol.cc | 460 |
1 files changed, 385 insertions, 75 deletions
diff --git a/src/pavucontrol.cc b/src/pavucontrol.cc index 08b3877..7fef582 100644 --- a/src/pavucontrol.cc +++ b/src/pavucontrol.cc @@ -27,11 +27,16 @@ #include <gtkmm.h> #include <libglademm.h> +#include <libintl.h> + +#include <canberra-gtk.h> #include <pulse/pulseaudio.h> #include <pulse/glib-mainloop.h> #include <pulse/ext-stream-restore.h> +#include "i18n.h" + #ifndef GLADE_FILE #define GLADE_FILE "pavucontrol.glade" #endif @@ -88,6 +93,8 @@ public: bool can_decibel; bool volumeScaleEnabled; + Glib::ustring beepDevice; + virtual void set_sensitive(bool enabled); }; @@ -115,6 +122,8 @@ public: void enableVolumeMeter(); void updatePeak(double v); + Glib::ustring beepDevice; + protected: virtual bool on_button_press_event(GdkEventButton* event); }; @@ -143,6 +152,48 @@ public: virtual void executeVolumeUpdate(); }; +class CardWidget : public Gtk::VBox { +public: + CardWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x); + static CardWidget* create(); + + Gtk::Label *nameLabel; + Gtk::ToggleButton *streamToggleButton; + Gtk::Menu menu; + Gtk::Image *iconImage; + Glib::ustring name; + uint32_t index; + bool updating; + + std::map<Glib::ustring,Glib::ustring> profiles; + Glib::ustring activeProfile; + bool hasSinks; + bool hasSources; + + void prepareMenu(); + +protected: + virtual void onProfileChange(); + + //Tree model columns: + class ModelColumns : public Gtk::TreeModel::ColumnRecord + { + public: + + ModelColumns() + { add(name); add(desc); } + + Gtk::TreeModelColumn<Glib::ustring> name; + Gtk::TreeModelColumn<Glib::ustring> desc; + }; + + ModelColumns profileModel; + + //Child widgets: + Gtk::ComboBox *profileList; + Glib::RefPtr<Gtk::ListStore> treeModel; +}; + class SinkWidget : public StreamWidget { public: SinkWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x); @@ -151,7 +202,7 @@ public: SinkType type; Glib::ustring description; Glib::ustring name; - uint32_t index, monitor_index; + uint32_t index, monitor_index, card_index; bool can_decibel; Gtk::CheckMenuItem defaultMenuItem; @@ -169,7 +220,7 @@ public: SourceType type; Glib::ustring name; Glib::ustring description; - uint32_t index; + uint32_t index, card_index; bool can_decibel; Gtk::CheckMenuItem defaultMenuItem; @@ -275,6 +326,7 @@ public: static MainWindow* create(); virtual ~MainWindow(); + void updateCard(const pa_card_info &info); void updateSink(const pa_sink_info &info); void updateSource(const pa_source_info &info); void updateSinkInput(const pa_sink_input_info &info); @@ -284,6 +336,7 @@ public: void updateVolumeMeter(uint32_t source_index, uint32_t sink_input_index, double v); void updateRole(const pa_ext_stream_restore_info &info); + void removeCard(uint32_t index); void removeSink(uint32_t index); void removeSource(uint32_t index); void removeSinkInput(uint32_t index); @@ -291,10 +344,11 @@ public: void removeClient(uint32_t index); Gtk::Notebook *notebook; - Gtk::VBox *streamsVBox, *recsVBox, *sinksVBox, *sourcesVBox; - Gtk::Label *noStreamsLabel, *noRecsLabel, *noSinksLabel, *noSourcesLabel; + Gtk::VBox *streamsVBox, *recsVBox, *sinksVBox, *sourcesVBox, *cardsVBox; + Gtk::Label *noStreamsLabel, *noRecsLabel, *noSinksLabel, *noSourcesLabel, *noCardsLabel; Gtk::ComboBox *sinkInputTypeComboBox, *sourceOutputTypeComboBox, *sinkTypeComboBox, *sourceTypeComboBox; + std::map<uint32_t, CardWidget*> cardWidgets; std::map<uint32_t, SinkWidget*> sinkWidgets; std::map<uint32_t, SourceWidget*> sourceWidgets; std::map<uint32_t, SinkInputWidget*> sinkInputWidgets; @@ -373,13 +427,15 @@ void ChannelWidget::setVolume(pa_volume_t volume) { if (dB > PA_DECIBEL_MININFTY) { snprintf(txt, sizeof(txt), "%0.2f dB", dB); - volumeLabel->set_text(txt); + volumeLabel->set_tooltip_text(txt); } else - volumeLabel->set_markup("-∞dB"); - } else { - snprintf(txt, sizeof(txt), "%0.0f%%", v); - volumeLabel->set_text(txt); - } + volumeLabel->set_tooltip_markup("-∞dB"); + volumeLabel->set_has_tooltip(TRUE); + } else + volumeLabel->set_has_tooltip(FALSE); + + snprintf(txt, sizeof(txt), "%0.0f%%", v); + volumeLabel->set_text(txt); volumeScaleEnabled = false; volumeScale->set_value(v > 100 ? 100 : v); @@ -396,6 +452,23 @@ void ChannelWidget::onVolumeScaleValueChanged() { pa_volume_t volume = (pa_volume_t) ((volumeScale->get_value() * PA_VOLUME_NORM) / 100); streamWidget->updateChannelVolume(channel, volume); + + if (beepDevice != "") { + ca_context_change_device(ca_gtk_context_get(), beepDevice.c_str()); + + ca_context_cancel(ca_gtk_context_get(), 2); + + ca_gtk_play_for_widget(GTK_WIDGET(volumeScale->gobj()), + 2, + CA_PROP_EVENT_DESCRIPTION, _("Volume Control Feedback Sound"), + CA_PROP_EVENT_ID, "audio-volume-change", + CA_PROP_CANBERRA_CACHE_CONTROL, "permanent", + CA_PROP_CANBERRA_VOLUME, "0", + CA_PROP_CANBERRA_ENABLE, "1", + NULL); + + ca_context_change_device(ca_gtk_context_get(), NULL); + } } void ChannelWidget::set_sensitive(bool enabled) { @@ -406,6 +479,76 @@ void ChannelWidget::set_sensitive(bool enabled) { volumeScale->set_sensitive(enabled); } + + +/*** CardWidget ***/ +CardWidget::CardWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) : + Gtk::VBox(cobject) { + + x->get_widget("nameLabel", nameLabel); + x->get_widget("profileList", profileList); + x->get_widget("iconImage", iconImage); + + treeModel = Gtk::ListStore::create(profileModel); + profileList->set_model(treeModel); + profileList->pack_start(profileModel.desc); + + profileList->signal_changed().connect( sigc::mem_fun(*this, &CardWidget::onProfileChange)); +} + +CardWidget* CardWidget::create() { + CardWidget* w; + Glib::RefPtr<Gnome::Glade::Xml> x = Gnome::Glade::Xml::create(GLADE_FILE, "cardWidget"); + x->get_widget_derived("cardWidget", w); + return w; +} + + +void CardWidget::prepareMenu() { + int idx = 0; + int active_idx = -1; + + treeModel->clear(); + //Fill the ComboBox's Tree Model: + for (std::map<Glib::ustring, Glib::ustring>::iterator i = profiles.begin(); i != profiles.end(); ++i) { + Gtk::TreeModel::Row row = *(treeModel->append()); + row[profileModel.name] = i->first; + row[profileModel.desc] = i->second; + if (i->first == activeProfile) + active_idx = idx; + idx++; + } + + if (active_idx >= 0) + profileList->set_active(active_idx); +} + +void CardWidget::onProfileChange() { + Gtk::TreeModel::iterator iter; + + if (updating) + return; + + iter = profileList->get_active(); + if (iter) + { + Gtk::TreeModel::Row row = *iter; + if (row) + { + pa_operation* o; + Glib::ustring profile = row[profileModel.name]; + + if (!(o = pa_context_set_card_profile_by_index(context, index, profile.c_str(), NULL, NULL))) { + show_error(_("pa_context_set_card_profile_by_index() failed")); + return; + } + + pa_operation_unref(o); + } + } +} + + /*** MinimalStreamWidget ***/ MinimalStreamWidget::MinimalStreamWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) : Gtk::VBox(cobject), @@ -521,6 +664,7 @@ void StreamWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) { for (int i = 0; i < m.channels; i++) { ChannelWidget *cw = channelWidgets[i] = ChannelWidget::create(); + cw->beepDevice = beepDevice; cw->channel = i; cw->can_decibel = can_decibel; cw->streamWidget = this; @@ -600,7 +744,7 @@ void SinkWidget::executeVolumeUpdate() { pa_operation* o; if (!(o = pa_context_set_sink_volume_by_index(context, index, &volume, NULL, NULL))) { - show_error("pa_context_set_sink_volume_by_index() failed"); + show_error(_("pa_context_set_sink_volume_by_index() failed")); return; } @@ -615,7 +759,7 @@ void SinkWidget::onMuteToggleButton() { pa_operation* o; if (!(o = pa_context_set_sink_mute_by_index(context, index, muteToggleButton->get_active(), NULL, NULL))) { - show_error("pa_context_set_sink_mute_by_index() failed"); + show_error(_("pa_context_set_sink_mute_by_index() failed")); return; } @@ -629,7 +773,7 @@ void SinkWidget::onDefaultToggle() { return; if (!(o = pa_context_set_default_sink(context, name.c_str(), NULL, NULL))) { - show_error("pa_context_set_default_sink() failed"); + show_error(_("pa_context_set_default_sink() failed")); return; } pa_operation_unref(o); @@ -637,7 +781,7 @@ void SinkWidget::onDefaultToggle() { SourceWidget::SourceWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) : StreamWidget(cobject, x), - defaultMenuItem("_Default", true){ + defaultMenuItem(_("_Default"), true){ add_events(Gdk::BUTTON_PRESS_MASK); @@ -658,7 +802,7 @@ void SourceWidget::executeVolumeUpdate() { pa_operation* o; if (!(o = pa_context_set_source_volume_by_index(context, index, &volume, NULL, NULL))) { - show_error("pa_context_set_source_volume_by_index() failed"); + show_error(_("pa_context_set_source_volume_by_index() failed")); return; } @@ -673,7 +817,7 @@ void SourceWidget::onMuteToggleButton() { pa_operation* o; if (!(o = pa_context_set_source_mute_by_index(context, index, muteToggleButton->get_active(), NULL, NULL))) { - show_error("pa_context_set_source_mute_by_index() failed"); + show_error(_("pa_context_set_source_mute_by_index() failed")); return; } @@ -687,7 +831,7 @@ void SourceWidget::onDefaultToggle() { return; if (!(o = pa_context_set_default_source(context, name.c_str(), NULL, NULL))) { - show_error("pa_context_set_default_source() failed"); + show_error(_("pa_context_set_default_source() failed")); return; } pa_operation_unref(o); @@ -696,8 +840,8 @@ void SourceWidget::onDefaultToggle() { SinkInputWidget::SinkInputWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) : StreamWidget(cobject, x), mainWindow(NULL), - titleMenuItem("_Move Stream...", true), - killMenuItem("_Terminate Stream", true) { + titleMenuItem(_("_Move Stream..."), true), + killMenuItem(_("_Terminate Stream"), true) { add_events(Gdk::BUTTON_PRESS_MASK); @@ -723,7 +867,7 @@ void SinkInputWidget::executeVolumeUpdate() { pa_operation* o; if (!(o = pa_context_set_sink_input_volume(context, index, &volume, NULL, NULL))) { - show_error("pa_context_set_sink_input_volume() failed"); + show_error(_("pa_context_set_sink_input_volume() failed")); return; } @@ -738,7 +882,7 @@ void SinkInputWidget::onMuteToggleButton() { pa_operation* o; if (!(o = pa_context_set_sink_input_mute(context, index, muteToggleButton->get_active(), NULL, NULL))) { - show_error("pa_context_set_sink_input_mute() failed"); + show_error(_("pa_context_set_sink_input_mute() failed")); return; } @@ -772,7 +916,7 @@ void SinkInputWidget::buildMenu() { void SinkInputWidget::onKill() { pa_operation* o; if (!(o = pa_context_kill_sink_input(context, index, NULL, NULL))) { - show_error("pa_context_kill_sink_input() failed"); + show_error(_("pa_context_kill_sink_input() failed")); return; } @@ -789,7 +933,7 @@ void SinkInputWidget::SinkMenuItem::onToggle() { pa_operation* o; if (!(o = pa_context_move_sink_input_by_index(context, widget->index, index, NULL, NULL))) { - show_error("pa_context_move_sink_input_by_index() failed"); + show_error(_("pa_context_move_sink_input_by_index() failed")); return; } @@ -799,8 +943,8 @@ void SinkInputWidget::SinkMenuItem::onToggle() { SourceOutputWidget::SourceOutputWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) : MinimalStreamWidget(cobject, x), mainWindow(NULL), - titleMenuItem("_Move Stream...", true), - killMenuItem("_Terminate Stream", true) { + titleMenuItem(_("_Move Stream..."), true), + killMenuItem(_("_Terminate Stream"), true) { add_events(Gdk::BUTTON_PRESS_MASK); @@ -825,7 +969,7 @@ SourceOutputWidget* SourceOutputWidget::create() { void SourceOutputWidget::onKill() { pa_operation* o; if (!(o = pa_context_kill_source_output(context, index, NULL, NULL))) { - show_error("pa_context_kill_source_output() failed"); + show_error(_("pa_context_kill_source_output() failed")); return; } @@ -866,7 +1010,7 @@ void SourceOutputWidget::SourceMenuItem::onToggle() { pa_operation* o; if (!(o = pa_context_move_source_output_by_index(context, widget->index, index, NULL, NULL))) { - show_error("pa_context_move_source_output_by_index() failed"); + show_error(_("pa_context_move_source_output_by_index() failed")); return; } @@ -903,19 +1047,18 @@ void RoleWidget::executeVolumeUpdate() { info.channel_map.channels = 1; info.channel_map.map[0] = PA_CHANNEL_POSITION_MONO; info.volume = volume; - info.device = device.c_str(); + info.device = device == "" ? NULL : device.c_str(); info.mute = muteToggleButton->get_active(); pa_operation* o; if (!(o = pa_ext_stream_restore_write(context, PA_UPDATE_REPLACE, &info, 1, TRUE, NULL, NULL))) { - show_error("pa_ext_stream_restore_write() failed"); + show_error(_("pa_ext_stream_restore_write() failed")); return; } pa_operation_unref(o); } - /*** MainWindow ***/ MainWindow::MainWindow(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) : @@ -926,10 +1069,12 @@ MainWindow::MainWindow(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade: showSourceType(SOURCE_NO_MONITOR), eventRoleWidget(NULL){ + x->get_widget("cardsVBox", cardsVBox); x->get_widget("streamsVBox", streamsVBox); x->get_widget("recsVBox", recsVBox); x->get_widget("sinksVBox", sinksVBox); x->get_widget("sourcesVBox", sourcesVBox); + x->get_widget("noCardsLabel", noCardsLabel); x->get_widget("noStreamsLabel", noStreamsLabel); x->get_widget("noRecsLabel", noRecsLabel); x->get_widget("noSinksLabel", noSinksLabel); @@ -940,6 +1085,7 @@ MainWindow::MainWindow(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade: x->get_widget("sourceTypeComboBox", sourceTypeComboBox); x->get_widget("notebook", notebook); + cardsVBox->set_reallocate_redraws(true); sourcesVBox->set_reallocate_redraws(true); streamsVBox->set_reallocate_redraws(true); recsVBox->set_reallocate_redraws(true); @@ -977,14 +1123,72 @@ MainWindow::~MainWindow() { } } +static void set_icon_name_fallback(Gtk::Image *i, const char *name, Gtk::IconSize size) { + Glib::RefPtr<Gtk::IconTheme> theme; + Glib::RefPtr<Gdk::Pixbuf> pixbuf; + gint width = 24, height = 24; + + Gtk::IconSize::lookup(size, width, height); + theme = Gtk::IconTheme::get_default(); + pixbuf = theme->load_icon(name, width, Gtk::ICON_LOOKUP_GENERIC_FALLBACK); + + if (pixbuf) + i->set(pixbuf); + else + i->set(name); +} + +void MainWindow::updateCard(const pa_card_info &info) { + CardWidget *w; + bool is_new = false; + const char *description, *icon; + + if (cardWidgets.count(info.index)) + w = cardWidgets[info.index]; + else { + cardWidgets[info.index] = w = CardWidget::create(); + cardsVBox->pack_start(*w, false, false, 0); + w->index = info.index; + is_new = true; + } + + w->updating = true; + + description = pa_proplist_gets(info.proplist, PA_PROP_DEVICE_DESCRIPTION); + w->name = description ? description : info.name; + w->nameLabel->set_markup(w->name.c_str()); + + icon = pa_proplist_gets(info.proplist, PA_PROP_DEVICE_ICON_NAME); + set_icon_name_fallback(w->iconImage, icon ? icon : "audio-card", Gtk::ICON_SIZE_SMALL_TOOLBAR); + + w->hasSinks = w->hasSources = false; + w->profiles.clear(); + for (uint32_t i=0; i<info.n_profiles; ++i) { + w->hasSinks = w->hasSinks || (info.profiles[i].n_sinks > 0); + w->hasSources = w->hasSources || (info.profiles[i].n_sources > 0); + w->profiles.insert(std::pair<Glib::ustring,Glib::ustring>(info.profiles[i].name, info.profiles[i].description)); + } + w->activeProfile = info.active_profile->name; + //w->defaultMenuItem.set_active(w->name == defaultSinkName); + + w->updating = false; + + w->prepareMenu(); + + if (is_new) + updateDeviceVisibility(); +} + void MainWindow::updateSink(const pa_sink_info &info) { SinkWidget *w; bool is_new = false; + const char *icon; if (sinkWidgets.count(info.index)) w = sinkWidgets[info.index]; else { sinkWidgets[info.index] = w = SinkWidget::create(); + w->beepDevice = info.name; w->setChannelMap(info.channel_map, !!(info.flags & PA_SINK_DECIBEL_VOLUME)); sinksVBox->pack_start(*w, false, false, 0); w->index = info.index; @@ -994,6 +1198,7 @@ void MainWindow::updateSink(const pa_sink_info &info) { w->updating = true; + w->card_index = info.card; w->name = info.name; w->description = info.description; w->type = info.flags & PA_SINK_HARDWARE ? SINK_HARDWARE : SINK_VIRTUAL; @@ -1003,7 +1208,8 @@ void MainWindow::updateSink(const pa_sink_info &info) { w->nameLabel->set_markup(txt = g_markup_printf_escaped("%s", info.description)); g_free(txt); - w->iconImage->set_from_icon_name("audio-card", Gtk::ICON_SIZE_SMALL_TOOLBAR); + icon = pa_proplist_gets(info.proplist, PA_PROP_DEVICE_ICON_NAME); + set_icon_name_fallback(w->iconImage, icon ? icon : "audio-card", Gtk::ICON_SIZE_SMALL_TOOLBAR); w->setVolume(info.volume); w->muteToggleButton->set_active(info.mute); @@ -1029,7 +1235,7 @@ static void read_callback(pa_stream *s, size_t length, void *userdata) { double v; if (pa_stream_peek(s, &data, &length) < 0) { - show_error("Failed to read data from stream"); + show_error(_("Failed to read data from stream")); return; } @@ -1053,6 +1259,7 @@ void MainWindow::createMonitorStreamForSource(uint32_t source_idx) { char t[16]; pa_buffer_attr attr; pa_sample_spec ss; + return; ss.channels = 1; ss.format = PA_SAMPLE_FLOAT32; @@ -1060,11 +1267,12 @@ void MainWindow::createMonitorStreamForSource(uint32_t source_idx) { memset(&attr, 0, sizeof(attr)); attr.fragsize = sizeof(float); + attr.maxlength = (uint32_t) -1; snprintf(t, sizeof(t), "%u", source_idx); - if (!(s = pa_stream_new(context, "Peak detect", &ss, NULL))) { - show_error("Failed to create monitoring stream"); + if (!(s = pa_stream_new(context, _("Peak detect"), &ss, NULL))) { + show_error(_("Failed to create monitoring stream")); return; } @@ -1072,7 +1280,7 @@ void MainWindow::createMonitorStreamForSource(uint32_t source_idx) { pa_stream_set_suspended_callback(s, suspended_callback, this); if (pa_stream_connect_record(s, t, &attr, (pa_stream_flags_t) (PA_STREAM_DONT_MOVE|PA_STREAM_PEAK_DETECT|PA_STREAM_ADJUST_LATENCY)) < 0) { - show_error("Failed to connect monitoring stream"); + show_error(_("Failed to connect monitoring stream")); pa_stream_unref(s); return; } @@ -1084,6 +1292,7 @@ void MainWindow::createMonitorStreamForSinkInput(uint32_t sink_input_idx, uint32 pa_buffer_attr attr; pa_sample_spec ss; uint32_t monitor_source_idx; + return; ss.channels = 1; ss.format = PA_SAMPLE_FLOAT32; @@ -1096,11 +1305,12 @@ void MainWindow::createMonitorStreamForSinkInput(uint32_t sink_input_idx, uint32 memset(&attr, 0, sizeof(attr)); attr.fragsize = sizeof(float); + attr.maxlength = (uint32_t) -1; snprintf(t, sizeof(t), "%u", monitor_source_idx); - if (!(s = pa_stream_new(context, "Peak detect", &ss, NULL))) { - show_error("Failed to create monitoring stream"); + if (!(s = pa_stream_new(context, _("Peak detect"), &ss, NULL))) { + show_error(_("Failed to create monitoring stream")); return; } @@ -1109,7 +1319,7 @@ void MainWindow::createMonitorStreamForSinkInput(uint32_t sink_input_idx, uint32 pa_stream_set_suspended_callback(s, suspended_callback, this); if (pa_stream_connect_record(s, t, &attr, (pa_stream_flags_t) (PA_STREAM_DONT_MOVE|PA_STREAM_PEAK_DETECT|PA_STREAM_ADJUST_LATENCY)) < 0) { - show_error("Failed to connect monitoring stream"); + show_error(_("Failed to connect monitoring stream")); pa_stream_unref(s); return; } @@ -1118,6 +1328,7 @@ void MainWindow::createMonitorStreamForSinkInput(uint32_t sink_input_idx, uint32 void MainWindow::updateSource(const pa_source_info &info) { SourceWidget *w; bool is_new = false; + const char *icon; if (sourceWidgets.count(info.index)) w = sourceWidgets[info.index]; @@ -1134,6 +1345,7 @@ void MainWindow::updateSource(const pa_source_info &info) { w->updating = true; + w->card_index = info.card; w->name = info.name; w->description = info.description; w->type = info.monitor_of_sink != PA_INVALID_INDEX ? SOURCE_MONITOR : (info.flags & PA_SOURCE_HARDWARE ? SOURCE_HARDWARE : SOURCE_VIRTUAL); @@ -1143,7 +1355,8 @@ void MainWindow::updateSource(const pa_source_info &info) { w->nameLabel->set_markup(txt = g_markup_printf_escaped("%s", info.description)); g_free(txt); - w->iconImage->set_from_icon_name("audio-input-microphone", Gtk::ICON_SIZE_SMALL_TOOLBAR); + icon = pa_proplist_gets(info.proplist, PA_PROP_DEVICE_ICON_NAME); + set_icon_name_fallback(w->iconImage, icon ? icon : "audio-input-microphone", Gtk::ICON_SIZE_SMALL_TOOLBAR); w->setVolume(info.volume); w->muteToggleButton->set_active(info.mute); @@ -1349,7 +1562,7 @@ bool MainWindow::createEventRoleWidget() { eventRoleWidget->setChannelMap(cm, true); eventRoleWidget->boldNameLabel->set_text(""); - eventRoleWidget->nameLabel->set_label("System Sounds"); + eventRoleWidget->nameLabel->set_label(_("System Sounds")); eventRoleWidget->iconImage->set_from_icon_name("multimedia-volume-control", Gtk::ICON_SIZE_SMALL_TOOLBAR); @@ -1388,10 +1601,10 @@ void MainWindow::updateRole(const pa_ext_stream_restore_info &info) { eventRoleWidget->updating = true; - eventRoleWidget->device = info.device; + eventRoleWidget->device = info.device ? info.device : ""; volume.channels = 1; - volume.values[0] = pa_cvolume_avg(&info.volume); + volume.values[0] = pa_cvolume_max(&info.volume); eventRoleWidget->setVolume(volume); eventRoleWidget->muteToggleButton->set_active(info.mute); @@ -1510,6 +1723,20 @@ void MainWindow::reallyUpdateDeviceVisibility() { is_empty = true; + for (std::map<uint32_t, CardWidget*>::iterator i = cardWidgets.begin(); i != cardWidgets.end(); ++i) { + CardWidget* w = i->second; + + w->show(); + is_empty = false; + } + + if (is_empty) + noCardsLabel->show(); + else + noCardsLabel->hide(); + + is_empty = true; + for (std::map<uint32_t, SourceWidget*>::iterator i = sourceWidgets.begin(); i != sourceWidgets.end(); ++i) { SourceWidget* w = i->second; @@ -1537,6 +1764,17 @@ void MainWindow::reallyUpdateDeviceVisibility() { streamsVBox->show(); recsVBox->hide(); recsVBox->show(); + cardsVBox->hide(); + cardsVBox->show(); +} + +void MainWindow::removeCard(uint32_t index) { + if (!cardWidgets.count(index)) + return; + + delete cardWidgets[index]; + cardWidgets.erase(index); + updateDeviceVisibility(); } void MainWindow::removeSink(uint32_t index) { @@ -1624,11 +1862,33 @@ static void dec_outstanding(MainWindow *w) { w->get_window()->set_cursor(); } +void card_cb(pa_context *, const pa_card_info *i, int eol, void *userdata) { + MainWindow *w = static_cast<MainWindow*>(userdata); + + if (eol < 0) { + if (pa_context_errno(context) == PA_ERR_NOENTITY) + return; + + show_error(_("Card callback failure")); + return; + } + + if (eol > 0) { + dec_outstanding(w); + return; + } + + w->updateCard(*i); +} + void sink_cb(pa_context *, const pa_sink_info *i, int eol, void *userdata) { MainWindow *w = static_cast<MainWindow*>(userdata); if (eol < 0) { - show_error("Sink callback failure"); + if (pa_context_errno(context) == PA_ERR_NOENTITY) + return; + + show_error(_("Sink callback failure")); return; } @@ -1644,7 +1904,10 @@ void source_cb(pa_context *, const pa_source_info *i, int eol, void *userdata) { MainWindow *w = static_cast<MainWindow*>(userdata); if (eol < 0) { - show_error("Source callback failure"); + if (pa_context_errno(context) == PA_ERR_NOENTITY) + return; + + show_error(_("Source callback failure")); return; } @@ -1660,7 +1923,10 @@ void sink_input_cb(pa_context *, const pa_sink_input_info *i, int eol, void *use MainWindow *w = static_cast<MainWindow*>(userdata); if (eol < 0) { - show_error("Sink input callback failure"); + if (pa_context_errno(context) == PA_ERR_NOENTITY) + return; + + show_error(_("Sink input callback failure")); return; } @@ -1676,7 +1942,10 @@ void source_output_cb(pa_context *, const pa_source_output_info *i, int eol, voi MainWindow *w = static_cast<MainWindow*>(userdata); if (eol < 0) { - show_error("Source output callback failure"); + if (pa_context_errno(context) == PA_ERR_NOENTITY) + return; + + show_error(_("Source output callback failure")); return; } @@ -1707,7 +1976,10 @@ void client_cb(pa_context *, const pa_client_info *i, int eol, void *userdata) { MainWindow *w = static_cast<MainWindow*>(userdata); if (eol < 0) { - show_error("Client callback failure"); + if (pa_context_errno(context) == PA_ERR_NOENTITY) + return; + + show_error(_("Client callback failure")); return; } @@ -1723,7 +1995,7 @@ void server_info_cb(pa_context *, const pa_server_info *i, void *userdata) { MainWindow *w = static_cast<MainWindow*>(userdata); if (!i) { - show_error("Server info callback failure"); + show_error(_("Server info callback failure")); return; } @@ -1740,7 +2012,7 @@ void ext_stream_restore_read_cb( MainWindow *w = static_cast<MainWindow*>(userdata); if (eol < 0) { - g_debug("Failed to initialized stream_restore extension: %s", pa_strerror(pa_context_errno(context))); + g_debug(_("Failed to initialized stream_restore extension: %s"), pa_strerror(pa_context_errno(context))); w->deleteEventRoleWidget(); return; } @@ -1760,7 +2032,7 @@ static void ext_stream_restore_subscribe_cb(pa_context *c, void *userdata) { pa_operation *o; if (!(o = pa_ext_stream_restore_read(c, ext_stream_restore_read_cb, w))) { - show_error("pa_ext_stream_restore_read() failed"); + show_error(_("pa_ext_stream_restore_read() failed")); return; } @@ -1777,7 +2049,7 @@ void subscribe_cb(pa_context *c, pa_subscription_event_type_t t, uint32_t index, else { pa_operation *o; if (!(o = pa_context_get_sink_info_by_index(c, index, sink_cb, w))) { - show_error("pa_context_get_sink_info_by_index() failed"); + show_error(_("pa_context_get_sink_info_by_index() failed")); return; } pa_operation_unref(o); @@ -1790,7 +2062,7 @@ void subscribe_cb(pa_context *c, pa_subscription_event_type_t t, uint32_t index, else { pa_operation *o; if (!(o = pa_context_get_source_info_by_index(c, index, source_cb, w))) { - show_error("pa_context_get_source_info_by_index() failed"); + show_error(_("pa_context_get_source_info_by_index() failed")); return; } pa_operation_unref(o); @@ -1803,7 +2075,7 @@ void subscribe_cb(pa_context *c, pa_subscription_event_type_t t, uint32_t index, else { pa_operation *o; if (!(o = pa_context_get_sink_input_info(c, index, sink_input_cb, w))) { - show_error("pa_context_get_sink_input_info() failed"); + show_error(_("pa_context_get_sink_input_info() failed")); return; } pa_operation_unref(o); @@ -1816,7 +2088,7 @@ void subscribe_cb(pa_context *c, pa_subscription_event_type_t t, uint32_t index, else { pa_operation *o; if (!(o = pa_context_get_source_output_info(c, index, source_output_cb, w))) { - show_error("pa_context_get_sink_input_info() failed"); + show_error(_("pa_context_get_sink_input_info() failed")); return; } pa_operation_unref(o); @@ -1829,7 +2101,7 @@ void subscribe_cb(pa_context *c, pa_subscription_event_type_t t, uint32_t index, else { pa_operation *o; if (!(o = pa_context_get_client_info(c, index, client_cb, w))) { - show_error("pa_context_get_client_info() failed"); + show_error(_("pa_context_get_client_info() failed")); return; } pa_operation_unref(o); @@ -1837,13 +2109,28 @@ void subscribe_cb(pa_context *c, pa_subscription_event_type_t t, uint32_t index, break; case PA_SUBSCRIPTION_EVENT_SERVER: { - pa_operation *o; - if (!(o = pa_context_get_server_info(c, server_info_cb, w))) { - show_error("pa_context_get_server_info() failed"); - return; + pa_operation *o; + if (!(o = pa_context_get_server_info(c, server_info_cb, w))) { + show_error(_("pa_context_get_server_info() failed")); + return; + } + pa_operation_unref(o); } - pa_operation_unref(o); - } + break; + + case PA_SUBSCRIPTION_EVENT_CARD: + if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) + w->removeCard(index); + else { + pa_operation *o; + if (!(o = pa_context_get_card_info_by_index(c, index, card_cb, w))) { + show_error(_("pa_context_get_card_info_by_index() failed")); + return; + } + pa_operation_unref(o); + } + break; + } } @@ -1870,49 +2157,64 @@ void context_state_callback(pa_context *c, void *userdata) { PA_SUBSCRIPTION_MASK_SINK_INPUT| PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT| PA_SUBSCRIPTION_MASK_CLIENT| - PA_SUBSCRIPTION_MASK_SERVER), NULL, NULL))) { - show_error("pa_context_subscribe() failed"); + PA_SUBSCRIPTION_MASK_SERVER| + PA_SUBSCRIPTION_MASK_CARD), NULL, NULL))) { + show_error(_("pa_context_subscribe() failed")); return; } pa_operation_unref(o); + // Keep track of the outstanding callbacks for UI tweaks + n_outstanding = 0; + if (!(o = pa_context_get_server_info(c, server_info_cb, w))) { - show_error("pa_context_get_server_info() failed"); + show_error(_("pa_context_get_server_info() failed")); return; } pa_operation_unref(o); + n_outstanding++; if (!(o = pa_context_get_client_info_list(c, client_cb, w))) { - show_error("pa_context_client_info_list() failed"); + show_error(_("pa_context_client_info_list() failed")); + return; + } + pa_operation_unref(o); + n_outstanding++; + + if (!(o = pa_context_get_card_info_list(c, card_cb, w))) { + show_error(_("pa_context_get_card_info_list() failed")); return; } pa_operation_unref(o); + n_outstanding++; if (!(o = pa_context_get_sink_info_list(c, sink_cb, w))) { - show_error("pa_context_get_sink_info_list() failed"); + show_error(_("pa_context_get_sink_info_list() failed")); return; } pa_operation_unref(o); + n_outstanding++; if (!(o = pa_context_get_source_info_list(c, source_cb, w))) { - show_error("pa_context_get_source_info_list() failed"); + show_error(_("pa_context_get_source_info_list() failed")); return; } pa_operation_unref(o); + n_outstanding++; if (!(o = pa_context_get_sink_input_info_list(c, sink_input_cb, w))) { - show_error("pa_context_get_sink_input_info_list() failed"); + show_error(_("pa_context_get_sink_input_info_list() failed")); return; } pa_operation_unref(o); + n_outstanding++; if (!(o = pa_context_get_source_output_info_list(c, source_output_cb, w))) { - show_error("pa_context_get_source_output_info_list() failed"); + show_error(_("pa_context_get_source_output_info_list() failed")); return; } pa_operation_unref(o); - - n_outstanding = 6; + n_outstanding++; /* This call is not always supported */ if ((o = pa_ext_stream_restore_read(c, ext_stream_restore_read_cb, w))) { @@ -1925,13 +2227,13 @@ void context_state_callback(pa_context *c, void *userdata) { pa_operation_unref(o); } else - g_debug("Failed to initialized stream_restore extension: %s", pa_strerror(pa_context_errno(context))); + g_debug(_("Failed to initialized stream_restore extension: %s"), pa_strerror(pa_context_errno(context))); break; } case PA_CONTEXT_FAILED: - show_error("Connection failed"); + show_error(_("Connection failed")); return; case PA_CONTEXT_TERMINATED: @@ -1942,10 +2244,18 @@ void context_state_callback(pa_context *c, void *userdata) { } int main(int argc, char *argv[]) { + + /* Initialize the i18n stuff */ + bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); + textdomain(GETTEXT_PACKAGE); + signal(SIGPIPE, SIG_IGN); Gtk::Main kit(argc, argv); + ca_context_set_driver(ca_gtk_context_get(), "pulse"); + Gtk::Window* mainWindow = MainWindow::create(); pa_glib_mainloop *m = pa_glib_mainloop_new(g_main_context_default()); @@ -1954,7 +2264,7 @@ int main(int argc, char *argv[]) { g_assert(api); pa_proplist *proplist = pa_proplist_new(); - pa_proplist_sets(proplist, PA_PROP_APPLICATION_NAME, "PulseAudio Volume Control"); + pa_proplist_sets(proplist, PA_PROP_APPLICATION_NAME, _("PulseAudio Volume Control")); pa_proplist_sets(proplist, PA_PROP_APPLICATION_ID, "org.PulseAudio.pavucontrol"); pa_proplist_sets(proplist, PA_PROP_APPLICATION_ICON_NAME, "audio-card"); pa_proplist_sets(proplist, PA_PROP_APPLICATION_VERSION, PACKAGE_VERSION); @@ -1967,7 +2277,7 @@ int main(int argc, char *argv[]) { pa_context_set_state_callback(context, context_state_callback, mainWindow); if (pa_context_connect(context, NULL, (pa_context_flags_t) 0, NULL) < 0) { - show_error("Connection failed"); + show_error(_("Connection failed")); goto finish; } |