sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2003-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 the License "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 |
#include <apgcli.h>
|
sl@0
|
19 |
#include <apmstd.h>
|
sl@0
|
20 |
#include <caf/supplieroutputfile.h>
|
sl@0
|
21 |
|
sl@0
|
22 |
#include <caf/caftypes.h>
|
sl@0
|
23 |
#include "resolver.h"
|
sl@0
|
24 |
|
sl@0
|
25 |
#ifndef REMOVE_CAF1
|
sl@0
|
26 |
#include <caf/attribute.h>
|
sl@0
|
27 |
#include <caf/content.h>
|
sl@0
|
28 |
#include <caf/bitset.h>
|
sl@0
|
29 |
#endif
|
sl@0
|
30 |
|
sl@0
|
31 |
|
sl@0
|
32 |
using namespace ContentAccess;
|
sl@0
|
33 |
|
sl@0
|
34 |
#ifndef REMOVE_CAF1
|
sl@0
|
35 |
EXPORT_C CSupplierOutputFile* CSupplierOutputFile::NewL(const TDesC& aFileName, const TOutputType aOutputType)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
return CSupplierOutputFile::NewL(aFileName, aOutputType, KNullDesC8());
|
sl@0
|
38 |
}
|
sl@0
|
39 |
#endif
|
sl@0
|
40 |
|
sl@0
|
41 |
EXPORT_C CSupplierOutputFile* CSupplierOutputFile::NewL(const TDesC& aFileName, const TOutputType aOutputType, const TDesC8& aMimeType)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
CSupplierOutputFile *self = new (ELeave) CSupplierOutputFile();
|
sl@0
|
44 |
CleanupStack::PushL(self);
|
sl@0
|
45 |
self->ConstructL(aFileName, aMimeType, aOutputType);
|
sl@0
|
46 |
CleanupStack::Pop(self);
|
sl@0
|
47 |
return self;
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
EXPORT_C CSupplierOutputFile* CSupplierOutputFile::NewL(RReadStream& aStream)
|
sl@0
|
51 |
{
|
sl@0
|
52 |
CSupplierOutputFile *self = new (ELeave) CSupplierOutputFile();
|
sl@0
|
53 |
CleanupStack::PushL(self);
|
sl@0
|
54 |
self->InternalizeL(aStream);
|
sl@0
|
55 |
CleanupStack::Pop(self);
|
sl@0
|
56 |
return self;
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
CSupplierOutputFile::CSupplierOutputFile()
|
sl@0
|
60 |
{
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
|
sl@0
|
64 |
void CSupplierOutputFile::ConstructL(const TDesC& aFileName, const TDesC8& aMimeType, const TOutputType aOutputType)
|
sl@0
|
65 |
{
|
sl@0
|
66 |
iOutputType = aOutputType;
|
sl@0
|
67 |
|
sl@0
|
68 |
CAgentResolver *resolver = CAgentResolver::NewL(EFalse);
|
sl@0
|
69 |
CleanupStack::PushL(resolver);
|
sl@0
|
70 |
iFileName = resolver->ConvertAgentFileNameL(aFileName);
|
sl@0
|
71 |
CleanupStack::PopAndDestroy(resolver);
|
sl@0
|
72 |
iMimeType.Copy(aMimeType);
|
sl@0
|
73 |
|
sl@0
|
74 |
// convert mime type to lower case
|
sl@0
|
75 |
iMimeType.LowerCase();
|
sl@0
|
76 |
}
|
sl@0
|
77 |
|
sl@0
|
78 |
|
sl@0
|
79 |
CSupplierOutputFile::~CSupplierOutputFile()
|
sl@0
|
80 |
{
|
sl@0
|
81 |
delete iFileName;
|
sl@0
|
82 |
#ifndef REMOVE_CAF1
|
sl@0
|
83 |
delete iAttr;
|
sl@0
|
84 |
#endif
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
|
sl@0
|
88 |
EXPORT_C TPtrC CSupplierOutputFile::FileName() const
|
sl@0
|
89 |
{
|
sl@0
|
90 |
return *iFileName;
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
EXPORT_C TOutputType CSupplierOutputFile::OutputType() const
|
sl@0
|
94 |
{
|
sl@0
|
95 |
return iOutputType;
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
EXPORT_C TPtrC8 CSupplierOutputFile::MimeTypeL()
|
sl@0
|
99 |
{
|
sl@0
|
100 |
TUid uid;
|
sl@0
|
101 |
TDataType dataType;
|
sl@0
|
102 |
RApaLsSession apparcSession;
|
sl@0
|
103 |
|
sl@0
|
104 |
if(iMimeType.Length() == 0)
|
sl@0
|
105 |
{
|
sl@0
|
106 |
// Use the Application Architecture Server to find the Mime type of the output File
|
sl@0
|
107 |
User::LeaveIfError(apparcSession.Connect());
|
sl@0
|
108 |
CleanupClosePushL(apparcSession);
|
sl@0
|
109 |
|
sl@0
|
110 |
// Use a temp FS session to preserve platsec
|
sl@0
|
111 |
RFs tempFsSession;
|
sl@0
|
112 |
User::LeaveIfError(tempFsSession.Connect());
|
sl@0
|
113 |
CleanupClosePushL(tempFsSession);
|
sl@0
|
114 |
User::LeaveIfError(tempFsSession.ShareProtected());
|
sl@0
|
115 |
|
sl@0
|
116 |
// Open file here and send the handle because AppArc doesn't have Allfiles capability
|
sl@0
|
117 |
#ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
|
sl@0
|
118 |
// If file size is greater than 2GB than RFile::Open will fail with KErrTooBig.
|
sl@0
|
119 |
// So RFile64.
|
sl@0
|
120 |
RFile64 tempFile;
|
sl@0
|
121 |
#else
|
sl@0
|
122 |
RFile tempFile;
|
sl@0
|
123 |
#endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
|
sl@0
|
124 |
User::LeaveIfError(tempFile.Open(tempFsSession, *iFileName, EFileRead|EFileShareAny));
|
sl@0
|
125 |
CleanupClosePushL(tempFile);
|
sl@0
|
126 |
|
sl@0
|
127 |
User::LeaveIfError(apparcSession.AppForDocument(tempFile, uid, dataType));
|
sl@0
|
128 |
|
sl@0
|
129 |
iMimeType.Copy(dataType.Des8().Left(KMaxDataTypeLength));
|
sl@0
|
130 |
|
sl@0
|
131 |
CleanupStack::PopAndDestroy(&tempFile); // close
|
sl@0
|
132 |
CleanupStack::PopAndDestroy(&tempFsSession); // close
|
sl@0
|
133 |
CleanupStack::PopAndDestroy(&apparcSession); // close
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
return iMimeType;
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
EXPORT_C void CSupplierOutputFile::ExternalizeL(RWriteStream& aStream) const
|
sl@0
|
140 |
{
|
sl@0
|
141 |
aStream.WriteInt32L(static_cast <TInt> (iOutputType));
|
sl@0
|
142 |
aStream.WriteInt32L(iFileName->Des().Length());
|
sl@0
|
143 |
aStream.WriteL(*iFileName);
|
sl@0
|
144 |
aStream.WriteInt32L(iMimeType.Length());
|
sl@0
|
145 |
aStream.WriteL(iMimeType);
|
sl@0
|
146 |
}
|
sl@0
|
147 |
|
sl@0
|
148 |
void CSupplierOutputFile::InternalizeL(RReadStream& aStream)
|
sl@0
|
149 |
{
|
sl@0
|
150 |
TInt length = 0;
|
sl@0
|
151 |
iOutputType = static_cast <TOutputType> (aStream.ReadInt32L());
|
sl@0
|
152 |
length = aStream.ReadInt32L();
|
sl@0
|
153 |
iFileName = HBufC::NewL(length);
|
sl@0
|
154 |
if(length)
|
sl@0
|
155 |
{
|
sl@0
|
156 |
TPtr filename = iFileName->Des();
|
sl@0
|
157 |
aStream.ReadL(filename, length);
|
sl@0
|
158 |
}
|
sl@0
|
159 |
length = aStream.ReadInt32L();
|
sl@0
|
160 |
aStream.ReadL(iMimeType, length);
|
sl@0
|
161 |
}
|
sl@0
|
162 |
|
sl@0
|
163 |
|
sl@0
|
164 |
|
sl@0
|
165 |
#ifndef REMOVE_CAF1
|
sl@0
|
166 |
EXPORT_C CAttribute & CSupplierOutputFile::AttributesL (TBool aPreloaded)
|
sl@0
|
167 |
{
|
sl@0
|
168 |
// retrieve the attributes, only need to do this once since this instance
|
sl@0
|
169 |
// will only ever refer to one output file
|
sl@0
|
170 |
if(!iAttr)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
// create a content consumer interface for the output file produced
|
sl@0
|
173 |
CContent* content = CContent::NewLC(FileName());
|
sl@0
|
174 |
iAttr = content->NewAttributeL(ETrue);
|
sl@0
|
175 |
CleanupStack::PopAndDestroy(content);
|
sl@0
|
176 |
}
|
sl@0
|
177 |
else if(aPreloaded) // update all attribute bits
|
sl@0
|
178 |
{
|
sl@0
|
179 |
CBitset &bitset = iAttr->QuerySet();
|
sl@0
|
180 |
bitset.SetAll();
|
sl@0
|
181 |
iAttr->GetL();
|
sl@0
|
182 |
}
|
sl@0
|
183 |
return *iAttr;
|
sl@0
|
184 |
}
|
sl@0
|
185 |
#endif // #ifndef REMOVE_CAF1
|