From eaa3728a6490d95c89cb6b055ace233167362417 Mon Sep 17 00:00:00 2001 From: "Arkadiusz (Arkq) Bokowy" Date: Mon, 20 Apr 2015 23:36:43 +0200 Subject: [PATCH] wpa_gui: Themed icon loader Signal strength meter uses non-standard icons (not included in the freedesktop icon specification), which might not be available in all icon sets on the market. What's more, according to the latest Ubuntu practices, in the status-like places one should use symbolic icons. Unfortunately not all icon sets provide them. In order to overcome this inconsistency, we are going to try to load more than one icon from the current theme in the fallback-like fashion. Signed-off-by: Arkadiusz Bokowy --- wpa_supplicant/wpa_gui-qt4/wpagui.cpp | 54 ++++++++++++++++++--------- wpa_supplicant/wpa_gui-qt4/wpagui.h | 2 + 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/wpa_supplicant/wpa_gui-qt4/wpagui.cpp b/wpa_supplicant/wpa_gui-qt4/wpagui.cpp index 408e3876c..d2d76f169 100644 --- a/wpa_supplicant/wpa_gui-qt4/wpagui.cpp +++ b/wpa_supplicant/wpa_gui-qt4/wpagui.cpp @@ -1503,8 +1503,8 @@ void WpaGui::updateTrayIcon(TrayIconType type) if (!tray_icon || currentIconType == type) return; - QIcon icon; QIcon fallback_icon; + QStringList names; if (QImageReader::supportedImageFormats().contains(QByteArray("svg"))) fallback_icon = QIcon(":/icons/wpa_gui.svg"); @@ -1513,41 +1513,59 @@ void WpaGui::updateTrayIcon(TrayIconType type) switch (type) { case TrayIconOffline: - icon = QIcon::fromTheme("network-wireless-offline", - fallback_icon); + names << "network-wireless-offline-symbolic" + << "network-wireless-offline" + << "network-wireless-signal-none-symbolic" + << "network-wireless-signal-none"; break; case TrayIconAcquiring: - icon = QIcon::fromTheme("network-wireless-acquiring", - fallback_icon); + names << "network-wireless-acquiring-symbolic" + << "network-wireless-acquiring"; break; case TrayIconConnected: - icon = QIcon::fromTheme("network-wireless-connected", - fallback_icon); + names << "network-wireless-connected-symbolic" + << "network-wireless-connected"; break; case TrayIconSignalNone: - icon = QIcon::fromTheme("network-wireless-signal-none", - fallback_icon); + names << "network-wireless-signal-none-symbolic" + << "network-wireless-signal-none"; break; case TrayIconSignalWeak: - icon = QIcon::fromTheme("network-wireless-signal-weak", - fallback_icon); + names << "network-wireless-signal-weak-symbolic" + << "network-wireless-signal-weak"; break; case TrayIconSignalOk: - icon = QIcon::fromTheme("network-wireless-signal-ok", - fallback_icon); + names << "network-wireless-signal-ok-symbolic" + << "network-wireless-signal-ok"; break; case TrayIconSignalGood: - icon = QIcon::fromTheme("network-wireless-signal-good", - fallback_icon); + names << "network-wireless-signal-good-symbolic" + << "network-wireless-signal-good"; break; case TrayIconSignalExcellent: - icon = QIcon::fromTheme("network-wireless-signal-excellent", - fallback_icon); + names << "network-wireless-signal-excellent-symbolic" + << "network-wireless-signal-excellent"; break; } currentIconType = type; - tray_icon->setIcon(icon); + tray_icon->setIcon(loadThemedIcon(names, fallback_icon)); +} + + +QIcon WpaGui::loadThemedIcon(const QStringList &names, + const QIcon &fallback) +{ + QIcon icon; + + for (QStringList::ConstIterator it = names.begin(); + it != names.end(); it++) { + icon = QIcon::fromTheme(*it); + if (!icon.isNull()) + return icon; + } + + return fallback; } diff --git a/wpa_supplicant/wpa_gui-qt4/wpagui.h b/wpa_supplicant/wpa_gui-qt4/wpagui.h index c0de67b0d..58c655d71 100644 --- a/wpa_supplicant/wpa_gui-qt4/wpagui.h +++ b/wpa_supplicant/wpa_gui-qt4/wpagui.h @@ -85,6 +85,8 @@ public slots: virtual void showTrayStatus(); virtual void updateTrayIcon(TrayIconType type); virtual void updateTrayToolTip(const QString &msg); + virtual QIcon loadThemedIcon(const QStringList &names, + const QIcon &fallback); virtual void wpsDialog(); virtual void peersDialog(); virtual void tabChanged(int index);