2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Declaration of RFavouritesDb.
19 #ifndef FAVOURITES_DB_H
20 #define FAVOURITES_DB_H
26 #include <favouritesitem.h>
27 #include <favouriteslimits.h>
28 #include <favouritessession.h>
29 #include <favouriteshandle.h>
31 // FORWARD DECLARATIONS
33 class CFavouritesItemList;
34 class MFavouritesItemData;
40 * RFavouritesDb is the representation of the favourites database.
41 * This class encapsulates a session with bookmark database server.
42 * It provides a way to access the database, do administration
43 * (recovery, compaction) and explicit transaction support.
45 class RFavouritesDb: public RFavouritesHandle
48 public: // New methods
51 * Open the database. Created if does not exist.
53 * @param aSess Session to be used.
54 * @param aName Database name.
57 IMPORT_C TInt Open( RFavouritesSession& aSess, const TDesC& aName );
59 public: // Adminstration
62 * Get version information.
64 * @return Version object of this CFavouritesDb.
66 IMPORT_C TVersion Version() const;
69 * Check if the database to be recovered is fully functional.
71 * @param aIsDamaged Result is returned here.
74 IMPORT_C TInt IsDamaged( TBool& aIsDamaged );
77 * Perform database synchronous recovery. This function requires exclusive access
82 IMPORT_C TInt Recover();
85 * Perform databas synchronous compaction. This function requires exclusive access
90 IMPORT_C TInt Compact();
93 * Get available database size.
95 * @param aSize Database size returned here.
98 IMPORT_C TInt Size( RDbDatabase::TSize& aSize ) const;
101 * Update database statistics.
103 * @return Error code.
105 IMPORT_C TInt UpdateStats();
107 public: // Transaction support
110 * Explicitly begin a transaction.
112 * @param aWrite Access mode.
113 * @return Error code.
115 IMPORT_C TInt Begin( TBool aWrite = EFalse );
118 * Commit the transaction.
120 * @return Error code.
122 IMPORT_C TInt Commit();
125 * Roll back the transaction.
129 IMPORT_C void Rollback();
132 * Push a rollback on the cleanup stack. Call this after Begin() call,
133 * to make the transaction leave-safe.
137 IMPORT_C void CleanupRollbackPushL();
139 public: // Data access / update / delete
142 * Get the item with this Uid.
144 * @param aUid Uid or item to get.
145 * @param aItem placeholder for the returned item data.
146 * @return Error code.
148 IMPORT_C TInt Get( TInt aUid, CFavouritesItem& aItem );
151 * Get all items matching the supplied criteria.
153 * @param aItemList placeholder for the returned item data. Existing
154 * items remain (new ones appended).
155 * @param aParentFolderFilter Uid value to filter. KFavouritesNullUid
156 * clears (all accepted); this is the default.
157 * @param aTypeFilter EItem or EFolder to use filter; ENone to clear
158 * filter (all accepted); this is the default.
159 * @param aNameFilter wildcard pattern to be used for name matching.
160 * NULL clears (all accepted); this is the default.
161 * @param aContextIdFilter ContextId value to filter.
162 * KFavouritesNullContextId clears (all accepted); this is the default.
163 * @return Error code.
167 CFavouritesItemList& aItemList,
168 TInt aParentFolderFilter = KFavouritesNullUid,
169 CFavouritesItem::TType aTypeFilter = CFavouritesItem::ENone,
170 const TDesC* aNameFilter = NULL,
171 TInt32 aContextIdFilter = KFavouritesNullContextId
175 * Get uids of all items matching the supplied criteria.
177 * @param aUids placeholder for the returned item data. Existing
178 * items remain (new ones appended).
179 * @param aParentFolderFilter Uid value to filter. KFavouritesNullUid
180 * clears (all accepted); this is the default.
181 * @param aTypeFilter EItem or EFolder to use filter; ENone to clear
182 * filter (all accepted); this is the default.
183 * @param aNameFilter wildcard pattern to be used for name matching.
184 * NULL clears (all accepted); this is the default.
185 * @param aContextIdFilter ContextId value to filter.
186 * KFavouritesNullContextId clears (all accepted); this is the default.
187 * @return Error code.
189 IMPORT_C TInt GetUids
191 CArrayFix<TInt>& aUids,
192 TInt aParentFolderFilter = KFavouritesNullUid,
193 CFavouritesItem::TType aTypeFilter = CFavouritesItem::ENone,
194 const TDesC* aNameFilter = NULL,
195 TInt32 aContextIdFilter = KFavouritesNullContextId
199 * Get preferred Uid for a folder.
201 * @param aFolder Folder Uid.
202 * @param aPreferredUid Uid of preferred item is returned here.
203 * @return Error code.
205 IMPORT_C TInt PreferredUid( TInt aFolder, TInt& aPreferredUid );
208 * Delete item by Uid. If this is a folder, all descendants and the contents
209 * of them are deleted. Homepage or root cannot be deleted.
211 * @param aUid Uid of item to delete.
212 * @return Error code, including:
213 * - KErrNotFound if the item is not found.
214 * - KErrAccessDenied if the item's cannot be deleted.
216 IMPORT_C TInt Delete( TInt aUid );
219 * Update an item. Remember Homapage or Last Visited Page cannot be updated using
222 * @param aItem Contents from this item (except Uid) will be used to
224 * If successful, its Uid, Last-Mod-Time (and possibly its name) is
226 * @param aUid Update this item.
227 * @param aAutoRename If this is ETrue, and the name already exists,
228 * the item will be renamed to a non-conflicting name.
229 * @return Error code, including:
230 * - KErrNotFound if the item is not found.
231 * - KErrArgument if the item's data is invalid (bad name, no URL,
232 * parent folder does not exist etc.).
233 * - KErrAlreadyExists if the name is already in use in that folder.
234 * - KErrAccessDenied for read-only items.
237 ( CFavouritesItem& aItem, TInt aUid, TBool aAutoRename );
240 * Add a new item to the database.
241 * If successful, its Uid, Last-Mod-Time (and possibly its name) is
244 * @param aItem The item to add.
245 * @param aAutoRename If this is ETrue, and the name already exists,
246 * the item will be renamed to a non-conflicting name.
247 * @return Error code, including:
248 * - KErrArgument if the item's data is invalid (bad name, no URL,
249 * parent folder does not exist etc.).
250 * - KErrAlreadyExists if the name is already in use in that folder.
252 IMPORT_C TInt Add( CFavouritesItem& aItem, TBool aAutoRename );
255 * Update the Homepage item. If does not exist, it is now
256 * created. The old Homepage, if any, is overwritten.
257 * If successful, its Uid and Last-Mod-Time is updated on return.
258 * Name needs not be unique.
260 * @param aItem Contents from this item (except Uid) will
261 * be used to update the Homepage Bookmark.
262 * @return Error code, including:
263 * - KErrArgument if the supplied item is not item, or is not in
266 IMPORT_C TInt SetHomepage( CFavouritesItem& aItem );
269 * Update the Last Visited. If does not exist, it is now
270 * created. The old Last Visited, if any, is overwritten.
271 * If successful, its Uid is updated on return.
272 * Name needs not be unique.
274 * @param aItem Contents from this item (except Uid) will
275 * be used to update the Last Visited Item.
276 * @return Error code, including:
277 * - KErrArgument if the supplied item is not item, or is not in
280 IMPORT_C TInt SetLastVisited( CFavouritesItem& aItem );
283 * Set factory item flag on an item.
284 * (Item with this flag set will be deleted if RFS is executed.)
286 * @param aUid Uid of item.
287 * @param aFactoryItem Flag value to set.
288 * @return Error code, including:
289 * - KErrNotFound if the item is not found.
291 IMPORT_C TInt SetFactoryItem( TInt aUid, TBool aFactoryItem );
294 * Set read-only flag on an item.
296 * @param aUid Uid of item.
297 * @param aReadOnly Flag value to set.
298 * @return Error code, including:
299 * - KErrNotFound if the item is not found.
301 IMPORT_C TInt SetReadOnly( TInt aUid, TBool aReadOnly );
304 * Manual setting of Last Modification Time of an item.
305 * Note that the Last Modification Time is automatically set by any
306 * edit, so this method need not be used in usual circumstances. It is
307 * provided for administration purposes only.
309 * @param aUid Uid of item.
310 * @param aModified Last Modification Time to set.
311 * @return Error code, including:
312 * - KErrNotFound if the item is not found.
314 IMPORT_C TInt SetModified( TInt aUid, TTime aModified );
317 * Set preferred Uid for a folder.
319 * @param aFolder Folder Uid.
320 * @param aUid Uid to be set as preferred. Not checked to exist in the folder.
321 * @return Error code, including:
322 * - KErrNotFound if aFolder is not found;
323 * - KErrArgument if aFolder is not a folder.
325 IMPORT_C TInt SetPreferredUid( TInt aFolder, TInt aUid );
328 * Check if we already have this item.
330 * @param aUid The item Uid to be checked.
331 * @param aItemExists Returned value.
332 * @return Error code.
334 IMPORT_C TInt ItemExists( TInt aUid, TBool& aItemExists );
337 * Check if the folder exists.
339 * @param aFolder The folder to be checked.
340 * @param aFolderExists Returned value.
341 * @return Error code.
343 IMPORT_C TInt FolderExists( TInt aFolder, TBool& aFolderExists );
346 * Count all items matching the supplied criteria.
348 * @param aCount Placeholder for the returned item count. In case of
349 * any error, existing value is unchanged.
350 * @param aParentFolderFilter Uid value to filter. KFavouritesNullUid
351 * clears (all accepted); this is the default.
352 * @param aTypeFilter EItem or EFolder to use filter; ENone to clear
353 * filter (all accepted); this is the default.
354 * @param aNameFilter Wildcard pattern to be used for name matching.
355 * NULL clears (all accepted); this is the default.
356 * @param aContextIdFilter ContextId value to filter.
357 * KFavouritesNullContextId clears (all accepted); this is the default.
358 * @return Error code.
363 TInt aParentFolderFilter = KFavouritesNullUid,
364 CFavouritesItem::TType aTypeFilter = CFavouritesItem::ENone,
365 const TDesC* aNameFilter = NULL,
366 TInt32 aContextIdFilter = KFavouritesNullContextId
369 public: // extra data
372 * Set data associated with an item. Any existing data, belonging to
373 * item having aUid, is now replaced. The item itself is not changed.
374 * In case of any errors, the data is not saved.
376 * @param aUid The uid of the item, to which the data belongs.
377 * @param aData Data) which replaces existing data.
378 * @return Error code, including:
379 * - KErrNotFound No item is found with aUid.
381 IMPORT_C TInt SetData( TInt aUid, const MFavouritesItemData& aData );
384 * Get data associated with an item.
386 * @param aUid The uid of the item, to which the data belongs.
387 * @param aData Data object, which receives the data.
388 * @return Error code, including:
389 * - KErrNotFound No item is found with aUid.
391 IMPORT_C TInt GetData( TInt aUid, MFavouritesItemData& aData );
393 public: // Browser data
396 * Set Browser data associated with an item. Any existing data,
397 * belonging to item having aUid, is now replaced. The item itself is
399 * This data is for Browser's dedicated use, do not tamper.
400 * In case of any errors, the data is not saved.
402 * @param aUid The uid of the item, to which the data belongs.
403 * @param aData Data) which replaces existing data.
404 * @return Error code, including:
405 * - KErrNotFound No item is found with aUid.
407 IMPORT_C TInt SetBrowserData( TInt aUid, const MFavouritesItemData& aData );
410 * Get Browser associated with an item.
411 * This data is for Browser's dedicated use, do not tamper.
413 * @param aUid The uid of the item, to which the data belongs.
414 * @param aData Data object, which receives the data.
415 * @return Error code, including:
416 * - KErrNotFound No item is found with aUid.
418 IMPORT_C TInt GetBrowserData( TInt aUid, MFavouritesItemData& aData );
420 public: // unique name support
423 * Check if aName is unique in aFolder; and if not, change to
424 * an unique one, appending a number. In case of any errors, aName is
425 * unchanged. Names of special items (Start Page etc.) are not
426 * considered (can have conflicting names).
428 * @param aName Descriptor containing the original name and receiving
429 * the resulting unique name. Must be large enough to accomodate the
430 * result. (The appended text is KFavouritesMaxPostfix characters at
431 * most; the resulting length is KFavouritesMaxName at most.)
432 * @param aFolder Folder to be used for uniqueness-checking.
433 * @return Error code, including:
434 * - KErrArgument aFolder is not found.
435 * - KErrBadName aName is empty.
437 IMPORT_C TInt MakeUniqueName( TDes& aName, TInt aFolder );
440 * Check if aName is unique in its folder; and if not, change to
441 * an unique one, appending a number. In case of any errors, aItem is
442 * unchanged. Names of special items (Start Page etc.) are not
443 * considered (can have conflicting names).
445 * @param aItem Item to set unique name for.
446 * @return Error code, including:
447 * - KErrArgument aFolder is not found.
448 * - KErrBadName Current name is empty.
450 IMPORT_C TInt MakeUniqueName( CFavouritesItem& aItem );
452 public: // Browser support
455 * Create an empty item with uid KFavouritesStartPageUid. Owner is the
456 * caller. Except its uid, the item is uninitialized. The Browser
457 * needs this. Note that this item does not exist in the database.
459 * @return The created item.
461 IMPORT_C CFavouritesItem* CreateStartPageItemL();
464 * Create a folder with uid KFavouritesAdaptiveItemsFolderUid.
465 * Owner is the caller. Uid, type (folder) and parent (root) is set,
466 * other properties are uninitialized. The Browser needs this. Note
467 * that this item does not exist in the database.
469 * @return The created item.
471 IMPORT_C CFavouritesItem* CreateAdaptiveItemsFolderL();
476 * Delete file. See RFavouritesFile.
478 * @param aUid Uid of the item.
479 * @return Errro code.
481 IMPORT_C TInt DeleteFile( TInt aUid );
486 * User-level Restore Factory Settings operation.
487 * Delete all items that has "factory item" flag set, then add new
488 * ones from reference database. In case of name conflilcts, new
489 * names are generated. Leaves on any error.
491 * @param aName Database name.
492 * @param aReferenceDbPath Full pathname of reference database.
493 * @param aApMapper Access Point mapper to be used.
495 IMPORT_C static void RestoreFactorySettingsL
498 const TDesC& aReferenceDbPath,
499 MRfsApMapper& aApMapper
502 private: // New methods
505 * Set Homepage / Last Visited Page.
507 * @param aItem Item data.
508 * @param aUid Uid of the item to be set.
509 * @return Error code.
511 TInt SetSpecialItem( CFavouritesItem& aItem, TInt aUid );
514 * Set data associated with an item.
516 * @param aFunction Function.
517 * @param aUid The uid of the item, to which the data belongs.
518 * @param aData Data which replaces existing data.
519 * @return Error code.
522 ( TInt aFunction, TInt aUid, const MFavouritesItemData& aData );
525 * Get data associated with an item.
527 * @param aFunction Function.
528 * @param aUid The uid of the item, to which the data belongs.
529 * @param aData Data object, which receives the data.
530 * @return Error code.
533 ( TInt aFunction, TInt aUid, MFavouritesItemData& aData );
536 * Implementation of RestoreFactorySettingsL().
538 * @param aReferenceDbPath Full pathname of reference database.
539 * @param aApMapper Access Point mapper to be used.
541 void DoRestoreFactorySettingsL
542 ( const TDesC& aReferenceDbPath, MRfsApMapper& aApMapper );
545 * Cleanup helper, static wrapper around the rollback call.
547 * @param aPtr This as TAny*.
549 static void StaticRollback( TAny* aPtr );