62
|
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: Model for handling indicator data.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <xqsettingsmanager.h>
|
|
19 |
#include <xqsettingskey.h>
|
|
20 |
#include <settingsinternalcrkeys.h>
|
|
21 |
|
|
22 |
|
|
23 |
#include "snsrindicatormodel.h"
|
|
24 |
#include "snsrindicatorinfo.h"
|
|
25 |
|
|
26 |
/*!
|
|
27 |
\class SnsrIndicatorModel
|
|
28 |
\ingroup group_snsrbigclockscreensaverplugin
|
|
29 |
\brief Model for handling indicator data.
|
|
30 |
*/
|
|
31 |
|
|
32 |
// TODO: what is the type string of silent indicator? couldn't
|
|
33 |
// find it in wk22 -> workaround solution: assume that it contains
|
|
34 |
// substring "silent"
|
|
35 |
const char *gSilentIndicatorTypeString = "silent";
|
|
36 |
const char *gOfflineIndicatorTypeString = "offline";
|
|
37 |
|
|
38 |
|
|
39 |
/*!
|
|
40 |
Constructs a new SnsrIndicatorModel
|
|
41 |
\param parent Parent object.
|
|
42 |
*/
|
|
43 |
SnsrIndicatorModel::SnsrIndicatorModel(QObject *parent): QObject(parent),
|
|
44 |
mOfflineStateOn(false)
|
|
45 |
{
|
|
46 |
initializeOfflineModeIndication();
|
|
47 |
}
|
|
48 |
|
|
49 |
/*!
|
|
50 |
Destructs the class.
|
|
51 |
*/
|
|
52 |
SnsrIndicatorModel::~SnsrIndicatorModel()
|
|
53 |
{
|
|
54 |
mNotificationIndicators.clear();
|
|
55 |
mSettingIndicators.clear();
|
|
56 |
mIndicatorsToShow.clear();
|
|
57 |
delete mSettingsManager;
|
|
58 |
delete mOfflineKey;
|
|
59 |
}
|
|
60 |
|
|
61 |
/*!
|
|
62 |
If there are already some active indicators when screensaver is
|
|
63 |
launched, then this method is called.
|
|
64 |
Indicators that are gonna be shown by the screensaver are
|
|
65 |
added to the model.
|
|
66 |
\param activeIndicators Active universal indicators in
|
|
67 |
chronological order according to their arrival time.
|
|
68 |
*/
|
|
69 |
void SnsrIndicatorModel::handleActiveIndicators(
|
|
70 |
const QList<HbIndicatorInterface*> &activeIndicators)
|
|
71 |
{
|
|
72 |
mNotificationIndicators.clear();
|
|
73 |
mSettingIndicators.clear();
|
|
74 |
|
|
75 |
bool addedAny(false);
|
|
76 |
|
|
77 |
for (int i = 0; i < activeIndicators.size(); ++i) {
|
|
78 |
HbIndicatorInterface* activatedIndicator = activeIndicators.at(i);
|
|
79 |
SnsrIndicatorInfo indicatorInfo;
|
|
80 |
if (activatedIndicator
|
|
81 |
&& showIndicatorInScreensaver(*activatedIndicator,indicatorInfo)) {
|
|
82 |
addIndicator(indicatorInfo);
|
|
83 |
addedAny = true;
|
|
84 |
}
|
|
85 |
}
|
|
86 |
|
|
87 |
// Send signal only once if there were any such indicators that
|
|
88 |
// screensaver is supposed to show (=added to the model).
|
|
89 |
if (addedAny) {
|
|
90 |
emitChangeSignal();
|
|
91 |
}
|
|
92 |
|
|
93 |
// TODO: no we need to listen to update signals?
|
|
94 |
// used for changing icon?
|
|
95 |
/* //connect indicator's update signal
|
|
96 |
QObject::connect(activatedIndicator, SIGNAL(dataChanged()),
|
|
97 |
this, SLOT(indicatorUpdated()));*/
|
|
98 |
}
|
|
99 |
|
|
100 |
/*!
|
|
101 |
Called when some universal indicator gets activated.
|
|
102 |
\param activatedIndicator Activated universal indicator
|
|
103 |
*/
|
|
104 |
void SnsrIndicatorModel::handleActivatedIndicator(
|
|
105 |
HbIndicatorInterface *activatedIndicator)
|
|
106 |
{
|
|
107 |
SnsrIndicatorInfo indicatorInfo;
|
|
108 |
if (activatedIndicator
|
|
109 |
&& showIndicatorInScreensaver(*activatedIndicator,indicatorInfo)) {
|
|
110 |
addIndicator(indicatorInfo);
|
|
111 |
emitChangeSignal();
|
|
112 |
}
|
|
113 |
}
|
|
114 |
|
|
115 |
/*!
|
|
116 |
Called when some universal indicator gets deactivated.
|
|
117 |
\param deactivatedIndicator Deactivated universal indicator
|
|
118 |
*/
|
|
119 |
void SnsrIndicatorModel::handleDeactivatedIndicator(
|
|
120 |
HbIndicatorInterface *deactivatedIndicator)
|
|
121 |
{
|
|
122 |
if (deactivatedIndicator) {
|
|
123 |
SnsrIndicatorInfo indicatorInfo(
|
|
124 |
deactivatedIndicator->indicatorType(),
|
|
125 |
deactivatedIndicator->indicatorData(HbIndicatorInterface::MonoDecorationNameRole).toString(),
|
|
126 |
deactivatedIndicator->category());
|
|
127 |
|
|
128 |
if (findAndRemoveIndicator(indicatorInfo)) {
|
|
129 |
emitChangeSignal();
|
|
130 |
}
|
|
131 |
}
|
|
132 |
}
|
|
133 |
|
|
134 |
/*!
|
|
135 |
Sends a signal with a list of all currently active indicators.
|
|
136 |
No signal is sent if there are no active indicators currently.
|
|
137 |
*/
|
|
138 |
void SnsrIndicatorModel::initializeIndicatorWidget()
|
|
139 |
{
|
|
140 |
getCurrentOfflineState(); // update status to be on the safe side
|
|
141 |
|
|
142 |
if ( anyActiveIndicators() ) {
|
|
143 |
emitChangeSignal();
|
|
144 |
}
|
|
145 |
}
|
|
146 |
|
|
147 |
/*!
|
|
148 |
listens airplane repository key. Not sure if the state can even be changed at the moment.
|
|
149 |
TODO: do we really need this?
|
|
150 |
*/
|
|
151 |
void SnsrIndicatorModel::offlineValueChanged( const XQSettingsKey &key, const QVariant &value )
|
|
152 |
{
|
|
153 |
bool previousState(mOfflineStateOn);
|
|
154 |
switch ( key.key() ) {
|
|
155 |
case KSettingsAirplaneMode:
|
|
156 |
if( value.toInt() == 1)
|
|
157 |
{
|
|
158 |
mOfflineStateOn = true;
|
|
159 |
}
|
|
160 |
else
|
|
161 |
{
|
|
162 |
mOfflineStateOn = false;
|
|
163 |
}
|
|
164 |
if (previousState != mOfflineStateOn) {
|
|
165 |
emitChangeSignal();
|
|
166 |
}
|
|
167 |
break;
|
|
168 |
default:
|
|
169 |
break;
|
|
170 |
|
|
171 |
}
|
|
172 |
}
|
|
173 |
|
|
174 |
/*!
|
|
175 |
Add the indicator into this model. Handle here the order in which
|
|
176 |
indicators are shown in screensaver: notification indicators should be
|
|
177 |
shown in the same order as shown in statusbar, that is in reversed
|
|
178 |
chronological order. Silent indicator should always be the right-most.
|
|
179 |
*/
|
|
180 |
void SnsrIndicatorModel::addIndicator(const SnsrIndicatorInfo &indicatorInfo)
|
|
181 |
{
|
|
182 |
// info from pattern library - todo: remove
|
|
183 |
//Indicators are displayed inside of each group in reversed chronological order
|
|
184 |
// according to the arrival time; the indicator that appeared most recently is placed on top of the group.
|
|
185 |
|
|
186 |
//Status bar indicators follow the same order; the most recent notification indicator (4) is on the left
|
|
187 |
// and similarly the most recent settings indicator (5) is on the right.
|
|
188 |
|
|
189 |
// use prepend to keep the list in reversed chronological order
|
|
190 |
if (indicatorInfo.category == HbIndicatorInterface::NotificationCategory) {
|
|
191 |
mNotificationIndicators.prepend(indicatorInfo);
|
|
192 |
}
|
|
193 |
else {
|
|
194 |
mSettingIndicators.append(indicatorInfo);
|
|
195 |
}
|
|
196 |
}
|
|
197 |
|
|
198 |
/*!
|
|
199 |
Remove indicator if it can be found.
|
|
200 |
/retval true if the indicator was removed
|
|
201 |
*/
|
|
202 |
bool SnsrIndicatorModel::findAndRemoveIndicator(const SnsrIndicatorInfo &indicatorInfo)
|
|
203 |
{
|
|
204 |
bool removed(false);
|
|
205 |
int index(-1);
|
|
206 |
QList<SnsrIndicatorInfo> &indicatorList =
|
|
207 |
indicatorInfo.category == HbIndicatorInterface::NotificationCategory
|
|
208 |
? mNotificationIndicators : mSettingIndicators;
|
|
209 |
|
|
210 |
for (int i = 0; i < indicatorList.size(); ++i) {
|
|
211 |
if (indicatorList.at(i).type == indicatorInfo.type) {
|
|
212 |
index = i;
|
|
213 |
break;
|
|
214 |
}
|
|
215 |
}
|
|
216 |
if (index >= 0) {
|
|
217 |
indicatorList.removeAt(index);
|
|
218 |
removed = true;
|
|
219 |
}
|
|
220 |
return removed;
|
|
221 |
}
|
|
222 |
|
|
223 |
/*!
|
|
224 |
Check whether to show the indicator in screensaver or not.
|
|
225 |
Icon path is asked with HbIndicatorInterface::MonoDecorationNameRole
|
|
226 |
which refers to the indicator icons shown also in the statusbar:
|
|
227 |
only 4 Notification indicators has premission to publish data with
|
|
228 |
that role. As those 4 are the ones wanted also by screensaver, no
|
|
229 |
extra checks are needed.
|
|
230 |
From the Setting category one should show only Silent indicator.
|
|
231 |
No indicators are shown from the Progress category.
|
|
232 |
If indicator should be shown by screensaver, indicator info is
|
|
233 |
packaged and returned within the parameter.
|
|
234 |
|
|
235 |
/retval true if the indicator should be shown in screensaver
|
|
236 |
*/
|
|
237 |
bool SnsrIndicatorModel::showIndicatorInScreensaver(
|
|
238 |
const HbIndicatorInterface &indicatorInterface, SnsrIndicatorInfo &indicatorInfo)
|
|
239 |
{
|
|
240 |
bool show(false);
|
|
241 |
// all indicators shown by screensaver must have valid status bar icon path
|
|
242 |
QString iconPath =
|
|
243 |
indicatorInterface.indicatorData(HbIndicatorInterface::MonoDecorationNameRole).toString();
|
|
244 |
QString typeString = indicatorInterface.indicatorType();
|
|
245 |
HbIndicatorInterface::Category category = indicatorInterface.category();
|
|
246 |
|
|
247 |
if (category == HbIndicatorInterface::NotificationCategory
|
|
248 |
&& !iconPath.isEmpty()) {
|
|
249 |
// only 4 indicators of this category has permission to publish status bar
|
|
250 |
// icon path->we should show all of them->no additional checks are neeeded.
|
|
251 |
show = true;
|
|
252 |
}
|
|
253 |
else if (category == HbIndicatorInterface::SettingCategory
|
|
254 |
&& !iconPath.isEmpty()
|
|
255 |
// TODO: what is the type string of silent indicator? couldn't
|
|
256 |
// find it in wk22 -> workaround solution: assume that it contains
|
|
257 |
// substring "silent"
|
|
258 |
// && type == gSilentIndicatorTypeString ) {
|
|
259 |
&& typeString.contains(gSilentIndicatorTypeString, Qt::CaseInsensitive)) {
|
|
260 |
show = true;
|
|
261 |
}
|
|
262 |
else { // e.g. no Progress category indicators are shown
|
|
263 |
show = false;
|
|
264 |
}
|
|
265 |
|
|
266 |
// package indicator data into indicatorInfo parameter
|
|
267 |
indicatorInfo.type = typeString;
|
|
268 |
indicatorInfo.iconPath = iconPath;
|
|
269 |
indicatorInfo.category = category;
|
|
270 |
|
|
271 |
return show;
|
|
272 |
}
|
|
273 |
|
|
274 |
/*!
|
|
275 |
Check whether there is any active indicator currently.
|
|
276 |
/retval true if there is at least one indicator to show
|
|
277 |
*/
|
|
278 |
bool SnsrIndicatorModel::anyActiveIndicators() const
|
|
279 |
{
|
|
280 |
bool any(false);
|
|
281 |
if ( mNotificationIndicators.size() != 0
|
|
282 |
|| mSettingIndicators.size() != 0
|
|
283 |
|| mOfflineStateOn ) {
|
|
284 |
any = true;
|
|
285 |
}
|
|
286 |
return any;
|
|
287 |
}
|
|
288 |
|
|
289 |
/*!
|
|
290 |
Send appropriate signal so that UI widget can update itself.
|
|
291 |
*/
|
|
292 |
void SnsrIndicatorModel::emitChangeSignal()
|
|
293 |
{
|
|
294 |
if (anyActiveIndicators()) {
|
|
295 |
updateIndicatorsToShowList();
|
|
296 |
emit indicatorsUpdated(mIndicatorsToShow);
|
|
297 |
}
|
|
298 |
else {
|
|
299 |
mIndicatorsToShow.clear();
|
|
300 |
emit allIndicatorsDeactivated();
|
|
301 |
}
|
|
302 |
}
|
|
303 |
|
|
304 |
/*!
|
|
305 |
Updates the list that contains all the indicators that
|
|
306 |
should be shown in UI. List should contain active indicators
|
|
307 |
in this order:
|
|
308 |
offline + notification indicators + settings indicators.
|
|
309 |
This is the list that will be sent to the widget.
|
|
310 |
*/
|
|
311 |
void SnsrIndicatorModel::updateIndicatorsToShowList()
|
|
312 |
{
|
|
313 |
mIndicatorsToShow.clear();
|
|
314 |
|
|
315 |
if (mOfflineStateOn) {
|
|
316 |
mIndicatorsToShow.append(mOfflineIndicatorInfo);
|
|
317 |
}
|
|
318 |
mIndicatorsToShow.append(mNotificationIndicators);
|
|
319 |
mIndicatorsToShow.append(mSettingIndicators);
|
|
320 |
}
|
|
321 |
|
|
322 |
/*!
|
|
323 |
* Reads the airplanemode repository value and starts monitoring it.
|
|
324 |
* if the value is 1, offline indicator is shown.
|
|
325 |
*/
|
|
326 |
void SnsrIndicatorModel::initializeOfflineModeIndication()
|
|
327 |
{
|
|
328 |
mOfflineIndicatorInfo = SnsrIndicatorInfo(
|
|
329 |
gOfflineIndicatorTypeString,
|
|
330 |
QLatin1String("qtg_mono_offline"),
|
|
331 |
HbIndicatorInterface::NotificationCategory);
|
|
332 |
|
|
333 |
mSettingsManager = new XQSettingsManager(this);
|
|
334 |
//connect to offlineValueChanged slot so we get information if the value is changed while screensaver is on
|
|
335 |
connect(mSettingsManager, SIGNAL(valueChanged(XQSettingsKey, QVariant)),
|
|
336 |
this, SLOT(offlineValueChanged( const XQSettingsKey, const QVariant)));
|
|
337 |
mOfflineKey = new XQSettingsKey(XQSettingsKey::TargetCentralRepository, KCRUidCommunicationSettings.iUid, KSettingsAirplaneMode);
|
|
338 |
if(mSettingsManager->readItemValue(*mOfflineKey).toInt() == 1)
|
|
339 |
{
|
|
340 |
mOfflineStateOn = true;
|
|
341 |
}
|
|
342 |
mSettingsManager->startMonitoring(*mOfflineKey);
|
|
343 |
}
|
|
344 |
|
|
345 |
/*!
|
|
346 |
Get current offline status.
|
|
347 |
*/
|
|
348 |
void SnsrIndicatorModel::getCurrentOfflineState()
|
|
349 |
{
|
|
350 |
if(mSettingsManager->readItemValue(*mOfflineKey).toInt() == 1) {
|
|
351 |
mOfflineStateOn = true;
|
|
352 |
}
|
|
353 |
else {
|
|
354 |
mOfflineStateOn = false;
|
|
355 |
}
|
|
356 |
}
|
|
357 |
|