sl@0: /* sl@0: * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "TSTCLIPB.H" sl@0: #include sl@0: sl@0: const TUid KClipboardFileUid={268435515}; sl@0: sl@0: sl@0: _LIT(KClipFilePath, "_:\\system\\clipbd\\main.sto"); sl@0: typedef TBuf<28> TClipboardFileName; sl@0: sl@0: sl@0: /** sl@0: Construct full path and name of clipbard file. sl@0: @param aFileName On completion this will hold the result. sl@0: */ sl@0: static void GetClipboardFileName(TClipboardFileName& aFileName) sl@0: { sl@0: aFileName.Copy(KClipFilePath); sl@0: aFileName[0] = 'A' + static_cast(RFs::GetSystemDrive()); sl@0: } sl@0: sl@0: sl@0: sl@0: EXPORT_C CClipboard* CClipboard::NewForReadingLC(RFs& aFsSession) sl@0: { sl@0: // get store filename sl@0: TClipboardFileName clipboardFileName; sl@0: GetClipboardFileName(clipboardFileName); sl@0: sl@0: TEntry entry; sl@0: User::LeaveIfError(aFsSession.Entry(clipboardFileName,entry)); sl@0: if (entry[0]!=KDirectFileStoreLayoutUid || entry[1]!=KClipboardFileUid) sl@0: User::Leave(KErrCorrupt); // !! get a better error sl@0: CClipboard* self=new(ELeave) CClipboard(aFsSession); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructForReadingL(clipboardFileName); sl@0: return(self); sl@0: } sl@0: sl@0: /** sl@0: Construct a clipboard store for reading from. sl@0: */ sl@0: void CClipboard::ConstructForReadingL(const TDesC& aFileName) sl@0: { sl@0: iStore=CDirectFileStore::OpenL(iFsSession,aFileName,EFileRead); sl@0: iStreamDictionary=CStreamDictionary::NewL(); sl@0: RStoreReadStream root; sl@0: root.OpenLC(*iStore,iStore->Root()); sl@0: root>> *iStreamDictionary; sl@0: CleanupStack::PopAndDestroy(); // root sl@0: } sl@0: sl@0: sl@0: EXPORT_C CClipboard* CClipboard::NewForWritingLC(RFs& aFsSession) sl@0: { sl@0: // get store filename sl@0: TClipboardFileName clipboardFileName; sl@0: GetClipboardFileName(clipboardFileName); sl@0: sl@0: CClipboard* self=new(ELeave) CClipboard(aFsSession); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructForWritingL(clipboardFileName); sl@0: return(self); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Construct a clipboard store for writing to. sl@0: */ sl@0: void CClipboard::ConstructForWritingL(const TDesC& aFileName) sl@0: { sl@0: CreateDirectoryL(aFileName); sl@0: iStore=CDirectFileStore::ReplaceL(iFsSession,aFileName,EFileRead|EFileWrite); sl@0: iStore->SetTypeL(TUidType(KDirectFileStoreLayoutUid,KClipboardFileUid)); sl@0: iStreamDictionary=CStreamDictionary::NewL(); sl@0: } sl@0: sl@0: sl@0: CClipboard::CClipboard(RFs& aFsSession) sl@0: : iFsSession(aFsSession) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CClipboard::~CClipboard() sl@0: { sl@0: delete(iStore); sl@0: delete(iStreamDictionary); sl@0: } sl@0: sl@0: sl@0: sl@0: void CClipboard::CreateDirectoryL(const TDesC& aFileName) sl@0: { sl@0: TParse parser; sl@0: parser.Set(aFileName,NULL,NULL); sl@0: TInt err=iFsSession.MkDirAll(parser.DriveAndPath()); sl@0: if (err!=KErrNone && err!=KErrAlreadyExists) sl@0: User::Leave(err); sl@0: } sl@0: sl@0: EXPORT_C void CClipboard::CommitL() sl@0: { sl@0: RStoreWriteStream stream; sl@0: TStreamId streamId=stream.CreateLC(*iStore); sl@0: stream<< *iStreamDictionary; sl@0: stream.CommitL(); sl@0: CleanupStack::PopAndDestroy(); // dictionary stream sl@0: iStore->SetRootL(streamId); sl@0: iStore->CommitL(); sl@0: }