1.1 --- a/epoc32/include/mw/favouritesdb.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/mw/favouritesdb.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,555 @@
1.4 -favouritesdb.h
1.5 +/*
1.6 +* Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
1.7 +* All rights reserved.
1.8 +* This component and the accompanying materials are made available
1.9 +* under the terms of the License "Eclipse Public License v1.0"
1.10 +* which accompanies this distribution, and is available
1.11 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.12 +*
1.13 +* Initial Contributors:
1.14 +* Nokia Corporation - initial contribution.
1.15 +*
1.16 +* Contributors:
1.17 +*
1.18 +* Description: Declaration of RFavouritesDb.
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +#ifndef FAVOURITES_DB_H
1.24 +#define FAVOURITES_DB_H
1.25 +
1.26 +// INCLUDES
1.27 +
1.28 +#include <e32base.h>
1.29 +#include <d32dbms.h>
1.30 +#include <FavouritesItem.h>
1.31 +#include <FavouritesLimits.h>
1.32 +#include <FavouritesSession.h>
1.33 +#include <FavouritesHandle.h>
1.34 +
1.35 +// FORWARD DECLARATIONS
1.36 +
1.37 +class CFavouritesItemList;
1.38 +class MFavouritesItemData;
1.39 +class MRfsApMapper;
1.40 +
1.41 +// CLASS DECLARATION
1.42 +
1.43 +/**
1.44 +* RFavouritesDb is the representation of the favourites database.
1.45 +* This class encapsulates a session with bookmark database server.
1.46 +* It provides a way to access the database, do administration
1.47 +* (recovery, compaction) and explicit transaction support.
1.48 +*/
1.49 +class RFavouritesDb: public RFavouritesHandle
1.50 + {
1.51 +
1.52 + public: // New methods
1.53 +
1.54 + /**
1.55 + * Open the database. Created if does not exist.
1.56 + * @since 0.9
1.57 + * @param aSess Session to be used.
1.58 + * @param aName Database name.
1.59 + * @return Error code.
1.60 + */
1.61 + IMPORT_C TInt Open( RFavouritesSession& aSess, const TDesC& aName );
1.62 +
1.63 + public: // Adminstration
1.64 +
1.65 + /**
1.66 + * Get version information.
1.67 + * @since 0.9
1.68 + * @return Version object of this CFavouritesDb.
1.69 + */
1.70 + IMPORT_C TVersion Version() const;
1.71 +
1.72 + /**
1.73 + * Check if the database to be recovered is fully functional.
1.74 + * @since 0.9
1.75 + * @param aIsDamaged Result is returned here.
1.76 + * @return Error code.
1.77 + */
1.78 + IMPORT_C TInt IsDamaged( TBool& aIsDamaged );
1.79 +
1.80 + /**
1.81 + * Perform database synchronous recovery. This function requires exclusive access
1.82 + * to the database.
1.83 + * @since 0.9
1.84 + * @return Error code.
1.85 + */
1.86 + IMPORT_C TInt Recover();
1.87 +
1.88 + /**
1.89 + * Perform databas synchronous compaction. This function requires exclusive access
1.90 + * to the database.
1.91 + * @since 0.9
1.92 + * @return Error code.
1.93 + */
1.94 + IMPORT_C TInt Compact();
1.95 +
1.96 + /**
1.97 + * Get available database size.
1.98 + * @since 0.9
1.99 + * @param aSize Database size returned here.
1.100 + * @return Error code.
1.101 + */
1.102 + IMPORT_C TInt Size( RDbDatabase::TSize& aSize ) const;
1.103 +
1.104 + /**
1.105 + * Update database statistics.
1.106 + * @since 0.9
1.107 + * @return Error code.
1.108 + */
1.109 + IMPORT_C TInt UpdateStats();
1.110 +
1.111 + public: // Transaction support
1.112 +
1.113 + /**
1.114 + * Explicitly begin a transaction.
1.115 + * @since 0.9
1.116 + * @param aWrite Access mode.
1.117 + * @return Error code.
1.118 + */
1.119 + IMPORT_C TInt Begin( TBool aWrite = EFalse );
1.120 +
1.121 + /**
1.122 + * Commit the transaction.
1.123 + * @since 0.9
1.124 + * @return Error code.
1.125 + */
1.126 + IMPORT_C TInt Commit();
1.127 +
1.128 + /**
1.129 + * Roll back the transaction.
1.130 + * @since 0.9
1.131 + * @return void
1.132 + */
1.133 + IMPORT_C void Rollback();
1.134 +
1.135 + /**
1.136 + * Push a rollback on the cleanup stack. Call this after Begin() call,
1.137 + * to make the transaction leave-safe.
1.138 + * @since 0.9
1.139 + * @return void
1.140 + */
1.141 + IMPORT_C void CleanupRollbackPushL();
1.142 +
1.143 + public: // Data access / update / delete
1.144 +
1.145 + /**
1.146 + * Get the item with this Uid.
1.147 + * @since 0.9
1.148 + * @param aUid Uid or item to get.
1.149 + * @param aItem placeholder for the returned item data.
1.150 + * @return Error code.
1.151 + */
1.152 + IMPORT_C TInt Get( TInt aUid, CFavouritesItem& aItem );
1.153 +
1.154 + /**
1.155 + * Get all items matching the supplied criteria.
1.156 + * @since 0.9
1.157 + * @param aItemList placeholder for the returned item data. Existing
1.158 + * items remain (new ones appended).
1.159 + * @param aParentFolderFilter Uid value to filter. KFavouritesNullUid
1.160 + * clears (all accepted); this is the default.
1.161 + * @param aTypeFilter EItem or EFolder to use filter; ENone to clear
1.162 + * filter (all accepted); this is the default.
1.163 + * @param aNameFilter wildcard pattern to be used for name matching.
1.164 + * NULL clears (all accepted); this is the default.
1.165 + * @param aContextIdFilter ContextId value to filter.
1.166 + * KFavouritesNullContextId clears (all accepted); this is the default.
1.167 + * @return Error code.
1.168 + */
1.169 + IMPORT_C TInt GetAll
1.170 + (
1.171 + CFavouritesItemList& aItemList,
1.172 + TInt aParentFolderFilter = KFavouritesNullUid,
1.173 + CFavouritesItem::TType aTypeFilter = CFavouritesItem::ENone,
1.174 + const TDesC* aNameFilter = NULL,
1.175 + TInt32 aContextIdFilter = KFavouritesNullContextId
1.176 + );
1.177 +
1.178 + /**
1.179 + * Get uids of all items matching the supplied criteria.
1.180 + * @since 0.9
1.181 + * @param aUids placeholder for the returned item data. Existing
1.182 + * items remain (new ones appended).
1.183 + * @param aParentFolderFilter Uid value to filter. KFavouritesNullUid
1.184 + * clears (all accepted); this is the default.
1.185 + * @param aTypeFilter EItem or EFolder to use filter; ENone to clear
1.186 + * filter (all accepted); this is the default.
1.187 + * @param aNameFilter wildcard pattern to be used for name matching.
1.188 + * NULL clears (all accepted); this is the default.
1.189 + * @param aContextIdFilter ContextId value to filter.
1.190 + * KFavouritesNullContextId clears (all accepted); this is the default.
1.191 + * @return Error code.
1.192 + */
1.193 + IMPORT_C TInt GetUids
1.194 + (
1.195 + CArrayFix<TInt>& aUids,
1.196 + TInt aParentFolderFilter = KFavouritesNullUid,
1.197 + CFavouritesItem::TType aTypeFilter = CFavouritesItem::ENone,
1.198 + const TDesC* aNameFilter = NULL,
1.199 + TInt32 aContextIdFilter = KFavouritesNullContextId
1.200 + );
1.201 +
1.202 + /**
1.203 + * Get preferred Uid for a folder.
1.204 + * @since 0.9
1.205 + * @param aFolder Folder Uid.
1.206 + * @param aPreferredUid Uid of preferred item is returned here.
1.207 + * @return Error code.
1.208 + */
1.209 + IMPORT_C TInt PreferredUid( TInt aFolder, TInt& aPreferredUid );
1.210 +
1.211 + /**
1.212 + * Delete item by Uid. If this is a folder, all descendants and the contents
1.213 + * of them are deleted. Homepage or root cannot be deleted.
1.214 + * @since 0.9
1.215 + * @param aUid Uid of item to delete.
1.216 + * @return Error code, including:
1.217 + * - KErrNotFound if the item is not found.
1.218 + * - KErrAccessDenied if the item's cannot be deleted.
1.219 + */
1.220 + IMPORT_C TInt Delete( TInt aUid );
1.221 +
1.222 + /**
1.223 + * Update an item. Remember Homapage or Last Visited Page cannot be updated using
1.224 + * this method.
1.225 + * @since 0.9
1.226 + * @param aItem Contents from this item (except Uid) will be used to
1.227 + * update the item.
1.228 + * If successful, its Uid, Last-Mod-Time (and possibly its name) is
1.229 + * updated on return.
1.230 + * @param aUid Update this item.
1.231 + * @param aAutoRename If this is ETrue, and the name already exists,
1.232 + * the item will be renamed to a non-conflicting name.
1.233 + * @return Error code, including:
1.234 + * - KErrNotFound if the item is not found.
1.235 + * - KErrArgument if the item's data is invalid (bad name, no URL,
1.236 + * parent folder does not exist etc.).
1.237 + * - KErrAlreadyExists if the name is already in use in that folder.
1.238 + * - KErrAccessDenied for read-only items.
1.239 + */
1.240 + IMPORT_C TInt Update
1.241 + ( CFavouritesItem& aItem, TInt aUid, TBool aAutoRename );
1.242 +
1.243 + /**
1.244 + * Add a new item to the database.
1.245 + * If successful, its Uid, Last-Mod-Time (and possibly its name) is
1.246 + * updated on return.
1.247 + * @since 0.9
1.248 + * @param aItem The item to add.
1.249 + * @param aAutoRename If this is ETrue, and the name already exists,
1.250 + * the item will be renamed to a non-conflicting name.
1.251 + * @return Error code, including:
1.252 + * - KErrArgument if the item's data is invalid (bad name, no URL,
1.253 + * parent folder does not exist etc.).
1.254 + * - KErrAlreadyExists if the name is already in use in that folder.
1.255 + */
1.256 + IMPORT_C TInt Add( CFavouritesItem& aItem, TBool aAutoRename );
1.257 +
1.258 + /**
1.259 + * Update the Homepage item. If does not exist, it is now
1.260 + * created. The old Homepage, if any, is overwritten.
1.261 + * If successful, its Uid and Last-Mod-Time is updated on return.
1.262 + * Name needs not be unique.
1.263 + * @since 0.9
1.264 + * @param aItem Contents from this item (except Uid) will
1.265 + * be used to update the Homepage Bookmark.
1.266 + * @return Error code, including:
1.267 + * - KErrArgument if the supplied item is not item, or is not in
1.268 + * the root folder.
1.269 + */
1.270 + IMPORT_C TInt SetHomepage( CFavouritesItem& aItem );
1.271 +
1.272 + /**
1.273 + * Update the Last Visited. If does not exist, it is now
1.274 + * created. The old Last Visited, if any, is overwritten.
1.275 + * If successful, its Uid is updated on return.
1.276 + * Name needs not be unique.
1.277 + * @since 0.9
1.278 + * @param aItem Contents from this item (except Uid) will
1.279 + * be used to update the Last Visited Item.
1.280 + * @return Error code, including:
1.281 + * - KErrArgument if the supplied item is not item, or is not in
1.282 + * the root folder.
1.283 + */
1.284 + IMPORT_C TInt SetLastVisited( CFavouritesItem& aItem );
1.285 +
1.286 + /**
1.287 + * Set factory item flag on an item.
1.288 + * (Item with this flag set will be deleted if RFS is executed.)
1.289 + * @since 0.9
1.290 + * @param aUid Uid of item.
1.291 + * @param aFactoryItem Flag value to set.
1.292 + * @return Error code, including:
1.293 + * - KErrNotFound if the item is not found.
1.294 + */
1.295 + IMPORT_C TInt SetFactoryItem( TInt aUid, TBool aFactoryItem );
1.296 +
1.297 + /**
1.298 + * Set read-only flag on an item.
1.299 + * @since 0.9
1.300 + * @param aUid Uid of item.
1.301 + * @param aReadOnly Flag value to set.
1.302 + * @return Error code, including:
1.303 + * - KErrNotFound if the item is not found.
1.304 + */
1.305 + IMPORT_C TInt SetReadOnly( TInt aUid, TBool aReadOnly );
1.306 +
1.307 + /**
1.308 + * Manual setting of Last Modification Time of an item.
1.309 + * Note that the Last Modification Time is automatically set by any
1.310 + * edit, so this method need not be used in usual circumstances. It is
1.311 + * provided for administration purposes only.
1.312 + * @since 0.9
1.313 + * @param aUid Uid of item.
1.314 + * @param aModified Last Modification Time to set.
1.315 + * @return Error code, including:
1.316 + * - KErrNotFound if the item is not found.
1.317 + */
1.318 + IMPORT_C TInt SetModified( TInt aUid, TTime aModified );
1.319 +
1.320 + /**
1.321 + * Set preferred Uid for a folder.
1.322 + * @since 0.9
1.323 + * @param aFolder Folder Uid.
1.324 + * @param aUid Uid to be set as preferred. Not checked to exist in the folder.
1.325 + * @return Error code, including:
1.326 + * - KErrNotFound if aFolder is not found;
1.327 + * - KErrArgument if aFolder is not a folder.
1.328 + */
1.329 + IMPORT_C TInt SetPreferredUid( TInt aFolder, TInt aUid );
1.330 +
1.331 + /**
1.332 + * Check if we already have this item.
1.333 + * @since 0.9
1.334 + * @param aUid The item Uid to be checked.
1.335 + * @param aItemExists Returned value.
1.336 + * @return Error code.
1.337 + */
1.338 + IMPORT_C TInt ItemExists( TInt aUid, TBool& aItemExists );
1.339 +
1.340 + /**
1.341 + * Check if the folder exists.
1.342 + * @since 0.9
1.343 + * @param aFolder The folder to be checked.
1.344 + * @param aFolderExists Returned value.
1.345 + * @return Error code.
1.346 + */
1.347 + IMPORT_C TInt FolderExists( TInt aFolder, TBool& aFolderExists );
1.348 +
1.349 + /**
1.350 + * Count all items matching the supplied criteria.
1.351 + * @since 0.9
1.352 + * @param aCount Placeholder for the returned item count. In case of
1.353 + * any error, existing value is unchanged.
1.354 + * @param aParentFolderFilter Uid value to filter. KFavouritesNullUid
1.355 + * clears (all accepted); this is the default.
1.356 + * @param aTypeFilter EItem or EFolder to use filter; ENone to clear
1.357 + * filter (all accepted); this is the default.
1.358 + * @param aNameFilter Wildcard pattern to be used for name matching.
1.359 + * NULL clears (all accepted); this is the default.
1.360 + * @param aContextIdFilter ContextId value to filter.
1.361 + * KFavouritesNullContextId clears (all accepted); this is the default.
1.362 + * @return Error code.
1.363 + */
1.364 + IMPORT_C TInt Count
1.365 + (
1.366 + TInt& aCount,
1.367 + TInt aParentFolderFilter = KFavouritesNullUid,
1.368 + CFavouritesItem::TType aTypeFilter = CFavouritesItem::ENone,
1.369 + const TDesC* aNameFilter = NULL,
1.370 + TInt32 aContextIdFilter = KFavouritesNullContextId
1.371 + );
1.372 +
1.373 + public: // extra data
1.374 +
1.375 + /**
1.376 + * Set data associated with an item. Any existing data, belonging to
1.377 + * item having aUid, is now replaced. The item itself is not changed.
1.378 + * In case of any errors, the data is not saved.
1.379 + * @since 0.9
1.380 + * @param aUid The uid of the item, to which the data belongs.
1.381 + * @param aData Data) which replaces existing data.
1.382 + * @return Error code, including:
1.383 + * - KErrNotFound No item is found with aUid.
1.384 + */
1.385 + IMPORT_C TInt SetData( TInt aUid, const MFavouritesItemData& aData );
1.386 +
1.387 + /**
1.388 + * Get data associated with an item.
1.389 + * @since 0.9
1.390 + * @param aUid The uid of the item, to which the data belongs.
1.391 + * @param aData Data object, which receives the data.
1.392 + * @return Error code, including:
1.393 + * - KErrNotFound No item is found with aUid.
1.394 + */
1.395 + IMPORT_C TInt GetData( TInt aUid, MFavouritesItemData& aData );
1.396 +
1.397 + public: // Browser data
1.398 +
1.399 + /**
1.400 + * Set Browser data associated with an item. Any existing data,
1.401 + * belonging to item having aUid, is now replaced. The item itself is
1.402 + * not changed.
1.403 + * This data is for Browser's dedicated use, do not tamper.
1.404 + * In case of any errors, the data is not saved.
1.405 + * @since 0.9
1.406 + * @param aUid The uid of the item, to which the data belongs.
1.407 + * @param aData Data) which replaces existing data.
1.408 + * @return Error code, including:
1.409 + * - KErrNotFound No item is found with aUid.
1.410 + */
1.411 + IMPORT_C TInt SetBrowserData( TInt aUid, const MFavouritesItemData& aData );
1.412 +
1.413 + /**
1.414 + * Get Browser associated with an item.
1.415 + * This data is for Browser's dedicated use, do not tamper.
1.416 + * @since 0.9
1.417 + * @param aUid The uid of the item, to which the data belongs.
1.418 + * @param aData Data object, which receives the data.
1.419 + * @return Error code, including:
1.420 + * - KErrNotFound No item is found with aUid.
1.421 + */
1.422 + IMPORT_C TInt GetBrowserData( TInt aUid, MFavouritesItemData& aData );
1.423 +
1.424 + public: // unique name support
1.425 +
1.426 + /**
1.427 + * Check if aName is unique in aFolder; and if not, change to
1.428 + * an unique one, appending a number. In case of any errors, aName is
1.429 + * unchanged. Names of special items (Start Page etc.) are not
1.430 + * considered (can have conflicting names).
1.431 + * @since 0.9
1.432 + * @param aName Descriptor containing the original name and receiving
1.433 + * the resulting unique name. Must be large enough to accomodate the
1.434 + * result. (The appended text is KFavouritesMaxPostfix characters at
1.435 + * most; the resulting length is KFavouritesMaxName at most.)
1.436 + * @param aFolder Folder to be used for uniqueness-checking.
1.437 + * @return Error code, including:
1.438 + * - KErrArgument aFolder is not found.
1.439 + * - KErrBadName aName is empty.
1.440 + */
1.441 + IMPORT_C TInt MakeUniqueName( TDes& aName, TInt aFolder );
1.442 +
1.443 + /**
1.444 + * Check if aName is unique in its folder; and if not, change to
1.445 + * an unique one, appending a number. In case of any errors, aItem is
1.446 + * unchanged. Names of special items (Start Page etc.) are not
1.447 + * considered (can have conflicting names).
1.448 + * @since 0.9
1.449 + * @param aItem Item to set unique name for.
1.450 + * @return Error code, including:
1.451 + * - KErrArgument aFolder is not found.
1.452 + * - KErrBadName Current name is empty.
1.453 + */
1.454 + IMPORT_C TInt MakeUniqueName( CFavouritesItem& aItem );
1.455 +
1.456 + public: // Browser support
1.457 +
1.458 + /**
1.459 + * Create an empty item with uid KFavouritesStartPageUid. Owner is the
1.460 + * caller. Except its uid, the item is uninitialized. The Browser
1.461 + * needs this. Note that this item does not exist in the database.
1.462 + * @since 0.9
1.463 + * @return The created item.
1.464 + */
1.465 + IMPORT_C CFavouritesItem* CreateStartPageItemL();
1.466 +
1.467 + /**
1.468 + * Create a folder with uid KFavouritesAdaptiveItemsFolderUid.
1.469 + * Owner is the caller. Uid, type (folder) and parent (root) is set,
1.470 + * other properties are uninitialized. The Browser needs this. Note
1.471 + * that this item does not exist in the database.
1.472 + * @since 0.9
1.473 + * @return The created item.
1.474 + */
1.475 + IMPORT_C CFavouritesItem* CreateAdaptiveItemsFolderL();
1.476 +
1.477 + public: // Files
1.478 +
1.479 + /**
1.480 + * Delete file. See RFavouritesFile.
1.481 + * @since 0.9
1.482 + * @param aUid Uid of the item.
1.483 + * @return Errro code.
1.484 + */
1.485 + IMPORT_C TInt DeleteFile( TInt aUid );
1.486 +
1.487 + public: // RFS
1.488 +
1.489 + /**
1.490 + * User-level Restore Factory Settings operation.
1.491 + * Delete all items that has "factory item" flag set, then add new
1.492 + * ones from reference database. In case of name conflilcts, new
1.493 + * names are generated. Leaves on any error.
1.494 + * @since 0.9
1.495 + * @param aName Database name.
1.496 + * @param aReferenceDbPath Full pathname of reference database.
1.497 + * @param aApMapper Access Point mapper to be used.
1.498 + */
1.499 + IMPORT_C static void RestoreFactorySettingsL
1.500 + (
1.501 + const TDesC& aName,
1.502 + const TDesC& aReferenceDbPath,
1.503 + MRfsApMapper& aApMapper
1.504 + );
1.505 +
1.506 + private: // New methods
1.507 +
1.508 + /**
1.509 + * Set Homepage / Last Visited Page.
1.510 + * @since 0.9
1.511 + * @param aItem Item data.
1.512 + * @param aUid Uid of the item to be set.
1.513 + * @return Error code.
1.514 + */
1.515 + TInt SetSpecialItem( CFavouritesItem& aItem, TInt aUid );
1.516 +
1.517 + /**
1.518 + * Set data associated with an item.
1.519 + * @since 0.9
1.520 + * @param aFunction Function.
1.521 + * @param aUid The uid of the item, to which the data belongs.
1.522 + * @param aData Data which replaces existing data.
1.523 + * @return Error code.
1.524 + */
1.525 + TInt SetData
1.526 + ( TInt aFunction, TInt aUid, const MFavouritesItemData& aData );
1.527 +
1.528 + /**
1.529 + * Get data associated with an item.
1.530 + * @since 0.9
1.531 + * @param aFunction Function.
1.532 + * @param aUid The uid of the item, to which the data belongs.
1.533 + * @param aData Data object, which receives the data.
1.534 + * @return Error code.
1.535 + */
1.536 + TInt GetData
1.537 + ( TInt aFunction, TInt aUid, MFavouritesItemData& aData );
1.538 +
1.539 + /**
1.540 + * Implementation of RestoreFactorySettingsL().
1.541 + * @since 0.9
1.542 + * @param aReferenceDbPath Full pathname of reference database.
1.543 + * @param aApMapper Access Point mapper to be used.
1.544 + */
1.545 + void DoRestoreFactorySettingsL
1.546 + ( const TDesC& aReferenceDbPath, MRfsApMapper& aApMapper );
1.547 +
1.548 + /**
1.549 + * Cleanup helper, static wrapper around the rollback call.
1.550 + * @since 0.9
1.551 + * @param aPtr This as TAny*.
1.552 + */
1.553 + static void StaticRollback( TAny* aPtr );
1.554 +
1.555 + };
1.556 +
1.557 +#endif
1.558 +
1.559 +// End of File