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 |
|
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 TPtrC type = aMenuItem.Type(); |
|
349 |
|
350 // is the item folder or suite? |
|
351 |
|
352 if ( type == KMenuTypeFolder ) |
|
353 { |
|
354 isFolder = ETrue; |
|
355 } |
|
356 |
|
357 if ( exists || isFolder ) |
|
358 { |
|
359 // the folder id is stored |
|
360 // in param attribute in HSPS |
|
361 if ( isFolder ) |
|
362 { |
|
363 TBuf<8> number; |
|
364 number.Num( aMenuItem.Id() ); |
|
365 param.Set( number ); |
|
366 } |
|
367 |
|
368 HBufC8* param8( NULL ); |
|
369 param8 = AiUtility::CopyToBufferL( param8, param ); |
|
370 CleanupStack::PushL( param8 ); |
|
371 properties[ i ]->SetValueL( *param8 ); |
|
372 CleanupStack::PopAndDestroy( param8 ); |
|
373 } |
|
374 else |
|
375 { |
|
376 properties[ i ]->SetValueL( KNullDesC8 ); |
|
377 } |
|
378 } |
|
379 else if ( properties[ i ]->Name() == KProperNameLocked ) |
|
380 { |
|
381 TPtrC locked = aMenuItem.GetAttributeL( KMenuAttrLocked, exists ); |
|
382 if ( exists ) |
|
383 { |
|
384 HBufC8* locked8( NULL ); |
|
385 locked8 = AiUtility::CopyToBufferL( locked8, locked ); |
|
386 CleanupStack::PushL( locked8 ); |
|
387 properties[ i ]->SetValueL( *locked8 ); |
|
388 CleanupStack::PopAndDestroy( locked8 ); |
|
389 } |
|
390 else |
|
391 { |
|
392 properties[i]->SetValueL( KNullDesC8 ); |
|
393 } |
|
394 } |
|
395 } |
|
396 } |
|
397 // ETrue tells that modified settings are stored also to plugin reference |
|
398 iPluginSettings->SetSettingsL( *iPluginId, settingItems, ETrue ); |
|
399 CleanupStack::Pop( &settingItems ); |
|
400 settingItems.ResetAndDestroy(); |
|
401 |
|
402 } |
|
403 |
|
404 // --------------------------------------------------------------------------- |
|
405 // Updates settings container. |
|
406 // --------------------------------------------------------------------------- |
|
407 // |
|
408 void CMCSPluginSettingsModel::UpdateSettingsContainerL( const TDesC8& aPluginId ) |
|
409 { |
|
410 if (iContainer) |
|
411 { |
|
412 if (iContainer->IsChangeDialogShowing()) |
|
413 { |
|
414 iContainer->CloseChangeDialog(); |
|
415 } |
|
416 } |
|
417 |
|
418 UpdateSettingsL( aPluginId ); |
|
419 |
|
420 if (iContainer) |
|
421 { |
|
422 iContainer->ResetCurrentListL(0); |
|
423 } |
|
424 } |
|
425 |
|
426 // --------------------------------------------------------------------------- |
|
427 // From MHomeScreenSettingsObserver - handler for HSPS setting change |
|
428 // --------------------------------------------------------------------------- |
|
429 // |
|
430 TInt CMCSPluginSettingsModel::SettingsChangedL( const TDesC8& /*aEvent*/, |
|
431 const TDesC8& /*aPluginName*/, |
|
432 const TDesC8& /*aPluginUid*/, |
|
433 const TDesC8& /*aPluginId*/ ) |
|
434 { |
|
435 return KErrNone; |
|
436 } |
|
437 |
|
438 // --------------------------------------------------------------------------- |
|
439 // From MDesCArray |
|
440 // Returns the number of descriptor elements in a descriptor array. |
|
441 // --------------------------------------------------------------------------- |
|
442 // |
|
443 TInt CMCSPluginSettingsModel::MdcaCount() const |
|
444 { |
|
445 return iSettings.Count(); |
|
446 } |
|
447 |
|
448 // --------------------------------------------------------------------------- |
|
449 // From MDesCArray |
|
450 // Indexes into a descriptor array. |
|
451 // --------------------------------------------------------------------------- |
|
452 // |
|
453 TPtrC CMCSPluginSettingsModel::MdcaPoint( TInt aIndex ) const |
|
454 { |
|
455 if (aIndex < 0 || aIndex >= iSettings.Count()) |
|
456 { |
|
457 TPtrC ret(KNullDesC); |
|
458 return ret; |
|
459 } |
|
460 if ( iSettings[aIndex].type == EApplication ) |
|
461 { |
|
462 const TDesC& caption = iAppList->MdcaPoint( iSettings[aIndex].id ); |
|
463 TPtrC line; |
|
464 TRAP_IGNORE( line.Set( ListBoxLineL( caption, aIndex ) ) ) |
|
465 return line; |
|
466 } |
|
467 else |
|
468 { |
|
469 const TDesC& caption = iBkmList->MdcaPoint( iSettings[aIndex].id ); |
|
470 TPtrC line; |
|
471 TRAP_IGNORE( line.Set( ListBoxLineL( caption, aIndex ) ) ) |
|
472 return line; |
|
473 } |
|
474 } |
|
475 |
|
476 // --------------------------------------------------------------------------- |
|
477 // Returns a setting ID for the given index. |
|
478 // --------------------------------------------------------------------------- |
|
479 // |
|
480 TInt CMCSPluginSettingsModel::ItemId( TInt aIndex ) const |
|
481 { |
|
482 if ( aIndex >= 0 && aIndex < iSettings.Count() ) |
|
483 { |
|
484 return iSettings[ aIndex ].id; |
|
485 } |
|
486 |
|
487 return KErrNotFound; |
|
488 } |
|
489 |
|
490 // --------------------------------------------------------------------------- |
|
491 // Returns a pointer to setting item for the given index |
|
492 // --------------------------------------------------------------------------- |
|
493 // |
|
494 const TSettingItem CMCSPluginSettingsModel::Item( TInt aIndex ) const |
|
495 { |
|
496 TSettingItem setting = { KErrNotFound, EApplication, EFalse }; |
|
497 |
|
498 if ( aIndex >= 0 && aIndex < iSettings.Count() ) |
|
499 { |
|
500 setting = iSettings[ aIndex ]; |
|
501 } |
|
502 |
|
503 return setting; |
|
504 } |
|
505 |
|
506 // --------------------------------------------------------------------------- |
|
507 // Replaces shortcut item at given index by a new one. |
|
508 // --------------------------------------------------------------------------- |
|
509 // |
|
510 TBool CMCSPluginSettingsModel::ReplaceItemL( const TInt& aSettingIndex, |
|
511 TInt aId, |
|
512 TSettingType aType ) |
|
513 { |
|
514 if (aSettingIndex >= 0 && aSettingIndex < iSettings.Count()) |
|
515 { |
|
516 // Old setting type is bookmark. Remove bookmark item from MCS |
|
517 // if it was created in runtime. |
|
518 if( iSettings[aSettingIndex].type == EBookmark ) |
|
519 { |
|
520 iBkmList->RemoveMenuItemL( iSettings[aSettingIndex].id ); |
|
521 } |
|
522 |
|
523 // Old setting type is application. |
|
524 // Remove app item from MCS if it was created in runtime (mailbox). |
|
525 if ( iSettings[ aSettingIndex ].type == EApplication ) |
|
526 { |
|
527 iAppList->RemoveMenuItemL( iSettings[ aSettingIndex ].id ); |
|
528 } |
|
529 |
|
530 iSettings[aSettingIndex].id = aId; |
|
531 iSettings[aSettingIndex].type = aType; |
|
532 |
|
533 if ( aType == EApplication ) |
|
534 { |
|
535 CMenuItem& item = iAppList->ItemL( aId ); |
|
536 SaveSettingsL( aSettingIndex, item ); |
|
537 } |
|
538 else |
|
539 { |
|
540 CMenuItem& item = iBkmList->ItemL( aId ); |
|
541 SaveSettingsL( aSettingIndex, item ); |
|
542 } |
|
543 |
|
544 return ETrue; |
|
545 } |
|
546 return EFalse; |
|
547 } |
|
548 |
|
549 // --------------------------------------------------------------------------- |
|
550 // Sets a container |
|
551 // --------------------------------------------------------------------------- |
|
552 // |
|
553 void CMCSPluginSettingsModel::SetContainer(CMCSPluginSettingsContainer* aContainer) |
|
554 { |
|
555 iContainer = aContainer; |
|
556 } |
|
557 |
|
558 // --------------------------------------------------------------------------- |
|
559 // Returns application list |
|
560 // --------------------------------------------------------------------------- |
|
561 // |
|
562 CMCSPluginSettingsAppList* CMCSPluginSettingsModel::AppList() |
|
563 { |
|
564 return iAppList; |
|
565 } |
|
566 |
|
567 // --------------------------------------------------------------------------- |
|
568 // Returns bookmarklist |
|
569 // --------------------------------------------------------------------------- |
|
570 // |
|
571 CMCSPluginSettingsBkmList* CMCSPluginSettingsModel::BkmList() |
|
572 { |
|
573 return iBkmList; |
|
574 } |
|
575 |
|
576 // --------------------------------------------------------------------------- |
|
577 // Updates application list |
|
578 // --------------------------------------------------------------------------- |
|
579 // |
|
580 void CMCSPluginSettingsModel::UpdateAppListL() |
|
581 { |
|
582 iAppList->StartL(); |
|
583 } |
|
584 |
|
585 // --------------------------------------------------------------------------- |
|
586 // Updates bookmark list |
|
587 // --------------------------------------------------------------------------- |
|
588 // |
|
589 void CMCSPluginSettingsModel::UpdateBkmListL() |
|
590 { |
|
591 delete iBkmList; |
|
592 iBkmList = NULL; |
|
593 iBkmList = CMCSPluginSettingsBkmList::NewL(); |
|
594 } |
|
595 |
|
596 // End of File. |
|