|
1 /* |
|
2 * Copyright (c) 2007-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: Implementation of notification handler manager |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include <ecom/ecom.h> // FinalClose() |
|
21 //<cmail> |
|
22 #include "CFSMailClient.h" |
|
23 //</cmail> |
|
24 #include <sysutil.h> |
|
25 //<cmail> |
|
26 #include <fsmailserver.rsg> |
|
27 #include "cmailhandlerpluginuids.h" |
|
28 #include "fsnotificationhandlerbase.h" |
|
29 #include "FsEmailGlobalDialogsAppUi.h" |
|
30 #include "FsEmailMessageQueryDialog.h" |
|
31 #include "FsEmailAuthenticationDialog.h" |
|
32 //</cmail> |
|
33 #include "fsnotificationhandlermgrimpl.h" |
|
34 //<cmail> |
|
35 #include "FsEmailGlobalDialogsAppUi.h" |
|
36 //</cmail> |
|
37 |
|
38 |
|
39 static const TInt64 KMegaByte = 1048576; |
|
40 |
|
41 // ======== MEMBER FUNCTIONS ======== |
|
42 |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 //<cmail> // aAppUi parameter no longer used, created by its own |
|
49 CFSNotificationHandlerMgr::CFSNotificationHandlerMgr(CFsEmailGlobalDialogsAppUi* aAppUi) : |
|
50 //</cmail> |
|
51 CActive( EPriorityStandard ), |
|
52 iAppUi( aAppUi ) |
|
53 { |
|
54 FUNC_LOG; |
|
55 CActiveScheduler::Add( this ); |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 void CFSNotificationHandlerMgr::ConstructL() |
|
63 { |
|
64 FUNC_LOG; |
|
65 // Performs the time consuming initialization asynchronously in RunL, in order |
|
66 // to let the process startup finish quicker |
|
67 TRequestStatus* status = &iStatus; |
|
68 User::RequestComplete(status, KErrNone); |
|
69 SetActive(); |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // Finishes the initialisation |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 void CFSNotificationHandlerMgr::RunL() |
|
77 { |
|
78 FUNC_LOG; |
|
79 // Create mail client |
|
80 iMailClient = CFSMailClient::NewL(); |
|
81 if ( iMailClient == NULL ) |
|
82 { |
|
83 User::Leave( KErrNoMemory ); |
|
84 } |
|
85 |
|
86 // Once mail client is created ok, disk space needs to be checked |
|
87 // and cleaned if necessary |
|
88 CleanTempFilesIfNeededL(); |
|
89 |
|
90 //<cmail> |
|
91 // Notification handlers are created next. |
|
92 // Notice that if a handler cannot be created it does not mean |
|
93 // that the construction of the manager would be stopped. This |
|
94 // approach is chosen so that if something goes wrong with |
|
95 // construction of a handler it can safely leave and get |
|
96 // destroyed but does not interfere other handlers. |
|
97 |
|
98 CreateAndStoreHandlerL( KMailIconHandlerUid ); |
|
99 |
|
100 CreateAndStoreHandlerL( KLedHandlerUid ); |
|
101 |
|
102 #ifndef __WINS__ |
|
103 CreateAndStoreHandlerL( KSoundHandlerUid ); |
|
104 // Earlier RefreshData() was called for the soundhandler |
|
105 // object after creation, but as it does not do anything |
|
106 // it is not called anymore. |
|
107 #endif |
|
108 |
|
109 CreateAndStoreHandlerL( KMtmHandlerUid ); |
|
110 |
|
111 CreateAndStoreHandlerL( KOutofMemoryHandlerUid ); |
|
112 |
|
113 CreateAndStoreHandlerL( KAuthenticationHandlerUid ); |
|
114 |
|
115 CreateAndStoreHandlerL( KMessageQueryHandlerUid ); |
|
116 |
|
117 CreateAndStoreHandlerL( KCMailCpsHandlerUid ); |
|
118 //</cmail> |
|
119 |
|
120 StartObservingL(); |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 void CFSNotificationHandlerMgr::DoCancel() |
|
128 { |
|
129 FUNC_LOG; |
|
130 // Nothing to cancel |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 void CFSNotificationHandlerMgr::CreateAndStoreHandlerL( TInt aImplementationUid ) |
|
138 { |
|
139 FUNC_LOG; |
|
140 CFSNotificationHandlerBase* handler = NULL; |
|
141 TRAPD( error, handler = CFSNotificationHandlerBase::NewL( aImplementationUid, *this ) ); |
|
142 if( handler && (error == KErrNone) ) |
|
143 { |
|
144 iHandlers.Append( handler ); |
|
145 } |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 //<cmail> |
|
153 CFSNotificationHandlerMgr* CFSNotificationHandlerMgr::NewL(CFsEmailGlobalDialogsAppUi* aAppUi) |
|
154 //</cmail> |
|
155 { |
|
156 FUNC_LOG; |
|
157 CFSNotificationHandlerMgr* self = CFSNotificationHandlerMgr::NewLC( aAppUi ); |
|
158 CleanupStack::Pop( self ); |
|
159 return self; |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 //<cmail> |
|
167 CFSNotificationHandlerMgr* CFSNotificationHandlerMgr::NewLC(CFsEmailGlobalDialogsAppUi* aAppUi) |
|
168 //</cmail> |
|
169 { |
|
170 FUNC_LOG; |
|
171 CFSNotificationHandlerMgr* self = new( ELeave ) CFSNotificationHandlerMgr( aAppUi ); |
|
172 CleanupStack::PushL( self ); |
|
173 self->ConstructL(); |
|
174 return self; |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 CFSNotificationHandlerMgr::~CFSNotificationHandlerMgr() |
|
182 { |
|
183 FUNC_LOG; |
|
184 Cancel(); |
|
185 |
|
186 StopObserving(); |
|
187 |
|
188 iHandlers.ResetAndDestroy(); |
|
189 |
|
190 iHSConnection = NULL; |
|
191 |
|
192 if( iMailClient ) |
|
193 { |
|
194 iMailClient->Close(); |
|
195 iMailClient = NULL; |
|
196 } |
|
197 |
|
198 //<cmail> |
|
199 iAppUi = NULL; |
|
200 //</cmail> |
|
201 |
|
202 // Finished using ECom |
|
203 // ECom used at least in CFSMailHSUpdateHandler |
|
204 REComSession::FinalClose(); |
|
205 } |
|
206 |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 // --------------------------------------------------------------------------- |
|
210 // |
|
211 void CFSNotificationHandlerMgr::EventL( |
|
212 TFSMailEvent aEvent, |
|
213 TFSMailMsgId aMailbox, |
|
214 TAny* aParam1, |
|
215 TAny* aParam2, |
|
216 TAny* aParam3 ) |
|
217 { |
|
218 FUNC_LOG; |
|
219 // First we check each event here. This is done so we know |
|
220 // if something has must be done before passing the event on |
|
221 // to handlers. For example we may want to register to |
|
222 // mailbox events. |
|
223 |
|
224 switch ( aEvent ) |
|
225 { |
|
226 case TFSEventNewMailbox: |
|
227 { |
|
228 iMailClient->SubscribeMailboxEventsL( aMailbox, *this ); |
|
229 iMailClient->GetBrandManagerL().UpdateMailboxNamesL( aMailbox ); |
|
230 break; |
|
231 } |
|
232 case TFSEventMailboxDeleted: |
|
233 { |
|
234 // Don't have to do anything here. Observing has ended when the |
|
235 // mailbox is deleted. |
|
236 break; |
|
237 } |
|
238 case TFSMailboxAvailable: // Flow through |
|
239 case TFSMailboxUnavailable: // Flow through |
|
240 case TFSEventMailboxRenamed: |
|
241 { |
|
242 break; |
|
243 } |
|
244 case TFSEventNewMail: |
|
245 { |
|
246 // If this is a preinstalled version and we receive a new mail we |
|
247 // update the current status of the HS here before passing |
|
248 // the events to handlers so they don't have to do it. If they |
|
249 // do it, it is done several times which is not desired. |
|
250 // The drawback is that by doing it here we might also do it |
|
251 // in situations where the handlers would actually not need it. |
|
252 // Possibly the best solution would be to initialise the |
|
253 // iHSConnection once and then let it observe for changes in |
|
254 // central repository. Currently that solution is not implemented |
|
255 // as it would require more time to implement. |
|
256 } |
|
257 default: |
|
258 { |
|
259 break; |
|
260 } |
|
261 } |
|
262 |
|
263 |
|
264 // Let's pass all events to handlers also. |
|
265 const TInt handlerCount( iHandlers.Count() ); |
|
266 TInt handlerIndex( 0 ); |
|
267 |
|
268 while ( handlerIndex < handlerCount ) |
|
269 { |
|
270 // Event is passed to each handler. If one fails the |
|
271 // event is still passed to others as they are not |
|
272 // necessarily dependant on the same services. This way |
|
273 // If one fails the others can still succeed. |
|
274 TRAP_IGNORE( |
|
275 iHandlers[handlerIndex]->EventL( aEvent, |
|
276 aMailbox, |
|
277 aParam1, |
|
278 aParam2, |
|
279 aParam3 ) ); |
|
280 ++handlerIndex; |
|
281 } |
|
282 } |
|
283 |
|
284 CFSMailClient& CFSNotificationHandlerMgr::MailClient() const |
|
285 { |
|
286 FUNC_LOG; |
|
287 // Instance of this class does not exist without the |
|
288 // mail client so it is safe to return a reference to the |
|
289 // pointed object. |
|
290 return *iMailClient; |
|
291 } |
|
292 |
|
293 CFSNotificationHandlerHSConnection* CFSNotificationHandlerMgr::HSConnection() const |
|
294 { |
|
295 FUNC_LOG; |
|
296 return iHSConnection; |
|
297 } |
|
298 |
|
299 void CFSNotificationHandlerMgr::IncreaseDialogCount() |
|
300 { |
|
301 FUNC_LOG; |
|
302 iDialogCount++; |
|
303 } |
|
304 |
|
305 void CFSNotificationHandlerMgr::DecreaseDialogCount() |
|
306 { |
|
307 FUNC_LOG; |
|
308 iDialogCount--; |
|
309 } |
|
310 |
|
311 TInt CFSNotificationHandlerMgr::GetDialogCount() |
|
312 { |
|
313 FUNC_LOG; |
|
314 return iDialogCount; |
|
315 } |
|
316 |
|
317 //<cmail> |
|
318 void CFSNotificationHandlerMgr::MessageQueryL( TDesC& aMailboxName, |
|
319 TRequestStatus& aStatus, |
|
320 const TDesC& aCustomMessageText, |
|
321 TFsEmailNotifierSystemMessageType aMessageType ) |
|
322 { |
|
323 FUNC_LOG; |
|
324 CFsEmailMessageQueryDialog* dialog = |
|
325 CFsEmailMessageQueryDialog::NewLC( |
|
326 aStatus, aMailboxName, aMessageType, aCustomMessageText ); |
|
327 // RunLD pops dialog from cleanup stack |
|
328 dialog->RunLD(); |
|
329 } |
|
330 //</cmail> |
|
331 |
|
332 TInt CFSNotificationHandlerMgr::AuthenticateL( TDes& aPassword, |
|
333 TDesC& aMailboxName, |
|
334 TRequestStatus& aStatus ) |
|
335 { |
|
336 FUNC_LOG; |
|
337 CFsEmailAuthenticationDialog* dialog = CFsEmailAuthenticationDialog::NewL( aStatus, aMailboxName, aPassword ); |
|
338 TRAPD( err, dialog->ExecuteLD( R_FS_MSERVER_DIALOG_AUTHENTICATION ) ); |
|
339 return err; |
|
340 } |
|
341 |
|
342 // --------------------------------------------------------------------------- |
|
343 // |
|
344 // --------------------------------------------------------------------------- |
|
345 // |
|
346 void CFSNotificationHandlerMgr::StartObservingL() |
|
347 { |
|
348 FUNC_LOG; |
|
349 iMailClient->AddObserverL( *this ); |
|
350 |
|
351 RPointerArray<CFSMailBox> mailBoxList; |
|
352 // Null id given as a plugin id. mailboxes of all plugins retrieved. |
|
353 // Notice that ownership of the mailboxes is not passed to here. |
|
354 iMailClient->ListMailBoxes( TFSMailMsgId(), mailBoxList ); |
|
355 |
|
356 TInt mailBoxCount( mailBoxList.Count() ); |
|
357 TInt mailboxIndexer( 0 ); |
|
358 while ( mailboxIndexer < mailBoxCount ) |
|
359 { |
|
360 |
|
361 // Here could be prevented the observing of mailboxes |
|
362 // that don't contain inbox but it is probably rather |
|
363 // improbable and it also would complicate the implementation. |
|
364 // So not implemented. |
|
365 TFSMailMsgId currentMailboxId( |
|
366 mailBoxList[mailboxIndexer]->GetId() ); |
|
367 TInt error = KErrNone; |
|
368 TRAP( error, iMailClient->SubscribeMailboxEventsL( currentMailboxId, |
|
369 *this ) ); |
|
370 |
|
371 // Although an error would occur in subscribing to some mailbox |
|
372 // the execution is still continued so that one mailbox won't |
|
373 // prevent mail server from using the other mailboxes. |
|
374 |
|
375 ++mailboxIndexer; |
|
376 } |
|
377 |
|
378 mailBoxList.ResetAndDestroy(); |
|
379 } |
|
380 |
|
381 // --------------------------------------------------------------------------- |
|
382 // |
|
383 // --------------------------------------------------------------------------- |
|
384 // |
|
385 void CFSNotificationHandlerMgr::StopObserving() |
|
386 { |
|
387 FUNC_LOG; |
|
388 |
|
389 // Removeobserver is also called for each mailbox |
|
390 // We should be an observer for each mailbox so this should not |
|
391 // bring up any problems normally. |
|
392 |
|
393 RPointerArray<CFSMailBox> mailBoxList; |
|
394 // Null id given as a plugin id. mailboxes of all plugins retrieved. |
|
395 // Notice that ownership of the mailboxes is not passed to here. |
|
396 iMailClient->ListMailBoxes( TFSMailMsgId(), mailBoxList ); |
|
397 |
|
398 TInt mailBoxCount( mailBoxList.Count() ); |
|
399 TInt mailboxIndexer( 0 ); |
|
400 while ( mailboxIndexer < mailBoxCount ) |
|
401 { |
|
402 TFSMailMsgId currentMailboxId( |
|
403 mailBoxList[mailboxIndexer]->GetId() ); |
|
404 iMailClient->UnsubscribeMailboxEvents( currentMailboxId, |
|
405 *this ); |
|
406 |
|
407 ++mailboxIndexer; |
|
408 } |
|
409 |
|
410 mailBoxList.ResetAndDestroy(); |
|
411 |
|
412 |
|
413 iMailClient->RemoveObserver( *this ); |
|
414 |
|
415 } |
|
416 |
|
417 // --------------------------------------------------------------------------- |
|
418 // Function cleans up downloaded files of mailboxes if disk space is low |
|
419 // --------------------------------------------------------------------------- |
|
420 // |
|
421 void CFSNotificationHandlerMgr::CleanTempFilesIfNeededL() |
|
422 { |
|
423 FUNC_LOG; |
|
424 RFs fsSession; |
|
425 User::LeaveIfError(fsSession.Connect()); |
|
426 CleanupClosePushL(fsSession); |
|
427 // Check whether disk space is below 3MB, in that case start cleaning up |
|
428 // downloaded attachments from mailboxes. |
|
429 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &fsSession, 3*KMegaByte, EDriveC ) ) |
|
430 { |
|
431 RPointerArray<CFSMailBox> mailBoxList; |
|
432 // Null id given as a plugin id. mailboxes of all plugins retrieved. |
|
433 // Notice that ownership of the mailboxes is not passed to here. |
|
434 iMailClient->ListMailBoxes( TFSMailMsgId(), mailBoxList ); |
|
435 for ( TInt i = 0 ; i < mailBoxList.Count() ; ++i ) |
|
436 { |
|
437 TRAP_IGNORE( mailBoxList[i]->RemoveDownLoadedAttachmentsL() ); |
|
438 } |
|
439 mailBoxList.ResetAndDestroy(); |
|
440 } |
|
441 CleanupStack::PopAndDestroy( &fsSession ); |
|
442 } |
|
443 |
|
444 |
|
445 //<cmail> |
|
446 // --------------------------------------------------------------------------- |
|
447 // CFSNotificationHandlerMgr::SendAppUiToBackground() |
|
448 // --------------------------------------------------------------------------- |
|
449 // |
|
450 void CFSNotificationHandlerMgr::SendAppUiToBackground() |
|
451 { |
|
452 FUNC_LOG; |
|
453 if(iAppUi) |
|
454 iAppUi->SendToBackground(); |
|
455 } |
|
456 |
|
457 // --------------------------------------------------------------------------- |
|
458 // CFSNotificationHandlerMgr::BringAppUiToForeground() |
|
459 // --------------------------------------------------------------------------- |
|
460 // |
|
461 void CFSNotificationHandlerMgr::BringAppUiToForeground() |
|
462 { |
|
463 FUNC_LOG; |
|
464 if(iAppUi) |
|
465 iAppUi->BringToForeground(); |
|
466 } |
|
467 //</cmail> |
|
468 |
|
469 // End of file |
|
470 |