diff -r f72a12da539e -r 5315654608de idlehomescreen/widgetmanager/src/wmpersistentwidgetorder.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/idlehomescreen/widgetmanager/src/wmpersistentwidgetorder.cpp Thu Jan 07 12:39:41 2010 +0200 @@ -0,0 +1,230 @@ +/* +* 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. 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 ); + // 2. write all content to the stream + writer.WriteInt32L( aArray.Count() ); + for( TInt i=0; iUid().iUid; + const TDesC16& publisherId = aArray[i]->HsContentInfo().PublisherId(); + writer.WriteInt32L( uid ); + writer.WriteInt32L( publisherId.Length() ); + writer.WriteL( publisherId, publisherId.Length() ); + } + // 3. check available space and commit the stream + TInt streamsize = writer.Sink()->SizeL(); + TBool belowCriticalLevel = SysUtil::DiskSpaceBelowCriticalLevelL( + &iFs, streamsize, EDriveC ); + if( !belowCriticalLevel ) + { + writer.CommitL(); + fileStore->SetRootL(id); + fileStore->CommitL(); + } + // 4. cleanup + CleanupStack::PopAndDestroy( &writer ); + CleanupStack::PopAndDestroy( fileStore ); + } + +// --------------------------------------------------------- +// CWmPersistentWidgetOrder::CleanupArray +// --------------------------------------------------------- +// +void CWmPersistentWidgetOrder::CleanupArray() + { + for( TInt i=0; i