51
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
53
|
18 |
#include <HbMainWindow>
|
51
|
19 |
#include <HbView>
|
|
20 |
#include <HbEvent>
|
|
21 |
#include <QFontMetrics>
|
|
22 |
|
|
23 |
#include "datapopup.h"
|
|
24 |
#include "enginewrapper.h"
|
|
25 |
#include "popupdatacontainer.h"
|
|
26 |
|
53
|
27 |
DataPopup::DataPopup(EngineWrapper &engine, HbMainWindow &mainWindow) :
|
51
|
28 |
mEngine(engine),
|
53
|
29 |
mMainWindow(mainWindow),
|
51
|
30 |
mPopupCreated(false),
|
|
31 |
mPopupVisible(false)
|
|
32 |
{
|
|
33 |
connect(&mEngine, SIGNAL(samplesUpdated()), this, SLOT(updateSamples()));
|
|
34 |
connect(&mEngine, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
|
|
35 |
connect(this, SIGNAL(dataReceived(QVariantMap)), this, SLOT(triggerAction(QVariantMap)));
|
53
|
36 |
connect(&mainWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(orientationChanged(Qt::Orientation)));
|
|
37 |
connect(&mainWindow, SIGNAL(obscured()), this, SLOT(inBackground()));
|
|
38 |
connect(&mainWindow, SIGNAL(revealed()), this, SLOT(inForeground()));
|
51
|
39 |
}
|
|
40 |
|
|
41 |
void DataPopup::show()
|
|
42 |
{
|
|
43 |
mPopupVisible = true;
|
|
44 |
if (!mPopupCreated &&
|
|
45 |
mEngine.sampleEntries().length() &&
|
|
46 |
mEngine.settings().dataPopupSources().enabledIndexes().length())
|
|
47 |
{
|
|
48 |
bool anyData = false;
|
|
49 |
foreach (QVariant index, mEngine.settings().dataPopupSources().enabledIndexes())
|
|
50 |
anyData = anyData || mEngine.sampleEntries().at(index.toInt()).sampleCount();
|
|
51 |
|
|
52 |
if (anyData) {
|
|
53 |
mPopupCreated = HbDeviceDialog::show("com.nokia.rnd.perfmondatapopup/1.0",
|
|
54 |
collectParams());
|
|
55 |
}
|
|
56 |
}
|
|
57 |
}
|
|
58 |
|
|
59 |
void DataPopup::hide()
|
|
60 |
{
|
|
61 |
mPopupVisible = false;
|
|
62 |
if (mPopupCreated) {
|
|
63 |
mPopupCreated = !cancel();
|
|
64 |
}
|
|
65 |
}
|
|
66 |
|
|
67 |
void DataPopup::updateSamples()
|
|
68 |
{
|
|
69 |
updateData();
|
|
70 |
}
|
|
71 |
|
|
72 |
void DataPopup::updateSettings()
|
|
73 |
{
|
53
|
74 |
updateVisibility(!mMainWindow.isObscured());
|
51
|
75 |
updateData();
|
|
76 |
}
|
|
77 |
|
|
78 |
void DataPopup::updateVisibility(bool foreground)
|
|
79 |
{
|
|
80 |
if (mEngine.settings().dataPopupVisibility() == EDataPopupVisbilityAlwaysOn ||
|
|
81 |
(mEngine.settings().dataPopupVisibility() == EDataPopupVisbilityBackgroundOnly && !foreground)) {
|
|
82 |
show();
|
|
83 |
} else {
|
|
84 |
hide();
|
|
85 |
}
|
|
86 |
}
|
|
87 |
|
|
88 |
void DataPopup::triggerAction(QVariantMap data)
|
|
89 |
{
|
|
90 |
if (data.contains("mouseEvent") && data["mouseEvent"].toString() == "press") {
|
|
91 |
// data popup was clicked, move it to other position
|
53
|
92 |
hide();
|
|
93 |
|
51
|
94 |
mEngine.settings().setDataPopupLocation(
|
|
95 |
EDataPopupLocationBottomMiddle - mEngine.settings().dataPopupLocation());
|
|
96 |
mEngine.updateSettings();
|
53
|
97 |
|
|
98 |
show();
|
51
|
99 |
}
|
|
100 |
}
|
|
101 |
|
|
102 |
QVariantMap DataPopup::collectParams() const
|
|
103 |
{
|
|
104 |
QVariantMap result;
|
|
105 |
|
|
106 |
// add location param
|
|
107 |
result["location"] = mEngine.settings().dataPopupLocation();
|
|
108 |
|
|
109 |
// add lines param
|
|
110 |
QStringList lines;
|
|
111 |
QList<SampleEntry> entries = mEngine.sampleEntries();
|
|
112 |
int posCounter(ESourceCPU);
|
|
113 |
|
|
114 |
if (mEngine.settings().dataPopupSources().isEnabled(posCounter))
|
|
115 |
{
|
|
116 |
// loop all CPUs
|
|
117 |
for (TInt i = mEngine.CPU0PositionInSamples(); i < mEngine.CPU0PositionInSamples() + mEngine.AmountOfCPUs(); i++)
|
|
118 |
{
|
|
119 |
// check samples available
|
|
120 |
if (entries.at(i).sampleCount() > 0)
|
|
121 |
{
|
|
122 |
const SampleEntry &entry = entries.at(i);
|
|
123 |
const SampleData &sample = entry.sample(0);
|
|
124 |
|
|
125 |
double perc = sample.mSize > 0 ?
|
|
126 |
100. - 100. * sample.mFree / sample.mSize : 0;
|
|
127 |
|
|
128 |
QString text = tr("%1 %2%").arg(entry.description()).
|
|
129 |
arg(perc, 0, 'f', 0);
|
|
130 |
lines.append(text);
|
|
131 |
}
|
|
132 |
}
|
|
133 |
}
|
|
134 |
|
|
135 |
posCounter++;
|
|
136 |
|
|
137 |
// draw RAM and Drive values
|
|
138 |
for (TInt i = mEngine.RAMPositionInSamples(); i < mEngine.PowerPositionInSamples(); i++)
|
|
139 |
{
|
|
140 |
// check if this setting has been enabled and it has some data
|
|
141 |
if (mEngine.settings().dataPopupSources().isEnabled(posCounter) && entries.at(i).sampleCount() > 0)
|
|
142 |
{
|
|
143 |
const SampleEntry &entry = entries.at(i);
|
|
144 |
const SampleData &sample = entry.sample(0);
|
|
145 |
|
|
146 |
QString text = tr("%1 free %L2%3").arg(entry.description()).
|
|
147 |
arg(sample.mFree).arg(entry.unitShort());
|
|
148 |
lines.append(text);
|
|
149 |
}
|
|
150 |
|
|
151 |
posCounter++;
|
|
152 |
}
|
|
153 |
|
|
154 |
// draw power value
|
|
155 |
// check if this setting has been enabled and it has some data
|
|
156 |
if (mEngine.settings().dataPopupSources().isEnabled(posCounter) && entries.at(mEngine.PowerPositionInSamples()).sampleCount() > 0)
|
|
157 |
{
|
|
158 |
const SampleEntry &entry = entries.at(mEngine.PowerPositionInSamples());
|
|
159 |
const SampleData &sample = entry.sample(0);
|
|
160 |
|
|
161 |
QString text = tr("%1 %L2%3").arg(entry.description()).
|
|
162 |
arg(sample.mSize - sample.mFree).arg(entry.unitShort());
|
|
163 |
lines.append(text);
|
|
164 |
}
|
|
165 |
|
|
166 |
result["lines"] = lines;
|
|
167 |
|
|
168 |
return result;
|
|
169 |
}
|
|
170 |
|
|
171 |
void DataPopup::updateData()
|
|
172 |
{
|
|
173 |
if (!mPopupVisible)
|
|
174 |
return;
|
|
175 |
|
|
176 |
if (!mPopupCreated) {
|
|
177 |
show();
|
|
178 |
} else {
|
|
179 |
HbDeviceDialog::update(collectParams());
|
|
180 |
}
|
|
181 |
}
|
53
|
182 |
|
|
183 |
void DataPopup::orientationChanged(Qt::Orientation /*newOrientation*/)
|
|
184 |
{
|
|
185 |
// force the reposition of the window
|
|
186 |
if( mEngine.settings().dataPopupVisibility() == EDataPopupVisbilityAlwaysOn ||
|
|
187 |
(mEngine.settings().dataPopupVisibility() == EDataPopupVisbilityBackgroundOnly && mMainWindow.isObscured()) ) {
|
|
188 |
hide();
|
|
189 |
show();
|
|
190 |
}
|
|
191 |
}
|
|
192 |
|
|
193 |
void DataPopup::inForeground()
|
|
194 |
{
|
|
195 |
updateVisibility(true);
|
|
196 |
}
|
|
197 |
|
|
198 |
void DataPopup::inBackground()
|
|
199 |
{
|
|
200 |
updateVisibility(false);
|
|
201 |
}
|