65
|
1 |
/*
|
|
2 |
* Copyright (c) 2002 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 the License "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 |
* Declaration of class CBrowserFavouritesModel.
|
|
16 |
*
|
|
17 |
*
|
|
18 |
*/
|
|
19 |
|
|
20 |
#ifndef BROWSER_FAVOURITES_MODEL_H
|
|
21 |
#define BROWSER_FAVOURITES_MODEL_H
|
|
22 |
|
|
23 |
// INCLUDES
|
|
24 |
|
|
25 |
#include <e32base.h>
|
|
26 |
#include <favouritesdbobserver.h>
|
|
27 |
#include "BrowserBookmarksOrder.h"
|
|
28 |
#include <favouritesdb.h>
|
|
29 |
#include <favouritesfile.h>
|
|
30 |
#include "ApiProvider.h"
|
|
31 |
|
|
32 |
// FORWARD DECLARATION
|
|
33 |
|
|
34 |
class CFavouritesItemList;
|
|
35 |
class CActiveFavouritesDbNotifier;
|
|
36 |
class MBrowserFavouritesModelObserver;
|
|
37 |
class CFavouritesItem;
|
|
38 |
|
|
39 |
// CLASS DECLARATION
|
|
40 |
|
|
41 |
/**
|
|
42 |
* Model for the Favourites Views of the WML Browser.
|
|
43 |
* This is a layer above the actual engines that do the data manipulation;
|
|
44 |
* and provides UI support for that (i.e. dialogs, notes etc.)
|
|
45 |
* Pure virtual.
|
|
46 |
*/
|
|
47 |
class CBrowserFavouritesModel: public CBase, public MFavouritesDbObserver
|
|
48 |
{
|
|
49 |
|
|
50 |
public: // types
|
|
51 |
|
|
52 |
/**
|
|
53 |
* Answer for database queries.
|
|
54 |
*/
|
|
55 |
enum TDbQuery
|
|
56 |
{
|
|
57 |
EYes, ///< Answer to query is yes.
|
|
58 |
ENo, ///< Answer to query is no.
|
|
59 |
EError ///< Could not get answer (i.e. database is busy etc.).
|
|
60 |
};
|
|
61 |
|
|
62 |
/**
|
|
63 |
* Rename mode for adding / updating items (what to do if an item
|
|
64 |
* to be added / updated in the database has a conflicting name).
|
|
65 |
*/
|
|
66 |
enum TRenameMode
|
|
67 |
{
|
|
68 |
EAutoRename, ///< Rename silently.
|
|
69 |
EDontRename, ///< Do not rename (quit operation).
|
|
70 |
EAskIfRename ///< Ask user.
|
|
71 |
};
|
|
72 |
|
|
73 |
public: // construction
|
|
74 |
|
|
75 |
/**
|
|
76 |
* Destructor.
|
|
77 |
*/
|
|
78 |
virtual ~CBrowserFavouritesModel();
|
|
79 |
|
|
80 |
public: // string resources
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Resource selector type for strings.
|
|
84 |
*/
|
|
85 |
enum TTextResourceType
|
|
86 |
{
|
|
87 |
EDefaultName, ///< Default name (e.g. "New Bookmark").
|
|
88 |
ERenamePrompt, ///< Rename prompt (e.g. "New Folder:").
|
|
89 |
ENewPrompt, ///< New prompt (e.g. "Folder name:").
|
|
90 |
ESaved, ///< Saved note (e.g. "Bookmark saved").
|
|
91 |
ENotSaved ///< Not saved note (e.g. "Bookmark not saved").
|
|
92 |
};
|
|
93 |
|
|
94 |
/**
|
|
95 |
* Get resource id of some text for an item.
|
|
96 |
* @param aItem The item to get resource id for.
|
|
97 |
* @param aType Type of resource text.
|
|
98 |
* @return Resource id of the text.
|
|
99 |
*/
|
|
100 |
virtual TInt StringResourceId
|
|
101 |
(
|
|
102 |
const CFavouritesItem& aItem,
|
|
103 |
TTextResourceType aType
|
|
104 |
) const = 0;
|
|
105 |
|
|
106 |
/**
|
|
107 |
* Set the name of this item to default (e.g. "New Bookmark",
|
|
108 |
* "New Folder" etc.). The name that is set is read from resource,
|
|
109 |
* the resource id is StringResourceId( EDefaultName ).
|
|
110 |
* @param aItem The item to set default name for.
|
|
111 |
*/
|
|
112 |
void SetNameToDefaultL( CFavouritesItem& aItem ) const;
|
|
113 |
|
|
114 |
public: // database opening / closing / access
|
|
115 |
|
|
116 |
/**
|
|
117 |
* Open the database.
|
|
118 |
* After succesful open, notifications to observer may come.
|
|
119 |
* Safe to call if already open.
|
|
120 |
* @param aDbErrorNote If ETrue, unsuccesful open will bring up an
|
|
121 |
* error note.
|
|
122 |
* @return Error code.
|
|
123 |
*/
|
|
124 |
TInt OpenDbL( TBool aDbErrorNote = ETrue );
|
|
125 |
|
|
126 |
/**
|
|
127 |
* Close the database. No further notification may come to the
|
|
128 |
* observer.
|
|
129 |
*/
|
|
130 |
void CloseDb();
|
|
131 |
|
|
132 |
/**
|
|
133 |
* Start a transaction.
|
|
134 |
* @param aWrite If ETrue, the table is opened with write-lock on.
|
|
135 |
* @param aDbErrorNote If ETrue, unsuccesful open will bring up an
|
|
136 |
* error note.
|
|
137 |
* @param aLffsCheck If ETrue (the default), free disk space is
|
|
138 |
* checked to be above critical level (only if aWrite==ETrue).
|
|
139 |
* Always use the default (except for deleting)!
|
|
140 |
* @return Error code.
|
|
141 |
*/
|
|
142 |
TInt BeginL
|
|
143 |
( TBool aWrite, TBool aDbErrorNote, TBool aLffsCheck = ETrue);
|
|
144 |
|
|
145 |
/**
|
|
146 |
* Commit the transaction.
|
|
147 |
* Safe to call if not open.
|
|
148 |
*/
|
|
149 |
void CommitL();
|
|
150 |
|
|
151 |
/**
|
|
152 |
* Add an observer.
|
|
153 |
* @param aObserver Observer to be notified about database-related
|
|
154 |
* events.
|
|
155 |
*/
|
|
156 |
void AddObserverL( MBrowserFavouritesModelObserver& aObserver );
|
|
157 |
|
|
158 |
/**
|
|
159 |
* Remove an observer. Panic if not added.
|
|
160 |
* @param aObserver The observer.
|
|
161 |
*/
|
|
162 |
void RemoveObserver( MBrowserFavouritesModelObserver& aObserver );
|
|
163 |
|
|
164 |
/**
|
|
165 |
* Get the database.
|
|
166 |
* @return The actual database.
|
|
167 |
*/
|
|
168 |
inline RFavouritesDb Database() const;
|
|
169 |
|
|
170 |
/**
|
|
171 |
* Opens an item associated with aUid in aFavFile.
|
|
172 |
* @return Error code.
|
|
173 |
*/
|
|
174 |
|
|
175 |
TInt OpenFavouritesFile ( RFavouritesFile & aFavFile, TInt aUid );
|
|
176 |
|
|
177 |
/**
|
|
178 |
* Opens an item associated with aUid in aFavFile for replacement.
|
|
179 |
* @return Error code.
|
|
180 |
*/
|
|
181 |
|
|
182 |
TInt ReplaceFavouritesFile ( RFavouritesFile & aFavFile, TInt aUid );
|
|
183 |
|
|
184 |
|
|
185 |
public: // database query / update
|
|
186 |
|
|
187 |
/**
|
|
188 |
* Add an item (folder or bookmark) to the database.
|
|
189 |
* @param aItem Item to add.
|
|
190 |
* @param aDbErrorNote If ETrue, unsuccesful database open will bring up an
|
|
191 |
* error note.
|
|
192 |
* @param aRenameMode What to do in case of the name is conflicting.
|
|
193 |
* @return Error code.
|
|
194 |
*/
|
|
195 |
TInt AddL
|
|
196 |
(
|
|
197 |
CFavouritesItem& aItem,
|
|
198 |
TBool aDbErrorNote,
|
|
199 |
TRenameMode aRenameMode
|
|
200 |
);
|
|
201 |
|
|
202 |
/**
|
|
203 |
* Update an item (folder or bookmark) in the database.
|
|
204 |
* @param aItem Item data.
|
|
205 |
* @param aUid Uid of item to be updated.
|
|
206 |
* @param aDbErrorNote If ETrue, unsuccesful database open will bring up
|
|
207 |
* an error note.
|
|
208 |
* @param aRenameMode What to do in case of the name is conflicting.
|
|
209 |
* @return Error code.
|
|
210 |
*/
|
|
211 |
TInt UpdateL
|
|
212 |
(
|
|
213 |
CFavouritesItem& aItem,
|
|
214 |
TInt aUid,
|
|
215 |
TBool aDbErrorNote,
|
|
216 |
TRenameMode aRenameMode
|
|
217 |
);
|
|
218 |
|
|
219 |
/**
|
|
220 |
* Set Homepage.
|
|
221 |
* @param aItem Item containing Homepage data.
|
|
222 |
* @param aDbErrorNote If ETrue, unsuccesful database open will bring up an
|
|
223 |
* error note.
|
|
224 |
* @param aRenameMode What to do in case of the name is conflicting.
|
|
225 |
* @return Error code.
|
|
226 |
*/
|
|
227 |
TInt SetHomepageL
|
|
228 |
(
|
|
229 |
CFavouritesItem& aItem,
|
|
230 |
TBool aDbErrorNote,
|
|
231 |
TRenameMode aRenameMode
|
|
232 |
);
|
|
233 |
|
|
234 |
/**
|
|
235 |
* Set Last Visited Page.
|
|
236 |
* @param aItem Item containing Homepage data.
|
|
237 |
* @param aDbErrorNote If ETrue, unsuccesful database open will bring up
|
|
238 |
* an error note.
|
|
239 |
* @param aRenameMode What to do in case of the name is conflicting.
|
|
240 |
* @return Error code.
|
|
241 |
*/
|
|
242 |
TInt SetLastVisitedL
|
|
243 |
(
|
|
244 |
CFavouritesItem& aItem,
|
|
245 |
TBool aDbErrorNote,
|
|
246 |
TRenameMode aRenameMode
|
|
247 |
);
|
|
248 |
|
|
249 |
/**
|
|
250 |
* Check if there are any folders (except the root).
|
|
251 |
* @return EYes, ENo or EError (if could not access the database).
|
|
252 |
*/
|
|
253 |
TDbQuery AnyFoldersL();
|
|
254 |
|
|
255 |
/**
|
|
256 |
* Check if the given list of uids contains
|
|
257 |
* any folders that are not empty.
|
|
258 |
* @param aUids List of Uids to check.
|
|
259 |
* @return EYes if there are non-empty folder(s), ENo if not,
|
|
260 |
* EError if could not access the database.
|
|
261 |
*/
|
|
262 |
TDbQuery AnyNonEmptyFoldersL( CArrayFix<TInt>& aUids );
|
|
263 |
|
|
264 |
/**
|
|
265 |
* Get the ordinal number of this folder in the alphabetically sorted
|
|
266 |
* list of folders. Expects a transaction.
|
|
267 |
* @param aFolder The folder to find.
|
|
268 |
* @param aFolderCount On successful return, this will be set to the
|
|
269 |
* number of folders.
|
|
270 |
* @param On successful return, this will be set to the ordinal number
|
|
271 |
* of the given folder.
|
|
272 |
* @return Error code.
|
|
273 |
*/
|
|
274 |
TInt FolderInfoL
|
|
275 |
( TInt aFolder, TInt& aFolderCount, TInt& aFolderIndex );
|
|
276 |
|
|
277 |
/**
|
|
278 |
* In the alphabetically sorted list of folders, get Uid of folder next
|
|
279 |
* to aFolder. Expects a transaction.
|
|
280 |
* @param aFolder Folder to start from.
|
|
281 |
* @param aForward If ETrue, get next; if EFalse, get previous.
|
|
282 |
* @return Uid of the next folder or KFavouritesNullUid in case of any
|
|
283 |
* error.
|
|
284 |
*/
|
|
285 |
TInt NextFolderL( TInt aFolder, TBool aForward );
|
|
286 |
|
|
287 |
/**
|
|
288 |
* Display a query for renaming this item. If the query is accepted,
|
|
289 |
* the item is renamed.
|
|
290 |
* @param aItem The item to rename.
|
|
291 |
* @param aItem New item, we do not rename.
|
|
292 |
* @return ETrue if the query is accepted and the item is renamed.
|
|
293 |
*/
|
|
294 |
TBool RenameQueryL( CFavouritesItem& aItem, TBool aNewItem );
|
|
295 |
|
|
296 |
/**
|
|
297 |
* Sort items in a list.
|
|
298 |
* @param aList List to sort.
|
|
299 |
*/
|
|
300 |
void SortL( CFavouritesItemList& aList );
|
|
301 |
|
|
302 |
public: // convenience methods
|
|
303 |
|
|
304 |
/**
|
|
305 |
* Check if aItem has a unique name (in its parent folder), and if
|
|
306 |
* not, make its name unique.
|
|
307 |
* @param aItem Item to set a unique name for.
|
|
308 |
* @return Error code.
|
|
309 |
*/
|
|
310 |
TInt MakeUniqueNameL( CFavouritesItem& aItem );
|
|
311 |
|
|
312 |
protected: // new functions
|
|
313 |
|
|
314 |
//MApiProvider& ApiProvider() const;
|
|
315 |
|
|
316 |
public: // from MFavouritesDbObserver
|
|
317 |
|
|
318 |
/**
|
|
319 |
* Handle database event.
|
|
320 |
* @param aEvent Database event.
|
|
321 |
*/
|
|
322 |
void HandleFavouritesDbEventL( RDbNotifier::TEvent aEvent );
|
|
323 |
|
|
324 |
void ManualSortL(TInt aFolder, CBrowserBookmarksOrder* aBMOrder, CArrayFixFlat<TInt>* aOrderArray, CFavouritesItemList* aItems);
|
|
325 |
|
|
326 |
/**
|
|
327 |
* Adds the given uid to the last place in bookmarks list
|
|
328 |
* @param aUid The uid to add
|
|
329 |
* @param aOrderArray the array that stores uids in manual order
|
|
330 |
* @param aCurrentOrder the object that stores manual sorting data
|
|
331 |
*/
|
|
332 |
|
|
333 |
void AddUidToLastPlaceL( TInt aUid , CArrayFixFlat<TInt>* aOrderArray, CBrowserBookmarksOrder* aCurrentOrder);
|
|
334 |
|
|
335 |
protected : // construction
|
|
336 |
|
|
337 |
/**
|
|
338 |
* Constructor.
|
|
339 |
*/
|
|
340 |
CBrowserFavouritesModel( MApiProvider& aApiProvider );
|
|
341 |
|
|
342 |
/**
|
|
343 |
* Second phase constructor. Leaves on failure.
|
|
344 |
*/
|
|
345 |
void ConstructL();
|
|
346 |
|
|
347 |
/**
|
|
348 |
* Returns with the underlying database's name.
|
|
349 |
* Derived classes must provide this method.
|
|
350 |
* @return The Database Engine's name.
|
|
351 |
*/
|
|
352 |
virtual const TDesC& GetDBName();
|
|
353 |
|
|
354 |
private: // implementation details
|
|
355 |
|
|
356 |
/**
|
|
357 |
* Open the database. If unsuccesful, retry two more times in
|
|
358 |
* 0.2 secs interval.
|
|
359 |
* @return Error code.
|
|
360 |
*/
|
|
361 |
TInt TimedOpenDbL();
|
|
362 |
|
|
363 |
/**
|
|
364 |
* Start a transaction. If unsuccesful, retry two more times in
|
|
365 |
* 0.2 secs interval.
|
|
366 |
* @param aWrite If ETrue, the table is opened with write-lock on.
|
|
367 |
* @return Error code.
|
|
368 |
*/
|
|
369 |
TInt TimedBeginL( TBool aWrite );
|
|
370 |
|
|
371 |
/**
|
|
372 |
* Add/update an item (folder or item) in the database; factoring out
|
|
373 |
* the common code.
|
|
374 |
* @param aItem Item data.
|
|
375 |
* @param aUid
|
|
376 |
* - When KFavouritesNullUid, the item is added.
|
|
377 |
* - Otherwise, Uid of the item to be updated.
|
|
378 |
* @param aDbErrorNote If ETrue, unsuccesful database open will bring up
|
|
379 |
* an error note.
|
|
380 |
* @param aRenameMode What to do in case of the name is conflicting.
|
|
381 |
* @return Error code.
|
|
382 |
*/
|
|
383 |
TInt AddUpdateL
|
|
384 |
(
|
|
385 |
CFavouritesItem& aItem,
|
|
386 |
TInt aUid,
|
|
387 |
TBool aDbErrorNote,
|
|
388 |
TRenameMode aRenameMode
|
|
389 |
);
|
|
390 |
|
|
391 |
/**
|
|
392 |
* Compare two descriptors (case insensitive).
|
|
393 |
* @since 3.2
|
|
394 |
* @param aFirst first descriptor
|
|
395 |
* @param aSecond second descriptor
|
|
396 |
* @return ETrue if strings match, EFalse otherwise
|
|
397 |
*/
|
|
398 |
TBool CompareIgnoreCase( const TDesC& aFirst, const TDesC& aSecond );
|
|
399 |
|
|
400 |
|
|
401 |
protected:
|
|
402 |
/**
|
|
403 |
* Get all folders in the root, sorted, and push it on the cleanup
|
|
404 |
* stack. No sanity check. Expects a transaction.
|
|
405 |
* @return List of folders. Owner is the caller.
|
|
406 |
*/
|
|
407 |
virtual CFavouritesItemList* GetFoldersSortedLC();
|
|
408 |
|
|
409 |
private: // observer support
|
|
410 |
|
|
411 |
/**
|
|
412 |
* Call each observer's HandleFavouritesModelChangeL().
|
|
413 |
*/
|
|
414 |
void NotifyObserversL();
|
|
415 |
|
|
416 |
private: // types
|
|
417 |
|
|
418 |
enum TState ///< Database state.
|
|
419 |
{
|
|
420 |
EClosed, ///< Database is closed.
|
|
421 |
EOpen, ///< Database is open.
|
|
422 |
ECorrupt ///< Database is corrupted (and is closed)
|
|
423 |
};
|
|
424 |
|
|
425 |
private: // data
|
|
426 |
|
|
427 |
/// Used database object. Owned.
|
|
428 |
|
|
429 |
RFavouritesDb iDb;
|
|
430 |
RFavouritesSession iFavouritesSess;
|
|
431 |
/// Notifier object. Owned.
|
|
432 |
CActiveFavouritesDbNotifier* iNotifier;
|
|
433 |
/// Observers. Array owned, contents not.
|
|
434 |
CArrayPtrFlat<MBrowserFavouritesModelObserver>* iObservers;
|
|
435 |
/// Database state.
|
|
436 |
TState iState;
|
|
437 |
|
|
438 |
MApiProvider& iApiProvider;
|
|
439 |
};
|
|
440 |
|
|
441 |
#include "BrowserFavouritesModel.inl"
|
|
442 |
|
|
443 |
#endif
|
|
444 |
|
|
445 |
// End of file |