44
|
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 <xqsettingsmanager.h>
|
|
19 |
#include <xqcentralrepositoryutils.h>
|
|
20 |
#include <xqcentralrepositorysearchcriteria.h>
|
|
21 |
#include <qlist.h>
|
|
22 |
|
|
23 |
#include "ipssosextendedsettingsmanager.h"
|
|
24 |
#include "nmipssettingitems.h"
|
|
25 |
#include "ipssettingkeys.h"
|
|
26 |
#include "nmcommon.h"
|
|
27 |
|
|
28 |
/*!
|
|
29 |
\class NmIpsSosExtendedSettingsManager
|
|
30 |
\brief The class is used for manipulating extended POP3 and IMAP4 account settings stored
|
|
31 |
in the Central Repository.
|
|
32 |
*/
|
|
33 |
|
|
34 |
// ======== MEMBER FUNCTIONS ========
|
|
35 |
|
|
36 |
/*!
|
|
37 |
Constructor
|
|
38 |
Creates the NmIpsSosExtendedSettingsManagerfor loading and saving extended mailbox settings.
|
|
39 |
\param mailboxId Mailbox identifier.
|
|
40 |
*/
|
|
41 |
NmIpsSosExtendedSettingsManager::NmIpsSosExtendedSettingsManager(const NmId &mailboxId)
|
|
42 |
: mMailboxId(mailboxId), mMailboxOffset(-1), mActiveProfileOffset(-1)
|
|
43 |
{
|
|
44 |
mSettingsManager = new XQSettingsManager();
|
|
45 |
|
|
46 |
calculateMailboxOffset();
|
|
47 |
}
|
|
48 |
|
|
49 |
/*!
|
|
50 |
Destructor
|
|
51 |
*/
|
|
52 |
NmIpsSosExtendedSettingsManager::~NmIpsSosExtendedSettingsManager()
|
|
53 |
{
|
|
54 |
delete mSettingsManager;
|
|
55 |
}
|
|
56 |
|
|
57 |
/*!
|
|
58 |
Reads extended mailbox setting.
|
|
59 |
\param settingItem SettingItem enum of the setting to return.
|
|
60 |
\param QVariant SettingValue of the found setting value.
|
|
61 |
\return bool <true> when the setting item was read, otherwise <false>.
|
|
62 |
*/
|
|
63 |
bool NmIpsSosExtendedSettingsManager::readSetting(IpsServices::SettingItem settingItem,
|
|
64 |
QVariant &settingValue) const
|
|
65 |
{
|
|
66 |
bool ret(mMailboxOffset>=0);
|
|
67 |
if(ret) {
|
|
68 |
switch(settingItem) {
|
|
69 |
case IpsServices::DownloadPictures:
|
|
70 |
settingValue = readFromCenRep(IpsServices::EmailKeyPreferenceDownloadPictures);
|
|
71 |
break;
|
|
72 |
case IpsServices::MessageDivider:
|
|
73 |
settingValue = readFromCenRep(IpsServices::EmailKeyPreferenceMessageDivider);
|
|
74 |
break;
|
|
75 |
case IpsServices::ReceptionActiveProfile:
|
|
76 |
settingValue = readFromCenRep(IpsServices::EmailKeyReceptionActiveProfile);
|
|
77 |
break;
|
|
78 |
case IpsServices::ReceptionUserDefinedProfile:
|
|
79 |
settingValue = readFromCenRep(IpsServices::EmailKeyReceptionUserDefinedProfile);
|
|
80 |
break;
|
|
81 |
case IpsServices::ReceptionInboxSyncWindow:
|
|
82 |
settingValue = readFromCenRep(mActiveProfileOffset +
|
|
83 |
IpsServices::EmailKeyReceptionInboxSyncWindow);
|
|
84 |
break;
|
|
85 |
case IpsServices::ReceptionGenericSyncWindowInMessages:
|
|
86 |
settingValue = readFromCenRep(mActiveProfileOffset +
|
|
87 |
IpsServices::EmailKeyReceptionGenericSyncWindowInMessages);
|
|
88 |
break;
|
|
89 |
case IpsServices::ReceptionWeekDays:
|
|
90 |
settingValue = readFromCenRep(mActiveProfileOffset +
|
|
91 |
IpsServices::EmailKeyReceptionWeekDays);
|
|
92 |
break;
|
|
93 |
case IpsServices::ReceptionDayStartTime:
|
|
94 |
settingValue = readFromCenRep(mActiveProfileOffset +
|
|
95 |
IpsServices::EmailKeyReceptionDayStartTime);
|
|
96 |
break;
|
|
97 |
case IpsServices::ReceptionDayEndTime:
|
|
98 |
settingValue = readFromCenRep(mActiveProfileOffset +
|
|
99 |
IpsServices::EmailKeyReceptionDayEndTime);
|
|
100 |
break;
|
|
101 |
case IpsServices::ReceptionRefreshPeriodDayTime:
|
|
102 |
settingValue = readFromCenRep(mActiveProfileOffset +
|
|
103 |
IpsServices::EmailKeyReceptionRefreshPeriodDayTime);
|
|
104 |
break;
|
|
105 |
case IpsServices::ReceptionRefreshPeriodOther:
|
|
106 |
settingValue = readFromCenRep(mActiveProfileOffset +
|
|
107 |
IpsServices::EmailKeyReceptionRefreshPeriodOther);
|
|
108 |
break;
|
|
109 |
case IpsServices::UserNameHidden:
|
|
110 |
settingValue = readFromCenRep(IpsServices::EmailKeyUserNameHidden);
|
|
111 |
break;
|
|
112 |
case IpsServices::EmailNotificationState:
|
|
113 |
settingValue = readFromCenRep(IpsServices::EmailKeyEMNState);
|
|
114 |
break;
|
|
115 |
case IpsServices::FirstEmnReceived:
|
|
116 |
settingValue = readFromCenRep(IpsServices::EmailKeyFirstEmnReceived);
|
|
117 |
break;
|
|
118 |
case IpsServices::EmnReceivedNotSynced:
|
|
119 |
settingValue = readFromCenRep(IpsServices::EmailKeyEmnReceivedNotSynced);
|
|
120 |
break;
|
|
121 |
case IpsServices::AoLastSuccessfulUpdateL:
|
|
122 |
settingValue = readFromCenRep(IpsServices::EmailKeyAoLastSuccessfulUpdateL);
|
|
123 |
break;
|
|
124 |
case IpsServices::AoLastSuccessfulUpdateH:
|
|
125 |
settingValue = readFromCenRep(IpsServices::EmailKeyAoLastSuccessfulUpdateH);
|
|
126 |
break;
|
|
127 |
case IpsServices::AoLastUpdateFailed:
|
|
128 |
settingValue = readFromCenRep(IpsServices::EmailKeyAoLastUpdateFailed);
|
|
129 |
break;
|
|
130 |
case IpsServices::AoUpdateSuccessfulWithCurSettings:
|
|
131 |
settingValue = readFromCenRep(IpsServices::EmailKeyAoUpdateSuccessfulWithCurSettings);
|
|
132 |
break;
|
|
133 |
default:
|
|
134 |
ret = false;
|
|
135 |
break;
|
|
136 |
}
|
|
137 |
}
|
|
138 |
if(!settingValue.isValid()){
|
|
139 |
ret = false;
|
|
140 |
}
|
|
141 |
|
|
142 |
return ret;
|
|
143 |
}
|
|
144 |
|
|
145 |
/*!
|
|
146 |
Writes extended mailbox setting.
|
|
147 |
\param settingItem SettingItem enum of the setting to replace.
|
|
148 |
\param settingValue QVariant of the new setting value.
|
|
149 |
\return bool <true> when the setting item was written, otherwise <false>.
|
|
150 |
*/
|
|
151 |
bool NmIpsSosExtendedSettingsManager::writeSetting(IpsServices::SettingItem settingItem,
|
|
152 |
const QVariant &settingValue)
|
|
153 |
{
|
|
154 |
return writeSettingToCenRep(mActiveProfileOffset, settingItem, settingValue);
|
|
155 |
}
|
|
156 |
|
|
157 |
/*!
|
|
158 |
|
|
159 |
*/
|
|
160 |
bool NmIpsSosExtendedSettingsManager::writeSetting(int profileMode,
|
|
161 |
IpsServices::SettingItem settingItem, const QVariant &settingValue)
|
|
162 |
{
|
|
163 |
quint32 profileOffset = convertToProfileOffset(profileMode);
|
|
164 |
return writeSettingToCenRep(profileOffset, settingItem, settingValue);
|
|
165 |
}
|
|
166 |
|
|
167 |
/*!
|
|
168 |
Deletes all the extended settings of the mailbox.
|
|
169 |
*/
|
|
170 |
void NmIpsSosExtendedSettingsManager::deleteSettings()
|
|
171 |
{
|
|
172 |
if(mMailboxOffset>=0) {
|
|
173 |
|
|
174 |
// Find all the keys that match the criteria 0xXXXXXZZZ, where X=part of mailbox offset
|
|
175 |
// and Z=don't care. This will give us all the keys for the particular mailbox.
|
|
176 |
quint32 partialKey(mMailboxOffset);
|
|
177 |
quint32 bitMask(0xFFFFF000);
|
|
178 |
XQCentralRepositorySearchCriteria criteria(IpsServices::EmailMailboxSettingRepository,
|
|
179 |
partialKey, bitMask);
|
|
180 |
// Find the keys.
|
|
181 |
XQCentralRepositoryUtils utils(*mSettingsManager);
|
|
182 |
QList<XQCentralRepositorySettingsKey> foundKeys = utils.findKeys(criteria);
|
|
183 |
|
|
184 |
// Delete the keys.
|
|
185 |
foreach(XQCentralRepositorySettingsKey key, foundKeys) {
|
|
186 |
utils.deleteKey(key);
|
|
187 |
}
|
|
188 |
}
|
|
189 |
}
|
|
190 |
|
|
191 |
/*!
|
|
192 |
|
|
193 |
*/
|
|
194 |
bool NmIpsSosExtendedSettingsManager::writeSettingToCenRep(qint32 profileOffset,
|
|
195 |
IpsServices::SettingItem settingItem, const QVariant &settingValue)
|
|
196 |
{
|
|
197 |
bool ret(profileOffset >= 0);
|
|
198 |
if(ret) {
|
|
199 |
switch(settingItem) {
|
|
200 |
case IpsServices::DownloadPictures:
|
|
201 |
ret = writeToCenRep(
|
|
202 |
IpsServices::EmailKeyPreferenceDownloadPictures,
|
|
203 |
settingValue);
|
|
204 |
break;
|
|
205 |
case IpsServices::MessageDivider:
|
|
206 |
ret = writeToCenRep(
|
|
207 |
IpsServices::EmailKeyPreferenceMessageDivider,
|
|
208 |
settingValue);
|
|
209 |
break;
|
|
210 |
case IpsServices::ReceptionActiveProfile:
|
|
211 |
ret = writeToCenRep(
|
|
212 |
IpsServices::EmailKeyReceptionActiveProfile,
|
|
213 |
settingValue);
|
|
214 |
calculateActiveProfileOffset();
|
|
215 |
break;
|
|
216 |
case IpsServices::ReceptionUserDefinedProfile:
|
|
217 |
ret = writeToCenRep(
|
|
218 |
IpsServices::EmailKeyReceptionUserDefinedProfile,
|
|
219 |
settingValue);
|
|
220 |
break;
|
|
221 |
case IpsServices::ReceptionInboxSyncWindow:
|
|
222 |
ret = writeToCenRep(
|
|
223 |
profileOffset +
|
|
224 |
IpsServices::EmailKeyReceptionInboxSyncWindow,
|
|
225 |
settingValue);
|
|
226 |
break;
|
|
227 |
case IpsServices::ReceptionGenericSyncWindowInMessages:
|
|
228 |
ret = writeToCenRep(
|
|
229 |
profileOffset +
|
|
230 |
IpsServices::EmailKeyReceptionGenericSyncWindowInMessages,
|
|
231 |
settingValue);
|
|
232 |
break;
|
|
233 |
case IpsServices::ReceptionWeekDays:
|
|
234 |
ret = writeToCenRep(
|
|
235 |
profileOffset +
|
|
236 |
IpsServices::EmailKeyReceptionWeekDays,
|
|
237 |
settingValue);
|
|
238 |
break;
|
|
239 |
case IpsServices::ReceptionDayStartTime:
|
|
240 |
ret = writeToCenRep(
|
|
241 |
profileOffset +
|
|
242 |
IpsServices::EmailKeyReceptionDayStartTime,
|
|
243 |
settingValue);
|
|
244 |
break;
|
|
245 |
case IpsServices::ReceptionDayEndTime:
|
|
246 |
ret = writeToCenRep(
|
|
247 |
profileOffset +
|
|
248 |
IpsServices::EmailKeyReceptionDayEndTime,
|
|
249 |
settingValue);
|
|
250 |
break;
|
|
251 |
case IpsServices::ReceptionRefreshPeriodDayTime:
|
|
252 |
ret = writeToCenRep(
|
|
253 |
profileOffset +
|
|
254 |
IpsServices::EmailKeyReceptionRefreshPeriodDayTime,
|
|
255 |
settingValue);
|
|
256 |
break;
|
|
257 |
case IpsServices::ReceptionRefreshPeriodOther:
|
|
258 |
ret = writeToCenRep(
|
|
259 |
profileOffset +
|
|
260 |
IpsServices::EmailKeyReceptionRefreshPeriodOther,
|
|
261 |
settingValue);
|
|
262 |
break;
|
|
263 |
case IpsServices::UserNameHidden:
|
|
264 |
ret = writeToCenRep(
|
|
265 |
IpsServices::EmailKeyUserNameHidden, settingValue);
|
|
266 |
break;
|
|
267 |
case IpsServices::EmailNotificationState:
|
|
268 |
ret = writeToCenRep(
|
|
269 |
IpsServices::EmailKeyEMNState, settingValue);
|
|
270 |
break;
|
|
271 |
case IpsServices::FirstEmnReceived:
|
|
272 |
ret = writeToCenRep(
|
|
273 |
IpsServices::EmailKeyFirstEmnReceived, settingValue);
|
|
274 |
break;
|
|
275 |
case IpsServices::EmnReceivedNotSynced:
|
|
276 |
ret = writeToCenRep(
|
|
277 |
IpsServices::EmailKeyEmnReceivedNotSynced,
|
|
278 |
settingValue);
|
|
279 |
break;
|
|
280 |
case IpsServices::AoLastSuccessfulUpdateL:
|
|
281 |
ret = writeToCenRep(
|
|
282 |
IpsServices::EmailKeyAoLastSuccessfulUpdateL,
|
|
283 |
settingValue);
|
|
284 |
break;
|
|
285 |
case IpsServices::AoLastSuccessfulUpdateH:
|
|
286 |
ret = writeToCenRep(
|
|
287 |
IpsServices::EmailKeyAoLastSuccessfulUpdateH,
|
|
288 |
settingValue);
|
|
289 |
break;
|
|
290 |
case IpsServices::AoLastUpdateFailed:
|
|
291 |
ret = writeToCenRep(
|
|
292 |
IpsServices::EmailKeyAoLastUpdateFailed,
|
|
293 |
settingValue);
|
|
294 |
break;
|
|
295 |
case IpsServices::AoUpdateSuccessfulWithCurSettings:
|
|
296 |
ret = writeToCenRep(
|
|
297 |
IpsServices::EmailKeyAoUpdateSuccessfulWithCurSettings,
|
|
298 |
settingValue);
|
|
299 |
break;
|
|
300 |
default:
|
|
301 |
ret = false;
|
|
302 |
break;
|
|
303 |
}
|
|
304 |
}
|
|
305 |
return ret;
|
|
306 |
}
|
|
307 |
|
|
308 |
/*!
|
|
309 |
Creates a new key-value pair into cenrep
|
|
310 |
*/
|
|
311 |
bool NmIpsSosExtendedSettingsManager::createKeyValuePair(
|
|
312 |
const IpsServices::SettingItem settingItem,
|
|
313 |
const QVariant &settingValue)
|
|
314 |
{
|
|
315 |
|
|
316 |
XQCentralRepositoryUtils* utils =
|
|
317 |
new XQCentralRepositoryUtils(*mSettingsManager);
|
|
318 |
|
|
319 |
XQCentralRepositorySettingsKey settingKey(
|
|
320 |
IpsServices::EmailMailboxSettingRepository,
|
|
321 |
mMailboxOffset + settingItem);
|
|
322 |
|
|
323 |
bool ret = utils->createKey(settingKey, settingValue);
|
|
324 |
|
|
325 |
|
|
326 |
delete utils;
|
|
327 |
|
|
328 |
return ret;
|
|
329 |
}
|
|
330 |
|
|
331 |
/*!
|
|
332 |
Reads a key value from the Central Repository.
|
|
333 |
\param key Key identifier.
|
|
334 |
\return The settings value for the given key.
|
|
335 |
*/
|
|
336 |
QVariant NmIpsSosExtendedSettingsManager::readFromCenRep(quint32 key) const
|
|
337 |
{
|
|
338 |
XQCentralRepositorySettingsKey settingKey(IpsServices::EmailMailboxSettingRepository,
|
|
339 |
mMailboxOffset + key);
|
|
340 |
return mSettingsManager->readItemValue(settingKey);
|
|
341 |
}
|
|
342 |
|
|
343 |
/*!
|
|
344 |
Writes a key value to the Central Repository.
|
|
345 |
\param key Key identifier.
|
|
346 |
\param value The settings value for the given key.
|
|
347 |
\return Returns <true> if the value was succesfully written, <false> if not.
|
|
348 |
*/
|
|
349 |
bool NmIpsSosExtendedSettingsManager::writeToCenRep(quint32 key, const QVariant &value) const
|
|
350 |
{
|
|
351 |
XQCentralRepositorySettingsKey settingKey(IpsServices::EmailMailboxSettingRepository,
|
|
352 |
mMailboxOffset + key);
|
|
353 |
return mSettingsManager->writeItemValue(settingKey, value);
|
|
354 |
}
|
|
355 |
|
|
356 |
void NmIpsSosExtendedSettingsManager::calculateMailboxOffset()
|
|
357 |
{
|
|
358 |
// Find all the keys that match the criteria 0xZZZZZ000, where Z=don't care.
|
|
359 |
// This will give us all the keys that hold the mailbox ids, e.g. 0x00001000, 0x00002000, etc.
|
|
360 |
quint32 partialKey(0x00000000);
|
|
361 |
quint32 bitMask(0x00000FFF);
|
|
362 |
XQCentralRepositorySearchCriteria criteria(IpsServices::EmailMailboxSettingRepository,
|
|
363 |
partialKey, bitMask);
|
|
364 |
// Set the mailbox id is value criteria for the search.
|
|
365 |
criteria.setValueCriteria((int)mMailboxId.id32());
|
|
366 |
|
|
367 |
// Find the keys.
|
|
368 |
XQCentralRepositoryUtils utils(*mSettingsManager);
|
|
369 |
QList<XQCentralRepositorySettingsKey> foundKeys = utils.findKeys(criteria);
|
|
370 |
|
|
371 |
// We should only get one key as a result.
|
|
372 |
if (foundKeys.count() == 1) {
|
|
373 |
mMailboxOffset = foundKeys[0].key();
|
|
374 |
calculateActiveProfileOffset();
|
|
375 |
}
|
|
376 |
}
|
|
377 |
|
|
378 |
/*!
|
|
379 |
Calculates the active reception schedule profile offset.
|
|
380 |
*/
|
|
381 |
void NmIpsSosExtendedSettingsManager::calculateActiveProfileOffset()
|
|
382 |
{
|
|
383 |
QVariant activeProfile = readFromCenRep(IpsServices::EmailKeyReceptionActiveProfile);
|
|
384 |
mActiveProfileOffset = convertToProfileOffset(activeProfile.toInt());
|
|
385 |
}
|
|
386 |
|
|
387 |
/*!
|
|
388 |
|
|
389 |
*/
|
|
390 |
qint32 NmIpsSosExtendedSettingsManager::convertToProfileOffset(int profile)
|
|
391 |
{
|
|
392 |
quint32 profileOffset(0);
|
|
393 |
// Possible values are defined in ipssettingkeys.h
|
|
394 |
switch(profile) {
|
|
395 |
case 0:
|
|
396 |
profileOffset = IpsServices::EmailProfileOffsetKUTD;
|
|
397 |
break;
|
|
398 |
case 1:
|
|
399 |
profileOffset = IpsServices::EmailProfileOffsetSE;
|
|
400 |
break;
|
|
401 |
case 2:
|
|
402 |
profileOffset = IpsServices::EmailProfileOffsetMF;
|
|
403 |
break;
|
|
404 |
case 3:
|
|
405 |
profileOffset = IpsServices::EmailProfileOffsetUD;
|
|
406 |
break;
|
|
407 |
default:
|
|
408 |
break;
|
|
409 |
}
|
|
410 |
return profileOffset;
|
|
411 |
}
|