UI: Tray: Improve icon for Block Internet

This commit is contained in:
Nodir Temirkhodjaev 2024-11-08 20:10:27 +05:00
parent 05097b2d58
commit f87d71277f
4 changed files with 53 additions and 16 deletions

View File

@ -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;
}

View File

@ -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,

View File

@ -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()

View File

@ -125,7 +125,8 @@ private:
void updateTrayIconShape();
QString trayIconPath() const;
QString trayIconPath(QString &overlayIconPath) const;
QString trayIconBlockPath(int blockType, QString &overlayIconPath) const;
void updateActionHotKeys();