From f87d71277f564c2646bdba5a8878a1668628a957 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Fri, 8 Nov 2024 20:10:27 +0500 Subject: [PATCH] UI: Tray: Improve icon for Block Internet --- src/ui/conf/firewallconf.cpp | 16 ++++++++----- src/ui/conf/firewallconf.h | 8 +++++++ src/ui/form/tray/trayicon.cpp | 42 ++++++++++++++++++++++++++--------- src/ui/form/tray/trayicon.h | 3 ++- 4 files changed, 53 insertions(+), 16 deletions(-) diff --git a/src/ui/conf/firewallconf.cpp b/src/ui/conf/firewallconf.cpp index 7f955a0c..f3e3b913 100644 --- a/src/ui/conf/firewallconf.cpp +++ b/src/ui/conf/firewallconf.cpp @@ -14,7 +14,13 @@ FirewallConf::FirewallConf(Settings *settings, QObject *parent) : QObject(parent int FirewallConf::blockTrafficIndex() const { - return m_blockInetTraffic ? 3 : (m_blockLanTraffic ? 2 : (m_blockTraffic ? 1 : 0)); + if (m_blockInetTraffic) + return BlockTrafficInet; + if (m_blockLanTraffic) + return BlockTrafficLan; + if (m_blockTraffic) + return BlockTrafficAll; + return BlockTrafficNone; } void FirewallConf::setBlockTrafficIndex(int index) @@ -24,15 +30,15 @@ void FirewallConf::setBlockTrafficIndex(int index) m_blockInetTraffic = false; switch (index) { - case 0: { // Disabled + case BlockTrafficNone: { // Disabled } break; - case 1: { // Block All Traffic + case BlockTrafficAll: { // Block All Traffic m_blockTraffic = true; } break; - case 2: { // Block LAN & Internet Traffic + case BlockTrafficLan: { // Block LAN & Internet Traffic m_blockLanTraffic = true; } break; - case 3: { // Block Internet Traffic + case BlockTrafficInet: { // Block Internet Traffic m_blockInetTraffic = true; } break; } diff --git a/src/ui/conf/firewallconf.h b/src/ui/conf/firewallconf.h index 68dbad5b..b4141551 100644 --- a/src/ui/conf/firewallconf.h +++ b/src/ui/conf/firewallconf.h @@ -25,6 +25,14 @@ public: Q_ENUM(EditedFlag) Q_DECLARE_FLAGS(EditedFlags, EditedFlag) + enum BlockTrafficType { + BlockTrafficNone = 0, + BlockTrafficAll, + BlockTrafficLan, + BlockTrafficInet, + }; + Q_ENUM(BlockTrafficType) + enum FilterMode { ModeAutoLearn = 0, ModeAskToConnect, diff --git a/src/ui/form/tray/trayicon.cpp b/src/ui/form/tray/trayicon.cpp index eee1c49a..f75ce929 100644 --- a/src/ui/form/tray/trayicon.cpp +++ b/src/ui/form/tray/trayicon.cpp @@ -725,28 +725,50 @@ void TrayIcon::removeAlertTimer() void TrayIcon::updateTrayIconShape() { - const QString mainIconPath = trayIconPath(); + QString overlayIconPath; + const QString mainIconPath = trayIconPath(overlayIconPath); - const auto icon = m_alerted - ? (m_animatedAlert ? IconCache::icon(":/icons/error.png") - : GuiUtil::overlayIcon(mainIconPath, ":/icons/error.png")) - : IconCache::icon(mainIconPath); + QIcon icon; + + if (m_alerted || !overlayIconPath.isEmpty()) { + if (m_alerted) { + overlayIconPath = ":/icons/error.png"; + } + + icon = m_animatedAlert ? IconCache::icon(overlayIconPath) + : GuiUtil::overlayIcon(mainIconPath, overlayIconPath); + } else { + icon = IconCache::icon(mainIconPath); + } this->setIcon(icon); } -QString TrayIcon::trayIconPath() const +QString TrayIcon::trayIconPath(QString &overlayIconPath) const { if (!conf()->filterEnabled() || !driverManager()->isDeviceOpened()) { return ":/icons/fort_gray.png"; } - if (conf()->blockTraffic()) { - return ":/icons/fort_red.png"; + + const auto blockType = conf()->blockTrafficIndex(); + if (blockType != FirewallConf::BlockTrafficNone) { + return trayIconBlockPath(blockType, overlayIconPath); } - if (conf()->blockLanTraffic() || conf()->blockInetTraffic()) { + + return ":/icons/fort.png"; +} + +QString TrayIcon::trayIconBlockPath(int blockType, QString &overlayIconPath) const +{ + switch (blockType) { + case FirewallConf::BlockTrafficAll: + return ":/icons/fort_red.png"; + case FirewallConf::BlockTrafficInet: + overlayIconPath = ":/icons/global_telecom.png"; + Q_FALLTHROUGH(); + default: return ":/icons/fort_orange.png"; } - return ":/icons/fort.png"; } void TrayIcon::saveTrayFlags() diff --git a/src/ui/form/tray/trayicon.h b/src/ui/form/tray/trayicon.h index 8f476873..ded06f04 100644 --- a/src/ui/form/tray/trayicon.h +++ b/src/ui/form/tray/trayicon.h @@ -125,7 +125,8 @@ private: void updateTrayIconShape(); - QString trayIconPath() const; + QString trayIconPath(QString &overlayIconPath) const; + QString trayIconBlockPath(int blockType, QString &overlayIconPath) const; void updateActionHotKeys();