|
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: |
|
15 * |
|
16 */ |
|
17 #include <mcsmenuitem.h> |
|
18 #include <mcsmenufilter.h> |
|
19 #include <itemmap.h> |
|
20 #include <aistrcnv.h> |
|
21 |
|
22 #include "mcsplugindata.h" |
|
23 #include "mcspluginengine.h" |
|
24 |
|
25 using namespace HSPluginSettingsIf; |
|
26 |
|
27 _LIT8( KAppUid, "271012080" ); |
|
28 _LIT( KMenuAttrParam, "param" ); |
|
29 _LIT( KMenuAttrLocked, "locked" ); |
|
30 _LIT8( KProperNameType, "type" ); |
|
31 _LIT8( KProperNameParam, "param" ); |
|
32 _LIT8( KProperNameUid, "uid" ); |
|
33 _LIT8( KProperNameView, "view" ); |
|
34 _LIT8( KProperValueFolder, "folder" ); |
|
35 _LIT8( KProperValueSuite, "suite" ); |
|
36 _LIT8( KProperValueBookmark, "bookmark" ); |
|
37 _LIT8( KProperValueAppl, "application" ); |
|
38 _LIT( KMCSPlugin, "MCSPlugin" ); |
|
39 _LIT( KSuiteName, "suite_name" ); |
|
40 |
|
41 // ======== LOCAL FUNCTIONS ======== |
|
42 |
|
43 static void ItemMapArrayCleanupFunc( TAny* aPointerArray ) |
|
44 { |
|
45 RPointerArray<CItemMap>* p = static_cast<RPointerArray<CItemMap>*>( aPointerArray ); |
|
46 p->ResetAndDestroy(); |
|
47 p->Close(); |
|
48 } |
|
49 |
|
50 // ======== MEMBER FUNCTIONS ======== |
|
51 |
|
52 void TMCSData::SetMenuItem( TMenuItem& aMenuItem ) |
|
53 { |
|
54 iMenuItem = aMenuItem; |
|
55 } |
|
56 |
|
57 TMenuItem& TMCSData::MenuItem() |
|
58 { |
|
59 return iMenuItem; |
|
60 } |
|
61 |
|
62 void TMCSData::SetDirty( TBool aDirty ) |
|
63 { |
|
64 iDirty = aDirty; |
|
65 } |
|
66 |
|
67 TBool TMCSData::IsDirty() const |
|
68 { |
|
69 return iDirty; |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // Symbian 2nd phase constructor can leave |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 CMCSPluginData* CMCSPluginData::NewL( CMCSPluginEngine& aEngine, const TDesC8& aInstanceUid ) |
|
77 { |
|
78 CMCSPluginData* self = new (ELeave) CMCSPluginData( aEngine, aInstanceUid ); |
|
79 CleanupStack::PushL( self ); |
|
80 self->ConstructL(); |
|
81 CleanupStack::Pop( self ); |
|
82 |
|
83 return self; |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // Default constructor |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 CMCSPluginData::CMCSPluginData( CMCSPluginEngine& aEngine, const TDesC8& aInstanceUid ) |
|
91 : iEngine( aEngine ), iInstanceUid( aInstanceUid ) |
|
92 { |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // Symbian 2nd phase constructor can leave |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 void CMCSPluginData::ConstructL() |
|
100 { |
|
101 // AILaunch uid in decimal format |
|
102 iPluginSettings = CHomescreenSettings::NewL( KAppUid, |
|
103 iInstanceUid, |
|
104 this ); |
|
105 UpdateDataL(); |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // Destructor |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 CMCSPluginData::~CMCSPluginData() |
|
113 { |
|
114 iData.Close(); |
|
115 delete iPluginSettings; |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // Gets the instance specific settings from HSPS and creates data items |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void CMCSPluginData::UpdateDataL() |
|
123 { |
|
124 RPointerArray<CItemMap> settings; |
|
125 TCleanupItem settingsCleanupItem( ItemMapArrayCleanupFunc, &settings ); |
|
126 CleanupStack::PushL( settingsCleanupItem ); |
|
127 iPluginSettings->GetSettingsL( iInstanceUid, settings ); |
|
128 TInt count = settings.Count(); |
|
129 for( TInt i = 0; i < count; i++ ) |
|
130 { |
|
131 CItemMap* itemMap = settings[i]; |
|
132 RPointerArray<HSPluginSettingsIf::CPropertyMap>& properties |
|
133 = itemMap->Properties(); |
|
134 TMenuItem item = CreateMenuItemL( properties ); |
|
135 TMCSData data; |
|
136 TInt id = -1; |
|
137 |
|
138 if ( count == iData.Count() ) |
|
139 { |
|
140 id = iData[i].MenuItem().Id(); |
|
141 } |
|
142 |
|
143 if ( id > 0 ) |
|
144 { |
|
145 if ( item.Id() != id ) |
|
146 { |
|
147 data.SetMenuItem( item ); |
|
148 data.SetDirty( ETrue ); |
|
149 iData.Remove( i ); |
|
150 iData.InsertL( data, i ); |
|
151 } |
|
152 } |
|
153 else |
|
154 { |
|
155 data.SetMenuItem( item ); |
|
156 data.SetDirty( ETrue ); |
|
157 iData.AppendL( data ); |
|
158 } |
|
159 } |
|
160 |
|
161 CleanupStack::PopAndDestroy(); // settingsCleanupItem |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 TInt CMCSPluginData::SettingsChangedL( const TDesC8& /*aEvent*/, const TDesC8& /*aPluginName*/, |
|
169 const TDesC8& /*aPluginUid*/, const TDesC8& /*aPluginId*/ ) |
|
170 { |
|
171 UpdateDataL(); |
|
172 return KErrNone; |
|
173 } |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // Gets the menu item from engine using the setting properties as filter |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 TMenuItem CMCSPluginData::CreateMenuItemL( RPointerArray<HSPluginSettingsIf::CPropertyMap>& aProperties ) |
|
180 { |
|
181 CMenuFilter* filter = CMenuFilter::NewLC(); |
|
182 |
|
183 // Exclude 'view' and 'param' attributes from search criteria by default |
|
184 // Criterias will be added to filter if setting defines them |
|
185 filter->DoNotHaveAttributeL( KMenuAttrView ); |
|
186 filter->DoNotHaveAttributeL( KMenuAttrParam ); |
|
187 TBool isFolder = EFalse; |
|
188 TBool isSuite = EFalse; |
|
189 |
|
190 // first, we need to check if the item is folder or suite |
|
191 for ( TInt i = 0; i < aProperties.Count(); i++ ) |
|
192 { |
|
193 if ( aProperties[i]->Name() == KProperNameType ) |
|
194 { |
|
195 if ( aProperties[i]->Value() == KProperValueFolder ) |
|
196 { |
|
197 isFolder = ETrue; |
|
198 } |
|
199 |
|
200 if ( aProperties[i]->Value() == KProperValueSuite ) |
|
201 { |
|
202 isSuite = ETrue; |
|
203 } |
|
204 |
|
205 break; |
|
206 } |
|
207 } |
|
208 |
|
209 // then add all property/value pairs to the filter |
|
210 for ( TInt i = 0; i < aProperties.Count(); i++ ) |
|
211 { |
|
212 |
|
213 // skip the type property |
|
214 if( aProperties[i]->Name() == KProperNameType ) |
|
215 { |
|
216 continue; |
|
217 } |
|
218 |
|
219 HBufC* name( NULL ); |
|
220 HBufC* value( NULL ); |
|
221 name = AiUtility::CopyToBufferL( name, aProperties[i]->Name() ); |
|
222 CleanupStack::PushL( name ); |
|
223 value = AiUtility::CopyToBufferL( value, aProperties[i]->Value() ); |
|
224 CleanupStack::PushL( value ); |
|
225 |
|
226 if ( value->Length() != 0 ) |
|
227 { |
|
228 // in case of folder/suite, we just have to extract |
|
229 // id from param attribute and return item with this id |
|
230 if ( aProperties[i]->Name() == KProperNameParam && ( isFolder || isSuite ) ) |
|
231 { |
|
232 |
|
233 TMenuItem item; |
|
234 |
|
235 // set the type |
|
236 if ( isFolder ) |
|
237 { |
|
238 // convert id to integer |
|
239 TInt id; |
|
240 TLex16 lextmp( value->Ptr() ); |
|
241 lextmp.Val( id ); |
|
242 item.SetType( KMenuTypeFolder ); |
|
243 item.SetId( id ); |
|
244 } |
|
245 |
|
246 if ( isSuite ) |
|
247 { |
|
248 CMenuFilter* suitefilter = CMenuFilter::NewLC(); |
|
249 // Exclude 'view' and 'param' attributes from search criteria by default |
|
250 // Criterias will be added to filter if setting defines them |
|
251 suitefilter->DoNotHaveAttributeL( KMenuAttrView ); |
|
252 suitefilter->DoNotHaveAttributeL( KMenuAttrParam ); |
|
253 suitefilter->HaveAttributeL( KSuiteName, *value ); |
|
254 // locked property excluded from search pattern |
|
255 suitefilter->DoNotHaveAttributeL( KMenuAttrLocked ); |
|
256 item = iEngine.FindMenuItemL( *suitefilter ); |
|
257 CleanupStack::PopAndDestroy( suitefilter ); |
|
258 |
|
259 } |
|
260 |
|
261 CleanupStack::PopAndDestroy( value ); |
|
262 CleanupStack::PopAndDestroy( name ); |
|
263 CleanupStack::PopAndDestroy( filter ); |
|
264 |
|
265 return item; |
|
266 } |
|
267 else |
|
268 { |
|
269 // otherwise, we just add name/value into filter |
|
270 filter->HaveAttributeL( *name, *value ); |
|
271 } |
|
272 } |
|
273 CleanupStack::PopAndDestroy( value ); |
|
274 CleanupStack::PopAndDestroy( name ); |
|
275 } |
|
276 |
|
277 // locked property excluded from search pattern |
|
278 filter->DoNotHaveAttributeL( KMenuAttrLocked ); |
|
279 |
|
280 TMenuItem item = iEngine.FindMenuItemL( *filter ); |
|
281 CleanupStack::PopAndDestroy( filter ); |
|
282 return item; |
|
283 } |
|
284 |
|
285 // --------------------------------------------------------------------------- |
|
286 // Returns menu item for given index |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 TMCSData& CMCSPluginData::DataItemL( TInt aIndex ) |
|
290 { |
|
291 if( aIndex < 0 || aIndex >= iData.Count()) |
|
292 { |
|
293 User::Leave( KErrArgument ); |
|
294 } |
|
295 return iData[aIndex]; |
|
296 } |
|
297 |
|
298 // --------------------------------------------------------------------------- |
|
299 // Replaces menuitem in data instance |
|
300 // --------------------------------------------------------------------------- |
|
301 // |
|
302 void CMCSPluginData::ReplaceMenuItemL( const TInt& aIndex, TMenuItem& aMenuItem ) |
|
303 { |
|
304 TMCSData& data = iData[aIndex]; |
|
305 data.SetMenuItem( aMenuItem ); |
|
306 data.SetDirty( ETrue ); |
|
307 } |
|
308 |
|
309 // --------------------------------------------------------------------------- |
|
310 // Save the setting persistently to HSPS |
|
311 // TODO HSPS setting api should be changed so that items and properties can |
|
312 // be added/removed dynamically. Now widgetconfiguration.xml must have all the |
|
313 // properties for every item even though property is not used. |
|
314 // It makes this function more compolicated. |
|
315 // --------------------------------------------------------------------------- |
|
316 // |
|
317 void CMCSPluginData::SaveSettingsL( const TInt& aIndex, CMenuItem& aMenuItem ) |
|
318 { |
|
319 RPointerArray<CItemMap> settingItems; |
|
320 CleanupClosePushL( settingItems ); |
|
321 iPluginSettings->GetSettingsL( iInstanceUid, settingItems ); |
|
322 if ( aIndex >= 0 && aIndex < settingItems.Count() ) |
|
323 { |
|
324 TBool exists( EFalse ); |
|
325 CItemMap* itemMap = settingItems[aIndex]; |
|
326 RPointerArray<HSPluginSettingsIf::CPropertyMap> properties; |
|
327 properties = itemMap->Properties(); |
|
328 for ( TInt i= 0; i < properties.Count(); i++ ) |
|
329 { |
|
330 if ( properties[i]->Name() == KProperNameType ) |
|
331 { |
|
332 TPtrC type = aMenuItem.Type(); |
|
333 if ( type == KMenuTypeUrl ) |
|
334 { |
|
335 properties[i]->SetValueL( KProperValueBookmark ); |
|
336 } |
|
337 else |
|
338 { |
|
339 properties[i]->SetValueL( KProperValueAppl ); |
|
340 } |
|
341 } |
|
342 else if ( properties[i]->Name() == KProperNameUid ) |
|
343 { |
|
344 TPtrC uid = aMenuItem.GetAttributeL( KMenuAttrUid, exists ); |
|
345 if ( exists ) |
|
346 { |
|
347 HBufC8* uid8( NULL ); |
|
348 uid8 = AiUtility::CopyToBufferL( uid8, uid ); |
|
349 CleanupStack::PushL( uid8 ); |
|
350 properties[i]->SetValueL( *uid8 ); |
|
351 CleanupStack::PopAndDestroy( uid8 ); |
|
352 } |
|
353 else |
|
354 { |
|
355 properties[i]->SetValueL( KNullDesC8 ); |
|
356 } |
|
357 } |
|
358 else if ( properties[i]->Name() == KProperNameView ) |
|
359 { |
|
360 TPtrC view = aMenuItem.GetAttributeL( KMenuAttrView, exists ); |
|
361 if ( exists ) |
|
362 { |
|
363 HBufC8* view8( NULL ); |
|
364 view8 = AiUtility::CopyToBufferL( view8, view ); |
|
365 CleanupStack::PushL( view8 ); |
|
366 properties[i]->SetValueL( *view8 ); |
|
367 CleanupStack::PopAndDestroy( view8 ); |
|
368 } |
|
369 else |
|
370 { |
|
371 properties[i]->SetValueL( KNullDesC8 ); |
|
372 } |
|
373 } |
|
374 else if ( properties[i]->Name() == KProperNameParam ) |
|
375 { |
|
376 TPtrC param = aMenuItem.GetAttributeL( KMenuAttrParam, exists ); |
|
377 if ( exists ) |
|
378 { |
|
379 HBufC8* param8( NULL ); |
|
380 param8 = AiUtility::CopyToBufferL( param8, param ); |
|
381 CleanupStack::PushL( param8 ); |
|
382 properties[i]->SetValueL( *param8 ); |
|
383 CleanupStack::PopAndDestroy( param8 ); |
|
384 } |
|
385 else |
|
386 { |
|
387 properties[i]->SetValueL( KNullDesC8 ); |
|
388 } |
|
389 } |
|
390 } |
|
391 } |
|
392 // ETrue tells that changes are stored also to plugin reference |
|
393 iPluginSettings->SetSettingsL( iInstanceUid, settingItems, ETrue ); |
|
394 CleanupStack::PopAndDestroy( &settingItems ); |
|
395 } |
|
396 |