|
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: handles interface to CenRep settings |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include <e32base.h> |
|
21 // CRepository |
|
22 #include <centralrepository.h> |
|
23 // Email Framework APIs |
|
24 //<cmail> |
|
25 #include "CFSMailCommon.h" |
|
26 #include "CFSMailClient.h" |
|
27 #include "CFSMailBox.h" |
|
28 #include "CFSMailFolder.h" |
|
29 //</cmail> |
|
30 |
|
31 #include "cmailcpssettings.h" |
|
32 #include "cmailwidgetcenrepkeysinternal.h" |
|
33 #include "cmailcpsifconsts.h" |
|
34 |
|
35 // ======== MEMBER FUNCTIONS ======== |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // CMailCpsSettings::NewL |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CMailCpsSettings* CMailCpsSettings::NewL( CFSMailClient& aMailClient ) |
|
42 { |
|
43 FUNC_LOG; |
|
44 CMailCpsSettings* self = new(ELeave) CMailCpsSettings( aMailClient ); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CMailCpsSettings::~CMailCpsSettings |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CMailCpsSettings::~CMailCpsSettings() |
|
56 { |
|
57 FUNC_LOG; |
|
58 Cancel(); |
|
59 iMailboxArray.Close(); |
|
60 delete iCenRep; |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // CMailCpsSettings::CMailCpsSettings |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CMailCpsSettings::CMailCpsSettings( CFSMailClient& aMailClient ) : |
|
68 CActive( EPriorityStandard ), |
|
69 iMailClient( aMailClient ), |
|
70 iCenRep( NULL ), |
|
71 iConfigData( 0 ) |
|
72 { |
|
73 FUNC_LOG; |
|
74 CActiveScheduler::Add( this ); |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // CMailCpsSettings::ConstructL |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 void CMailCpsSettings::ConstructL() |
|
82 { |
|
83 FUNC_LOG; |
|
84 // In case there is no repository available, following call will leave |
|
85 // Trapping is done by MailServer infrastructure, not by CPS handler |
|
86 // In practice, this is fatal to cps handling, and widget won't work |
|
87 iCenRep = CRepository::NewL( KCRUidCmailWidget ); |
|
88 LoadSettingsL(); // mailboxes etc. user changeable data |
|
89 LoadConfigurationL(); // internal configuration data |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // CMailCpsSettings::RunL |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 void CMailCpsSettings::RunL() |
|
97 { |
|
98 FUNC_LOG; |
|
99 LoadSettingsL(); // mailboxes etc. user changeable data |
|
100 LoadConfigurationL(); // internal configuration data |
|
101 iObserver->SettingsChangedCallback(); |
|
102 StartObservingL(); |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // CMailCpsSettings::DoCancel |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 void CMailCpsSettings::DoCancel() |
|
110 { |
|
111 FUNC_LOG; |
|
112 // Always returns KErrNone |
|
113 iCenRep->NotifyCancel( KCmailPartialKey, KCmailMask ); |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // CMailCpsSettings::LoadSettingsL |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 void CMailCpsSettings::LoadSettingsL() |
|
121 { |
|
122 FUNC_LOG; |
|
123 // Clean up local settings cache |
|
124 iMailboxArray.Reset(); |
|
125 TInt ret( KErrNone ); |
|
126 |
|
127 // Load mailbox array |
|
128 RArray<TUint32> keys; |
|
129 CleanupClosePushL( keys ); |
|
130 GetMailboxNonZeroKeysL( keys ); |
|
131 const TInt iiMax( keys.Count() ); |
|
132 for ( TInt ii = 0; ii < iiMax; ii++ ) |
|
133 { |
|
134 TInt value( 0 ); |
|
135 ret = iCenRep->Get( keys[ii], value ); |
|
136 if ( ret ) |
|
137 { |
|
138 User::Leave( ret ); |
|
139 } |
|
140 else |
|
141 { |
|
142 TFSMailMsgId mailbox; |
|
143 ret = ResolveMailbox( value, mailbox ); |
|
144 if ( ret ) |
|
145 { |
|
146 // Resolving encountered error, ignore this entry |
|
147 ret = iCenRep->Reset( KCMailMailboxIdBase+ii ); |
|
148 ret = iCenRep->Reset( KCMailPluginIdBase+ii ); |
|
149 ret = iCenRep->Reset( KCMailMailboxIdBase+ii ); |
|
150 if ( ret ) |
|
151 { |
|
152 } |
|
153 } |
|
154 else |
|
155 { |
|
156 iMailboxArray.AppendL( mailbox ); |
|
157 } |
|
158 } |
|
159 } |
|
160 CleanupStack::PopAndDestroy(); // CleanupClosePushL( keys ) |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // CMailCpsSettings::LoadConfigurationL |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 void CMailCpsSettings::LoadConfigurationL() |
|
168 { |
|
169 FUNC_LOG; |
|
170 TInt ret( KErrNone ); |
|
171 TInt value( 0 ); |
|
172 ret = iCenRep->Get( KCmailCPConfiguration, value ); |
|
173 if ( !ret ) |
|
174 { |
|
175 INFO_2("iConfigData: %d -> %d", iConfigData, value); |
|
176 iConfigData = static_cast<TInt32>( value ); |
|
177 } |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // CMailCpsSettings::GetMailboxNonZeroKeysL |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 void CMailCpsSettings::GetMailboxNonZeroKeysL( RArray<TUint32>& aKeys ) |
|
185 { |
|
186 FUNC_LOG; |
|
187 TInt ret = iCenRep->FindNeqL( KCmailPartialKeyRange, KCmailRangeMask, 0, aKeys ); |
|
188 if ( ret != KErrNone && ret != KErrNotFound ) |
|
189 { |
|
190 User::Leave( ret ); |
|
191 } |
|
192 } |
|
193 |
|
194 // --------------------------------------------------------------------------- |
|
195 // CMailCpsSettings::ResolveMailbox |
|
196 // --------------------------------------------------------------------------- |
|
197 // |
|
198 TInt CMailCpsSettings::ResolveMailbox( const TInt aMailboxId, TFSMailMsgId& aMsg ) |
|
199 { |
|
200 FUNC_LOG; |
|
201 RPointerArray<CFSMailBox> mailboxarray; |
|
202 TInt err = iMailClient.ListMailBoxes( TFSMailMsgId(), mailboxarray ); |
|
203 if( !err ) |
|
204 { |
|
205 err = KErrNotFound; |
|
206 aMsg.SetId( aMailboxId ); |
|
207 const TInt iiMax( mailboxarray.Count() ); |
|
208 for ( TInt ii = 0; ii < iiMax; ii++ ) |
|
209 { |
|
210 if ( mailboxarray[ii]->GetId().Id() == aMsg.Id() ) |
|
211 { |
|
212 // Mailbox found |
|
213 aMsg.SetPluginId( mailboxarray[ii]->GetId().PluginId() ); |
|
214 return err = KErrNone; |
|
215 } |
|
216 } |
|
217 } |
|
218 else |
|
219 { |
|
220 } |
|
221 mailboxarray.ResetAndDestroy(); |
|
222 return err; |
|
223 } |
|
224 |
|
225 // --------------------------------------------------------------------------- |
|
226 // CMailCpsSettings::StartObservingL |
|
227 // --------------------------------------------------------------------------- |
|
228 // |
|
229 void CMailCpsSettings::StartObservingL( MMailCpsSettingsCallback* aObserver ) |
|
230 { |
|
231 FUNC_LOG; |
|
232 iObserver = aObserver; |
|
233 StartObservingL(); |
|
234 } |
|
235 |
|
236 // --------------------------------------------------------------------------- |
|
237 // CMailCpsSettings::StartObservingL |
|
238 // --------------------------------------------------------------------------- |
|
239 // |
|
240 void CMailCpsSettings::StartObservingL() |
|
241 { |
|
242 FUNC_LOG; |
|
243 TInt ret = iCenRep->NotifyRequest( KCmailPartialKey, KCmailMask, iStatus ); |
|
244 if ( ret ) |
|
245 { |
|
246 User::Leave( ret ); |
|
247 } |
|
248 SetActive(); |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------------------------- |
|
252 // CMailCpsSettings::StopObserving |
|
253 // --------------------------------------------------------------------------- |
|
254 // |
|
255 void CMailCpsSettings::StopObserving() |
|
256 { |
|
257 FUNC_LOG; |
|
258 Cancel(); |
|
259 // observer not owned by settings |
|
260 iObserver = NULL; |
|
261 } |
|
262 |
|
263 // --------------------------------------------------------------------------- |
|
264 // CMailCpsSettings::Mailboxes |
|
265 // --------------------------------------------------------------------------- |
|
266 // |
|
267 RArray<TFSMailMsgId>& CMailCpsSettings::Mailboxes() |
|
268 { |
|
269 return iMailboxArray; |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // CMailCpsSettings::AddMailboxL |
|
274 // --------------------------------------------------------------------------- |
|
275 // |
|
276 void CMailCpsSettings::AddMailboxL( const TFSMailMsgId aMailbox ) |
|
277 { |
|
278 FUNC_LOG; |
|
279 |
|
280 // Ensure message is not already in settings |
|
281 RArray<TUint32> keys; |
|
282 CleanupClosePushL( keys ); |
|
283 GetMailboxNonZeroKeysL( keys ); |
|
284 const TInt iiMax( keys.Count() ); |
|
285 for ( TInt ii = 0; ii < iiMax; ii++ ) |
|
286 { |
|
287 TInt value( 0 ); |
|
288 iCenRep->Get( keys[ii], value ); |
|
289 if( value == aMailbox.Id() ) |
|
290 { |
|
291 // mailbox already in settings, simply return |
|
292 CleanupStack::PopAndDestroy( &keys ); |
|
293 return; |
|
294 } |
|
295 } |
|
296 |
|
297 // Add mailbox to settings |
|
298 keys.Reset(); |
|
299 TInt ret = iCenRep->FindEqL( KCmailPartialKeyRange, KCmailRangeMask, 0, keys ); |
|
300 if ( ret != KErrNone && ret != KErrNotFound ) |
|
301 { |
|
302 User::Leave( ret ); |
|
303 } |
|
304 if( keys.Count() > 0 ) |
|
305 { |
|
306 // Casting uint32 to int32 below is safe because following is always true: |
|
307 // aMailbox.Id() < 0x7FFFFFFF |
|
308 iCenRep->Set( keys[0], static_cast<TInt>( aMailbox.Id() ) ); |
|
309 } |
|
310 else |
|
311 { |
|
312 } |
|
313 |
|
314 CleanupStack::PopAndDestroy(); // CleanupClosePushL( keys ); |
|
315 |
|
316 } |
|
317 |
|
318 // --------------------------------------------------------------------------- |
|
319 // CMailCpsSettings::RemoveMailboxL |
|
320 // --------------------------------------------------------------------------- |
|
321 // |
|
322 void CMailCpsSettings::RemoveMailboxL( const TFSMailMsgId aMailbox ) |
|
323 { |
|
324 FUNC_LOG; |
|
325 TInt iiMax( iMailboxArray.Count() ); |
|
326 for ( TInt ii = 0; ii < iiMax; ii++ ) |
|
327 { |
|
328 if( iMailboxArray[ii].Id() == aMailbox.Id() ) |
|
329 { |
|
330 RemoveMailboxL( ii ); |
|
331 break; |
|
332 } |
|
333 } |
|
334 } |
|
335 |
|
336 // --------------------------------------------------------------------------- |
|
337 // CMailCpsSettings::RemoveMailboxL |
|
338 // --------------------------------------------------------------------------- |
|
339 // |
|
340 void CMailCpsSettings::RemoveMailboxL( const TInt aIndex ) |
|
341 { |
|
342 FUNC_LOG; |
|
343 |
|
344 // Remove mailbox from local array |
|
345 TFSMailMsgId mailboxId = iMailboxArray[aIndex]; |
|
346 iMailboxArray.Remove( aIndex ); |
|
347 |
|
348 // Remove mailbox from widget settings |
|
349 RArray<TUint32> keys; |
|
350 GetMailboxNonZeroKeysL( keys ); |
|
351 const TInt iiMax( keys.Count() ); |
|
352 for ( TInt ii = 0; ii < iiMax; ii++ ) |
|
353 { |
|
354 TInt value( 0 ); |
|
355 iCenRep->Get( keys[ii], value ); |
|
356 if( value == mailboxId.Id() ) |
|
357 { |
|
358 iCenRep->Set( keys[ii], 0 ); |
|
359 } |
|
360 } |
|
361 } |
|
362 |
|
363 // --------------------------------------------------------------------------- |
|
364 // CMailCpsSettings::MaxRowCount |
|
365 // --------------------------------------------------------------------------- |
|
366 // |
|
367 TInt CMailCpsSettings::MaxRowCount() |
|
368 { |
|
369 FUNC_LOG; |
|
370 return KMaxRowCount; |
|
371 } |
|
372 |
|
373 // --------------------------------------------------------------------------- |
|
374 // CMailCpsSettings::MaxMailboxCount |
|
375 // --------------------------------------------------------------------------- |
|
376 // |
|
377 TInt CMailCpsSettings::MaxMailboxCount() |
|
378 { |
|
379 FUNC_LOG; |
|
380 return KMaxMailboxCount; |
|
381 } |
|
382 |
|
383 // --------------------------------------------------------------------------- |
|
384 // CMailCpsSettings::AssociateWidgetToSetting |
|
385 // --------------------------------------------------------------------------- |
|
386 // |
|
387 TBool CMailCpsSettings::AssociateWidgetToSetting( const TDesC& aContentId ) |
|
388 { |
|
389 FUNC_LOG; |
|
390 TBool alreadyAssociated(ETrue); |
|
391 |
|
392 if (!IsAlreadyAssociated(aContentId)) |
|
393 { |
|
394 TUint32 key (GetSettingToAssociate()); |
|
395 iCenRep->Set( key, aContentId ); |
|
396 alreadyAssociated = EFalse; |
|
397 } |
|
398 return alreadyAssociated; |
|
399 } |
|
400 |
|
401 // --------------------------------------------------------------------------- |
|
402 // CMailCpsSettings::DissociateWidgetFromSetting |
|
403 // --------------------------------------------------------------------------- |
|
404 // |
|
405 void CMailCpsSettings::DissociateWidgetFromSetting( const TDesC& aContentId ) |
|
406 { |
|
407 FUNC_LOG; |
|
408 TUint32 key(0); |
|
409 TUint32 mailboxKey(0); |
|
410 |
|
411 for (TInt i = 0; i < KMaxMailboxCount; i++) |
|
412 { |
|
413 TBuf<KMaxDescLen> value; |
|
414 TUint32 tempKey(KCMailWidgetContentIdBase+i); |
|
415 iCenRep->Get( tempKey, value ); |
|
416 TInt result = value.Compare(aContentId); |
|
417 if (!result) |
|
418 { |
|
419 key = tempKey; |
|
420 mailboxKey = KCMailMailboxIdBase + i; |
|
421 iCenRep->Reset(key); |
|
422 iCenRep->Reset(mailboxKey); |
|
423 break; |
|
424 } |
|
425 } |
|
426 } |
|
427 |
|
428 // --------------------------------------------------------------------------- |
|
429 // CMailCpsSettings::GetContentId |
|
430 // --------------------------------------------------------------------------- |
|
431 // |
|
432 void CMailCpsSettings::GetContentId( TInt aId, TDes16& aValue ) |
|
433 { |
|
434 FUNC_LOG; |
|
435 for (TInt i = 0; i < KMaxMailboxCount; i++) |
|
436 { |
|
437 TInt value; |
|
438 TUint32 mailboxKey(KCMailMailboxIdBase+i); |
|
439 iCenRep->Get( mailboxKey, value ); |
|
440 if (aId == value) |
|
441 { |
|
442 iCenRep->Get( KCMailWidgetContentIdBase+i, aValue ); |
|
443 break; |
|
444 } |
|
445 } |
|
446 } |
|
447 |
|
448 // --------------------------------------------------------------------------- |
|
449 // CMailCpsSettings::IsSelected |
|
450 // --------------------------------------------------------------------------- |
|
451 // |
|
452 TBool CMailCpsSettings::IsSelected( TInt aId ) |
|
453 { |
|
454 FUNC_LOG; |
|
455 TBool ret(EFalse); |
|
456 for (TInt i = 0; i < KMaxMailboxCount; i++) |
|
457 { |
|
458 TInt value; |
|
459 TUint32 mailboxKey(KCMailMailboxIdBase+i); |
|
460 iCenRep->Get( mailboxKey, value ); |
|
461 if (aId == value) |
|
462 { |
|
463 ret = ETrue; |
|
464 break; |
|
465 } |
|
466 } |
|
467 return ret; |
|
468 } |
|
469 |
|
470 // --------------------------------------------------------------------------- |
|
471 // CMailCpsSettings::GetSettingToAssociate |
|
472 // --------------------------------------------------------------------------- |
|
473 // |
|
474 TUint CMailCpsSettings::GetMailboxUidByContentId( const TDesC& aContentId ) |
|
475 { |
|
476 FUNC_LOG; |
|
477 TInt ret(KErrNone); |
|
478 for (TInt i = 0; i < KMaxMailboxCount; i++) |
|
479 { |
|
480 TBuf<KMaxDescLen> cid; |
|
481 TUint32 key(KCMailWidgetContentIdBase+i); |
|
482 iCenRep->Get( key, cid ); |
|
483 TInt result = cid.Compare(aContentId); |
|
484 if (!result) |
|
485 { |
|
486 TUint32 key2(KCMailMailboxIdBase+i); |
|
487 iCenRep->Get( key2, ret ); |
|
488 break; |
|
489 } |
|
490 } |
|
491 return ret; |
|
492 } |
|
493 |
|
494 // --------------------------------------------------------------------------- |
|
495 // CMailCpsSettings::GetPluginUidByContentId |
|
496 // --------------------------------------------------------------------------- |
|
497 // |
|
498 TUint CMailCpsSettings::GetPluginUidByContentId( const TDesC& aContentId ) |
|
499 { |
|
500 FUNC_LOG; |
|
501 TInt ret(KErrNone); |
|
502 for (TInt i = 0; i < KMaxMailboxCount; i++) |
|
503 { |
|
504 TBuf<KMaxDescLen> cid; |
|
505 TUint32 key(KCMailWidgetContentIdBase+i); |
|
506 iCenRep->Get( key, cid ); |
|
507 TInt result = cid.Compare(aContentId); |
|
508 if (!result) |
|
509 { |
|
510 TUint32 key2(KCMailPluginIdBase+i); |
|
511 iCenRep->Get( key2, ret ); |
|
512 break; |
|
513 } |
|
514 } |
|
515 return ret; |
|
516 } |
|
517 |
|
518 // --------------------------------------------------------------------------- |
|
519 // CMailCpsSettings::IsAlreadyAssociated |
|
520 // --------------------------------------------------------------------------- |
|
521 // |
|
522 TBool CMailCpsSettings::IsAlreadyAssociated( const TDesC& aContentId ) |
|
523 { |
|
524 FUNC_LOG; |
|
525 TBool ret(EFalse); |
|
526 for (TInt i = 0; i < KMaxMailboxCount; i++) |
|
527 { |
|
528 TBuf<KMaxDescLen> value; |
|
529 TUint32 key(KCMailWidgetContentIdBase+i); |
|
530 iCenRep->Get( key, value ); |
|
531 TInt result = value.Compare(aContentId); |
|
532 if (!result) |
|
533 { |
|
534 ret = ETrue; |
|
535 break; |
|
536 } |
|
537 } |
|
538 return ret; |
|
539 } |
|
540 |
|
541 // --------------------------------------------------------------------------- |
|
542 // CMailCpsSettings::GetSettingToAssociate |
|
543 // --------------------------------------------------------------------------- |
|
544 // |
|
545 TUint32 CMailCpsSettings::GetSettingToAssociate() |
|
546 { |
|
547 FUNC_LOG; |
|
548 TUint32 ret(KErrNone); |
|
549 for (TInt i = 0; i < KMaxMailboxCount; i++) |
|
550 { |
|
551 TBuf<KMaxDescLen> value; |
|
552 TUint32 key(KCMailWidgetContentIdBase+i); |
|
553 iCenRep->Get( key, value ); |
|
554 TInt result = value.Compare(KDissociated); |
|
555 if (!result) |
|
556 { |
|
557 ret = KCMailWidgetContentIdBase + i; |
|
558 break; |
|
559 } |
|
560 } |
|
561 return ret; |
|
562 } |
|
563 |
|
564 // --------------------------------------------------------------------------- |
|
565 // CMailCpsSettings::Configuration |
|
566 // --------------------------------------------------------------------------- |
|
567 // |
|
568 TInt32 CMailCpsSettings::Configuration() |
|
569 { |
|
570 FUNC_LOG; |
|
571 return iConfigData; |
|
572 } |
|
573 |
|
574 // --------------------------------------------------------------------------- |
|
575 // CMailCpsSettings::GetTotalMailboxCount |
|
576 // --------------------------------------------------------------------------- |
|
577 // |
|
578 TInt CMailCpsSettings::GetTotalMailboxCount() |
|
579 { |
|
580 FUNC_LOG; |
|
581 RPointerArray<CFSMailBox> mailboxarray; |
|
582 iMailClient.ListMailBoxes( TFSMailMsgId(), mailboxarray ); |
|
583 TInt ret = mailboxarray.Count(); |
|
584 return ret; |
|
585 } |
|
586 |