[Git][pulseaudio/pavucontrol][master] 3 commits: Add a checkbox to hide unavailable profiles
Arun Raghavan (@arun)
gitlab at gitlab.freedesktop.org
Fri Sep 27 11:49:16 UTC 2024
Arun Raghavan pushed to branch master at PulseAudio / pavucontrol
Commits:
c46fbee8 by rohit haldipur at 2024-09-27T07:13:20-04:00
Add a checkbox to hide unavailable profiles
- - - - -
72055b48 by rohit haldipur at 2024-09-27T07:13:21-04:00
Simplified logic for hiding unavailable/unplugged card profiles
- - - - -
b4af9ef7 by Arun Raghavan at 2024-09-27T07:46:22-04:00
Correctly handle profile list indices in dropdown
With the option to hide some profiles, we need to track the list store
index separately from the profile list iterator, so that the active
selection in the dropdown is correct. We also need to allow an invalid
selection, as an unavailable profile might be selected.
- - - - -
5 changed files:
- src/cardwidget.cc
- src/cardwidget.h
- src/mainwindow.cc
- src/mainwindow.h
- src/mainwindow.ui
Changes:
=====================================
src/cardwidget.cc
=====================================
@@ -52,6 +52,7 @@ CardWidget::CardWidget(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>
codecList->signal_changed().connect( sigc::mem_fun(*this, &CardWidget::onCodecChange));
hasProfileLock = false;
+ hideUnavailableProfiles = false;
profileLockToggleButton->signal_clicked().connect(sigc::mem_fun(*this, &CardWidget::onProfileLockToggleButton));
profileLockToggleButton->set_sensitive(true);
@@ -72,16 +73,25 @@ void CardWidget::prepareMenu() {
profileListStore->clear();
active_idx = -1;
+
/* Fill the ComboBox's Tree Model */
- for (uint32_t i = 0; i < profiles.size(); ++i) {
+ for (uint32_t i = 0, idx = 0; i < profiles.size(); ++i) {
+ if (hideUnavailableProfiles && !availableProfiles[profiles[i].first])
+ continue;
+
Gtk::TreeModel::Row row = *(profileListStore->append());
row[profileModel.name] = profiles[i].first;
row[profileModel.desc] = profiles[i].second;
+
if (profiles[i].first == activeProfile)
- active_idx = i;
+ active_idx = idx;
+
+ /* Track the index in the list store, as we might have few entries than
+ * all the profiles if unavailable profiles are hidden. */
+ idx++;
}
- if (active_idx >= 0)
+ if (profiles.size())
profileList->set_active(active_idx);
codecListStore->clear();
=====================================
src/cardwidget.h
=====================================
@@ -50,6 +50,7 @@ public:
// each entry in profiles is a pair of profile name and profile description
std::vector<std::pair<Glib::ustring, Glib::ustring>> profiles;
+ std::map<Glib::ustring, bool> availableProfiles;
std::map<Glib::ustring, PortInfo> ports;
Glib::ustring activeProfile;
bool hasSinks;
@@ -60,6 +61,7 @@ public:
Glib::ustring activeCodec;
bool hasProfileLock;
+ bool hideUnavailableProfiles;
void prepareMenu();
=====================================
src/mainwindow.cc
=====================================
@@ -97,6 +97,7 @@ MainWindow::MainWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>
sourceTypeComboBox = x->get_widget<Gtk::ComboBox>("sourceTypeComboBox");
notebook = x->get_widget<Gtk::Notebook>("notebook");
showVolumeMetersCheckButton = x->get_widget<Gtk::CheckButton>("showVolumeMetersCheckButton");
+ hideUnavailableCardProfilesCheckButton = x->get_widget<Gtk::CheckButton>("hideUnavailableCardProfilesCheckButton");
sinkInputTypeComboBox->set_active((int) showSinkInputType);
sourceOutputTypeComboBox->set_active((int) showSourceOutputType);
@@ -108,6 +109,7 @@ MainWindow::MainWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>
sinkTypeComboBox->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::onSinkTypeComboBoxChanged));
sourceTypeComboBox->signal_changed().connect(sigc::mem_fun(*this, &MainWindow::onSourceTypeComboBoxChanged));
showVolumeMetersCheckButton->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::onShowVolumeMetersCheckButtonToggled));
+ hideUnavailableCardProfilesCheckButton->signal_toggled().connect(sigc::mem_fun(*this, &MainWindow::onHideUnavailableCardProfilesCheckButtonToggled));
auto event_controller_key = Gtk::EventControllerKey::create();
event_controller_key->signal_key_pressed().connect(sigc::mem_fun(*this, &MainWindow::on_key_press_event), false);
@@ -130,6 +132,9 @@ MainWindow::MainWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>
if (g_key_file_has_key(config, "window", "showVolumeMeters", NULL)) {
showVolumeMetersCheckButton->set_active(g_key_file_get_boolean(config, "window", "showVolumeMeters", NULL));
}
+ if (g_key_file_has_key(config, "window", "hideUnavailableCardProfiles", NULL)) {
+ hideUnavailableCardProfilesCheckButton->set_active(g_key_file_get_boolean(config, "window", "hideUnavailableCardProfiles", NULL));
+ }
int default_width, default_height;
get_default_size(default_width, default_height);
@@ -237,6 +242,7 @@ MainWindow::~MainWindow() {
g_key_file_set_integer(config, "window", "sinkType", sinkTypeComboBox->get_active_row_number());
g_key_file_set_integer(config, "window", "sourceType", sourceTypeComboBox->get_active_row_number());
g_key_file_set_integer(config, "window", "showVolumeMeters", showVolumeMetersCheckButton->get_active());
+ g_key_file_set_integer(config, "window", "hideUnavailableCardProfiles", hideUnavailableCardProfilesCheckButton->get_active());
gsize filelen;
GError *err = NULL;
@@ -360,6 +366,8 @@ void MainWindow::updateCard(const pa_card_info &info) {
cardsVBox->append(*w);
w->unreference();
w->index = info.index;
+ w->hideUnavailableProfiles = hideUnavailableCardProfilesCheckButton->get_active();
+ w->prepareMenu();
is_new = true;
}
@@ -402,7 +410,7 @@ void MainWindow::updateCard(const pa_card_info &info) {
w->profiles.clear();
for (std::set<pa_card_profile_info2>::iterator profileIt = profile_priorities.begin(); profileIt != profile_priorities.end(); ++profileIt) {
- bool hasNo = false, hasOther = false;
+ bool hasNo = false, hasOther = false, available = true;
std::map<Glib::ustring, PortInfo>::iterator portIt;
Glib::ustring desc = profileIt->description;
@@ -419,13 +427,18 @@ void MainWindow::updateCard(const pa_card_info &info) {
break;
}
}
- if (hasNo && !hasOther)
+ if (hasNo && !hasOther) {
desc += _(" (unplugged)");
+ available = false;
+ }
- if (!profileIt->available)
+ if (!profileIt->available) {
desc += _(" (unavailable)");
+ available = false;
+ }
w->profiles.push_back(std::pair<Glib::ustring, Glib::ustring>(profileIt->name, desc));
+ w->availableProfiles[profileIt->name] = available;
}
w->activeProfile = info.active_profile ? info.active_profile->name : "";
@@ -1422,3 +1435,14 @@ void MainWindow::onShowVolumeMetersCheckButtonToggled() {
sw->setVolumeMeterVisible(state);
}
}
+
+
+void MainWindow::onHideUnavailableCardProfilesCheckButtonToggled() {
+ bool state = hideUnavailableCardProfilesCheckButton->get_active();
+
+ for (std::map<uint32_t, CardWidget*>::iterator it = cardWidgets.begin() ; it != cardWidgets.end(); it++) {
+ CardWidget *cw = it->second;
+ cw->hideUnavailableProfiles = state;
+ cw->prepareMenu();
+ }
+}
=====================================
src/mainwindow.h
=====================================
@@ -83,7 +83,7 @@ public:
Gtk::Box *streamsVBox, *recsVBox, *sinksVBox, *sourcesVBox, *cardsVBox;
Gtk::Label *noStreamsLabel, *noRecsLabel, *noSinksLabel, *noSourcesLabel, *noCardsLabel, *connectingLabel;
Gtk::ComboBox *sinkInputTypeComboBox, *sourceOutputTypeComboBox, *sinkTypeComboBox, *sourceTypeComboBox;
- Gtk::CheckButton *showVolumeMetersCheckButton;
+ Gtk::CheckButton *showVolumeMetersCheckButton, *hideUnavailableCardProfilesCheckButton;
std::map<uint32_t, CardWidget*> cardWidgets;
std::map<uint32_t, SinkWidget*> sinkWidgets;
@@ -102,6 +102,7 @@ public:
virtual void onSinkTypeComboBoxChanged();
virtual void onSourceTypeComboBoxChanged();
virtual void onShowVolumeMetersCheckButtonToggled();
+ virtual void onHideUnavailableCardProfilesCheckButtonToggled();
void setConnectionState(gboolean connected);
void updateDeviceVisibility();
=====================================
src/mainwindow.ui
=====================================
@@ -433,6 +433,13 @@
<property name="active">1</property>
</object>
</child>
+ <child>
+ <object class="GtkCheckButton" id="hideUnavailableCardProfilesCheckButton">
+ <property name="label" translatable="yes">Hide unavailable card profiles</property>
+ <property name="focusable">1</property>
+ <property name="active">0</property>
+ </object>
+ </child>
</object>
</child>
</object>
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pavucontrol/-/compare/34e364b880fc0a39ded730c3a1d474e793a777bd...b4af9ef7fa272bd2f174bf21ba6c49eafe89e226
--
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pavucontrol/-/compare/34e364b880fc0a39ded730c3a1d474e793a777bd...b4af9ef7fa272bd2f174bf21ba6c49eafe89e226
You're receiving this email because of your account on gitlab.freedesktop.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-commits/attachments/20240927/56e74a91/attachment-0001.htm>
More information about the pulseaudio-commits
mailing list