|
1 /* |
|
2 * Copyright (c) 2004 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: Defines class CNcnNotifApiObserver. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CNCNNOTIFAPIOBSERVER_H |
|
21 #define CNCNNOTIFAPIOBSERVER_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <msvapi.h> |
|
26 #include "MNcnNotificationObserver.h" |
|
27 #include "MNcnMsvSessionHandlerObserver.h" |
|
28 #include "NcnBaseTimer.h" |
|
29 |
|
30 // FORWARD DECLARATIONS |
|
31 class CNcnModelBase; |
|
32 class CMsvSession; |
|
33 class CNcnTimer; |
|
34 |
|
35 // CLASS DECLARATION |
|
36 |
|
37 /** |
|
38 * Observes if there are any messages in any of remote email boxes. |
|
39 * This version supports NCN Notification API. |
|
40 */ |
|
41 class CNcnNotifApiObserver : public CBase, |
|
42 public MNcnNotificationObserver, |
|
43 public MNcnMsvSessionHandlerObserver, |
|
44 public MNcnTimer |
|
45 { |
|
46 |
|
47 public: // Constructors and destructor |
|
48 |
|
49 /** |
|
50 * Two-phased constructor. |
|
51 */ |
|
52 static CNcnNotifApiObserver* NewL( CNcnModelBase& aModel ); |
|
53 |
|
54 /** |
|
55 * Destructor. |
|
56 */ |
|
57 virtual ~CNcnNotifApiObserver(); |
|
58 |
|
59 public: // New methods |
|
60 |
|
61 /** |
|
62 * Handles new email entries from msv. Updates the count |
|
63 * on appropriate mailbox. |
|
64 * @param aEntry EMail msv entry. |
|
65 */ |
|
66 void HandleNewEMailMsvEntryL( const TMsvEntry& aEntry ); |
|
67 |
|
68 /** |
|
69 * Handles deleted email entries from msv. Updates the count |
|
70 * on appropriate mailbox. |
|
71 * @param aEntry EMail msv entry id. |
|
72 */ |
|
73 void HandleDeletedEMailMsvEntryL( const TMsvId& aEntryId ); |
|
74 |
|
75 private: // From MNcnTimer |
|
76 |
|
77 void NcnTimerCompleted(); |
|
78 |
|
79 private: // From MNcnMsvSessionHandlerObserver |
|
80 |
|
81 void HandleMsvSessionReadyL( CMsvSession& aMsvSession ); |
|
82 void HandleMsvSessionClosedL(); |
|
83 void HandleMsvEntryCreatedL( const TMsvId& aMsvId ); |
|
84 void HandleMsvEntryDeletedL( const TMsvId& aMsvId ); |
|
85 void HandleMsvMediaChangedL( const TDriveNumber& aDriveNumber ); |
|
86 void HandleMsvMediaAvailableL( const TDriveNumber& aDriveNumber ); |
|
87 void HandleMsvMediaUnavailableL(); |
|
88 |
|
89 private: // From MNcnNoficationObserver |
|
90 |
|
91 void HandleNewInternalMessagesL( |
|
92 const TNcnNotifMessageType aType ); |
|
93 |
|
94 void HandleNewInternalMessagesL( |
|
95 const TNcnNotifMessageType aType, |
|
96 const TMsvId& aMailBox, |
|
97 const MDesCArray& aInfo ); |
|
98 |
|
99 void HandleInternalMarkUnreadL( |
|
100 const TNcnUnreadRequestType aRequest ); |
|
101 |
|
102 void HandleInternalMarkUnreadL( |
|
103 const TNcnUnreadRequestType aRequest, |
|
104 const TMsvId& aMailbox ); |
|
105 |
|
106 void HandleNewMessagesL( |
|
107 const TMsvId& aMailBox, |
|
108 const MNcnNotification::TIndicationType aIndicationType, |
|
109 const MDesCArray& aInfo ); |
|
110 |
|
111 void HandleMarkUnreadL( const TMsvId& aMailBox ); |
|
112 |
|
113 private: // New functions |
|
114 |
|
115 /** |
|
116 * Returns ETrue if entry is an email entry. |
|
117 */ |
|
118 TBool IsEMailEntry( const TMsvEntry& aEntry ); |
|
119 |
|
120 /** |
|
121 * Internal helper class for new mail count book-keeping. |
|
122 * Used to allow storing of mailbox status in an array. |
|
123 */ |
|
124 class TNcnMailBoxStatus |
|
125 { |
|
126 public : |
|
127 |
|
128 TNcnMailBoxStatus( TMsvId aMailBox ); |
|
129 |
|
130 static TInt Compare( const TNcnMailBoxStatus& aFirst, |
|
131 const TNcnMailBoxStatus& aSecond ); |
|
132 |
|
133 static TBool Match( const TNcnMailBoxStatus& aFirst, |
|
134 const TNcnMailBoxStatus& Second ); |
|
135 |
|
136 public: |
|
137 |
|
138 /** |
|
139 * MsvId of the mailbox. |
|
140 */ |
|
141 TMsvId iMailBox; |
|
142 |
|
143 /** |
|
144 * MTM of the mailbox. Eg. Pop3, Imap etc. |
|
145 */ |
|
146 TUid iMTMType; |
|
147 |
|
148 /** |
|
149 * Technology type of the mailbox. |
|
150 */ |
|
151 TUid iMailBoxTechnologyType; |
|
152 |
|
153 /** |
|
154 * Amount of new emails at the time of the last NewMessages call |
|
155 * on mailbox. |
|
156 */ |
|
157 TInt iPublishedNewEmailCount; |
|
158 |
|
159 /** |
|
160 * Highest email msv id so far in mailbox. |
|
161 */ |
|
162 TMsvId iHighestEMailMsvId; |
|
163 |
|
164 /** |
|
165 * Highest IMAP uid id so far in mailbox. |
|
166 */ |
|
167 TUint32 iHighestIMAPId; |
|
168 |
|
169 /** |
|
170 * Time when the latest message has arrived to this inbox |
|
171 */ |
|
172 TTime iLatestMessageArrival; |
|
173 |
|
174 /** |
|
175 * Highest MsvId at the time of the last MarkUnread call |
|
176 * on mailbox. |
|
177 */ |
|
178 TMsvId iUnreadCheckpointMsvId; |
|
179 |
|
180 /** |
|
181 * Highest MsvId at the time of the last NewMessages call |
|
182 * on mailbox. |
|
183 */ |
|
184 TMsvId iPublishedCheckpointMsvId; |
|
185 |
|
186 /** |
|
187 * Highest IMAP uid at the time of the last NewMessages call |
|
188 * on mailbox. This is IMAP specific variable. The IMAP |
|
189 * messages come to the terminal in ID order. |
|
190 * In boot-up this is set to highest IMAP id in the box |
|
191 */ |
|
192 TUint32 iPublishedCheckpointIMAPId; |
|
193 |
|
194 /** |
|
195 * Timestamp at the time of the last NewMessages call |
|
196 * on mailbox. This is used for non IMAP messages (POP, SyncMl etc.) |
|
197 * In boot-up this is set to latest time stamp in the box |
|
198 */ |
|
199 TTime iPublishedCheckpointTimeStamp; |
|
200 |
|
201 /** |
|
202 * Array containing the id's of messages considered new |
|
203 * in the box. |
|
204 */ |
|
205 RArray<TMsvId> iNewMessageIds; |
|
206 |
|
207 /** |
|
208 * Refresh request status |
|
209 */ |
|
210 TBool iRefreshRequested; |
|
211 |
|
212 /** |
|
213 * Notification status. |
|
214 */ |
|
215 TBool iNotified; |
|
216 |
|
217 /** |
|
218 * Mail boxes can use specific notification parameters |
|
219 * If TRUE notification by icon is required. Default TRUE |
|
220 */ |
|
221 TBool iIcon; |
|
222 |
|
223 /** |
|
224 * Mail boxes can use specific notification parameters |
|
225 * If TRUE notification by tone is required. Default TRUE |
|
226 */ |
|
227 TBool iTone; |
|
228 |
|
229 /** |
|
230 * Mail boxes can use specific notification parameters |
|
231 * If TRUE notification by note is required. Default TRUE |
|
232 */ |
|
233 TBool iNote; |
|
234 |
|
235 /** Mail box will request for show icon if iShowIcon is true. |
|
236 * Default value will be True |
|
237 * This flag will be set to true if new mail is received. |
|
238 * This flag will be set to flase, if mce sends mailbox oened |
|
239 * event. |
|
240 * If iShowIcon is true |
|
241 * than mailbox will request for icon notification |
|
242 * and iShowIcon is False |
|
243 * Than mailbox will not request for icon notification, |
|
244 * because mailbox is opened by user in MCE. Mce inform |
|
245 * opening of mailbox event to respective mailbox in ncn list. |
|
246 */ |
|
247 TBool iShowIcon; |
|
248 }; |
|
249 |
|
250 /** |
|
251 * Loads all registered mail boxes to status array. |
|
252 * @param aMsvSession Current msv session. |
|
253 */ |
|
254 void LoadMailboxesL( CMsvSession& aMsvSession ); |
|
255 |
|
256 /** |
|
257 * Returns ETrue if technology type is a mail technology type. |
|
258 * @return ETrue if technology type is a mail technology type. |
|
259 */ |
|
260 TBool IsMailTechnologyType( const TUid& aTechnologyType ); |
|
261 |
|
262 /** |
|
263 * Adds mailboxes of given mtm type to iMailBoxStatusArray. |
|
264 * @param aMtmType MTM of the mailbox. |
|
265 * @param aTechnologyType Technology type of the mailbox. |
|
266 * @param aMsvSession Current msv session. |
|
267 */ |
|
268 void AddBoxesToStatusArrayL( const TUid& aMtmType, const TUid& aTechnologyType, CMsvSession& aMsvSession ); |
|
269 |
|
270 /** |
|
271 * Adds a mail box to status array. |
|
272 * @param aMsvId MsvId of the mail box. |
|
273 * @param aMtmType MTM of the mailbox. |
|
274 * @param aTechnologyType Technology type of the mail box. |
|
275 */ |
|
276 void AddMailBoxL( const TMsvId& aMsvId, const TUid& aMtmType, const TUid& aTechnologyType ); |
|
277 |
|
278 /** |
|
279 * Removes a mail box to status array. |
|
280 * @param aMsvId MsvId of the mail box. |
|
281 * @param aMtm Mtm of the mail box. |
|
282 */ |
|
283 void RemoveMailBox( const TMsvId& aMsvId ); |
|
284 |
|
285 /** |
|
286 * Updates the amount of total new emails based on iMailBoxStatusArray. |
|
287 * Note: This method does not query message server. |
|
288 */ |
|
289 void UpdateTotalNewEmails(); |
|
290 |
|
291 /** |
|
292 * Updates the notification to reflect the current state of |
|
293 * new email count. Update is not done if change has not happened |
|
294 * @param aForceUpdate Forces the update of the notification |
|
295 * @param aIcon Notifies with icon |
|
296 * @param aTone Notifies with tone |
|
297 * @param aNote Notifies with note |
|
298 */ |
|
299 void UpdateNotification( TBool aForceUpdate = EFalse, |
|
300 TBool aIcon = ETrue, |
|
301 TBool aTone = ETrue, |
|
302 TBool aNote = ETrue); |
|
303 |
|
304 /** |
|
305 * Returns the Mailbox with specified id. Leaves with KErrNotFound if no |
|
306 * such mailbox is found (in local structure). |
|
307 * @param aId Mailbox id. |
|
308 */ |
|
309 TNcnMailBoxStatus& MailBoxStatusL( const TMsvId& aId ); |
|
310 |
|
311 /** |
|
312 * Checks the mailbox's "new email indicator" setting. |
|
313 * Setting is only available in IMAP/POP/SyncMl boxes |
|
314 * and not in 3rd party boxes. |
|
315 * @param aMailboxStatus the queried mail box |
|
316 * @Leave KErrNotSupported if the mail box does not support this setting |
|
317 * @return ETrue if "new email indicator" setting is on |
|
318 */ |
|
319 TBool NewEmailIndicatorsSetL( const TNcnMailBoxStatus& aMailboxStatus ); |
|
320 |
|
321 /** |
|
322 * Returns message server entry with specified service id. |
|
323 * |
|
324 * Method leaves with KErrNotSupported if supplied id does not |
|
325 * point to a service entry. |
|
326 * |
|
327 * @param aServiceId Service id. |
|
328 * @return Message server entry. |
|
329 */ |
|
330 CMsvEntry* ServiceEntryL( const TMsvId& aServiceId ); |
|
331 |
|
332 /** |
|
333 * Returns message server entry with specified service id and |
|
334 * puts it into the cleanup stack. |
|
335 * |
|
336 * Method leaves with KErrNotSupported if supplied id does not |
|
337 * point to a service entry. |
|
338 * |
|
339 * @param aServiceId Service id. |
|
340 * @return Message server entry. |
|
341 */ |
|
342 CMsvEntry* ServiceEntryLC( const TMsvId& aServiceId ); |
|
343 |
|
344 /** |
|
345 * Marks the mailbox unread. This resets the amount of new |
|
346 * emails, both released and actual. |
|
347 * @param aId Id of the mailbox. |
|
348 */ |
|
349 void MarkUnreadL( const TMsvId& aId ); |
|
350 |
|
351 /** |
|
352 * Marks all mailboxes unread. |
|
353 */ |
|
354 void MarkAllUnread( ); |
|
355 |
|
356 /** |
|
357 * Publishes mailboxes new email amount. All new emails that |
|
358 * have not been published are added to the amount of |
|
359 * new emails. Note that this method does not update the notification, |
|
360 * use UpdateNotification. |
|
361 * @param aId Id of the mailbox. |
|
362 */ |
|
363 void PublishNewMessagesL( const TMsvId& aId ); |
|
364 |
|
365 /** |
|
366 * Publishes new email amounts in all mailboxes. |
|
367 * Note that this method does not update the notification, |
|
368 * use UpdateNotification. |
|
369 */ |
|
370 void PublishAllNewMessages( ); |
|
371 |
|
372 /** |
|
373 * Browse through the mailbox's messages and find highest |
|
374 * MsvId, ImapId and latest time stamp that messages have. |
|
375 * Defaults values to 0. |
|
376 * @param aId Id of the mailbox. |
|
377 * @param aHighestMsvId Highest message MsvId that box contains |
|
378 * @param aHighestImapId Highest message ImapId that box contains |
|
379 * @param aLatestTimeStamp Latest message time stamp that box contains |
|
380 */ |
|
381 void FindHighest_MsvId_ImapId_LatestTime( const TMsvId& aId, |
|
382 TMsvId& aHighestMsvId, |
|
383 TUint32& aHighestImapId, |
|
384 TTime& aLatestTimeStamp ); |
|
385 |
|
386 /** |
|
387 * Browse through the mailbox's messages and find highest |
|
388 * MsvId, ImapId and latest time stamp that messages have. |
|
389 * Values should be 0 when the method is used. |
|
390 * @param aId Id of the mailbox. |
|
391 * @param aHighestMsvId Highest message MsvId that box contains |
|
392 * @param aHighestImapId Highest message ImapId that box contains |
|
393 * @param aLatestTimeStamp Latest message time stamp that box contains |
|
394 */ |
|
395 void FindHighest_MsvId_ImapId_LatestTimeL( const TMsvId& aId, |
|
396 TMsvId& aHighestMsvId, |
|
397 TUint32& aHighestImapId, |
|
398 TTime& aLatestTimeStamp ); |
|
399 |
|
400 /** |
|
401 * Returns mail boxes MTM and Technolgy type |
|
402 * @param aId Id of the entry. |
|
403 * @param aMtmType The MTM type |
|
404 * @param aTechnologyType The technolgy type |
|
405 * @return System wide error code |
|
406 */ |
|
407 TInt GetMailBoxesAttributesL( const TMsvId& aMsvId, TUid& aMtmType, TUid& aTechnologyType ); |
|
408 |
|
409 /** |
|
410 * Makes a check for this entry and determines if it requires notification. |
|
411 * Phone keeps a certain amount of messages in the terminal and when one of |
|
412 * those messages is deleted it retrieves another one from the mail box. |
|
413 * Sometimes it retrieves a message that has already been notified so it |
|
414 * requires no notification. In this method we try to identify those messages. |
|
415 * In IMAP boxes the messages have a special id, this is in increasing order. |
|
416 * We know the highest id at the time of notification and do not notify of messages |
|
417 * that have lower id. In POP, SyncMl etc. boxes we do this same comparison using |
|
418 * time stamps. We only notify messages that have newer timestamp than last notification. |
|
419 * Timestamp comparison must be done using UTC time because of the time zones. |
|
420 * @param aMailbox The mailbox that contains this message |
|
421 * @param aEntry The entry it self. |
|
422 * @return True if notification is required |
|
423 */ |
|
424 TBool IsNotificationNeededForThisMessageL( const TNcnMailBoxStatus& aMailbox, const TMsvEntry& aEntry ); |
|
425 |
|
426 /** |
|
427 * Takes the mailbox and determines the used notifications for it. |
|
428 * 3rs party mailboxes give the notifications in the API, but IMAP |
|
429 * POP and SynvMl do not. For S60 mailbox's ncnlist will read |
|
430 * "new mail indicator" setting and determines the used notification |
|
431 * based on the settings value. |
|
432 * @param aMailbox updated mailbox status entity |
|
433 * @leave KErrNotSupported given mail box is not IMAP/POP/SyncMl |
|
434 * @leave System wide error code |
|
435 */ |
|
436 void UpdateS60MailBoxNotificationAttributesL( TNcnMailBoxStatus& aMailbox ); |
|
437 |
|
438 /** |
|
439 * A small helper method. Takes the desired indicators as TIndicationType |
|
440 * and converts it to separate booleans for tone, note and icon |
|
441 * Method updates the values to the mailbox |
|
442 * @param aMailbox updated mailbox status entity |
|
443 * @param aIndicationType The desired indication type |
|
444 */ |
|
445 void UpdateMailBoxesNotifications( TNcnMailBoxStatus& aMailbox, const TInt& aIndicationType ); |
|
446 |
|
447 private: // Constructors and destructor |
|
448 |
|
449 /** |
|
450 * C++ default constructor. |
|
451 */ |
|
452 CNcnNotifApiObserver( CNcnModelBase& aModel ); |
|
453 |
|
454 /** |
|
455 * By default Symbian OS constructor is private. |
|
456 */ |
|
457 void ConstructL(); |
|
458 |
|
459 /** |
|
460 * Returns ETrue, if aEntry is in SyncML boxes Sent folder |
|
461 */ |
|
462 TBool IsSyncMLEntryInSentFolderL( const TMsvEntry& aEntry ); |
|
463 |
|
464 private: // Data |
|
465 |
|
466 // Array containing mailbox 1ids and number of new mails in each of them. |
|
467 RArray<TNcnMailBoxStatus> iMailBoxStatusArray; |
|
468 |
|
469 // Sum of all mailboxes' new mail counts |
|
470 TInt iTotalNewMailCount; |
|
471 |
|
472 // Last notified new mail count |
|
473 TInt iNotifiedNewMailCount; |
|
474 |
|
475 // Not own, pointer to the event monitor object. |
|
476 CNcnModelBase& iModel; |
|
477 |
|
478 // Timer instance. Owned. |
|
479 CNcnTimer* iTimer; |
|
480 |
|
481 //Reference to msv session. Not owned |
|
482 CMsvSession* iMsvSession; |
|
483 }; |
|
484 |
|
485 #endif // CNCNNOTIFAPIOBSERVER_H |
|
486 |
|
487 // End of File |