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