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 |
|
18 #include <HbView> |
|
19 #include <HbEvent> |
|
20 #include <QFontMetrics> |
|
21 |
|
22 #include "datapopup.h" |
|
23 #include "enginewrapper.h" |
|
24 #include "popupdatacontainer.h" |
|
25 |
|
26 DataPopup::DataPopup(EngineWrapper &engine) : |
|
27 mEngine(engine), |
|
28 mPopupCreated(false), |
|
29 mPopupVisible(false) |
|
30 { |
|
31 connect(&mEngine, SIGNAL(samplesUpdated()), this, SLOT(updateSamples())); |
|
32 connect(&mEngine, SIGNAL(settingsUpdated()), this, SLOT(updateSettings())); |
|
33 connect(this, SIGNAL(dataReceived(QVariantMap)), this, SLOT(triggerAction(QVariantMap))); |
|
34 } |
|
35 |
|
36 void DataPopup::show() |
|
37 { |
|
38 mPopupVisible = true; |
|
39 if (!mPopupCreated && |
|
40 mEngine.sampleEntries().length() && |
|
41 mEngine.settings().dataPopupSources().enabledIndexes().length()) |
|
42 { |
|
43 bool anyData = false; |
|
44 foreach (QVariant index, mEngine.settings().dataPopupSources().enabledIndexes()) |
|
45 anyData = anyData || mEngine.sampleEntries().at(index.toInt()).sampleCount(); |
|
46 |
|
47 if (anyData) { |
|
48 mPopupCreated = HbDeviceDialog::show("com.nokia.rnd.perfmondatapopup/1.0", |
|
49 collectParams()); |
|
50 } |
|
51 } |
|
52 } |
|
53 |
|
54 void DataPopup::hide() |
|
55 { |
|
56 mPopupVisible = false; |
|
57 if (mPopupCreated) { |
|
58 mPopupCreated = !cancel(); |
|
59 } |
|
60 } |
|
61 |
|
62 void DataPopup::updateSamples() |
|
63 { |
|
64 updateData(); |
|
65 } |
|
66 |
|
67 void DataPopup::updateSettings() |
|
68 { |
|
69 // mEngine.settings().dataPopupVisibility can only be changed from |
|
70 // main window, so we may assume the window is in foreground |
|
71 updateVisibility(true); |
|
72 updateData(); |
|
73 } |
|
74 |
|
75 void DataPopup::updateVisibility(bool foreground) |
|
76 { |
|
77 if (mEngine.settings().dataPopupVisibility() == EDataPopupVisbilityAlwaysOn || |
|
78 (mEngine.settings().dataPopupVisibility() == EDataPopupVisbilityBackgroundOnly && !foreground)) { |
|
79 |
|
80 show(); |
|
81 } else { |
|
82 hide(); |
|
83 } |
|
84 } |
|
85 |
|
86 void DataPopup::triggerAction(QVariantMap data) |
|
87 { |
|
88 if (data.contains("mouseEvent") && data["mouseEvent"].toString() == "press") { |
|
89 emit clicked(); |
|
90 |
|
91 // data popup was clicked, move it to other position |
|
92 mEngine.settings().setDataPopupLocation( |
|
93 EDataPopupLocationBottomMiddle - mEngine.settings().dataPopupLocation()); |
|
94 mEngine.updateSettings(); |
|
95 } |
|
96 } |
|
97 |
|
98 QVariantMap DataPopup::collectParams() const |
|
99 { |
|
100 QVariantMap result; |
|
101 |
|
102 // add location param |
|
103 result["location"] = mEngine.settings().dataPopupLocation(); |
|
104 |
|
105 // add lines param |
|
106 QStringList lines; |
|
107 QList<SampleEntry> entries = mEngine.sampleEntries(); |
|
108 for (int i=0; i<entries.length(); i++) |
|
109 { |
|
110 if (mEngine.settings().dataPopupSources().isEnabled(i) && |
|
111 entries.at(i).sampleCount() > 0) |
|
112 { |
|
113 const SampleEntry &entry = entries.at(i); |
|
114 const SampleData &sample = entry.sample(0); |
|
115 |
|
116 if (i == ESourceCPU) |
|
117 { |
|
118 // CPU |
|
119 double perc = sample.mSize > 0 ? |
|
120 100. - 100. * sample.mFree / sample.mSize : 0; |
|
121 |
|
122 |
|
123 QString text = tr("%1 %2%").arg(entry.description()). |
|
124 arg(perc, 0, 'f', 0); |
|
125 lines.append(text); |
|
126 } |
|
127 else |
|
128 { |
|
129 // RAM and Drives |
|
130 QString text = tr("%1 free %L2%3").arg(entry.description()). |
|
131 arg(sample.mFree).arg(entry.unitShort()); |
|
132 lines.append(text); |
|
133 } |
|
134 } |
|
135 } |
|
136 result["lines"] = lines; |
|
137 |
|
138 return result; |
|
139 } |
|
140 |
|
141 void DataPopup::updateData() |
|
142 { |
|
143 if (!mPopupVisible) |
|
144 return; |
|
145 |
|
146 if (!mPopupCreated) { |
|
147 show(); |
|
148 } else { |
|
149 HbDeviceDialog::update(collectParams()); |
|
150 } |
|
151 } |
|