|
1 /* |
|
2 * Copyright (c) 2008 - 2009 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: Class to handle content publishing for widget |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __CMAILCPSHANDLER_H__ |
|
20 #define __CMAILCPSHANDLER_H__ |
|
21 |
|
22 #include <aknappui.h> |
|
23 #include <memailobserverlistener.h> // base class |
|
24 #include <AknGlobalNote.h> |
|
25 |
|
26 // FSMailServer classes (base classes and callback interfaces) |
|
27 #include "fsnotificationhandlerbase.h" |
|
28 #include "fsnotificationhandlernotifierinitiator.h" |
|
29 #include "fsnotificationhandlernotifierinitiatorobserver.h" |
|
30 // Member classes |
|
31 #include "cmailcpssettings.h" // MMailCpsSettingsCallback |
|
32 |
|
33 class CMailCpsIf; |
|
34 class CFSMailBox; |
|
35 class CMailMailboxDetails; |
|
36 class CMailCpsSettings; |
|
37 class CMailExternalAccount; |
|
38 class CMailPluginProxy; |
|
39 class CEmailObserverPlugin; |
|
40 class CMailCpsUpdateHelper; |
|
41 |
|
42 /** |
|
43 * CMail ContentPublishingService Handler class |
|
44 * Class implementing a handler functionality towards rest of the MailServer |
|
45 * |
|
46 * @lib fsmailserver.exe |
|
47 * @since S60 v5.1 |
|
48 */ |
|
49 NONSHARABLE_CLASS( CMailCpsHandler ) : |
|
50 public CFSNotificationHandlerBase, |
|
51 public MMailCpsSettingsCallback, |
|
52 public EmailInterface::MEmailObserverListener |
|
53 { |
|
54 public: |
|
55 |
|
56 /** |
|
57 * Two-phased constructor. |
|
58 * @param aOwner Owner and manager of this handler. |
|
59 */ |
|
60 static CMailCpsHandler* NewL( MFSNotificationHandlerMgr& aOwner ); |
|
61 |
|
62 /** |
|
63 * Destructor. |
|
64 */ |
|
65 virtual ~CMailCpsHandler(); |
|
66 |
|
67 /** |
|
68 * From MMailCpsSettingsCallback |
|
69 */ |
|
70 virtual void SettingsChangedCallback(); |
|
71 |
|
72 /** |
|
73 * |
|
74 */ |
|
75 void SetUpdateNeeded( const TFSMailMsgId aMailbox ); |
|
76 |
|
77 /** |
|
78 * Wraps all "Update*" methods |
|
79 */ |
|
80 void UpdateFullL(); |
|
81 |
|
82 /** |
|
83 * Method that actually does the full update. |
|
84 * Used by CMailCpsUpdateHelper. |
|
85 */ |
|
86 void DoUpdateFullL(); |
|
87 |
|
88 /** |
|
89 * |
|
90 */ |
|
91 void UpdateMailboxesL(TInt aInstance, const TDesC& aContentId); |
|
92 |
|
93 /** |
|
94 * |
|
95 */ |
|
96 void LaunchWidgetSettingsL( const TDesC& aContentId ); |
|
97 |
|
98 /** |
|
99 * |
|
100 */ |
|
101 void LaunchEmailUIL( const TDesC& aContentId ); |
|
102 |
|
103 /** |
|
104 * |
|
105 */ |
|
106 void LaunchEmailWizardL( const TDesC& aContentId ); |
|
107 /** |
|
108 * Launches an application based on the given contentId |
|
109 * This method is for external (3rd party) accounts |
|
110 * @param aContentId specifies the widget that was pressed by the user |
|
111 */ |
|
112 void LaunchExtAppL( const TDesC& aContentId ); |
|
113 |
|
114 /** |
|
115 * |
|
116 */ |
|
117 void DissociateWidgetFromSettingL( const TDesC& aContentId ); |
|
118 |
|
119 /** |
|
120 * Return total number of mailboxes (native+3rd party) in the system |
|
121 */ |
|
122 TInt TotalMailboxCountL(); |
|
123 |
|
124 /** |
|
125 * Return total number of native mailboxes in the system |
|
126 */ |
|
127 TInt TotalIntMailboxCount(); |
|
128 |
|
129 /** |
|
130 * Return total number of 3rd party mailboxes in the system |
|
131 */ |
|
132 TInt TotalExtMailboxCountL(); |
|
133 |
|
134 /** |
|
135 * Gets correct localised format for time (or date) string |
|
136 */ |
|
137 static HBufC* GetMessageTimeStringL( TTime aMessageTime ); |
|
138 |
|
139 // From MEmailObserverListener |
|
140 void EmailObserverEvent( EmailInterface::MEmailData& aData ); |
|
141 |
|
142 /** |
|
143 * |
|
144 */ |
|
145 void SetWaitingForNewMailbox( const TDesC& aContentId ); |
|
146 |
|
147 /** |
|
148 * |
|
149 */ |
|
150 void CleanWaitingForNewMailbox(); |
|
151 |
|
152 /** |
|
153 * |
|
154 */ |
|
155 void SetWaitingForNewWidget( const TFSMailMsgId aMailbox ); |
|
156 |
|
157 /** |
|
158 * |
|
159 */ |
|
160 void CleanWaitingForNewWidget(); |
|
161 |
|
162 /** |
|
163 * |
|
164 */ |
|
165 TFSMailMsgId WaitingForNewWidget(); |
|
166 |
|
167 /** |
|
168 * |
|
169 */ |
|
170 void AssociateWidgetToSetting( const TDesC& aContentId, |
|
171 const TFSMailMsgId aMailbox ); |
|
172 |
|
173 /** |
|
174 * |
|
175 */ |
|
176 TBool Associated( const TDesC& aContentId ); |
|
177 |
|
178 /** |
|
179 * |
|
180 */ |
|
181 void DisplayHSPageFullNoteL(); |
|
182 |
|
183 /** |
|
184 * get count of unread messages in inbox |
|
185 * @param aMailbox mailbox id |
|
186 */ |
|
187 TInt GetUnreadCountL( TFSMailMsgId aMailbox); |
|
188 |
|
189 protected: |
|
190 /** |
|
191 * From CFSNotificationHandlerBase |
|
192 * see baseclass for details |
|
193 */ |
|
194 virtual TBool CapabilitiesToContinueL( |
|
195 TFSMailEvent aEvent, |
|
196 TFSMailMsgId aMailbox, |
|
197 TAny* aParam1, |
|
198 TAny* aParam2, |
|
199 TAny* aParam3 ) const; |
|
200 |
|
201 /** |
|
202 * From CFSNotificationHandlerBase |
|
203 * see baseclass for details |
|
204 */ |
|
205 virtual void HandleEventL( |
|
206 TFSMailEvent aEvent, |
|
207 TFSMailMsgId aMailbox, |
|
208 TAny* aParam1, |
|
209 TAny* aParam2, |
|
210 TAny* aParam3 ); |
|
211 |
|
212 private: |
|
213 /** |
|
214 * Constructor |
|
215 * @param aOwner reference to owning class. CpsHandler is just one of |
|
216 * the handlers running in MailServer process. |
|
217 */ |
|
218 CMailCpsHandler( MFSNotificationHandlerMgr& aOwner ); |
|
219 void ConstructL(); |
|
220 |
|
221 // Initialization methods |
|
222 /** |
|
223 * Resets everything |
|
224 */ |
|
225 void Reset(); |
|
226 |
|
227 /** |
|
228 * Initializes native accounts |
|
229 */ |
|
230 void InitializeL(); |
|
231 |
|
232 /** |
|
233 * Initializes external accounts |
|
234 */ |
|
235 void InitializeExternalAccountsL(); |
|
236 |
|
237 // Creation methods |
|
238 /** |
|
239 * Creates an instance of mailboxdetails based on parameters |
|
240 * @param aMailbox mailbox |
|
241 * @return pointer to instance of CMailMailboxDetails. |
|
242 * Caller gets ownership of the returned object. |
|
243 */ |
|
244 CMailMailboxDetails* CreateMailboxDetailsL( CFSMailBox& aMailbox ); |
|
245 |
|
246 /** |
|
247 * Finds mailbox details instance from the local array |
|
248 * @param aMailbox mailbox id |
|
249 * @return pointer to instance of CMailMailboxDetails |
|
250 */ |
|
251 CMailMailboxDetails* FindMailboxDetails( TFSMailMsgId aMailbox ); |
|
252 |
|
253 /** |
|
254 * |
|
255 */ |
|
256 void CMailCpsHandler::UpdateMailboxNameL( const TInt aMailBoxNumber, |
|
257 const TInt aWidgetInstance, |
|
258 const TInt aRowNumber ); |
|
259 |
|
260 /** |
|
261 * Handles publishing of message details |
|
262 */ |
|
263 void UpdateMessagesL( const TInt aMailBoxNumber, |
|
264 const TInt aWidgetInstance, |
|
265 const TInt aMessageNumber, |
|
266 const TInt aFirstRow ); |
|
267 |
|
268 /** |
|
269 * |
|
270 */ |
|
271 void UpdateEmptyMessagesL( const TInt aWidgetInstance, |
|
272 const TInt aFirstRow ); |
|
273 |
|
274 /** |
|
275 * Handles publishing of mailbox icon |
|
276 */ |
|
277 void UpdateMailBoxIconL( const TInt aMailBoxNumber, |
|
278 const TInt aWidgetInstance, |
|
279 const TInt aRowNumber ); |
|
280 |
|
281 /** |
|
282 * Handles publishing of unseen icon |
|
283 */ |
|
284 void UpdateIndicatorIconL( const TInt aMailBoxNumber, |
|
285 const TInt aWidgetInstance, |
|
286 const TInt aRowNumber ); |
|
287 |
|
288 // Event handling subroutines |
|
289 /** |
|
290 * handles new mailbox event |
|
291 * @param aMailbox mailbox id |
|
292 */ |
|
293 void HandleNewMailboxEventL( const TFSMailMsgId aMailbox ); |
|
294 |
|
295 /** |
|
296 * Handles mailbox renamed event. |
|
297 * @param aMailbox mailbox id |
|
298 */ |
|
299 void HandleMailboxRenamedEventL( const TFSMailMsgId aMailbox ); |
|
300 |
|
301 /** |
|
302 * handles mailbox deleted event |
|
303 * @param aMailbox mailbox id |
|
304 */ |
|
305 void HandleMailboxDeletedEventL( const TFSMailMsgId aMailbox ); |
|
306 |
|
307 /** |
|
308 * handles new mail event |
|
309 * @param aMailbox mailbox id |
|
310 * @param aParam1 contains event specific parameters |
|
311 * @param aParam2 contains event specific parameters |
|
312 */ |
|
313 void HandleNewMailEventL( TFSMailMsgId aMailbox, TAny* aParam1, TAny* aParam2 ); |
|
314 |
|
315 /** |
|
316 * handles mail deleted event |
|
317 * @param aMailbox mailbox id |
|
318 * @param aParam1 contains event specific parameters |
|
319 * @param aParam2 contains event specific parameters |
|
320 */ |
|
321 void HandleMailDeletedEventL( TFSMailMsgId aMailbox, TAny* aParam1, TAny* aParam2 ); |
|
322 |
|
323 /** |
|
324 * get count of unseen messages in inbox |
|
325 * @param aMailbox mailbox id |
|
326 */ |
|
327 TInt GetUnseenCountL( TFSMailMsgId aMailbox); |
|
328 |
|
329 /** |
|
330 * Tells if outbox is empty |
|
331 * @param aMailbox mailbox id |
|
332 */ |
|
333 TBool IsOutboxEmptyL( TFSMailMsgId aMailbox); |
|
334 |
|
335 /** |
|
336 * From CFSNotificationHandlerBase |
|
337 * Not used |
|
338 */ |
|
339 virtual void TurnNotificationOn(); |
|
340 |
|
341 /** |
|
342 * From CFSNotificationHandlerBase |
|
343 * Not used |
|
344 */ |
|
345 virtual void TurnNotificationOff(); |
|
346 |
|
347 /** |
|
348 * |
|
349 */ |
|
350 TInt GetMailIcon( CFSMailMessage* aMsg ); |
|
351 |
|
352 /** |
|
353 * |
|
354 */ |
|
355 TInt GetUnreadMsgIcon( CFSMailMessage* aMsg ); |
|
356 |
|
357 /** |
|
358 * |
|
359 */ |
|
360 TInt GetReadMsgIcon( CFSMailMessage* aMsg ); |
|
361 |
|
362 /** |
|
363 * |
|
364 */ |
|
365 TInt GetUnreadCalMsgIcon( CFSMailMessage* aMsg ); |
|
366 |
|
367 /** |
|
368 * |
|
369 */ |
|
370 TInt GetReadCalMsgIcon( CFSMailMessage* aMsg ); |
|
371 |
|
372 /** |
|
373 * |
|
374 */ |
|
375 TBool IsValidDisplayName(const TDesC& aDisplayName); |
|
376 |
|
377 /** |
|
378 * |
|
379 */ |
|
380 void PublishMessageL( TInt aWidgetInstance, CFSMailMessage& aMessage, |
|
381 const TDesC& aSenderName, |
|
382 const TDesC& aSubject, |
|
383 const TDesC& aTime, TInt aFirstRow); |
|
384 |
|
385 /** |
|
386 * Checks if the given message is already know/published |
|
387 * @param aMailbox specifies the mailboxdetails object where duplicate is searched from |
|
388 * @param aMsgId Id of the new message |
|
389 * @return ETrue if duplicate, EFalse if new message |
|
390 */ |
|
391 TBool IsDuplicate( const CMailMailboxDetails& aMailbox, const TFSMailMsgId& aMsgId ); |
|
392 |
|
393 // |
|
394 // Private methods related to 3rd party email widget publishers |
|
395 // |
|
396 /** |
|
397 * Removes all plugin proxies (and plugins) that are not listed in aAccounts |
|
398 * @param aAccounts up-to-date list of external (3rd party) email accounts |
|
399 * that are specified in settings |
|
400 */ |
|
401 void RemoveUnusedPluginsL( RPointerArray<CMailExternalAccount>& aAccounts ); |
|
402 |
|
403 /** |
|
404 * Goes through the array of external accounts and instantiates (newly added) |
|
405 * 3rd party plugins |
|
406 * @param aAccounts up-to-date list of external (3rd party) email accounts |
|
407 * that are specified in settings |
|
408 */ |
|
409 void AddNewPluginsL( RPointerArray<CMailExternalAccount>& aAccounts ); |
|
410 |
|
411 /** |
|
412 * Goes through the array of existing 3rd party plugin (proxies) and |
|
413 * lets them take the accounts given in the param array. |
|
414 * Plugin proxies also update the widget data. |
|
415 * @param aAccounts up-to-date list of external (3rd party) email accounts |
|
416 * that are specified in settings |
|
417 */ |
|
418 void SelectAndUpdateExtAccountsL( RPointerArray<CMailExternalAccount>& aAccounts ); |
|
419 |
|
420 /** |
|
421 * Checks whether aAccounts array has entries relating to plugin with id aPluginId |
|
422 * @param aPluginId 3rd party plugin identifier (implementation uid) |
|
423 * @param aAccounts array of 3rd party email account information |
|
424 * @return true or false |
|
425 */ |
|
426 TBool IsPluginInArray( const TInt aPluginId, RPointerArray<CMailExternalAccount>& aAccounts ); |
|
427 |
|
428 /** |
|
429 * Checks whether aPlugins array has entries relating to plugin with id aPluginId |
|
430 * @param aPluginId 3rd party plugin identifier (implementation uid) |
|
431 * @param aPlugins array of plugin proxies |
|
432 * @return true or false |
|
433 */ |
|
434 TBool IsPluginInArray( const TInt aPluginId, RPointerArray<CMailPluginProxy>& aPlugins ); |
|
435 |
|
436 /** |
|
437 * Goes through iExternalPlugins array and finds correct entry |
|
438 * @param aContentId specifying a widget/account |
|
439 * @return correct plugin proxy instance pointer (ownership not transferred) |
|
440 * if not found, NULL is retuned |
|
441 */ |
|
442 CMailPluginProxy* GetExtPluginL( const TDesC& aContentId ); |
|
443 |
|
444 private: // data |
|
445 CEikonEnv* iEnv; |
|
446 // pointer to liw wrapper that handles actual publishing |
|
447 CMailCpsIf* iLiwIf; |
|
448 // pointer to settings class that handles settings loading and observing logic |
|
449 CMailCpsSettings* iSettings; |
|
450 // local cache of mailbox details |
|
451 RPointerArray<CMailMailboxDetails> iAccountsArray; |
|
452 // array of plugin proxies. One plugin proxy handles one 3rd party plugin and its accounts |
|
453 RPointerArray<CMailPluginProxy> iExternalPlugins; |
|
454 // tells if email wizard is started from widget and it is still running |
|
455 // and to which widget next added account is added. |
|
456 HBufC* iWaitingForNewMailbox; |
|
457 // |
|
458 TFSMailMsgId iWaitingForNewWidget; |
|
459 // |
|
460 CAknGlobalNote* iQuery; |
|
461 // Helper for limiting rate of updates to Homescreen widget |
|
462 CMailCpsUpdateHelper* iUpdateHelper; |
|
463 }; |
|
464 |
|
465 //----------------------------------------------------------------------------- |
|
466 //----------------------------------------------------------------------------- |
|
467 |
|
468 // Helper class for limiting rate of updates to Homescreen widget |
|
469 |
|
470 // Don't make widget updates more often than this delay (milliseconds) |
|
471 #define KMailCpsHandlerUpdateDelay 1000 |
|
472 |
|
473 class CMailCpsUpdateHelper : public CTimer |
|
474 { |
|
475 public: |
|
476 static CMailCpsUpdateHelper* NewLC( CMailCpsHandler *aHandler ); |
|
477 static CMailCpsUpdateHelper* NewL( CMailCpsHandler *aHandler ); |
|
478 |
|
479 virtual ~CMailCpsUpdateHelper(); |
|
480 |
|
481 // Notify that Homescreen widget(s) should be updated |
|
482 void UpdateL(); |
|
483 |
|
484 protected: |
|
485 void ConstructL(); |
|
486 virtual void RunL(); |
|
487 TInt RunError( TInt aError ); |
|
488 |
|
489 private: |
|
490 CMailCpsUpdateHelper( CMailCpsHandler *aHandler ); |
|
491 |
|
492 // Performs the update, resets the timer, etc. |
|
493 void DoUpdateL(); |
|
494 |
|
495 // Handler to use to do updates (not owned) |
|
496 CMailCpsHandler *iCpsHandler; |
|
497 // Whether or not an update is pending |
|
498 TBool iPending; |
|
499 }; |
|
500 |
|
501 |
|
502 #endif //__CMAILCPSHANDLER_H__ |