-
Notifications
You must be signed in to change notification settings - Fork 2
/
MWToolsPowersave.cpp
125 lines (109 loc) · 3.31 KB
/
MWToolsPowersave.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
#include "MWToolsPowersave.h"
MWToolsPowersave::MWToolsPowersave(QGraphicsObject *parent):
MWToolsWidget("powersave", true, parent)
{
addIcon("icon-widgets-powersave-battery");
setIcon(0);
percentage = new MLabel(this);
QFont font = percentage->font();
font.setPixelSize(20);
percentage->setColor(QColor(255,255,255));
percentage->setPos(11,10);
pix_bg = QPixmap(14,14);
bg = new MImageWidget(&pix_bg, this);
bg->setGeometry(QRectF(32,25,14,14));
m_gconf_display_percentage = new GConfItem("/desktop/meego/status_area/display_percentage");
connect(m_gconf_display_percentage, SIGNAL(valueChanged()), this, SLOT(onDisplayPercentageChanged()));
m_gconf_autopsm = new GConfItem("/system/osso/dsm/energymanagement/enable_power_saving");
m_gconf_forcepsm = new GConfItem("/system/osso/dsm/energymanagement/force_power_saving");
connect(m_gconf_autopsm, SIGNAL(valueChanged()), this, SLOT(onValueChanged()));
connect(m_gconf_forcepsm, SIGNAL(valueChanged()), this, SLOT(onValueChanged()));
m_battery = new MeeGo::QmBattery(this);
}
void MWToolsPowersave::enterDisplayEvent()
{
onValueChanged();
onDisplayPercentageChanged();
}
void MWToolsPowersave::exitDisplayEvent()
{
}
void MWToolsPowersave::shortAction()
{
if (forcePSM)
{
m_gconf_forcepsm->set(false);
m_gconf_autopsm->set(false);
}
else if (autoPSM)
{
m_gconf_forcepsm->set(true);
m_gconf_autopsm->set(false);
}
else
{
m_gconf_forcepsm->set(false);
m_gconf_autopsm->set(true);
}
}
void MWToolsPowersave::longAction()
{
QDBusInterface("com.nokia.DuiControlPanel",
"/",
"com.nokia.DuiControlPanelIf",
QDBusConnection::sessionBus(),
this).call(QDBus::NoBlock,
"appletPage", "Battery");
}
void MWToolsPowersave::onValueChanged()
{
forcePSM = m_gconf_forcepsm->value().toBool();
autoPSM = m_gconf_autopsm->value().toBool();
if (forcePSM)
{
pix_bg.fill(QColor(60,200,255));
bg->setPixmap(pix_bg);
percentage->setColor(QColor(60,200,255));
}
else if (autoPSM)
{
pix_bg.fill(QColor(80,255,80));
bg->setPixmap(pix_bg);
percentage->setColor(QColor(80,255,80));
}
else
{
pix_bg.fill(QColor(255,255,255));
bg->setPixmap(pix_bg);
percentage->setColor(QColor(255,255,255));
}
}
void MWToolsPowersave::onBatteryChanged(int pct, int )
{
if (pct < 100)
{
if (pct > 9)
percentage->setText(QString("%1").arg(pct));
else
percentage->setText(QString("0%1").arg(pct));
}
else
{
percentage->setText(QString("##"));
}
}
void MWToolsPowersave::onDisplayPercentageChanged()
{
bool isPercentage = m_gconf_display_percentage->value(false).toBool();
bg->setVisible(isPercentage);
percentage->setVisible(!isPercentage);
if (isPercentage)
{
disconnect(m_battery, SIGNAL(batteryRemainingCapacityChanged(int,int)), this, SLOT(onBatteryChanged(int,int)));
}
else
{
connect(m_battery, SIGNAL(batteryRemainingCapacityChanged(int,int)), this, SLOT(onBatteryChanged(int,int)));
onBatteryChanged(m_battery->getRemainingCapacityPct(), 0);
}
}