diff -r f72a12da539e -r 5315654608de widgetmanager/src/wmpersistentwidgetorder.cpp --- a/widgetmanager/src/wmpersistentwidgetorder.cpp Thu Dec 17 08:40:49 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,244 +0,0 @@ -/* -* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).. -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* -* Description: -* Defines an ordered list of widget id's with persistence capability -* -*/ - -// INCLUDES -#include // RFile -#include // streams -#include -#include - -#include "wmwidgetdata.h" -#include "wmpersistentwidgetorder.h" - -// CONSTANTS -_LIT( KStoreFileName, "wmlistorder.dat" ); - - -// --------------------------------------------------------- -// CWmPersistentWidgetOrder::NewL -// --------------------------------------------------------- -// -CWmPersistentWidgetOrder* CWmPersistentWidgetOrder::NewL( RFs& aFs ) - { - CWmPersistentWidgetOrder* self = - new (ELeave) CWmPersistentWidgetOrder( aFs ); - CleanupStack::PushL( self ); - self->ConstructL(); - CleanupStack::Pop( self ); - return self; - } - -// --------------------------------------------------------- -// CWmPersistentWidgetOrder::CWmPersistentWidgetOrder -// --------------------------------------------------------- -// -CWmPersistentWidgetOrder::CWmPersistentWidgetOrder( RFs& aFs ) - : iFs( aFs ) - { - } - -// --------------------------------------------------------- -// CWmPersistentWidgetOrder::ConstructL -// --------------------------------------------------------- -// -void CWmPersistentWidgetOrder::ConstructL() - { - } - -// --------------------------------------------------------- -// CWmPersistentWidgetOrder::~CWmPersistentWidgetOrder -// --------------------------------------------------------- -// -CWmPersistentWidgetOrder::~CWmPersistentWidgetOrder() - { - CleanupArray(); - } - -// --------------------------------------------------------- -// CWmPersistentWidgetOrder::LoadL -// --------------------------------------------------------- -// -void CWmPersistentWidgetOrder::LoadL() - { - // 1. empty the in-mempory storage - CleanupArray(); - // 2. create stream for reading data from a file - TFileName storeFileName; - GetStoreFileNameL( storeFileName ); - CPermanentFileStore* fileStore = NULL; - fileStore = CPermanentFileStore::OpenL( - iFs, storeFileName, EFileRead ); - CleanupStack::PushL( fileStore ); - RStoreReadStream reader; - reader.OpenLC( *fileStore, fileStore->Root() ); - // 3. read all contents from the stream - TInt arrayCount = reader.ReadInt32L(); - while( iTagArray.Count() < arrayCount ) - { - TInt32 uid = reader.ReadInt32L(); - TInt32 publisherIdLen = reader.ReadInt32L(); - HBufC16* publisherId = HBufC16::NewLC(publisherIdLen); - TPtr16 publisherIdPtr = publisherId->Des(); - reader.ReadL( publisherIdPtr, publisherIdLen ); - iTagArray.AppendL( Tag( uid, publisherId ) ); - CleanupStack::Pop( publisherId ); - } - // 4. cleanup - CleanupStack::PopAndDestroy( &reader ); - CleanupStack::PopAndDestroy( fileStore ); - } - -// --------------------------------------------------------- -// CWmPersistentWidgetOrder::StoreL -// --------------------------------------------------------- -// -void CWmPersistentWidgetOrder::StoreL( const RWidgetDataValues& aArray ) - { - // 1. empty the in-mempory storage - CleanupArray(); - // 2. serialize the widget array tags to a local array - for( TInt i=0; iUid().iUid; - HBufC16* publisherId = aArray[i]->HsContentInfo().PublisherId().AllocLC(); - iTagArray.AppendL( Tag( uid, publisherId ) ); - CleanupStack::Pop( publisherId ); - } - // 3. create stream for storing the data to a file - TFileName storeFileName; - GetStoreFileNameL( storeFileName ); - CPermanentFileStore* fileStore = CPermanentFileStore::ReplaceLC( - iFs, storeFileName, EFileWrite ); - fileStore->SetTypeL(KPermanentFileStoreLayoutUid); - RStoreWriteStream writer; - TStreamId id = writer.CreateLC( *fileStore ); - // 4. write all content to the stream - writer.WriteInt32L( iTagArray.Count() ); - for( TInt i=0; iLength() ); - writer.WriteL( *iTagArray[i].iPublisherId, - iTagArray[i].iPublisherId->Length() ); - } - // 5. check available space and commit the stream - TInt streamsize = writer.Sink()->SizeL(); - TBool noSpace = SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, streamsize, - EDriveC ); - if( noSpace ) - { - //do nothing - } - else // there is enough free space - { - writer.CommitL(); - fileStore->SetRootL(id); - fileStore->CommitL(); - } - - // 6. cleanup - CleanupStack::PopAndDestroy( &writer ); - CleanupStack::PopAndDestroy( fileStore ); - } - -// --------------------------------------------------------- -// CWmPersistentWidgetOrder::CleanupArray -// --------------------------------------------------------- -// -void CWmPersistentWidgetOrder::CleanupArray() - { - for( TInt i=0; i