|
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 <QVariant> |
|
19 #include <pop3set.h> |
|
20 #include <cemailaccounts.h> |
|
21 #include <xqconversions.h> |
|
22 |
|
23 #include "nmipspop3settingsmanager.h" |
|
24 #include "nmipsextendedsettingsmanager.h" |
|
25 |
|
26 /*! |
|
27 \class NmIpsPop3SettingsManager |
|
28 \brief The class implements NmIpsPop3SettingsManager which is used for manipulating |
|
29 pop3 settings of a pop3 mailbox. |
|
30 */ |
|
31 |
|
32 // ======== MEMBER FUNCTIONS ======== |
|
33 |
|
34 /*! |
|
35 Constructor |
|
36 Creates the CImPop4Settings instance for loading and saving the POP3 settings. |
|
37 Finds and loads the SMTP account and settings linked to the POP3 account. |
|
38 \param mailboxId Mailbox identifier. |
|
39 \param account CEmailAccounts created by the settings manager factory. Takes ownership. |
|
40 \param imapAccount TImapAccount of the mailbox. |
|
41 */ |
|
42 NmIpsPop3SettingsManager::NmIpsPop3SettingsManager(const NmId &mailboxId, |
|
43 CEmailAccounts *account, TPopAccount popAccount) |
|
44 : NmIpsSettingsManagerBase(mailboxId, account), |
|
45 mPop3Account(popAccount) |
|
46 { |
|
47 QT_TRAP_THROWING(mPop3Settings = new(ELeave) CImPop3Settings()); |
|
48 |
|
49 TRAP_IGNORE(mAccount->LoadPopSettingsL(mPop3Account, *mPop3Settings)); |
|
50 TRAP_IGNORE(mAccount->GetSmtpAccountL(mPop3Account.iSmtpService, mSmtpAccount)); |
|
51 TRAP_IGNORE(mAccount->LoadSmtpSettingsL(mSmtpAccount, *mSmtpSettings)); |
|
52 } |
|
53 |
|
54 /*! |
|
55 Destructor |
|
56 */ |
|
57 NmIpsPop3SettingsManager::~NmIpsPop3SettingsManager() |
|
58 { |
|
59 delete mPop3Settings; |
|
60 } |
|
61 |
|
62 /*! |
|
63 Finds and returns settings for the account. |
|
64 \param settingItem SettingItem enum of the setting to return. |
|
65 \param QVariant SettingValue of the found setting value. |
|
66 \return <true> when the setting item was found otherwise <false>. |
|
67 */ |
|
68 bool NmIpsPop3SettingsManager::readSetting(IpsServices::SettingItem settingItem, QVariant &value) |
|
69 { |
|
70 bool found(true); |
|
71 switch (settingItem) { |
|
72 case IpsServices::LoginName: |
|
73 value = XQConversions::s60Desc8ToQString(mPop3Settings->LoginName()); |
|
74 break; |
|
75 case IpsServices::Password: |
|
76 value = XQConversions::s60Desc8ToQString(mPop3Settings->Password()); |
|
77 break; |
|
78 case IpsServices::MailboxName: |
|
79 value = XQConversions::s60DescToQString(mPop3Account.iPopAccountName); |
|
80 break; |
|
81 default: |
|
82 found = NmIpsSettingsManagerBase::readSetting(settingItem, value); |
|
83 break; |
|
84 } |
|
85 return found; |
|
86 } |
|
87 |
|
88 /*! |
|
89 Writes POP3 specific settings or passes SMTP and extended settings to the base class. |
|
90 \param settingItem SettingItem enum of the setting to replace. |
|
91 \param settingValue QVariant of the new setting value. |
|
92 */ |
|
93 bool NmIpsPop3SettingsManager::writeSetting(IpsServices::SettingItem settingItem, const QVariant &settingValue) |
|
94 { |
|
95 HBufC *tmp = 0; |
|
96 HBufC8 *tmp8 = 0; |
|
97 |
|
98 bool ret(false); |
|
99 TInt err(KErrNone); |
|
100 |
|
101 switch (settingItem) { |
|
102 case IpsServices::LoginName: |
|
103 tmp8 = XQConversions::qStringToS60Desc8(settingValue.toString()); |
|
104 TRAP(err, mPop3Settings->SetLoginNameL(*tmp8)); |
|
105 delete tmp8; |
|
106 if (err==KErrNone) { |
|
107 ret = saveSettings(); |
|
108 } |
|
109 break; |
|
110 case IpsServices::Password: |
|
111 tmp8 = XQConversions::qStringToS60Desc8(settingValue.toString()); |
|
112 TRAP(err, mPop3Settings->SetPasswordL(*tmp8)); |
|
113 delete tmp8; |
|
114 if (err==KErrNone) { |
|
115 ret = saveSettings(); |
|
116 } |
|
117 break; |
|
118 case IpsServices::MailboxName: |
|
119 tmp = XQConversions::qStringToS60Desc(settingValue.toString()); |
|
120 TRAP(err, mPop3Account.iPopAccountName.Copy(*tmp)); |
|
121 delete tmp; |
|
122 if (err==KErrNone) { |
|
123 ret = saveSettings(); |
|
124 } |
|
125 break; |
|
126 default: |
|
127 ret = NmIpsSettingsManagerBase::writeSetting(settingItem, settingValue); |
|
128 break; |
|
129 } |
|
130 return ret; |
|
131 } |
|
132 |
|
133 /*! |
|
134 Deletes the POP3 mailbox. |
|
135 |
|
136 \return Error code <code>0</code> if mailbox deletion was successful, otherwise error |
|
137 code is returned. |
|
138 */ |
|
139 int NmIpsPop3SettingsManager::deleteMailbox() |
|
140 { |
|
141 int error(NmIpsSettingsManagerBase::deleteMailbox()); |
|
142 if (!error) { |
|
143 TRAP(error, mAccount->DeletePopAccountL(mPop3Account)); |
|
144 } |
|
145 |
|
146 NMLOG(QString("NmIpsPop3SettingsManager::deleteMailbox status %1").arg(error)); |
|
147 return error; |
|
148 } |
|
149 |
|
150 /*! |
|
151 Stores the POP3 specific settings. |
|
152 \return bool <true> when the POP3 settings were succesfully written, otherwise <false>. |
|
153 */ |
|
154 bool NmIpsPop3SettingsManager::saveSettings() |
|
155 { |
|
156 TRAPD(err, mAccount->SavePopSettingsL(mPop3Account, *mPop3Settings)); |
|
157 NMLOG(QString("NmIpsPop3SettingsManager::saveSettings rval %1").arg(err)); |
|
158 return (err==KErrNone); |
|
159 } |