os/textandloc/textrendering/texthandling/sconpics/TSTCLIPB.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include "TSTCLIPB.H"
    20 #include <s32file.h>
    21 
    22 const TUid KClipboardFileUid={268435515};
    23 
    24 
    25 _LIT(KClipFilePath, "_:\\system\\clipbd\\main.sto");
    26 typedef TBuf<28> TClipboardFileName;
    27 
    28 
    29 /**
    30 Construct full path and name of clipbard file.
    31 @param aFileName On completion this will hold the result.
    32 */
    33 static void GetClipboardFileName(TClipboardFileName& aFileName)
    34 	{
    35 	aFileName.Copy(KClipFilePath);
    36 	aFileName[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive());
    37 	}
    38 
    39 
    40 
    41 EXPORT_C CClipboard* CClipboard::NewForReadingLC(RFs& aFsSession)
    42     {
    43     // get store filename
    44 	TClipboardFileName clipboardFileName;
    45 	GetClipboardFileName(clipboardFileName);
    46 
    47 	TEntry entry;
    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);
    54 	return(self);
    55 	}
    56 
    57 /**
    58 Construct a clipboard store for reading from.
    59 */
    60 void CClipboard::ConstructForReadingL(const TDesC& aFileName)
    61     {
    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
    68 	}
    69 
    70 
    71 EXPORT_C CClipboard* CClipboard::NewForWritingLC(RFs& aFsSession)
    72     {
    73     // get store filename
    74 	TClipboardFileName clipboardFileName;
    75 	GetClipboardFileName(clipboardFileName);
    76     
    77 	CClipboard* self=new(ELeave) CClipboard(aFsSession);
    78     CleanupStack::PushL(self);
    79 	self->ConstructForWritingL(clipboardFileName);
    80 	return(self);
    81 	}
    82 
    83 
    84 /**
    85 Construct a clipboard store for writing to.
    86 */
    87 void CClipboard::ConstructForWritingL(const TDesC& aFileName)
    88     {
    89 	CreateDirectoryL(aFileName);
    90 	iStore=CDirectFileStore::ReplaceL(iFsSession,aFileName,EFileRead|EFileWrite);
    91 	iStore->SetTypeL(TUidType(KDirectFileStoreLayoutUid,KClipboardFileUid));
    92 	iStreamDictionary=CStreamDictionary::NewL();
    93 	}
    94 
    95 
    96 CClipboard::CClipboard(RFs& aFsSession)
    97 	: iFsSession(aFsSession)
    98 	{
    99 	}
   100 
   101 EXPORT_C CClipboard::~CClipboard()
   102     {
   103    	delete(iStore);
   104 	delete(iStreamDictionary);
   105     }
   106 
   107 
   108 
   109 void CClipboard::CreateDirectoryL(const TDesC& aFileName)
   110 	{
   111 	TParse parser;
   112 	parser.Set(aFileName,NULL,NULL);
   113 	TInt err=iFsSession.MkDirAll(parser.DriveAndPath());
   114 	if (err!=KErrNone && err!=KErrAlreadyExists)
   115 		User::Leave(err);
   116 	}
   117 
   118 EXPORT_C void CClipboard::CommitL()
   119 	{
   120 	RStoreWriteStream stream;
   121 	TStreamId streamId=stream.CreateLC(*iStore);
   122 	stream<< *iStreamDictionary;
   123 	stream.CommitL();
   124 	CleanupStack::PopAndDestroy(); // dictionary stream
   125 	iStore->SetRootL(streamId);
   126 	iStore->CommitL();
   127 	}