56
|
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 |
*/
|
74
|
17 |
#include <nmapiheaders.h>
|
56
|
18 |
|
74
|
19 |
// Helpers
|
|
20 |
HBufC8* StringToS60HBufC8LC(const QString &string)
|
|
21 |
{
|
|
22 |
HBufC8* tmp = XQConversions::qStringToS60Desc8(string);
|
|
23 |
User::LeaveIfNull(tmp);
|
|
24 |
CleanupStack::PushL(tmp);
|
|
25 |
return tmp;
|
|
26 |
}
|
56
|
27 |
|
74
|
28 |
const TPtrC StringToS60TPtrC(const QString &string)
|
|
29 |
{
|
|
30 |
return TPtrC(reinterpret_cast<const TUint16*>(string.utf16()));
|
|
31 |
}
|
|
32 |
|
56
|
33 |
|
|
34 |
namespace EmailClientApi
|
|
35 |
{
|
74
|
36 |
const int KUndefinedOffset = -1;
|
56
|
37 |
|
74
|
38 |
NmApiSettingsManagerPrivate::NmApiSettingsManagerPrivate()
|
|
39 |
: mAccount(NULL),
|
|
40 |
mPop3Settings(NULL),
|
|
41 |
mImap4Settings(NULL),
|
|
42 |
mSmtpSettings(NULL),
|
|
43 |
mQSettingsManager(NULL),
|
|
44 |
mMailboxOffset(KUndefinedOffset),
|
|
45 |
mActiveProfileOffset(KUndefinedOffset),
|
56
|
46 |
mMailboxId(0)
|
|
47 |
{
|
|
48 |
}
|
|
49 |
|
|
50 |
NmApiSettingsManagerPrivate::~NmApiSettingsManagerPrivate()
|
|
51 |
{
|
|
52 |
delete mPop3Settings;
|
|
53 |
delete mImap4Settings;
|
|
54 |
delete mSmtpSettings;
|
|
55 |
delete mQSettingsManager;
|
|
56 |
delete mAccount;
|
|
57 |
}
|
|
58 |
|
|
59 |
/*!
|
74
|
60 |
Loads email account settings.
|
56
|
61 |
\param mailboxId which settings are returned
|
|
62 |
\param data consists of keys and values of settings.
|
|
63 |
\return bool <true> when the setting items were found otherwise <false>.
|
|
64 |
*/
|
|
65 |
bool NmApiSettingsManagerPrivate::load(quint64 mailboxId, NmApiMailboxSettingsData &data)
|
|
66 |
{
|
74
|
67 |
AccountDataCleanUpItem(mAccount, mPop3Settings,
|
|
68 |
mImap4Settings, mSmtpSettings, mQSettingsManager);
|
|
69 |
mMailboxId = mailboxId; // Last 32 bits are used as mailbox id
|
|
70 |
data.setMailboxId(mailboxId);
|
|
71 |
bool retVal = false;
|
|
72 |
TRAPD(err, initAccountL());
|
|
73 |
if (!err) {
|
|
74 |
readSettings(data);
|
|
75 |
retVal = readCenRepSettings(data);
|
|
76 |
}
|
|
77 |
return retVal;
|
56
|
78 |
}
|
|
79 |
|
|
80 |
/*!
|
74
|
81 |
Saves mailbox settings.
|
|
82 |
\param mailboxId which settings are saved
|
56
|
83 |
\param data consists of keys and values of settings.
|
|
84 |
\return bool <true> when the setting items were successfully saved otherwise <false>.
|
|
85 |
*/
|
74
|
86 |
bool NmApiSettingsManagerPrivate::save(quint64 mailboxId, const NmApiMailboxSettingsData &data)
|
56
|
87 |
{
|
74
|
88 |
AccountDataCleanUpItem(mAccount, mPop3Settings,
|
|
89 |
mImap4Settings, mSmtpSettings, mQSettingsManager);
|
|
90 |
mMailboxId = mailboxId; // Last 32 bits are used as mailbox id
|
|
91 |
bool retVal = false;
|
|
92 |
TRAPD(err, initAccountL());
|
|
93 |
if (!err) {
|
|
94 |
TRAP(err, writeSettingL(data));
|
|
95 |
if(!err) {
|
|
96 |
retVal = writeSettingToCenRep(data);
|
|
97 |
}
|
|
98 |
}
|
|
99 |
return (!err && retVal);
|
56
|
100 |
}
|
|
101 |
|
|
102 |
/*!
|
74
|
103 |
Reads the mailbox account specific settings.
|
|
104 |
\param data consists of keys and values of settings.
|
56
|
105 |
*/
|
74
|
106 |
void NmApiSettingsManagerPrivate::readSettings(NmApiMailboxSettingsData &data)
|
56
|
107 |
{
|
|
108 |
if (mMailboxType == NmApiMailboxTypePop) {
|
|
109 |
data.setValue(IncomingLoginName, XQConversions::s60Desc8ToQString(mPop3Settings->LoginName()));
|
|
110 |
data.setValue(IncomingPassword, XQConversions::s60Desc8ToQString(mPop3Settings->Password()));
|
|
111 |
data.setValue(MailboxName, XQConversions::s60DescToQString(mPop3Account.iPopAccountName));
|
|
112 |
data.setValue(IncomingMailServer, XQConversions::s60DescToQString(mPop3Settings->ServerAddress()));
|
|
113 |
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
|
|
114 |
data.setValue(IncomingMailUsesAuthentication, mPop3Settings->POP3Auth());
|
|
115 |
#endif
|
|
116 |
data.setValue(IncomingPort, mPop3Settings->Port());
|
74
|
117 |
data.setValue(IncomingMailSecurityType, security(*mPop3Settings));
|
56
|
118 |
}
|
|
119 |
else if (mMailboxType == NmApiMailboxTypeImap) {
|
|
120 |
data.setValue(IncomingLoginName, XQConversions::s60Desc8ToQString(mImap4Settings->LoginName()));
|
|
121 |
data.setValue(IncomingPassword, XQConversions::s60Desc8ToQString(mImap4Settings->Password()));
|
|
122 |
data.setValue(MailboxName, XQConversions::s60DescToQString(
|
|
123 |
mImap4Account.iImapAccountName));
|
|
124 |
data.setValue(IncomingMailServer, XQConversions::s60DescToQString(
|
|
125 |
mImap4Settings->ServerAddress()));
|
|
126 |
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
|
|
127 |
data.setValue(IncomingMailUsesAuthentication, mImap4Settings->IAMP4Auth());
|
|
128 |
#endif
|
|
129 |
data.setValue(IncomingPort, mImap4Settings->Port());
|
|
130 |
data.setValue(FolderPath, XQConversions::s60Desc8ToQString(mImap4Settings->FolderPath()));
|
74
|
131 |
data.setValue(IncomingMailSecurityType, security(*mImap4Settings));
|
56
|
132 |
}
|
|
133 |
|
|
134 |
data.setValue(MyName, XQConversions::s60DescToQString(mSmtpSettings->EmailAlias()));
|
|
135 |
data.setValue(EmailAlias, XQConversions::s60DescToQString(mSmtpSettings->EmailAlias()));
|
|
136 |
data.setValue(EmailAddress, XQConversions::s60DescToQString(mSmtpSettings->EmailAddress()));
|
|
137 |
data.setValue(ReplyAddress, XQConversions::s60DescToQString(mSmtpSettings->ReplyToAddress()));
|
|
138 |
data.setValue(OutgoingMailServer, XQConversions::s60DescToQString(mSmtpSettings->ServerAddress()));
|
|
139 |
data.setValue(OutgoingPort, mSmtpSettings->Port());
|
|
140 |
data.setValue(OutgoingLoginName, XQConversions::s60Desc8ToQString(mSmtpSettings->LoginName()));
|
|
141 |
data.setValue(OutgoingPassword, XQConversions::s60Desc8ToQString(mSmtpSettings->Password()));
|
|
142 |
data.setValue(UseOutgoingAuthentication, mSmtpSettings->SMTPAuth());
|
|
143 |
data.setValue(OutgoingMailUsesAuthentication, mSmtpSettings->SMTPAuth());
|
|
144 |
data.setValue(OutgoingSecureSockets, mSmtpSettings->SecureSockets());
|
|
145 |
data.setValue(OutgoingSSLWrapper, mSmtpSettings->SSLWrapper());
|
74
|
146 |
data.setValue(OutgoingMailSecurityType, security(*mSmtpSettings));
|
|
147 |
}
|
|
148 |
|
|
149 |
/*!
|
|
150 |
Returns the Central Repository setting. Sets given boolen parameter to <false>
|
|
151 |
if error happens. If no error happens boolean status is not changed.
|
|
152 |
\param cenRepKey Central repository key
|
|
153 |
\param success Boolean which is set to <false> if some other error than
|
|
154 |
XQSettingsManager::NotFoundError occurs.
|
|
155 |
Note! Variable is never set to <true>.
|
|
156 |
\return QVariant The settings value for the given key.
|
|
157 |
*/
|
|
158 |
QVariant NmApiSettingsManagerPrivate::readFromCenRep(quint32 key,
|
|
159 |
bool &success) const
|
|
160 |
{
|
|
161 |
QVariant setting = readFromCenRep(key);
|
|
162 |
|
|
163 |
/*
|
|
164 |
XQSettingsManager::NotFoundError occurs if some setting is not found from the cenrep.
|
|
165 |
This is a valid case since all accounts doesn't neccessarily have all possible settings.
|
|
166 |
All other errors are "real" errors and those are indicated to the API user.
|
|
167 |
*/
|
|
168 |
if (setting.isNull()
|
|
169 |
&& mQSettingsManager->error() != XQSettingsManager::NotFoundError) {
|
|
170 |
success = false;
|
|
171 |
}
|
|
172 |
|
|
173 |
return setting;
|
|
174 |
}
|
|
175 |
|
|
176 |
bool NmApiSettingsManagerPrivate::readCenRepSettings(NmApiMailboxSettingsData &data)
|
|
177 |
{
|
|
178 |
bool retVal = true;
|
|
179 |
|
|
180 |
data.setValue(DownloadPictures,
|
|
181 |
readFromCenRep(IpsServices::EmailKeyPreferenceDownloadPictures, retVal));
|
|
182 |
data.setValue(MessageDivider,
|
|
183 |
readFromCenRep(IpsServices::EmailKeyPreferenceMessageDivider, retVal));
|
|
184 |
|
|
185 |
QVariant activeProfileSetting = readFromCenRep(IpsServices::EmailKeyReceptionActiveProfile, retVal);
|
|
186 |
|
|
187 |
if (!activeProfileSetting.isNull()) {
|
|
188 |
switch (activeProfileSetting.toInt()) {
|
|
189 |
case IpsServices::EmailSyncProfileKeepUpToDate:
|
|
190 |
data.setValue(ReceptionActiveProfile, EmailClientApi::EmailProfileOffsetKUTD);
|
|
191 |
break;
|
|
192 |
case IpsServices::EmailSyncProfileSaveEnergy:
|
|
193 |
data.setValue(ReceptionActiveProfile, EmailClientApi::EmailProfileOffsetSE);
|
|
194 |
break;
|
|
195 |
case IpsServices::EmailSyncProfileManualFetch:
|
|
196 |
data.setValue(ReceptionActiveProfile, EmailClientApi::EmailProfileOffsetMF);
|
|
197 |
break;
|
|
198 |
case IpsServices::EmailSyncProfileUserDefined:
|
|
199 |
data.setValue(ReceptionActiveProfile, EmailClientApi::EmailProfileOffsetUD);
|
|
200 |
break;
|
|
201 |
default:
|
|
202 |
data.setValue(ReceptionActiveProfile, EmailClientApi::EmailProfileOffsetKUTD);
|
|
203 |
break;
|
|
204 |
}
|
|
205 |
}
|
|
206 |
|
|
207 |
data.setValue(ReceptionUserDefinedProfile, readFromCenRep(
|
|
208 |
IpsServices::EmailKeyReceptionUserDefinedProfile, retVal));
|
|
209 |
data.setValue(ReceptionInboxSyncWindow, readFromCenRep(mActiveProfileOffset
|
|
210 |
+ IpsServices::EmailKeyReceptionInboxSyncWindow, retVal));
|
|
211 |
data.setValue(ReceptionGenericSyncWindowInMessages, readFromCenRep(mActiveProfileOffset
|
|
212 |
+ IpsServices::EmailKeyReceptionGenericSyncWindowInMessages, retVal));
|
|
213 |
data.setValue(ReceptionWeekDays, readFromCenRep(mActiveProfileOffset
|
|
214 |
+ IpsServices::EmailKeyReceptionWeekDays, retVal));
|
|
215 |
data.setValue(ReceptionDayStartTime, readFromCenRep(mActiveProfileOffset
|
|
216 |
+ IpsServices::EmailKeyReceptionDayStartTime, retVal));
|
|
217 |
data.setValue(ReceptionDayEndTime, readFromCenRep(mActiveProfileOffset
|
|
218 |
+ IpsServices::EmailKeyReceptionDayEndTime, retVal));
|
|
219 |
data.setValue(ReceptionRefreshPeriodDayTime, readFromCenRep(mActiveProfileOffset
|
|
220 |
+ IpsServices::EmailKeyReceptionRefreshPeriodDayTime, retVal));
|
|
221 |
data.setValue(ReceptionRefreshPeriodOther, readFromCenRep(mActiveProfileOffset
|
|
222 |
+ IpsServices::EmailKeyReceptionRefreshPeriodOther, retVal));
|
|
223 |
data.setValue(UserNameHidden, readFromCenRep(IpsServices::EmailKeyUserNameHidden, retVal));
|
|
224 |
data.setValue(EmailNotificationState, readFromCenRep(IpsServices::EmailKeyEMNState, retVal));
|
|
225 |
data.setValue(FirstEmnReceived, readFromCenRep(IpsServices::EmailKeyFirstEmnReceived, retVal));
|
|
226 |
data.setValue(EmnReceivedNotSynced, readFromCenRep(
|
|
227 |
IpsServices::EmailKeyEmnReceivedNotSynced, retVal));
|
|
228 |
data.setValue(AlwaysOnlineState, alwaysOnlineState(retVal));
|
|
229 |
|
|
230 |
data.setValue(AoLastSuccessfulUpdate, readFromCenRep(
|
|
231 |
IpsServices::EmailKeyAoLastSuccessfulUpdateL, retVal));
|
|
232 |
data.setValue(AoLastUpdateFailed, readFromCenRep(
|
|
233 |
IpsServices::EmailKeyAoLastUpdateFailed, retVal));
|
|
234 |
data.setValue(AoUpdateSuccessfulWithCurSettings, readFromCenRep(
|
|
235 |
IpsServices::EmailKeyAoUpdateSuccessfulWithCurSettings, retVal));
|
|
236 |
return retVal;
|
56
|
237 |
}
|
|
238 |
|
74
|
239 |
void NmApiSettingsManagerPrivate::fillImapSettingDataL(const NmApiMailboxSettingsData &data)
|
56
|
240 |
{
|
74
|
241 |
int key = -1;
|
|
242 |
QVariant settingValue;
|
|
243 |
QList<int> keylist = data.listSettings();
|
|
244 |
|
|
245 |
for (int i = 0; i < keylist.size(); i++) {
|
|
246 |
key = keylist[i];
|
|
247 |
if (data.getValue(key, settingValue) && !settingValue.isNull()) {
|
|
248 |
switch (key) {
|
|
249 |
case IncomingLoginName:
|
|
250 |
mImap4Settings->SetLoginNameL(*StringToS60HBufC8LC(settingValue.toString()));
|
|
251 |
CleanupStack::PopAndDestroy();
|
|
252 |
break;
|
|
253 |
case IncomingPassword:
|
|
254 |
mImap4Settings->SetPasswordL(*StringToS60HBufC8LC(settingValue.toString()));
|
|
255 |
CleanupStack::PopAndDestroy();
|
|
256 |
break;
|
|
257 |
case MailboxName:
|
|
258 |
mImap4Account.iImapAccountName.Copy(StringToS60TPtrC(settingValue.toString()));
|
|
259 |
break;
|
|
260 |
case IncomingMailServer:
|
|
261 |
mImap4Settings->SetServerAddressL(StringToS60TPtrC(settingValue.toString()));
|
|
262 |
break;
|
|
263 |
case IncomingMailUsesAuthentication:
|
|
264 |
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
|
|
265 |
mImap4Settings->SetIAMP4Auth(settingValue.toBool());
|
|
266 |
#endif
|
|
267 |
break;
|
|
268 |
case FolderPath:
|
|
269 |
mImap4Settings->SetFolderPathL(*StringToS60HBufC8LC(settingValue.toString()));
|
|
270 |
CleanupStack::PopAndDestroy();
|
|
271 |
break;
|
|
272 |
case IncomingMailSecurityType:
|
|
273 |
setSecurity(*mImap4Settings, settingValue.toString());
|
|
274 |
break;
|
|
275 |
case IncomingPort:
|
|
276 |
mImap4Settings->SetPort(settingValue.toInt());
|
|
277 |
break;
|
|
278 |
case IncomingSecureSockets:
|
|
279 |
mImap4Settings->SetSecureSockets(settingValue.toBool());
|
|
280 |
break;
|
|
281 |
case IncomingSSLWrapper:
|
|
282 |
mImap4Settings->SetSSLWrapper(settingValue.toBool());
|
|
283 |
break;
|
|
284 |
default:
|
|
285 |
fillSmtpSettingDataL(data, settingValue, key);
|
|
286 |
break;
|
|
287 |
}
|
|
288 |
}
|
|
289 |
}
|
|
290 |
}
|
56
|
291 |
|
74
|
292 |
void NmApiSettingsManagerPrivate::fillPopSettingDataL(const NmApiMailboxSettingsData &data)
|
|
293 |
{
|
|
294 |
int key = -1;
|
|
295 |
QVariant settingValue;
|
|
296 |
QList<int> keylist = data.listSettings();
|
|
297 |
|
|
298 |
for (int i = 0; i < keylist.size(); i++) {
|
|
299 |
key = keylist[i];
|
|
300 |
if (data.getValue(key, settingValue) && !settingValue.isNull()) {
|
|
301 |
switch (key) {
|
|
302 |
case IncomingLoginName:
|
|
303 |
mPop3Settings->SetLoginNameL(*StringToS60HBufC8LC(settingValue.toString()));
|
|
304 |
CleanupStack::PopAndDestroy();
|
|
305 |
break;
|
|
306 |
case IncomingPassword:
|
|
307 |
mPop3Settings->SetPasswordL(*StringToS60HBufC8LC(settingValue.toString()));
|
|
308 |
CleanupStack::PopAndDestroy();
|
|
309 |
break;
|
|
310 |
case MailboxName:
|
|
311 |
mPop3Account.iPopAccountName.Copy(StringToS60TPtrC(settingValue.toString()));
|
|
312 |
break;
|
|
313 |
case IncomingMailServer:
|
|
314 |
mPop3Settings->SetServerAddressL(StringToS60TPtrC(settingValue.toString()));
|
|
315 |
break;
|
|
316 |
case IncomingMailUsesAuthentication:
|
|
317 |
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
|
|
318 |
mPop3Settings->SetPOP3Auth(settingValue.toBool());
|
|
319 |
#endif
|
|
320 |
break;
|
|
321 |
case IncomingMailSecurityType:
|
|
322 |
setSecurity(*mPop3Settings, settingValue.toString());
|
|
323 |
break;
|
|
324 |
case IncomingPort:
|
|
325 |
mPop3Settings->SetPort(settingValue.toInt());
|
|
326 |
break;
|
|
327 |
case IncomingSecureSockets:
|
|
328 |
mPop3Settings->SetSecureSockets(settingValue.toBool());
|
|
329 |
break;
|
|
330 |
case IncomingSSLWrapper:
|
|
331 |
mPop3Settings->SetSSLWrapper(settingValue.toBool());
|
|
332 |
break;
|
|
333 |
default:
|
|
334 |
fillSmtpSettingDataL(data, settingValue, key);
|
|
335 |
break;
|
|
336 |
}
|
|
337 |
}
|
|
338 |
}
|
|
339 |
}
|
56
|
340 |
|
74
|
341 |
void NmApiSettingsManagerPrivate::fillSmtpSettingDataL(const NmApiMailboxSettingsData &data,
|
|
342 |
const QVariant settingValue, const int key)
|
|
343 |
{
|
|
344 |
switch (key) {
|
|
345 |
case EmailAddress:
|
|
346 |
mSmtpSettings->SetEmailAddressL(StringToS60TPtrC(settingValue.toString()));
|
|
347 |
break;
|
|
348 |
case ReplyAddress:
|
|
349 |
mSmtpSettings->SetReplyToAddressL(StringToS60TPtrC(settingValue.toString()));
|
|
350 |
break;
|
|
351 |
case EmailAlias:
|
|
352 |
mSmtpSettings->SetEmailAliasL(StringToS60TPtrC(settingValue.toString()));
|
|
353 |
break;
|
|
354 |
case MyName:
|
|
355 |
// If EmailAlias is not set already
|
|
356 |
if(mSmtpSettings->EmailAlias().Length() == 0) {
|
|
357 |
mSmtpSettings->SetEmailAliasL(StringToS60TPtrC(settingValue.toString()));
|
|
358 |
}
|
|
359 |
break;
|
|
360 |
case OutgoingMailServer:
|
|
361 |
mSmtpSettings->SetServerAddressL(StringToS60TPtrC(settingValue.toString()));
|
|
362 |
break;
|
|
363 |
case OutgoingLoginName:
|
|
364 |
mSmtpSettings->SetLoginNameL(*StringToS60HBufC8LC(settingValue.toString()));
|
|
365 |
CleanupStack::PopAndDestroy();
|
|
366 |
break;
|
|
367 |
case OutgoingPassword:
|
|
368 |
mSmtpSettings->SetPasswordL(*StringToS60HBufC8LC(settingValue.toString()));
|
|
369 |
CleanupStack::PopAndDestroy();
|
|
370 |
break;
|
|
371 |
case UseOutgoingAuthentication:
|
|
372 |
// fall through
|
|
373 |
case OutgoingMailUsesAuthentication:
|
|
374 |
mSmtpSettings->SetSMTPAuth(settingValue.toBool());
|
|
375 |
break;
|
|
376 |
case OutgoingSecureSockets:
|
|
377 |
mSmtpSettings->SetSecureSockets(settingValue.toBool());
|
|
378 |
break;
|
|
379 |
case OutgoingSSLWrapper:
|
|
380 |
mSmtpSettings->SetSSLWrapper(settingValue.toBool());
|
|
381 |
break;
|
|
382 |
case OutgoingMailSecurityType:
|
|
383 |
setSecurity(*mSmtpSettings, settingValue.toString());
|
|
384 |
break;
|
|
385 |
case OutgoingPort:
|
|
386 |
mSmtpSettings->SetPort(settingValue.toInt());
|
|
387 |
break;
|
|
388 |
default:
|
|
389 |
break;
|
|
390 |
}
|
56
|
391 |
}
|
|
392 |
|
|
393 |
/*!
|
|
394 |
Writes POP3/IMAP4 specific settings.
|
|
395 |
\param data consists of keys and values of settings.
|
|
396 |
*/
|
74
|
397 |
void NmApiSettingsManagerPrivate::writeSettingL(const NmApiMailboxSettingsData &data)
|
|
398 |
{
|
|
399 |
if (mMailboxType == NmApiMailboxTypePop) {
|
|
400 |
fillPopSettingDataL(data);
|
|
401 |
mAccount->SavePopSettingsL(mPop3Account, *mPop3Settings);
|
56
|
402 |
}
|
74
|
403 |
else if (mMailboxType == NmApiMailboxTypeImap) {
|
|
404 |
fillImapSettingDataL(data);
|
|
405 |
mAccount->SaveImapSettingsL(mImap4Account, *mImap4Settings);
|
|
406 |
}
|
|
407 |
mAccount->SaveSmtpSettingsL(mSmtpAccount, *mSmtpSettings);
|
56
|
408 |
}
|
|
409 |
|
|
410 |
/*!
|
74
|
411 |
Writes settings to central repository.
|
|
412 |
\param data consists of keys and values of settings.
|
56
|
413 |
*/
|
|
414 |
bool NmApiSettingsManagerPrivate::writeSettingToCenRep(
|
|
415 |
const NmApiMailboxSettingsData &data)
|
|
416 |
{
|
74
|
417 |
int key = -1;
|
56
|
418 |
QVariant settingValue;
|
74
|
419 |
QList<int> keylist = data.listSettings();
|
56
|
420 |
bool ret = false;
|
74
|
421 |
|
|
422 |
if (data.getValue(ReceptionActiveProfile, settingValue) && !settingValue.isNull()) {
|
56
|
423 |
QVariant profileOffset = 0;
|
|
424 |
if(settingValue.toString() == EmailClientApi::EmailProfileOffsetKUTD) {
|
74
|
425 |
profileOffset = 0;
|
56
|
426 |
} else if(settingValue.toString() == EmailClientApi::EmailProfileOffsetSE){
|
|
427 |
profileOffset = 1;
|
|
428 |
} else if (settingValue.toString() == EmailClientApi::EmailProfileOffsetMF){
|
74
|
429 |
profileOffset = 2;
|
56
|
430 |
} else if (settingValue.toString() == EmailClientApi::EmailProfileOffsetUD) {
|
|
431 |
profileOffset = 3;
|
|
432 |
}
|
|
433 |
ret = writeToCenRep(IpsServices::EmailKeyReceptionActiveProfile, profileOffset);
|
|
434 |
if(ret) {
|
74
|
435 |
ret = calculateActiveProfileOffset();
|
56
|
436 |
}
|
|
437 |
}
|
|
438 |
if (ret) {
|
74
|
439 |
bool cenRepSuccess = true;
|
56
|
440 |
for (int i = 0; i < keylist.size(); i++) {
|
|
441 |
key = keylist[i];
|
74
|
442 |
if (data.getValue(key, settingValue) && !settingValue.isNull()) {
|
|
443 |
switch (key) {
|
|
444 |
case DownloadPictures:
|
|
445 |
cenRepSuccess = writeToCenRep(IpsServices::EmailKeyPreferenceDownloadPictures,
|
|
446 |
settingValue);
|
|
447 |
break;
|
|
448 |
case MessageDivider:
|
|
449 |
cenRepSuccess = writeToCenRep(IpsServices::EmailKeyPreferenceMessageDivider,
|
|
450 |
settingValue);
|
|
451 |
break;
|
|
452 |
case ReceptionUserDefinedProfile:
|
|
453 |
cenRepSuccess = writeToCenRep(IpsServices::EmailKeyReceptionUserDefinedProfile,
|
|
454 |
settingValue);
|
|
455 |
break;
|
|
456 |
case ReceptionInboxSyncWindow:
|
|
457 |
cenRepSuccess = writeToCenRep(mActiveProfileOffset
|
|
458 |
+ IpsServices::EmailKeyReceptionInboxSyncWindow, settingValue);
|
|
459 |
break;
|
|
460 |
case ReceptionGenericSyncWindowInMessages:
|
|
461 |
cenRepSuccess = writeToCenRep(mActiveProfileOffset
|
|
462 |
+ IpsServices::EmailKeyReceptionGenericSyncWindowInMessages,
|
|
463 |
settingValue);
|
|
464 |
break;
|
|
465 |
case ReceptionWeekDays:
|
|
466 |
cenRepSuccess = writeToCenRep(mActiveProfileOffset
|
|
467 |
+ IpsServices::EmailKeyReceptionWeekDays, settingValue);
|
|
468 |
break;
|
|
469 |
case ReceptionDayStartTime:
|
|
470 |
cenRepSuccess = writeToCenRep(mActiveProfileOffset
|
|
471 |
+ IpsServices::EmailKeyReceptionDayStartTime, settingValue);
|
|
472 |
break;
|
|
473 |
case ReceptionDayEndTime:
|
|
474 |
cenRepSuccess = writeToCenRep(mActiveProfileOffset
|
|
475 |
+ IpsServices::EmailKeyReceptionDayEndTime, settingValue);
|
|
476 |
break;
|
|
477 |
case ReceptionRefreshPeriodDayTime:
|
|
478 |
cenRepSuccess = writeToCenRep(mActiveProfileOffset
|
|
479 |
+ IpsServices::EmailKeyReceptionRefreshPeriodDayTime, settingValue);
|
|
480 |
break;
|
|
481 |
case ReceptionRefreshPeriodOther:
|
|
482 |
cenRepSuccess = writeToCenRep(mActiveProfileOffset
|
|
483 |
+ IpsServices::EmailKeyReceptionRefreshPeriodOther, settingValue);
|
|
484 |
break;
|
|
485 |
case UserNameHidden:
|
|
486 |
cenRepSuccess = writeToCenRep(IpsServices::EmailKeyUserNameHidden,
|
|
487 |
settingValue);
|
|
488 |
break;
|
|
489 |
case EmailNotificationState:
|
|
490 |
cenRepSuccess = writeToCenRep(IpsServices::EmailKeyEMNState,
|
|
491 |
settingValue);
|
|
492 |
break;
|
|
493 |
case FirstEmnReceived:
|
|
494 |
cenRepSuccess = writeToCenRep(IpsServices::EmailKeyFirstEmnReceived,
|
|
495 |
settingValue);
|
|
496 |
break;
|
|
497 |
case EmnReceivedNotSynced:
|
|
498 |
cenRepSuccess = writeToCenRep(IpsServices::EmailKeyEmnReceivedNotSynced,
|
|
499 |
settingValue);
|
|
500 |
break;
|
|
501 |
case AlwaysOnlineState:
|
|
502 |
cenRepSuccess = setAlwaysOnlineState(settingValue);
|
|
503 |
break;
|
|
504 |
case AoLastSuccessfulUpdate:
|
|
505 |
cenRepSuccess = writeToCenRep(IpsServices::EmailKeyAoLastSuccessfulUpdateL,
|
|
506 |
settingValue);
|
|
507 |
break;
|
|
508 |
case AoLastUpdateFailed:
|
|
509 |
cenRepSuccess = writeToCenRep(IpsServices::EmailKeyAoLastUpdateFailed,
|
|
510 |
settingValue);
|
|
511 |
break;
|
|
512 |
case AoUpdateSuccessfulWithCurSettings:
|
|
513 |
cenRepSuccess = writeToCenRep(
|
|
514 |
IpsServices::EmailKeyAoUpdateSuccessfulWithCurSettings,
|
|
515 |
settingValue);
|
|
516 |
break;
|
|
517 |
case ReceptionActiveProfile:
|
|
518 |
// fall through
|
|
519 |
default:
|
|
520 |
break;
|
56
|
521 |
}
|
74
|
522 |
|
|
523 |
if (!cenRepSuccess) {
|
|
524 |
ret = false; // ret is false if even one of the cenrep operations fails
|
56
|
525 |
}
|
74
|
526 |
}
|
56
|
527 |
}
|
|
528 |
}
|
|
529 |
return ret;
|
|
530 |
}
|
|
531 |
|
|
532 |
/*!
|
|
533 |
Reads a key value from the Central Repository.
|
|
534 |
\param key Key identifier.
|
74
|
535 |
\return QVariant The settings value for the given key.
|
56
|
536 |
*/
|
|
537 |
QVariant NmApiSettingsManagerPrivate::readFromCenRep(quint32 key) const
|
|
538 |
{
|
|
539 |
XQCentralRepositorySettingsKey settingKey(IpsServices::EmailMailboxSettingRepository,
|
|
540 |
mMailboxOffset + key);
|
|
541 |
return mQSettingsManager->readItemValue(settingKey);
|
|
542 |
}
|
|
543 |
|
|
544 |
/*!
|
|
545 |
Writes a key value to the Central Repository.
|
|
546 |
\param key Key identifier.
|
|
547 |
\param value The settings value for the given key.
|
74
|
548 |
\return bool Returns <true> if the value was succesfully written, <false> if not.
|
56
|
549 |
*/
|
|
550 |
bool NmApiSettingsManagerPrivate::writeToCenRep(quint32 key, const QVariant &value) const
|
|
551 |
{
|
|
552 |
XQCentralRepositorySettingsKey settingKey(IpsServices::EmailMailboxSettingRepository,
|
|
553 |
mMailboxOffset + key);
|
|
554 |
return mQSettingsManager->writeItemValue(settingKey, value);
|
|
555 |
}
|
|
556 |
|
74
|
557 |
void NmApiSettingsManagerPrivate::setSecurity(CImBaseEmailSettings &settings,
|
|
558 |
QString securityType)
|
56
|
559 |
{
|
74
|
560 |
settings.SetSecureSockets(securityType == NmApiStartTls ? ETrue : EFalse );
|
|
561 |
settings.SetSSLWrapper(securityType == NmApiSSLTls ? ETrue : EFalse );
|
56
|
562 |
}
|
|
563 |
|
74
|
564 |
QString NmApiSettingsManagerPrivate::security(CImBaseEmailSettings &settings) const
|
56
|
565 |
{
|
74
|
566 |
bool ss(settings.SecureSockets());
|
|
567 |
bool sslWrapper(settings.SSLWrapper());
|
|
568 |
QString securityType(NmApiSecurityOff);
|
56
|
569 |
|
74
|
570 |
if (ss == true && sslWrapper == false) {
|
|
571 |
securityType = NmApiStartTls;
|
56
|
572 |
}
|
74
|
573 |
else if (ss == false && sslWrapper == true) {
|
|
574 |
securityType = NmApiSSLTls;
|
56
|
575 |
}
|
|
576 |
|
|
577 |
return securityType;
|
|
578 |
}
|
|
579 |
|
|
580 |
/*!
|
74
|
581 |
Function for getting online state.
|
|
582 |
\param success Boolean variable for informing if operation fails.
|
|
583 |
Note! If success is already <false> it is not set to <true>.
|
|
584 |
\return QString Online state.
|
56
|
585 |
*/
|
74
|
586 |
QString NmApiSettingsManagerPrivate::alwaysOnlineState(bool &success) const
|
56
|
587 |
{
|
74
|
588 |
QString ret = NmApiOff;
|
|
589 |
int settingValue = -1;
|
|
590 |
bool cenRepSuccess = true;
|
|
591 |
QVariant state = readFromCenRep(IpsServices::EmailKeyReceptionActiveProfile,
|
|
592 |
cenRepSuccess);
|
56
|
593 |
|
74
|
594 |
if (cenRepSuccess) {
|
|
595 |
settingValue = state.toInt();
|
|
596 |
if (settingValue != IpsServices::EmailSyncProfileManualFetch) {
|
56
|
597 |
ret = NmApiAlways;
|
|
598 |
}
|
|
599 |
}
|
74
|
600 |
else { // If cenrep read fails it is informed via parameter
|
|
601 |
success = cenRepSuccess;
|
|
602 |
}
|
|
603 |
|
56
|
604 |
return ret;
|
|
605 |
}
|
|
606 |
|
|
607 |
/*!
|
74
|
608 |
Function for setting online state off. It is not allowed to change it on.
|
|
609 |
\return bool Return <true> if operation was successful otherwise <false>.
|
56
|
610 |
*/
|
74
|
611 |
bool NmApiSettingsManagerPrivate::setAlwaysOnlineState(const QVariant &state)
|
56
|
612 |
{
|
74
|
613 |
bool retVal = true;
|
56
|
614 |
if (state.toString() == NmApiOff) {
|
74
|
615 |
retVal = writeToCenRep(IpsServices::EmailKeyReceptionActiveProfile,
|
56
|
616 |
IpsServices::EmailSyncProfileManualFetch);
|
|
617 |
}
|
74
|
618 |
return retVal;
|
56
|
619 |
}
|
|
620 |
|
74
|
621 |
/*!
|
|
622 |
Function for calculating mailbox offset.
|
|
623 |
\return bool Returns <true> if operation was successfull otherwise returns <false>.
|
|
624 |
*/
|
|
625 |
bool NmApiSettingsManagerPrivate::calculateMailboxOffset()
|
56
|
626 |
{
|
|
627 |
// Find all the keys that match the criteria 0xZZZZZ000, where Z=don't care.
|
|
628 |
// This will give us all the keys that hold the mailbox ids, e.g. 0x00001000, 0x00002000, etc.
|
|
629 |
quint32 partialKey(0x00000000);
|
|
630 |
quint32 bitMask(0x00000FFF);
|
|
631 |
XQCentralRepositorySearchCriteria criteria(IpsServices::EmailMailboxSettingRepository,
|
|
632 |
partialKey, bitMask);
|
|
633 |
// Set the mailbox id is value criteria for the search.
|
74
|
634 |
criteria.setValueCriteria((static_cast<int>(mMailboxId)));
|
56
|
635 |
|
|
636 |
// Find the keys.
|
|
637 |
XQCentralRepositoryUtils utils(*mQSettingsManager);
|
|
638 |
QList<XQCentralRepositorySettingsKey> foundKeys = utils.findKeys(criteria);
|
|
639 |
|
74
|
640 |
bool retVal = true;
|
56
|
641 |
// We should only get one key as a result.
|
|
642 |
if (foundKeys.count() == 1) {
|
|
643 |
mMailboxOffset = foundKeys[0].key();
|
74
|
644 |
retVal = calculateActiveProfileOffset();
|
56
|
645 |
}
|
|
646 |
else {
|
74
|
647 |
mActiveProfileOffset = KUndefinedOffset;
|
|
648 |
mMailboxOffset = KUndefinedOffset;
|
|
649 |
retVal = false;
|
56
|
650 |
}
|
74
|
651 |
return retVal;
|
56
|
652 |
}
|
|
653 |
|
|
654 |
/*!
|
74
|
655 |
Calculates the Active profile offset.
|
|
656 |
\return bool Returns <true> if operation was successfull otherwise <false>.
|
56
|
657 |
*/
|
74
|
658 |
bool NmApiSettingsManagerPrivate::calculateActiveProfileOffset()
|
56
|
659 |
{
|
74
|
660 |
bool retVal = true;
|
|
661 |
QVariant activeProfile = readFromCenRep(
|
|
662 |
IpsServices::EmailKeyReceptionActiveProfile, retVal);
|
|
663 |
if (retVal) {
|
|
664 |
switch (activeProfile.toInt()) {
|
|
665 |
case 0:
|
|
666 |
mActiveProfileOffset = IpsServices::EmailProfileOffsetKUTD;
|
|
667 |
break;
|
|
668 |
case 1:
|
|
669 |
mActiveProfileOffset = IpsServices::EmailProfileOffsetSE;
|
|
670 |
break;
|
|
671 |
case 2:
|
|
672 |
mActiveProfileOffset = IpsServices::EmailProfileOffsetMF;
|
|
673 |
break;
|
|
674 |
case 3:
|
|
675 |
mActiveProfileOffset = IpsServices::EmailProfileOffsetUD;
|
|
676 |
break;
|
|
677 |
default:
|
|
678 |
mActiveProfileOffset = IpsServices::EmailProfileOffsetKUTD;
|
|
679 |
break;
|
56
|
680 |
}
|
74
|
681 |
}
|
|
682 |
return retVal;
|
56
|
683 |
}
|
|
684 |
|
74
|
685 |
/*!
|
|
686 |
Function for checking account type.
|
|
687 |
\return bool Returns <true> If account type was identified. <false> if not.
|
|
688 |
*/
|
|
689 |
bool NmApiSettingsManagerPrivate::checkAccountTypeL()
|
56
|
690 |
{
|
|
691 |
bool identified = false;
|
|
692 |
RArray<TImapAccount> imapAccounts;
|
|
693 |
CleanupClosePushL(imapAccounts);
|
74
|
694 |
|
|
695 |
mAccount->GetImapAccountsL(imapAccounts);
|
|
696 |
for (int i=0; i < imapAccounts.Count(); ++i) {
|
|
697 |
TImapAccount account = imapAccounts[i];
|
|
698 |
if (account.iImapService == mMailboxId) {
|
|
699 |
mImap4Account = account;
|
|
700 |
mMailboxType = NmApiMailboxTypeImap;
|
|
701 |
identified = true;
|
|
702 |
break;
|
56
|
703 |
}
|
|
704 |
}
|
|
705 |
CleanupStack::PopAndDestroy(&imapAccounts);
|
|
706 |
|
|
707 |
if (!identified) {
|
|
708 |
RArray<TPopAccount> popAccounts;
|
|
709 |
CleanupClosePushL(popAccounts);
|
74
|
710 |
mAccount->GetPopAccountsL(popAccounts);
|
|
711 |
for (int i = 0; i < popAccounts.Count(); ++i) {
|
|
712 |
TPopAccount account = popAccounts[i];
|
|
713 |
if (popAccounts[i].iPopService == mMailboxId) {
|
|
714 |
mPop3Account = account;
|
|
715 |
mMailboxType = NmApiMailboxTypePop;
|
|
716 |
identified = true;
|
|
717 |
break;
|
56
|
718 |
}
|
|
719 |
}
|
|
720 |
CleanupStack::PopAndDestroy(&popAccounts);
|
|
721 |
}
|
|
722 |
return identified;
|
|
723 |
}
|
|
724 |
|
74
|
725 |
/*!
|
|
726 |
Function for initializing account information.
|
|
727 |
*/
|
56
|
728 |
void NmApiSettingsManagerPrivate::initAccountL()
|
|
729 |
{
|
74
|
730 |
mAccount = CEmailAccounts::NewL();
|
|
731 |
|
|
732 |
if (!checkAccountTypeL()) {
|
|
733 |
User::Leave(KErrNotSupported); // Account type was not identified
|
|
734 |
}
|
|
735 |
|
|
736 |
if (mMailboxType == NmApiMailboxTypePop) {
|
56
|
737 |
mPop3Settings = new(ELeave) CImPop3Settings();
|
|
738 |
mAccount->LoadPopSettingsL(mPop3Account, *mPop3Settings);
|
74
|
739 |
mAccount->GetSmtpAccountL(mPop3Account.iSmtpService, mSmtpAccount);
|
56
|
740 |
}
|
74
|
741 |
else if (mMailboxType == NmApiMailboxTypeImap) {
|
56
|
742 |
mImap4Settings = new(ELeave) CImImap4Settings();
|
|
743 |
mAccount->LoadImapSettingsL(mImap4Account, *mImap4Settings);
|
74
|
744 |
mAccount->GetSmtpAccountL(mImap4Account.iSmtpService, mSmtpAccount);
|
|
745 |
}
|
|
746 |
else {
|
|
747 |
User::Leave(KErrNotSupported);
|
56
|
748 |
}
|
|
749 |
|
|
750 |
mSmtpSettings = new(ELeave) CImSmtpSettings();
|
|
751 |
mAccount->LoadSmtpSettingsL(mSmtpAccount, *mSmtpSettings);
|
74
|
752 |
|
|
753 |
QT_TRYCATCH_LEAVING(mQSettingsManager = new XQSettingsManager());
|
|
754 |
calculateMailboxOffset();
|
56
|
755 |
}
|
|
756 |
|
|
757 |
} // end namespace
|