1 /* |
1 /* |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2009 - 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
13 * |
13 * |
14 * Description: Bookmark list for settings listbox |
14 * Description: Bookmark list for settings listbox |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 #include <favouritesitemlist.h> |
19 #include <StringLoader.h> |
|
20 #include <activefavouritesdbnotifier.h> // For CActiveFavouritesDbNotifier |
|
21 #include <aistrcnv.h> |
19 #include <aistrcnv.h> |
22 #include <mcsmenufilter.h> |
20 #include <mcsmenufilter.h> |
23 #include <mcsmenuitem.h> |
21 #include <mcsmenuitem.h> |
24 #include <mcsmenuoperation.h> |
|
25 #include <mcspluginsettingsres.rsg> |
|
26 |
22 |
27 #include "mcspluginsettingsmodel.h" |
23 #include "mcspluginsettingsmodel.h" |
28 #include "mcspluginsettingsapplist.h" |
|
29 #include "mcspluginsettingsbkmlist.h" |
24 #include "mcspluginsettingsbkmlist.h" |
30 #include "mcspluginwatcher.h" |
|
31 #include "debug.h" |
|
32 |
25 |
33 _LIT( KMyMenuData, "matrixmenudata" ); |
26 _LIT( KMyMenuData, "matrixmenudata" ); |
34 _LIT( KMenuUrl, "menu:url" ); |
27 _LIT( KMenuUrl, "menu:url" ); |
35 _LIT( KMenuIconFile, "aimcsplugin.mif" ); |
|
36 _LIT( KMenuIconId, "16386" ); |
|
37 _LIT( KMenuMaskId, "16387" ); |
|
38 _LIT( KUrl, "url" ); |
28 _LIT( KUrl, "url" ); |
39 _LIT8( KUid, "uid" ); |
29 _LIT8( KUid, "uid" ); |
40 _LIT( KMenuAttrRefcount, "ref_count" ); |
30 _LIT( KMenuAttrParameter, "param" ); |
41 _LIT( KInitialRefCount, "1" ); |
|
42 _LIT( KMCSFolder, "mcsplugin_folder" ); |
|
43 |
|
44 |
31 |
45 // ======== MEMBER FUNCTIONS ======== |
32 // ======== MEMBER FUNCTIONS ======== |
46 |
33 |
47 |
34 |
48 // --------------------------------------------------------------------------- |
35 // --------------------------------------------------------------------------- |
49 // First-phase construction |
36 // First-phase construction |
50 // --------------------------------------------------------------------------- |
37 // --------------------------------------------------------------------------- |
51 // |
38 // |
52 CMCSPluginSettingsBkmList::CMCSPluginSettingsBkmList() |
39 CMCSPluginSettingsBkmList::CMCSPluginSettingsBkmList() |
53 { |
40 { |
54 iMCSPluginFolderId = 0; |
|
55 } |
41 } |
56 |
42 |
57 // --------------------------------------------------------------------------- |
43 // --------------------------------------------------------------------------- |
58 // Second-phase construction |
44 // Second-phase construction |
59 // --------------------------------------------------------------------------- |
45 // --------------------------------------------------------------------------- |
62 { |
48 { |
63 User::LeaveIfError(iBookmarkSess.Connect()); |
49 User::LeaveIfError(iBookmarkSess.Connect()); |
64 User::LeaveIfError(iBookmarkDb.Open(iBookmarkSess, KBrowserBookmarks)); |
50 User::LeaveIfError(iBookmarkDb.Open(iBookmarkSess, KBrowserBookmarks)); |
65 iMenu.OpenL( KMyMenuData ); |
51 iMenu.OpenL( KMyMenuData ); |
66 GetBookmarkListL(); |
52 GetBookmarkListL(); |
67 |
|
68 iSaveWatcher = CMCSPluginWatcher::NewL( CMCSPluginWatcher::EOperation ); |
|
69 iUpdateWatcher = CMCSPluginWatcher::NewL( CMCSPluginWatcher::EOperation ); |
|
70 iRemoveWatcher = CMCSPluginWatcher::NewL( CMCSPluginWatcher::EOperation ); |
|
71 } |
53 } |
72 |
54 |
73 // --------------------------------------------------------------------------- |
55 // --------------------------------------------------------------------------- |
74 // Two-phased constructor |
56 // Two-phased constructor |
75 // --------------------------------------------------------------------------- |
57 // --------------------------------------------------------------------------- |
92 iListItems.ResetAndDestroy(); |
74 iListItems.ResetAndDestroy(); |
93 iMenuItems.ResetAndDestroy(); |
75 iMenuItems.ResetAndDestroy(); |
94 iBookmarkDb.Close(); |
76 iBookmarkDb.Close(); |
95 iBookmarkSess.Close(); |
77 iBookmarkSess.Close(); |
96 iMenu.Close(); |
78 iMenu.Close(); |
97 delete iSaveWatcher; |
|
98 delete iUpdateWatcher; |
|
99 delete iRemoveWatcher; |
|
100 } |
79 } |
101 |
80 |
102 // --------------------------------------------------------------------------- |
81 // --------------------------------------------------------------------------- |
103 // From MDesCArray |
82 // From MDesCArray |
104 // Returns the number of descriptor elements in a descriptor array. |
83 // Returns the number of descriptor elements in a descriptor array. |
130 // --------------------------------------------------------------------------- |
109 // --------------------------------------------------------------------------- |
131 // |
110 // |
132 TSettingItem CMCSPluginSettingsBkmList::FindItemL( RPointerArray<HSPluginSettingsIf::CPropertyMap>& aProperties ) |
111 TSettingItem CMCSPluginSettingsBkmList::FindItemL( RPointerArray<HSPluginSettingsIf::CPropertyMap>& aProperties ) |
133 { |
112 { |
134 TInt index( KErrNotFound ); |
113 TInt index( KErrNotFound ); |
135 TSettingItem settingItem = { KErrNotFound, EBookmark }; |
114 TSettingItem settingItem = { KErrNotFound, EBookmark, EFalse }; |
136 for( TInt i= 0; i < aProperties.Count(); i++ ) |
115 for( TInt i= 0; i < aProperties.Count(); i++ ) |
137 { |
116 { |
138 if( aProperties[i]->Name() == KUid ) |
117 if( aProperties[i]->Name() == KUid ) |
139 { |
118 { |
140 HBufC* value( NULL ); |
119 HBufC* value( NULL ); |
216 CMenuItem* menuItem = CMenuItem::OpenL( iMenu, itemArray[i] ); |
195 CMenuItem* menuItem = CMenuItem::OpenL( iMenu, itemArray[i] ); |
217 CleanupStack::PushL( menuItem ); |
196 CleanupStack::PushL( menuItem ); |
218 TPtrC uid = menuItem->GetAttributeL( KMenuAttrUid, exists ); |
197 TPtrC uid = menuItem->GetAttributeL( KMenuAttrUid, exists ); |
219 TPtrC name = menuItem->GetAttributeL( KMenuAttrLongName, exists ); |
198 TPtrC name = menuItem->GetAttributeL( KMenuAttrLongName, exists ); |
220 TPtrC url = menuItem->GetAttributeL( KUrl, exists ); |
199 TPtrC url = menuItem->GetAttributeL( KUrl, exists ); |
221 |
200 // if exists, add it |
222 // Check if bookmark is already present in Bookmark list. |
201 if ( exists ) |
223 // This may happen in case of Favourite Bookmarks that were |
|
224 // previously added to MCS. |
|
225 // If it is, do not add it to Bookmark list anymore. |
|
226 |
|
227 TBool isRuntimeGenerated = EFalse; |
|
228 menuItem->GetAttributeL( KMenuAttrRefcount, isRuntimeGenerated ); |
|
229 |
|
230 // if is not runtime generated and url exists, add it |
|
231 if ( !isRuntimeGenerated && exists ) |
|
232 { |
202 { |
233 AddBookmarkL( uid, name, url, EMCSBookmark ); |
203 AddBookmarkL( uid, name, url, EMCSBookmark ); |
234 } |
204 } |
235 |
205 |
236 CleanupStack::PopAndDestroy( menuItem ); |
206 CleanupStack::PopAndDestroy( menuItem ); |
249 CMenuItem& CMCSPluginSettingsBkmList::ItemL( TInt aIndex ) |
219 CMenuItem& CMCSPluginSettingsBkmList::ItemL( TInt aIndex ) |
250 { |
220 { |
251 CMenuItem* menuItem( NULL ); |
221 CMenuItem* menuItem( NULL ); |
252 CBkmListItem* listItem = iListItems[aIndex]; |
222 CBkmListItem* listItem = iListItems[aIndex]; |
253 if ( listItem->iType == EFavBookmark ) |
223 if ( listItem->iType == EFavBookmark ) |
254 { |
224 { |
255 TPtrC uid = *listItem->iUid; |
225 menuItem = CreateMenuItemL( *listItem->iUid, *listItem->iCaption, *listItem->iUrl ); |
256 TPtrC name = *listItem->iCaption; |
|
257 TPtrC url = *listItem->iUrl; |
|
258 menuItem = CreateMenuItemL( uid, name, url ); |
|
259 } |
226 } |
260 else |
227 else |
261 { |
228 { |
262 menuItem = MCSMenuItemL( *listItem->iUid, *listItem->iCaption, *listItem->iUrl ); |
229 menuItem = MCSMenuItemL( *listItem->iUid, *listItem->iCaption, *listItem->iUrl ); |
263 } |
230 } |
264 return *menuItem; |
231 return *menuItem; |
265 } |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // Removes the menu item from MCS if it was created in runtime i.e. type is EFavBookmark. |
|
269 // Favourite bookmarks have ref_count attribute, which is decremented everytime |
|
270 // the bookmark is removed from some shortcut. When this counter reaches 0, |
|
271 // its MenuItem is removed from MCS. |
|
272 // --------------------------------------------------------------------------- |
|
273 // |
|
274 void CMCSPluginSettingsBkmList::RemoveMenuItemL( TInt aIndex ) |
|
275 { |
|
276 |
|
277 if ( aIndex < 0 || aIndex > iListItems.Count() - 1 ) |
|
278 { |
|
279 return; |
|
280 } |
|
281 |
|
282 CBkmListItem* listItem = iListItems[aIndex]; |
|
283 if( listItem->iType == EFavBookmark ) |
|
284 { |
|
285 CMenuItem* menuItem = MCSMenuItemL( *listItem->iUid, *listItem->iCaption, *listItem->iUrl ); |
|
286 if ( !menuItem ) |
|
287 { |
|
288 return; |
|
289 } |
|
290 // decrement ref_count attribute |
|
291 TInt newRefCount = UpdateMenuItemsRefCountL( menuItem, -1 ); |
|
292 if ( newRefCount > 0 ) |
|
293 { |
|
294 CleanupStack::PushL( menuItem ); |
|
295 CMenuOperation* op = menuItem->SaveL( iUpdateWatcher->iStatus ); |
|
296 CleanupStack::Pop( menuItem ); |
|
297 iUpdateWatcher->Watch( op ); |
|
298 } |
|
299 else if ( newRefCount == 0 ) |
|
300 { |
|
301 // counter reached 0 -> item is not referenced by any shortcut |
|
302 // so remove it from MCS |
|
303 if ( iRemoveWatcher->IsActive() ) |
|
304 { |
|
305 return; |
|
306 } |
|
307 CMenuOperation* op = iMenu.RemoveL( menuItem->Id(), iRemoveWatcher->iStatus ); |
|
308 iRemoveWatcher->Watch( op ); |
|
309 } |
|
310 } |
|
311 } |
232 } |
312 |
233 |
313 // --------------------------------------------------------------------------- |
234 // --------------------------------------------------------------------------- |
314 // Tries to find menuitem with given UID, Name and Url in MCS, |
235 // Tries to find menuitem with given UID, Name and Url in MCS, |
315 // If it does not exist, it is created and saved there. |
236 // If it does not exist, it is created and saved there. |
318 // |
239 // |
319 CMenuItem* CMCSPluginSettingsBkmList::CreateMenuItemL( const TDesC& aUid, |
240 CMenuItem* CMCSPluginSettingsBkmList::CreateMenuItemL( const TDesC& aUid, |
320 const TDesC& aName, |
241 const TDesC& aName, |
321 const TDesC& aUrl ) |
242 const TDesC& aUrl ) |
322 { |
243 { |
323 // try to search item in MCS |
244 CMenuItem* newItem = CMenuItem::CreateL( iMenu, KMenuTypeUrl, 0, 0 ); |
324 CMenuItem* item = MCSMenuItemL( aUid, aName, aUrl ); |
245 CleanupStack::PushL( newItem ); |
325 |
246 newItem->SetAttributeL( KMenuAttrUid, aUid ); |
326 if ( item == NULL ) |
247 newItem->SetAttributeL( KMenuAttrLongName, aName ); |
327 { |
248 newItem->SetAttributeL( KMenuAttrView, aUrl ); |
328 // Item does not exist in MCS yet. |
249 newItem->SetAttributeL( KMenuAttrParameter, aName ); |
329 // We will add a new one with reference counter set to 1. |
250 iMenuItems.AppendL( newItem ); |
330 CMenuItem* newItem = CMenuItem::CreateL( iMenu, |
251 CleanupStack::Pop( newItem ); |
331 KMenuTypeUrl, |
252 return newItem; |
332 GetMCSPluginFolderIdL(), 0 ); |
|
333 CleanupStack::PushL( newItem ); |
|
334 |
|
335 newItem->SetAttributeL( KMenuAttrUid, aUid ); |
|
336 newItem->SetAttributeL( KMenuAttrLongName, aName ); |
|
337 newItem->SetAttributeL( KMenuAttrIconFile, KMenuIconFile ); |
|
338 newItem->SetAttributeL( KMenuAttrIconId, KMenuIconId ); |
|
339 newItem->SetAttributeL( KMenuAttrMaskId, KMenuMaskId ); |
|
340 newItem->SetAttributeL( KMenuAttrRefcount, KInitialRefCount ); |
|
341 newItem->SetAttributeL( KUrl , aUrl ); |
|
342 |
|
343 CMenuOperation* op = newItem->SaveL( iSaveWatcher->iStatus ); |
|
344 iSaveWatcher->Watch( op ); |
|
345 iMenuItems.AppendL( newItem ); |
|
346 CleanupStack::Pop( newItem ); |
|
347 return newItem; |
|
348 } |
|
349 else |
|
350 { |
|
351 // Item already exists in MCS |
|
352 // If it has reference counter, increment it before returning. |
|
353 TInt newRefCount = UpdateMenuItemsRefCountL( item, 1 ); |
|
354 if ( newRefCount > -1 ) |
|
355 { |
|
356 CleanupStack::PushL( item ); |
|
357 CMenuOperation* op = item->SaveL( iSaveWatcher->iStatus ); |
|
358 CleanupStack::Pop( item ); |
|
359 iSaveWatcher->Watch( op ); |
|
360 } |
|
361 } |
|
362 return item; |
|
363 } |
253 } |
364 |
254 |
365 // --------------------------------------------------------------------------- |
255 // --------------------------------------------------------------------------- |
366 // Finds menuitem with given UID, Name and URL in MCS and returns it |
256 // Finds menuitem with given UID, Name and URL in MCS and returns it |
367 // --------------------------------------------------------------------------- |
257 // --------------------------------------------------------------------------- |
414 User::LeaveIfError(iListItems.InsertInOrderAllowRepeats(listItem, sortMethod)); |
304 User::LeaveIfError(iListItems.InsertInOrderAllowRepeats(listItem, sortMethod)); |
415 CleanupStack::Pop(listItem); |
305 CleanupStack::Pop(listItem); |
416 } |
306 } |
417 |
307 |
418 // --------------------------------------------------------------------------- |
308 // --------------------------------------------------------------------------- |
419 // Updates the bookmark list. |
|
420 // --------------------------------------------------------------------------- |
|
421 // |
|
422 void CMCSPluginSettingsBkmList::UpdateBkmListL() |
|
423 { |
|
424 GetBookmarkListL(); |
|
425 } |
|
426 |
|
427 // --------------------------------------------------------------------------- |
|
428 //Nested class to store individual bookmark list items |
309 //Nested class to store individual bookmark list items |
429 // --------------------------------------------------------------------------- |
310 // --------------------------------------------------------------------------- |
430 // |
311 // |
431 CMCSPluginSettingsBkmList::CBkmListItem::CBkmListItem() |
312 CMCSPluginSettingsBkmList::CBkmListItem::CBkmListItem() |
432 { |
313 { |
484 TPtrC CMCSPluginSettingsBkmList::CBkmListItem::Caption() const |
365 TPtrC CMCSPluginSettingsBkmList::CBkmListItem::Caption() const |
485 { |
366 { |
486 return TPtrC(*iCaption); |
367 return TPtrC(*iCaption); |
487 } |
368 } |
488 |
369 |
489 // --------------------------------------------------------------------------- |
|
490 // Gets MCS Plugin folder ID. This hidden folder in matrixmenudata.xml is used |
|
491 // for storing run-time generated menuitems |
|
492 // --------------------------------------------------------------------------- |
|
493 // |
|
494 TInt CMCSPluginSettingsBkmList::GetMCSPluginFolderIdL() |
|
495 { |
|
496 if ( iMCSPluginFolderId == 0 ) |
|
497 { |
|
498 CMenuItem* item( NULL ); |
|
499 CMenuFilter* filter = CMenuFilter::NewL(); |
|
500 CleanupStack::PushL( filter ); |
|
501 filter->SetType( KMenuTypeFolder ); |
|
502 filter->HaveAttributeL( KMenuAttrLongName, KMCSFolder ); |
|
503 const TInt rootId = iMenu.RootFolderL(); |
|
504 RArray<TMenuItem> itemArray; |
|
505 CleanupClosePushL( itemArray ); |
|
506 iMenu.GetItemsL( itemArray, rootId, filter, ETrue ); |
|
507 if ( itemArray.Count() > 0 ) |
|
508 { |
|
509 item = CMenuItem::OpenL( iMenu, itemArray[0] ); |
|
510 iMCSPluginFolderId = item->Id(); |
|
511 } |
|
512 else |
|
513 { |
|
514 iMCSPluginFolderId = iMenu.RootFolderL(); |
|
515 } |
|
516 CleanupStack::PopAndDestroy( &itemArray ); |
|
517 CleanupStack::PopAndDestroy( filter ); |
|
518 delete item; |
|
519 } |
|
520 return iMCSPluginFolderId; |
|
521 } |
|
522 |
|
523 // --------------------------------------------------------------------------- |
|
524 // Helper method for updating ref_count attribute of run-time generated |
|
525 // menuitems |
|
526 // --------------------------------------------------------------------------- |
|
527 // |
|
528 TInt CMCSPluginSettingsBkmList::UpdateMenuItemsRefCountL( CMenuItem* aItem, |
|
529 TInt aValueToAdd ) |
|
530 { |
|
531 |
|
532 TBool exists = EFalse; |
|
533 CleanupStack::PushL( aItem ); |
|
534 TPtrC param = aItem->GetAttributeL( KMenuAttrRefcount, exists ); |
|
535 CleanupStack::Pop( aItem ); |
|
536 if ( exists ) |
|
537 { |
|
538 TInt references; |
|
539 TLex16 lextmp( param ); |
|
540 lextmp.Val( references ); |
|
541 references += aValueToAdd; |
|
542 TBuf<128> buf; |
|
543 buf.NumUC( references ); |
|
544 |
|
545 // set new ref_count |
|
546 CleanupStack::PushL( aItem ); |
|
547 aItem->SetAttributeL( KMenuAttrRefcount, buf ); |
|
548 CleanupStack::Pop( aItem ); |
|
549 // return new ref_count |
|
550 return references; |
|
551 } |
|
552 return -1; |
|
553 } |
|
554 |
370 |
555 // End of File. |
371 // End of File. |