114
|
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: Bookmark list for settings listbox
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <favouritesitemlist.h>
|
|
19 |
#include <aistrcnv.h>
|
|
20 |
#include <mcsmenufilter.h>
|
|
21 |
#include <mcsmenuitem.h>
|
|
22 |
|
|
23 |
#include "mcspluginsettingsmodel.h"
|
|
24 |
#include "mcspluginsettingsbkmlist.h"
|
|
25 |
|
|
26 |
_LIT( KMyMenuData, "matrixmenudata" );
|
|
27 |
_LIT( KMenuUrl, "menu:url" );
|
|
28 |
_LIT( KUrl, "url" );
|
|
29 |
_LIT8( KUid, "uid" );
|
|
30 |
_LIT( KMenuAttrParameter, "param" );
|
|
31 |
|
|
32 |
// ======== MEMBER FUNCTIONS ========
|
|
33 |
|
|
34 |
|
|
35 |
// ---------------------------------------------------------------------------
|
|
36 |
// First-phase construction
|
|
37 |
// ---------------------------------------------------------------------------
|
|
38 |
//
|
|
39 |
CMCSPluginSettingsBkmList::CMCSPluginSettingsBkmList()
|
|
40 |
{
|
|
41 |
}
|
|
42 |
|
|
43 |
// ---------------------------------------------------------------------------
|
|
44 |
// Second-phase construction
|
|
45 |
// ---------------------------------------------------------------------------
|
|
46 |
//
|
|
47 |
void CMCSPluginSettingsBkmList::ConstructL()
|
|
48 |
{
|
|
49 |
User::LeaveIfError(iBookmarkSess.Connect());
|
|
50 |
User::LeaveIfError(iBookmarkDb.Open(iBookmarkSess, KBrowserBookmarks));
|
|
51 |
iMenu.OpenL( KMyMenuData );
|
|
52 |
GetBookmarkListL();
|
|
53 |
}
|
|
54 |
|
|
55 |
// ---------------------------------------------------------------------------
|
|
56 |
// Two-phased constructor
|
|
57 |
// ---------------------------------------------------------------------------
|
|
58 |
//
|
|
59 |
CMCSPluginSettingsBkmList* CMCSPluginSettingsBkmList::NewL()
|
|
60 |
{
|
|
61 |
CMCSPluginSettingsBkmList* self = new (ELeave) CMCSPluginSettingsBkmList();
|
|
62 |
CleanupStack::PushL(self);
|
|
63 |
self->ConstructL();
|
|
64 |
CleanupStack::Pop(self);
|
|
65 |
return self;
|
|
66 |
}
|
|
67 |
|
|
68 |
// ---------------------------------------------------------------------------
|
|
69 |
// Destructor
|
|
70 |
// ---------------------------------------------------------------------------
|
|
71 |
//
|
|
72 |
CMCSPluginSettingsBkmList::~CMCSPluginSettingsBkmList()
|
|
73 |
{
|
|
74 |
iListItems.ResetAndDestroy();
|
|
75 |
iMenuItems.ResetAndDestroy();
|
|
76 |
iBookmarkDb.Close();
|
|
77 |
iBookmarkSess.Close();
|
|
78 |
iMenu.Close();
|
|
79 |
}
|
|
80 |
|
|
81 |
// ---------------------------------------------------------------------------
|
|
82 |
// From MDesCArray
|
|
83 |
// Returns the number of descriptor elements in a descriptor array.
|
|
84 |
// ---------------------------------------------------------------------------
|
|
85 |
//
|
|
86 |
TInt CMCSPluginSettingsBkmList::MdcaCount() const
|
|
87 |
{
|
|
88 |
return iListItems.Count();
|
|
89 |
}
|
|
90 |
|
|
91 |
// ---------------------------------------------------------------------------
|
|
92 |
// From MDesCArray
|
|
93 |
// Indexes into a descriptor array.
|
|
94 |
// ---------------------------------------------------------------------------
|
|
95 |
//
|
|
96 |
TPtrC CMCSPluginSettingsBkmList::MdcaPoint(TInt aIndex) const
|
|
97 |
{
|
|
98 |
if (aIndex < 0 || aIndex >= iListItems.Count())
|
|
99 |
{
|
|
100 |
TPtrC ret(KNullDesC);
|
|
101 |
return ret;
|
|
102 |
}
|
|
103 |
return iListItems[aIndex]->Caption();
|
|
104 |
}
|
|
105 |
|
|
106 |
// ---------------------------------------------------------------------------
|
|
107 |
// Iterates thru the bookmark list and tries to find a menuitem which
|
|
108 |
// matches given property map from HSPS
|
|
109 |
// ---------------------------------------------------------------------------
|
|
110 |
//
|
|
111 |
TSettingItem CMCSPluginSettingsBkmList::FindItemL( RPointerArray<HSPluginSettingsIf::CPropertyMap>& aProperties )
|
|
112 |
{
|
|
113 |
TInt index( KErrNotFound );
|
|
114 |
TSettingItem settingItem = { KErrNotFound, EBookmark, EFalse };
|
|
115 |
for( TInt i= 0; i < aProperties.Count(); i++ )
|
|
116 |
{
|
|
117 |
if( aProperties[i]->Name() == KUid )
|
|
118 |
{
|
|
119 |
HBufC* value( NULL );
|
|
120 |
value = AiUtility::CopyToBufferL( value, aProperties[i]->Value());
|
|
121 |
for( TInt j = 0; j < iListItems.Count(); j++ )
|
|
122 |
{
|
|
123 |
TPtrC uid = *iListItems[j]->iUid;
|
|
124 |
if( uid.Compare( *value ) == 0 )
|
|
125 |
{
|
|
126 |
index = j;
|
|
127 |
break;
|
|
128 |
}
|
|
129 |
}
|
|
130 |
delete value;
|
|
131 |
}
|
|
132 |
if( index != KErrNotFound )
|
|
133 |
{
|
|
134 |
settingItem.id = index;
|
|
135 |
settingItem.type = EBookmark;
|
|
136 |
break;
|
|
137 |
}
|
|
138 |
}
|
|
139 |
return settingItem;
|
|
140 |
}
|
|
141 |
|
|
142 |
// ---------------------------------------------------------------------------
|
|
143 |
// Gets bookmark list.
|
|
144 |
// ---------------------------------------------------------------------------
|
|
145 |
//
|
|
146 |
void CMCSPluginSettingsBkmList::GetBookmarkListL()
|
|
147 |
{
|
|
148 |
iListItems.ResetAndDestroy();
|
|
149 |
|
|
150 |
GetBookmarksFromFavouritesL();
|
|
151 |
GetBookmarksFromMCSL();
|
|
152 |
}
|
|
153 |
|
|
154 |
// ---------------------------------------------------------------------------
|
|
155 |
// Gets bookmarks from Favourites server's bookmark database.
|
|
156 |
// ---------------------------------------------------------------------------
|
|
157 |
//
|
|
158 |
void CMCSPluginSettingsBkmList::GetBookmarksFromFavouritesL()
|
|
159 |
{
|
|
160 |
CFavouritesItemList* favItems = new (ELeave) CFavouritesItemList();
|
|
161 |
CleanupStack::PushL( favItems );
|
|
162 |
TInt err = iBookmarkDb.GetAll( *favItems, KFavouritesNullUid, CFavouritesItem::EItem);
|
|
163 |
if( err != KErrNone )
|
|
164 |
{
|
|
165 |
ASSERT(0);
|
|
166 |
}
|
|
167 |
TInt count = favItems->Count();
|
|
168 |
for ( TInt i = count - 1; i >= 0; i-- ) // newest on top
|
|
169 |
{
|
|
170 |
TUid uid = TUid::Uid(favItems->At(i)->Uid());
|
|
171 |
TPtrC name = favItems->At(i)->Name();
|
|
172 |
TPtrC url = favItems->At(i)->Url();
|
|
173 |
AddBookmarkL( uid.Name(), name, url, EFavBookmark );
|
|
174 |
}
|
|
175 |
CleanupStack::PopAndDestroy( favItems );
|
|
176 |
}
|
|
177 |
|
|
178 |
// ---------------------------------------------------------------------------
|
|
179 |
// Gets bookmarks from Menu Content Service.
|
|
180 |
// ---------------------------------------------------------------------------
|
|
181 |
//
|
|
182 |
void CMCSPluginSettingsBkmList::GetBookmarksFromMCSL()
|
|
183 |
{
|
|
184 |
CMenuFilter* filter = CMenuFilter::NewL();
|
|
185 |
CleanupStack::PushL( filter );
|
|
186 |
filter->SetType( KMenuUrl );
|
|
187 |
const TInt rootId = iMenu.RootFolderL();
|
|
188 |
RArray<TMenuItem> itemArray;
|
|
189 |
CleanupClosePushL( itemArray );
|
|
190 |
iMenu.GetItemsL( itemArray, rootId, filter, ETrue );
|
|
191 |
TInt count( itemArray.Count() );
|
|
192 |
for ( TInt i = 0; i < count; i++ )
|
|
193 |
{
|
|
194 |
TBool uidExists( EFalse );
|
|
195 |
TBool nameExists( EFalse );
|
|
196 |
TBool urlExists( EFalse );
|
|
197 |
CMenuItem* menuItem = CMenuItem::OpenL( iMenu, itemArray[i] );
|
|
198 |
CleanupStack::PushL( menuItem );
|
|
199 |
TPtrC uid = menuItem->GetAttributeL( KMenuAttrUid, uidExists );
|
|
200 |
TPtrC name = menuItem->GetAttributeL( KMenuAttrLongName, nameExists );
|
|
201 |
TPtrC url = menuItem->GetAttributeL( KUrl, urlExists );
|
|
202 |
// if all attrib exists, add it ( url ignored )
|
|
203 |
if ( uidExists && uid.Length() > 0 &&
|
|
204 |
nameExists && name.Length() > 0 )
|
|
205 |
{
|
|
206 |
AddBookmarkL( uid, name, url, EMCSBookmark );
|
|
207 |
}
|
|
208 |
CleanupStack::PopAndDestroy( menuItem );
|
|
209 |
}
|
|
210 |
|
|
211 |
CleanupStack::PopAndDestroy( &itemArray );
|
|
212 |
CleanupStack::PopAndDestroy( filter );
|
|
213 |
|
|
214 |
}
|
|
215 |
|
|
216 |
// ---------------------------------------------------------------------------
|
|
217 |
// If bookmark was selected amongst Favourites, new menu item is created into MCS.
|
|
218 |
// If predefined bookmark was selected, MCS menu item is retrieved
|
|
219 |
// ---------------------------------------------------------------------------
|
|
220 |
//
|
|
221 |
CMenuItem* CMCSPluginSettingsBkmList::ItemL( TInt aIndex )
|
|
222 |
{
|
|
223 |
CMenuItem* menuItem( NULL );
|
|
224 |
CBkmListItem* listItem = iListItems[aIndex];
|
|
225 |
if ( listItem->iType == EFavBookmark )
|
|
226 |
{
|
|
227 |
menuItem = CreateMenuItemL( *listItem->iUid, *listItem->iCaption, *listItem->iUrl );
|
|
228 |
}
|
|
229 |
else
|
|
230 |
{
|
|
231 |
menuItem = MCSMenuItemL( *listItem->iUid, *listItem->iCaption, *listItem->iUrl );
|
|
232 |
}
|
|
233 |
return menuItem;
|
|
234 |
}
|
|
235 |
|
|
236 |
// ---------------------------------------------------------------------------
|
|
237 |
// Tries to find menuitem with given UID, Name and Url in MCS,
|
|
238 |
// If it does not exist, it is created and saved there.
|
|
239 |
// If it exists already, ref_count attribute is incremented.
|
|
240 |
// ---------------------------------------------------------------------------
|
|
241 |
//
|
|
242 |
CMenuItem* CMCSPluginSettingsBkmList::CreateMenuItemL( const TDesC& aUid,
|
|
243 |
const TDesC& aName,
|
|
244 |
const TDesC& aUrl )
|
|
245 |
{
|
|
246 |
CMenuItem* newItem = CMenuItem::CreateL( iMenu, KMenuTypeUrl, 0, 0 );
|
|
247 |
CleanupStack::PushL( newItem );
|
|
248 |
newItem->SetAttributeL( KMenuAttrUid, aUid );
|
|
249 |
newItem->SetAttributeL( KMenuAttrLongName, aName );
|
|
250 |
newItem->SetAttributeL( KMenuAttrView, aUrl );
|
|
251 |
newItem->SetAttributeL( KMenuAttrParameter, aName );
|
|
252 |
iMenuItems.AppendL( newItem );
|
|
253 |
CleanupStack::Pop( newItem );
|
|
254 |
return newItem;
|
|
255 |
}
|
|
256 |
|
|
257 |
// ---------------------------------------------------------------------------
|
|
258 |
// Finds menuitem with given UID, Name and URL in MCS and returns it
|
|
259 |
// ---------------------------------------------------------------------------
|
|
260 |
//
|
|
261 |
CMenuItem* CMCSPluginSettingsBkmList::MCSMenuItemL( const TDesC& aUid,
|
|
262 |
const TDesC& aName,
|
|
263 |
const TDesC& aUrl )
|
|
264 |
{
|
|
265 |
CMenuItem* item( NULL );
|
|
266 |
CMenuFilter* filter = CMenuFilter::NewL();
|
|
267 |
CleanupStack::PushL( filter );
|
|
268 |
|
|
269 |
filter->SetType( KMenuUrl );
|
|
270 |
filter->HaveAttributeL( KMenuAttrUid, aUid );
|
|
271 |
filter->HaveAttributeL( KMenuAttrLongName, aName );
|
|
272 |
filter->HaveAttributeL( KUrl , aUrl );
|
|
273 |
const TInt rootId = iMenu.RootFolderL();
|
|
274 |
RArray<TMenuItem> itemArray;
|
|
275 |
CleanupClosePushL( itemArray );
|
|
276 |
iMenu.GetItemsL( itemArray, rootId, filter, ETrue );
|
|
277 |
if( itemArray.Count() > 0 )
|
|
278 |
{
|
|
279 |
item = CMenuItem::OpenL( iMenu, itemArray[0] );
|
|
280 |
if ( item )
|
|
281 |
{
|
|
282 |
CleanupStack::PushL( item );
|
|
283 |
iMenuItems.AppendL( item );
|
|
284 |
CleanupStack::Pop( item );
|
|
285 |
}
|
|
286 |
}
|
|
287 |
CleanupStack::PopAndDestroy( &itemArray );
|
|
288 |
CleanupStack::PopAndDestroy( filter );
|
|
289 |
return item;
|
|
290 |
}
|
|
291 |
|
|
292 |
// ---------------------------------------------------------------------------
|
|
293 |
// Adds an bookmark to the list.
|
|
294 |
// ---------------------------------------------------------------------------
|
|
295 |
//
|
|
296 |
void CMCSPluginSettingsBkmList::AddBookmarkL( const TDesC& aUid,
|
|
297 |
const TDesC& aCaption,
|
|
298 |
const TDesC& aUrl,
|
|
299 |
TBookmarkType aType )
|
|
300 |
{
|
|
301 |
CBkmListItem* listItem = CBkmListItem::NewLC(aUid, aCaption);
|
|
302 |
|
|
303 |
listItem->iType = aType;
|
|
304 |
if( aUrl.Length() > 0 )
|
|
305 |
{
|
|
306 |
listItem->iUrl = aUrl.AllocL();
|
|
307 |
}
|
|
308 |
else
|
|
309 |
{
|
|
310 |
listItem->iUrl = KNullDesC().AllocL();
|
|
311 |
}
|
|
312 |
|
|
313 |
TLinearOrder<CBkmListItem> sortMethod(CBkmListItem::CompareCaption);
|
|
314 |
User::LeaveIfError(iListItems.InsertInOrderAllowRepeats(listItem, sortMethod));
|
|
315 |
CleanupStack::Pop(listItem);
|
|
316 |
}
|
|
317 |
|
|
318 |
// ---------------------------------------------------------------------------
|
|
319 |
//Nested class to store individual bookmark list items
|
|
320 |
// ---------------------------------------------------------------------------
|
|
321 |
//
|
|
322 |
CMCSPluginSettingsBkmList::CBkmListItem::CBkmListItem()
|
|
323 |
{
|
|
324 |
}
|
|
325 |
|
|
326 |
// ---------------------------------------------------------------------------
|
|
327 |
// Second-phase construction
|
|
328 |
// ---------------------------------------------------------------------------
|
|
329 |
//
|
|
330 |
void CMCSPluginSettingsBkmList::CBkmListItem::ConstructL( const TDesC& aUid,
|
|
331 |
const TDesC& aCaption )
|
|
332 |
{
|
|
333 |
iUid = aUid.AllocL();
|
|
334 |
iCaption = aCaption.AllocL();
|
|
335 |
}
|
|
336 |
|
|
337 |
// ---------------------------------------------------------------------------
|
|
338 |
// Two-phased constructor
|
|
339 |
// ---------------------------------------------------------------------------
|
|
340 |
//
|
|
341 |
CMCSPluginSettingsBkmList::CBkmListItem* CMCSPluginSettingsBkmList::CBkmListItem::NewLC(
|
|
342 |
const TDesC& aUid, const TDesC& aCaption )
|
|
343 |
{
|
|
344 |
CBkmListItem* self = new (ELeave) CBkmListItem();
|
|
345 |
CleanupStack::PushL(self);
|
|
346 |
self->ConstructL( aUid, aCaption );
|
|
347 |
return self;
|
|
348 |
}
|
|
349 |
|
|
350 |
// ---------------------------------------------------------------------------
|
|
351 |
// Destructor
|
|
352 |
// ---------------------------------------------------------------------------
|
|
353 |
//
|
|
354 |
CMCSPluginSettingsBkmList::CBkmListItem::~CBkmListItem()
|
|
355 |
{
|
|
356 |
delete iUid;
|
|
357 |
delete iCaption;
|
|
358 |
delete iUrl;
|
|
359 |
}
|
|
360 |
|
|
361 |
// ---------------------------------------------------------------------------
|
|
362 |
// Compare method used to add the items to the list in sorted order.
|
|
363 |
// ---------------------------------------------------------------------------
|
|
364 |
//
|
|
365 |
TInt CMCSPluginSettingsBkmList::CBkmListItem::CompareCaption( const CBkmListItem& aFirst,
|
|
366 |
const CBkmListItem& aSecond )
|
|
367 |
{
|
|
368 |
return aFirst.iCaption->Des().CompareC(*aSecond.iCaption);
|
|
369 |
}
|
|
370 |
|
|
371 |
// ---------------------------------------------------------------------------
|
|
372 |
// Returns the item target bookmark caption.
|
|
373 |
// ---------------------------------------------------------------------------
|
|
374 |
//
|
|
375 |
TPtrC CMCSPluginSettingsBkmList::CBkmListItem::Caption() const
|
|
376 |
{
|
|
377 |
return TPtrC(*iCaption);
|
|
378 |
}
|
|
379 |
|
|
380 |
|
|
381 |
// End of File.
|