|
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: Exports a m3u playlist file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef MPXM3UPLAYLISTEXPORTER_H |
|
20 #define MPXM3UPLAYLISTEXPORTER_H |
|
21 |
|
22 #include <f32file.h> |
|
23 #include <mpxplaylistpluginobserver.h> |
|
24 |
|
25 /** |
|
26 * CMPXM3uPlaylistExporter exports a m3u playlist file. Each instance can |
|
27 * only handle the export of one m3u file and the processing starts as |
|
28 * soon as the object is instantiated. |
|
29 * |
|
30 * When processing is complete, CMPXM3uPlaylistExporter will invoke |
|
31 * callback through MMPXPlaylistPluginObserver interface. Once completed, |
|
32 * the exporting service cannot be restarted. A new instance is required |
|
33 * if the client wishes to export another m3u playlist file. |
|
34 */ |
|
35 class CMPXM3uPlaylistExporter : public CActive |
|
36 { |
|
37 public: // Constructors and destructor |
|
38 |
|
39 /** |
|
40 * Two-phased constructor |
|
41 * |
|
42 * @param aFs a file session handle |
|
43 * @param aObserver reference to the playlist plugin observer |
|
44 * @param aPlaylist playlist to be externalized |
|
45 * @param aFilePath File path for where the playlist should be placed |
|
46 * @param aStatus caller's request status |
|
47 * @return object of constructed |
|
48 */ |
|
49 IMPORT_C static CMPXM3uPlaylistExporter* NewL( |
|
50 RFs* aFs, |
|
51 MMPXPlaylistPluginObserver* aObserver, |
|
52 const CMPXMedia& aPlaylist, |
|
53 const TDesC& aFilePath, |
|
54 TRequestStatus& aStatus ); |
|
55 |
|
56 /** |
|
57 * Destructor |
|
58 */ |
|
59 IMPORT_C virtual ~CMPXM3uPlaylistExporter(); |
|
60 |
|
61 |
|
62 protected: |
|
63 |
|
64 /** |
|
65 * Constructor |
|
66 * |
|
67 * @param aFs a file session handle |
|
68 * @param aObserver reference to the playlist plugin observer |
|
69 * @param aPlaylist playlist to be externalized |
|
70 * @param aStatus caller's request status |
|
71 * @return object of constructed |
|
72 */ |
|
73 IMPORT_C CMPXM3uPlaylistExporter( |
|
74 RFs* aFs, |
|
75 MMPXPlaylistPluginObserver* aObserver, |
|
76 const CMPXMedia& aPlaylist, |
|
77 TRequestStatus& aStatus ); |
|
78 |
|
79 /** |
|
80 * 2nd phase constructor |
|
81 * |
|
82 * @param aFilePath File path for where the playlist should be placed |
|
83 */ |
|
84 IMPORT_C virtual void ConstructL( |
|
85 const TDesC& aFilePath); |
|
86 |
|
87 /** |
|
88 * From CActive |
|
89 * Handles an active object's request completion event |
|
90 */ |
|
91 IMPORT_C virtual void RunL(); |
|
92 |
|
93 /** |
|
94 * From CActive |
|
95 * Implements cancellation of an outstanding request. |
|
96 */ |
|
97 IMPORT_C virtual void DoCancel(); |
|
98 |
|
99 /** |
|
100 * Does a step of the task |
|
101 */ |
|
102 IMPORT_C virtual void DoTaskStep(); |
|
103 |
|
104 private: |
|
105 |
|
106 /** |
|
107 * externalize a set number of the medias. This will be called until all |
|
108 * the given medias have been processed |
|
109 */ |
|
110 void ExternalizeL(); |
|
111 |
|
112 /** |
|
113 * Populates iLines with HBufC8's each representing one line of playlist |
|
114 * file. |
|
115 */ |
|
116 void PopulateLineArrayL(); |
|
117 |
|
118 /** |
|
119 * Converts iLine to 8-bit ASCII and places it to iLines array. |
|
120 */ |
|
121 void AddLineToArrayL(); |
|
122 |
|
123 /** |
|
124 * Creates a header string, which tells that the playlist is in the |
|
125 * extented m3u format, and stores it to iLine. |
|
126 */ |
|
127 void CreateHeaderLineL(); |
|
128 |
|
129 /** |
|
130 * If media has title defined, creates extented info tag containing |
|
131 * audio clip length and title. Info tag is stored to iLine. |
|
132 */ |
|
133 void CreateExtentedInfoLineL( |
|
134 const CMPXMedia& aMedia); |
|
135 |
|
136 /** |
|
137 * Creates a string containing iItem's relative or absolute path (path |
|
138 * is relative if the audio clip is stored to the same directory, or |
|
139 * it's sub-directories, as the playlist file). The stirng is stored to |
|
140 * iLine. |
|
141 */ |
|
142 void CreatePathLineL( |
|
143 const CMPXMedia& aMedia, |
|
144 const TDesC& aCurrentFolder, |
|
145 TBool aAddNewLine); |
|
146 |
|
147 /** |
|
148 * Caluculates the length of the final playlist file, creates new buffer |
|
149 * with that length, and appends all lines from iLines to it and frees |
|
150 * iLines |
|
151 */ |
|
152 void FlushLineArrayToBufferL(); |
|
153 |
|
154 /** |
|
155 * Writes playlist data from buffer to a file. |
|
156 */ |
|
157 void WritePlaylistToFileL(); |
|
158 |
|
159 /** |
|
160 * Reset data members after processing the current request. |
|
161 */ |
|
162 void Cleanup(); |
|
163 |
|
164 /** |
|
165 * Notify client of the specified error through MMPXPlaylistPluginObserver |
|
166 * interface |
|
167 */ |
|
168 void NotifyClient(TInt aError); |
|
169 |
|
170 protected: // Data |
|
171 |
|
172 const CMPXMedia& iPlaylist; |
|
173 CMPXMediaArray* iMedias; |
|
174 HBufC* iPlaylistFilePath; |
|
175 TInt iDriveNumber; |
|
176 TBool iPlaylistFileCreated; |
|
177 |
|
178 HBufC8* iPlaylistBuf; |
|
179 RPointerArray<HBufC8> iLines; |
|
180 HBufC* iLine; |
|
181 |
|
182 RFs* iFs; // not owned |
|
183 MMPXPlaylistPluginObserver* iObserver; // not owned |
|
184 |
|
185 TInt iCurrentMedia; |
|
186 TBool iMoreToDo; |
|
187 |
|
188 TRequestStatus* iCallerStatus; |
|
189 }; |
|
190 |
|
191 #endif // MPXM3UPLAYLISTIMPORTER_H |
|
192 |
|
193 |