|
1 /* |
|
2 * Copyright (c) 2005-2006 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 |
|
19 #include <StringLoader.h> |
|
20 #include <ActiveFavouritesDbNotifier.h> // For CActiveFavouritesDbNotifier |
|
21 |
|
22 #include <aiscutsettingsres.rsg> |
|
23 #include <aiscuttexts.rsg> |
|
24 |
|
25 #include "caiscutsettingsmodel.h" |
|
26 #include "caiscutsettingsapplist.h" |
|
27 #include "caiscutsettingsbkmlist.h" |
|
28 #include "taiscutparser.h" |
|
29 #include "caiscutsettingsitem.h" |
|
30 #include "aiscutdefs.h" |
|
31 |
|
32 #include "debug.h" |
|
33 |
|
34 |
|
35 _LIT( KText, "bkm=0x%x" ); |
|
36 const TInt KTBUF16 = 16; |
|
37 |
|
38 // ======== MEMBER FUNCTIONS ======== |
|
39 |
|
40 CAiScutSettingsBkmList::CAiScutSettingsBkmList( |
|
41 CCoeEnv* aEnv, |
|
42 CAiScutSettingsModel* aModel, |
|
43 MAiScutListObserver& aObserver |
|
44 ) |
|
45 : iEnv(aEnv) |
|
46 , iModel(aModel) |
|
47 , iObserver(aObserver) |
|
48 { |
|
49 } |
|
50 |
|
51 void CAiScutSettingsBkmList::ConstructL() |
|
52 { |
|
53 } |
|
54 |
|
55 CAiScutSettingsBkmList* CAiScutSettingsBkmList::NewL( |
|
56 CCoeEnv* aEnv, |
|
57 CAiScutSettingsModel* aModel, |
|
58 MAiScutListObserver& aObserver) |
|
59 { |
|
60 CAiScutSettingsBkmList* self = new (ELeave) CAiScutSettingsBkmList( |
|
61 aEnv, aModel, aObserver); |
|
62 CleanupStack::PushL(self); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop(self); |
|
65 return self; |
|
66 } |
|
67 |
|
68 CAiScutSettingsBkmList::~CAiScutSettingsBkmList() |
|
69 { |
|
70 iListItems.ResetAndDestroy(); |
|
71 delete iBookmarkDbObserver; |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // From MDesCArray |
|
76 // Returns the number of descriptor elements in a descriptor array. |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 TInt CAiScutSettingsBkmList::MdcaCount() const |
|
80 { |
|
81 return iListItems.Count(); |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // From MDesCArray |
|
86 // Indexes into a descriptor array. |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 TPtrC CAiScutSettingsBkmList::MdcaPoint(TInt aIndex) const |
|
90 { |
|
91 if (aIndex < 0 || aIndex >= iListItems.Count()) |
|
92 { |
|
93 TPtrC ret(KNullDesC); |
|
94 return ret; |
|
95 } |
|
96 return iListItems[aIndex]->Caption(); |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // Gets bookmark list. |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 void CAiScutSettingsBkmList::GetBookmarkListL() |
|
104 { |
|
105 iListItems.ResetAndDestroy(); |
|
106 |
|
107 iModel->ReadBookmarksL(); |
|
108 |
|
109 TInt count = iModel->BookmarkCount(); |
|
110 |
|
111 for (TInt i = count - 1; i >= 0; i--) // newest on top |
|
112 { |
|
113 CFavouritesItem* item = iModel->GetBookmark(i); |
|
114 |
|
115 TUid uid = TUid::Uid(item->Uid()); |
|
116 TPtrC name = item->Name(); |
|
117 |
|
118 AddBookmarkL(uid, name); |
|
119 } |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // Tells the bookmark list to start or stop observing for changes. |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CAiScutSettingsBkmList::SetObservingL(TBool aObserving) |
|
127 { |
|
128 delete iBookmarkDbObserver; |
|
129 iBookmarkDbObserver = NULL; |
|
130 |
|
131 if (aObserving) |
|
132 { |
|
133 |
|
134 iBookmarkDbObserver = new (ELeave) CActiveFavouritesDbNotifier( |
|
135 iModel->FavouritesDb(), *this); |
|
136 iBookmarkDbObserver->Start(); |
|
137 } |
|
138 |
|
139 iObserving = aObserving; |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // Finds the index of the given settings item in the bookmark list. |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 TInt CAiScutSettingsBkmList::FindIndex(CAiScutSettingsItem& aItem) |
|
147 { |
|
148 TInt index = KErrNotFound; |
|
149 |
|
150 TAiScutParser parser; |
|
151 parser.Parse(aItem.Value()); |
|
152 TUid uid = parser.ParseUid(parser.Get(EScutDefParamValue)); |
|
153 |
|
154 for (TInt i = iListItems.Count() - 1; i >= 0; --i) |
|
155 { |
|
156 if (iListItems[i]->Uid() == uid) |
|
157 { |
|
158 index = i; |
|
159 break; |
|
160 } |
|
161 } |
|
162 |
|
163 return index; |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // Returns target bookmark data from the given index. |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 TInt CAiScutSettingsBkmList::GetDataByIndex( |
|
171 TInt aIndex, TPtrC& aParams, TPtrC& aCaption) const |
|
172 { |
|
173 if (aIndex >= 0 && aIndex < iListItems.Count()) |
|
174 { |
|
175 CBkmListItem* item = iListItems[aIndex]; |
|
176 aParams.Set(item->Params()); |
|
177 aCaption.Set(item->Caption()); |
|
178 return KErrNone; |
|
179 } |
|
180 |
|
181 return KErrNotFound; |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------------------------- |
|
185 // Adds an bookmark to the list. |
|
186 // --------------------------------------------------------------------------- |
|
187 // |
|
188 void CAiScutSettingsBkmList::AddBookmarkL(TUid aUid, const TDesC& aCaption) |
|
189 { |
|
190 CBkmListItem* listItem = CBkmListItem::NewLC(aUid, aCaption); |
|
191 |
|
192 TBuf<KTBUF16> buf; |
|
193 buf.Format( KText, aUid.iUid ); |
|
194 |
|
195 listItem->SetParamsL(buf); |
|
196 TLinearOrder<CBkmListItem> sortMethod(CBkmListItem::CompareCaption); |
|
197 User::LeaveIfError(iListItems.InsertInOrderAllowRepeats(listItem, sortMethod)); |
|
198 CleanupStack::Pop(listItem); |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // Updates the bookmark list. |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 void CAiScutSettingsBkmList::UpdateBkmListL() |
|
206 { |
|
207 GetBookmarkListL(); |
|
208 iObserver.HandleScutListEventL(MAiScutListObserver::EBkmListUpdated, EFalse); |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // From class MFavouritesDbObserver. |
|
213 // Handles database event. |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 void CAiScutSettingsBkmList::HandleFavouritesDbEventL(RDbNotifier::TEvent aEvent) |
|
217 { |
|
218 __PRINT( __DBG_FORMAT( "XAI: CAiScutSettingsBkmList::HandleFavouritesDbEventL aEvent = %d"), aEvent); |
|
219 |
|
220 if (aEvent == RDbNotifier::ECommit) |
|
221 { |
|
222 UpdateBkmListL(); |
|
223 } |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 //Nested class to store individual bookmark list items |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 CAiScutSettingsBkmList::CBkmListItem::CBkmListItem(TUid aUid) : iUid(aUid) |
|
231 { |
|
232 } |
|
233 |
|
234 void CAiScutSettingsBkmList::CBkmListItem::ConstructL(const TDesC& aCaption) |
|
235 { |
|
236 iCaption = aCaption.AllocL(); |
|
237 } |
|
238 |
|
239 CAiScutSettingsBkmList::CBkmListItem* CAiScutSettingsBkmList::CBkmListItem::NewLC( |
|
240 TUid aUid, const TDesC& aCaption) |
|
241 { |
|
242 CBkmListItem* self = new (ELeave) CBkmListItem(aUid); |
|
243 CleanupStack::PushL(self); |
|
244 self->ConstructL(aCaption); |
|
245 return self; |
|
246 } |
|
247 |
|
248 CAiScutSettingsBkmList::CBkmListItem::~CBkmListItem() |
|
249 { |
|
250 delete iCaption; |
|
251 delete iParams; |
|
252 } |
|
253 |
|
254 // --------------------------------------------------------------------------- |
|
255 // Compare method used to add the items to the list in sorted order. |
|
256 // --------------------------------------------------------------------------- |
|
257 // |
|
258 TInt CAiScutSettingsBkmList::CBkmListItem::CompareCaption(const CBkmListItem& aFirst, |
|
259 const CBkmListItem& aSecond) |
|
260 { |
|
261 return aFirst.iCaption->Des().CompareC(*aSecond.iCaption); |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------------------------- |
|
265 // Returns the item target bookmark uid. |
|
266 // --------------------------------------------------------------------------- |
|
267 // |
|
268 TUid CAiScutSettingsBkmList::CBkmListItem::Uid() const |
|
269 { |
|
270 return iUid; |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // Returns the item target bookmark caption. |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 TPtrC CAiScutSettingsBkmList::CBkmListItem::Caption() const |
|
278 { |
|
279 return TPtrC(*iCaption); |
|
280 } |
|
281 |
|
282 // --------------------------------------------------------------------------- |
|
283 // Returns the possible parameters for item target. |
|
284 // --------------------------------------------------------------------------- |
|
285 // |
|
286 TPtrC CAiScutSettingsBkmList::CBkmListItem::Params() const |
|
287 { |
|
288 TPtrC params; |
|
289 if (iParams) |
|
290 { |
|
291 params.Set(*iParams); |
|
292 } |
|
293 return params; |
|
294 } |
|
295 |
|
296 // --------------------------------------------------------------------------- |
|
297 // Sets the parameters for the item target. |
|
298 // --------------------------------------------------------------------------- |
|
299 // |
|
300 void CAiScutSettingsBkmList::CBkmListItem::SetParamsL(const TDesC& aParams) |
|
301 { |
|
302 HBufC* newParams = aParams.AllocL(); |
|
303 delete iParams; |
|
304 iParams = newParams; |
|
305 } |
|
306 |
|
307 // End of File. |