williamr@2: /* williamr@2: * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@2: * under the terms of the License "Eclipse Public License v1.0" williamr@2: * which accompanies this distribution, and is available williamr@2: * at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: Declaration of RFavouritesDb. williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: #ifndef FAVOURITES_DB_H williamr@2: #define FAVOURITES_DB_H williamr@2: williamr@2: // INCLUDES williamr@2: williamr@2: #include williamr@2: #include williamr@4: #include williamr@4: #include williamr@4: #include williamr@4: #include williamr@2: williamr@2: // FORWARD DECLARATIONS williamr@2: williamr@2: class CFavouritesItemList; williamr@2: class MFavouritesItemData; williamr@2: class MRfsApMapper; williamr@2: williamr@2: // CLASS DECLARATION williamr@2: williamr@2: /** williamr@2: * RFavouritesDb is the representation of the favourites database. williamr@2: * This class encapsulates a session with bookmark database server. williamr@2: * It provides a way to access the database, do administration williamr@2: * (recovery, compaction) and explicit transaction support. williamr@2: */ williamr@2: class RFavouritesDb: public RFavouritesHandle williamr@2: { williamr@2: williamr@2: public: // New methods williamr@2: williamr@2: /** williamr@2: * Open the database. Created if does not exist. williamr@2: * @since 0.9 williamr@2: * @param aSess Session to be used. williamr@2: * @param aName Database name. williamr@2: * @return Error code. williamr@2: */ williamr@2: IMPORT_C TInt Open( RFavouritesSession& aSess, const TDesC& aName ); williamr@2: williamr@2: public: // Adminstration williamr@2: williamr@2: /** williamr@2: * Get version information. williamr@2: * @since 0.9 williamr@2: * @return Version object of this CFavouritesDb. williamr@2: */ williamr@2: IMPORT_C TVersion Version() const; williamr@2: williamr@2: /** williamr@2: * Check if the database to be recovered is fully functional. williamr@2: * @since 0.9 williamr@2: * @param aIsDamaged Result is returned here. williamr@2: * @return Error code. williamr@2: */ williamr@2: IMPORT_C TInt IsDamaged( TBool& aIsDamaged ); williamr@2: williamr@2: /** williamr@2: * Perform database synchronous recovery. This function requires exclusive access williamr@2: * to the database. williamr@2: * @since 0.9 williamr@2: * @return Error code. williamr@2: */ williamr@2: IMPORT_C TInt Recover(); williamr@2: williamr@2: /** williamr@2: * Perform databas synchronous compaction. This function requires exclusive access williamr@2: * to the database. williamr@2: * @since 0.9 williamr@2: * @return Error code. williamr@2: */ williamr@2: IMPORT_C TInt Compact(); williamr@2: williamr@2: /** williamr@2: * Get available database size. williamr@2: * @since 0.9 williamr@2: * @param aSize Database size returned here. williamr@2: * @return Error code. williamr@2: */ williamr@2: IMPORT_C TInt Size( RDbDatabase::TSize& aSize ) const; williamr@2: williamr@2: /** williamr@2: * Update database statistics. williamr@2: * @since 0.9 williamr@2: * @return Error code. williamr@2: */ williamr@2: IMPORT_C TInt UpdateStats(); williamr@2: williamr@2: public: // Transaction support williamr@2: williamr@2: /** williamr@2: * Explicitly begin a transaction. williamr@2: * @since 0.9 williamr@2: * @param aWrite Access mode. williamr@2: * @return Error code. williamr@2: */ williamr@2: IMPORT_C TInt Begin( TBool aWrite = EFalse ); williamr@2: williamr@2: /** williamr@2: * Commit the transaction. williamr@2: * @since 0.9 williamr@2: * @return Error code. williamr@2: */ williamr@2: IMPORT_C TInt Commit(); williamr@2: williamr@2: /** williamr@2: * Roll back the transaction. williamr@2: * @since 0.9 williamr@2: * @return void williamr@2: */ williamr@2: IMPORT_C void Rollback(); williamr@2: williamr@2: /** williamr@2: * Push a rollback on the cleanup stack. Call this after Begin() call, williamr@2: * to make the transaction leave-safe. williamr@2: * @since 0.9 williamr@2: * @return void williamr@2: */ williamr@2: IMPORT_C void CleanupRollbackPushL(); williamr@2: williamr@2: public: // Data access / update / delete williamr@2: williamr@2: /** williamr@2: * Get the item with this Uid. williamr@2: * @since 0.9 williamr@2: * @param aUid Uid or item to get. williamr@2: * @param aItem placeholder for the returned item data. williamr@2: * @return Error code. williamr@2: */ williamr@2: IMPORT_C TInt Get( TInt aUid, CFavouritesItem& aItem ); williamr@2: williamr@2: /** williamr@2: * Get all items matching the supplied criteria. williamr@2: * @since 0.9 williamr@2: * @param aItemList placeholder for the returned item data. Existing williamr@2: * items remain (new ones appended). williamr@2: * @param aParentFolderFilter Uid value to filter. KFavouritesNullUid williamr@2: * clears (all accepted); this is the default. williamr@2: * @param aTypeFilter EItem or EFolder to use filter; ENone to clear williamr@2: * filter (all accepted); this is the default. williamr@2: * @param aNameFilter wildcard pattern to be used for name matching. williamr@2: * NULL clears (all accepted); this is the default. williamr@2: * @param aContextIdFilter ContextId value to filter. williamr@2: * KFavouritesNullContextId clears (all accepted); this is the default. williamr@2: * @return Error code. williamr@2: */ williamr@2: IMPORT_C TInt GetAll williamr@2: ( williamr@2: CFavouritesItemList& aItemList, williamr@2: TInt aParentFolderFilter = KFavouritesNullUid, williamr@2: CFavouritesItem::TType aTypeFilter = CFavouritesItem::ENone, williamr@2: const TDesC* aNameFilter = NULL, williamr@2: TInt32 aContextIdFilter = KFavouritesNullContextId williamr@2: ); williamr@2: williamr@2: /** williamr@2: * Get uids of all items matching the supplied criteria. williamr@2: * @since 0.9 williamr@2: * @param aUids placeholder for the returned item data. Existing williamr@2: * items remain (new ones appended). williamr@2: * @param aParentFolderFilter Uid value to filter. KFavouritesNullUid williamr@2: * clears (all accepted); this is the default. williamr@2: * @param aTypeFilter EItem or EFolder to use filter; ENone to clear williamr@2: * filter (all accepted); this is the default. williamr@2: * @param aNameFilter wildcard pattern to be used for name matching. williamr@2: * NULL clears (all accepted); this is the default. williamr@2: * @param aContextIdFilter ContextId value to filter. williamr@2: * KFavouritesNullContextId clears (all accepted); this is the default. williamr@2: * @return Error code. williamr@2: */ williamr@2: IMPORT_C TInt GetUids williamr@2: ( williamr@2: CArrayFix& aUids, williamr@2: TInt aParentFolderFilter = KFavouritesNullUid, williamr@2: CFavouritesItem::TType aTypeFilter = CFavouritesItem::ENone, williamr@2: const TDesC* aNameFilter = NULL, williamr@2: TInt32 aContextIdFilter = KFavouritesNullContextId williamr@2: ); williamr@2: williamr@2: /** williamr@2: * Get preferred Uid for a folder. williamr@2: * @since 0.9 williamr@2: * @param aFolder Folder Uid. williamr@2: * @param aPreferredUid Uid of preferred item is returned here. williamr@2: * @return Error code. williamr@2: */ williamr@2: IMPORT_C TInt PreferredUid( TInt aFolder, TInt& aPreferredUid ); williamr@2: williamr@2: /** williamr@2: * Delete item by Uid. If this is a folder, all descendants and the contents williamr@2: * of them are deleted. Homepage or root cannot be deleted. williamr@2: * @since 0.9 williamr@2: * @param aUid Uid of item to delete. williamr@2: * @return Error code, including: williamr@2: * - KErrNotFound if the item is not found. williamr@2: * - KErrAccessDenied if the item's cannot be deleted. williamr@2: */ williamr@2: IMPORT_C TInt Delete( TInt aUid ); williamr@2: williamr@2: /** williamr@2: * Update an item. Remember Homapage or Last Visited Page cannot be updated using williamr@2: * this method. williamr@2: * @since 0.9 williamr@2: * @param aItem Contents from this item (except Uid) will be used to williamr@2: * update the item. williamr@2: * If successful, its Uid, Last-Mod-Time (and possibly its name) is williamr@2: * updated on return. williamr@2: * @param aUid Update this item. williamr@2: * @param aAutoRename If this is ETrue, and the name already exists, williamr@2: * the item will be renamed to a non-conflicting name. williamr@2: * @return Error code, including: williamr@2: * - KErrNotFound if the item is not found. williamr@2: * - KErrArgument if the item's data is invalid (bad name, no URL, williamr@2: * parent folder does not exist etc.). williamr@2: * - KErrAlreadyExists if the name is already in use in that folder. williamr@2: * - KErrAccessDenied for read-only items. williamr@2: */ williamr@2: IMPORT_C TInt Update williamr@2: ( CFavouritesItem& aItem, TInt aUid, TBool aAutoRename ); williamr@2: williamr@2: /** williamr@2: * Add a new item to the database. williamr@2: * If successful, its Uid, Last-Mod-Time (and possibly its name) is williamr@2: * updated on return. williamr@2: * @since 0.9 williamr@2: * @param aItem The item to add. williamr@2: * @param aAutoRename If this is ETrue, and the name already exists, williamr@2: * the item will be renamed to a non-conflicting name. williamr@2: * @return Error code, including: williamr@2: * - KErrArgument if the item's data is invalid (bad name, no URL, williamr@2: * parent folder does not exist etc.). williamr@2: * - KErrAlreadyExists if the name is already in use in that folder. williamr@2: */ williamr@2: IMPORT_C TInt Add( CFavouritesItem& aItem, TBool aAutoRename ); williamr@2: williamr@2: /** williamr@2: * Update the Homepage item. If does not exist, it is now williamr@2: * created. The old Homepage, if any, is overwritten. williamr@2: * If successful, its Uid and Last-Mod-Time is updated on return. williamr@2: * Name needs not be unique. williamr@2: * @since 0.9 williamr@2: * @param aItem Contents from this item (except Uid) will williamr@2: * be used to update the Homepage Bookmark. williamr@2: * @return Error code, including: williamr@2: * - KErrArgument if the supplied item is not item, or is not in williamr@2: * the root folder. williamr@2: */ williamr@2: IMPORT_C TInt SetHomepage( CFavouritesItem& aItem ); williamr@2: williamr@2: /** williamr@2: * Update the Last Visited. If does not exist, it is now williamr@2: * created. The old Last Visited, if any, is overwritten. williamr@2: * If successful, its Uid is updated on return. williamr@2: * Name needs not be unique. williamr@2: * @since 0.9 williamr@2: * @param aItem Contents from this item (except Uid) will williamr@2: * be used to update the Last Visited Item. williamr@2: * @return Error code, including: williamr@2: * - KErrArgument if the supplied item is not item, or is not in williamr@2: * the root folder. williamr@2: */ williamr@2: IMPORT_C TInt SetLastVisited( CFavouritesItem& aItem ); williamr@2: williamr@2: /** williamr@2: * Set factory item flag on an item. williamr@2: * (Item with this flag set will be deleted if RFS is executed.) williamr@2: * @since 0.9 williamr@2: * @param aUid Uid of item. williamr@2: * @param aFactoryItem Flag value to set. williamr@2: * @return Error code, including: williamr@2: * - KErrNotFound if the item is not found. williamr@2: */ williamr@2: IMPORT_C TInt SetFactoryItem( TInt aUid, TBool aFactoryItem ); williamr@2: williamr@2: /** williamr@2: * Set read-only flag on an item. williamr@2: * @since 0.9 williamr@2: * @param aUid Uid of item. williamr@2: * @param aReadOnly Flag value to set. williamr@2: * @return Error code, including: williamr@2: * - KErrNotFound if the item is not found. williamr@2: */ williamr@2: IMPORT_C TInt SetReadOnly( TInt aUid, TBool aReadOnly ); williamr@2: williamr@2: /** williamr@2: * Manual setting of Last Modification Time of an item. williamr@2: * Note that the Last Modification Time is automatically set by any williamr@2: * edit, so this method need not be used in usual circumstances. It is williamr@2: * provided for administration purposes only. williamr@2: * @since 0.9 williamr@2: * @param aUid Uid of item. williamr@2: * @param aModified Last Modification Time to set. williamr@2: * @return Error code, including: williamr@2: * - KErrNotFound if the item is not found. williamr@2: */ williamr@2: IMPORT_C TInt SetModified( TInt aUid, TTime aModified ); williamr@2: williamr@2: /** williamr@2: * Set preferred Uid for a folder. williamr@2: * @since 0.9 williamr@2: * @param aFolder Folder Uid. williamr@2: * @param aUid Uid to be set as preferred. Not checked to exist in the folder. williamr@2: * @return Error code, including: williamr@2: * - KErrNotFound if aFolder is not found; williamr@2: * - KErrArgument if aFolder is not a folder. williamr@2: */ williamr@2: IMPORT_C TInt SetPreferredUid( TInt aFolder, TInt aUid ); williamr@2: williamr@2: /** williamr@2: * Check if we already have this item. williamr@2: * @since 0.9 williamr@2: * @param aUid The item Uid to be checked. williamr@2: * @param aItemExists Returned value. williamr@2: * @return Error code. williamr@2: */ williamr@2: IMPORT_C TInt ItemExists( TInt aUid, TBool& aItemExists ); williamr@2: williamr@2: /** williamr@2: * Check if the folder exists. williamr@2: * @since 0.9 williamr@2: * @param aFolder The folder to be checked. williamr@2: * @param aFolderExists Returned value. williamr@2: * @return Error code. williamr@2: */ williamr@2: IMPORT_C TInt FolderExists( TInt aFolder, TBool& aFolderExists ); williamr@2: williamr@2: /** williamr@2: * Count all items matching the supplied criteria. williamr@2: * @since 0.9 williamr@2: * @param aCount Placeholder for the returned item count. In case of williamr@2: * any error, existing value is unchanged. williamr@2: * @param aParentFolderFilter Uid value to filter. KFavouritesNullUid williamr@2: * clears (all accepted); this is the default. williamr@2: * @param aTypeFilter EItem or EFolder to use filter; ENone to clear williamr@2: * filter (all accepted); this is the default. williamr@2: * @param aNameFilter Wildcard pattern to be used for name matching. williamr@2: * NULL clears (all accepted); this is the default. williamr@2: * @param aContextIdFilter ContextId value to filter. williamr@2: * KFavouritesNullContextId clears (all accepted); this is the default. williamr@2: * @return Error code. williamr@2: */ williamr@2: IMPORT_C TInt Count williamr@2: ( williamr@2: TInt& aCount, williamr@2: TInt aParentFolderFilter = KFavouritesNullUid, williamr@2: CFavouritesItem::TType aTypeFilter = CFavouritesItem::ENone, williamr@2: const TDesC* aNameFilter = NULL, williamr@2: TInt32 aContextIdFilter = KFavouritesNullContextId williamr@2: ); williamr@2: williamr@2: public: // extra data williamr@2: williamr@2: /** williamr@2: * Set data associated with an item. Any existing data, belonging to williamr@2: * item having aUid, is now replaced. The item itself is not changed. williamr@2: * In case of any errors, the data is not saved. williamr@2: * @since 0.9 williamr@2: * @param aUid The uid of the item, to which the data belongs. williamr@2: * @param aData Data) which replaces existing data. williamr@2: * @return Error code, including: williamr@2: * - KErrNotFound No item is found with aUid. williamr@2: */ williamr@2: IMPORT_C TInt SetData( TInt aUid, const MFavouritesItemData& aData ); williamr@2: williamr@2: /** williamr@2: * Get data associated with an item. williamr@2: * @since 0.9 williamr@2: * @param aUid The uid of the item, to which the data belongs. williamr@2: * @param aData Data object, which receives the data. williamr@2: * @return Error code, including: williamr@2: * - KErrNotFound No item is found with aUid. williamr@2: */ williamr@2: IMPORT_C TInt GetData( TInt aUid, MFavouritesItemData& aData ); williamr@2: williamr@2: public: // Browser data williamr@2: williamr@2: /** williamr@2: * Set Browser data associated with an item. Any existing data, williamr@2: * belonging to item having aUid, is now replaced. The item itself is williamr@2: * not changed. williamr@2: * This data is for Browser's dedicated use, do not tamper. williamr@2: * In case of any errors, the data is not saved. williamr@2: * @since 0.9 williamr@2: * @param aUid The uid of the item, to which the data belongs. williamr@2: * @param aData Data) which replaces existing data. williamr@2: * @return Error code, including: williamr@2: * - KErrNotFound No item is found with aUid. williamr@2: */ williamr@2: IMPORT_C TInt SetBrowserData( TInt aUid, const MFavouritesItemData& aData ); williamr@2: williamr@2: /** williamr@2: * Get Browser associated with an item. williamr@2: * This data is for Browser's dedicated use, do not tamper. williamr@2: * @since 0.9 williamr@2: * @param aUid The uid of the item, to which the data belongs. williamr@2: * @param aData Data object, which receives the data. williamr@2: * @return Error code, including: williamr@2: * - KErrNotFound No item is found with aUid. williamr@2: */ williamr@2: IMPORT_C TInt GetBrowserData( TInt aUid, MFavouritesItemData& aData ); williamr@2: williamr@2: public: // unique name support williamr@2: williamr@2: /** williamr@2: * Check if aName is unique in aFolder; and if not, change to williamr@2: * an unique one, appending a number. In case of any errors, aName is williamr@2: * unchanged. Names of special items (Start Page etc.) are not williamr@2: * considered (can have conflicting names). williamr@2: * @since 0.9 williamr@2: * @param aName Descriptor containing the original name and receiving williamr@2: * the resulting unique name. Must be large enough to accomodate the williamr@2: * result. (The appended text is KFavouritesMaxPostfix characters at williamr@2: * most; the resulting length is KFavouritesMaxName at most.) williamr@2: * @param aFolder Folder to be used for uniqueness-checking. williamr@2: * @return Error code, including: williamr@2: * - KErrArgument aFolder is not found. williamr@2: * - KErrBadName aName is empty. williamr@2: */ williamr@2: IMPORT_C TInt MakeUniqueName( TDes& aName, TInt aFolder ); williamr@2: williamr@2: /** williamr@2: * Check if aName is unique in its folder; and if not, change to williamr@2: * an unique one, appending a number. In case of any errors, aItem is williamr@2: * unchanged. Names of special items (Start Page etc.) are not williamr@2: * considered (can have conflicting names). williamr@2: * @since 0.9 williamr@2: * @param aItem Item to set unique name for. williamr@2: * @return Error code, including: williamr@2: * - KErrArgument aFolder is not found. williamr@2: * - KErrBadName Current name is empty. williamr@2: */ williamr@2: IMPORT_C TInt MakeUniqueName( CFavouritesItem& aItem ); williamr@2: williamr@2: public: // Browser support williamr@2: williamr@2: /** williamr@2: * Create an empty item with uid KFavouritesStartPageUid. Owner is the williamr@2: * caller. Except its uid, the item is uninitialized. The Browser williamr@2: * needs this. Note that this item does not exist in the database. williamr@2: * @since 0.9 williamr@2: * @return The created item. williamr@2: */ williamr@2: IMPORT_C CFavouritesItem* CreateStartPageItemL(); williamr@2: williamr@2: /** williamr@2: * Create a folder with uid KFavouritesAdaptiveItemsFolderUid. williamr@2: * Owner is the caller. Uid, type (folder) and parent (root) is set, williamr@2: * other properties are uninitialized. The Browser needs this. Note williamr@2: * that this item does not exist in the database. williamr@2: * @since 0.9 williamr@2: * @return The created item. williamr@2: */ williamr@2: IMPORT_C CFavouritesItem* CreateAdaptiveItemsFolderL(); williamr@2: williamr@2: public: // Files williamr@2: williamr@2: /** williamr@2: * Delete file. See RFavouritesFile. williamr@2: * @since 0.9 williamr@2: * @param aUid Uid of the item. williamr@2: * @return Errro code. williamr@2: */ williamr@2: IMPORT_C TInt DeleteFile( TInt aUid ); williamr@2: williamr@2: public: // RFS williamr@2: williamr@2: /** williamr@2: * User-level Restore Factory Settings operation. williamr@2: * Delete all items that has "factory item" flag set, then add new williamr@2: * ones from reference database. In case of name conflilcts, new williamr@2: * names are generated. Leaves on any error. williamr@2: * @since 0.9 williamr@2: * @param aName Database name. williamr@2: * @param aReferenceDbPath Full pathname of reference database. williamr@2: * @param aApMapper Access Point mapper to be used. williamr@2: */ williamr@2: IMPORT_C static void RestoreFactorySettingsL williamr@2: ( williamr@2: const TDesC& aName, williamr@2: const TDesC& aReferenceDbPath, williamr@2: MRfsApMapper& aApMapper williamr@2: ); williamr@2: williamr@2: private: // New methods williamr@2: williamr@2: /** williamr@2: * Set Homepage / Last Visited Page. williamr@2: * @since 0.9 williamr@2: * @param aItem Item data. williamr@2: * @param aUid Uid of the item to be set. williamr@2: * @return Error code. williamr@2: */ williamr@2: TInt SetSpecialItem( CFavouritesItem& aItem, TInt aUid ); williamr@2: williamr@2: /** williamr@2: * Set data associated with an item. williamr@2: * @since 0.9 williamr@2: * @param aFunction Function. williamr@2: * @param aUid The uid of the item, to which the data belongs. williamr@2: * @param aData Data which replaces existing data. williamr@2: * @return Error code. williamr@2: */ williamr@2: TInt SetData williamr@2: ( TInt aFunction, TInt aUid, const MFavouritesItemData& aData ); williamr@2: williamr@2: /** williamr@2: * Get data associated with an item. williamr@2: * @since 0.9 williamr@2: * @param aFunction Function. williamr@2: * @param aUid The uid of the item, to which the data belongs. williamr@2: * @param aData Data object, which receives the data. williamr@2: * @return Error code. williamr@2: */ williamr@2: TInt GetData williamr@2: ( TInt aFunction, TInt aUid, MFavouritesItemData& aData ); williamr@2: williamr@2: /** williamr@2: * Implementation of RestoreFactorySettingsL(). williamr@2: * @since 0.9 williamr@2: * @param aReferenceDbPath Full pathname of reference database. williamr@2: * @param aApMapper Access Point mapper to be used. williamr@2: */ williamr@2: void DoRestoreFactorySettingsL williamr@2: ( const TDesC& aReferenceDbPath, MRfsApMapper& aApMapper ); williamr@2: williamr@2: /** williamr@2: * Cleanup helper, static wrapper around the rollback call. williamr@2: * @since 0.9 williamr@2: * @param aPtr This as TAny*. williamr@2: */ williamr@2: static void StaticRollback( TAny* aPtr ); williamr@2: williamr@2: }; williamr@2: williamr@2: #endif williamr@2: williamr@2: // End of File