|
1 /* |
|
2 * Copyright (c) 2007 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: This file implements classes Account, Account. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include <e32base.h> |
|
21 #include <SendUiConsts.h> |
|
22 |
|
23 #include "ipssetutils.h" |
|
24 #include "ipssetdatactrlaccount.h" |
|
25 #include "ipssetdatastorer.h" |
|
26 #include "ipssetutilsexception.h" |
|
27 |
|
28 enum TIpsSetUiAccountErrors |
|
29 { |
|
30 EIpsSetUiNoError = 0, |
|
31 EIpsSetUiMboxToAccIdMtmError, |
|
32 EIpsSetUiAccIdToExtIdMtmError, |
|
33 EIpsSetUiExtIdToAccIdMtmError |
|
34 }; |
|
35 |
|
36 // Account Id conversion to Extension Id |
|
37 enum TIpsSetUiKeyShifts |
|
38 { |
|
39 EIpsSetUiKeyShiftImap4 = 0, |
|
40 EIpsSetUiKeyShiftPop3 = 8 |
|
41 }; |
|
42 |
|
43 const TInt KIpsSetDataShiftAccountId = 8; |
|
44 |
|
45 // ============================ MEMBER FUNCTIONS =============================== |
|
46 |
|
47 // ---------------------------------------------------------------------------- |
|
48 // IpsSetDataCtrlAccount::CreateBaseKeyFromAccountId() |
|
49 // ---------------------------------------------------------------------------- |
|
50 // |
|
51 TUint32 IpsSetDataCtrlAccount::CreateBaseKeyFromAccountId( |
|
52 const TUint32 aAccountId, |
|
53 const TUid& aProtocol ) |
|
54 { |
|
55 FUNC_LOG; |
|
56 TUint32 extendedAccountId = |
|
57 AccountIdToExtendedAccountId( aAccountId, aProtocol ); |
|
58 return ( extendedAccountId << KIpsSetDataShiftAccountId ); |
|
59 } |
|
60 |
|
61 // ---------------------------------------------------------------------------- |
|
62 // IpsSetDataCtrlAccount::CreateBaseKeyFromExtendedAccountId() |
|
63 // ---------------------------------------------------------------------------- |
|
64 // |
|
65 TUint32 IpsSetDataCtrlAccount::CreateBaseKeyFromExtendedAccountId( |
|
66 const TUint32 aExtendedAccountId ) |
|
67 { |
|
68 FUNC_LOG; |
|
69 return ( aExtendedAccountId << KIpsSetDataShiftAccountId ); |
|
70 } |
|
71 |
|
72 // ---------------------------------------------------------------------------- |
|
73 // IpsSetDataCtrlAccount::MailboxIdToAccountIdL() |
|
74 // ---------------------------------------------------------------------------- |
|
75 // |
|
76 TUint32 IpsSetDataCtrlAccount::MailboxIdToAccountIdL( |
|
77 const TMsvId aMailboxId, |
|
78 const TUid& aMtmId ) |
|
79 { |
|
80 FUNC_LOG; |
|
81 TUint32 accountId = 0; |
|
82 |
|
83 switch ( aMtmId.iUid ) |
|
84 { |
|
85 case KSenduiMtmSmtpUidValue: |
|
86 accountId = IpsSetUtils::GetSmtpAccountIdL( |
|
87 aMailboxId ).iSmtpAccountId; |
|
88 break; |
|
89 |
|
90 case KSenduiMtmPop3UidValue: |
|
91 accountId = IpsSetUtils::GetPopAccountIdL( |
|
92 aMailboxId ).iPopAccountId; |
|
93 break; |
|
94 |
|
95 case KSenduiMtmImap4UidValue: |
|
96 accountId = IpsSetUtils::GetImapAccountIdL( |
|
97 aMailboxId ).iImapAccountId; |
|
98 break; |
|
99 |
|
100 default: |
|
101 { |
|
102 IPSASSERT_LEAVE_OR_PANIC_L( EAccountCtrl, EInvalidAccount ); |
|
103 } |
|
104 break; |
|
105 } |
|
106 |
|
107 return accountId; |
|
108 } |
|
109 |
|
110 // ---------------------------------------------------------------------------- |
|
111 // IpsSetDataCtrlAccount::AccountIdToMailboxId() |
|
112 // ---------------------------------------------------------------------------- |
|
113 // |
|
114 TMsvId IpsSetDataCtrlAccount::AccountIdToMailboxId( |
|
115 CEmailAccounts& aAccounts, |
|
116 const TUint32 aAccountId, |
|
117 const TUid& aMtmId ) |
|
118 { |
|
119 FUNC_LOG; |
|
120 TMsvId mailboxId = KErrNotFound; |
|
121 |
|
122 // Get the correct accounts according to the protocol |
|
123 if ( aMtmId.iUid == KSenduiMtmImap4UidValue ) |
|
124 { |
|
125 // IMAP4 |
|
126 TImapAccount imapAccount; |
|
127 RArray<TImapAccount> accountArray; |
|
128 TRAPD( error, aAccounts.GetImapAccountsL( accountArray ) ); |
|
129 |
|
130 TInt account = ( error == KErrNone ) ? |
|
131 accountArray.Count() : KErrNotFound; |
|
132 |
|
133 while ( mailboxId < 0 && --account >= 0 ) |
|
134 { |
|
135 imapAccount = accountArray[account]; |
|
136 |
|
137 // Check if the id's match |
|
138 if ( imapAccount.iImapAccountId == aAccountId ) |
|
139 { |
|
140 mailboxId = imapAccount.iImapService; |
|
141 } |
|
142 } |
|
143 } |
|
144 else |
|
145 { |
|
146 // POP3 |
|
147 TPopAccount popAccount; |
|
148 RArray<TPopAccount> accountArray; |
|
149 TRAPD( error, aAccounts.GetPopAccountsL( accountArray ) ); |
|
150 |
|
151 TInt account = ( error == KErrNone ) ? |
|
152 accountArray.Count() : KErrNotFound; |
|
153 |
|
154 while ( mailboxId < 0 && --account >= 0 ) |
|
155 { |
|
156 popAccount = accountArray[account]; |
|
157 |
|
158 // Check if the id's match |
|
159 if ( popAccount.iPopAccountId == aAccountId ) |
|
160 { |
|
161 mailboxId = popAccount.iPopService; |
|
162 } |
|
163 } |
|
164 } |
|
165 |
|
166 return mailboxId; |
|
167 } |
|
168 |
|
169 |
|
170 // ---------------------------------------------------------------------------- |
|
171 // IpsSetDataCtrlAccount::AccountIdToExtendedAccountId() |
|
172 // ---------------------------------------------------------------------------- |
|
173 // |
|
174 TUint32 IpsSetDataCtrlAccount::AccountIdToExtendedAccountId( |
|
175 const TUint32 aAccountId, |
|
176 const TUid& aMtmId ) |
|
177 { |
|
178 FUNC_LOG; |
|
179 // Imap4 accounts are 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 |
|
180 if ( aMtmId == KSenduiMtmImap4Uid ) |
|
181 { |
|
182 return ( aAccountId << EIpsSetUiKeyShiftImap4 ); |
|
183 } |
|
184 // Pop3 accounts are 0x100, 0x200, 0x300, 0x400, 0x500, 0x600 |
|
185 else if ( aMtmId == KSenduiMtmPop3Uid ) |
|
186 { |
|
187 return ( aAccountId << EIpsSetUiKeyShiftPop3 ); |
|
188 } |
|
189 else |
|
190 { |
|
191 IPSASSERT_LEAVE_OR_PANIC_L( EAccountCtrl, EInvalidMtm ); |
|
192 } |
|
193 |
|
194 return 0; |
|
195 } |
|
196 |
|
197 // ---------------------------------------------------------------------------- |
|
198 // IpsSetDataCtrlAccount::ExtendedAccountIdToAccountId() |
|
199 // ---------------------------------------------------------------------------- |
|
200 // |
|
201 TUint32 IpsSetDataCtrlAccount::ExtendedAccountIdToAccountId( |
|
202 const TUint32 aExtendedAccountId, |
|
203 const TUid& aMtmId ) |
|
204 { |
|
205 FUNC_LOG; |
|
206 // Imap4 accounts are 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 |
|
207 if ( aMtmId == KSenduiMtmImap4Uid ) |
|
208 { |
|
209 return ( aExtendedAccountId >> EIpsSetUiKeyShiftImap4 ); |
|
210 } |
|
211 // Pop3 accounts are 0x100, 0x200, 0x300, 0x400, 0x500, 0x600 |
|
212 else if ( aMtmId == KSenduiMtmPop3Uid ) |
|
213 { |
|
214 return ( aExtendedAccountId >> EIpsSetUiKeyShiftPop3 ); |
|
215 } |
|
216 else |
|
217 { |
|
218 IPSASSERT_LEAVE_OR_PANIC_L( EAccountCtrl, EInvalidMtm ); |
|
219 } |
|
220 |
|
221 return 0; |
|
222 } |
|
223 |
|
224 // ---------------------------------------------------------------------------- |
|
225 // IpsSetDataCtrlAccount::CreateSettingKey() |
|
226 // ---------------------------------------------------------------------------- |
|
227 // |
|
228 TUint32 IpsSetDataCtrlAccount::CreateSettingKey( |
|
229 const TUint32 aAccountId, |
|
230 const TUint32 aSetting, |
|
231 const TUid& aMtmId ) |
|
232 { |
|
233 FUNC_LOG; |
|
234 return CreateBaseKeyFromAccountId( aAccountId, aMtmId ) + aSetting; |
|
235 |
|
236 } |
|
237 // End of File |
|
238 |