|
1 /* |
|
2 * Copyright (c) 2008 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 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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef VCXMYVIDEOSDOWNLOADUTIL_H |
|
22 #define VCXMYVIDEOSDOWNLOADUTIL_H |
|
23 |
|
24 // INCLUDES |
|
25 |
|
26 #include <DownloadMgrClient.h> |
|
27 #include <mpxmedia.h> |
|
28 #include <vcxmyvideosdefs.h> |
|
29 #include <ipvideo/vcxconnutilengineobserver.h> |
|
30 #include "vcxmyvideostimer.h" |
|
31 |
|
32 // FORWARD DECLARATIONS |
|
33 class CVcxConnectionUtility; |
|
34 class CMediatorEventProvider; |
|
35 class RFs; |
|
36 |
|
37 // CONSTANTS |
|
38 const TInt KVcxSubDirLevels = 2; |
|
39 const TInt KVcxMaxSubDirLength = 10; |
|
40 const TInt KVcxMaxSubDirsLength = KVcxMaxSubDirLength * KVcxSubDirLevels; |
|
41 const TInt KVcxMaxItemsInDir = 100; |
|
42 |
|
43 // CLASS DECLARATION |
|
44 |
|
45 NONSHARABLE_CLASS(MVcxMyVideosDownloadUtilObserver) |
|
46 { |
|
47 public: |
|
48 /** |
|
49 * Event handler which client must implement. |
|
50 * |
|
51 * @param aDownloadId Download ID in Download Manager. |
|
52 * @param aProgress Download progress, 0-100. |
|
53 * @param aDownloaded Current file size, in bytes. |
|
54 * @param aDownloadError If download goes to failed state, this contains the reason code |
|
55 * otherwise 0. |
|
56 * @param aDownloadGlobalError if download goes to failed state, this contains the global reason |
|
57 * code, otherwise 0. |
|
58 */ |
|
59 virtual void HandleDlEvent( TVcxMyVideosDownloadState aState, |
|
60 TUint32 aDownloadId, |
|
61 TInt aProgress, |
|
62 TInt64 aDownloaded, |
|
63 TInt32 aDownloadError, |
|
64 TInt32 aDownloadGlobalError ) = 0; |
|
65 }; |
|
66 |
|
67 /** |
|
68 * Download related stuff. |
|
69 * |
|
70 * @lib mpxmyvideoscollectionplugin.dll |
|
71 */ |
|
72 NONSHARABLE_CLASS(CVcxMyVideosDownloadUtil) : |
|
73 public CBase, |
|
74 public MHttpDownloadMgrObserver, |
|
75 public MVcxMyVideosTimerObserver, |
|
76 public MConnUtilEngineObserver |
|
77 { |
|
78 public: // Constructors and destructor |
|
79 |
|
80 /** |
|
81 * Two-phased constructor |
|
82 * @param aObserver Observer |
|
83 * @param aFs File server session. |
|
84 * @return Object constructed |
|
85 */ |
|
86 static CVcxMyVideosDownloadUtil* NewL ( MVcxMyVideosDownloadUtilObserver& aObserver, RFs& aFs ); |
|
87 |
|
88 /** |
|
89 * Destructor |
|
90 */ |
|
91 virtual ~CVcxMyVideosDownloadUtil(); |
|
92 |
|
93 public: |
|
94 /** |
|
95 * Starts download. New download ID is written to aDownload. If KVcxMediaMyVideosDownloadId |
|
96 * != 0, then the existing download is resumed. |
|
97 * |
|
98 * @param aDownload download parameters |
|
99 */ |
|
100 void StartDownloadL( CMPXMedia& aDownload ); |
|
101 |
|
102 /** |
|
103 * Pauses download. |
|
104 * |
|
105 * @param aDownloadId Download ID. |
|
106 * @return System-wide error code. |
|
107 */ |
|
108 TInt PauseDownload( TUint32 aDownloadId ); |
|
109 |
|
110 /** |
|
111 * Returns download by download ID. Ownership is not moved. |
|
112 * |
|
113 * @param aDownloadId Download ID. |
|
114 * @return Download, or NULL if not found. |
|
115 */ |
|
116 RHttpDownload* Download( TUint32 aDownloadId ); |
|
117 |
|
118 /** |
|
119 * Returns download which has aFileName as EDlAttrDestFilename. |
|
120 * Ownership is not moved. |
|
121 * |
|
122 * @param aFileName Filename. |
|
123 * @return Download, or NULL if not found. |
|
124 */ |
|
125 RHttpDownload* Download( const TDesC& aFileName ); |
|
126 |
|
127 /** |
|
128 * Returns array to downloads. |
|
129 */ |
|
130 const CDownloadArray& Downloads(); |
|
131 |
|
132 /** |
|
133 * Deletes download from download manager using download id. |
|
134 * |
|
135 * @param aDeleteContent If ETrue, then content is deleted also. |
|
136 * @return System-wide error code. |
|
137 */ |
|
138 TInt CancelDownload( TInt32 aId, TBool aDeleteContent ); |
|
139 |
|
140 /** |
|
141 * Gets MPX/MDS version of the download state. |
|
142 * |
|
143 * @param aDownload Download whose state is fetched. |
|
144 * @param aDownloadState On completion, the download state is written here. |
|
145 */ |
|
146 void GetDownloadState( |
|
147 RHttpDownload& aDownload, |
|
148 TVcxMyVideosDownloadState& aDownloadState ); |
|
149 |
|
150 /** |
|
151 * Returns download state. |
|
152 * |
|
153 * @param aDownload Download |
|
154 * @param aDownloaded How much the file has been downloaded in bytes. |
|
155 * @param aAllowSilentReset if ETrue, silent flag is set to EFalse, in |
|
156 * case dl size is not gotten ok. |
|
157 * @return Download progress, in percentages. |
|
158 */ |
|
159 TInt8 DownloadProgress( RHttpDownload& aDownload, TUint64& aDownloaded, |
|
160 TBool aAllowSilentReset ); |
|
161 |
|
162 |
|
163 /** |
|
164 * Checks that every download item in Download Manager has corresponding |
|
165 * object in MPX/MDS (= aVideoList), if not, deletes the download. |
|
166 */ |
|
167 void ClearOrphanDownloadsL( CMPXMedia& aVideoList ); |
|
168 |
|
169 /** |
|
170 * Deletes download asynchronously. |
|
171 * |
|
172 * @param aDownloadId Download to delete. |
|
173 * @param aDeleteContent If ETrue, then the content file is also deleted. |
|
174 */ |
|
175 void DeleteDownloadAsync( TInt32 aDownloadId, TBool aDeleteContent ); |
|
176 |
|
177 /** |
|
178 * Creates path and filename for the new video download. |
|
179 * |
|
180 * @return The path. |
|
181 */ |
|
182 HBufC* CreateFilePathL( const CMPXMedia& aMedia ); |
|
183 |
|
184 /** |
|
185 * Notify via mediator, that one download has finished succesfully. |
|
186 * |
|
187 * @param aMsg Buffer that contains the data that is sent with event. |
|
188 */ |
|
189 void NotifyDownloadCompleted( const TDesC8& aMsg ); |
|
190 |
|
191 /** |
|
192 * Notify via mediator, that count of new videos has decreased. |
|
193 * |
|
194 * @param aMsg Buffer that constains the data that is sent with event. |
|
195 */ |
|
196 void NotifyNewVideosCountDecreased( const TDesC8& aMsg ); |
|
197 |
|
198 public: // From MHttpDownloadMgrObserver |
|
199 |
|
200 /** |
|
201 * Handler function for download events. |
|
202 * |
|
203 * @param aDownload download |
|
204 * @aEvent aEvent event |
|
205 */ |
|
206 void HandleDMgrEventL( RHttpDownload& aDownload, THttpDownloadEvent aEvent ); |
|
207 |
|
208 public: // from MConnUtilEngineObserver |
|
209 |
|
210 /** |
|
211 * Roaming request from connectioutility. |
|
212 * Download utility decides whether it allows |
|
213 * iap roaming and returns true or false based on decision. |
|
214 * |
|
215 * @return TBool |
|
216 */ |
|
217 TBool RequestIsRoamingAllowedL(); |
|
218 |
|
219 /** |
|
220 * Iap change notification from connectiontutility |
|
221 * |
|
222 */ |
|
223 void IapChangedL(); |
|
224 |
|
225 public: // from MVcxMyVideosTimer |
|
226 /** |
|
227 * Handle timer event. |
|
228 * |
|
229 * @param aTimer pointer to timer which expired. |
|
230 */ |
|
231 void TimerExpired( CVcxMyVideosTimer* aTimer ); |
|
232 |
|
233 private: |
|
234 /** |
|
235 * Constructor |
|
236 * |
|
237 * @param aObserver Observer |
|
238 * @param aFs File server session. |
|
239 */ |
|
240 CVcxMyVideosDownloadUtil( MVcxMyVideosDownloadUtilObserver& aObserver, RFs& aFs ); |
|
241 |
|
242 /** |
|
243 * Symbian 2nd phase constructor. |
|
244 */ |
|
245 void ConstructL (); |
|
246 |
|
247 #ifdef _DEBUG |
|
248 const TDesC& GetS60DlStateDes( TInt32 aState ); |
|
249 const TDesC& GetS60DlProgressDes( TInt32 aProgress ); |
|
250 #endif |
|
251 |
|
252 /** |
|
253 * Signal via mediator event that there is ongoing downloads. |
|
254 */ |
|
255 void NotifyDownloadStarted(); |
|
256 |
|
257 /** |
|
258 * Check, is there running downloads. If not, notify via mediator |
|
259 */ |
|
260 void NotifyIfNoActiveDownloads(); |
|
261 |
|
262 /** |
|
263 * Counts active downloads. |
|
264 * @return Active download count. |
|
265 */ |
|
266 TInt32 ActiveDownloadCount(); |
|
267 |
|
268 /** |
|
269 * Creates filepath. |
|
270 * |
|
271 * @param aMedia Media item whose path is created |
|
272 * @param aPath New path is written here. |
|
273 * @param aCounter Counter value which is inserted to filename. |
|
274 */ |
|
275 void GeneratePathL( const CMPXMedia& aMedia, TDes& aPath, TInt aCounter ); |
|
276 |
|
277 /** |
|
278 * Finds a sub dir which has less than KVcxMaxItemsInDir items, if not |
|
279 * found, creates one. The result is stored to iSubDir. |
|
280 * |
|
281 * @param aPath path |
|
282 */ |
|
283 void FindSubDirL( const TDesC& aPath ); |
|
284 |
|
285 /** |
|
286 * Calculates entries from the path. |
|
287 * |
|
288 * @param aPath Path. |
|
289 * @returm Entrycount on the path. |
|
290 */ |
|
291 TInt FileCountL( const TDesC& aPath ); |
|
292 |
|
293 /** |
|
294 * Returns the drive section of the file path, |
|
295 * according to preferred cenrep setting. If drive |
|
296 * is locked or not present, the next available drive is |
|
297 * tried. If no available drives found, system drive is used. |
|
298 * Stores value to iPreferredMemoryDrivePath. |
|
299 * |
|
300 * @return The drive section of the file path. |
|
301 */ |
|
302 const TDesC& UsedMemoryDesL(); |
|
303 |
|
304 /** |
|
305 * Stops iDownloadProgressTimer. |
|
306 */ |
|
307 void StopProgressTimer(); |
|
308 |
|
309 /** |
|
310 * Starts iDownloadProgressTimer. |
|
311 */ |
|
312 void StartProgressTimer(); |
|
313 |
|
314 private: //data |
|
315 |
|
316 /** |
|
317 * S60 Download manager client object. |
|
318 */ |
|
319 RHttpDownloadMgr iDownloadManager; |
|
320 |
|
321 /** |
|
322 * Storage class for user name, used for 16->8 bit conversion. |
|
323 * This is member variable to reduce stack usage. |
|
324 */ |
|
325 TBuf8<KMaxDefAttrLength> iUserName; |
|
326 |
|
327 /** |
|
328 * Storage class for password, used for 16->8 bit conversion. |
|
329 * This is member variable to reduce stack usage. |
|
330 */ |
|
331 TBuf8<KMaxDefAttrLength> iPassword; |
|
332 |
|
333 /** |
|
334 * Storage class for url, used for 16->8 bit conversion. |
|
335 * This is member variable to reduce stack usage. |
|
336 */ |
|
337 TBuf8<KMaxUrlLength> iUrl; |
|
338 |
|
339 /** |
|
340 * Observer of this class. |
|
341 */ |
|
342 MVcxMyVideosDownloadUtilObserver& iObserver; |
|
343 |
|
344 /** |
|
345 * Used to delete download asynchronously, own. |
|
346 */ |
|
347 CVcxMyVideosTimer* iDownloadDeleteTimer; |
|
348 |
|
349 /** |
|
350 * Used to update download progresses, own. |
|
351 */ |
|
352 CVcxMyVideosTimer* iDownloadProgressTimer; |
|
353 |
|
354 /** |
|
355 * Downloads which are deleted asynchronously are stored here. |
|
356 */ |
|
357 RArray<TInt32> iDownloadsToDelete; |
|
358 |
|
359 /** |
|
360 * Delete content flags for async download delete are stored here. |
|
361 */ |
|
362 RArray<TBool> iDeleteContent; |
|
363 |
|
364 /** |
|
365 * connectionutility |
|
366 */ |
|
367 CVcxConnectionUtility* iConnUtil; |
|
368 |
|
369 /** |
|
370 * iMediatorEventProvider |
|
371 */ |
|
372 CMediatorEventProvider* iMediatorEventProvider; |
|
373 |
|
374 /** |
|
375 * IAP currently set to Download Manager. |
|
376 * is used to avoid new set if IAP is the same already. |
|
377 */ |
|
378 TUint32 iCurrentIap; |
|
379 |
|
380 /** |
|
381 * Used for storing the drive section of the path, |
|
382 * c:, e:, etc. |
|
383 */ |
|
384 TBuf<2> iUsedMemoryDrivePath; |
|
385 |
|
386 /** |
|
387 * Drive used for downloading. |
|
388 */ |
|
389 TInt iUsedDrive; |
|
390 |
|
391 /** |
|
392 * Fileserver session. |
|
393 */ |
|
394 RFs& iFs; |
|
395 |
|
396 /** |
|
397 * SubDir is stored here. |
|
398 */ |
|
399 TBuf<KVcxMaxSubDirsLength> iSubDir; |
|
400 |
|
401 /** |
|
402 * Flag that tells do we really have a roaming situation. |
|
403 */ |
|
404 TBool iRoamingOngoing; |
|
405 }; |
|
406 |
|
407 #endif // VCXMYVIDEOSDOWNLOADUTIL_H |