50 _LIT8( KProperValueMailbox, "mailbox" ); |
50 _LIT8( KProperValueMailbox, "mailbox" ); |
51 _LIT( KMenuTypeMailbox, "menu:mailbox" ); |
51 _LIT( KMenuTypeMailbox, "menu:mailbox" ); |
52 |
52 |
53 using namespace HSPluginSettingsIf; |
53 using namespace HSPluginSettingsIf; |
54 |
54 |
|
55 // ======== LOCAL FUNCTIONS ======== |
|
56 |
|
57 // ---------------------------------------------------------------------------- |
|
58 // CleanupResetAndDestroy() |
|
59 // ---------------------------------------------------------------------------- |
|
60 // |
|
61 template<class T> |
|
62 static void CleanupResetAndDestroy( TAny* aObj ) |
|
63 { |
|
64 if( aObj ) |
|
65 { |
|
66 static_cast<T*>( aObj )->ResetAndDestroy(); |
|
67 } |
|
68 } |
|
69 |
|
70 // ---------------------------------------------------------------------------- |
|
71 // CleanupResetAndDestroyPushL |
|
72 // ---------------------------------------------------------------------------- |
|
73 // |
|
74 template<class T> |
|
75 static void CleanupResetAndDestroyPushL(T& aArray) |
|
76 { |
|
77 CleanupStack::PushL( TCleanupItem( &CleanupResetAndDestroy<T>, &aArray ) ); |
|
78 } |
|
79 |
|
80 // ======== MEMBER FUNCTIONS ======== |
|
81 |
55 // ----------------------------------------------------------------------------- |
82 // ----------------------------------------------------------------------------- |
56 // Creates a formatted listbox line. |
83 // Creates a formatted listbox line. |
57 // ----------------------------------------------------------------------------- |
84 // ----------------------------------------------------------------------------- |
58 // |
85 // |
59 TPtrC CMCSPluginSettingsModel::ListBoxLineL( const TDesC& aCaption, TInt aIndex ) const |
86 TPtrC CMCSPluginSettingsModel::ListBoxLineL( const TDesC& aCaption, TInt aIndex ) const |
159 // Gets the latest settings from HSPS and updates |
186 // Gets the latest settings from HSPS and updates |
160 // --------------------------------------------------------------------------- |
187 // --------------------------------------------------------------------------- |
161 // |
188 // |
162 void CMCSPluginSettingsModel::UpdateSettingsL() |
189 void CMCSPluginSettingsModel::UpdateSettingsL() |
163 { |
190 { |
|
191 iSettings.Reset(); |
164 if( !iPluginId ) |
192 if( !iPluginId ) |
165 { |
193 { |
166 return; |
194 return; |
167 } |
195 } |
168 |
196 |
169 if (iContainer) |
197 if (iContainer) |
170 { |
198 { |
171 iContainer->CloseChangeDialog(); |
199 iContainer->CloseChangeDialog(); |
172 } |
200 } |
173 |
201 |
174 iSettings.Reset(); |
|
175 RPointerArray<CItemMap> settingItems; |
202 RPointerArray<CItemMap> settingItems; |
176 CleanupClosePushL( settingItems ); |
203 CleanupResetAndDestroyPushL( settingItems ); |
177 |
204 |
178 iPluginSettings->GetSettingsL( *iPluginId, settingItems ); |
205 iPluginSettings->GetSettingsL( *iPluginId, settingItems ); |
179 |
206 |
180 TInt count = settingItems.Count(); |
207 for ( TInt i = 0; i < settingItems.Count(); i++ ) |
181 for ( TInt i = 0; i < count; i++ ) |
|
182 { |
208 { |
183 CItemMap* itemMap = settingItems[i]; |
209 CItemMap* itemMap = settingItems[i]; |
184 RPointerArray<HSPluginSettingsIf::CPropertyMap> properties; |
210 RPointerArray<HSPluginSettingsIf::CPropertyMap> properties; |
185 properties = itemMap->Properties(); |
211 properties = itemMap->Properties(); |
186 TSettingItem item = ItemL( properties ); |
212 TSettingItem item = ItemL( properties ); |
187 iSettings.AppendL( item ); |
213 iSettings.AppendL( item ); |
188 } |
214 } |
189 CleanupStack::Pop( &settingItems ); |
215 |
190 settingItems.ResetAndDestroy(); |
216 CleanupStack::PopAndDestroy(); // settingItems |
191 |
217 |
192 if (iContainer) |
218 if (iContainer) |
193 { |
219 { |
194 iContainer->ResetCurrentListL(0); |
220 iContainer->ResetCurrentListL(0); |
195 } |
221 } |
281 { |
307 { |
282 if( !iPluginId ) |
308 if( !iPluginId ) |
283 { |
309 { |
284 return; |
310 return; |
285 } |
311 } |
286 |
312 |
287 RPointerArray<CItemMap> settingItems; |
313 RPointerArray<CItemMap> settingItems; |
288 CleanupClosePushL( settingItems ); |
314 CleanupResetAndDestroyPushL( settingItems ); |
289 iPluginSettings->GetSettingsL( *iPluginId, settingItems ); |
315 iPluginSettings->GetSettingsL( *iPluginId, settingItems ); |
|
316 |
290 if ( aIndex >= 0 && aIndex < settingItems.Count() ) |
317 if ( aIndex >= 0 && aIndex < settingItems.Count() ) |
291 { |
318 { |
292 TBool exists( EFalse ); |
319 TBool exists( EFalse ); |
293 CItemMap* itemMap = settingItems[ aIndex ]; |
320 CItemMap* itemMap = settingItems[ aIndex ]; |
294 RPointerArray<HSPluginSettingsIf::CPropertyMap> properties; |
321 RPointerArray<HSPluginSettingsIf::CPropertyMap> properties; |
295 properties = itemMap->Properties(); |
322 properties = itemMap->Properties(); |
|
323 |
|
324 const TInt KGranularity = 6; |
|
325 CDesC8Array* propertiesList = new ( ELeave ) CDesC8ArrayFlat( KGranularity ); |
|
326 CleanupStack::PushL( propertiesList ); |
|
327 propertiesList->AppendL( KProperNameType ); |
|
328 propertiesList->AppendL( KProperNameParam ); |
|
329 propertiesList->AppendL( KProperNameUid ); |
|
330 propertiesList->AppendL( KProperNameView ); |
|
331 // skip KProperNameLocked property, attribute may be missing. results into |
|
332 // leave with -1 when saving settings |
|
333 |
|
334 // add missing properties |
|
335 for ( TInt i=0; i<propertiesList->Count(); i++ ) |
|
336 { |
|
337 TBool found( EFalse ); |
|
338 const TPtrC8 namePtr = propertiesList->MdcaPoint( i ); |
|
339 for ( TInt j=0; j<properties.Count() && !found; j++ ) |
|
340 { |
|
341 found = ( (namePtr == properties[ j ]->Name() ) ? ETrue : EFalse ); |
|
342 } |
|
343 if ( !found ) |
|
344 { |
|
345 CPropertyMap* property = CPropertyMap::NewLC(); |
|
346 property->SetNameL( namePtr ); |
|
347 property->SetValueL( KNullDesC8 ); |
|
348 itemMap->AddPropertyMapL( property ); |
|
349 CleanupStack::Pop( property ); |
|
350 |
|
351 // get updated list |
|
352 properties = itemMap->Properties(); |
|
353 } |
|
354 } |
|
355 CleanupStack::PopAndDestroy( propertiesList ); |
|
356 |
296 for ( TInt i = 0; i < properties.Count(); i++ ) |
357 for ( TInt i = 0; i < properties.Count(); i++ ) |
297 { |
358 { |
298 if ( properties[ i ]->Name() == KProperNameType ) |
359 if ( properties[ i ]->Name() == KProperNameType ) |
299 { |
360 { |
300 TPtrC type = aMenuItem.Type(); |
361 TPtrC type = aMenuItem.Type(); |
320 } |
381 } |
321 } |
382 } |
322 else if ( properties[ i ]->Name() == KProperNameUid ) |
383 else if ( properties[ i ]->Name() == KProperNameUid ) |
323 { |
384 { |
324 TPtrC uid = aMenuItem.GetAttributeL( KMenuAttrUid, exists ); |
385 TPtrC uid = aMenuItem.GetAttributeL( KMenuAttrUid, exists ); |
325 if ( exists ) |
386 if ( exists && uid.Length() > 0 ) |
326 { |
387 { |
327 HBufC8* uid8( NULL ); |
388 HBufC8* uid8( NULL ); |
328 uid8 = AiUtility::CopyToBufferL( uid8, uid ); |
389 uid8 = AiUtility::CopyToBufferL( uid8, uid ); |
329 CleanupStack::PushL( uid8 ); |
390 CleanupStack::PushL( uid8 ); |
330 properties[ i ]->SetValueL( *uid8 ); |
391 properties[ i ]->SetValueL( *uid8 ); |
336 } |
397 } |
337 } |
398 } |
338 else if ( properties[ i ]->Name() == KProperNameView ) |
399 else if ( properties[ i ]->Name() == KProperNameView ) |
339 { |
400 { |
340 TPtrC view = aMenuItem.GetAttributeL( KMenuAttrView, exists ); |
401 TPtrC view = aMenuItem.GetAttributeL( KMenuAttrView, exists ); |
341 if( exists ) |
402 if( exists && view.Length() > 0 ) |
342 { |
403 { |
343 HBufC8* view8( NULL ); |
404 HBufC8* view8( NULL ); |
344 view8 = AiUtility::CopyToBufferL( view8, view ); |
405 view8 = AiUtility::CopyToBufferL( view8, view ); |
345 CleanupStack::PushL( view8 ); |
406 CleanupStack::PushL( view8 ); |
346 properties[i]->SetValueL( *view8 ); |
407 properties[i]->SetValueL( *view8 ); |
387 } |
448 } |
388 } |
449 } |
389 else if ( properties[ i ]->Name() == KProperNameLocked ) |
450 else if ( properties[ i ]->Name() == KProperNameLocked ) |
390 { |
451 { |
391 TPtrC locked = aMenuItem.GetAttributeL( KMenuAttrLocked, exists ); |
452 TPtrC locked = aMenuItem.GetAttributeL( KMenuAttrLocked, exists ); |
392 if ( exists ) |
453 if ( exists && locked.Length() > 0 ) |
393 { |
454 { |
394 HBufC8* locked8( NULL ); |
455 HBufC8* locked8( NULL ); |
395 locked8 = AiUtility::CopyToBufferL( locked8, locked ); |
456 locked8 = AiUtility::CopyToBufferL( locked8, locked ); |
396 CleanupStack::PushL( locked8 ); |
457 CleanupStack::PushL( locked8 ); |
397 properties[ i ]->SetValueL( *locked8 ); |
458 properties[ i ]->SetValueL( *locked8 ); |
402 properties[i]->SetValueL( KNullDesC8 ); |
463 properties[i]->SetValueL( KNullDesC8 ); |
403 } |
464 } |
404 } |
465 } |
405 } |
466 } |
406 } |
467 } |
|
468 |
407 // ETrue tells that modified settings are stored also to plugin reference |
469 // ETrue tells that modified settings are stored also to plugin reference |
408 iPluginSettings->SetSettingsL( *iPluginId, settingItems, ETrue ); |
470 User::LeaveIfError( iPluginSettings->SetSettingsL( *iPluginId, settingItems, ETrue ) ); |
409 CleanupStack::Pop( &settingItems ); |
471 CleanupStack::PopAndDestroy(); // settingItems |
410 settingItems.ResetAndDestroy(); |
|
411 |
|
412 } |
472 } |
413 |
473 |
414 // --------------------------------------------------------------------------- |
474 // --------------------------------------------------------------------------- |
415 // Updates settings container. |
475 // Updates settings container. |
416 // --------------------------------------------------------------------------- |
476 // --------------------------------------------------------------------------- |
436 // From MDesCArray |
496 // From MDesCArray |
437 // Indexes into a descriptor array. |
497 // Indexes into a descriptor array. |
438 // --------------------------------------------------------------------------- |
498 // --------------------------------------------------------------------------- |
439 // |
499 // |
440 TPtrC CMCSPluginSettingsModel::MdcaPoint( TInt aIndex ) const |
500 TPtrC CMCSPluginSettingsModel::MdcaPoint( TInt aIndex ) const |
441 { |
501 { |
442 if (aIndex < 0 || aIndex >= iSettings.Count()) |
502 if (aIndex < 0 || aIndex >= iSettings.Count()) |
443 { |
503 { |
444 TPtrC ret(KNullDesC); |
504 TPtrC ret(KNullDesC); |
445 return ret; |
505 return ret; |
446 } |
506 } |
|
507 |
|
508 TPtrC line( KNullDesC ); |
447 if ( iSettings[aIndex].type == EApplication ) |
509 if ( iSettings[aIndex].type == EApplication ) |
448 { |
510 { |
449 // first, we need to check if the item is missing |
511 // first, we need to check if the item is missing |
450 // (application uninstalled or mmc card removed) |
512 // (application uninstalled or mmc card removed) |
451 // If it is, we return "Undefined" application name instead |
513 // If it is, we return "Undefined" application name instead |
452 if ( iSettings[ aIndex ].id == KErrNotFound ) |
514 if ( iSettings[ aIndex ].id == KErrNotFound ) |
453 { |
515 { |
454 const TDesC& caption = iAppList->UndefinedText(); |
516 const TDesC& caption = iAppList->UndefinedText(); |
455 TPtrC line; |
|
456 TRAP_IGNORE( line.Set( ListBoxLineL( caption, aIndex ) ) ) |
517 TRAP_IGNORE( line.Set( ListBoxLineL( caption, aIndex ) ) ) |
457 return line; |
|
458 } |
518 } |
459 else |
519 else |
460 { |
520 { |
461 const TDesC& caption = iAppList->MdcaPoint( iSettings[ aIndex ].id ); |
521 const TDesC& caption = iAppList->MdcaPoint( iSettings[ aIndex ].id ); |
462 TPtrC line; |
|
463 TRAP_IGNORE( line.Set( ListBoxLineL( caption, aIndex ) ) ) |
522 TRAP_IGNORE( line.Set( ListBoxLineL( caption, aIndex ) ) ) |
464 return line; |
|
465 } |
523 } |
466 } |
524 } |
467 else |
525 else |
468 { |
526 { |
469 const TDesC& caption = iBkmList->MdcaPoint( iSettings[aIndex].id ); |
527 const TDesC& caption = iBkmList->MdcaPoint( iSettings[aIndex].id ); |
470 TPtrC line; |
|
471 TRAP_IGNORE( line.Set( ListBoxLineL( caption, aIndex ) ) ) |
528 TRAP_IGNORE( line.Set( ListBoxLineL( caption, aIndex ) ) ) |
472 return line; |
529 } |
473 } |
530 |
474 } |
531 return line; |
|
532 } |
475 |
533 |
476 // --------------------------------------------------------------------------- |
534 // --------------------------------------------------------------------------- |
477 // Returns a setting ID for the given index. |
535 // Returns a setting ID for the given index. |
478 // --------------------------------------------------------------------------- |
536 // --------------------------------------------------------------------------- |
479 // |
537 // |
509 // |
567 // |
510 TBool CMCSPluginSettingsModel::ReplaceItemL( const TInt& aSettingIndex, |
568 TBool CMCSPluginSettingsModel::ReplaceItemL( const TInt& aSettingIndex, |
511 TInt aId, |
569 TInt aId, |
512 TSettingType aType ) |
570 TSettingType aType ) |
513 { |
571 { |
|
572 TBool replaced( EFalse ); |
514 if (aSettingIndex >= 0 && aSettingIndex < iSettings.Count()) |
573 if (aSettingIndex >= 0 && aSettingIndex < iSettings.Count()) |
515 { |
574 { |
516 iSettings[ aSettingIndex ].id = aId; |
575 CMenuItem* item( NULL ); |
517 iSettings[ aSettingIndex ].type = aType; |
|
518 |
|
519 if ( aType == EApplication ) |
576 if ( aType == EApplication ) |
520 { |
577 { |
521 CMenuItem* item = iAppList->ItemL( aId ); |
578 item = iAppList->ItemL( aId ); |
|
579 } |
|
580 else |
|
581 { |
|
582 item = iBkmList->ItemL( aId ); |
|
583 } |
|
584 |
|
585 if ( item ) |
|
586 { |
522 SaveSettingsL( aSettingIndex, *item ); |
587 SaveSettingsL( aSettingIndex, *item ); |
523 } |
588 iSettings[ aSettingIndex ].id = aId; |
524 else |
589 iSettings[ aSettingIndex ].type = aType; |
525 { |
590 replaced = ETrue; |
526 CMenuItem& item = iBkmList->ItemL( aId ); |
591 } |
527 SaveSettingsL( aSettingIndex, item ); |
592 } |
528 } |
593 return replaced; |
529 return ETrue; |
|
530 } |
|
531 return EFalse; |
|
532 } |
594 } |
533 |
595 |
534 // --------------------------------------------------------------------------- |
596 // --------------------------------------------------------------------------- |
535 // Sets a container |
597 // Sets a container |
536 // --------------------------------------------------------------------------- |
598 // --------------------------------------------------------------------------- |
560 |
622 |
561 // --------------------------------------------------------------------------- |
623 // --------------------------------------------------------------------------- |
562 // Updates application list |
624 // Updates application list |
563 // --------------------------------------------------------------------------- |
625 // --------------------------------------------------------------------------- |
564 // |
626 // |
565 void CMCSPluginSettingsModel::UpdateAppListL() |
627 void CMCSPluginSettingsModel::UpdateAppListL( TBool aUpdateSettings ) |
566 { |
628 { |
567 if( !iAppList ) |
629 if( !iAppList ) |
568 { |
630 { |
569 iAppList = CMCSPluginSettingsAppList::NewL(); |
631 iAppList = CMCSPluginSettingsAppList::NewL(); |
570 } |
632 } |
571 iAppList->StartL(); |
633 iAppList->StartL(); |
|
634 if ( aUpdateSettings ) |
|
635 { |
|
636 UpdateSettingsL(); |
|
637 } |
572 } |
638 } |
573 |
639 |
574 // --------------------------------------------------------------------------- |
640 // --------------------------------------------------------------------------- |
575 // Updates bookmark list |
641 // Updates bookmark list |
576 // --------------------------------------------------------------------------- |
642 // --------------------------------------------------------------------------- |
577 // |
643 // |
578 void CMCSPluginSettingsModel::UpdateBkmListL() |
644 void CMCSPluginSettingsModel::UpdateBkmListL( TBool aUpdateSettings ) |
579 { |
645 { |
580 delete iBkmList; |
646 delete iBkmList; |
581 iBkmList = NULL; |
647 iBkmList = NULL; |
582 iBkmList = CMCSPluginSettingsBkmList::NewL(); |
648 iBkmList = CMCSPluginSettingsBkmList::NewL(); |
583 } |
649 if ( aUpdateSettings ) |
|
650 { |
|
651 UpdateSettingsL(); |
|
652 } |
|
653 } |
584 |
654 |
585 // End of File. |
655 // End of File. |