forked from lxqt/lxqt-connman-applet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iconproducer.cpp
150 lines (134 loc) · 5.58 KB
/
iconproducer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* BEGIN_COMMON_COPYRIGHT_HEADER
* (c)LGPL2+
*
* lxqt-connman-applet - a gui frontend for connman
*
* Copyright: 2014-2015 Christian Surlykke
*
* This program or library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* END_COMMON_COPYRIGHT_HEADER */
#include "iconproducer.h"
#include <XdgIcon>
#include <LXQt/Settings>
#include <QtSvg/QSvgRenderer>
#include <QPainter>
#include <QFile>
#include <QDebug>
const IconProducer& IconProducer::instance()
{
static IconProducer inst;
return inst;
}
IconProducer::IconProducer()
{
mBuiltInDisconnected = buildIcon(":/resources/wired-disconnected.svg");
mBuiltInWiredConnected = buildIcon(":/resources/wired-connected.svg");
mBuiltInWirelessNone = buildIcon(":/resources/signal-strength-0.svg");
mBuiltInWirelessWeak = buildIcon(":/resources/signal-strength-1.svg");
mBuiltInWirelessOk = buildIcon(":/resources/signal-strength-2.svg");
mBuiltInWirelessGood = buildIcon(":/resources/signal-strength-3.svg");
mBuiltInWirelessExcellent = buildIcon(":/resources/signal-strength-4.svg");
QPixmap pixmap(30,30);
pixmap.fill(QColor(0,0,0,0));
mBlanc = QIcon(pixmap);
connect(LXQt::GlobalSettings::globalSettings(), SIGNAL(iconThemeChanged()), this, SLOT(onIconThemeChanged()));
onIconThemeChanged();
}
void IconProducer::onIconThemeChanged()
{
// Oxygen and Breeze has these
if (QIcon::hasThemeIcon("network-wired") &&
QIcon::hasThemeIcon("network-connect") &&
QIcon::hasThemeIcon("network-wireless-connected-00") &&
QIcon::hasThemeIcon("network-wireless-connected-25") &&
QIcon::hasThemeIcon("network-wireless-connected-50") &&
QIcon::hasThemeIcon("network-wireless-connected-75") &&
QIcon::hasThemeIcon("network-wireless-connected-100"))
{
iconThemeType = IconThemeType::oxygen;
}
else if (// Gnome and several other themes has these
QIcon::hasThemeIcon("network-offline") &&
QIcon::hasThemeIcon("network-wired") &&
QIcon::hasThemeIcon("network-wireless-signal-none-symbolic") &&
QIcon::hasThemeIcon("network-wireless-signal-weak-symbolic") &&
QIcon::hasThemeIcon("network-wireless-signal-ok-symbolic") &&
QIcon::hasThemeIcon("network-wireless-signal-good-symbolic") &&
QIcon::hasThemeIcon("network-wireless-signal-excellent-symbolic"))
{
iconThemeType = IconThemeType::gnome;
}
else // Fallback to ugly built-in icons
{
iconThemeType = IconThemeType::none;
}
emit iconsChanged();
}
QIcon IconProducer::buildIcon(QString pathToSvgFile)
{
QFile svgFile(pathToSvgFile);
svgFile.open(QIODevice::ReadOnly);
QByteArray svg = svgFile.readAll();
QSvgRenderer render(svg);
QPixmap pixmap(render.defaultSize());
pixmap.fill(QColor(0,0,0,0));
QPainter painter(&pixmap);
render.render(&painter);
return QIcon(pixmap);
}
QIcon IconProducer::disconnected() const
{
switch (iconThemeType) {
case IconThemeType::oxygen: return QIcon::fromTheme("network-wired");
case IconThemeType::gnome: return QIcon::fromTheme("network-offline");
case IconThemeType::none: return mBuiltInDisconnected;
}
}
QIcon IconProducer::wiredConnected() const
{
switch (iconThemeType) {
case IconThemeType::oxygen: return QIcon::fromTheme("network-connect");
case IconThemeType::gnome: return QIcon::fromTheme("network-wired");
case IconThemeType::none: return mBuiltInWiredConnected;
}
}
QIcon IconProducer::wireless(int strength) const
{
switch (iconThemeType) {
case IconThemeType::oxygen:
if (strength < 10) return QIcon::fromTheme("network-wireless-connected-00");
else if (strength < 37) return QIcon::fromTheme("network-wireless-connected-25");
else if (strength < 63) return QIcon::fromTheme("network-wireless-connected-50");
else if (strength < 90) return QIcon::fromTheme("network-wireless-connected-75");
else return QIcon::fromTheme("network-wireless-connected-100");
case IconThemeType::gnome:
if (strength < 10) return QIcon::fromTheme("network-wireless-signal-none-symbolic");
else if (strength < 37) return QIcon::fromTheme("network-wireless-signal-weak-symbolic");
else if (strength < 63) return QIcon::fromTheme("network-wireless-signal-ok-symbolic");
else if (strength < 90) return QIcon::fromTheme("network-wireless-signal-good-symbolic");
else return QIcon::fromTheme("network-wireless-signal-excellent-symbolic");
case IconThemeType::none:
if (strength < 10) return mBuiltInWirelessNone;
else if (strength < 37) return mBuiltInWirelessWeak;
else if (strength < 63) return mBuiltInWirelessOk;
else if (strength < 90) return mBuiltInWirelessGood;
else return mBuiltInWirelessExcellent;
}
}
QIcon IconProducer::blanc() const
{
return mBlanc;
}