|
1 /* |
|
2 * Copyright (c) 2006 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: Imports a m3u playlist file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef MPXM3UPLAYLISTIMPORTER_H |
|
20 #define MPXM3UPLAYLISTIMPORTER_H |
|
21 |
|
22 #include <mpxplaylistpluginobserver.h> |
|
23 #include <f32file.h> |
|
24 #include <charconv.h> |
|
25 |
|
26 |
|
27 class CMPXMediaArray; |
|
28 |
|
29 /** |
|
30 * CMPXM3uPlaylistImporter imports a m3u playlist file. Each instance can |
|
31 * only handle the import of one m3u file and the processing starts as |
|
32 * soon as the object is instantiated. |
|
33 * |
|
34 * When processing is complete, CMPXM3uPlaylistImporter will invoke |
|
35 * callback through MMPXPlaylistPluginObserver interface. Once completed, |
|
36 * the importing service cannot be restarted. A new instance is required |
|
37 * if the client wishes to import another m3u playlist file. |
|
38 */ |
|
39 class CMPXM3uPlaylistImporter : public CActive |
|
40 { |
|
41 public: // Constructors and destructor |
|
42 |
|
43 /** |
|
44 * Two-phased constructor |
|
45 * |
|
46 * @param aFs a file session handle |
|
47 * @param aObserver reference to the playlist plugin observer |
|
48 * @param aPlaylistUri URI of the playlist file to be internalized |
|
49 * @param aTopCharacterSet top character set for the current locale |
|
50 * @param aAvailableCharacterSet available character set in the system |
|
51 * @param aStatus caller's request status |
|
52 * @return object of constructed |
|
53 */ |
|
54 IMPORT_C static CMPXM3uPlaylistImporter* NewL( |
|
55 RFs* aFs, |
|
56 MMPXPlaylistPluginObserver* aObserver, |
|
57 const TDesC& aPlaylistUri, |
|
58 const CArrayFix<CCnvCharacterSetConverter::SCharacterSet>& aTopCharacterSet, |
|
59 const CArrayFix<CCnvCharacterSetConverter::SCharacterSet>& aAvailableCharacterSet, |
|
60 TRequestStatus& aStatus ); |
|
61 |
|
62 /** |
|
63 * Destructor |
|
64 */ |
|
65 IMPORT_C virtual ~CMPXM3uPlaylistImporter(); |
|
66 |
|
67 protected: |
|
68 |
|
69 /** |
|
70 * Constructor |
|
71 * |
|
72 * @param aFs a file session handle |
|
73 * @param aObserver reference to the playlist plugin observer |
|
74 * @param aTopCharacterSet top character set for the current locale |
|
75 * @param aAvailableCharacterSet available character set in the system |
|
76 * @param aStatus caller's request status |
|
77 */ |
|
78 IMPORT_C CMPXM3uPlaylistImporter( |
|
79 RFs* aFs, |
|
80 MMPXPlaylistPluginObserver* aObserver, |
|
81 const CArrayFix<CCnvCharacterSetConverter::SCharacterSet>& aTopCharacterSet, |
|
82 const CArrayFix<CCnvCharacterSetConverter::SCharacterSet>& aAvailableCharacterSet, |
|
83 TRequestStatus& aStatus ); |
|
84 |
|
85 /** |
|
86 * 2nd phase constructor |
|
87 * |
|
88 * @param aPlaylistUri URI of the playlist file to be internalized |
|
89 */ |
|
90 IMPORT_C virtual void ConstructL( const TDesC& aPlaylistUri ); |
|
91 |
|
92 /** |
|
93 * From CActive |
|
94 * Handles an active object's request completion event |
|
95 */ |
|
96 IMPORT_C virtual void RunL(); |
|
97 |
|
98 /** |
|
99 * From CActive |
|
100 * Implements cancellation of an outstanding request. |
|
101 */ |
|
102 IMPORT_C virtual void DoCancel(); |
|
103 |
|
104 /** |
|
105 * Does a step of the task |
|
106 */ |
|
107 IMPORT_C virtual void DoTaskStep(); |
|
108 |
|
109 /** |
|
110 * Does a step of the task, leave if there is an error |
|
111 */ |
|
112 IMPORT_C virtual void DoTaskStepL(); |
|
113 |
|
114 private: |
|
115 |
|
116 /** |
|
117 * Reads data from playlist file to the buffer |
|
118 */ |
|
119 void ReadPlaylistFileToBufferL(); |
|
120 |
|
121 /** |
|
122 * Auto detects the character encoding from the supplied character |
|
123 * set |
|
124 * @param aSample a sample of the file |
|
125 * @param aCharSetId auto-detected character set for the supplied |
|
126 * sample |
|
127 * @param aCharacterSet a character set to detect the encoding from |
|
128 * @return KErrNone if a character set is found; otherwise |
|
129 * KErrNotFound. |
|
130 */ |
|
131 TInt DetectCharacterSetL( |
|
132 const TDesC8& aSample, |
|
133 const CArrayFix<CCnvCharacterSetConverter::SCharacterSet>& aCharacterSet, |
|
134 TUint& aCharSetId); |
|
135 |
|
136 /** |
|
137 * Parses the buffer where playlist file was read to. |
|
138 */ |
|
139 void ParsePlaylistBufferL( |
|
140 CMPXMediaArray& aPlaylist, |
|
141 TInt& aInvalidItemCount); |
|
142 |
|
143 /** |
|
144 * Reads next line from iBuffer and stores it to iLine. Returns EFalse |
|
145 * if there are no more new lines. |
|
146 */ |
|
147 TBool ReadNextLineL(); |
|
148 |
|
149 /** |
|
150 * Decides what to do with an iLine read from iBuffer |
|
151 */ |
|
152 void ProcessLineL( |
|
153 CMPXMediaArray& aPlaylist, |
|
154 TInt& aInvalidItemCount); |
|
155 |
|
156 /** |
|
157 * Parses path or extended info from an iLine and stores them to iItem |
|
158 */ |
|
159 TInt ParseLineL( |
|
160 CMPXMedia* aItem, |
|
161 TInt& aInvalidItemCount); |
|
162 |
|
163 /** |
|
164 * Parses and returns an absolute path if aPath is relative to playlist |
|
165 * file's path. If path is not valid or it doesn't exist, error code is |
|
166 * returned in aError. |
|
167 * |
|
168 * caller assumes ownership of the returned HBufC |
|
169 */ |
|
170 HBufC* ParseAbsolutePathLC( |
|
171 const TDesC& aPath, |
|
172 TInt& aError); |
|
173 |
|
174 /** |
|
175 * compose CMPXMedia to be sent back to the client |
|
176 */ |
|
177 void ComposePlaylistL(); |
|
178 |
|
179 /** |
|
180 * Reset data members for after completing the current request |
|
181 */ |
|
182 void Cleanup(); |
|
183 |
|
184 /** |
|
185 * Notify client of the specified error through MMPXPlaylistPluginObserver |
|
186 * interface |
|
187 */ |
|
188 void NotifyClient(TInt aError); |
|
189 |
|
190 protected: |
|
191 |
|
192 enum TMPXM3UImporterState |
|
193 { |
|
194 EMPXM3UReadBufferWithAutoDetectEncoding, |
|
195 EMPXM3UParseWithAutoDetectEncoding, |
|
196 EMPXM3UComposePlaylistMedia |
|
197 }; |
|
198 |
|
199 protected: // Data |
|
200 |
|
201 HBufC* iBuffer; |
|
202 TPtrC iBufferPtr; |
|
203 |
|
204 TPtrC iPlaylistFilePath; |
|
205 |
|
206 HBufC* iLine; |
|
207 |
|
208 RFs* iFs; // not owned |
|
209 MMPXPlaylistPluginObserver* iObserver;// not owned |
|
210 |
|
211 TBool iExtendedFormat; |
|
212 |
|
213 TRequestStatus* iCallerStatus; |
|
214 |
|
215 TInt iEndLineNumber; |
|
216 TInt iCurrentLineNumber; |
|
217 TBool iMoreToDo; |
|
218 TBool iEndOfFile; |
|
219 CMPXMedia* iItem; |
|
220 |
|
221 CMPXMediaArray* iAutoEncodingPlaylistArray; |
|
222 TInt iAutoEncodingInvalidItems; |
|
223 |
|
224 CMPXMedia* iPlaylist; |
|
225 |
|
226 TMPXM3UImporterState iState; |
|
227 |
|
228 const CArrayFix<CCnvCharacterSetConverter::SCharacterSet>& iTopCharacterSet; |
|
229 const CArrayFix<CCnvCharacterSetConverter::SCharacterSet>& iAvailableCharacterSet; |
|
230 }; |
|
231 |
|
232 #endif // MPXM3UPLAYLISTIMPORTER_H |
|
233 |
|
234 |