3 commits - src/cardwidget.cc src/cardwidget.h src/mainwindow.cc src/mainwindow.h src/mainwindow.ui
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Sep 27 11:49:15 UTC 2024
src/cardwidget.cc | 16 +++++++++++++---
src/cardwidget.h | 2 ++
src/mainwindow.cc | 30 +++++++++++++++++++++++++++---
src/mainwindow.h | 3 ++-
src/mainwindow.ui | 7 +++++++
5 files changed, 51 insertions(+), 7 deletions(-)
New commits:
commit b4af9ef7fa272bd2f174bf21ba6c49eafe89e226
Author: Arun Raghavan <arun at asymptotic.io>
Date: Fri Sep 27 07:46:22 2024 -0400
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.
diff --git a/src/cardwidget.cc b/src/cardwidget.cc
index 7deba33..6f6ed76 100644
--- a/src/cardwidget.cc
+++ b/src/cardwidget.cc
@@ -73,19 +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();
commit 72055b484a8a7e94a0d75afd7ed6154fefee2c76
Author: rohit haldipur <rohithaldipur at gmail.com>
Date: Wed Aug 7 23:26:30 2024 +0530
Simplified logic for hiding unavailable/unplugged card profiles
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index f227b34..8a3f2f3 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -410,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;
@@ -427,14 +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] = hasOther && profileIt->available;
+ w->availableProfiles[profileIt->name] = available;
}
w->activeProfile = info.active_profile ? info.active_profile->name : "";
commit c46fbee81c28d38f7ce650bacb865429a0fdf739
Author: rohit haldipur <rohithaldipur at gmail.com>
Date: Mon Aug 5 11:30:37 2024 -0400
Add a checkbox to hide unavailable profiles
diff --git a/src/cardwidget.cc b/src/cardwidget.cc
index 05e0d0b..7deba33 100644
--- a/src/cardwidget.cc
+++ b/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);
@@ -74,6 +75,9 @@ void CardWidget::prepareMenu() {
active_idx = -1;
/* Fill the ComboBox's Tree Model */
for (uint32_t i = 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;
diff --git a/src/cardwidget.h b/src/cardwidget.h
index fcaacdd..27873ed 100644
--- a/src/cardwidget.h
+++ b/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();
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index f834e18..f227b34 100644
--- a/src/mainwindow.cc
+++ b/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;
}
@@ -426,6 +434,7 @@ void MainWindow::updateCard(const pa_card_info &info) {
desc += _(" (unavailable)");
w->profiles.push_back(std::pair<Glib::ustring, Glib::ustring>(profileIt->name, desc));
+ w->availableProfiles[profileIt->name] = hasOther && profileIt->available;
}
w->activeProfile = info.active_profile ? info.active_profile->name : "";
@@ -1422,3 +1431,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();
+ }
+}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index dcbc2f0..a9fb4a2 100644
--- a/src/mainwindow.h
+++ b/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();
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index 37b07c0..d6046a5 100644
--- a/src/mainwindow.ui
+++ b/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>
More information about the pulseaudio-commits
mailing list