|
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 <cemailaccounts.h> |
|
19 |
|
20 #include "nmipssettingsmanagerfactory.h" |
|
21 #include "nmipsimap4settingsmanager.h" |
|
22 #include "nmipspop3settingsmanager.h" |
|
23 #include "nmcommon.h" |
|
24 |
|
25 /*! |
|
26 \class NmIpsSettingsManagerFactory |
|
27 \brief The class verify the mailbox type and return the appropriate settings manager |
|
28 */ |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 |
|
32 /*! |
|
33 Static factory function that creates the appropriate settingsmanager. |
|
34 \param mailboxId Id of the mailbox. |
|
35 \return <code>NmIpsImap4SettingsManager</code> if Imap4 mailbox otherwise |
|
36 <code>NmIpsPop3SettingsManager</code> if Pop3 mailbox |
|
37 */ |
|
38 NmIpsSettingsManagerBase *NmIpsSettingsManagerFactory::createSettingManager(const NmId &mailboxId) |
|
39 { |
|
40 NmIpsSettingsManagerBase *settingManager = 0; |
|
41 TImapAccount imapAccount; |
|
42 TPopAccount popAccount; |
|
43 |
|
44 QScopedPointer<CEmailAccounts> emailAccounts; |
|
45 TRAPD(err, emailAccounts.reset(CEmailAccounts::NewL())); |
|
46 |
|
47 if (err == KErrNone) { |
|
48 bool isImapAccount = false; |
|
49 isImapAccount = isImap4MailAccount(*emailAccounts, mailboxId, imapAccount); |
|
50 if (isImapAccount) { |
|
51 settingManager = new NmIpsImap4SettingsManager(mailboxId, emailAccounts.data(), imapAccount); |
|
52 (void)emailAccounts.take(); |
|
53 } else { |
|
54 bool isPopAccount = false; |
|
55 isPopAccount = isPop3MailAccount(*emailAccounts, mailboxId, popAccount); |
|
56 if (isPopAccount) { |
|
57 settingManager = new NmIpsPop3SettingsManager(mailboxId, emailAccounts.data(), popAccount); |
|
58 (void)emailAccounts.take(); |
|
59 } |
|
60 } |
|
61 } |
|
62 return settingManager; |
|
63 } |
|
64 |
|
65 /*! |
|
66 Function first search for all the Imap mailboxes, then it checks if one the mailboxes |
|
67 matches the mailbox id. |
|
68 \param emailAccounts CEmailAccounts that will be used to manipulate the mailbox. |
|
69 \param mailboxId Id of the mailbox. |
|
70 \param imapAccount TImapAccount reference for returning the Imap mailbox if found. |
|
71 \return <code>true</code> if the Imap4 mailbox were found otherwise <code>false</code> |
|
72 */ |
|
73 bool NmIpsSettingsManagerFactory::isImap4MailAccount(CEmailAccounts &emailAccounts, |
|
74 const NmId &mailboxId, TImapAccount &imapAccount) |
|
75 { |
|
76 bool result = false; |
|
77 RArray<TImapAccount> imapAccounts; |
|
78 TRAPD(err, emailAccounts.GetImapAccountsL( imapAccounts )); |
|
79 if (err == KErrNone) { |
|
80 TInt accountCount( imapAccounts.Count() ); |
|
81 for ( TInt accountIndex( 0 ); accountIndex < accountCount; ++accountIndex ) { |
|
82 // mailboxId.mId contains exactly same value as account.iImapAccountId |
|
83 // when refering to same mailbox. |
|
84 TImapAccount account = imapAccounts[accountIndex]; |
|
85 if ( account.iImapService == mailboxId.id32()) { |
|
86 imapAccount = account; |
|
87 result = true; //is imap4 box |
|
88 break; |
|
89 } |
|
90 } |
|
91 } |
|
92 return result; |
|
93 } |
|
94 |
|
95 /*! |
|
96 Function first search for all the Pop mailboxes, then it checks if one the mailboxes |
|
97 matches the mailbox id. |
|
98 \param emailAccounts CEmailAccounts that will be used to manipulate the mailbox. |
|
99 \param mailboxId Id of the mailbox. |
|
100 \param popAccount TPopAccount reference for returning the pop mailbox if found. |
|
101 \return <code>true</code> if the Pop3 mailbox were found otherwise <code>false</code> |
|
102 */ |
|
103 bool NmIpsSettingsManagerFactory::isPop3MailAccount(CEmailAccounts &emailAccounts, |
|
104 const NmId &mailboxId, TPopAccount &popAccount) |
|
105 { |
|
106 bool result = false; |
|
107 RArray<TPopAccount> popAccounts; |
|
108 TRAPD(err, emailAccounts.GetPopAccountsL(popAccounts)); |
|
109 if (err == KErrNone) { |
|
110 TInt accountCount = popAccounts.Count(); |
|
111 for (TInt i = 0; i < accountCount; ++i) { |
|
112 // mailboxId.mId contains exactly same value as account.iPopAccountId |
|
113 // when refering to same mailbox. |
|
114 TPopAccount account = popAccounts[i]; |
|
115 if (popAccounts[i].iPopService == mailboxId.id32()) { |
|
116 popAccount = account; |
|
117 result = true; //is pop3 box |
|
118 break; |
|
119 } |
|
120 } |
|
121 } |
|
122 return result; |
|
123 } |
|
124 |