|
1 /* |
|
2 * Copyright (c) 2008 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 class CFSMailMessageQueryHandler. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //<cmail> |
|
20 #include "emailtrace.h" |
|
21 #include "CFSMailClient.h" |
|
22 //</cmail> |
|
23 |
|
24 #include "fsmailmessagequeryhandler.h" |
|
25 |
|
26 |
|
27 CFSMailMessageQueryHandler* CFSMailMessageQueryHandler::NewL( |
|
28 MFSNotificationHandlerMgr& aOwner ) |
|
29 { |
|
30 FUNC_LOG; |
|
31 CFSMailMessageQueryHandler* self = |
|
32 new (ELeave) CFSMailMessageQueryHandler( aOwner ); |
|
33 CleanupStack::PushL( self ); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop( self ); |
|
36 return self; |
|
37 } |
|
38 |
|
39 CFSMailMessageQueryHandler::CFSMailMessageQueryHandler( |
|
40 MFSNotificationHandlerMgr& aOwner ) : |
|
41 CFSNotificationHandlerBase( aOwner ) |
|
42 { |
|
43 FUNC_LOG; |
|
44 } |
|
45 |
|
46 void CFSMailMessageQueryHandler::ConstructL() |
|
47 { |
|
48 FUNC_LOG; |
|
49 CFSNotificationHandlerBase::ConstructL(); |
|
50 |
|
51 // We are now ready to observe mail events |
|
52 SetObserving( ETrue ); |
|
53 } |
|
54 |
|
55 CFSMailMessageQueryHandler::~CFSMailMessageQueryHandler() |
|
56 { |
|
57 FUNC_LOG; |
|
58 iNotifierInitiators.ResetAndDestroy(); |
|
59 } |
|
60 |
|
61 void CFSMailMessageQueryHandler::NotifierInitiatorDoneL( |
|
62 CFSNotificationHandlerNotifierInitiator* aInitiator ) |
|
63 { |
|
64 FUNC_LOG; |
|
65 |
|
66 TInt initiatorIndexer( FindInitiator( aInitiator ) ); |
|
67 |
|
68 if ( initiatorIndexer == KErrNotFound ) |
|
69 { |
|
70 User::Leave( KErrNotFound ); |
|
71 } |
|
72 |
|
73 iNotifierInitiators.Remove( initiatorIndexer ); |
|
74 CleanupStack::PushL( aInitiator ); |
|
75 |
|
76 MFSMailExceptionEventCallback* callback = aInitiator->Callback(); |
|
77 if( callback ) |
|
78 { |
|
79 TFSMailMsgId mailboxId = aInitiator->MailBoxId(); |
|
80 TFsEmailNotifierSystemMessageType msgType = aInitiator->MessageType(); |
|
81 TBool response = aInitiator->GetLastResponse(); |
|
82 callback->ExceptionEventCallbackL( mailboxId, msgType, response ); |
|
83 } |
|
84 |
|
85 CleanupStack::PopAndDestroy( aInitiator ); |
|
86 } |
|
87 |
|
88 TBool CFSMailMessageQueryHandler::CapabilitiesToContinueL( |
|
89 TFSMailEvent /*aEvent*/, |
|
90 TFSMailMsgId /*aMailbox*/, |
|
91 TAny* /*aParam1*/, |
|
92 TAny* /*aParam2*/, |
|
93 TAny* /*aParam3*/ ) const |
|
94 { |
|
95 FUNC_LOG; |
|
96 // Authentication query is always shown by instance of this class |
|
97 // if necessary. |
|
98 return ETrue; |
|
99 } |
|
100 |
|
101 /* |
|
102 static const TInt KTestCountMin( 0 ); |
|
103 static const TInt KTestCountMax( 3 ); |
|
104 _LIT( KTestText, "Very fancy test text." ); |
|
105 */ |
|
106 |
|
107 void CFSMailMessageQueryHandler::HandleEventL( |
|
108 TFSMailEvent aEvent, |
|
109 TFSMailMsgId aMailbox, |
|
110 TAny* aParam1, |
|
111 TAny* aParam2, |
|
112 TAny* aParam3 ) |
|
113 { |
|
114 FUNC_LOG; |
|
115 switch ( aEvent ) |
|
116 { |
|
117 case TFSEventException: |
|
118 { |
|
119 TFsEmailNotifierSystemMessageType& msgType = *static_cast<TFsEmailNotifierSystemMessageType*>( aParam1 ); |
|
120 TDesC& msgText = *static_cast<TDesC*>( aParam2 ); |
|
121 MFSMailExceptionEventCallback* callback = static_cast<MFSMailExceptionEventCallback*>( aParam3 ); |
|
122 |
|
123 |
|
124 ShowMessageQueryL( aMailbox, msgType, msgText, callback ); |
|
125 |
|
126 break; |
|
127 } |
|
128 /* |
|
129 case TFSEventMailboxOnline: |
|
130 { |
|
131 // ONLY FOR TESTING |
|
132 static TInt testCounter( KTestCountMin ); |
|
133 |
|
134 testCounter++; |
|
135 if( testCounter > KTestCountMax ) |
|
136 { |
|
137 testCounter = KTestCountMin; |
|
138 } |
|
139 |
|
140 TFsEmailNotifierSystemMessageType msgType = static_cast<TFsEmailNotifierSystemMessageType>( testCounter ); |
|
141 |
|
142 ShowMessageQueryL( aMailbox, msgType, KTestText(), NULL ); |
|
143 |
|
144 break; |
|
145 } |
|
146 */ |
|
147 default: |
|
148 { |
|
149 break; |
|
150 } |
|
151 } |
|
152 } |
|
153 |
|
154 |
|
155 void CFSMailMessageQueryHandler::ShowMessageQueryL( |
|
156 TFSMailMsgId aMailbox, |
|
157 TFsEmailNotifierSystemMessageType aMessageType, |
|
158 const TDesC& aCustomMessageText, |
|
159 MFSMailExceptionEventCallback* aCallback ) |
|
160 { |
|
161 FUNC_LOG; |
|
162 |
|
163 TInt index( FindInitiator( aMailbox, aMessageType ) ); |
|
164 |
|
165 // Only one message query is permitted for one mailbox-message type |
|
166 // combination. So one mailbox can have several message query dialogs |
|
167 // open, if they are not of the same type. On the other hand, two |
|
168 // or more mailboxes can show the same message. |
|
169 if ( index == KErrNotFound ) |
|
170 { |
|
171 |
|
172 CFSMailBox* mailBox( |
|
173 MailClient().GetMailBoxByUidL( aMailbox ) ); |
|
174 User::LeaveIfNull( mailBox ); |
|
175 CleanupStack::PushL( mailBox ); |
|
176 TDesC& mailboxName( mailBox->GetName() ); |
|
177 |
|
178 CFSNotificationHandlerNotifierInitiator* newNotifierInitiator = |
|
179 CFSNotificationHandlerNotifierInitiator::NewL( *this, iOwner ); |
|
180 CleanupStack::PushL( newNotifierInitiator ); |
|
181 |
|
182 newNotifierInitiator->SetMailBoxId( aMailbox ); |
|
183 newNotifierInitiator->SetMessageType( aMessageType ); |
|
184 newNotifierInitiator->SetCallback( aCallback ); |
|
185 |
|
186 newNotifierInitiator->RequestMessageQueryL( |
|
187 mailboxName, |
|
188 aMessageType, |
|
189 aCustomMessageText ); |
|
190 |
|
191 iNotifierInitiators.AppendL( newNotifierInitiator ); |
|
192 CleanupStack::Pop( newNotifierInitiator ); |
|
193 CleanupStack::PopAndDestroy( mailBox ); |
|
194 } |
|
195 else |
|
196 { |
|
197 // notifierInitiator exists so we are already showing |
|
198 // this message query for this mailbox. Let's not |
|
199 // show/queue a new one. |
|
200 } |
|
201 } |
|
202 |
|
203 |
|
204 TInt CFSMailMessageQueryHandler::FindInitiator( |
|
205 CFSNotificationHandlerNotifierInitiator* aInitiator ) const |
|
206 { |
|
207 FUNC_LOG; |
|
208 return iNotifierInitiators.Find( aInitiator ); |
|
209 } |
|
210 |
|
211 TInt CFSMailMessageQueryHandler::FindInitiator( |
|
212 TFSMailMsgId aMailBoxId, |
|
213 TFsEmailNotifierSystemMessageType aMessageType ) const |
|
214 { |
|
215 FUNC_LOG; |
|
216 TInt initiatorCount( iNotifierInitiators.Count() ); |
|
217 TInt initiatorIndexer( 0 ); |
|
218 |
|
219 while ( initiatorIndexer < initiatorCount ) |
|
220 { |
|
221 if( iNotifierInitiators[initiatorIndexer]->MailBoxId() == aMailBoxId && |
|
222 iNotifierInitiators[initiatorIndexer]->MessageType() == aMessageType ) |
|
223 { |
|
224 return initiatorIndexer; |
|
225 } |
|
226 |
|
227 ++initiatorIndexer; |
|
228 } |
|
229 |
|
230 return KErrNotFound; |
|
231 } |
|
232 |
|
233 |
|
234 void CFSMailMessageQueryHandler::TurnNotificationOn() |
|
235 { |
|
236 FUNC_LOG; |
|
237 } |
|
238 |
|
239 void CFSMailMessageQueryHandler::TurnNotificationOff() |
|
240 { |
|
241 FUNC_LOG; |
|
242 } |
|
243 |