summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorkrukai2020-07-02 21:54:18 +0200
committerLuís Pereira2020-07-03 18:34:38 +0200
commit92d4b808d318ee02cb80e8af20e07be2a9a0a516 (patch)
treedc2e0adcce463193d14f8022123a9e4068a1b80d /src
parentSafely iterate over card profile info array (diff)
downloadpavucontrol-slx-92d4b808d318ee02cb80e8af20e07be2a9a0a516.tar.gz
pavucontrol-slx-92d4b808d318ee02cb80e8af20e07be2a9a0a516.tar.xz
pavucontrol-slx-92d4b808d318ee02cb80e8af20e07be2a9a0a516.zip
Fall back to default icon when no candidate is found
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cc14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index e3e25ca..5cb0743 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -176,8 +176,10 @@ static void updatePorts(DeviceWidget *w, std::map<QByteArray, PortInfo> &ports)
}
}
-static void setIconByName(QLabel* label, const char* name) {
- QIcon icon = QIcon::fromTheme(QString::fromUtf8(name));
+static void setIconByName(QLabel* label, const char* name, const char* fallback_name = nullptr) {
+ QIcon icon = QIcon::fromTheme(QString::fromLatin1(name));
+ if (icon.isNull() || icon.availableSizes().isEmpty())
+ icon = QIcon::fromTheme(QString::fromLatin1(fallback_name));
int size = label->style()->pixelMetric(QStyle::PM_ToolBarIconSize);
QPixmap pix = icon.pixmap(size, size);
label->setPixmap(pix);
@@ -205,7 +207,7 @@ void MainWindow::updateCard(const pa_card_info &info) {
w->nameLabel->setText(QString::fromUtf8(w->name));
icon = pa_proplist_gets(info.proplist, PA_PROP_DEVICE_ICON_NAME);
- setIconByName(w->iconImage, icon ? icon : "audio-card");
+ setIconByName(w->iconImage, icon, "audio-card");
w->hasSinks = w->hasSources = false;
profile_priorities.clear();
@@ -336,7 +338,7 @@ bool MainWindow::updateSink(const pa_sink_info &info) {
g_free(txt);
icon = pa_proplist_gets(info.proplist, PA_PROP_DEVICE_ICON_NAME);
- setIconByName(w->iconImage, icon ? icon : "audio-card");
+ setIconByName(w->iconImage, icon, "audio-card");
w->setVolume(info.volume);
w->muteToggleButton->setChecked(info.mute);
@@ -502,7 +504,7 @@ void MainWindow::updateSource(const pa_source_info &info) {
g_free(txt);
icon = pa_proplist_gets(info.proplist, PA_PROP_DEVICE_ICON_NAME);
- setIconByName(w->iconImage, icon ? icon : "audio-input-microphone");
+ setIconByName(w->iconImage, icon, "audio-input-microphone");
w->setVolume(info.volume);
w->muteToggleButton->setChecked(info.mute);
@@ -573,7 +575,7 @@ void MainWindow::setIconFromProplist(QLabel *icon, pa_proplist *l, const char *d
finish:
- setIconByName(icon, t);
+ setIconByName(icon, t, def);
}