|
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 initialization |
|
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 iAppUi = NULL; |
|
199 |
|
200 // Finished using ECom |
|
201 // ECom used at least in CFSMailHSUpdateHandler |
|
202 REComSession::FinalClose(); |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 void CFSNotificationHandlerMgr::EventL( |
|
210 TFSMailEvent aEvent, |
|
211 TFSMailMsgId aMailbox, |
|
212 TAny* aParam1, |
|
213 TAny* aParam2, |
|
214 TAny* aParam3 ) |
|
215 { |
|
216 FUNC_LOG; |
|
217 // First we check each event here. This is done so we know |
|
218 // if something has must be done before passing the event on |
|
219 // to handlers. For example we may want to register to |
|
220 // mailbox events. |
|
221 |
|
222 switch ( aEvent ) |
|
223 { |
|
224 case TFSEventNewMailbox: |
|
225 { |
|
226 iMailClient->SubscribeMailboxEventsL( aMailbox, *this ); |
|
227 iMailClient->GetBrandManagerL().UpdateMailboxNamesL( aMailbox ); |
|
228 break; |
|
229 } |
|
230 case TFSEventMailboxDeleted: |
|
231 { |
|
232 // Observing has ended when the mailbox is deleted. |
|
233 |
|
234 // reset mailbox cached values |
|
235 iPreviousParentFolderId = TFSMailMsgId(); |
|
236 iPreviousMailbox = TFSMailMsgId(); |
|
237 break; |
|
238 } |
|
239 case TFSMailboxAvailable: // Flow through |
|
240 case TFSMailboxUnavailable: // Flow through |
|
241 case TFSEventMailboxRenamed: |
|
242 { |
|
243 break; |
|
244 } |
|
245 case TFSEventNewMail: |
|
246 { |
|
247 // If this is a pre-installed version and we receive a new mail we |
|
248 // update the current status of the HS here before passing |
|
249 // the events to handlers so they don't have to do it. If they |
|
250 // do it, it is done several times which is not desired. |
|
251 // The drawback is that by doing it here we might also do it |
|
252 // in situations where the handlers would actually not need it. |
|
253 // Possibly the best solution would be to initialize the |
|
254 // iHSConnection once and then let it observe for changes in |
|
255 // central repository. Currently that solution is not implemented |
|
256 // as it would require more time to implement. |
|
257 } |
|
258 default: |
|
259 { |
|
260 break; |
|
261 } |
|
262 } |
|
263 |
|
264 |
|
265 // Let's pass all events to handlers also. |
|
266 const TInt handlerCount( iHandlers.Count() ); |
|
267 TInt handlerIndex( 0 ); |
|
268 |
|
269 while ( handlerIndex < handlerCount ) |
|
270 { |
|
271 // Event is passed to each handler. If one fails the |
|
272 // event is still passed to others as they are not |
|
273 // necessarily dependent on the same services. This way |
|
274 // If one fails the others can still succeed. |
|
275 TRAP_IGNORE( |
|
276 iHandlers[handlerIndex]->EventL( aEvent, |
|
277 aMailbox, |
|
278 aParam1, |
|
279 aParam2, |
|
280 aParam3 ) ); |
|
281 ++handlerIndex; |
|
282 } |
|
283 } |
|
284 |
|
285 CFSMailClient& CFSNotificationHandlerMgr::MailClient() const |
|
286 { |
|
287 FUNC_LOG; |
|
288 // Instance of this class does not exist without the |
|
289 // mail client so it is safe to return a reference to the |
|
290 // pointed object. |
|
291 return *iMailClient; |
|
292 } |
|
293 |
|
294 CFSNotificationHandlerHSConnection* CFSNotificationHandlerMgr::HSConnection() const |
|
295 { |
|
296 FUNC_LOG; |
|
297 return iHSConnection; |
|
298 } |
|
299 |
|
300 void CFSNotificationHandlerMgr::IncreaseDialogCount() |
|
301 { |
|
302 FUNC_LOG; |
|
303 iDialogCount++; |
|
304 } |
|
305 |
|
306 void CFSNotificationHandlerMgr::DecreaseDialogCount() |
|
307 { |
|
308 FUNC_LOG; |
|
309 iDialogCount--; |
|
310 } |
|
311 |
|
312 TInt CFSNotificationHandlerMgr::GetDialogCount() |
|
313 { |
|
314 FUNC_LOG; |
|
315 return iDialogCount; |
|
316 } |
|
317 |
|
318 //<cmail> |
|
319 void CFSNotificationHandlerMgr::MessageQueryL( TDesC& aMailboxName, |
|
320 TRequestStatus& aStatus, |
|
321 const TDesC& aCustomMessageText, |
|
322 TFsEmailNotifierSystemMessageType aMessageType ) |
|
323 { |
|
324 FUNC_LOG; |
|
325 CFsEmailMessageQueryDialog* dialog = |
|
326 CFsEmailMessageQueryDialog::NewLC( |
|
327 aStatus, aMailboxName, aMessageType, aCustomMessageText ); |
|
328 // RunLD pops dialog from cleanup stack |
|
329 dialog->RunLD(); |
|
330 } |
|
331 //</cmail> |
|
332 |
|
333 TInt CFSNotificationHandlerMgr::AuthenticateL( TDes& aPassword, |
|
334 TDesC& aMailboxName, |
|
335 TRequestStatus& aStatus ) |
|
336 { |
|
337 FUNC_LOG; |
|
338 CFsEmailAuthenticationDialog* dialog = CFsEmailAuthenticationDialog::NewL( aStatus, aMailboxName, aPassword ); |
|
339 TRAPD( err, dialog->ExecuteLD( R_FS_MSERVER_DIALOG_AUTHENTICATION ) ); |
|
340 return err; |
|
341 } |
|
342 |
|
343 |
|
344 TFSFolderType CFSNotificationHandlerMgr::GetFolderTypeL( TFSMailMsgId& aMailbox, TFSMailMsgId* parentFolderId ) |
|
345 { |
|
346 TFSFolderType folderType( EFSInbox ); |
|
347 if ( parentFolderId ) |
|
348 { |
|
349 if ( (*parentFolderId) == iPreviousParentFolderId && |
|
350 aMailbox == iPreviousMailbox ) |
|
351 { |
|
352 // we assume that folder with some id does not change |
|
353 // its type during mail synchronization |
|
354 folderType = iPreviousParentFolderType; |
|
355 } |
|
356 else |
|
357 { |
|
358 iPreviousParentFolderId = (*parentFolderId); |
|
359 // Get the parent folder object |
|
360 CFSMailFolder* parentFolder = iMailClient->GetFolderByUidL( |
|
361 aMailbox, *parentFolderId ); |
|
362 if ( parentFolder ) |
|
363 { |
|
364 folderType = parentFolder->GetFolderType(); |
|
365 iPreviousParentFolderType = folderType; |
|
366 delete parentFolder; |
|
367 parentFolder = NULL; |
|
368 } |
|
369 } |
|
370 } |
|
371 |
|
372 return folderType; |
|
373 } |
|
374 // --------------------------------------------------------------------------- |
|
375 // |
|
376 // --------------------------------------------------------------------------- |
|
377 // |
|
378 void CFSNotificationHandlerMgr::StartObservingL() |
|
379 { |
|
380 FUNC_LOG; |
|
381 iMailClient->AddObserverL( *this ); |
|
382 |
|
383 RPointerArray<CFSMailBox> mailBoxList; |
|
384 // Null id given as a plugin id. mailboxes of all plugins retrieved. |
|
385 // Notice that ownership of the mailboxes is not passed to here. |
|
386 iMailClient->ListMailBoxes( TFSMailMsgId(), mailBoxList ); |
|
387 |
|
388 TInt mailBoxCount( mailBoxList.Count() ); |
|
389 TInt mailboxIndexer( 0 ); |
|
390 while ( mailboxIndexer < mailBoxCount ) |
|
391 { |
|
392 |
|
393 // Here could be prevented the observing of mailboxes |
|
394 // that don't contain inbox but it is probably rather |
|
395 // improbable and it also would complicate the implementation. |
|
396 // So not implemented. |
|
397 TFSMailMsgId currentMailboxId( |
|
398 mailBoxList[mailboxIndexer]->GetId() ); |
|
399 TInt error = KErrNone; |
|
400 TRAP( error, iMailClient->SubscribeMailboxEventsL( currentMailboxId, |
|
401 *this ) ); |
|
402 |
|
403 // Although an error would occur in subscribing to some mailbox |
|
404 // the execution is still continued so that one mailbox won't |
|
405 // prevent mail server from using the other mailboxes. |
|
406 |
|
407 ++mailboxIndexer; |
|
408 } |
|
409 |
|
410 mailBoxList.ResetAndDestroy(); |
|
411 } |
|
412 |
|
413 // --------------------------------------------------------------------------- |
|
414 // |
|
415 // --------------------------------------------------------------------------- |
|
416 // |
|
417 void CFSNotificationHandlerMgr::StopObserving() |
|
418 { |
|
419 FUNC_LOG; |
|
420 |
|
421 // Removeobserver is also called for each mailbox |
|
422 // We should be an observer for each mailbox so this should not |
|
423 // bring up any problems normally. |
|
424 |
|
425 RPointerArray<CFSMailBox> mailBoxList; |
|
426 // Null id given as a plugin id. mailboxes of all plugins retrieved. |
|
427 // Notice that ownership of the mailboxes is not passed to here. |
|
428 iMailClient->ListMailBoxes( TFSMailMsgId(), mailBoxList ); |
|
429 |
|
430 TInt mailBoxCount( mailBoxList.Count() ); |
|
431 TInt mailboxIndexer( 0 ); |
|
432 while ( mailboxIndexer < mailBoxCount ) |
|
433 { |
|
434 TFSMailMsgId currentMailboxId( |
|
435 mailBoxList[mailboxIndexer]->GetId() ); |
|
436 iMailClient->UnsubscribeMailboxEvents( currentMailboxId, |
|
437 *this ); |
|
438 |
|
439 ++mailboxIndexer; |
|
440 } |
|
441 |
|
442 mailBoxList.ResetAndDestroy(); |
|
443 |
|
444 |
|
445 iMailClient->RemoveObserver( *this ); |
|
446 |
|
447 } |
|
448 |
|
449 // --------------------------------------------------------------------------- |
|
450 // Function cleans up downloaded files of mailboxes if disk space is low |
|
451 // --------------------------------------------------------------------------- |
|
452 // |
|
453 void CFSNotificationHandlerMgr::CleanTempFilesIfNeededL() |
|
454 { |
|
455 FUNC_LOG; |
|
456 RFs fsSession; |
|
457 User::LeaveIfError(fsSession.Connect()); |
|
458 CleanupClosePushL(fsSession); |
|
459 // Check whether disk space is below 3MB, in that case start cleaning up |
|
460 // downloaded attachments from mailboxes. |
|
461 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &fsSession, 3*KMegaByte, EDriveC ) ) |
|
462 { |
|
463 RPointerArray<CFSMailBox> mailBoxList; |
|
464 // Null id given as a plugin id. mailboxes of all plugins retrieved. |
|
465 // Notice that ownership of the mailboxes is not passed to here. |
|
466 iMailClient->ListMailBoxes( TFSMailMsgId(), mailBoxList ); |
|
467 for ( TInt i = 0 ; i < mailBoxList.Count() ; ++i ) |
|
468 { |
|
469 TRAP_IGNORE( mailBoxList[i]->RemoveDownLoadedAttachmentsL() ); |
|
470 } |
|
471 mailBoxList.ResetAndDestroy(); |
|
472 } |
|
473 CleanupStack::PopAndDestroy( &fsSession ); |
|
474 } |
|
475 |
|
476 |
|
477 //<cmail> |
|
478 // --------------------------------------------------------------------------- |
|
479 // CFSNotificationHandlerMgr::SendAppUiToBackground() |
|
480 // --------------------------------------------------------------------------- |
|
481 // |
|
482 void CFSNotificationHandlerMgr::SendAppUiToBackground() |
|
483 { |
|
484 FUNC_LOG; |
|
485 if(iAppUi) |
|
486 iAppUi->SendToBackground(); |
|
487 } |
|
488 |
|
489 // --------------------------------------------------------------------------- |
|
490 // CFSNotificationHandlerMgr::BringAppUiToForeground() |
|
491 // --------------------------------------------------------------------------- |
|
492 // |
|
493 void CFSNotificationHandlerMgr::BringAppUiToForeground() |
|
494 { |
|
495 FUNC_LOG; |
|
496 if(iAppUi) |
|
497 iAppUi->BringToForeground(); |
|
498 } |
|
499 //</cmail> |
|
500 |
|
501 // End of file |
|
502 |