47
|
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 |
|
48
|
18 |
#include "nmapiheaders.h"
|
56
|
19 |
#include <nmapisettingsmanager.h>
|
47
|
20 |
|
|
21 |
namespace EmailClientApi
|
|
22 |
{
|
74
|
23 |
NmApiMailboxSettingsPrivate::NmApiMailboxSettingsPrivate(QObject *parent) :
|
|
24 |
QObject(parent),
|
47
|
25 |
mFactory(NULL),
|
|
26 |
mDeleteMailboxOperation(NULL)
|
|
27 |
{
|
|
28 |
NM_FUNCTION;
|
|
29 |
mFactory = NmApiDataPluginFactory::instance();
|
|
30 |
Q_CHECK_PTR(mFactory);
|
|
31 |
}
|
|
32 |
|
|
33 |
NmApiMailboxSettingsPrivate::~NmApiMailboxSettingsPrivate()
|
|
34 |
{
|
|
35 |
NM_FUNCTION;
|
|
36 |
NmApiDataPluginFactory::releaseInstance(mFactory);
|
|
37 |
if(mDeleteMailboxOperation && mDeleteMailboxOperation->isRunning()) {
|
74
|
38 |
mDeleteMailboxOperation->cancelOperation();
|
47
|
39 |
}
|
|
40 |
}
|
|
41 |
|
|
42 |
bool NmApiMailboxSettingsPrivate::listMailboxIds(QList<quint64> &idList)
|
|
43 |
{
|
74
|
44 |
NM_FUNCTION;
|
47
|
45 |
QList<NmId> mailboxIds;
|
|
46 |
bool ret = false;
|
|
47 |
idList.clear();
|
74
|
48 |
|
47
|
49 |
NmDataPluginInterface *instance = mFactory->interfaceInstance();
|
|
50 |
if (instance) {
|
|
51 |
if (instance->listMailboxIds(mailboxIds) == KErrNone) {
|
74
|
52 |
|
47
|
53 |
foreach (NmId boxId, mailboxIds) {
|
|
54 |
idList.append(boxId.id());
|
|
55 |
}
|
74
|
56 |
|
|
57 |
ret = true;
|
47
|
58 |
}
|
74
|
59 |
}
|
|
60 |
|
47
|
61 |
return ret;
|
|
62 |
}
|
|
63 |
|
74
|
64 |
QString NmApiMailboxSettingsPrivate::getMailboxType(quint64 mailboxId)
|
|
65 |
{
|
|
66 |
QString mailboxType;
|
|
67 |
//Return null string if mailbox is not resolved or some error occurs
|
|
68 |
TRAP_IGNORE(mailboxType = resolveMailboxTypeL(mailboxId));
|
|
69 |
NM_ERROR(!mailboxType.isNull(), QString("Can not receive mailbox type")
|
|
70 |
+ QString::number(mailboxId));
|
|
71 |
return mailboxType;
|
|
72 |
}
|
|
73 |
|
|
74 |
QString NmApiMailboxSettingsPrivate::resolveMailboxTypeL(quint64 mailboxId)
|
|
75 |
{
|
|
76 |
QString mailboxType;
|
|
77 |
quint32 serviceId = mailboxId;
|
|
78 |
CEmailAccounts *accounts = CEmailAccounts::NewLC();
|
|
79 |
|
|
80 |
RArray<TImapAccount> imapAccounts;
|
|
81 |
CleanupClosePushL(imapAccounts);
|
|
82 |
accounts->GetImapAccountsL(imapAccounts);
|
|
83 |
for (int i=0; i < imapAccounts.Count(); ++i) {
|
|
84 |
if (imapAccounts[i].iImapService == serviceId) {
|
|
85 |
mailboxType = NmApiMailboxTypeImap;
|
|
86 |
break;
|
|
87 |
}
|
|
88 |
}
|
|
89 |
CleanupStack::PopAndDestroy(&imapAccounts);
|
|
90 |
|
|
91 |
if (mailboxType.isNull()) {
|
|
92 |
RArray<TPopAccount> popAccounts;
|
|
93 |
CleanupClosePushL(popAccounts);
|
|
94 |
accounts->GetPopAccountsL(popAccounts);
|
|
95 |
for (int i = 0; i < popAccounts.Count(); ++i) {
|
|
96 |
if (popAccounts[i].iPopService == serviceId) {
|
|
97 |
mailboxType = NmApiMailboxTypePop;
|
|
98 |
break;
|
|
99 |
}
|
|
100 |
}
|
|
101 |
CleanupStack::PopAndDestroy(&popAccounts);
|
|
102 |
}
|
|
103 |
CleanupStack::PopAndDestroy(accounts);
|
|
104 |
return mailboxType;
|
|
105 |
}
|
|
106 |
|
|
107 |
|
47
|
108 |
bool NmApiMailboxSettingsPrivate::loadSettings(quint64 mailboxId, NmApiMailboxSettingsData &data)
|
|
109 |
{
|
|
110 |
NM_FUNCTION;
|
74
|
111 |
QScopedPointer<NmApiSettingsManager> settingsManager(new NmApiSettingsManager(mailboxId));
|
56
|
112 |
return settingsManager->load(mailboxId, data);
|
47
|
113 |
}
|
|
114 |
|
|
115 |
bool NmApiMailboxSettingsPrivate::saveSettings(const NmApiMailboxSettingsData &data)
|
|
116 |
{
|
|
117 |
NM_FUNCTION;
|
74
|
118 |
QScopedPointer<NmApiSettingsManager> settingsManager(new NmApiSettingsManager(data.mailboxId()));
|
56
|
119 |
return settingsManager->save(data);
|
47
|
120 |
}
|
|
121 |
|
|
122 |
bool NmApiMailboxSettingsPrivate::createMailbox(
|
|
123 |
const QString &mailboxType,
|
|
124 |
NmApiMailboxSettingsData &data)
|
|
125 |
{
|
|
126 |
NM_FUNCTION;
|
48
|
127 |
Q_UNUSED(mailboxType);
|
|
128 |
Q_UNUSED(data);
|
47
|
129 |
bool ret = false;
|
74
|
130 |
|
47
|
131 |
/*QT_TRY {
|
|
132 |
if (mailboxType==NmApiMailboxTypePop || mailboxType==NmApiMailboxTypeImap) {
|
74
|
133 |
QScopedPointer<NmApiPopImapSettingsManager> popImapManager(new NmApiPopImapSettingsManager());
|
47
|
134 |
popImapManager->createMailbox(mailboxType, data);
|
|
135 |
ret = true;
|
|
136 |
}
|
|
137 |
else {
|
|
138 |
ret = false;
|
|
139 |
}
|
|
140 |
//TODO store cenrep stuff here
|
|
141 |
}
|
|
142 |
QT_CATCH(...){
|
|
143 |
ret = false;
|
|
144 |
}*/
|
74
|
145 |
|
47
|
146 |
return ret;
|
|
147 |
}
|
|
148 |
|
|
149 |
bool NmApiMailboxSettingsPrivate::deleteMailbox(quint64 mailboxId)
|
|
150 |
{
|
74
|
151 |
Q_UNUSED(mailboxId);
|
|
152 |
return false;
|
|
153 |
|
47
|
154 |
}
|
|
155 |
|
|
156 |
bool NmApiMailboxSettingsPrivate::populateDefaultSettings(
|
74
|
157 |
const QString &mailboxType, NmApiMailboxSettingsData &data)
|
47
|
158 |
{
|
74
|
159 |
NM_FUNCTION;
|
|
160 |
// Q_UNUSED(mailboxType);
|
|
161 |
// Q_UNUSED(data);
|
|
162 |
QScopedPointer<NmApiPopImapSettingsManager> popImapManager(new NmApiPopImapSettingsManager());
|
|
163 |
return popImapManager->populateDefaults(mailboxType, data);
|
|
164 |
// return true;
|
47
|
165 |
}
|
|
166 |
|
|
167 |
}// namespace
|