author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 21:55:16 +0300 | |
branch | RCL_3 |
changeset 31 | 8baec10861af |
parent 30 | a5a39a295112 |
permissions | -rw-r--r-- |
30 | 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: MCS settings plug-in model. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
#include <eikenv.h> |
|
19 |
#include <itemmap.h> |
|
20 |
#include <mhomescreensettingsif.h> |
|
21 |
#include <aistrcnv.h> |
|
22 |
#include <StringLoader.h> |
|
23 |
#include <uri16.h> |
|
24 |
#include <mcspluginsettingsres.rsg> |
|
25 |
#include <mcsmenuitem.h> |
|
26 |
||
27 |
#include "mcspluginsettingsmodel.h" |
|
28 |
#include "mcspluginsettingsapplist.h" |
|
29 |
#include "mcspluginsettingsbkmlist.h" |
|
30 |
#include "mcspluginsettingscontainer.h" |
|
31 |
||
32 |
||
33 |
/** |
|
34 |
* Line format for the settings list box |
|
35 |
*/ |
|
36 |
_LIT(KSettingListboxLineFormat, " \t%S\t\t%S"); |
|
37 |
_LIT( KMenuAttrParam, "param"); |
|
38 |
_LIT( KMenuAttrLocked, "locked"); |
|
39 |
_LIT8( KTrue, "true" ); |
|
40 |
_LIT8( KAppUid, "271012080" ); |
|
41 |
_LIT8( KProperNameType, "type" ); |
|
42 |
_LIT8( KProperNameParam, "param" ); |
|
43 |
_LIT8( KProperNameUid, "uid" ); |
|
44 |
_LIT8( KProperNameView, "view" ); |
|
45 |
_LIT8( KProperNameLocked, "locked" ); |
|
46 |
_LIT8( KProperValueFolder, "folder" ); |
|
47 |
_LIT8( KProperValueSuite, "suite" ); |
|
48 |
_LIT8( KProperValueBookmark, "bookmark" ); |
|
49 |
_LIT8( KProperValueAppl, "application" ); |
|
50 |
_LIT8( KProperValueMailbox, "mailbox" ); |
|
51 |
_LIT( KMenuTypeMailbox, "menu:mailbox" ); |
|
31
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
52 |
_LIT8( KMenuAttrInvokeSettingsUid, "0x99999990" ); |
30 | 53 |
|
54 |
using namespace HSPluginSettingsIf; |
|
55 |
||
56 |
// ======== LOCAL FUNCTIONS ======== |
|
57 |
||
58 |
// ---------------------------------------------------------------------------- |
|
59 |
// CleanupResetAndDestroy() |
|
60 |
// ---------------------------------------------------------------------------- |
|
61 |
// |
|
62 |
template<class T> |
|
63 |
static void CleanupResetAndDestroy( TAny* aObj ) |
|
64 |
{ |
|
65 |
if( aObj ) |
|
66 |
{ |
|
67 |
static_cast<T*>( aObj )->ResetAndDestroy(); |
|
68 |
} |
|
69 |
} |
|
70 |
||
71 |
// ---------------------------------------------------------------------------- |
|
72 |
// CleanupResetAndDestroyPushL |
|
73 |
// ---------------------------------------------------------------------------- |
|
74 |
// |
|
75 |
template<class T> |
|
76 |
static void CleanupResetAndDestroyPushL(T& aArray) |
|
77 |
{ |
|
78 |
CleanupStack::PushL( TCleanupItem( &CleanupResetAndDestroy<T>, &aArray ) ); |
|
79 |
} |
|
80 |
||
81 |
// ======== MEMBER FUNCTIONS ======== |
|
82 |
||
83 |
// ----------------------------------------------------------------------------- |
|
84 |
// Creates a formatted listbox line. |
|
85 |
// ----------------------------------------------------------------------------- |
|
86 |
// |
|
87 |
TPtrC CMCSPluginSettingsModel::ListBoxLineL( const TDesC& aCaption, TInt aIndex ) const |
|
88 |
{ |
|
89 |
HBufC* title = StringLoader::LoadLC( |
|
90 |
R_AI_MCS_SETTINGS_TXT_LINKN, aIndex + 1, iEnv ); |
|
91 |
||
92 |
TPtrC caption; |
|
93 |
caption.Set(aCaption); |
|
94 |
||
95 |
TUriParser parser; |
|
96 |
TInt err = parser.Parse(aCaption); |
|
97 |
if (err == KErrNone) |
|
98 |
{ |
|
99 |
// Remove scheme from the url. |
|
100 |
const TDesC& host = parser.Extract(EUriHost); |
|
101 |
if (host.Length()) |
|
102 |
{ |
|
103 |
caption.Set(host); |
|
104 |
} |
|
105 |
} |
|
106 |
||
107 |
// Format (" \t%S\t\t%S") without %S characters. |
|
108 |
TInt formatLength = KSettingListboxLineFormat().Length(); |
|
109 |
||
110 |
HBufC* listBoxLine = |
|
111 |
HBufC::NewLC( title->Length() + |
|
112 |
caption.Length() + |
|
113 |
formatLength ); |
|
114 |
||
115 |
TPtr ptr = listBoxLine->Des(); |
|
116 |
ptr.Format(KSettingListboxLineFormat, title, &caption); |
|
117 |
||
118 |
delete iListBoxLine; |
|
119 |
iListBoxLine = NULL; |
|
120 |
iListBoxLine = listBoxLine; |
|
121 |
CleanupStack::Pop(listBoxLine); |
|
122 |
CleanupStack::PopAndDestroy(title); |
|
123 |
return *iListBoxLine; |
|
124 |
} |
|
125 |
||
126 |
// ======== MEMBER FUNCTIONS ======== |
|
127 |
||
128 |
// --------------------------------------------------------------------------- |
|
129 |
// Two phased constructor |
|
130 |
// --------------------------------------------------------------------------- |
|
131 |
// |
|
132 |
CMCSPluginSettingsModel* CMCSPluginSettingsModel::NewL( CMCSPluginSettings& aPlugin, |
|
133 |
CCoeEnv* aEnv) |
|
134 |
{ |
|
135 |
CMCSPluginSettingsModel* self = new (ELeave) CMCSPluginSettingsModel(aPlugin, aEnv); |
|
136 |
||
137 |
CleanupStack::PushL(self); |
|
138 |
self->ConstructL(); |
|
139 |
CleanupStack::Pop(self); |
|
140 |
||
141 |
return self; |
|
142 |
} |
|
143 |
||
144 |
// --------------------------------------------------------------------------- |
|
145 |
// First phase construction |
|
146 |
// --------------------------------------------------------------------------- |
|
147 |
// |
|
148 |
CMCSPluginSettingsModel::CMCSPluginSettingsModel( CMCSPluginSettings& aPlugin, |
|
149 |
CCoeEnv* aEnv ) |
|
150 |
: iPlugin( aPlugin ), |
|
151 |
iEnv( aEnv ) |
|
152 |
{ |
|
153 |
} |
|
154 |
||
155 |
// --------------------------------------------------------------------------- |
|
156 |
// Destructor |
|
157 |
// --------------------------------------------------------------------------- |
|
158 |
// |
|
159 |
CMCSPluginSettingsModel::~CMCSPluginSettingsModel() |
|
160 |
{ |
|
161 |
delete iAppList; |
|
162 |
delete iBkmList; |
|
163 |
iSettings.Reset(); |
|
164 |
delete iPluginId; |
|
165 |
delete iListBoxLine; |
|
166 |
||
167 |
CHomescreenSettings::UnInitialize(); |
|
168 |
iPluginSettings = NULL; |
|
169 |
} |
|
170 |
||
171 |
// --------------------------------------------------------------------------- |
|
172 |
// Second phase construction |
|
173 |
// --------------------------------------------------------------------------- |
|
174 |
// |
|
175 |
void CMCSPluginSettingsModel::ConstructL() |
|
176 |
{ |
|
177 |
CHomescreenSettings::InitializeL( KAppUid ); |
|
178 |
||
179 |
iPluginSettings = CHomescreenSettings::Instance(); |
|
180 |
if( iPluginSettings == NULL ) |
|
181 |
{ |
|
182 |
User::Leave( KErrUnknown ); |
|
183 |
} |
|
184 |
} |
|
185 |
||
186 |
// --------------------------------------------------------------------------- |
|
187 |
// Gets the latest settings from HSPS and updates |
|
188 |
// --------------------------------------------------------------------------- |
|
189 |
// |
|
190 |
void CMCSPluginSettingsModel::UpdateSettingsL() |
|
191 |
{ |
|
192 |
iSettings.Reset(); |
|
193 |
if( !iPluginId ) |
|
194 |
{ |
|
195 |
return; |
|
196 |
} |
|
197 |
||
198 |
if (iContainer) |
|
199 |
{ |
|
200 |
iContainer->CloseChangeDialog(); |
|
201 |
} |
|
202 |
||
203 |
RPointerArray<CItemMap> settingItems; |
|
204 |
CleanupResetAndDestroyPushL( settingItems ); |
|
205 |
||
206 |
User::LeaveIfError( |
|
207 |
iPluginSettings->GetSettingsL( *iPluginId, settingItems ) ); |
|
208 |
||
209 |
for ( TInt i = 0; i < settingItems.Count(); i++ ) |
|
210 |
{ |
|
211 |
CItemMap* itemMap = settingItems[i]; |
|
212 |
// get properties |
|
213 |
RPointerArray<HSPluginSettingsIf::CPropertyMap>& properties |
|
214 |
= itemMap->Properties(); |
|
215 |
TSettingItem item = ItemL( properties ); |
|
216 |
iSettings.AppendL( item ); |
|
217 |
} |
|
218 |
||
219 |
CleanupStack::PopAndDestroy(); // settingItems |
|
220 |
||
221 |
if (iContainer) |
|
222 |
{ |
|
223 |
iContainer->ResetCurrentListL(0); |
|
224 |
} |
|
225 |
} |
|
226 |
||
227 |
// --------------------------------------------------------------------------- |
|
228 |
// Tries to find menuitem which matches given HSPS entry |
|
229 |
// --------------------------------------------------------------------------- |
|
230 |
// |
|
231 |
TSettingItem CMCSPluginSettingsModel::ItemL( |
|
232 |
RPointerArray<HSPluginSettingsIf::CPropertyMap>& aProperties ) |
|
233 |
{ |
|
31
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
234 |
TSettingItem setting = { KErrNotFound, EApplication , EFalse, EFalse }; |
30 | 235 |
|
236 |
TSettingType type = SettingTypeL( aProperties ); |
|
237 |
if ( type == EApplication || type == EMailbox ) |
|
238 |
{ |
|
239 |
setting = iAppList->FindItemL( aProperties ); |
|
240 |
} |
|
241 |
else if ( type == EBookmark ) |
|
242 |
{ |
|
243 |
setting = iBkmList->FindItemL( aProperties ); |
|
244 |
} |
|
245 |
||
246 |
setting.locked = SettingLockedL( aProperties ); |
|
31
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
247 |
setting.empty = SettingEmptyL( aProperties ); |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
248 |
|
30 | 249 |
return setting; |
250 |
} |
|
251 |
||
252 |
// --------------------------------------------------------------------------- |
|
253 |
// Gets Type (application or bookmark) of given HSPS entry |
|
254 |
// --------------------------------------------------------------------------- |
|
255 |
// |
|
256 |
TSettingType CMCSPluginSettingsModel::SettingTypeL( |
|
257 |
RPointerArray<HSPluginSettingsIf::CPropertyMap>& aProperties ) |
|
258 |
{ |
|
259 |
TSettingType type( EApplication ); |
|
260 |
||
261 |
for( TInt i = 0; i < aProperties.Count(); i++ ) |
|
262 |
{ |
|
263 |
TPtrC8 name = aProperties[i]->Name(); |
|
264 |
if( name == KProperNameType ) |
|
265 |
{ |
|
266 |
TPtrC8 value = aProperties[i]->Value(); |
|
267 |
if( value == KProperValueBookmark ) |
|
268 |
{ |
|
269 |
type = EBookmark; |
|
270 |
} |
|
271 |
else |
|
272 |
{ |
|
273 |
type = EApplication; |
|
274 |
} |
|
275 |
} |
|
276 |
} |
|
277 |
||
278 |
return type; |
|
279 |
} |
|
280 |
||
281 |
// --------------------------------------------------------------------------- |
|
282 |
// Gets locking status of given HSPS entry |
|
283 |
// --------------------------------------------------------------------------- |
|
284 |
// |
|
285 |
TBool CMCSPluginSettingsModel::SettingLockedL( |
|
286 |
RPointerArray<HSPluginSettingsIf::CPropertyMap>& aProperties ) |
|
287 |
{ |
|
288 |
||
289 |
for( TInt i = 0; i <aProperties.Count(); i++ ) |
|
290 |
{ |
|
291 |
TPtrC8 name = aProperties[i]->Name(); |
|
292 |
if( name == KProperNameLocked ) |
|
293 |
{ |
|
294 |
TPtrC8 value = aProperties[i]->Value(); |
|
295 |
if( value == KTrue ) |
|
296 |
{ |
|
297 |
return ETrue; |
|
298 |
} |
|
299 |
} |
|
300 |
} |
|
301 |
||
302 |
return EFalse; |
|
303 |
} |
|
304 |
||
305 |
// --------------------------------------------------------------------------- |
|
31
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
306 |
// Gets empty status of given HSPS entry |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
307 |
// --------------------------------------------------------------------------- |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
308 |
// |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
309 |
TBool CMCSPluginSettingsModel::SettingEmptyL( |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
310 |
RPointerArray<HSPluginSettingsIf::CPropertyMap>& aProperties ) |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
311 |
{ |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
312 |
|
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
313 |
for( TInt i = 0; i <aProperties.Count(); i++ ) |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
314 |
{ |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
315 |
TPtrC8 name = aProperties[i]->Name(); |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
316 |
if( name == KProperNameUid ) |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
317 |
{ |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
318 |
TPtrC8 value = aProperties[i]->Value(); |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
319 |
if( value.Compare(KMenuAttrInvokeSettingsUid) == 0 ) |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
320 |
{ |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
321 |
return ETrue; |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
322 |
} |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
323 |
} |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
324 |
} |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
325 |
|
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
326 |
return EFalse; |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
327 |
} |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
328 |
|
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
329 |
// --------------------------------------------------------------------------- |
30 | 330 |
// Saves menuitem to HSPS to the given shortcut index |
331 |
// --------------------------------------------------------------------------- |
|
332 |
// |
|
333 |
void CMCSPluginSettingsModel::SaveSettingsL( const TInt& aIndex, |
|
334 |
CMenuItem& aMenuItem ) |
|
335 |
{ |
|
336 |
if( !iPluginId ) |
|
337 |
{ |
|
338 |
return; |
|
339 |
} |
|
340 |
||
341 |
RPointerArray<CItemMap> settingItems; |
|
342 |
CleanupResetAndDestroyPushL( settingItems ); |
|
343 |
User::LeaveIfError( iPluginSettings->GetSettingsL( *iPluginId, settingItems ) ); |
|
344 |
||
345 |
if ( aIndex >= 0 && aIndex < settingItems.Count() ) |
|
346 |
{ |
|
347 |
TBool exists( EFalse ); |
|
348 |
CItemMap* itemMap = settingItems[ aIndex ]; |
|
349 |
||
350 |
// get properties |
|
351 |
RPointerArray<HSPluginSettingsIf::CPropertyMap>& properties |
|
352 |
= itemMap->Properties(); |
|
353 |
||
354 |
const TInt KGranularity = 6; |
|
355 |
CDesC8Array* propertiesList = new ( ELeave ) CDesC8ArrayFlat( KGranularity ); |
|
356 |
CleanupStack::PushL( propertiesList ); |
|
357 |
propertiesList->AppendL( KProperNameType ); |
|
358 |
propertiesList->AppendL( KProperNameParam ); |
|
359 |
propertiesList->AppendL( KProperNameUid ); |
|
360 |
propertiesList->AppendL( KProperNameView ); |
|
361 |
// skip KProperNameLocked property, attribute may be missing. results into |
|
362 |
// leave with -1 when saving settings |
|
363 |
||
364 |
// add missing properties |
|
365 |
for ( TInt i=0; i<propertiesList->Count(); i++ ) |
|
366 |
{ |
|
367 |
TBool found( EFalse ); |
|
368 |
const TPtrC8 namePtr = propertiesList->MdcaPoint( i ); |
|
369 |
for ( TInt j=0; j<properties.Count() && !found; j++ ) |
|
370 |
{ |
|
371 |
found = ( (namePtr == properties[ j ]->Name() ) ? ETrue : EFalse ); |
|
372 |
} |
|
373 |
if ( !found ) |
|
374 |
{ |
|
375 |
CPropertyMap* property = CPropertyMap::NewLC(); |
|
376 |
property->SetNameL( namePtr ); |
|
377 |
property->SetValueL( KNullDesC8 ); |
|
378 |
itemMap->AddPropertyMapL( property ); |
|
379 |
CleanupStack::Pop( property ); |
|
380 |
||
381 |
// get updated list |
|
382 |
properties = itemMap->Properties(); |
|
383 |
} |
|
384 |
} |
|
385 |
CleanupStack::PopAndDestroy( propertiesList ); |
|
386 |
||
387 |
for ( TInt i = 0; i < properties.Count(); i++ ) |
|
388 |
{ |
|
389 |
if ( properties[ i ]->Name() == KProperNameType ) |
|
390 |
{ |
|
391 |
TPtrC type = aMenuItem.Type(); |
|
392 |
if ( type == KMenuTypeUrl ) |
|
393 |
{ |
|
394 |
properties[ i ]->SetValueL( KProperValueBookmark ); |
|
395 |
} |
|
396 |
else if ( type == KMenuTypeFolder ) |
|
397 |
{ |
|
398 |
properties[ i ]->SetValueL( KProperValueFolder ); |
|
399 |
} |
|
400 |
else if ( type == KMenuTypeSuite ) |
|
401 |
{ |
|
402 |
properties[ i ]->SetValueL( KProperValueSuite ); |
|
403 |
} |
|
404 |
else if( type == KMenuTypeMailbox ) |
|
405 |
{ |
|
406 |
properties[ i ]->SetValueL( KProperValueMailbox ); |
|
407 |
} |
|
408 |
else |
|
409 |
{ |
|
410 |
properties[ i ]->SetValueL( KProperValueAppl ); |
|
411 |
} |
|
412 |
} |
|
413 |
else if ( properties[ i ]->Name() == KProperNameUid ) |
|
414 |
{ |
|
415 |
TPtrC uid = aMenuItem.GetAttributeL( KMenuAttrUid, exists ); |
|
416 |
if ( exists && uid.Length() > 0 ) |
|
417 |
{ |
|
418 |
HBufC8* uid8( NULL ); |
|
419 |
uid8 = AiUtility::CopyToBufferL( uid8, uid ); |
|
420 |
CleanupStack::PushL( uid8 ); |
|
421 |
properties[ i ]->SetValueL( *uid8 ); |
|
422 |
CleanupStack::PopAndDestroy( uid8 ); |
|
423 |
} |
|
424 |
else |
|
425 |
{ |
|
426 |
properties[ i ]->SetValueL( KNullDesC8 ); |
|
427 |
} |
|
428 |
} |
|
429 |
else if ( properties[ i ]->Name() == KProperNameView ) |
|
430 |
{ |
|
31
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
431 |
TPtrC type = aMenuItem.Type(); |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
432 |
TPtrC attr; |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
433 |
if ( type == KMenuTypeUrl ) |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
434 |
{ |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
435 |
// In case of bookmark type item, bookmark URL is stored to view property |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
436 |
attr.Set( KMenuAttrUrl ); |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
437 |
} |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
438 |
else |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
439 |
{ |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
440 |
attr.Set( KMenuAttrView ); |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
441 |
} |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
442 |
TPtrC view = aMenuItem.GetAttributeL( attr, exists ); |
30 | 443 |
if( exists && view.Length() > 0 ) |
444 |
{ |
|
445 |
HBufC8* view8( NULL ); |
|
446 |
view8 = AiUtility::CopyToBufferL( view8, view ); |
|
447 |
CleanupStack::PushL( view8 ); |
|
448 |
properties[i]->SetValueL( *view8 ); |
|
449 |
CleanupStack::PopAndDestroy( view8 ); |
|
450 |
} |
|
451 |
else |
|
452 |
{ |
|
453 |
properties[ i ]->SetValueL( KNullDesC8 ); |
|
454 |
} |
|
455 |
} |
|
456 |
else if ( properties[ i ]->Name() == KProperNameParam ) |
|
457 |
{ |
|
458 |
TPtrC param = aMenuItem.GetAttributeL( KMenuAttrParam, exists ); |
|
459 |
TBool isFolder = EFalse; |
|
460 |
TPtrC type = aMenuItem.Type(); |
|
461 |
||
462 |
// is the item folder or suite? |
|
463 |
||
464 |
if ( type == KMenuTypeFolder ) |
|
465 |
{ |
|
466 |
isFolder = ETrue; |
|
467 |
} |
|
468 |
||
469 |
if ( (exists && param.Length() > 0) || (isFolder) ) |
|
470 |
{ |
|
471 |
// the folder id is stored |
|
472 |
// in param attribute in HSPS |
|
473 |
if ( isFolder ) |
|
474 |
{ |
|
475 |
TBuf<8> number; |
|
476 |
number.Num( aMenuItem.Id() ); |
|
477 |
param.Set( number ); |
|
478 |
} |
|
479 |
||
480 |
HBufC8* param8( NULL ); |
|
481 |
param8 = AiUtility::CopyToBufferL( param8, param ); |
|
482 |
CleanupStack::PushL( param8 ); |
|
483 |
properties[ i ]->SetValueL( *param8 ); |
|
484 |
CleanupStack::PopAndDestroy( param8 ); |
|
485 |
} |
|
486 |
else |
|
487 |
{ |
|
488 |
properties[ i ]->SetValueL( KNullDesC8 ); |
|
489 |
} |
|
490 |
} |
|
491 |
else if ( properties[ i ]->Name() == KProperNameLocked ) |
|
492 |
{ |
|
493 |
TPtrC locked = aMenuItem.GetAttributeL( KMenuAttrLocked, exists ); |
|
494 |
if ( exists && locked.Length() > 0 ) |
|
495 |
{ |
|
496 |
HBufC8* locked8( NULL ); |
|
497 |
locked8 = AiUtility::CopyToBufferL( locked8, locked ); |
|
498 |
CleanupStack::PushL( locked8 ); |
|
499 |
properties[ i ]->SetValueL( *locked8 ); |
|
500 |
CleanupStack::PopAndDestroy( locked8 ); |
|
501 |
} |
|
502 |
else |
|
503 |
{ |
|
504 |
properties[i]->SetValueL( KNullDesC8 ); |
|
505 |
} |
|
506 |
} |
|
507 |
} |
|
508 |
} |
|
509 |
||
31
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
510 |
// EFalse tells that modified settings are not stored to plugin reference |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
511 |
User::LeaveIfError( iPluginSettings->SetSettingsL( *iPluginId, settingItems, EFalse ) ); |
30 | 512 |
CleanupStack::PopAndDestroy(); // settingItems |
513 |
} |
|
514 |
||
515 |
// --------------------------------------------------------------------------- |
|
516 |
// Updates settings container. |
|
517 |
// --------------------------------------------------------------------------- |
|
518 |
// |
|
519 |
void CMCSPluginSettingsModel::SetPluginIdL( const TDesC8& aPluginId ) |
|
520 |
{ |
|
521 |
delete iPluginId; |
|
522 |
iPluginId = NULL; |
|
523 |
iPluginId = aPluginId.AllocL(); |
|
524 |
} |
|
525 |
||
526 |
// --------------------------------------------------------------------------- |
|
527 |
// From MDesCArray |
|
528 |
// Returns the number of descriptor elements in a descriptor array. |
|
529 |
// --------------------------------------------------------------------------- |
|
530 |
// |
|
531 |
TInt CMCSPluginSettingsModel::MdcaCount() const |
|
532 |
{ |
|
533 |
return iSettings.Count(); |
|
534 |
} |
|
535 |
||
536 |
// --------------------------------------------------------------------------- |
|
537 |
// From MDesCArray |
|
538 |
// Indexes into a descriptor array. |
|
539 |
// --------------------------------------------------------------------------- |
|
540 |
// |
|
541 |
TPtrC CMCSPluginSettingsModel::MdcaPoint( TInt aIndex ) const |
|
542 |
{ |
|
543 |
if (aIndex < 0 || aIndex >= iSettings.Count()) |
|
544 |
{ |
|
545 |
TPtrC ret(KNullDesC); |
|
546 |
return ret; |
|
547 |
} |
|
548 |
||
549 |
TPtrC line( KNullDesC ); |
|
550 |
if ( iSettings[aIndex].type == EApplication ) |
|
551 |
{ |
|
552 |
// first, we need to check if the item is missing |
|
553 |
// (application uninstalled or mmc card removed) |
|
554 |
// If it is, we return "Undefined" application name instead |
|
31
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
555 |
// In case of empty item, it's own name is returned |
30 | 556 |
if ( iSettings[ aIndex ].id == KErrNotFound ) |
557 |
{ |
|
31
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
558 |
if ( iSettings[ aIndex ].empty ) |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
559 |
{ |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
560 |
const TDesC& caption = iAppList->EmptyText(); |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
561 |
TRAP_IGNORE( line.Set( ListBoxLineL( caption, aIndex ) ) ) |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
562 |
} |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
563 |
else |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
564 |
{ |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
565 |
const TDesC& caption = iAppList->UndefinedText(); |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
566 |
TRAP_IGNORE( line.Set( ListBoxLineL( caption, aIndex ) ) ) |
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
567 |
} |
30 | 568 |
} |
569 |
else |
|
570 |
{ |
|
571 |
const TDesC& caption = iAppList->MdcaPoint( iSettings[ aIndex ].id ); |
|
572 |
TRAP_IGNORE( line.Set( ListBoxLineL( caption, aIndex ) ) ) |
|
573 |
} |
|
574 |
} |
|
575 |
else |
|
576 |
{ |
|
577 |
const TDesC& caption = iBkmList->MdcaPoint( iSettings[aIndex].id ); |
|
578 |
TRAP_IGNORE( line.Set( ListBoxLineL( caption, aIndex ) ) ) |
|
579 |
} |
|
580 |
||
581 |
return line; |
|
582 |
} |
|
583 |
||
584 |
// --------------------------------------------------------------------------- |
|
585 |
// Returns a setting ID for the given index. |
|
586 |
// --------------------------------------------------------------------------- |
|
587 |
// |
|
588 |
TInt CMCSPluginSettingsModel::ItemId( TInt aIndex ) const |
|
589 |
{ |
|
590 |
if ( aIndex >= 0 && aIndex < iSettings.Count() ) |
|
591 |
{ |
|
592 |
return iSettings[ aIndex ].id; |
|
593 |
} |
|
594 |
||
595 |
return KErrNotFound; |
|
596 |
} |
|
597 |
||
598 |
// --------------------------------------------------------------------------- |
|
599 |
// Returns a pointer to setting item for the given index |
|
600 |
// --------------------------------------------------------------------------- |
|
601 |
// |
|
602 |
const TSettingItem CMCSPluginSettingsModel::Item( TInt aIndex ) const |
|
603 |
{ |
|
31
8baec10861af
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
604 |
TSettingItem setting = { KErrNotFound, EApplication, EFalse, EFalse }; |
30 | 605 |
|
606 |
if ( aIndex >= 0 && aIndex < iSettings.Count() ) |
|
607 |
{ |
|
608 |
setting = iSettings[ aIndex ]; |
|
609 |
} |
|
610 |
||
611 |
return setting; |
|
612 |
} |
|
613 |
||
614 |
// --------------------------------------------------------------------------- |
|
615 |
// Replaces shortcut item at given index by a new one. |
|
616 |
// --------------------------------------------------------------------------- |
|
617 |
// |
|
618 |
TBool CMCSPluginSettingsModel::ReplaceItemL( const TInt& aSettingIndex, |
|
619 |
TInt aId, |
|
620 |
TSettingType aType ) |
|
621 |
{ |
|
622 |
TBool replaced( EFalse ); |
|
623 |
if (aSettingIndex >= 0 && aSettingIndex < iSettings.Count()) |
|
624 |
{ |
|
625 |
CMenuItem* item( NULL ); |
|
626 |
if ( aType == EApplication ) |
|
627 |
{ |
|
628 |
item = iAppList->ItemL( aId ); |
|
629 |
} |
|
630 |
else |
|
631 |
{ |
|
632 |
item = iBkmList->ItemL( aId ); |
|
633 |
} |
|
634 |
||
635 |
if ( item ) |
|
636 |
{ |
|
637 |
SaveSettingsL( aSettingIndex, *item ); |
|
638 |
iSettings[ aSettingIndex ].id = aId; |
|
639 |
iSettings[ aSettingIndex ].type = aType; |
|
640 |
replaced = ETrue; |
|
641 |
} |
|
642 |
} |
|
643 |
return replaced; |
|
644 |
} |
|
645 |
||
646 |
// --------------------------------------------------------------------------- |
|
647 |
// Sets a container |
|
648 |
// --------------------------------------------------------------------------- |
|
649 |
// |
|
650 |
void CMCSPluginSettingsModel::SetContainer(CMCSPluginSettingsContainer* aContainer) |
|
651 |
{ |
|
652 |
iContainer = aContainer; |
|
653 |
} |
|
654 |
||
655 |
// --------------------------------------------------------------------------- |
|
656 |
// Returns application list |
|
657 |
// --------------------------------------------------------------------------- |
|
658 |
// |
|
659 |
CMCSPluginSettingsAppList* CMCSPluginSettingsModel::AppList() |
|
660 |
{ |
|
661 |
return iAppList; |
|
662 |
} |
|
663 |
||
664 |
// --------------------------------------------------------------------------- |
|
665 |
// Returns bookmarklist |
|
666 |
// --------------------------------------------------------------------------- |
|
667 |
// |
|
668 |
CMCSPluginSettingsBkmList* CMCSPluginSettingsModel::BkmList() |
|
669 |
{ |
|
670 |
return iBkmList; |
|
671 |
} |
|
672 |
||
673 |
// --------------------------------------------------------------------------- |
|
674 |
// Updates application list |
|
675 |
// --------------------------------------------------------------------------- |
|
676 |
// |
|
677 |
void CMCSPluginSettingsModel::UpdateAppListL( TBool aUpdateSettings ) |
|
678 |
{ |
|
679 |
if( !iAppList ) |
|
680 |
{ |
|
681 |
iAppList = CMCSPluginSettingsAppList::NewL(); |
|
682 |
} |
|
683 |
iAppList->StartL(); |
|
684 |
if ( aUpdateSettings ) |
|
685 |
{ |
|
686 |
UpdateSettingsL(); |
|
687 |
} |
|
688 |
} |
|
689 |
||
690 |
// --------------------------------------------------------------------------- |
|
691 |
// Updates bookmark list |
|
692 |
// --------------------------------------------------------------------------- |
|
693 |
// |
|
694 |
void CMCSPluginSettingsModel::UpdateBkmListL( TBool aUpdateSettings ) |
|
695 |
{ |
|
696 |
delete iBkmList; |
|
697 |
iBkmList = NULL; |
|
698 |
iBkmList = CMCSPluginSettingsBkmList::NewL(); |
|
699 |
if ( aUpdateSettings ) |
|
700 |
{ |
|
701 |
UpdateSettingsL(); |
|
702 |
} |
|
703 |
} |
|
704 |
||
705 |
// End of File. |