sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "TSTCLIPB.H"
|
sl@0
|
20 |
#include <s32file.h>
|
sl@0
|
21 |
|
sl@0
|
22 |
const TUid KClipboardFileUid={268435515};
|
sl@0
|
23 |
|
sl@0
|
24 |
|
sl@0
|
25 |
_LIT(KClipFilePath, "_:\\system\\clipbd\\main.sto");
|
sl@0
|
26 |
typedef TBuf<28> TClipboardFileName;
|
sl@0
|
27 |
|
sl@0
|
28 |
|
sl@0
|
29 |
/**
|
sl@0
|
30 |
Construct full path and name of clipbard file.
|
sl@0
|
31 |
@param aFileName On completion this will hold the result.
|
sl@0
|
32 |
*/
|
sl@0
|
33 |
static void GetClipboardFileName(TClipboardFileName& aFileName)
|
sl@0
|
34 |
{
|
sl@0
|
35 |
aFileName.Copy(KClipFilePath);
|
sl@0
|
36 |
aFileName[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive());
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
|
sl@0
|
40 |
|
sl@0
|
41 |
EXPORT_C CClipboard* CClipboard::NewForReadingLC(RFs& aFsSession)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
// get store filename
|
sl@0
|
44 |
TClipboardFileName clipboardFileName;
|
sl@0
|
45 |
GetClipboardFileName(clipboardFileName);
|
sl@0
|
46 |
|
sl@0
|
47 |
TEntry entry;
|
sl@0
|
48 |
User::LeaveIfError(aFsSession.Entry(clipboardFileName,entry));
|
sl@0
|
49 |
if (entry[0]!=KDirectFileStoreLayoutUid || entry[1]!=KClipboardFileUid)
|
sl@0
|
50 |
User::Leave(KErrCorrupt); // !! get a better error
|
sl@0
|
51 |
CClipboard* self=new(ELeave) CClipboard(aFsSession);
|
sl@0
|
52 |
CleanupStack::PushL(self);
|
sl@0
|
53 |
self->ConstructForReadingL(clipboardFileName);
|
sl@0
|
54 |
return(self);
|
sl@0
|
55 |
}
|
sl@0
|
56 |
|
sl@0
|
57 |
/**
|
sl@0
|
58 |
Construct a clipboard store for reading from.
|
sl@0
|
59 |
*/
|
sl@0
|
60 |
void CClipboard::ConstructForReadingL(const TDesC& aFileName)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
iStore=CDirectFileStore::OpenL(iFsSession,aFileName,EFileRead);
|
sl@0
|
63 |
iStreamDictionary=CStreamDictionary::NewL();
|
sl@0
|
64 |
RStoreReadStream root;
|
sl@0
|
65 |
root.OpenLC(*iStore,iStore->Root());
|
sl@0
|
66 |
root>> *iStreamDictionary;
|
sl@0
|
67 |
CleanupStack::PopAndDestroy(); // root
|
sl@0
|
68 |
}
|
sl@0
|
69 |
|
sl@0
|
70 |
|
sl@0
|
71 |
EXPORT_C CClipboard* CClipboard::NewForWritingLC(RFs& aFsSession)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
// get store filename
|
sl@0
|
74 |
TClipboardFileName clipboardFileName;
|
sl@0
|
75 |
GetClipboardFileName(clipboardFileName);
|
sl@0
|
76 |
|
sl@0
|
77 |
CClipboard* self=new(ELeave) CClipboard(aFsSession);
|
sl@0
|
78 |
CleanupStack::PushL(self);
|
sl@0
|
79 |
self->ConstructForWritingL(clipboardFileName);
|
sl@0
|
80 |
return(self);
|
sl@0
|
81 |
}
|
sl@0
|
82 |
|
sl@0
|
83 |
|
sl@0
|
84 |
/**
|
sl@0
|
85 |
Construct a clipboard store for writing to.
|
sl@0
|
86 |
*/
|
sl@0
|
87 |
void CClipboard::ConstructForWritingL(const TDesC& aFileName)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
CreateDirectoryL(aFileName);
|
sl@0
|
90 |
iStore=CDirectFileStore::ReplaceL(iFsSession,aFileName,EFileRead|EFileWrite);
|
sl@0
|
91 |
iStore->SetTypeL(TUidType(KDirectFileStoreLayoutUid,KClipboardFileUid));
|
sl@0
|
92 |
iStreamDictionary=CStreamDictionary::NewL();
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
|
sl@0
|
96 |
CClipboard::CClipboard(RFs& aFsSession)
|
sl@0
|
97 |
: iFsSession(aFsSession)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
}
|
sl@0
|
100 |
|
sl@0
|
101 |
EXPORT_C CClipboard::~CClipboard()
|
sl@0
|
102 |
{
|
sl@0
|
103 |
delete(iStore);
|
sl@0
|
104 |
delete(iStreamDictionary);
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
|
sl@0
|
108 |
|
sl@0
|
109 |
void CClipboard::CreateDirectoryL(const TDesC& aFileName)
|
sl@0
|
110 |
{
|
sl@0
|
111 |
TParse parser;
|
sl@0
|
112 |
parser.Set(aFileName,NULL,NULL);
|
sl@0
|
113 |
TInt err=iFsSession.MkDirAll(parser.DriveAndPath());
|
sl@0
|
114 |
if (err!=KErrNone && err!=KErrAlreadyExists)
|
sl@0
|
115 |
User::Leave(err);
|
sl@0
|
116 |
}
|
sl@0
|
117 |
|
sl@0
|
118 |
EXPORT_C void CClipboard::CommitL()
|
sl@0
|
119 |
{
|
sl@0
|
120 |
RStoreWriteStream stream;
|
sl@0
|
121 |
TStreamId streamId=stream.CreateLC(*iStore);
|
sl@0
|
122 |
stream<< *iStreamDictionary;
|
sl@0
|
123 |
stream.CommitL();
|
sl@0
|
124 |
CleanupStack::PopAndDestroy(); // dictionary stream
|
sl@0
|
125 |
iStore->SetRootL(streamId);
|
sl@0
|
126 |
iStore->CommitL();
|
sl@0
|
127 |
}
|