|
1 /* |
|
2 * Copyright (c) 2009 - 2010 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 CMailMailboxDetails. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <cmailhandlerplugin.mbg> // icons |
|
19 #include <StringLoader.h> |
|
20 #include <emailwidget.rsg> |
|
21 |
|
22 #include <memaildata.h> |
|
23 #include <emailobserverplugin.h> |
|
24 #include <memailmailboxdata.h> |
|
25 #include <memailapplaunchdata.h> |
|
26 |
|
27 #include "emailtrace.h" |
|
28 #include "cmailpluginproxy.h" |
|
29 #include "cmailexternalaccount.h" |
|
30 #include "cmailcpsif.h" |
|
31 #include "cmailcpsutils.h" |
|
32 |
|
33 using namespace EmailInterface; |
|
34 |
|
35 // --------------------------------------------------------- |
|
36 // CMailPluginProxy::NewL |
|
37 // --------------------------------------------------------- |
|
38 // |
|
39 CMailPluginProxy* CMailPluginProxy::NewL( |
|
40 const TInt aPluginId, |
|
41 CMailCpsIf& aPublisher ) |
|
42 { |
|
43 FUNC_LOG; |
|
44 CMailPluginProxy* self = new(ELeave) CMailPluginProxy( aPluginId, aPublisher ); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------- |
|
52 // CMailPluginProxy::CMailPluginProxy |
|
53 // --------------------------------------------------------- |
|
54 // |
|
55 CMailPluginProxy::CMailPluginProxy( |
|
56 const TInt aPluginId, |
|
57 CMailCpsIf& aPublisher ) : |
|
58 iPluginId( aPluginId ), |
|
59 iPublisher( aPublisher ) |
|
60 { |
|
61 FUNC_LOG; |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------- |
|
65 // CMailPluginProxy::~CMailPluginProxy |
|
66 // --------------------------------------------------------- |
|
67 // |
|
68 CMailPluginProxy::~CMailPluginProxy() |
|
69 { |
|
70 FUNC_LOG; |
|
71 delete iPlugin; |
|
72 TRAP_IGNORE( RemoveAccountsL() ); |
|
73 iAccounts.ResetAndDestroy(); |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------- |
|
77 // CMailPluginProxy::ConstructL |
|
78 // --------------------------------------------------------- |
|
79 // |
|
80 void CMailPluginProxy::ConstructL() |
|
81 { |
|
82 FUNC_LOG; |
|
83 TUid implUid = TUid::Uid( iPluginId ); |
|
84 iPlugin = EmailInterface::CEmailObserverPlugin::NewL( implUid, this ); |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------- |
|
88 // CMailPluginProxy::EmailObserverEvent |
|
89 // --------------------------------------------------------- |
|
90 // |
|
91 void CMailPluginProxy::EmailObserverEvent( MEmailData& /*aData*/ ) |
|
92 { |
|
93 FUNC_LOG; |
|
94 TRAP_IGNORE( PublishAccountsL() ); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------- |
|
98 // CMailPluginProxy::PluginId |
|
99 // --------------------------------------------------------- |
|
100 // |
|
101 TInt CMailPluginProxy::PluginId() |
|
102 { |
|
103 FUNC_LOG; |
|
104 return iPluginId; |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------- |
|
108 // CMailPluginProxy::RemoveAccountsL |
|
109 // --------------------------------------------------------- |
|
110 // |
|
111 void CMailPluginProxy::RemoveAccountsL() |
|
112 { |
|
113 FUNC_LOG; |
|
114 while ( iAccounts.Count() ) |
|
115 { |
|
116 delete iAccounts[0]; |
|
117 iAccounts.Remove(0); |
|
118 } |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------- |
|
122 // CMailPluginProxy::ResetAccountL |
|
123 // --------------------------------------------------------- |
|
124 // |
|
125 void CMailPluginProxy::ResetAccountL( const TDesC& aContentId ) |
|
126 { |
|
127 FUNC_LOG; |
|
128 TInt instId = ResolveWidgetInstance( aContentId ); |
|
129 if ( instId >= 0 ) |
|
130 { |
|
131 TFSMailMsgId dummy; |
|
132 iPublisher.PublishMailboxIconL( instId, KNullDesC ); |
|
133 iPublisher.PublishActiveMailboxNameL( instId, 1, KNullDesC); |
|
134 iPublisher.PublishIndicatorIconL( instId, 1, KNullIcon ); |
|
135 |
|
136 ResetMessageRowL( instId, 2 ); // 1st message row |
|
137 ResetMessageRowL( instId, 3 ); // 2nd.. |
|
138 } |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------- |
|
142 // CMailPluginProxy::ResetMessageRowL |
|
143 // --------------------------------------------------------- |
|
144 // |
|
145 void CMailPluginProxy::ResetMessageRowL( const TInt aWidgetInstanceId, const TInt aRow ) |
|
146 { |
|
147 FUNC_LOG; |
|
148 TFSMailMsgId dummy; |
|
149 iPublisher.PublishMailboxIconL( aWidgetInstanceId, aRow, KNullIcon, dummy ); |
|
150 iPublisher.PublishMailDetailL( aWidgetInstanceId, aRow, KNullDesC, ESender ); |
|
151 iPublisher.PublishMailDetailL( aWidgetInstanceId, aRow, KNullDesC, ETime ); |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------- |
|
155 // CMailPluginProxy::SelectOwnAccountsL |
|
156 // --------------------------------------------------------- |
|
157 // |
|
158 void CMailPluginProxy::SelectOwnAccountsL( RPointerArray<CMailExternalAccount>& aAccounts ) |
|
159 { |
|
160 FUNC_LOG; |
|
161 for ( TInt i = 0; i < aAccounts.Count(); i++ ) |
|
162 { |
|
163 if ( aAccounts[i]->PluginId() == iPluginId ) |
|
164 { |
|
165 // own account, take ownership |
|
166 iAccounts.AppendL( aAccounts[i] ); |
|
167 aAccounts.Remove(i); |
|
168 i--; // update loop indexing |
|
169 } |
|
170 } |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------- |
|
174 // CMailPluginProxy::PublishAccountsL |
|
175 // --------------------------------------------------------- |
|
176 // |
|
177 void CMailPluginProxy::PublishAccountsL() |
|
178 { |
|
179 FUNC_LOG; |
|
180 // Loops through all external accounts of this plugin (that are configured |
|
181 // to be published), and calls publish on them |
|
182 for ( TInt i = 0; i < iAccounts.Count(); i++ ) |
|
183 { |
|
184 TInt instId = ResolveWidgetInstance( iAccounts[i]->ContentId() ); |
|
185 if ( instId != KErrNotFound && iPublisher.AllowedToPublish( instId ) ) |
|
186 { |
|
187 PublishAccountL( instId, iAccounts[i]->MailboxId() ); |
|
188 } |
|
189 else |
|
190 { |
|
191 INFO("Correct widget not found, not publishing.."); |
|
192 } |
|
193 } |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------- |
|
197 // CMailPluginProxy::PublishAccountL |
|
198 // --------------------------------------------------------- |
|
199 // |
|
200 void CMailPluginProxy::PublishAccountL( const TInt aWidgetInstanceId, const TInt aMailboxId ) |
|
201 { |
|
202 FUNC_LOG; |
|
203 // Loops through plugin's mailbox array and finds matching mailbox |
|
204 MEmailData& data( iPlugin->EmailDataL() ); |
|
205 RPointerArray<MMailboxData> mailboxes = data.MailboxesL(); |
|
206 for ( TInt j = 0; j < mailboxes.Count(); j++ ) |
|
207 { |
|
208 if ( mailboxes[j]->MailboxId() == aMailboxId ) |
|
209 { |
|
210 PublishAccountL( aWidgetInstanceId, *(mailboxes[j]) ); |
|
211 } |
|
212 } |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------- |
|
216 // CMailPluginProxy::PublishAccountL |
|
217 // --------------------------------------------------------- |
|
218 // |
|
219 void CMailPluginProxy::PublishAccountL( const TInt aWidgetInstanceId, MMailboxData& aMailboxData ) |
|
220 { |
|
221 FUNC_LOG; |
|
222 // 1st row |
|
223 PublishFirstRowL( aWidgetInstanceId, aMailboxData ); |
|
224 |
|
225 // message rows |
|
226 TInt msgCount = aMailboxData.LatestMessagesL().Count(); |
|
227 for ( TInt i = 0; i < KMaxMsgCount; i++ ) |
|
228 { |
|
229 if ( msgCount > i ) |
|
230 { |
|
231 // enough messages for this row |
|
232 PublishMessageRowL( aWidgetInstanceId, *(aMailboxData.LatestMessagesL()[i]), i+2 ); // message-rows start from 2 |
|
233 } |
|
234 else |
|
235 { |
|
236 // make sure this row is empty |
|
237 TFSMailMsgId dummy; |
|
238 iPublisher.PublishMailboxIconL( aWidgetInstanceId, i+2, KNullIcon, dummy ); |
|
239 iPublisher.PublishMailDetailL( aWidgetInstanceId, i+2, KNullDesC, ESender ); |
|
240 iPublisher.PublishMailDetailL( aWidgetInstanceId, i+2, KNullDesC, ESubject ); |
|
241 iPublisher.PublishMailDetailL( aWidgetInstanceId, i+2, KNullDesC, ETime ); |
|
242 } |
|
243 } |
|
244 } |
|
245 |
|
246 // --------------------------------------------------------- |
|
247 // CMailPluginProxy::PublishMessageL |
|
248 // --------------------------------------------------------- |
|
249 // |
|
250 void CMailPluginProxy::PublishMessageRowL( const TInt aWidgetInstanceId, EmailInterface::MMessageData& aMessageData, const TInt aRow ) |
|
251 { |
|
252 FUNC_LOG; |
|
253 TFSMailMsgId dummy; |
|
254 TInt iconId = TMailCpsUtils::ResolveIcon( |
|
255 aMessageData.Unread(), |
|
256 aMessageData.CalendarMsg(), |
|
257 aMessageData.Attachments(), |
|
258 aMessageData.Priority(), |
|
259 aMessageData.Replied(), |
|
260 aMessageData.Forwarded() ); |
|
261 |
|
262 iPublisher.PublishMailboxIconL( aWidgetInstanceId, aRow, iconId, dummy ); |
|
263 iPublisher.PublishMailDetailL( aWidgetInstanceId, aRow, aMessageData.Sender(), ESender ); |
|
264 iPublisher.PublishMailDetailL( aWidgetInstanceId, aRow, aMessageData.Subject(), ESubject ); |
|
265 HBufC* timeString = CMailCpsHandler::GetMessageTimeStringL( aMessageData.TimeStamp() ); |
|
266 CleanupStack::PushL( timeString ); |
|
267 iPublisher.PublishMailDetailL( aWidgetInstanceId, aRow, *timeString, ETime ); |
|
268 CleanupStack::PopAndDestroy( timeString ); |
|
269 } |
|
270 |
|
271 // --------------------------------------------------------- |
|
272 // CMailPluginProxy::PublishFirstRowL |
|
273 // --------------------------------------------------------- |
|
274 // |
|
275 void CMailPluginProxy::PublishFirstRowL( const TInt aWidgetInstanceId, EmailInterface::MMailboxData& aMailboxData ) |
|
276 { |
|
277 FUNC_LOG; |
|
278 HBufC* firstLineText = ConstructMailboxNameWithMessageCountLC( aMailboxData ); |
|
279 TInt indicator = ResolveIndicatorIcon( aMailboxData ); |
|
280 iPublisher.PublishMailboxIconL( aWidgetInstanceId, aMailboxData.BrandingIcon() ); |
|
281 iPublisher.PublishMailboxNameL( aWidgetInstanceId, *firstLineText, KTriggerEmailUi8 ); |
|
282 iPublisher.PublishIndicatorIconL( aWidgetInstanceId, 1, indicator ); |
|
283 CleanupStack::PopAndDestroy( firstLineText ); |
|
284 } |
|
285 |
|
286 // --------------------------------------------------------- |
|
287 // CMailPluginProxy::ConstructMailboxNameWithMessageCountLC |
|
288 // --------------------------------------------------------- |
|
289 // |
|
290 HBufC* CMailPluginProxy::ConstructMailboxNameWithMessageCountLC( MMailboxData& aMailboxData ) |
|
291 { |
|
292 FUNC_LOG; |
|
293 HBufC* mailboxAndCount( NULL ); |
|
294 TInt unreadCount = UnreadCountL( aMailboxData ); |
|
295 if ( unreadCount > 0 ) |
|
296 { |
|
297 // Arrays must be used when loc string contains indexed parameters |
|
298 CDesCArrayFlat* strings = new CDesCArrayFlat( 1 ); |
|
299 CleanupStack::PushL( strings ); |
|
300 strings->AppendL( aMailboxData.Name() ); // replace "%0U" with mailbox name |
|
301 |
|
302 CArrayFix<TInt>* ints = new(ELeave) CArrayFixFlat<TInt>( 1 ); |
|
303 CleanupStack::PushL( ints ); |
|
304 ints->AppendL( unreadCount ); // replace "%1N" with number of unread messages |
|
305 |
|
306 mailboxAndCount = StringLoader::LoadL( R_EMAILWIDGET_TEXT_MAILBOX_AND_MAILCOUNT, *strings, *ints ); |
|
307 CleanupStack::PopAndDestroy(ints); |
|
308 CleanupStack::PopAndDestroy(strings); |
|
309 CleanupStack::PushL( mailboxAndCount ); |
|
310 } |
|
311 else |
|
312 { |
|
313 // if 0 messages, first line text is pure mailbox name |
|
314 mailboxAndCount = aMailboxData.Name().AllocLC(); |
|
315 } |
|
316 INFO_1("first line: %S", mailboxAndCount); |
|
317 return mailboxAndCount; |
|
318 } |
|
319 |
|
320 // --------------------------------------------------------- |
|
321 // CMailPluginProxy::UnreadCountL |
|
322 // --------------------------------------------------------- |
|
323 // |
|
324 TInt CMailPluginProxy::UnreadCountL( EmailInterface::MMailboxData& aMailboxData ) |
|
325 { |
|
326 FUNC_LOG; |
|
327 TInt count( 0 ); |
|
328 for ( TInt i = 0; i < aMailboxData.LatestMessagesL().Count(); i++ ) |
|
329 { |
|
330 if ( aMailboxData.LatestMessagesL()[i]->Unread() ) |
|
331 { |
|
332 count++; |
|
333 } |
|
334 } |
|
335 return count; |
|
336 } |
|
337 |
|
338 // --------------------------------------------------------------------------- |
|
339 // CMailPluginProxy::ResolveIndicatorIcon |
|
340 // --------------------------------------------------------------------------- |
|
341 // |
|
342 TInt CMailPluginProxy::ResolveIndicatorIcon( EmailInterface::MMailboxData& aMailboxData ) |
|
343 { |
|
344 FUNC_LOG; |
|
345 TInt indicator( 0 ); |
|
346 if ( aMailboxData.Unseen() ) |
|
347 { |
|
348 indicator = EMbmCmailhandlerpluginQgn_indi_cmail_unseen_msg; |
|
349 } |
|
350 else if ( !aMailboxData.IsOutboxEmpty() ) |
|
351 { |
|
352 indicator = EMbmCmailhandlerpluginQgn_indi_cmail_outbox_msg; |
|
353 } |
|
354 else |
|
355 { |
|
356 indicator = KNullIcon; |
|
357 } |
|
358 return indicator; |
|
359 } |
|
360 |
|
361 // --------------------------------------------------------------------------- |
|
362 // CMailPluginProxy::ResolveWidgetInstance |
|
363 // --------------------------------------------------------------------------- |
|
364 // |
|
365 TInt CMailPluginProxy::ResolveWidgetInstance( const TDesC& aContentId ) |
|
366 { |
|
367 FUNC_LOG; |
|
368 TInt id( KErrNotFound ); |
|
369 for ( TInt i = 0; i < iPublisher.iInstIdList.Count(); i++ ) |
|
370 { |
|
371 if ( aContentId.Compare( iPublisher.iInstIdList[i].iCid ) == 0 ) |
|
372 { |
|
373 id = i; |
|
374 } |
|
375 } |
|
376 return id; |
|
377 } |
|
378 |
|
379 // --------------------------------------------------------------------------- |
|
380 // CMailPluginProxy::HasAccount |
|
381 // --------------------------------------------------------------------------- |
|
382 // |
|
383 TBool CMailPluginProxy::HasAccount( const TDesC& aContentId ) |
|
384 { |
|
385 FUNC_LOG; |
|
386 TBool found( EFalse ); |
|
387 for ( TInt i = 0; i < iAccounts.Count(); i++ ) |
|
388 { |
|
389 if ( !( iAccounts[i]->ContentId().Compare( aContentId ) ) ) |
|
390 { |
|
391 found = ETrue; |
|
392 } |
|
393 } |
|
394 return found; |
|
395 } |
|
396 |
|
397 // --------------------------------------------------------------------------- |
|
398 // CMailPluginProxy::LaunchExtAppL |
|
399 // --------------------------------------------------------------------------- |
|
400 // |
|
401 void CMailPluginProxy::LaunchExtAppL( const TDesC& aContentId ) |
|
402 { |
|
403 FUNC_LOG; |
|
404 MMailboxData& mailbox = GetMailboxDataL( GetMailboxId( aContentId ) ); |
|
405 MEmailLaunchParameters& launchParams = mailbox.LaunchParameters(); |
|
406 |
|
407 CEikonEnv* env = CEikonEnv::Static(); |
|
408 TVwsViewId view( launchParams.ApplicationUid(), launchParams.ViewId() ); |
|
409 if ( launchParams.CustomMessageId().iUid == 0 ) |
|
410 { |
|
411 env->EikAppUi()->ActivateViewL( view, launchParams.CustomMessageId(), launchParams.CustomMessage() ); |
|
412 } |
|
413 else |
|
414 { |
|
415 env->EikAppUi()->ActivateViewL( view ); |
|
416 } |
|
417 } |
|
418 |
|
419 // --------------------------------------------------------------------------- |
|
420 // CMailPluginProxy::ResolveMailboxId |
|
421 // --------------------------------------------------------------------------- |
|
422 // |
|
423 TInt CMailPluginProxy::GetMailboxId( const TDesC& aContentId ) |
|
424 { |
|
425 FUNC_LOG; |
|
426 TInt mailboxId( 0 ); |
|
427 for ( TInt i = 0; i < iAccounts.Count(); i++ ) |
|
428 { |
|
429 if ( !(iAccounts[i]->ContentId().Compare( aContentId )) ) |
|
430 { |
|
431 mailboxId = iAccounts[i]->MailboxId(); |
|
432 } |
|
433 } |
|
434 return mailboxId; |
|
435 } |
|
436 |
|
437 // --------------------------------------------------------------------------- |
|
438 // CMailPluginProxy::GetMailboxDataL |
|
439 // --------------------------------------------------------------------------- |
|
440 // |
|
441 EmailInterface::MMailboxData& CMailPluginProxy::GetMailboxDataL( TInt aMailboxId ) |
|
442 { |
|
443 FUNC_LOG; |
|
444 TInt index( KErrNotFound ); |
|
445 RPointerArray<MMailboxData> mailboxes = iPlugin->EmailDataL().MailboxesL(); |
|
446 for ( TInt i = 0; i < mailboxes.Count(); i++ ) |
|
447 { |
|
448 if ( mailboxes[i]->MailboxId() == aMailboxId ) |
|
449 { |
|
450 index = i; |
|
451 } |
|
452 } |
|
453 |
|
454 if ( index == KErrNotFound ) |
|
455 { |
|
456 User::Leave( KErrNotFound ); |
|
457 } |
|
458 |
|
459 return *(mailboxes[index]); |
|
460 } |
|
461 |
|
462 // --------------------------------------------------------------------------- |
|
463 // CMailPluginProxy::SelectAndUpdateAccountsL |
|
464 // --------------------------------------------------------------------------- |
|
465 // |
|
466 void CMailPluginProxy::SelectAndUpdateAccountsL( RPointerArray<CMailExternalAccount>& aAccounts ) |
|
467 { |
|
468 FUNC_LOG; |
|
469 RemoveAccountsL(); |
|
470 SelectOwnAccountsL( aAccounts ); |
|
471 PublishAccountsL(); |
|
472 } |
|
473 |
|
474 // --------------------------------------------------------------------------- |
|
475 // CMailPluginProxy::UpdateAccountL |
|
476 // --------------------------------------------------------------------------- |
|
477 // |
|
478 void CMailPluginProxy::UpdateAccountL( const TDesC& aContentId ) |
|
479 { |
|
480 FUNC_LOG; |
|
481 PublishAccountL( |
|
482 ResolveWidgetInstance( aContentId ), |
|
483 GetMailboxId( aContentId ) ); |
|
484 } |