Update contrib.
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 const TUid KClipboardFileUid={268435515};
25 _LIT(KClipFilePath, "_:\\system\\clipbd\\main.sto");
26 typedef TBuf<28> TClipboardFileName;
30 Construct full path and name of clipbard file.
31 @param aFileName On completion this will hold the result.
33 static void GetClipboardFileName(TClipboardFileName& aFileName)
35 aFileName.Copy(KClipFilePath);
36 aFileName[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive());
41 EXPORT_C CClipboard* CClipboard::NewForReadingLC(RFs& aFsSession)
44 TClipboardFileName clipboardFileName;
45 GetClipboardFileName(clipboardFileName);
48 User::LeaveIfError(aFsSession.Entry(clipboardFileName,entry));
49 if (entry[0]!=KDirectFileStoreLayoutUid || entry[1]!=KClipboardFileUid)
50 User::Leave(KErrCorrupt); // !! get a better error
51 CClipboard* self=new(ELeave) CClipboard(aFsSession);
52 CleanupStack::PushL(self);
53 self->ConstructForReadingL(clipboardFileName);
58 Construct a clipboard store for reading from.
60 void CClipboard::ConstructForReadingL(const TDesC& aFileName)
62 iStore=CDirectFileStore::OpenL(iFsSession,aFileName,EFileRead);
63 iStreamDictionary=CStreamDictionary::NewL();
64 RStoreReadStream root;
65 root.OpenLC(*iStore,iStore->Root());
66 root>> *iStreamDictionary;
67 CleanupStack::PopAndDestroy(); // root
71 EXPORT_C CClipboard* CClipboard::NewForWritingLC(RFs& aFsSession)
74 TClipboardFileName clipboardFileName;
75 GetClipboardFileName(clipboardFileName);
77 CClipboard* self=new(ELeave) CClipboard(aFsSession);
78 CleanupStack::PushL(self);
79 self->ConstructForWritingL(clipboardFileName);
85 Construct a clipboard store for writing to.
87 void CClipboard::ConstructForWritingL(const TDesC& aFileName)
89 CreateDirectoryL(aFileName);
90 iStore=CDirectFileStore::ReplaceL(iFsSession,aFileName,EFileRead|EFileWrite);
91 iStore->SetTypeL(TUidType(KDirectFileStoreLayoutUid,KClipboardFileUid));
92 iStreamDictionary=CStreamDictionary::NewL();
96 CClipboard::CClipboard(RFs& aFsSession)
97 : iFsSession(aFsSession)
101 EXPORT_C CClipboard::~CClipboard()
104 delete(iStreamDictionary);
109 void CClipboard::CreateDirectoryL(const TDesC& aFileName)
112 parser.Set(aFileName,NULL,NULL);
113 TInt err=iFsSession.MkDirAll(parser.DriveAndPath());
114 if (err!=KErrNone && err!=KErrAlreadyExists)
118 EXPORT_C void CClipboard::CommitL()
120 RStoreWriteStream stream;
121 TStreamId streamId=stream.CreateLC(*iStore);
122 stream<< *iStreamDictionary;
124 CleanupStack::PopAndDestroy(); // dictionary stream
125 iStore->SetRootL(streamId);