omads/omadsextensions/adapters/bookmark/src/bookmarkdatastore.cpp
changeset 0 dab8a81a92de
child 3 c2b8a5ae6ed5
equal deleted inserted replaced
-1:000000000000 0:dab8a81a92de
       
     1 /*
       
     2 * Copyright (c) 2005-2009 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:  Part of SyncML Data Synchronization Plug In Adapter
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <sysutil.h> 
       
    20 #include <FavouritesItem.h>
       
    21 #include <FavouritesItemList.h> 
       
    22 
       
    23 #include <FeedsServerClient.h>
       
    24 #include <FeedsServerFeed.h>
       
    25 #include <FeedsServerFolderItem.h>
       
    26 
       
    27 #include "bookmarkdatastore.h"
       
    28 #include "vbookmarkconverter.h"
       
    29 #include "omadsfolderobject.h"
       
    30 #include "bookmarkdataproviderdefs.h"
       
    31 #include "conversionutil.h"
       
    32 #include "changefinder.h"
       
    33 #include "logger.h"
       
    34 
       
    35 
       
    36 _LIT8( KBookmarkFolderMimeType, "application/vnd.omads-folder+xml" );
       
    37 _LIT8( KBookmarkFolderMimeVersion, "" );
       
    38 _LIT8( KBookmarkItemMimeType, "text/x-vbookmark" );
       
    39 _LIT8( KBookmarkItemMimeVersion, "" );
       
    40 _LIT( KRSSRootFolderName, "Web Feeds" );
       
    41 
       
    42 const TInt KDefaultBufferSize = 1024;
       
    43 const TInt KDataBufferNotReady = -1;
       
    44 const TInt KRssFeedsOffset = 50000;
       
    45 // -----------------------------------------------------------------------------
       
    46 // CBookmarkDataStore::CBookmarkDataStore
       
    47 // C++ default constructor can NOT contain any code, that might leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 CBookmarkDataStore::CBookmarkDataStore() :
       
    50     iDataBaseOpened( EFalse ), iFeedsServer(*this), iRootFolder(*this),
       
    51     iKey( TKeyArrayFix( _FOFF( TNSmlSnapshotItem, ItemId() ), ECmpTInt ) ),
       
    52     iHasHistory( EFalse )
       
    53     {
       
    54     LOGGER_ENTERFN( "CBookmarkDataStore" );
       
    55     LOGGER_LEAVEFN( "CBookmarkDataStore" ); 
       
    56     }
       
    57     
       
    58 // -----------------------------------------------------------------------------
       
    59 // CBookmarkDataStore::ConstructL
       
    60 // Symbian 2nd phase constructor, can leave.
       
    61 // -----------------------------------------------------------------------------    
       
    62 void CBookmarkDataStore::ConstructL()
       
    63     {
       
    64     LOGGER_ENTERFN( "CBookmarkDataStore::ConstructL" );
       
    65     
       
    66     User::LeaveIfError( iRfs.Connect() );
       
    67     User::LeaveIfError( iSession.Connect() );
       
    68     
       
    69     iNewItems = new ( ELeave ) CNSmlDataItemUidSet;
       
    70     iDeletedItems = new ( ELeave ) CNSmlDataItemUidSet;
       
    71     iSoftDeletedItems = new ( ELeave ) CNSmlDataItemUidSet;
       
    72     iUpdatedItems = new ( ELeave ) CNSmlDataItemUidSet;
       
    73     iMovedItems = new ( ELeave ) CNSmlDataItemUidSet;
       
    74     
       
    75     LOGGER_LEAVEFN( "CBookmarkDataStore::ConstructL" );
       
    76     }
       
    77     
       
    78 // -----------------------------------------------------------------------------
       
    79 // CBookmarkDataStore::~CBookmarkDataStore
       
    80 // Destructor
       
    81 // -----------------------------------------------------------------------------    
       
    82 CBookmarkDataStore::~CBookmarkDataStore()
       
    83     {
       
    84     LOGGER_ENTERFN( "~CBookmarkDataStore" );
       
    85 
       
    86     delete iDataBuffer;
       
    87     delete iNewItems;
       
    88     delete iDeletedItems;
       
    89     delete iSoftDeletedItems;
       
    90     delete iUpdatedItems;
       
    91     delete iMovedItems;
       
    92     delete iItemToBeReplaced;
       
    93     
       
    94     if ( iChangeFinder )
       
    95         {
       
    96         TRAPD( error, iChangeFinder->CloseL() );
       
    97         if ( error != KErrNone )
       
    98             {
       
    99             LOGGER_WRITE_1( "iChangeFinder->CloseL() leaved with %d", error );
       
   100             }
       
   101         }
       
   102     delete iChangeFinder;
       
   103     
       
   104     delete iConverter;
       
   105             
       
   106     if ( iDataBaseOpened )
       
   107         {
       
   108         iDb.Close();
       
   109         iRootFolder.Close();
       
   110         iFeedsServer.Close();
       
   111         }
       
   112     
       
   113     iSession.Close();
       
   114     iRfs.Close();
       
   115     LOGGER_LEAVEFN( "~CBookmarkDataStore" );
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CBookmarkDataStore::NewL
       
   120 // Two-phased constructor.
       
   121 // -----------------------------------------------------------------------------
       
   122 CBookmarkDataStore* CBookmarkDataStore::NewL()
       
   123     {
       
   124     LOGGER_ENTERFN( "CBookmarkDataStore::NewL" );
       
   125     CBookmarkDataStore* self = CBookmarkDataStore::NewLC();
       
   126     CleanupStack::Pop( self );
       
   127     LOGGER_LEAVEFN( "CBookmarkDataStore::NewL" );
       
   128     return self;
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CBookmarkDataStore::NewLC
       
   133 // Two-phased constructor.
       
   134 // -----------------------------------------------------------------------------
       
   135 CBookmarkDataStore* CBookmarkDataStore::NewLC()
       
   136     {
       
   137     LOGGER_ENTERFN( "CBookmarkDataStore::NewLC" );
       
   138     CBookmarkDataStore* self = new ( ELeave ) CBookmarkDataStore();
       
   139     CleanupStack::PushL( self );
       
   140     self->ConstructL();
       
   141     LOGGER_LEAVEFN( "CBookmarkDataStore::NewLC" );
       
   142     return self;
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CBookmarkDataStore::DoOpenL
       
   147 // Opens database.
       
   148 // -----------------------------------------------------------------------------
       
   149 void CBookmarkDataStore::DoOpenL( const TDesC& /*aStoreName*/,
       
   150     MSmlSyncRelationship& aContext, TRequestStatus& aStatus )
       
   151     {
       
   152     LOGGER_ENTERFN( "CBookmarkDataStore::DoOpenL" );
       
   153     
       
   154     iCallerStatus = &aStatus;           
       
   155     *iCallerStatus = KRequestPending;
       
   156     
       
   157     if ( iDataBaseOpened )
       
   158         {
       
   159         User::RequestComplete( iCallerStatus, KErrInUse );
       
   160         LOGGER_WRITE( "CBookmarkDataStore::DoOpenL failed with KErrInUse." );
       
   161         return;
       
   162         }
       
   163         
       
   164     // Create ChangeFinder
       
   165     if ( iChangeFinder )
       
   166         {
       
   167         delete iChangeFinder;
       
   168         iChangeFinder = NULL;
       
   169         }
       
   170     iChangeFinder = CChangeFinder::NewL( aContext, iKey, iHasHistory );
       
   171     
       
   172     // Create converter object
       
   173     if ( iConverter )
       
   174         {
       
   175         delete iConverter;
       
   176         iConverter = NULL;
       
   177         }
       
   178     iConverter = CBookmarkConversionUtil::NewL();
       
   179     
       
   180 
       
   181     TInt err( KErrNone );       
       
   182     err = iDb.Open( iSession, KBrowserBookmarks );
       
   183     if ( err )
       
   184         {
       
   185         LOGGER_WRITE_1( "CBookmarkDataStore::DoOpenL iDb.Open err: %d.", err );
       
   186         User::RequestComplete( iCallerStatus, err );
       
   187         return;
       
   188         }
       
   189     err = iFeedsServer.Connect();
       
   190     if ( err )
       
   191         {
       
   192         LOGGER_WRITE_1( "CBookmarkDataStore::DoOpenL iFeedsServer.Connect err: %d.", err );
       
   193         User::RequestComplete( iCallerStatus, err );
       
   194         return;
       
   195         }
       
   196     err = iRootFolder.Open( iFeedsServer );
       
   197     if ( err )
       
   198         {
       
   199         LOGGER_WRITE_1( "CBookmarkDataStore::DoOpenL iRootFolder.Open err: %d.", err );
       
   200         User::RequestComplete( iCallerStatus, err );
       
   201         return;
       
   202         }
       
   203         
       
   204     iRootFolder.FetchRootFolderItemL(); // calls FolderItemRequestCompleted when completed
       
   205     
       
   206     LOGGER_LEAVEFN( "CBookmarkDataStore::DoOpenL" );
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CBookmarkDataStore::FolderItemRequestCompleted
       
   211 // RSS item database request is completed
       
   212 // -----------------------------------------------------------------------------
       
   213 void CBookmarkDataStore::FolderItemRequestCompleted( TInt aStatus,
       
   214     CRequestHandler::TRequestHandlerType )
       
   215     {
       
   216     LOGGER_ENTERFN( "CBookmarkDataStore::FolderItemRequestCompleted" );
       
   217     
       
   218     TRAPD( err, DoFolderItemRequestCompletedL( aStatus ) );
       
   219     
       
   220     if ( err != KErrNone )
       
   221         {
       
   222         LOGGER_WRITE_1( "DoFolderItemRequestCompletedL leaved with err: %d", err );
       
   223         User::RequestComplete( iCallerStatus, err );
       
   224         }
       
   225     
       
   226     LOGGER_LEAVEFN( "CBookmarkDataStore::FolderItemRequestCompleted" );
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CBookmarkDataStore::DoFolderItemRequestCompletedL
       
   231 // RSS item database request is completed
       
   232 // -----------------------------------------------------------------------------
       
   233 void CBookmarkDataStore::DoFolderItemRequestCompletedL( TInt aStatus )
       
   234     {
       
   235     LOGGER_ENTERFN( "CBookmarkDataStore::DoFolderItemRequestCompletedL" );
       
   236     switch ( iCurrentState )
       
   237         {
       
   238         case EClosed : 
       
   239             {
       
   240             LOGGER_WRITE("Database ready");
       
   241             iDataBaseOpened = ETrue;
       
   242             iCurrentState = EOpenAndWaiting;
       
   243             RegisterSnapshotL();
       
   244             break;
       
   245             }
       
   246         
       
   247         // bookmark is added (Add command)
       
   248         case EBookmarkCreating :
       
   249            	{
       
   250            	// RSS Item has been created.
       
   251            	LOGGER_WRITE_1("RSS item created, err %d", aStatus);
       
   252            	// Restore state
       
   253            	iCurrentState = EOpenAndWaiting;
       
   254             if ( aStatus == KErrNone )
       
   255                 {
       
   256                 RssItemCreatedL();
       
   257                 }
       
   258             break;
       
   259             }
       
   260         
       
   261         // bookmark is updated (Replace command)
       
   262         case EBookmarkUpdating :
       
   263             {
       
   264             LOGGER_WRITE("RSS item replaced");
       
   265             if ( aStatus == KErrNone )
       
   266                 {
       
   267                 TBool moveNeeded(EFalse);
       
   268                 RssItemReplacedL( moveNeeded );
       
   269                 
       
   270                 if ( moveNeeded )
       
   271                     {
       
   272                     // Moving is still ongoing, don't complete request yet.
       
   273                     return;
       
   274                     }
       
   275                 
       
   276                 LOGGER_WRITE_1("Item ID: %d", *iCurrentItem);
       
   277                 LOGGER_WRITE_1("Parent ID: %d", iParentFolder);
       
   278                 }
       
   279             // Restore state
       
   280             iCurrentState = EOpenAndWaiting;
       
   281             break;
       
   282             }
       
   283         
       
   284         // bookmark is updated and moved (Replace command, 2nd phase)
       
   285         case EBookmarkUpdatedAndMoving:
       
   286             {
       
   287             LOGGER_WRITE_1( "RSS item moved (replaced), err: %d", aStatus );
       
   288             if ( aStatus == KErrNone )
       
   289                 {
       
   290                 // Inform ChangeFinder of updated item
       
   291                 iChangeFinder->ItemUpdatedL( *iMovedItem ); // ownership transferred
       
   292                 iMovedItem = NULL;
       
   293                 LOGGER_WRITE( "ItemReplacedL" );
       
   294                 }
       
   295             else
       
   296                 {
       
   297                 delete iMovedItem;
       
   298                 iMovedItem = NULL;
       
   299                 }
       
   300             // Restore state
       
   301             iCurrentState = EOpenAndWaiting;
       
   302             break;
       
   303             }
       
   304         
       
   305         // bookmark is moved (Move command)
       
   306         case EBookmarkMoving:
       
   307             {
       
   308             LOGGER_WRITE_1( "RSS item moved, err: %d", aStatus );
       
   309             if ( aStatus == KErrNone )
       
   310                 {
       
   311                 iChangeFinder->ItemMovedL( *iMovedItem ); // ownership transferred
       
   312                 iMovedItem = NULL;
       
   313                 }
       
   314             else
       
   315                 {
       
   316                 delete iMovedItem;
       
   317                 iMovedItem = NULL;
       
   318                 }
       
   319             // Restore state
       
   320             iCurrentState = EOpenAndWaiting;
       
   321             break;
       
   322             }
       
   323             
       
   324         case EBookmarkDeleting:
       
   325             {
       
   326             LOGGER_WRITE_1( "RSS item removed, err: %d", aStatus );
       
   327             if ( aStatus == KErrNone )
       
   328                 {
       
   329                 // Inform ChangeFinder of the removed item
       
   330                 TSnapshotItem item( iReplaceItem );     
       
   331                 iChangeFinder->ItemDeletedL( item );
       
   332                 }
       
   333             // Restore state
       
   334             iCurrentState = EOpenAndWaiting;
       
   335             break;
       
   336             }
       
   337         case EBookmarkDeletingAll:
       
   338             {
       
   339             LOGGER_WRITE_1( "all RSS items removed, err: %d", aStatus );
       
   340             break;
       
   341             }
       
   342         
       
   343         default :
       
   344             LOGGER_WRITE_1( "Invalid state: %d", iCurrentState );
       
   345             return;
       
   346         }
       
   347     User::RequestComplete( iCallerStatus, aStatus );
       
   348     LOGGER_LEAVEFN( "CBookmarkDataStore::DoFolderItemRequestCompletedL" ); 
       
   349     }
       
   350 
       
   351 // -----------------------------------------------------------------------------
       
   352 // CBookmarkDataStore::RssItemCreatedL
       
   353 // Rss item has been created, add item to changefinder
       
   354 // -----------------------------------------------------------------------------
       
   355 void CBookmarkDataStore::RssItemCreatedL()
       
   356     {
       
   357     TRACE_FUNC_ENTRY;
       
   358     if ( !iRootFolder.HasRootFolderItem() )
       
   359         {
       
   360         LOGGER_WRITE( "rss root folder not found" );
       
   361         User::Leave( KErrNotFound );
       
   362         }
       
   363     const CFolderItem& rootFolder = iRootFolder.RootFolderItem();
       
   364     const CFolderItem* parent = rootFolder.Search( iParentFolder - KRssFeedsOffset );
       
   365     if ( !parent )
       
   366         {
       
   367         LOGGER_WRITE( "parent folder not found" );
       
   368         User::Leave( KErrNotFound );
       
   369         }
       
   370     LOGGER_WRITE_1("parent->Id(): %d", parent->Id());
       
   371     LOGGER_WRITE_1( "Name: %S", &iNewItemName );
       
   372     const CFolderItem* addedItem = parent->Search( iNewItemName );
       
   373     iNewItemName.Zero();
       
   374     if ( addedItem )
       
   375         {
       
   376         LOGGER_WRITE_1("addedItem found, id: %d", addedItem->Id());
       
   377         
       
   378         // Output the uid value of new item
       
   379         *iCurrentItem = addedItem->Id() + KRssFeedsOffset;
       
   380         
       
   381         // Inform ChangeFinder of the added item
       
   382         TSnapshotItem snapshotItem( *iCurrentItem );
       
   383         snapshotItem.SetParentId( iParentFolder );
       
   384         snapshotItem.CreateHashL( addedItem->Name(), addedItem->SourceUrl() );
       
   385         iChangeFinder->ItemAddedL( snapshotItem );
       
   386         LOGGER_WRITE( "ItemAddedL" );
       
   387         }
       
   388     else
       
   389         {
       
   390         LOGGER_WRITE( "Added item not found" );
       
   391         User::Leave( KErrNotFound );
       
   392         }
       
   393     LOGGER_WRITE_1("Item ID: %d", *iCurrentItem);
       
   394     LOGGER_WRITE_1("Parent ID: %d", iParentFolder);
       
   395     TRACE_FUNC_EXIT;
       
   396     }
       
   397 
       
   398 // -----------------------------------------------------------------------------
       
   399 // CBookmarkDataStore::RssItemReplacedL
       
   400 // Rss item has been replaced, update changefinder
       
   401 // -----------------------------------------------------------------------------
       
   402 void CBookmarkDataStore::RssItemReplacedL( TBool& aMoveNeeded )
       
   403     {
       
   404     TRACE_FUNC_ENTRY;
       
   405     aMoveNeeded = EFalse;
       
   406     if ( !iRootFolder.HasRootFolderItem() )
       
   407         {
       
   408         LOGGER_WRITE( "rss root folder not found" );
       
   409         User::Leave( KErrNotFound );
       
   410         }
       
   411     const CFolderItem& rootFolder = iRootFolder.RootFolderItem();
       
   412     LOGGER_WRITE_1( "rootFolder.Search %d", iReplaceItem - KRssFeedsOffset );
       
   413     const CFolderItem* modItem = rootFolder.Search( iReplaceItem - KRssFeedsOffset );
       
   414     if ( modItem )
       
   415         {
       
   416         LOGGER_WRITE_1("Item found, id: %d", modItem->Id());
       
   417         
       
   418         const CFolderItem* parent = modItem->Parent();
       
   419         if ( parent )
       
   420             {
       
   421             TInt currentParent = parent->Id() + KRssFeedsOffset;
       
   422             if ( iParentFolder != parent->Id() + KRssFeedsOffset )
       
   423                 {
       
   424                 // move to another folder
       
   425                 const CFolderItem* newParent = rootFolder.Search(
       
   426                     iParentFolder - KRssFeedsOffset );
       
   427                 if ( !newParent )
       
   428                     {
       
   429                     // new parent not found
       
   430                     LOGGER_WRITE( "new parent not found" );
       
   431                     User::Leave( KErrPathNotFound );
       
   432                     }
       
   433                 else if ( !newParent->IsFolder() )
       
   434                     {
       
   435                     // not a folder
       
   436                     LOGGER_WRITE( "parent is not a folder" );
       
   437                     User::Leave( KErrPathNotFound );
       
   438                     }
       
   439                 else
       
   440                     {
       
   441                     // Output the uid value of new item
       
   442                     *iCurrentItem = modItem->Id() + KRssFeedsOffset;
       
   443         
       
   444                     iCurrentState = EBookmarkUpdatedAndMoving;
       
   445                     RPointerArray<const CFolderItem> movedItems;
       
   446                     CleanupClosePushL( movedItems );
       
   447                     movedItems.Append( modItem );
       
   448                     // FolderItemRequestCompleted is called when ready
       
   449                     iRootFolder.MoveFolderItemsToL( movedItems, *newParent);
       
   450                     CleanupStack::PopAndDestroy( &movedItems );
       
   451                     aMoveNeeded = ETrue;
       
   452                     
       
   453                     delete iMovedItem;
       
   454                     iMovedItem = NULL;
       
   455                     iMovedItem = new (ELeave) TSnapshotItem( *iCurrentItem ,
       
   456                         iParentFolder );
       
   457                     iMovedItem->CreateHashL( modItem->Name(), modItem->SourceUrl() );
       
   458                     LOGGER_WRITE( "ItemReplacedL,waiting to move item.." );
       
   459                     return;
       
   460                     }
       
   461                 
       
   462                 }
       
   463             }
       
   464         else
       
   465             {
       
   466             //parent not found
       
   467             LOGGER_WRITE( "rss parent not defined" );
       
   468             }
       
   469         
       
   470         // Output the uid value of new item
       
   471         *iCurrentItem = modItem->Id() + KRssFeedsOffset;
       
   472         
       
   473         // Inform ChangeFinder of updated item
       
   474         TSnapshotItem snapshotItem( *iCurrentItem, iParentFolder );
       
   475         snapshotItem.CreateHashL( modItem->Name(), modItem->SourceUrl() );
       
   476         iChangeFinder->ItemUpdatedL( snapshotItem );
       
   477         LOGGER_WRITE( "ItemReplacedL" );
       
   478         }
       
   479     else
       
   480         {
       
   481         LOGGER_WRITE_1( "Replaced item %d not found",iReplaceItem - KRssFeedsOffset );
       
   482         User::Leave( KErrNotFound );
       
   483         }
       
   484     TRACE_FUNC_EXIT;
       
   485     }
       
   486 
       
   487 // -----------------------------------------------------------------------------
       
   488 // CBookmarkDataStore::DoCancelRequest
       
   489 // Not supported, does nothing.
       
   490 // -----------------------------------------------------------------------------
       
   491 void CBookmarkDataStore::DoCancelRequest()
       
   492     {
       
   493     LOGGER_ENTERFN( "CBookmarkDataStore::DoCancelRequest" );
       
   494     LOGGER_LEAVEFN( "CBookmarkDataStore::DoCancelRequest" );    
       
   495     }
       
   496 
       
   497 // -----------------------------------------------------------------------------
       
   498 // CBookmarkDataStore::DoStoreName
       
   499 // Returns the name of the DataStore
       
   500 // -----------------------------------------------------------------------------
       
   501 const TDesC& CBookmarkDataStore::DoStoreName() const
       
   502     {
       
   503     LOGGER_ENTERFN( "CBookmarkDataStore::DoStoreName" );
       
   504     LOGGER_LEAVEFN( "CBookmarkDataStore::DoStoreName" );
       
   505     
       
   506     if ( iDataBaseOpened )
       
   507         {
       
   508         return KBrowserBookmarks;
       
   509         }
       
   510     else
       
   511         {
       
   512         return KNullDesC;
       
   513         }
       
   514     }
       
   515     
       
   516 // -----------------------------------------------------------------------------
       
   517 // CBookmarkDataStore::DoBeginTransactionL
       
   518 // Transactions are not supported.
       
   519 // -----------------------------------------------------------------------------    
       
   520 void CBookmarkDataStore::DoBeginTransactionL()
       
   521     {
       
   522     LOGGER_ENTERFN( "CBookmarkDataStore::DoBeginTransactionL" );
       
   523     LOGGER_WRITE( "CBookmarkDataStore::DoBeginTransactionL leaved with KErrNotSupported." )
       
   524     User::Leave( KErrNotSupported );
       
   525     }
       
   526 
       
   527 // -----------------------------------------------------------------------------
       
   528 // CBookmarkDataStore::DoCommitTransactionL
       
   529 // Transactions are not supported.
       
   530 // -----------------------------------------------------------------------------
       
   531 void CBookmarkDataStore::DoCommitTransactionL( TRequestStatus& aStatus )
       
   532     {
       
   533     LOGGER_ENTERFN( "CBookmarkDataStore::DoCommitTransactionL" );
       
   534     LOGGER_WRITE( "CBookmarkDataStore::DoCommitTransactionL failed with KErrNotSupported." );
       
   535     
       
   536     iCallerStatus = &aStatus;
       
   537     User::RequestComplete( iCallerStatus, KErrNotSupported );
       
   538     
       
   539     LOGGER_LEAVEFN( "CBookmarkDataStore::DoCommitTransactionL" );
       
   540     }
       
   541 
       
   542 // -----------------------------------------------------------------------------
       
   543 // CBookmarkDataStore::DoRevertTransaction
       
   544 // Transactions are not supported.
       
   545 // -----------------------------------------------------------------------------
       
   546 void CBookmarkDataStore::DoRevertTransaction( TRequestStatus& aStatus )
       
   547     {
       
   548     LOGGER_ENTERFN( "CBookmarkDataStore::DoRevertTransaction" );
       
   549     iCallerStatus = &aStatus;
       
   550     User::RequestComplete( iCallerStatus, KErrNotSupported );
       
   551     LOGGER_LEAVEFN( "CBookmarkDataStore::DoRevertTransaction" );
       
   552     }
       
   553 
       
   554 // -----------------------------------------------------------------------------
       
   555 // CBookmarkDataStore::DoBeginBatchL
       
   556 // Batching is not supported.
       
   557 // -----------------------------------------------------------------------------
       
   558 void CBookmarkDataStore::DoBeginBatchL()
       
   559     {
       
   560     LOGGER_ENTERFN( "CBookmarkDataStore::DoBeginBatchL" );
       
   561     LOGGER_WRITE( "CBookmarkDataStore::DoBeginBatchL leaved with KErrNotSupported." );
       
   562     User::Leave( KErrNotSupported );
       
   563     }
       
   564 
       
   565 // -----------------------------------------------------------------------------
       
   566 // CBookmarkDataStore::DoCommitBatchL
       
   567 // Batching is not supported
       
   568 // -----------------------------------------------------------------------------
       
   569 void CBookmarkDataStore::DoCommitBatchL( RArray<TInt>& /*aResultArray*/, TRequestStatus& aStatus )
       
   570     {
       
   571     LOGGER_ENTERFN( "CBookmarkDataStore::DoCommitBatchL" );
       
   572     LOGGER_WRITE( "CBookmarkDataStore::DoCommitBatchL failed with KErrNotSupported" );
       
   573         
       
   574     iCallerStatus = &aStatus;
       
   575     User::RequestComplete( iCallerStatus, KErrNotSupported );
       
   576     
       
   577     LOGGER_LEAVEFN( "CBookmarkDataStore::DoCommitBatchL" );
       
   578     }
       
   579 
       
   580 // -----------------------------------------------------------------------------
       
   581 // CBookmarkDataStore::DoCancelBatch
       
   582 // Batching is not supported
       
   583 // -----------------------------------------------------------------------------
       
   584 void CBookmarkDataStore::DoCancelBatch()
       
   585     {
       
   586     LOGGER_ENTERFN( "CBookmarkDataStore::DoCancelBatch" );
       
   587     LOGGER_LEAVEFN( "CBookmarkDataStore::DoCancelBatch" );
       
   588     }
       
   589 
       
   590 // -----------------------------------------------------------------------------
       
   591 // CBookmarkDataStore::DoSetRemoteStoreFormatL
       
   592 // Not supported
       
   593 // -----------------------------------------------------------------------------
       
   594 void CBookmarkDataStore::DoSetRemoteStoreFormatL( const CSmlDataStoreFormat& /*aServerDataStoreFormat*/ )
       
   595     {
       
   596     LOGGER_ENTERFN( "CBookmarkDataStore::DoSetRemoteStoreFormatL" );
       
   597     LOGGER_LEAVEFN( "CBookmarkDataStore::DoSetRemoteStoreFormatL" );
       
   598     }
       
   599     
       
   600 // -----------------------------------------------------------------------------
       
   601 // CBookmarkDataStore::DoSetRemoteMaxObjectSize
       
   602 // Not supported
       
   603 // -----------------------------------------------------------------------------
       
   604 void CBookmarkDataStore::DoSetRemoteMaxObjectSize( TInt /*aServerMaxObjectSize*/ )
       
   605     {
       
   606     LOGGER_ENTERFN( "CBookmarkDataStore::DoSetRemoteMaxObjectSize" );
       
   607     LOGGER_LEAVEFN( "CBookmarkDataStore::DoSetRemoteMaxObjectSize" );   
       
   608     }
       
   609 
       
   610 
       
   611 // -----------------------------------------------------------------------------
       
   612 // CBookmarkDataStore::DoMaxObjectSize
       
   613 // Reads the maximum object size from the central repository
       
   614 // -----------------------------------------------------------------------------
       
   615 TInt CBookmarkDataStore::DoMaxObjectSize() const
       
   616     {
       
   617     LOGGER_ENTERFN( "CBookmarkDataStore::DoMaxObjectSize" );
       
   618     LOGGER_LEAVEFN( "CBookmarkDataStore::DoMaxObjectSize" );    
       
   619     return 0; // no limit
       
   620     }
       
   621 
       
   622 // -----------------------------------------------------------------------------
       
   623 // CBookmarkDataStore::DoOpenItemL
       
   624 // Opens item in the DataStore, reads it (either completely or partially) 
       
   625 // to the temporary buffer where it can be later read to the remote database.
       
   626 // -----------------------------------------------------------------------------
       
   627 void CBookmarkDataStore::DoOpenItemL(
       
   628     TSmlDbItemUid aUid, 
       
   629     TBool& aFieldChange, 
       
   630     TInt& aSize, 
       
   631     TSmlDbItemUid& aParent, 
       
   632     TDes8& aMimeType, 
       
   633     TDes8& aMimeVer, 
       
   634     TRequestStatus& aStatus )
       
   635     {
       
   636     LOGGER_ENTERFN( "CBookmarkDataStore::DoOpenItemL" );
       
   637     LOGGER_WRITE_1( "Item: %d", aUid );
       
   638     
       
   639     
       
   640     iCallerStatus = &aStatus;
       
   641     *iCallerStatus = KRequestPending;
       
   642     
       
   643     aFieldChange = EFalse;
       
   644     
       
   645     if ( iCurrentState != EOpenAndWaiting )
       
   646         {
       
   647         LOGGER_WRITE_1( "Warning: Unexpected current state: %d", iCurrentState );
       
   648         }
       
   649     
       
   650     SAFEDELETE( iDataBuffer );
       
   651     iDataBuffer = CBufFlat::NewL( KDefaultBufferSize ); 
       
   652     iReaderPosition = 0;
       
   653     if ( aUid < KRssFeedsOffset )
       
   654         {
       
   655         LOGGER_WRITE( "Handle id as bookmark item " );
       
   656         TInt err( KErrNone );   
       
   657         CFavouritesItem* item = CFavouritesItem::NewLC();
       
   658         err = iDb.Get( aUid, *item );
       
   659         if (err)
       
   660             {
       
   661             User::RequestComplete( iCallerStatus, KErrNotFound );
       
   662             LOGGER_WRITE_1( "RFavouritesDb::Get failed with %d", err );
       
   663             CleanupStack::PopAndDestroy( item );
       
   664             return;
       
   665             }
       
   666             
       
   667         
       
   668         
       
   669         iConverter->FavouritesItemToBufferL( *item, *iDataBuffer );
       
   670         aSize = iDataBuffer->Size();
       
   671         aParent = item->ParentFolder();
       
   672 
       
   673         // Set mime type according to item type
       
   674         // The following code handles also the case, where the receiving
       
   675         // buffer doesn't contain enough space for the type (truncated)
       
   676         if ( item->Type() == CFavouritesItem::EItem )
       
   677             {
       
   678             LOGGER_WRITE("item type: EItem");
       
   679             AssignString( aMimeType, KBookmarkItemMimeType );
       
   680             AssignString( aMimeVer, KBookmarkItemMimeVersion );
       
   681             }
       
   682         else
       
   683             {
       
   684             LOGGER_WRITE("item type: EFolder");
       
   685             AssignString( aMimeType, KBookmarkFolderMimeType );
       
   686             AssignString( aMimeVer, KBookmarkFolderMimeVersion );
       
   687             }
       
   688 
       
   689         CleanupStack::PopAndDestroy( item );
       
   690         }
       
   691     else
       
   692         {
       
   693         LOGGER_WRITE( "Handle id as rssFeed item " );
       
   694         
       
   695         TInt rssId = aUid - KRssFeedsOffset;
       
   696         LOGGER_WRITE_1( "rssId: %d", rssId );
       
   697         
       
   698         if ( !iRootFolder.HasRootFolderItem() )
       
   699             {
       
   700             User::RequestComplete( iCallerStatus, KErrNotFound );
       
   701             LOGGER_WRITE( "rss root folder not found" );
       
   702             return;
       
   703             }
       
   704         
       
   705         const CFolderItem& rootFolder = iRootFolder.RootFolderItem();
       
   706         const CFolderItem* founded = rootFolder.Search( rssId );
       
   707         if ( founded )
       
   708             {
       
   709             LOGGER_WRITE( "Item found" );
       
   710             const CFolderItem* parent = founded->Parent();
       
   711             if ( parent )
       
   712                 {
       
   713                 LOGGER_WRITE( "parent found" );
       
   714                 aParent = parent->Id() + KRssFeedsOffset;
       
   715                 }
       
   716             else
       
   717                 {
       
   718                 LOGGER_WRITE( "no parent (root)" );
       
   719                 aParent = KErrNotFound;// rootFolder.Id() + KRssFeedsOffset;
       
   720                 }
       
   721             
       
   722             if ( !founded->IsFolder() )
       
   723                 {
       
   724                 LOGGER_WRITE("item type: EItem");
       
   725                 AssignString( aMimeType, KBookmarkItemMimeType );
       
   726                 AssignString( aMimeVer, KBookmarkItemMimeVersion );
       
   727                 }
       
   728             else
       
   729                 {
       
   730                 LOGGER_WRITE("item type: EFolder");
       
   731                 AssignString( aMimeType, KBookmarkFolderMimeType );
       
   732                 AssignString( aMimeVer, KBookmarkFolderMimeVersion );
       
   733                 }
       
   734             iConverter->RssItemToBufferL( *founded, *iDataBuffer );
       
   735             aSize = iDataBuffer->Size();
       
   736             
       
   737             }
       
   738         else
       
   739             {
       
   740             LOGGER_WRITE( "Item not found" );
       
   741             User::RequestComplete( iCallerStatus, KErrNotFound );
       
   742             return;
       
   743             }
       
   744         
       
   745         }
       
   746     
       
   747     User::RequestComplete( iCallerStatus, KErrNone );   
       
   748     iCurrentState = EBookmarkOpen;
       
   749     
       
   750 #ifdef _DEBUG
       
   751     LOGGER_WRITE_1( "aFieldChange: %d", (TInt)aFieldChange );
       
   752     LOGGER_WRITE_1( "aSize: %d", aSize );
       
   753     LOGGER_WRITE_1( "aParent: %d", aParent );
       
   754     TPtr8 bufPtr = iDataBuffer->Ptr(0);
       
   755     LOGGER_WRITE8_1( "iDataBuffer: %S", &bufPtr);
       
   756 #endif
       
   757 
       
   758     LOGGER_LEAVEFN( "CBookmarkDataStore::DoOpenItemL" );        
       
   759     }
       
   760 
       
   761 // -----------------------------------------------------------------------------
       
   762 // CBookmarkDataStore::DoCreateItemL
       
   763 // Create new item to the message store.
       
   764 // Return the id number of the newly created item
       
   765 // -----------------------------------------------------------------------------
       
   766 void CBookmarkDataStore::DoCreateItemL(
       
   767     TSmlDbItemUid& aUid, 
       
   768     TInt aSize, 
       
   769     TSmlDbItemUid aParent, 
       
   770     const TDesC8& aMimeType, 
       
   771     const TDesC8& /*aMimeVer*/, 
       
   772     TRequestStatus& aStatus )
       
   773     {
       
   774     LOGGER_ENTERFN( "CBookmarkDataStore::DoCreateItemL" );
       
   775     LOGGER_WRITE_1( "aParent: %d", aParent );
       
   776     LOGGER_WRITE8_1( "aMimeType: %S", &aMimeType );
       
   777     
       
   778     iCallerStatus = &aStatus;
       
   779     *iCallerStatus = KRequestPending;
       
   780     
       
   781     delete iItemToBeReplaced;
       
   782     iItemToBeReplaced = NULL;
       
   783     
       
   784     // Check MIME type
       
   785     if ( aMimeType.Compare( KBookmarkFolderMimeType() ) == 0 )  
       
   786         {
       
   787         LOGGER_WRITE("item type: EFolder");
       
   788         iMimeType = CFavouritesItem::EFolder;
       
   789         }
       
   790     else if ( aMimeType.Compare( KBookmarkItemMimeType() ) == 0 )
       
   791         {
       
   792         LOGGER_WRITE("item type: EItem");
       
   793         iMimeType = CFavouritesItem::EItem;
       
   794         }
       
   795     else
       
   796         {
       
   797         User::RequestComplete( iCallerStatus, KErrNotSupported );
       
   798         LOGGER_WRITE( "Unexpected mime type" );
       
   799         return;
       
   800         }   
       
   801     
       
   802     // Ensure that we're in a proper state
       
   803     if ( iCurrentState != EOpenAndWaiting )
       
   804         {
       
   805         LOGGER_WRITE_1( "Warning: Unexpected current state: %d", iCurrentState );
       
   806         }
       
   807         
       
   808     // Ensure that we've got enough disk space for the item
       
   809     if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iRfs, aSize, EDriveC ) )
       
   810         {
       
   811         User::RequestComplete( iCallerStatus, KErrDiskFull );
       
   812         LOGGER_WRITE( "SysUtil::DiskSpaceBelowCriticalLevelL failed with KErrDiskFull." );
       
   813         return;
       
   814         }
       
   815     
       
   816     if ( aParent < KRssFeedsOffset )
       
   817         {
       
   818         LOGGER_WRITE( "Handle id as bookmark item" );
       
   819         // Ensure that parent folder exists 
       
   820         TBool folderExists( EFalse );   
       
   821         TInt err = iDb.FolderExists( aParent, folderExists );
       
   822         if ( err || !folderExists )
       
   823             {
       
   824             User::RequestComplete( iCallerStatus, KErrPathNotFound );
       
   825             LOGGER_WRITE_1( "iDb.FolderExist returned %d, folder not found", err );
       
   826             return;
       
   827             }
       
   828         
       
   829         }
       
   830     else
       
   831         {
       
   832         LOGGER_WRITE( "Handle id as rssFeed item " );
       
   833         
       
   834         TInt rssId = aParent - KRssFeedsOffset;
       
   835         LOGGER_WRITE_1( "parentRssId: %d", rssId );
       
   836         
       
   837         if ( !iRootFolder.HasRootFolderItem() )
       
   838             {
       
   839             User::RequestComplete( iCallerStatus, KErrPathNotFound );
       
   840             LOGGER_WRITE( "rss root folder not found" );
       
   841             return;
       
   842             }
       
   843         
       
   844         const CFolderItem& rootFolder = iRootFolder.RootFolderItem();
       
   845         const CFolderItem* founded = rootFolder.Search( rssId );
       
   846         TBool folderExists( EFalse );
       
   847         if ( founded )
       
   848             {
       
   849             if ( founded->IsFolder() )
       
   850                 {
       
   851                 folderExists = ETrue;
       
   852                 }
       
   853             }
       
   854         if ( !folderExists )
       
   855             {
       
   856             User::RequestComplete( iCallerStatus, KErrPathNotFound );
       
   857             LOGGER_WRITE( "Folder does not exist" );
       
   858             return;
       
   859             }
       
   860         }
       
   861     
       
   862     iCurrentState = EBookmarkCreating;
       
   863     // Store parent for further use 
       
   864     iParentFolder = aParent;    
       
   865                 
       
   866     SAFEDELETE( iDataBuffer );
       
   867     iDataBuffer = CBufFlat::NewL( KDefaultBufferSize );
       
   868     iWriterPosition = 0;
       
   869         
       
   870     iCurrentItem = &aUid;   
       
   871     
       
   872     
       
   873     User::RequestComplete( iCallerStatus, KErrNone );
       
   874         
       
   875     LOGGER_LEAVEFN( "CBookmarkDataStore::DoCreateItemL" );      
       
   876     }
       
   877 
       
   878 // -----------------------------------------------------------------------------
       
   879 // CBookmarkDataStore::DoReplaceItemL
       
   880 // Begin the replace operation, ensure that the item really exists
       
   881 // -----------------------------------------------------------------------------
       
   882 void CBookmarkDataStore::DoReplaceItemL(
       
   883     TSmlDbItemUid aUid, 
       
   884     TInt aSize, 
       
   885     TSmlDbItemUid aParent,
       
   886     TBool /*aFieldChange*/, 
       
   887     TRequestStatus& aStatus )
       
   888     {
       
   889     LOGGER_ENTERFN( "CBookmarkDataStore::DoReplaceItemL" );
       
   890     LOGGER_WRITE_1("aUid: %d", aUid);
       
   891     LOGGER_WRITE_1("aParent: %d", aParent);
       
   892     
       
   893     iCallerStatus = &aStatus;
       
   894     *iCallerStatus = KRequestPending;
       
   895     
       
   896     delete iItemToBeReplaced;
       
   897     iItemToBeReplaced = NULL;
       
   898     
       
   899     if ( iCurrentState != EOpenAndWaiting )
       
   900         {
       
   901         LOGGER_WRITE_1( "Warning: Unexpected current state: %d", iCurrentState );
       
   902         }
       
   903         
       
   904     // Ensure that we've got enough disk space for the item
       
   905     if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iRfs, aSize, EDriveC ) )
       
   906         {
       
   907         User::RequestComplete( iCallerStatus, KErrDiskFull );
       
   908         LOGGER_WRITE( "SysUtil::DiskSpaceBelowCriticalLevelL failed with KErrDiskFull." );
       
   909         return;
       
   910         }       
       
   911     
       
   912     if ( aUid < KRssFeedsOffset )
       
   913         {
       
   914         LOGGER_WRITE( "Bookmark item" );
       
   915         iItemToBeReplaced = CFavouritesItem::NewL();
       
   916         // Check that item exists
       
   917         TInt err = iDb.Get( aUid, *iItemToBeReplaced );
       
   918         if ( err != KErrNone )
       
   919             {
       
   920             User::RequestComplete( iCallerStatus, KErrNotFound );
       
   921             LOGGER_WRITE_1( "iDb.Get failed with %d", err );
       
   922             SAFEDELETE(iItemToBeReplaced);
       
   923             return;
       
   924             }
       
   925         
       
   926         // is parent changed
       
   927         if ( aParent != iItemToBeReplaced->ParentFolder() )
       
   928             {
       
   929             if ( aParent >= KRssFeedsOffset )
       
   930                 {
       
   931                 User::RequestComplete( iCallerStatus, KErrNotSupported );
       
   932                 LOGGER_WRITE( "cannot move to RSS items folder" );
       
   933                 SAFEDELETE(iItemToBeReplaced);
       
   934                 return;
       
   935                 }
       
   936             // parent is changed, ensure that new parent folder exists
       
   937             TBool folderExists( EFalse ); 
       
   938             err = iDb.FolderExists( aParent, folderExists );
       
   939             if ( err || !folderExists )
       
   940                 {
       
   941                 User::RequestComplete( iCallerStatus, KErrPathNotFound );
       
   942                 LOGGER_WRITE_1( "iDb.FolderExist returned %d, new parent folder not found", err );
       
   943                 SAFEDELETE(iItemToBeReplaced);
       
   944                 return;
       
   945                 }
       
   946             }
       
   947         
       
   948         
       
   949         // Store some variables to be used later in commit
       
   950         iMimeType = iItemToBeReplaced->Type();
       
   951         iItemToBeReplaced->SetParentFolder( aParent );
       
   952         iParentFolder = aParent;
       
   953         iReplaceItem = aUid;
       
   954         }
       
   955     else
       
   956         {
       
   957         LOGGER_WRITE( "RSS item" );
       
   958         if ( aParent < KRssFeedsOffset )
       
   959             {
       
   960             User::RequestComplete( iCallerStatus, KErrNotSupported );
       
   961             LOGGER_WRITE( "cannot move RSS item to normal folder" );
       
   962             return;
       
   963             }
       
   964         if ( !iRootFolder.HasRootFolderItem() )
       
   965             {
       
   966             User::RequestComplete( iCallerStatus, KErrNotFound );
       
   967             LOGGER_WRITE( "rss root folder not found" );
       
   968             return;
       
   969             }
       
   970         const CFolderItem& rootFolder = iRootFolder.RootFolderItem();
       
   971         const CFolderItem* rssItem = rootFolder.Search( aUid - KRssFeedsOffset );
       
   972         if ( !rssItem )
       
   973             {
       
   974             User::RequestComplete( iCallerStatus, KErrNotFound );
       
   975             LOGGER_WRITE( "rss item not found" );
       
   976             return;
       
   977             }
       
   978         if ( rssItem->IsFolder() )
       
   979             {
       
   980             iMimeType = CFavouritesItem::EFolder;
       
   981             }
       
   982         else
       
   983             {
       
   984             iMimeType = CFavouritesItem::EItem;
       
   985             }
       
   986         const CFolderItem* parent = rssItem->Parent();
       
   987         if ( parent )
       
   988             {
       
   989             TInt currentParent = parent->Id() + KRssFeedsOffset;
       
   990             
       
   991             const CFolderItem* newParent = rootFolder.Search( aParent - KRssFeedsOffset );
       
   992             if ( !newParent )
       
   993                 {
       
   994                 User::RequestComplete( iCallerStatus, KErrPathNotFound );
       
   995                 LOGGER_WRITE( "new parent not found" );
       
   996                 return;
       
   997                 }
       
   998             else if ( !newParent->IsFolder() )
       
   999                 {
       
  1000                 User::RequestComplete( iCallerStatus, KErrPathNotFound );
       
  1001                 LOGGER_WRITE( "new parent must be folder" );
       
  1002                 return;
       
  1003                 }
       
  1004             else
       
  1005                 {
       
  1006                 iParentFolder = aParent;
       
  1007                 }
       
  1008             
       
  1009             }
       
  1010         else
       
  1011             {
       
  1012             iParentFolder = KErrNotFound;
       
  1013             }
       
  1014         iReplaceItem = aUid;
       
  1015         }
       
  1016     
       
  1017     
       
  1018     
       
  1019     SAFEDELETE(iDataBuffer);
       
  1020     iDataBuffer = CBufFlat::NewL( KDefaultBufferSize );
       
  1021     iWriterPosition = 0;
       
  1022         
       
  1023     iCurrentItem = &aUid;   
       
  1024     iCurrentState = EBookmarkUpdating;
       
  1025     
       
  1026     User::RequestComplete( iCallerStatus, KErrNone );   
       
  1027     
       
  1028     LOGGER_LEAVEFN( "CBookmarkDataStore::DoReplaceItemL" );     
       
  1029     }
       
  1030 
       
  1031 // -----------------------------------------------------------------------------
       
  1032 // CBookmarkDataStore::DoReadItemL
       
  1033 // Read specified amount of data from the temporary buffer
       
  1034 // -----------------------------------------------------------------------------
       
  1035 void CBookmarkDataStore::DoReadItemL( TDes8& aBuffer )
       
  1036     {
       
  1037     LOGGER_ENTERFN( "CBookmarkDataStore::DoReadItemL" );
       
  1038     
       
  1039     if (iCurrentState != EBookmarkOpen || !iDataBuffer)
       
  1040         {
       
  1041         LOGGER_WRITE_1( "Unexpected state %d", iCurrentState );
       
  1042         User::Leave( KErrNotReady );
       
  1043         }
       
  1044         
       
  1045     if (iReaderPosition == KDataBufferNotReady)
       
  1046         {
       
  1047         LOGGER_WRITE( "No data to read" );
       
  1048         User::Leave( KErrEof );
       
  1049         }
       
  1050     
       
  1051     // Thiw is how much data there is left in the buffer    
       
  1052     TInt left = iDataBuffer->Size() - iReaderPosition;
       
  1053     
       
  1054     if ( left > 0 )
       
  1055         {
       
  1056         // This is how much there's space in the destination buffer
       
  1057         TInt destSize = aBuffer.MaxSize();
       
  1058         
       
  1059         // This is how much we can read
       
  1060         TInt toRead = destSize < left ? destSize : left;
       
  1061         
       
  1062         // Read the data from the buffer, then update the position      
       
  1063         iDataBuffer->Read( iReaderPosition, aBuffer, toRead );
       
  1064         iReaderPosition += toRead;
       
  1065         }
       
  1066     else
       
  1067         {
       
  1068         iReaderPosition = KDataBufferNotReady;
       
  1069         LOGGER_WRITE( "No data to read" );
       
  1070         User::Leave( KErrEof );
       
  1071         }   
       
  1072         
       
  1073     LOGGER_LEAVEFN( "CBookmarkDataStore::DoReadItemL" );        
       
  1074     }
       
  1075 
       
  1076 // -----------------------------------------------------------------------------
       
  1077 // CBookmarkDataStore::DoWriteItemL
       
  1078 // Write specified amount of data to the temporary buffer
       
  1079 // -----------------------------------------------------------------------------
       
  1080 void CBookmarkDataStore::DoWriteItemL( const TDesC8& aData )
       
  1081     {
       
  1082     LOGGER_ENTERFN( "CBookmarkDataStore::DoWriteItemL" );
       
  1083     
       
  1084     if ( iCurrentState != EBookmarkCreating && iCurrentState != EBookmarkUpdating )
       
  1085         {
       
  1086         LOGGER_WRITE_1( "Unexpected current state: %d", iCurrentState );
       
  1087         User::Leave( KErrNotReady );
       
  1088         }
       
  1089     
       
  1090     // Calculate total size
       
  1091     TInt totalSize = aData.Size() + iDataBuffer->Size();
       
  1092 
       
  1093     // Ensure that we've got enough disk space for the item
       
  1094     if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iRfs, totalSize, EDriveC ) )
       
  1095         {
       
  1096         User::RequestComplete( iCallerStatus, KErrDiskFull );
       
  1097         LOGGER_WRITE("SysUtil::DiskSpaceBelowCriticalLevelL failed with KErrDiskFull.");
       
  1098         return;
       
  1099         }
       
  1100         
       
  1101     // Add data to buffer       
       
  1102     iDataBuffer->InsertL( iWriterPosition, aData );
       
  1103     iWriterPosition += aData.Size();
       
  1104     
       
  1105     LOGGER_LEAVEFN( "CBookmarkDataStore::DoWriteItemL" );
       
  1106     }
       
  1107 
       
  1108 // -----------------------------------------------------------------------------
       
  1109 // CBookmarkDataStore::DoCommitItemL
       
  1110 // Commits item from temporary buffer to the message store
       
  1111 // -----------------------------------------------------------------------------
       
  1112 void CBookmarkDataStore::DoCommitItemL( TRequestStatus& aStatus )
       
  1113     {
       
  1114     LOGGER_ENTERFN( "CBookmarkDataStore::DoCommitItemL" );
       
  1115     LOGGER_WRITE_1("iParentFolder: %d", iParentFolder);
       
  1116     iCallerStatus = &aStatus;
       
  1117     *iCallerStatus = KRequestPending;
       
  1118     
       
  1119     // Check that we're in proper state
       
  1120     if ( iCurrentState != EBookmarkCreating && iCurrentState != EBookmarkUpdating )
       
  1121         {
       
  1122         User::RequestComplete( iCallerStatus, KErrNotReady );
       
  1123         LOGGER_WRITE_1( "Unexpected current state: %d", iCurrentState );
       
  1124         return;
       
  1125         }
       
  1126         
       
  1127     if ( iDataBuffer->Size() <= 0 )
       
  1128         {
       
  1129         User::RequestComplete( iCallerStatus, KErrNotReady );
       
  1130         LOGGER_WRITE_1( "Data buffer has no data (%d)", iDataBuffer->Size() );
       
  1131         return; 
       
  1132         }
       
  1133     
       
  1134     
       
  1135     
       
  1136     // If iItemToBeReplaced exist, bookmark item is going to be replaced.
       
  1137     // iItemToBeReplaced contains original bookmark and only some of it's data is replaced.
       
  1138     CFavouritesItem* item(NULL);
       
  1139     if ( iItemToBeReplaced )
       
  1140         {
       
  1141         // Change object ownership to "item"-object, and push to cleanupStack
       
  1142         item = iItemToBeReplaced;
       
  1143         CleanupStack::PushL( item );
       
  1144         iItemToBeReplaced = NULL;
       
  1145         }
       
  1146     else
       
  1147         {
       
  1148         // Create new object.
       
  1149         item = CFavouritesItem::NewLC();
       
  1150         }
       
  1151     
       
  1152     iDataBuffer->Compress();
       
  1153     TInt err = iConverter->BufferToFavouritesItemL( iMimeType, *iDataBuffer, *item );
       
  1154     
       
  1155     if ( iParentFolder == KErrNotFound )
       
  1156         {
       
  1157         if ( item->Name().Compare( KRSSRootFolderName ) == 0 )
       
  1158             {
       
  1159             LOGGER_WRITE( "Was RSS Rootfolder" );
       
  1160             // Remove from cleanup stack
       
  1161             CleanupStack::PopAndDestroy( item );
       
  1162             
       
  1163             if ( !iRootFolder.HasRootFolderItem() )
       
  1164                 {
       
  1165                 User::RequestComplete( iCallerStatus, KErrNotFound );
       
  1166                 LOGGER_WRITE( "rss root folder not found" );
       
  1167                 return;
       
  1168                 }
       
  1169             const CFolderItem& rootFolder = iRootFolder.RootFolderItem();
       
  1170             
       
  1171             *iCurrentItem = rootFolder.Id() + KRssFeedsOffset;
       
  1172             
       
  1173             // Inform ChangeFinder of updated item
       
  1174             TSnapshotItem snapshotItem( rootFolder.Id() + KRssFeedsOffset );
       
  1175             snapshotItem.SetParentId( iParentFolder );
       
  1176             snapshotItem.CreateHashL( KRSSRootFolderName, KNullDesC );
       
  1177             iChangeFinder->ItemUpdatedL( snapshotItem );
       
  1178             
       
  1179             // Destroy buffer
       
  1180             SAFEDELETE( iDataBuffer );
       
  1181             iWriterPosition = 0;
       
  1182             
       
  1183             // Restore state and signal we're done
       
  1184             LOGGER_WRITE( "Signal KErrNone" );
       
  1185             iCurrentState = EOpenAndWaiting;
       
  1186             User::RequestComplete( iCallerStatus, KErrNone );
       
  1187             
       
  1188             LOGGER_WRITE_1("Item ID: %d", *iCurrentItem);
       
  1189             LOGGER_WRITE_1("Parent ID: %d", iParentFolder);
       
  1190             LOGGER_LEAVEFN( "CBookmarkDataStore::DoCommitItemL" );
       
  1191             return;
       
  1192             }
       
  1193         }
       
  1194 
       
  1195     if ( iParentFolder < KRssFeedsOffset )
       
  1196         {
       
  1197         // Convert buffer to favourites item
       
  1198         LOGGER_WRITE( "BookmarkItem" );
       
  1199         
       
  1200         if ( err == KErrNone )
       
  1201             {
       
  1202             LOGGER_WRITE_1 ( "ParentFolder: %d", iParentFolder )
       
  1203             // Creating new item
       
  1204             if ( iCurrentState == EBookmarkCreating )
       
  1205                 {
       
  1206 #ifdef _DEBUG                
       
  1207                 LOGGER_WRITE( "Create new bookmark item" );
       
  1208                 TPtrC namePtr = item->Name();
       
  1209                 LOGGER_WRITE_1( "name: %S", &namePtr );
       
  1210 #endif
       
  1211                 // Set parent folder
       
  1212                 item->SetParentFolder( iParentFolder );
       
  1213 
       
  1214                 // Add to database
       
  1215                 err = iDb.Add( *item, EFalse );
       
  1216                 LOGGER_WRITE_1("iDb.Add return: %d", err);
       
  1217                 if ( err == KErrNone )
       
  1218                     {
       
  1219                     // Output the uid value of new item
       
  1220                     *iCurrentItem = item->Uid();
       
  1221                     LOGGER_WRITE_1("New item Uid: %d", *iCurrentItem);
       
  1222                     // Inform ChangeFinder of the added item
       
  1223                     TSnapshotItem snapshotItem( *iCurrentItem );
       
  1224                     snapshotItem.SetParentId( iParentFolder );
       
  1225                     snapshotItem.CreateHashL( item->Name(), item->Url() );
       
  1226                     iChangeFinder->ItemAddedL( snapshotItem );
       
  1227                     }
       
  1228                 else
       
  1229                     {
       
  1230                     LOGGER_WRITE_1( "RFavouritesDb::Add failed: %d", err );
       
  1231                     }
       
  1232                 }
       
  1233             // Updating existing item
       
  1234             else
       
  1235                 {
       
  1236                 LOGGER_WRITE( "Update existing item" );
       
  1237                 item->SetParentFolder(iParentFolder);
       
  1238                 err = iDb.Update( *item, iReplaceItem, EFalse );
       
  1239                 if ( err == KErrNone )
       
  1240                     {
       
  1241                     // Inform ChangeFinder of updated item
       
  1242                     TSnapshotItem snapshotItem( iReplaceItem );
       
  1243                     snapshotItem.SetParentId( iParentFolder );
       
  1244                     snapshotItem.CreateHashL( item->Name(), item->Url() );
       
  1245                     iChangeFinder->ItemUpdatedL( snapshotItem );
       
  1246                     }
       
  1247                 else
       
  1248                     {
       
  1249                     LOGGER_WRITE_1( "RFavouritesDb::Update failed: %d", err );
       
  1250                     }
       
  1251                 }
       
  1252             }
       
  1253         else
       
  1254             {
       
  1255             LOGGER_WRITE_1( "Failed to create db item (%d)", err );
       
  1256             }
       
  1257 
       
  1258         }
       
  1259     else
       
  1260         {
       
  1261         LOGGER_WRITE( "RSS item" );
       
  1262         err = iConverter->BufferToFavouritesItemL( iMimeType, *iDataBuffer, *item );
       
  1263         // Destroy buffer
       
  1264         SAFEDELETE( iDataBuffer );
       
  1265         iWriterPosition = 0;
       
  1266         if ( err == KErrNone )
       
  1267             {
       
  1268             if ( iCurrentState == EBookmarkCreating )
       
  1269                 {
       
  1270                 TBool isFolder = ( iMimeType == CFavouritesItem::EFolder );
       
  1271                 CreateRssItemL( iParentFolder - KRssFeedsOffset, item->Name(), item->Url(), isFolder );
       
  1272                 
       
  1273                 CleanupStack::PopAndDestroy( item );
       
  1274                 LOGGER_WRITE( "waiting FolderItemRequestCompleted..." );
       
  1275                 return;    
       
  1276                 }
       
  1277             else
       
  1278                 {
       
  1279                 LOGGER_WRITE( "Replace RSS item" );
       
  1280                 ReplaceRssItemL( iReplaceItem - KRssFeedsOffset, item->Name(), item->Url());
       
  1281                 
       
  1282                 CleanupStack::PopAndDestroy( item );
       
  1283                 LOGGER_WRITE( "waiting FolderItemRequestCompleted..." );
       
  1284                 return;
       
  1285                 }
       
  1286             }
       
  1287         else
       
  1288             {
       
  1289             // Data was corrupted
       
  1290             LOGGER_WRITE_1( " iConverter->BufferToFavouritesItemL err: %d", err );
       
  1291             err = KErrCorrupt;
       
  1292             }
       
  1293         }
       
  1294     
       
  1295 
       
  1296     // Remove from cleanup stack
       
  1297     CleanupStack::PopAndDestroy( item );
       
  1298     
       
  1299     // Destroy buffer
       
  1300     SAFEDELETE( iDataBuffer );
       
  1301     iWriterPosition = 0;
       
  1302     
       
  1303     // Restore state and signal we're done
       
  1304     iCurrentState = EOpenAndWaiting;
       
  1305     User::RequestComplete( iCallerStatus, err );
       
  1306     
       
  1307     LOGGER_WRITE_1("Item ID: %d", iReplaceItem);
       
  1308     LOGGER_WRITE_1("Parent ID: %d", iParentFolder);
       
  1309     LOGGER_LEAVEFN( "CBookmarkDataStore::DoCommitItemL" );
       
  1310     }
       
  1311 
       
  1312 // -----------------------------------------------------------------------------
       
  1313 // CBookmarkDataStore::CreateRssItemL
       
  1314 // Creates new Rss item, FolderItemRequestCompleted is called when done
       
  1315 // -----------------------------------------------------------------------------
       
  1316 void CBookmarkDataStore::CreateRssItemL( TInt aRssParentUid, const TDesC& aName, const TDesC& aUrl, TBool aIsFolder )
       
  1317     {
       
  1318     TRACE_FUNC_ENTRY;
       
  1319     LOGGER_WRITE_1("aRssParentUid: %d", aRssParentUid);
       
  1320     LOGGER_WRITE_1("aName: %S", &aName);
       
  1321     
       
  1322     if ( !iRootFolder.HasRootFolderItem() )
       
  1323         {
       
  1324         LOGGER_WRITE( "rss root folder not found" );
       
  1325         User::Leave( KErrNotFound );
       
  1326         }
       
  1327     
       
  1328     const CFolderItem& rootFolder = iRootFolder.RootFolderItem();
       
  1329     
       
  1330     // check that parent folder exists
       
  1331     const CFolderItem* parent = rootFolder.Search( aRssParentUid );
       
  1332     if ( !parent )
       
  1333         {
       
  1334         LOGGER_WRITE( "parent folder not found" );
       
  1335         User::Leave( KErrNotFound );
       
  1336         }
       
  1337     
       
  1338     // check that folder does not already exists
       
  1339     const CFolderItem* existingItem = parent->Search( aName );
       
  1340     if ( existingItem )
       
  1341         {
       
  1342         LOGGER_WRITE("Same name already exist, return KErrAlreadyExists");
       
  1343         User::Leave( KErrAlreadyExists );
       
  1344         }
       
  1345     
       
  1346     TInt err(KErrNone);
       
  1347     // async func. FolderItemRequestCompleted is called when completed
       
  1348     TRAP( err, iRootFolder.AddFolderItemL(
       
  1349         aName,
       
  1350         aUrl,
       
  1351         aIsFolder,
       
  1352         *parent ) );
       
  1353     LOGGER_WRITE_1( "iRootFolder.AddFolderItemL err: %d", err );
       
  1354     
       
  1355     iNewItemName.Copy( aName );
       
  1356     
       
  1357     TRACE_FUNC_EXIT;
       
  1358     }
       
  1359 
       
  1360 // -----------------------------------------------------------------------------
       
  1361 // CBookmarkDataStore::ReplaceRssItemL
       
  1362 // Replaces rss item, FolderItemRequestCompleted is called when done
       
  1363 // -----------------------------------------------------------------------------
       
  1364 void CBookmarkDataStore::ReplaceRssItemL( TInt aRssItemUid, const TDesC& aNewName, const TDesC& aNewUrl )
       
  1365     {
       
  1366     TRACE_FUNC_ENTRY;
       
  1367     LOGGER_WRITE_1("aRssItemUid: %d", aRssItemUid);
       
  1368     LOGGER_WRITE_1("aNewName: %S", &aNewName);
       
  1369     LOGGER_WRITE_1("aNewUrl: %S", &aNewUrl);
       
  1370     
       
  1371     if ( !iRootFolder.HasRootFolderItem() )
       
  1372         {
       
  1373         LOGGER_WRITE( "rss root folder not found" );
       
  1374         User::Leave( KErrNotFound );
       
  1375         }
       
  1376     const CFolderItem& rootFolder = iRootFolder.RootFolderItem();
       
  1377     LOGGER_WRITE_1( "rootFolder.Search %d", aRssItemUid );
       
  1378     const CFolderItem* rssItem = rootFolder.Search( aRssItemUid );
       
  1379     if ( !rssItem )
       
  1380         {
       
  1381         LOGGER_WRITE( "rssItem not found" );
       
  1382         User::Leave( KErrNotFound );
       
  1383         }
       
  1384     
       
  1385     // async func. FolderItemRequestCompleted is called when completed
       
  1386     if ( rssItem->IsFolder() )
       
  1387         {
       
  1388         iRootFolder.ChangeFolderItemL(
       
  1389         *rssItem,
       
  1390         aNewName,
       
  1391         KNullDesC );
       
  1392         }
       
  1393     else
       
  1394         {
       
  1395         iRootFolder.ChangeFolderItemL(
       
  1396         *rssItem,
       
  1397         aNewName,
       
  1398         aNewUrl );
       
  1399         }
       
  1400     
       
  1401     TRACE_FUNC_EXIT;
       
  1402     }
       
  1403 
       
  1404 // -----------------------------------------------------------------------------
       
  1405 // CBookmarkDataStore::DoCloseItem
       
  1406 // Closes open item in the data store
       
  1407 // -----------------------------------------------------------------------------
       
  1408 void CBookmarkDataStore::DoCloseItem()
       
  1409     {
       
  1410     LOGGER_ENTERFN( "CBookmarkDataStore::DoCloseItem" );
       
  1411     
       
  1412     // Make sure that we're opened an item
       
  1413     if ( iCurrentState == EBookmarkOpen )
       
  1414         {
       
  1415         // Reset read buffer 
       
  1416         iReaderPosition = KDataBufferNotReady;
       
  1417         SAFEDELETE( iDataBuffer );
       
  1418         
       
  1419         // Start to wait for the next operation     
       
  1420         iCurrentState = EOpenAndWaiting;
       
  1421         }
       
  1422     else 
       
  1423         {
       
  1424         LOGGER_WRITE_1( "Invalid state %d.", iCurrentState );
       
  1425         }   
       
  1426     
       
  1427     LOGGER_LEAVEFN( "CBookmarkDataStore::DoCloseItem" );    
       
  1428     }
       
  1429 
       
  1430 // -----------------------------------------------------------------------------
       
  1431 // CBookmarkDataStore::DoMoveItemL
       
  1432 // Moves item from one bookmark folder to another 
       
  1433 // -----------------------------------------------------------------------------
       
  1434 void CBookmarkDataStore::DoMoveItemL( TSmlDbItemUid aUid,
       
  1435     TSmlDbItemUid aNewParent, TRequestStatus& aStatus )
       
  1436     {
       
  1437     LOGGER_ENTERFN( "CBookmarkDataStore::DoMoveItemL" );
       
  1438     LOGGER_WRITE_1("aUid: %d", aUid);
       
  1439     LOGGER_WRITE_1("new parent: %d", aNewParent);
       
  1440 
       
  1441     iCallerStatus = &aStatus;
       
  1442     *iCallerStatus = KRequestPending;
       
  1443 
       
  1444     TInt err( KErrNone ); 
       
  1445     
       
  1446     if ( iCurrentState != EOpenAndWaiting )
       
  1447         {
       
  1448         LOGGER_WRITE_1( "WARNING! Invalid state: %d", iCurrentState );
       
  1449         }
       
  1450     
       
  1451     if ( aUid < KRssFeedsOffset )
       
  1452         {
       
  1453         // Bookmark item
       
  1454         LOGGER_WRITE( "Bookmark item" );
       
  1455         // Ensure that new parent folder exists 
       
  1456         TBool folderExists( EFalse );   
       
  1457         err = iDb.FolderExists( aNewParent, folderExists );
       
  1458         if ( err || !folderExists )
       
  1459             {
       
  1460             User::RequestComplete( iCallerStatus, KErrPathNotFound );
       
  1461             LOGGER_WRITE_1( "iDb.FolderExist returned %d, new parent folder not found", err );
       
  1462             return;
       
  1463             }   
       
  1464         
       
  1465         CFavouritesItem* item = CFavouritesItem::NewLC();
       
  1466 
       
  1467         err = iDb.Get( aUid, *item );
       
  1468         if ( err == KErrNone )
       
  1469             {
       
  1470             if ( item->ParentFolder() != aNewParent )
       
  1471                 {
       
  1472                 TTime time = item->Modified();
       
  1473                 
       
  1474                 // Parent was changed, set new
       
  1475                 item->SetParentFolder( aNewParent );
       
  1476 
       
  1477                 // Update, this'll move the item
       
  1478                 err = iDb.Update( *item, aUid, ETrue );
       
  1479                 
       
  1480                 if ( err == KErrNone )
       
  1481                     {
       
  1482                     // Do not change the timestamp, otherwise this will be
       
  1483                     // considered to be 'updated' item instead of moved one
       
  1484                     err = iDb.SetModified(aUid, time);
       
  1485                     if ( err != KErrNone )
       
  1486                         {
       
  1487                         LOGGER_WRITE_1( "iDb.SetModified(aUid, time) failed (%d).", err );
       
  1488                         }
       
  1489                         
       
  1490                     // Inform ChangeFinder of updated item
       
  1491                     TSnapshotItem snapshotItem( aUid );
       
  1492                     snapshotItem.SetParentId( iParentFolder );
       
  1493                     snapshotItem.CreateHashL( item->Name(), item->Url() );
       
  1494                     iChangeFinder->ItemMovedL( snapshotItem );
       
  1495                     }
       
  1496                 else 
       
  1497                     {
       
  1498                     LOGGER_WRITE_1( "iDb.Update(*item, aUid, ETrue) failed (%d).", err );
       
  1499                     }               
       
  1500                 }
       
  1501             else 
       
  1502                 {
       
  1503                 LOGGER_WRITE( "Ignoring move (parent was already correct)." );
       
  1504                 }           
       
  1505             }
       
  1506         else
       
  1507             {
       
  1508             LOGGER_WRITE_1( "RFavouritesDb::Get failed with %d", err );
       
  1509             err = KErrNotFound;
       
  1510             }
       
  1511 
       
  1512         CleanupStack::PopAndDestroy( item );
       
  1513         User::RequestComplete( iCallerStatus, err ); 
       
  1514         }
       
  1515     else
       
  1516         {
       
  1517         // RRS item
       
  1518         LOGGER_WRITE( "RSS item" );
       
  1519         if ( !iRootFolder.HasRootFolderItem() )
       
  1520             {
       
  1521             User::RequestComplete( iCallerStatus, KErrNotFound );
       
  1522             LOGGER_WRITE( "rss root folder not found" );
       
  1523             return;
       
  1524             }
       
  1525         const CFolderItem& rootFolder = iRootFolder.RootFolderItem();
       
  1526         const CFolderItem* rssItem = rootFolder.Search( aUid - KRssFeedsOffset );
       
  1527         if ( !rssItem )
       
  1528             {
       
  1529             User::RequestComplete( iCallerStatus, KErrNotFound );
       
  1530             LOGGER_WRITE( "rssItem not found" );
       
  1531             return;
       
  1532             }
       
  1533         LOGGER_WRITE_1("rssItem->Id(): %d", rssItem->Id());
       
  1534         if ( !rssItem->Parent() )
       
  1535             {
       
  1536             // this is "RSS Root" folder, can't move
       
  1537             User::RequestComplete( iCallerStatus, KErrNotFound );
       
  1538             LOGGER_WRITE( "RSS Root folder, can't move" );
       
  1539             return;
       
  1540             }
       
  1541         const CFolderItem* parent = rootFolder.Search( aNewParent - KRssFeedsOffset );
       
  1542         if ( !parent )
       
  1543             {
       
  1544             // new parent not found
       
  1545             User::RequestComplete( iCallerStatus, KErrNotFound );
       
  1546             LOGGER_WRITE( "new parent not found" );
       
  1547             return;
       
  1548             }
       
  1549         if ( !parent->IsFolder() )
       
  1550             {
       
  1551             // not a folder
       
  1552             User::RequestComplete( iCallerStatus, KErrNotFound );
       
  1553             LOGGER_WRITE( "parent is not a folder" );
       
  1554             return;
       
  1555             }
       
  1556         RPointerArray<const CFolderItem> movedItems;
       
  1557         CleanupClosePushL( movedItems );
       
  1558         movedItems.Append( rssItem );
       
  1559         // FolderItemRequestCompleted is called when ready
       
  1560         iRootFolder.MoveFolderItemsToL( movedItems, *parent);
       
  1561         CleanupStack::PopAndDestroy( &movedItems );
       
  1562               
       
  1563         delete iMovedItem;
       
  1564         iMovedItem = NULL;
       
  1565         iMovedItem = new (ELeave) TSnapshotItem( aUid, aNewParent );
       
  1566         
       
  1567         iCurrentState = EBookmarkMoving;
       
  1568         LOGGER_WRITE( "Wait for FolderItemRequestCompleted.." );
       
  1569         }   
       
  1570     
       
  1571     LOGGER_LEAVEFN( "CBookmarkDataStore::DoMoveItemL" );
       
  1572     }
       
  1573 
       
  1574 // -----------------------------------------------------------------------------
       
  1575 // CBookmarkDataStore::DoDeleteItemL
       
  1576 // Removes item from the message store
       
  1577 // -----------------------------------------------------------------------------
       
  1578 void CBookmarkDataStore::DoDeleteItemL( TSmlDbItemUid aUid, TRequestStatus& aStatus )
       
  1579     {
       
  1580     LOGGER_ENTERFN( "CBookmarkDataStore::DoDeleteItemL" );
       
  1581     LOGGER_WRITE_1( "aUid: %d", aUid );
       
  1582     iCallerStatus = &aStatus;
       
  1583     *iCallerStatus = KRequestPending;
       
  1584     
       
  1585     // Check that we're in proper state
       
  1586     if ( iCurrentState != EOpenAndWaiting ) 
       
  1587         {
       
  1588         LOGGER_WRITE_1("CBookmarkDataStore::DoDeleteItemL, Incorrect state: %d", iCurrentState);
       
  1589         }
       
  1590     
       
  1591     TInt error( KErrNone );
       
  1592     if ( aUid < KRssFeedsOffset )
       
  1593         {
       
  1594         LOGGER_WRITE( "Delete Bookmark item" );
       
  1595         // Delete item from db and return the error code
       
  1596         error = iDb.Delete( aUid );
       
  1597         
       
  1598         if ( error == KErrNone )
       
  1599             {
       
  1600             // Inform ChangeFinder of the removed item
       
  1601             TSnapshotItem item( aUid );     
       
  1602             iChangeFinder->ItemDeletedL( item );
       
  1603             }
       
  1604         else
       
  1605             {
       
  1606             LOGGER_WRITE_1("CBookmarkDataStore::DoDeleteItemL, iDb.Delete failed: %d", error);
       
  1607             }
       
  1608         
       
  1609         User::RequestComplete( iCallerStatus, error );
       
  1610         }
       
  1611     else
       
  1612         {
       
  1613         LOGGER_WRITE( "Delete RSS item" );
       
  1614         if ( !iRootFolder.HasRootFolderItem() )
       
  1615             {
       
  1616             User::RequestComplete( iCallerStatus, KErrNotFound );
       
  1617             LOGGER_WRITE( "rss root folder not found" );
       
  1618             LOGGER_LEAVEFN( "CBookmarkDataStore::DoDeleteItemL" );
       
  1619             return;
       
  1620             }
       
  1621         const CFolderItem& rootFolder = iRootFolder.RootFolderItem();
       
  1622         const CFolderItem* item = rootFolder.Search( aUid - KRssFeedsOffset );
       
  1623         if ( !item )
       
  1624             {
       
  1625             User::RequestComplete( iCallerStatus, KErrNotFound );
       
  1626             LOGGER_WRITE( "item not found" );
       
  1627             LOGGER_LEAVEFN( "CBookmarkDataStore::DoDeleteItemL" );
       
  1628             return;
       
  1629             }
       
  1630         
       
  1631         LOGGER_WRITE_1("founded. item->Id(): %d", item->Id());
       
  1632         if ( !item->Parent() )
       
  1633             {
       
  1634             LOGGER_WRITE_1(
       
  1635             "Item parent not found, this is root folder. Return error: %d", KErrAccessDenied);
       
  1636             User::RequestComplete( iCallerStatus, KErrAccessDenied );
       
  1637             LOGGER_LEAVEFN( "CBookmarkDataStore::DoDeleteItemL" );
       
  1638             return;
       
  1639             }
       
  1640         else
       
  1641             {
       
  1642             LOGGER_WRITE( "parent found" );
       
  1643             }
       
  1644         
       
  1645         RPointerArray<const CFolderItem> folderItems;
       
  1646         CleanupClosePushL( folderItems );
       
  1647         error = folderItems.Append( item );
       
  1648         LOGGER_WRITE_1( "folderItems.Append error: %d", error );
       
  1649         TRAP( error, iRootFolder.DeleteFolderItemsL( folderItems ) );
       
  1650         CleanupStack::PopAndDestroy( &folderItems );
       
  1651         LOGGER_WRITE_1( "Trap error: %d", error );
       
  1652         
       
  1653         iReplaceItem = aUid;
       
  1654         iCurrentState = EBookmarkDeleting;
       
  1655         LOGGER_WRITE( "Wait for FolderItemRequestCompleted.." );
       
  1656         }
       
  1657         
       
  1658     LOGGER_LEAVEFN( "CBookmarkDataStore::DoDeleteItemL" );
       
  1659     }
       
  1660 
       
  1661 // -----------------------------------------------------------------------------
       
  1662 // CBookmarkDataStore::DoSoftDeleteItemL
       
  1663 // Soft delete isn't supported.
       
  1664 // -----------------------------------------------------------------------------
       
  1665 void CBookmarkDataStore::DoSoftDeleteItemL(TSmlDbItemUid /*aUid*/, TRequestStatus& aStatus)
       
  1666     {
       
  1667     LOGGER_ENTERFN( "CBookmarkDataStore::DoSoftDeleteItemL" );
       
  1668     iCallerStatus = &aStatus;
       
  1669     *iCallerStatus = KRequestPending;
       
  1670     
       
  1671     User::RequestComplete(iCallerStatus, KErrNotSupported); 
       
  1672     LOGGER_LEAVEFN( "CBookmarkDataStore::DoSoftDeleteItemL" );  
       
  1673     }
       
  1674 
       
  1675 // -----------------------------------------------------------------------------
       
  1676 // CBookmarkDataStore::DoDeleteAllItemsL
       
  1677 // Deletes all items in the standard folders of bookmark store
       
  1678 // -----------------------------------------------------------------------------
       
  1679 void CBookmarkDataStore::DoDeleteAllItemsL( TRequestStatus& aStatus )
       
  1680     {
       
  1681     LOGGER_ENTERFN( "CBookmarkDataStore::DoDeleteAllItemsL" );
       
  1682 
       
  1683     iCallerStatus = &aStatus;
       
  1684     *iCallerStatus = KRequestPending;
       
  1685 
       
  1686     // Check that we're in proper state
       
  1687     if (iCurrentState != EOpenAndWaiting) 
       
  1688         {
       
  1689         LOGGER_WRITE_1( "CSmsDataStore::DoDeleteAllItemsL, Incorrect state: %d", iCurrentState );
       
  1690         }
       
  1691 
       
  1692     // Reset the whole change finder
       
  1693     iChangeFinder->ResetL();
       
  1694     
       
  1695     // Delete all Bookmark items
       
  1696     LOGGER_WRITE( "Delete Bookmark items" );
       
  1697     // Loop through all items at root, and delete everything
       
  1698     CFavouritesItemList* list = new ( ELeave ) CFavouritesItemList();
       
  1699     TInt error = iDb.GetAll( *list, KFavouritesRootUid );
       
  1700     if ( error == KErrNone )  
       
  1701         {
       
  1702         // Loop through the list and delete all items
       
  1703         TInt count = list->Count();
       
  1704         LOGGER_WRITE_1("list->Count(): %d", count);
       
  1705         for ( TInt i = 0; i < count; ++i )
       
  1706             {
       
  1707             CFavouritesItem* item = (*list)[i];
       
  1708         
       
  1709             // Don't bother try to erase items, which are read only
       
  1710             if ( !item->IsFactoryItem() )
       
  1711                 {
       
  1712                 TInt deleted = iDb.Delete( item->Uid() );
       
  1713                 if ( deleted != KErrNone )
       
  1714                     {
       
  1715                     // In the case of error, store the error value
       
  1716                     error = deleted;
       
  1717                     LOGGER_WRITE_1("CBookmarkDataStore::DoDeleteAllItemsL, iDb.Delete failed: %d", error);
       
  1718                     }
       
  1719                 
       
  1720                 LOGGER_WRITE_1("item->Uid(): %d", item->Uid())
       
  1721                 LOGGER_WRITE_1("iDb.Delete ret: %d", error)
       
  1722                 
       
  1723                 }
       
  1724             else
       
  1725                 {
       
  1726                 LOGGER_WRITE_1("item->IsFactoryItem(): id: %d", item->Uid());
       
  1727                 }
       
  1728             }
       
  1729         }
       
  1730     else
       
  1731         {
       
  1732         LOGGER_WRITE_1("CBookmarkDataStore::DoDeleteAllItemsL, iDb.GetAll failed: %d", error);
       
  1733         }
       
  1734     delete list;
       
  1735     
       
  1736     // Delete all WebFeeds
       
  1737     LOGGER_WRITE( "Delete RSS items" );
       
  1738     if ( !iRootFolder.HasRootFolderItem() )
       
  1739         {
       
  1740         User::RequestComplete( iCallerStatus, error );
       
  1741         LOGGER_WRITE( "no RSS items" );
       
  1742         return;
       
  1743         }
       
  1744     const CFolderItem& rootFolder = iRootFolder.RootFolderItem();
       
  1745     // add subfolders
       
  1746     RPointerArray<const CFolderItem> folderItems;
       
  1747     CleanupClosePushL( folderItems );
       
  1748     for ( TInt i = 0; i < rootFolder.FolderItemCount(); i++)
       
  1749         {
       
  1750         error = folderItems.Append( rootFolder.FolderItemAt( i ) );
       
  1751         LOGGER_WRITE_1( "folderItems.Append error: %d", error );
       
  1752         }
       
  1753     
       
  1754     if ( folderItems.Count() > 0 )
       
  1755         {
       
  1756         TRAP( error, iRootFolder.DeleteFolderItemsL( folderItems ) );
       
  1757         
       
  1758         LOGGER_WRITE_1( "Trap error: %d", error );
       
  1759         
       
  1760         iCurrentState = EBookmarkDeletingAll;
       
  1761         LOGGER_WRITE( "Wait for FolderItemRequestCompleted.." );
       
  1762         }
       
  1763     else
       
  1764         {
       
  1765         LOGGER_WRITE( "RSS items not found" );
       
  1766         User::RequestComplete( iCallerStatus, KErrNone ); 
       
  1767         }
       
  1768     CleanupStack::PopAndDestroy( &folderItems );
       
  1769     LOGGER_LEAVEFN( "CBookmarkDataStore::DoDeleteAllItemsL" );          
       
  1770     }
       
  1771 
       
  1772 // -----------------------------------------------------------------------------
       
  1773 // CBookmarkDataStore::DoHasSyncHistory
       
  1774 // This method returns ETrue if Data Store has history information. 
       
  1775 // Slow-sync will be used if Data Store does not have history information.
       
  1776 // -----------------------------------------------------------------------------
       
  1777 TBool CBookmarkDataStore::DoHasSyncHistory() const
       
  1778     {
       
  1779     LOGGER_ENTERFN( "CBookmarkDataStore::DoHasSyncHistory" );
       
  1780     LOGGER_WRITE_1( "iHasHistory: %d", iHasHistory );
       
  1781     LOGGER_LEAVEFN( "CBookmarkDataStore::DoHasSyncHistory" );   
       
  1782     return iHasHistory;
       
  1783     }
       
  1784 
       
  1785 // -----------------------------------------------------------------------------
       
  1786 // CBookmarkDataStore::DoAddedItems
       
  1787 // This method returns UIDs of added items. Those items are added after previous
       
  1788 // synchronization with current synchronization relationship. 
       
  1789 // -----------------------------------------------------------------------------
       
  1790 const MSmlDataItemUidSet& CBookmarkDataStore::DoAddedItems() const
       
  1791     {
       
  1792     LOGGER_ENTERFN( "CBookmarkDataStore::DoAddedItems" );
       
  1793     
       
  1794     // Ensure that we're in a proper state
       
  1795     if ( iCurrentState != EOpenAndWaiting )
       
  1796         {
       
  1797         LOGGER_WRITE_1( "CBookmarkDataStore::DoAddedItems, invalid state %d.", iCurrentState );
       
  1798         }
       
  1799     
       
  1800     TInt error(KErrNone);
       
  1801     
       
  1802     // Clear new-items array
       
  1803     iNewItems->Reset();
       
  1804     
       
  1805     // Search for new items
       
  1806     TRAP( error, iChangeFinder->FindNewItemsL( *iNewItems ) )
       
  1807     if ( error != KErrNone )
       
  1808         {
       
  1809         LOGGER_WRITE_1( "CBookmarkDataStore::DoAddedItems, iChangeFinder->FindNewItemsL leaved with %d.", error );
       
  1810         } 
       
  1811     
       
  1812     LOGGER_WRITE_1( "New item count: %d.", iNewItems->ItemCount() );
       
  1813     LOGGER_LEAVEFN( "CBookmarkDataStore::DoAddedItems" );
       
  1814     
       
  1815     return *iNewItems;  
       
  1816     }
       
  1817     
       
  1818 // -----------------------------------------------------------------------------
       
  1819 // CBookmarkDataStore::DoDeletedItems
       
  1820 // Returns ids of items, which are deleted after previous synchronization
       
  1821 // -----------------------------------------------------------------------------
       
  1822 const MSmlDataItemUidSet& CBookmarkDataStore::DoDeletedItems() const
       
  1823     {
       
  1824     LOGGER_ENTERFN( "CBookmarkDataStore::DoDeletedItemsL" );    
       
  1825     
       
  1826     // Ensure that we're in a proper state
       
  1827     if ( iCurrentState != EOpenAndWaiting )
       
  1828         {
       
  1829         LOGGER_WRITE_1( "CBookmarkDataStore::DoDeletedItems, invalid state %d.", iCurrentState );
       
  1830         }
       
  1831     
       
  1832     TInt error( KErrNone );
       
  1833     
       
  1834     // Clear deleted-items array
       
  1835     iDeletedItems->Reset();
       
  1836     
       
  1837     // Search for deleted items
       
  1838     TRAP( error, iChangeFinder->FindDeletedItemsL( *iDeletedItems ) );
       
  1839     if ( error != KErrNone )
       
  1840         {
       
  1841         LOGGER_WRITE_1( "CBookmarkDataStore::DoDeletedItems, iChangeFinder->FindDeletedItemsL leaved with %d.", error );
       
  1842         }
       
  1843     
       
  1844     LOGGER_WRITE_1( "Deleted item count: %d.", iDeletedItems->ItemCount() );
       
  1845     LOGGER_LEAVEFN( "CBookmarkDataStore::DoDeletedItemsL" );
       
  1846     return *iDeletedItems;
       
  1847     }
       
  1848 
       
  1849 // -----------------------------------------------------------------------------
       
  1850 // CBookmarkDataStore::DoSoftDeletedItems
       
  1851 // Not directly supported, empty list returned
       
  1852 // -----------------------------------------------------------------------------
       
  1853 const MSmlDataItemUidSet& CBookmarkDataStore::DoSoftDeletedItems() const
       
  1854     {
       
  1855     LOGGER_ENTERFN( "CBookmarkDataStore::DoSoftDeletedItems" );
       
  1856     LOGGER_LEAVEFN( "CBookmarkDataStore::DoSoftDeletedItems" );         
       
  1857 
       
  1858     // Return empty array as a result
       
  1859     iSoftDeletedItems->Reset();
       
  1860     return *iSoftDeletedItems;
       
  1861     }
       
  1862 
       
  1863 // -----------------------------------------------------------------------------
       
  1864 // CBookmarkDataStore::DoModifiedItems
       
  1865 // Finds all modified items in the data store
       
  1866 // -----------------------------------------------------------------------------
       
  1867 const MSmlDataItemUidSet& CBookmarkDataStore::DoModifiedItems() const
       
  1868     {
       
  1869     LOGGER_ENTERFN( "CBookmarkDataStore::DoModifiedItems" );    
       
  1870     
       
  1871     // Ensure that we're in a proper state
       
  1872     if ( iCurrentState != EOpenAndWaiting )
       
  1873         {
       
  1874         LOGGER_WRITE_1( "CBookmarkDataStore::DoModifiedItems, invalid state %d.", iCurrentState );
       
  1875         }
       
  1876 
       
  1877     TInt error( KErrNone );
       
  1878 
       
  1879     // Clear updated-items array
       
  1880     iUpdatedItems->Reset();
       
  1881     
       
  1882     // Search for updated items
       
  1883     TRAP( error, iChangeFinder->FindChangedItemsL( *iUpdatedItems ) )
       
  1884     if ( error != KErrNone )
       
  1885         {
       
  1886         LOGGER_WRITE_1( "CBookmarkDataStore::DoModifiedItems, iChangeFinder->FindChangedItemsL leaved with %d.", error );
       
  1887         }
       
  1888     
       
  1889     LOGGER_WRITE_1( "Modified item count: %d.", iUpdatedItems->ItemCount() );
       
  1890     LOGGER_LEAVEFN( "CBookmarkDataStore::DoModifiedItems" );        
       
  1891     return *iUpdatedItems;
       
  1892     }
       
  1893 
       
  1894 // -----------------------------------------------------------------------------
       
  1895 // CBookmarkDataStore::DoMovedItems
       
  1896 // Finds all moved items in the data store
       
  1897 // -----------------------------------------------------------------------------
       
  1898 const MSmlDataItemUidSet& CBookmarkDataStore::DoMovedItems() const
       
  1899     {
       
  1900     LOGGER_ENTERFN( "CBookmarkDataStore::DoMovedItems" );   
       
  1901     
       
  1902     // Ensure that we're in a proper state
       
  1903     if ( iCurrentState != EOpenAndWaiting )
       
  1904         {
       
  1905         LOGGER_WRITE_1( "CBookmarkDataStore::DoMovedItems, invalid state %d.", iCurrentState );
       
  1906         }       
       
  1907     
       
  1908     TInt error( KErrNone );
       
  1909     
       
  1910     // Clear moved-items array
       
  1911     iMovedItems->Reset();
       
  1912     
       
  1913     TRAP( error, iChangeFinder->FindMovedItemsL( *iMovedItems ) );
       
  1914     if ( error != KErrNone )
       
  1915         {
       
  1916         LOGGER_WRITE_1( "CBookmarkDataStore::DoMovedItems, iChangeFinder->FindMovedItemsL leaved with %d.", error );
       
  1917         }
       
  1918        
       
  1919     LOGGER_WRITE_1( "Moved item count: %d.", iMovedItems->ItemCount() );
       
  1920     LOGGER_LEAVEFN( "CBookmarkDataStore::DoMovedItems" );
       
  1921     return *iMovedItems;
       
  1922     }
       
  1923 
       
  1924 // -----------------------------------------------------------------------------
       
  1925 // CBookmarkDataStore::DoResetChangeInfoL
       
  1926 // Resets change history in the data store. All content is considered
       
  1927 // new in the data store point of view.
       
  1928 // -----------------------------------------------------------------------------
       
  1929 void CBookmarkDataStore::DoResetChangeInfoL( TRequestStatus& aStatus )
       
  1930     {
       
  1931     LOGGER_ENTERFN( "CBookmarkDataStore::DoResetChangeInfoL" );
       
  1932     
       
  1933     iCallerStatus = &aStatus;
       
  1934     *iCallerStatus = KRequestPending;
       
  1935     
       
  1936     // Check that we're in proper state
       
  1937     if ( iCurrentState != EOpenAndWaiting ) 
       
  1938         {
       
  1939         LOGGER_WRITE_1( "CBookmarkDataStore::DoResetChangeInfoL, invalid state %d.", iCurrentState );
       
  1940         }   
       
  1941             
       
  1942     // Reset change info in ChangeFinder
       
  1943     iChangeFinder->ResetL();
       
  1944     iHasHistory = EFalse;
       
  1945     
       
  1946     // Signal we're done
       
  1947     User::RequestComplete( iCallerStatus, KErrNone );   
       
  1948         
       
  1949     LOGGER_LEAVEFN( "CBookmarkDataStore::DoResetChangeInfoL" );     
       
  1950     }
       
  1951 
       
  1952 // -----------------------------------------------------------------------------
       
  1953 // CBookmarkDataStore::DoCommitChangeInfoL
       
  1954 // Commits change info. These items are no longer reported, when change
       
  1955 // information is being queried.
       
  1956 // -----------------------------------------------------------------------------
       
  1957 void CBookmarkDataStore::DoCommitChangeInfoL( TRequestStatus& aStatus,
       
  1958     const MSmlDataItemUidSet& aItems )
       
  1959     {
       
  1960     LOGGER_ENTERFN( "CBookmarkDataStore::DoCommitChangeInfoL(1)" );
       
  1961     
       
  1962     iCallerStatus = &aStatus;
       
  1963     *iCallerStatus = KRequestPending;
       
  1964     
       
  1965     // Ensure that we're in a proper state
       
  1966     if ( iCurrentState != EOpenAndWaiting ) 
       
  1967         {
       
  1968         LOGGER_WRITE_1( "CBookmarkDataStore::DoCommitChangeInfoL, invalid state %d.", iCurrentState );
       
  1969         }
       
  1970 
       
  1971     // Notify ChangeFinder
       
  1972     LOGGER_WRITE_1( "CBookmarkDataStore::DoCommitChangeInfoL, item count %d.", aItems.ItemCount() );
       
  1973     iChangeFinder->CommitChangesL( aItems );
       
  1974     iHasHistory = ETrue;
       
  1975         
       
  1976     // Signal we're done
       
  1977     User::RequestComplete( iCallerStatus, KErrNone );
       
  1978     
       
  1979     LOGGER_LEAVEFN(" CBookmarkDataStore::DoCommitChangeInfoL(1)" ); 
       
  1980     }
       
  1981 
       
  1982 // -----------------------------------------------------------------------------
       
  1983 // CBookmarkDataStore::DoCommitChangeInfoL
       
  1984 // Commits change info. There is no more nothing to report when change
       
  1985 // information is being queried. 
       
  1986 // -----------------------------------------------------------------------------
       
  1987 void CBookmarkDataStore::DoCommitChangeInfoL( TRequestStatus& aStatus )
       
  1988     {
       
  1989     LOGGER_ENTERFN( "CBookmarkDataStore::DoCommitChangeInfoL(2)" );
       
  1990 
       
  1991     iCallerStatus = &aStatus;
       
  1992     *iCallerStatus = KRequestPending;
       
  1993     
       
  1994     // Ensure that we're in a proper state
       
  1995     if ( iCurrentState != EOpenAndWaiting ) 
       
  1996         {
       
  1997         LOGGER_WRITE_1( "CBookmarkDataStore::DoCommitChangeInfoL, invalid state %d.", iCurrentState );
       
  1998         }
       
  1999     
       
  2000     // Notify ChangeFinder
       
  2001     iChangeFinder->CommitChangesL();
       
  2002     iHasHistory = ETrue;
       
  2003         
       
  2004     // Signal we're done
       
  2005     User::RequestComplete( iCallerStatus, KErrNone );
       
  2006         
       
  2007     LOGGER_LEAVEFN( "CBookmarkDataStore::DoCommitChangeInfoL(2)" );     
       
  2008     }
       
  2009 
       
  2010 // -----------------------------------------------------------------------------
       
  2011 // CBookmarkDataStore::RegisterSnapshotL
       
  2012 // Sets Changefinder to compare against current bookmark store content
       
  2013 // -----------------------------------------------------------------------------
       
  2014 void CBookmarkDataStore::RegisterSnapshotL()
       
  2015     {
       
  2016     LOGGER_ENTERFN( "CBookmarkDataStore::RegisterSnapshotL()" );
       
  2017     
       
  2018     CArrayFixSeg<TSnapshotItem>* snapshot = 
       
  2019         new ( ELeave ) CArrayFixSeg<TSnapshotItem>( KSnapshotGranularity );
       
  2020     CleanupStack::PushL( snapshot );
       
  2021     
       
  2022     
       
  2023     RegisterToSnapshotL( snapshot, KFavouritesRootUid );
       
  2024     
       
  2025     if ( iRootFolder.HasRootFolderItem() )
       
  2026         {
       
  2027         RegisterRssFeedsToSnapshotL( snapshot, iRootFolder.RootFolderItem() );
       
  2028         }
       
  2029     
       
  2030     // Set new snapshot to compare against
       
  2031     iChangeFinder->SetNewSnapshot( snapshot );
       
  2032     
       
  2033     // Changefinder takes ownership of the snapshot
       
  2034     CleanupStack::Pop( snapshot );
       
  2035     
       
  2036     LOGGER_LEAVEFN( "CBookmarkDataStore::RegisterSnapshotL()" );
       
  2037     }
       
  2038 
       
  2039 
       
  2040 // -----------------------------------------------------------------------------
       
  2041 // CBookmarkDataStore::RegisterToSnapshotL
       
  2042 // Adds recursively all the bookmark items to the snapshot
       
  2043 // -----------------------------------------------------------------------------
       
  2044 void CBookmarkDataStore::RegisterToSnapshotL( CArrayFixSeg<TSnapshotItem>* aSnapshot,
       
  2045     TInt aFolderUid )
       
  2046     {
       
  2047     CFavouritesItemList* list = new ( ELeave ) CFavouritesItemList;
       
  2048     CleanupStack::PushL( list );
       
  2049     TInt error = iDb.GetAll( *list, aFolderUid );
       
  2050     if ( error == KErrNone )
       
  2051         {
       
  2052         // Loop through the list. Add folders and items to the snapshot
       
  2053         TInt count = list->Count();
       
  2054         for ( TInt i = 0; i < count; ++i )
       
  2055             {
       
  2056             CFavouritesItem* item = (*list)[i];
       
  2057             // No matter whether it's a folder or item, we'll add it to snapshot
       
  2058             TSnapshotItem snapshotItem( item->Uid() );
       
  2059             snapshotItem.SetParentId( item->ParentFolder() );
       
  2060             snapshotItem.CreateHashL( item->Name(), item->Url() );
       
  2061             TKeyArrayFix key( iKey );
       
  2062             aSnapshot->InsertIsqL( snapshotItem, key );
       
  2063 
       
  2064             // Remember to add also childs in case of folder (recurse)
       
  2065             if ( item->Type() == CFavouritesItem::EFolder )
       
  2066                 {
       
  2067                 RegisterToSnapshotL( aSnapshot, item->Uid() );
       
  2068                 }
       
  2069             }
       
  2070         }
       
  2071     CleanupStack::PopAndDestroy( list ); //list
       
  2072     }
       
  2073 
       
  2074 // -----------------------------------------------------------------------------
       
  2075 // CBookmarkDataStore::RegisterRssFeedsToSnapshotL
       
  2076 // Adds recursively all the rssFeed items to the snapshot
       
  2077 // -----------------------------------------------------------------------------
       
  2078 void CBookmarkDataStore::RegisterRssFeedsToSnapshotL( CArrayFixSeg<TSnapshotItem>* aSnapshot,
       
  2079     const CFolderItem& folder )
       
  2080     {
       
  2081     TSnapshotItem snapshotItem( folder.Id() + KRssFeedsOffset );
       
  2082     
       
  2083     const CFolderItem* parent = folder.Parent();
       
  2084     if ( parent )
       
  2085         {
       
  2086         snapshotItem.SetParentId( parent->Id() + KRssFeedsOffset );
       
  2087         }
       
  2088     else
       
  2089         {
       
  2090         snapshotItem.SetParentId( KErrNotFound );
       
  2091         }
       
  2092     snapshotItem.CreateHashL( folder.Name(), folder.SourceUrl() );
       
  2093     
       
  2094     TKeyArrayFix key( iKey );
       
  2095     aSnapshot->InsertIsqL( snapshotItem, key );
       
  2096     
       
  2097     // add subfolders
       
  2098     for ( TInt i = 0; i < folder.FolderItemCount(); i++)
       
  2099         {
       
  2100         RegisterRssFeedsToSnapshotL( aSnapshot, *(folder.FolderItemAt( i ) ));
       
  2101         }
       
  2102     }
       
  2103 
       
  2104 // -----------------------------------------------------------------------------
       
  2105 // CBookmarkDataStore::AssignString
       
  2106 // Assigns data from one descriptor into another, truncates if too long 
       
  2107 // -----------------------------------------------------------------------------
       
  2108 void CBookmarkDataStore::AssignString( TDes8& aDestination, const TDesC8& aSource )
       
  2109     {
       
  2110     TInt targetLength = aSource.Length();
       
  2111     if ( aDestination.MaxLength() < targetLength )
       
  2112         {
       
  2113         targetLength = aDestination.MaxLength();
       
  2114         }
       
  2115         
       
  2116     aDestination.Copy( aSource.Ptr(), targetLength );
       
  2117     }