First public contribution.
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "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.
20 #include <caf/supplieroutputfile.h>
22 #include <caf/caftypes.h>
26 #include <caf/attribute.h>
27 #include <caf/content.h>
28 #include <caf/bitset.h>
32 using namespace ContentAccess;
35 EXPORT_C CSupplierOutputFile* CSupplierOutputFile::NewL(const TDesC& aFileName, const TOutputType aOutputType)
37 return CSupplierOutputFile::NewL(aFileName, aOutputType, KNullDesC8());
41 EXPORT_C CSupplierOutputFile* CSupplierOutputFile::NewL(const TDesC& aFileName, const TOutputType aOutputType, const TDesC8& aMimeType)
43 CSupplierOutputFile *self = new (ELeave) CSupplierOutputFile();
44 CleanupStack::PushL(self);
45 self->ConstructL(aFileName, aMimeType, aOutputType);
46 CleanupStack::Pop(self);
50 EXPORT_C CSupplierOutputFile* CSupplierOutputFile::NewL(RReadStream& aStream)
52 CSupplierOutputFile *self = new (ELeave) CSupplierOutputFile();
53 CleanupStack::PushL(self);
54 self->InternalizeL(aStream);
55 CleanupStack::Pop(self);
59 CSupplierOutputFile::CSupplierOutputFile()
64 void CSupplierOutputFile::ConstructL(const TDesC& aFileName, const TDesC8& aMimeType, const TOutputType aOutputType)
66 iOutputType = aOutputType;
68 CAgentResolver *resolver = CAgentResolver::NewL(EFalse);
69 CleanupStack::PushL(resolver);
70 iFileName = resolver->ConvertAgentFileNameL(aFileName);
71 CleanupStack::PopAndDestroy(resolver);
72 iMimeType.Copy(aMimeType);
74 // convert mime type to lower case
75 iMimeType.LowerCase();
79 CSupplierOutputFile::~CSupplierOutputFile()
88 EXPORT_C TPtrC CSupplierOutputFile::FileName() const
93 EXPORT_C TOutputType CSupplierOutputFile::OutputType() const
98 EXPORT_C TPtrC8 CSupplierOutputFile::MimeTypeL()
102 RApaLsSession apparcSession;
104 if(iMimeType.Length() == 0)
106 // Use the Application Architecture Server to find the Mime type of the output File
107 User::LeaveIfError(apparcSession.Connect());
108 CleanupClosePushL(apparcSession);
110 // Use a temp FS session to preserve platsec
112 User::LeaveIfError(tempFsSession.Connect());
113 CleanupClosePushL(tempFsSession);
114 User::LeaveIfError(tempFsSession.ShareProtected());
116 // Open file here and send the handle because AppArc doesn't have Allfiles capability
117 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
118 // If file size is greater than 2GB than RFile::Open will fail with KErrTooBig.
123 #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
124 User::LeaveIfError(tempFile.Open(tempFsSession, *iFileName, EFileRead|EFileShareAny));
125 CleanupClosePushL(tempFile);
127 User::LeaveIfError(apparcSession.AppForDocument(tempFile, uid, dataType));
129 iMimeType.Copy(dataType.Des8().Left(KMaxDataTypeLength));
131 CleanupStack::PopAndDestroy(&tempFile); // close
132 CleanupStack::PopAndDestroy(&tempFsSession); // close
133 CleanupStack::PopAndDestroy(&apparcSession); // close
139 EXPORT_C void CSupplierOutputFile::ExternalizeL(RWriteStream& aStream) const
141 aStream.WriteInt32L(static_cast <TInt> (iOutputType));
142 aStream.WriteInt32L(iFileName->Des().Length());
143 aStream.WriteL(*iFileName);
144 aStream.WriteInt32L(iMimeType.Length());
145 aStream.WriteL(iMimeType);
148 void CSupplierOutputFile::InternalizeL(RReadStream& aStream)
151 iOutputType = static_cast <TOutputType> (aStream.ReadInt32L());
152 length = aStream.ReadInt32L();
153 iFileName = HBufC::NewL(length);
156 TPtr filename = iFileName->Des();
157 aStream.ReadL(filename, length);
159 length = aStream.ReadInt32L();
160 aStream.ReadL(iMimeType, length);
166 EXPORT_C CAttribute & CSupplierOutputFile::AttributesL (TBool aPreloaded)
168 // retrieve the attributes, only need to do this once since this instance
169 // will only ever refer to one output file
172 // create a content consumer interface for the output file produced
173 CContent* content = CContent::NewLC(FileName());
174 iAttr = content->NewAttributeL(ETrue);
175 CleanupStack::PopAndDestroy(content);
177 else if(aPreloaded) // update all attribute bits
179 CBitset &bitset = iAttr->QuerySet();
185 #endif // #ifndef REMOVE_CAF1