|
1 /* |
|
2 * Copyright (c) 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: MCS settings plug-in model. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <eikenv.h> |
|
19 #include <itemmap.h> |
|
20 #include <mhomescreensettingsif.h> |
|
21 |
|
22 #include <aistrcnv.h> |
|
23 #include <StringLoader.h> |
|
24 #include <uri16.h> |
|
25 #include <mcspluginsettingsres.rsg> |
|
26 |
|
27 |
|
28 #include "mcspluginsettings.h" |
|
29 #include "mcspluginsettingsmodel.h" |
|
30 #include "mcspluginsettingscontainer.h" |
|
31 |
|
32 |
|
33 #include "debug.h" |
|
34 |
|
35 #include <mcsmenuitem.h> |
|
36 |
|
37 /** |
|
38 * Line format for the settings list box |
|
39 */ |
|
40 _LIT(KSettingListboxLineFormat, " \t%S\t\t%S"); |
|
41 _LIT( KMenuAttrParam, "param"); |
|
42 _LIT( KMenuAttrLocked, "locked"); |
|
43 _LIT8( KTrue, "true" ); |
|
44 _LIT8( KAppUid, "271012080" ); |
|
45 _LIT8( KProperNameType, "type" ); |
|
46 _LIT8( KProperNameParam, "param" ); |
|
47 _LIT8( KProperNameUid, "uid" ); |
|
48 _LIT8( KProperNameView, "view" ); |
|
49 _LIT8( KProperNameLocked, "locked" ); |
|
50 _LIT8( KProperValueFolder, "folder" ); |
|
51 _LIT8( KProperValueSuite, "suite" ); |
|
52 _LIT8( KProperValueBookmark, "bookmark" ); |
|
53 _LIT8( KProperValueAppl, "application" ); |
|
54 _LIT( KSuiteName, "suite_name" ); |
|
55 |
|
56 |
|
57 using namespace HSPluginSettingsIf; |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // Creates a formatted listbox line. |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 TPtrC CMCSPluginSettingsModel::ListBoxLineL( const TDesC& aCaption, TInt aIndex ) const |
|
64 { |
|
65 HBufC* title = StringLoader::LoadLC( |
|
66 R_AI_MCS_SETTINGS_TXT_LINKN, aIndex + 1, iEnv ); |
|
67 |
|
68 TPtrC caption; |
|
69 caption.Set(aCaption); |
|
70 |
|
71 TUriParser parser; |
|
72 TInt err = parser.Parse(aCaption); |
|
73 if (err == KErrNone) |
|
74 { |
|
75 // Remove scheme from the url. |
|
76 const TDesC& host = parser.Extract(EUriHost); |
|
77 if (host.Length()) |
|
78 { |
|
79 caption.Set(host); |
|
80 } |
|
81 } |
|
82 |
|
83 // Format (" \t%S\t\t%S") without %S characters. |
|
84 TInt formatLength = KSettingListboxLineFormat().Length(); |
|
85 |
|
86 HBufC* listBoxLine = |
|
87 HBufC::NewLC(title->Length() + caption.Length() + formatLength); |
|
88 |
|
89 TPtr ptr = listBoxLine->Des(); |
|
90 ptr.Format(KSettingListboxLineFormat, title, &caption); |
|
91 |
|
92 delete iListBoxLine; |
|
93 iListBoxLine = NULL; |
|
94 iListBoxLine = listBoxLine; |
|
95 CleanupStack::Pop(listBoxLine); |
|
96 CleanupStack::PopAndDestroy(title); |
|
97 return *iListBoxLine; |
|
98 } |
|
99 |
|
100 // ======== MEMBER FUNCTIONS ======== |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // Two phased constructor |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 CMCSPluginSettingsModel* CMCSPluginSettingsModel::NewL( CMCSPluginSettings& aPlugin, |
|
107 CCoeEnv* aEnv) |
|
108 { |
|
109 CMCSPluginSettingsModel* self = new (ELeave) CMCSPluginSettingsModel(aPlugin, aEnv); |
|
110 |
|
111 CleanupStack::PushL(self); |
|
112 self->ConstructL(); |
|
113 CleanupStack::Pop(self); |
|
114 |
|
115 return self; |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // First phase construction |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 CMCSPluginSettingsModel::CMCSPluginSettingsModel( CMCSPluginSettings& aPlugin, |
|
123 CCoeEnv* aEnv ) |
|
124 : iPlugin( aPlugin ), |
|
125 iEnv( aEnv ) |
|
126 { |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // Destructor |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 CMCSPluginSettingsModel::~CMCSPluginSettingsModel() |
|
134 { |
|
135 delete iAppList; |
|
136 delete iBkmList; |
|
137 iSettings.Reset(); |
|
138 delete iPluginSettings; |
|
139 delete iPluginId; |
|
140 delete iListBoxLine; |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // Second phase construction |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 void CMCSPluginSettingsModel::ConstructL() |
|
148 { |
|
149 iAppList = CMCSPluginSettingsAppList::NewL(); |
|
150 iAppList->StartL(); |
|
151 iBkmList = CMCSPluginSettingsBkmList::NewL(); |
|
152 } |
|
153 |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // Gets the latest settings from HSPS and updates |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 void CMCSPluginSettingsModel::UpdateSettingsL( const TDesC8& aPluginId ) |
|
160 { |
|
161 if( !iPlugin.Activated() ) |
|
162 { |
|
163 return; |
|
164 } |
|
165 if( !iPluginSettings ) |
|
166 { |
|
167 // AILaunch uid in decimal format |
|
168 iPluginSettings = CHomescreenSettings::NewL( KAppUid, aPluginId, this ); |
|
169 iPluginId = aPluginId.AllocL(); |
|
170 } |
|
171 |
|
172 iSettings.Reset(); |
|
173 RPointerArray<CItemMap> settingItems; |
|
174 CleanupClosePushL( settingItems ); |
|
175 |
|
176 iPluginSettings->GetSettingsL( *iPluginId, settingItems ); |
|
177 |
|
178 TInt count = settingItems.Count(); |
|
179 for ( TInt i = 0; i < count; i++ ) |
|
180 { |
|
181 CItemMap* itemMap = settingItems[i]; |
|
182 RPointerArray<HSPluginSettingsIf::CPropertyMap> properties; |
|
183 properties = itemMap->Properties(); |
|
184 TSettingItem item = ItemL( properties ); |
|
185 iSettings.AppendL( item ); |
|
186 } |
|
187 CleanupStack::Pop( &settingItems ); |
|
188 settingItems.ResetAndDestroy(); |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // Tries to find menuitem which matches given HSPS entry |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 TSettingItem CMCSPluginSettingsModel::ItemL( |
|
196 RPointerArray<HSPluginSettingsIf::CPropertyMap>& aProperties ) |
|
197 { |
|
198 TSettingItem setting = { KErrNotFound, EApplication , EFalse }; |
|
199 |
|
200 TSettingType type = SettingTypeL( aProperties ); |
|
201 if( type == EApplication ) |
|
202 { |
|
203 setting = iAppList->FindItemL( aProperties ); |
|
204 } |
|
205 else if( type == EBookmark ) |
|
206 { |
|
207 setting = iBkmList->FindItemL( aProperties ); |
|
208 } |
|
209 |
|
210 setting.locked = SettingLockedL( aProperties ); |
|
211 |
|
212 return setting; |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // Gets Type (application or bookmark) of given HSPS entry |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 TSettingType CMCSPluginSettingsModel::SettingTypeL( |
|
220 RPointerArray<HSPluginSettingsIf::CPropertyMap>& aProperties ) |
|
221 { |
|
222 TSettingType type( EApplication ); |
|
223 |
|
224 for( TInt i = 0; i < aProperties.Count(); i++ ) |
|
225 { |
|
226 TPtrC8 name = aProperties[i]->Name(); |
|
227 if( name == KProperNameType ) |
|
228 { |
|
229 TPtrC8 value = aProperties[i]->Value(); |
|
230 if( value == KProperValueBookmark ) |
|
231 { |
|
232 type = EBookmark; |
|
233 } |
|
234 else |
|
235 { |
|
236 type = EApplication; |
|
237 } |
|
238 } |
|
239 } |
|
240 |
|
241 return type; |
|
242 } |
|
243 |
|
244 // --------------------------------------------------------------------------- |
|
245 // Gets locking status of given HSPS entry |
|
246 // --------------------------------------------------------------------------- |
|
247 // |
|
248 TBool CMCSPluginSettingsModel::SettingLockedL( |
|
249 RPointerArray<HSPluginSettingsIf::CPropertyMap>& aProperties ) |
|
250 { |
|
251 |
|
252 for( TInt i = 0; i <aProperties.Count(); i++ ) |
|
253 { |
|
254 TPtrC8 name = aProperties[i]->Name(); |
|
255 if( name == KProperNameLocked ) |
|
256 { |
|
257 TPtrC8 value = aProperties[i]->Value(); |
|
258 if( value == KTrue ) |
|
259 { |
|
260 return ETrue; |
|
261 } |
|
262 } |
|
263 } |
|
264 |
|
265 return EFalse; |
|
266 } |
|
267 |
|
268 |
|
269 // --------------------------------------------------------------------------- |
|
270 // Saves menuitem to HSPS to the given shortcut index |
|
271 // --------------------------------------------------------------------------- |
|
272 // |
|
273 void CMCSPluginSettingsModel::SaveSettingsL( const TInt& aIndex, |
|
274 CMenuItem& aMenuItem ) |
|
275 { |
|
276 |
|
277 if ( !iPluginSettings ) |
|
278 { |
|
279 return; |
|
280 } |
|
281 RPointerArray<CItemMap> settingItems; |
|
282 CleanupClosePushL( settingItems ); |
|
283 iPluginSettings->GetSettingsL( *iPluginId, settingItems ); |
|
284 if ( aIndex >= 0 && aIndex < settingItems.Count() ) |
|
285 { |
|
286 TBool exists( EFalse ); |
|
287 CItemMap* itemMap = settingItems[ aIndex ]; |
|
288 RPointerArray<HSPluginSettingsIf::CPropertyMap> properties; |
|
289 properties = itemMap->Properties(); |
|
290 for ( TInt i = 0; i < properties.Count(); i++ ) |
|
291 { |
|
292 if ( properties[ i ]->Name() == KProperNameType ) |
|
293 { |
|
294 TPtrC type = aMenuItem.Type(); |
|
295 if ( type == KMenuTypeUrl ) |
|
296 { |
|
297 properties[ i ]->SetValueL( KProperValueBookmark ); |
|
298 } |
|
299 else if ( type == KMenuTypeFolder ) |
|
300 { |
|
301 properties[ i ]->SetValueL( KProperValueFolder ); |
|
302 } |
|
303 else if ( type == KMenuTypeSuite ) |
|
304 { |
|
305 properties[ i ]->SetValueL( KProperValueSuite ); |
|
306 } |
|
307 else |
|
308 { |
|
309 properties[ i ]->SetValueL( KProperValueAppl ); |
|
310 } |
|
311 } |
|
312 else if ( properties[ i ]->Name() == KProperNameUid ) |
|
313 { |
|
314 TPtrC uid = aMenuItem.GetAttributeL( KMenuAttrUid, exists ); |
|
315 if ( exists ) |
|
316 { |
|
317 HBufC8* uid8( NULL ); |
|
318 uid8 = AiUtility::CopyToBufferL( uid8, uid ); |
|
319 CleanupStack::PushL( uid8 ); |
|
320 properties[ i ]->SetValueL( *uid8 ); |
|
321 CleanupStack::PopAndDestroy( uid8 ); |
|
322 } |
|
323 else |
|
324 { |
|
325 properties[ i ]->SetValueL( KNullDesC8 ); |
|
326 } |
|
327 } |
|
328 else if ( properties[ i ]->Name() == KProperNameView ) |
|
329 { |
|
330 TPtrC view = aMenuItem.GetAttributeL( KMenuAttrView, exists ); |
|
331 if( exists ) |
|
332 { |
|
333 HBufC8* view8( NULL ); |
|
334 view8 = AiUtility::CopyToBufferL( view8, view ); |
|
335 CleanupStack::PushL( view8 ); |
|
336 properties[i]->SetValueL( *view8 ); |
|
337 CleanupStack::PopAndDestroy( view8 ); |
|
338 } |
|
339 else |
|
340 { |
|
341 properties[ i ]->SetValueL( KNullDesC8 ); |
|
342 } |
|
343 } |
|
344 else if ( properties[ i ]->Name() == KProperNameParam ) |
|
345 { |
|
346 TPtrC param = aMenuItem.GetAttributeL( KMenuAttrParam, exists ); |
|
347 TBool isFolder = EFalse; |
|
348 TBool isSuite = EFalse; |
|
349 TPtrC type = aMenuItem.Type(); |
|
350 |
|
351 // is the item folder or suite? |
|
352 |
|
353 if ( type == KMenuTypeFolder ) |
|
354 { |
|
355 isFolder = ETrue; |
|
356 } |
|
357 |
|
358 if ( type == KMenuTypeSuite ) |
|
359 { |
|
360 isSuite = ETrue; |
|
361 } |
|
362 |
|
363 if ( exists || isFolder || isSuite ) |
|
364 { |
|
365 // the folder id is stored |
|
366 // in param attribute in HSPS |
|
367 if ( isFolder ) |
|
368 { |
|
369 TBuf<8> number; |
|
370 number.Num( aMenuItem.Id() ); |
|
371 param.Set( number ); |
|
372 } |
|
373 |
|
374 // the suite_name is stored |
|
375 // in param attribute in HSPS |
|
376 if ( isSuite ) |
|
377 { |
|
378 TBool suiteNameExists = EFalse; |
|
379 TPtrC suiteName = aMenuItem.GetAttributeL( KSuiteName, suiteNameExists ); |
|
380 if ( suiteNameExists ) |
|
381 { |
|
382 param.Set( suiteName ); |
|
383 } |
|
384 } |
|
385 |
|
386 HBufC8* param8( NULL ); |
|
387 param8 = AiUtility::CopyToBufferL( param8, param ); |
|
388 CleanupStack::PushL( param8 ); |
|
389 properties[ i ]->SetValueL( *param8 ); |
|
390 CleanupStack::PopAndDestroy( param8 ); |
|
391 } |
|
392 else |
|
393 { |
|
394 properties[ i ]->SetValueL( KNullDesC8 ); |
|
395 } |
|
396 } |
|
397 else if ( properties[ i ]->Name() == KProperNameLocked ) |
|
398 { |
|
399 TPtrC locked = aMenuItem.GetAttributeL( KMenuAttrLocked, exists ); |
|
400 if ( exists ) |
|
401 { |
|
402 HBufC8* locked8( NULL ); |
|
403 locked8 = AiUtility::CopyToBufferL( locked8, locked ); |
|
404 CleanupStack::PushL( locked8 ); |
|
405 properties[ i ]->SetValueL( *locked8 ); |
|
406 CleanupStack::PopAndDestroy( locked8 ); |
|
407 } |
|
408 else |
|
409 { |
|
410 properties[i]->SetValueL( KNullDesC8 ); |
|
411 } |
|
412 } |
|
413 } |
|
414 } |
|
415 // ETrue tells that modified settings are stored also to plugin reference |
|
416 iPluginSettings->SetSettingsL( *iPluginId, settingItems, ETrue ); |
|
417 CleanupStack::Pop( &settingItems ); |
|
418 settingItems.ResetAndDestroy(); |
|
419 |
|
420 } |
|
421 |
|
422 // --------------------------------------------------------------------------- |
|
423 // Updates settings container. |
|
424 // --------------------------------------------------------------------------- |
|
425 // |
|
426 void CMCSPluginSettingsModel::UpdateSettingsContainerL( const TDesC8& aPluginId ) |
|
427 { |
|
428 if (iContainer) |
|
429 { |
|
430 if (iContainer->IsChangeDialogShowing()) |
|
431 { |
|
432 iContainer->CloseChangeDialog(); |
|
433 } |
|
434 } |
|
435 |
|
436 UpdateSettingsL( aPluginId ); |
|
437 |
|
438 if (iContainer) |
|
439 { |
|
440 iContainer->ResetCurrentListL(0); |
|
441 } |
|
442 } |
|
443 |
|
444 // --------------------------------------------------------------------------- |
|
445 // From MHomeScreenSettingsObserver - handler for HSPS setting change |
|
446 // --------------------------------------------------------------------------- |
|
447 // |
|
448 TInt CMCSPluginSettingsModel::SettingsChangedL( const TDesC8& /*aEvent*/, |
|
449 const TDesC8& /*aPluginName*/, |
|
450 const TDesC8& /*aPluginUid*/, |
|
451 const TDesC8& /*aPluginId*/ ) |
|
452 { |
|
453 return KErrNone; |
|
454 } |
|
455 |
|
456 // --------------------------------------------------------------------------- |
|
457 // From MDesCArray |
|
458 // Returns the number of descriptor elements in a descriptor array. |
|
459 // --------------------------------------------------------------------------- |
|
460 // |
|
461 TInt CMCSPluginSettingsModel::MdcaCount() const |
|
462 { |
|
463 return iSettings.Count(); |
|
464 } |
|
465 |
|
466 // --------------------------------------------------------------------------- |
|
467 // From MDesCArray |
|
468 // Indexes into a descriptor array. |
|
469 // --------------------------------------------------------------------------- |
|
470 // |
|
471 TPtrC CMCSPluginSettingsModel::MdcaPoint( TInt aIndex ) const |
|
472 { |
|
473 if (aIndex < 0 || aIndex >= iSettings.Count()) |
|
474 { |
|
475 TPtrC ret(KNullDesC); |
|
476 return ret; |
|
477 } |
|
478 if ( iSettings[aIndex].type == EApplication ) |
|
479 { |
|
480 const TDesC& caption = iAppList->MdcaPoint( iSettings[aIndex].id ); |
|
481 TPtrC line; |
|
482 TRAP_IGNORE( line.Set( ListBoxLineL( caption, aIndex ) ) ) |
|
483 return line; |
|
484 } |
|
485 else |
|
486 { |
|
487 const TDesC& caption = iBkmList->MdcaPoint( iSettings[aIndex].id ); |
|
488 TPtrC line; |
|
489 TRAP_IGNORE( line.Set( ListBoxLineL( caption, aIndex ) ) ) |
|
490 return line; |
|
491 } |
|
492 } |
|
493 |
|
494 // --------------------------------------------------------------------------- |
|
495 // Returns a setting ID for the given index. |
|
496 // --------------------------------------------------------------------------- |
|
497 // |
|
498 TInt CMCSPluginSettingsModel::ItemId( TInt aIndex ) const |
|
499 { |
|
500 if ( aIndex >= 0 && aIndex < iSettings.Count() ) |
|
501 { |
|
502 return iSettings[ aIndex ].id; |
|
503 } |
|
504 |
|
505 return KErrNotFound; |
|
506 } |
|
507 |
|
508 // --------------------------------------------------------------------------- |
|
509 // Returns a pointer to setting item for the given index |
|
510 // --------------------------------------------------------------------------- |
|
511 // |
|
512 const TSettingItem CMCSPluginSettingsModel::Item( TInt aIndex ) const |
|
513 { |
|
514 TSettingItem setting = { KErrNotFound, EApplication, EFalse }; |
|
515 |
|
516 if ( aIndex >= 0 && aIndex < iSettings.Count() ) |
|
517 { |
|
518 setting = iSettings[ aIndex ]; |
|
519 } |
|
520 |
|
521 return setting; |
|
522 } |
|
523 |
|
524 // --------------------------------------------------------------------------- |
|
525 // Replaces shortcut item at given index by a new one. |
|
526 // --------------------------------------------------------------------------- |
|
527 // |
|
528 TBool CMCSPluginSettingsModel::ReplaceItemL( const TInt& aSettingIndex, |
|
529 TInt aId, |
|
530 TSettingType aType ) |
|
531 { |
|
532 if (aSettingIndex >= 0 && aSettingIndex < iSettings.Count()) |
|
533 { |
|
534 // Old setting type is bookmark. Remove bookmark item from MCS |
|
535 // if it was created in runtime. |
|
536 if( iSettings[aSettingIndex].type == EBookmark ) |
|
537 { |
|
538 iBkmList->RemoveMenuItemL( iSettings[aSettingIndex].id ); |
|
539 } |
|
540 |
|
541 // Old setting type is application. |
|
542 // Remove app item from MCS if it was created in runtime (mailbox). |
|
543 if ( iSettings[ aSettingIndex ].type == EApplication ) |
|
544 { |
|
545 iAppList->RemoveMenuItemL( iSettings[ aSettingIndex ].id ); |
|
546 } |
|
547 |
|
548 iSettings[aSettingIndex].id = aId; |
|
549 iSettings[aSettingIndex].type = aType; |
|
550 |
|
551 if ( aType == EApplication ) |
|
552 { |
|
553 CMenuItem& item = iAppList->ItemL( aId ); |
|
554 SaveSettingsL( aSettingIndex, item ); |
|
555 } |
|
556 else |
|
557 { |
|
558 CMenuItem& item = iBkmList->ItemL( aId ); |
|
559 SaveSettingsL( aSettingIndex, item ); |
|
560 } |
|
561 |
|
562 return ETrue; |
|
563 } |
|
564 return EFalse; |
|
565 } |
|
566 |
|
567 // --------------------------------------------------------------------------- |
|
568 // Sets a container |
|
569 // --------------------------------------------------------------------------- |
|
570 // |
|
571 void CMCSPluginSettingsModel::SetContainer(CMCSPluginSettingsContainer* aContainer) |
|
572 { |
|
573 iContainer = aContainer; |
|
574 } |
|
575 |
|
576 // --------------------------------------------------------------------------- |
|
577 // Returns application list |
|
578 // --------------------------------------------------------------------------- |
|
579 // |
|
580 CMCSPluginSettingsAppList* CMCSPluginSettingsModel::AppList() |
|
581 { |
|
582 return iAppList; |
|
583 } |
|
584 |
|
585 // --------------------------------------------------------------------------- |
|
586 // Returns bookmarklist |
|
587 // --------------------------------------------------------------------------- |
|
588 // |
|
589 CMCSPluginSettingsBkmList* CMCSPluginSettingsModel::BkmList() |
|
590 { |
|
591 return iBkmList; |
|
592 } |
|
593 |
|
594 // --------------------------------------------------------------------------- |
|
595 // Updates application list |
|
596 // --------------------------------------------------------------------------- |
|
597 // |
|
598 void CMCSPluginSettingsModel::UpdateAppListL() |
|
599 { |
|
600 iAppList->StartL(); |
|
601 } |
|
602 |
|
603 // --------------------------------------------------------------------------- |
|
604 // Updates bookmark list |
|
605 // --------------------------------------------------------------------------- |
|
606 // |
|
607 void CMCSPluginSettingsModel::UpdateBkmListL() |
|
608 { |
|
609 delete iBkmList; |
|
610 iBkmList = NULL; |
|
611 iBkmList = CMCSPluginSettingsBkmList::NewL(); |
|
612 } |
|
613 |
|
614 // End of File. |