Update contrib.
2 * Copyright (c) 2003-2008 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.
28 #ifndef __IMPORTFILE_H__
29 #define __IMPORTFILE_H__
33 #include <caf/caftypes.h>
35 namespace ContentAccess
38 class CSupplierOutputFile;
41 class CAgentImportFile;
47 Created by the CSupplier to import a file.
49 The mime type of the file must be one of the CAF supplier mime types.
50 Applications should check using CSupplier::IsImportSupported().
52 This class creates a CAgentSupplier and uses it to import the file into the
53 content access agent who supports the given mime type.
55 This class is single use only and cannot be used to import multiple files.
56 The import process may result in one or more output files.
61 class CImportFile: public CBase
63 friend class CSupplier;
66 /** Destructor - deleting the CImportFile instance before calling WriteComplete() aborts the import operation
68 virtual ~CImportFile();
70 /** Write a block of data from a file to an agent.
72 @param aData The block of data.
73 @return The result of the write operation.
74 @return KErrNone if the data was written successfully.
75 @return KErrCANewFileHandleRequired if the agent requires the client to provide a new file handle before proceeding. The agent must save its state and continue processing when the new handle is supplied by ContinueWithNewOutputFile().
76 @return KErrCorrupt if the file does not match the format the agent is expecting.
77 @return KErrNotReady if the agent was not expecting WriteData() to be called at this point.
78 @return Otherwise one of the other CAF error codes defined in \c caferr.h or one of the
79 other system-wide error codes for any other errors.
81 IMPORT_C TInt WriteData(const TDesC8& aData);
83 /** Asynchronously write a block of data from a file to an agent.
84 Notifies the client when the write operation is complete.
85 NB: It is important that the descriptor passed to
86 aData remains in scope until the request has completed.
88 @param aData The block of data.
89 @param aStatus Asynchronous request status. On completion this will
90 contain one of the following error codes: KErrNone if the data was written successfully.
91 KErrCANewFileHandleRequired if the agent requires a new
92 file handle before proceeding - the agent must save its
93 state and continue processing when the new handle
94 is supplied by ContinueWithNewOutputFile(). KErrCorrupt
95 if the file does not match the format the agent is expecting.
96 KErrNotReady if the agent was not expecting WriteDataComplete()
97 to be called at this point. Otherwise one of the other CAF error codes
98 defined in \c caferr.h or one of the other standard system-wide
99 error codes for any other errors.
101 IMPORT_C void WriteData(const TDesC8& aData, TRequestStatus& aStatus);
103 /** Signals to the agent that the entire file has now been transferred to the agent.
105 @return The result of the write operation.
106 @return KErrNone if the data was written successfully.
107 @return KErrCANewFileHandleRequired if the agent requires the client to provide a new file handle before proceeding. The agent must save its state and continue processing when the new handle is supplied by ContinueWithNewOutputFile().
108 @return KErrCorrupt if the file does not match the format the agent is expecting.
109 @return KErrNotReady if the agent was not expecting WriteDataComplete() to be called at this point.
110 @return Otherwise one of the other CAF error codes defined in \c caferr.h or one of the
111 other system-wide error codes for any other errors.
113 IMPORT_C TInt WriteDataComplete();
116 /** Signals to the agent that the entire file has now been transferred to the agent
118 Notifies the client when any final processing operation is complete.
120 @param aStatus Asynchronous request status. On completion this will
121 contain one of the following error codes: KErrNone if the data was written successfully.
122 KErrCANewFileHandleRequired if the agent requires a new
123 file handle before proceeding - the agent must save its
124 state and continue processing when the new handle
125 is supplied by ContinueWithNewOutputFile(). KErrCorrupt
126 if the file does not match the format the agent is expecting.
127 KErrNotReady if the agent was not expecting WriteDataComplete()
128 to be called at this point. Otherwise one of the other CAF error codes
129 defined in \c caferr.h or one of the other standard system-wide
130 error codes for any other errors.
132 IMPORT_C void WriteDataComplete(TRequestStatus& aStatus);
134 /** Gets the number of output files produced so far.
135 @return The number of output files.
137 IMPORT_C TInt OutputFileCountL() const;
139 /** Return information about an output file generated by the import operation.
141 It is possible that the output file does not have the same name
142 as the one suggested at the beginning of the import. An agent may
143 need to use a particular file extension or a particular name.
145 The agent may decide not to store the output file in the output directory
146 suggested at the start of the import. eg. it may store the file in its private
149 The output files may only appear in this array after the WriteDataComplete()
150 function has been called.
152 @param aIndex The zero-based index of the file (must be less than the value returned by OutputFileCountL().
153 @return The CSupplierOutputFile for this object.
155 IMPORT_C CSupplierOutputFile& OutputFileL(TInt aIndex) const;
157 /** Retrieve the import status
159 Used to indicate non fatal problems encountered during the import operation.
160 Provides feedback to the client in case any problems are encountered.
162 The client can then decide whether or not to continue the import.
164 @return The state of the import operation.
166 IMPORT_C TImportStatus GetImportStatus() const;
168 /** Get the agents suggestion for the file extension of the output file required by the agent
170 This function should only be called when the agent has returned KErrCANewFileHandleRequired from
171 WriteData() or WriteDataComplete().
173 The extension must include the dot '.' character.
175 @param aFileExtension On completion this will contain the appropriate file extension.
176 @return The result of the request for a file extension.
177 @return KErrNone if the agent populated aFileExtension with the correct file extension.
178 @return KErrNotReady if the agent is not waiting for another file handle to be provided.
179 @return KErrUnknown if the agent does not know what extension should be used.
181 IMPORT_C TInt GetSuggestedOutputFileExtension(TDes& aFileExtension);
183 /** Get the agents suggestion for the file name (with extension) of the output file required by the agent
185 This function should only be called when the agent has returned KErrCANewFileHandleRequired from
186 WriteData() or WriteDataComplete().
188 The file name is of the form filename.extension.
190 @param aFileName On completion this will contain the appropriate file name.
191 @return KErrNone if the agent populated aFileName with the correct file name.
192 @return KErrNotReady if the agent is not waiting for another file handle to be provided.
193 @return KErrUnknown if the agent does not know what file name should be used.
195 IMPORT_C TInt GetSuggestedOutputFileName(TDes& aFileName);
197 /** Continue the last write operation with a new file handle as requested by the agent
199 @param aFile A new file handle opened with write permission.
200 @param aFileName The name of the file handle that has been supplied. This is used by the agent when creating CSupplierOutputFile objects. It should include the full path and filename in order to be consistent with files generated by the agent.
201 @return The result of the continuing write operation.
202 @return KErrNone if the WriteData() or WriteDataComplete() operation is now complete.
203 @return KErrCANewFileHandleRequired if the agent requires a new
204 file handle before proceeding - the agent must save its
205 state and continue processing when the new handle
206 is supplied by ContinueWithNewOutputFile().
207 @return Otherwise one of the other CAF error codes defined in \c caferr.h or one of the
208 other system-wide error codes for any other errors.
210 IMPORT_C TInt ContinueWithNewOutputFile(RFile& aFile, const TDesC& aFileName);
212 /** Continue the last write operation with a new file handle and return the result asynchronously.
213 NB: It is important that the handle passed to aFile and the
214 descriptor passed to aFileName remain in scope until the request has completed.
216 @param aFile A new file handle opened with write permission.
217 @param aFileName The name of the file handle that has been supplied. This is used by the agent when creating CSupplierOutputFile objects. It should include the full path and filename in order to be consistent with files generated by the agent
218 @param aStatus Asynchronous request status. On completion this will
219 contain one of the following error codes: KErrNone if the
220 WriteData() or WriteDataComplete() operation is now complete.
221 KErrCANewFileHandleRequired if the agent requires a new
222 file handle before proceeding - the agent must save its
223 state and continue processing when the new handle
224 is supplied by ContinueWithNewOutputFile(). Otherwise one of the
225 other CAF error codes defined in \c caferr.h or one of the
226 other system-wide error codes for any other errors.
228 IMPORT_C void ContinueWithNewOutputFile(RFile& aFile, const TDesC& aFileName, TRequestStatus& aStatus);
230 /** Cancel an outstanding asynchronous request to WriteData() or WriteDataComplete().
232 IMPORT_C void Cancel();
234 /** Retrieve the content MIME type based on available data
236 This function should only be called when the agent has returned KErrCANewFileHandleRequired from
243 err = import->WriteData(data);
245 // When application supplies file handles it must always check to see if
246 // the agent needs a new file handle
247 while(err == KErrCANewFileHandleRequired)
249 //We need to find out the content MIME type based on available data
250 TBuf<KMaxDataTypeLength> contentMime;
251 if(import->ContentMimeTypeL(contentMime) == KErrNone)
253 //content MIME type is discovered. Now client code could do something
254 //to determine the output location and supply the appropriate file handle
260 //content MIME type can't be determined yet. Client should decide the location for
261 //output file now,e.g. a default location
265 err = import->ContinueWithNewOutputFile(outputFileHandle, outputFileName);
266 // It is possible that the agent needs yet another file handle
267 outputFileHandle.Close(); // agent makes a copy so we don't need to keep our file handle
273 @param aContentMime On return this will contain the appropriate content MIME type.
274 @return The result of the request for a content MIME type.
275 @return ETrue if the agent populated aContentMime with the correct content MIME type.
276 @return EFalse if the agent cannot return the content MIME type (for example, there
277 is not enough data, or the content is multi-part)
279 IMPORT_C TBool ContentMimeTypeL(TDes8& aContentMime);
284 static CImportFile* NewL(TUid aAgentUid, const TDesC8& aMimeType, const CMetaDataArray& aImportMetaData, const TDesC& aOutputDirectory, const TDesC& aSuggestedFileName);
285 void ConstructL(TUid aAgentUid, const TDesC8& aMimeType, const CMetaDataArray& aImportMetaData, const TDesC& aOutputDirectory, const TDesC& aSuggestedFileName);
287 static CImportFile* NewL(TUid aAgentUid, const TDesC8& aMimeType, const CMetaDataArray& aImportMetaData);
288 void ConstructL(TUid aAgentUid, const TDesC8& aMimeType, const CMetaDataArray& aImportMetaData);
291 // Agent within CAF used to import the file
292 CAgentImportFile* iAgentImportFile;
294 // Agent factory, de-facto ECOM session handle
295 CAgentFactory* iAgentFactory;