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 <arkadiusz.bokowy@gmail.com>
This commit is contained in:
Arkadiusz (Arkq) Bokowy 2015-04-20 23:36:43 +02:00 committed by Jouni Malinen
parent 9a3cb4133d
commit eaa3728a64
2 changed files with 38 additions and 18 deletions

View file

@ -1503,8 +1503,8 @@ void WpaGui::updateTrayIcon(TrayIconType type)
if (!tray_icon || currentIconType == type) if (!tray_icon || currentIconType == type)
return; return;
QIcon icon;
QIcon fallback_icon; QIcon fallback_icon;
QStringList names;
if (QImageReader::supportedImageFormats().contains(QByteArray("svg"))) if (QImageReader::supportedImageFormats().contains(QByteArray("svg")))
fallback_icon = QIcon(":/icons/wpa_gui.svg"); fallback_icon = QIcon(":/icons/wpa_gui.svg");
@ -1513,41 +1513,59 @@ void WpaGui::updateTrayIcon(TrayIconType type)
switch (type) { switch (type) {
case TrayIconOffline: case TrayIconOffline:
icon = QIcon::fromTheme("network-wireless-offline", names << "network-wireless-offline-symbolic"
fallback_icon); << "network-wireless-offline"
<< "network-wireless-signal-none-symbolic"
<< "network-wireless-signal-none";
break; break;
case TrayIconAcquiring: case TrayIconAcquiring:
icon = QIcon::fromTheme("network-wireless-acquiring", names << "network-wireless-acquiring-symbolic"
fallback_icon); << "network-wireless-acquiring";
break; break;
case TrayIconConnected: case TrayIconConnected:
icon = QIcon::fromTheme("network-wireless-connected", names << "network-wireless-connected-symbolic"
fallback_icon); << "network-wireless-connected";
break; break;
case TrayIconSignalNone: case TrayIconSignalNone:
icon = QIcon::fromTheme("network-wireless-signal-none", names << "network-wireless-signal-none-symbolic"
fallback_icon); << "network-wireless-signal-none";
break; break;
case TrayIconSignalWeak: case TrayIconSignalWeak:
icon = QIcon::fromTheme("network-wireless-signal-weak", names << "network-wireless-signal-weak-symbolic"
fallback_icon); << "network-wireless-signal-weak";
break; break;
case TrayIconSignalOk: case TrayIconSignalOk:
icon = QIcon::fromTheme("network-wireless-signal-ok", names << "network-wireless-signal-ok-symbolic"
fallback_icon); << "network-wireless-signal-ok";
break; break;
case TrayIconSignalGood: case TrayIconSignalGood:
icon = QIcon::fromTheme("network-wireless-signal-good", names << "network-wireless-signal-good-symbolic"
fallback_icon); << "network-wireless-signal-good";
break; break;
case TrayIconSignalExcellent: case TrayIconSignalExcellent:
icon = QIcon::fromTheme("network-wireless-signal-excellent", names << "network-wireless-signal-excellent-symbolic"
fallback_icon); << "network-wireless-signal-excellent";
break; break;
} }
currentIconType = type; 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;
} }

View file

@ -85,6 +85,8 @@ public slots:
virtual void showTrayStatus(); virtual void showTrayStatus();
virtual void updateTrayIcon(TrayIconType type); virtual void updateTrayIcon(TrayIconType type);
virtual void updateTrayToolTip(const QString &msg); virtual void updateTrayToolTip(const QString &msg);
virtual QIcon loadThemedIcon(const QStringList &names,
const QIcon &fallback);
virtual void wpsDialog(); virtual void wpsDialog();
virtual void peersDialog(); virtual void peersDialog();
virtual void tabChanged(int index); virtual void tabChanged(int index);