|
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: This class provides the functions to manipulate the podcast collection |
|
15 * database. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef MPXPODCASTDBHANDLER_H |
|
21 #define MPXPODCASTDBHANDLER_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <f32file.h> |
|
26 |
|
27 #include <mpxattribute.h> |
|
28 #include <mpxmediageneraldefs.h> |
|
29 #include <mpxpodcastdefs.h> |
|
30 |
|
31 #include "mpxdbcommonstd.h" |
|
32 |
|
33 #include "mpxpodcastcollectiondbstd.h" |
|
34 #include "mpxpodcastcollectiondb.hrh" |
|
35 #include "mpxdbpodcast.h" // For MMPXDbPodcastObserver |
|
36 #include "mpxdbactivetask.h" |
|
37 |
|
38 // FORWARD DECLARATIONS |
|
39 class CMPXMedia; |
|
40 class CMPXMediaArray; |
|
41 |
|
42 class CMPXPodcastDbManager; |
|
43 class CMPXDbCategory; |
|
44 class CMPXDbAuxiliary; |
|
45 |
|
46 // CLASS DECLARATION |
|
47 |
|
48 /** |
|
49 * Podcast collection database handler |
|
50 * |
|
51 * @lib mpxpodcastdbplugin.lib |
|
52 */ |
|
53 class CMPXPodcastDbHandler : |
|
54 public CBase, |
|
55 public MMPXDbPodcastObserver |
|
56 { |
|
57 public: // Constructors and destructor |
|
58 |
|
59 /** |
|
60 * Two-phased constructor. |
|
61 * @param aFs file server session |
|
62 * @return New CMPXPodcastDbHandler instance |
|
63 */ |
|
64 static CMPXPodcastDbHandler* NewL(RFs& aFs, CMPXResource& aResource); |
|
65 |
|
66 /** |
|
67 * Two-phased constructor. |
|
68 * @param aFs file server session |
|
69 * @return New CMPXPodcastDbHandler instance |
|
70 */ |
|
71 static CMPXPodcastDbHandler* NewLC(RFs& aFs, CMPXResource& aResource); |
|
72 |
|
73 /** |
|
74 * Destructor. |
|
75 */ |
|
76 virtual ~CMPXPodcastDbHandler(); |
|
77 |
|
78 public: |
|
79 |
|
80 /** |
|
81 * Add a episode to the podcast collection database |
|
82 * @param aMedia media object which contains file path, |
|
83 * author, name(title), episode no., etc... |
|
84 * @return TUint32 id of the item added |
|
85 */ |
|
86 TUint32 AddEpisodeL(const CMPXMedia& aMedia); |
|
87 |
|
88 /** |
|
89 * Update episode info for a episode in the podcast collection database |
|
90 * @param aMedia episode details object which contains file path, |
|
91 * author, name(title), episode no., etc... |
|
92 * @param aMessageArray resulted change events |
|
93 * @return ETrue if the change is UI visible |
|
94 */ |
|
95 CMPXDbActiveTask::TChangeVisibility UpdateEpisodeL(const CMPXMedia& aMedia, CMPXMessageArray& aMessageArray); |
|
96 |
|
97 /** |
|
98 * Remove all episodes within podcast collection database |
|
99 */ |
|
100 void RemoveEntireCollectionL(); |
|
101 |
|
102 /** |
|
103 * Remove a episode from the podcast collection database |
|
104 * @param aEpisodeId ID of the episode to be removed |
|
105 * @param aUriArray a descriptor array to contain the URI of the deleted file |
|
106 * @param aMessageArray a list of change events as a result of the |
|
107 * episode removal |
|
108 * @param aDeleteRecord indicates whether the client has explictly requested |
|
109 * to delete the records from the database. If ETrue, records |
|
110 * associated with the media will be deleted from the database; |
|
111 * if EFalse, whether to mark the records as deleted or to delete |
|
112 * the records will be based on other deciding factors. |
|
113 */ |
|
114 void RemoveEpisodeL(TUint32 aEpisodeId, CDesCArray& aUriArray, |
|
115 CMPXMessageArray& aMessageArray, TBool aDeleteRecord = EFalse); |
|
116 |
|
117 /** |
|
118 * Removes a category of episodes from the podcast collection, and its |
|
119 * corresponding category in the lookup table |
|
120 * @param aCategory the category to remove |
|
121 * @param aCategoryId ID of the category to remove |
|
122 * @param aUriArray a descriptor array to contain the URI of the deleted file(s) |
|
123 * @param aMessageArray change events as result of the episode removal |
|
124 */ |
|
125 void RemoveEpisodesMatchingCategoryL(TMPXGeneralCategory aCategory, |
|
126 TUint32 aCategoryId, CDesCArray& aUriArray, CMPXMessageArray& aMessageArray); |
|
127 |
|
128 /** |
|
129 * Removes a publish date category of episodes from the podcast collection |
|
130 * @param aCategoryId the publish date cateogry to remove |
|
131 * @param aUriArray a descriptor array to contain the URI of the deleted file(s) |
|
132 * @param aMessageArray change events as result of the episode removal |
|
133 */ |
|
134 void RemoveEpisodesMatchingPublishDateCategoryL(TUint32 aCategoryId, |
|
135 CDesCArray& aUriArray, CMPXMessageArray& aMessageArray); |
|
136 |
|
137 /** |
|
138 * Delete records in all databases which have been marked as deleted |
|
139 */ |
|
140 void CleanupDeletedRecordsL(); |
|
141 |
|
142 /** |
|
143 * Get all episodes from the podcast collection databasee |
|
144 * @param aAttrs Array of attributes to @return |
|
145 * @param aMediaArray Array to place all the episodes' required info |
|
146 */ |
|
147 void GetAllEpisodesL(const TArray<TMPXAttribute>& aAttrs, |
|
148 CMPXMediaArray& aMediaArray); |
|
149 |
|
150 /** |
|
151 * Get all the episodes that match the given title ID |
|
152 * @param aTitleId ID of the title to match |
|
153 * @param aAttrs Array of attributes to return |
|
154 * @param aMediaArray Array to place all the matching episodes' required info |
|
155 */ |
|
156 void GetEpisodesMatchingTitleL(TUint aTitleId, |
|
157 const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray); |
|
158 |
|
159 /** |
|
160 * Get all the episodes that match the given playlist ID. |
|
161 * Podcast collection only support Recently Added and Not Yet Played |
|
162 * auto playlists. |
|
163 * @param aPlaylistId ID of the playlist to match |
|
164 * @param aAttrs Array of attributes to return |
|
165 * @param aMediaArray Array to place all the required episode info |
|
166 * @param aIndexOfCurrentlyPlayingItem index of the currently playing |
|
167 * episode or KErrNotFound (-1) if no currently playing episode within |
|
168 * this playlist |
|
169 */ |
|
170 void GetEpisodesMatchingPlaylistL(TUint aPlaylistId, |
|
171 const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray, |
|
172 TInt& aIndexOfCurrentlyPlayingItem); |
|
173 |
|
174 /** |
|
175 * Get the episode info that matches the given episode ID |
|
176 * @param aEpisodeId ID of the episode |
|
177 * @param aAttrs Array of attributes to return |
|
178 * @param aMediaArray Array to place all the required episode info |
|
179 */ |
|
180 void GetEpisodeL(TUint32 aEpisodeId, const TArray<TMPXAttribute>& aAttrs, |
|
181 CMPXMediaArray& aMediaArray); |
|
182 |
|
183 /** |
|
184 * Get the episode info that matches the given episode ID |
|
185 * @aEpisodeId ID of the episode |
|
186 * @param aAttrs Array of attributes to return |
|
187 * @param aMedia CMPXMedia instance to place all the required song info |
|
188 */ |
|
189 void GetEpisodeL(TUint32 aEpisodeId, const TArray<TMPXAttribute>& aAttrs, |
|
190 CMPXMedia& aMedia); |
|
191 |
|
192 /** |
|
193 * Get the episode ID of the episode that matches the given URI |
|
194 * @param aUri URI to match |
|
195 * @return Episode ID |
|
196 */ |
|
197 TUint32 GetEpisodeIdMatchingUriL(const TDesC& aUri); |
|
198 |
|
199 /** |
|
200 * Get all the podcast title names from the podcast collection database |
|
201 * @param aAttrs Array of attributes to return |
|
202 * @param aMediaArray Array to place all the titles required info |
|
203 */ |
|
204 void GetAllPodcastTitlesL(const TArray<TMPXAttribute>& aAttrs, |
|
205 CMPXMediaArray& aMediaArray); |
|
206 |
|
207 /** |
|
208 * Get all episodes matching the specified publish date |
|
209 * @param aPlaylistId the publish date playlist to retrieve |
|
210 * @param aAttrs the attributes to return |
|
211 * @param aPendingCategoryDeletionFlag true if the episodes within a publish |
|
212 * date category are being retrieved to be deleted |
|
213 * @param aMediaArray Array to place all the episode info |
|
214 */ |
|
215 TInt GetEpisodesMatchingPublishPlaylistL(TUint aPlaylistId, |
|
216 const TArray<TMPXAttribute>& aAttrs, TBool aPendingCategoryDeletionFlag, |
|
217 CMPXMediaArray& aMediaArray); |
|
218 |
|
219 /** |
|
220 * Get title name using the specified ID |
|
221 * @param aId the id of the title to retrieve the name of |
|
222 * @return the podcast title matching the specified ID, ownership is transferred |
|
223 */ |
|
224 HBufC* GetTitleNameMatchingIdL(const TUint32 aId); |
|
225 |
|
226 /** |
|
227 * Get URI from the Id |
|
228 * @param aId to search for |
|
229 * @return URI matching the ID, ownership is transferred |
|
230 */ |
|
231 HBufC* GetUriMatchingIdL (const TUint32 aId); |
|
232 |
|
233 /** |
|
234 * Get the duration for all episodes |
|
235 * @return duration value |
|
236 */ |
|
237 TInt GetAllEpisodesDurationL(); |
|
238 |
|
239 /** |
|
240 * Get the duration for a specified title |
|
241 * @param aTitleId identifies the title |
|
242 * @return duration value |
|
243 */ |
|
244 TInt GetTitleDurationL(TUint32 aTitleId); |
|
245 |
|
246 /** |
|
247 * Get the duration for the episodes not yet played |
|
248 * @return duration value |
|
249 */ |
|
250 TInt GetNotPlayedDurationL(); |
|
251 |
|
252 /** |
|
253 * Get the duration for recently added episodes |
|
254 * @return duration value |
|
255 */ |
|
256 TInt GetRecentlyAddedDurationL(); |
|
257 |
|
258 /** |
|
259 * Fetch the total number of items in the specified category |
|
260 * @param aCategory category to be queried |
|
261 * @return number of items. |
|
262 */ |
|
263 TInt NumberOfItemsL(TMPXPodcastCategory aCategory); |
|
264 |
|
265 /** |
|
266 * Find media(s) from the collection |
|
267 * @param aCriteria selection criteria |
|
268 * @param aAttrs attributes for the matching media |
|
269 * @return matching media. Ownership is transferred. |
|
270 */ |
|
271 CMPXMedia* FindAllLC(const CMPXMedia& aCriteria, |
|
272 const TArray<TMPXAttribute>& aAttrs); |
|
273 |
|
274 /** |
|
275 * Set the last refreshed time |
|
276 * @param aTime the updated last refresh time |
|
277 */ |
|
278 void SetLastRefreshedTimeL( TTime aTime ); |
|
279 |
|
280 /** |
|
281 * Get the last refreshed time |
|
282 * @return last refreshed time |
|
283 */ |
|
284 TTime GetLastRefreshedTimeL(); |
|
285 |
|
286 /** |
|
287 * Set the db corrupted bit in the aux table for all drives |
|
288 * @param aCorrupted flag indicating whether or not the db is corrupted |
|
289 */ |
|
290 void SetDBCorruptedL(TBool aCorrupted); |
|
291 |
|
292 /** |
|
293 * Get the db corrupted flag |
|
294 * @return ETrue if database is corrupted, else EFalse |
|
295 */ |
|
296 TBool IsDBCorruptedL(); |
|
297 |
|
298 /** |
|
299 * Checks if the database has been created |
|
300 * @return ETrue if file has been created |
|
301 */ |
|
302 TBool DatabaseCreated(); |
|
303 |
|
304 /** |
|
305 * Close and re-open the podcast collection database stored on the specified drive |
|
306 * @param aDrive drive containing the podcast collection database to re-open |
|
307 */ |
|
308 void OpenDatabaseL(TInt aDrive); |
|
309 |
|
310 /** |
|
311 * Close a database for a particular drive |
|
312 * @param aDrive drive to close |
|
313 */ |
|
314 void CloseDatabaseL(TInt aDrive); |
|
315 |
|
316 /** |
|
317 * Recreate all podcast databases |
|
318 */ |
|
319 void ReCreateDatabasesL(); |
|
320 |
|
321 /** |
|
322 * Start a refresh operation |
|
323 */ |
|
324 void RefreshStartL(); |
|
325 |
|
326 /** |
|
327 * End a refresh operation |
|
328 */ |
|
329 void RefreshEndL(); |
|
330 |
|
331 /** |
|
332 * Sets the value of the IsPlaying field for a given episode |
|
333 * @param aMedia contains episode information |
|
334 * @param aIsPlaying value of the IsPlaying field |
|
335 */ |
|
336 void SetIsPlayingL(const CMPXMedia& aMedia, TBool aIsPlaying); |
|
337 |
|
338 /** |
|
339 * Get total record count for podcasts in db |
|
340 * @param aDrive, specifies drive number for db selection |
|
341 * @return count |
|
342 */ |
|
343 TUint GetTotalCountL(TInt aDrive); |
|
344 |
|
345 /** |
|
346 * Get URIs for all podcasts |
|
347 * @param aDrive, specifies drive number for db selection |
|
348 * @param aFromID, specifies last record's unique ID |
|
349 * @param aRecords, specifies the number of records to get |
|
350 * @param aUriArr, will contain all URIs on return |
|
351 * @param aLastID, will contain a unique ID of last record in the array |
|
352 */ |
|
353 void GetPodcastUriArrayL(TInt aDrive, TInt aFromID, TInt aRecords, |
|
354 CDesCArray& aUriArr, TInt& aLastID); |
|
355 |
|
356 /** |
|
357 * Starts a transaction |
|
358 */ |
|
359 void BeginTransactionL(); |
|
360 |
|
361 /** |
|
362 * Ends a transaction. Depending on the error code either commits or |
|
363 * rollsback the transaction. |
|
364 * @param aError error code |
|
365 */ |
|
366 void EndTransactionL(TInt aError); |
|
367 |
|
368 /** |
|
369 * Checks if the database is currently in a transaction. |
|
370 * @return ETrue if database is currently in a transaction, EFalse otherwise |
|
371 */ |
|
372 TBool InTransaction(); |
|
373 |
|
374 /** |
|
375 * Checks if the spefified drive is a remove drive |
|
376 */ |
|
377 TBool IsRemoteDrive(TDriveNumber aDrive); |
|
378 |
|
379 private: |
|
380 |
|
381 /** |
|
382 * Find media entry/entries from the collection |
|
383 * @param aCriteria selection criteria |
|
384 * @param aAttrs attributes for the matching media |
|
385 * @param aMediaArray array of matching media entry/entries |
|
386 */ |
|
387 void FindAllL(const CMPXMedia& aCriteria, const TArray<TMPXAttribute>& aAttrs, |
|
388 CMPXMediaArray& aMediaArray); |
|
389 |
|
390 /** |
|
391 * Find episode(s) which match(es) the selection criteria |
|
392 * @param aCriteria selection criteria |
|
393 * @param aAttrs the attributes to include for the artist(s) matching the |
|
394 * selection criteria |
|
395 * @param aMediaArray artist(s) matching the selection criteria |
|
396 */ |
|
397 void FindEpisodesL(const CMPXMedia& aCriteria, const TArray<TMPXAttribute>& aAttrs, |
|
398 CMPXMediaArray& aMediaArray); |
|
399 |
|
400 /** |
|
401 * Add an episode to the podcast collection database |
|
402 * @param aMedia media object which contains file path, author, name, podcast title etc... |
|
403 * @return episode Id of the episode that has been added to the database |
|
404 */ |
|
405 TUint32 DoAddEpisodeL(const CMPXMedia& aMedia); |
|
406 |
|
407 /** |
|
408 * Update episode info for a episode in the podcast collection database |
|
409 * @param aMedia episode details object which contains file path, |
|
410 * author, name(title), podcast title, etc... |
|
411 * @param aItemChangedMessages a list of items changed |
|
412 * @return ETrue if UI visible change |
|
413 */ |
|
414 CMPXDbActiveTask::TChangeVisibility DoUpdateEpisodeL(const CMPXMedia& aMedia, |
|
415 CMPXMessageArray& aItemChangedMessages); |
|
416 |
|
417 /** |
|
418 * Remove a episode from the podcast collection database |
|
419 * @param aEpisodeId ID of the episode to be removed |
|
420 * @param aUriArray a descriptor array to contain the URI of the deleted file |
|
421 * @param aMessageArray change events as result of the episode removal |
|
422 * @param aDeleteRecord if ETrue the episode will be deleted, if EFalse |
|
423 * it will be marked as deleted |
|
424 */ |
|
425 void DoRemoveEpisodeL(TUint32 aEpisodeId, CDesCArray& aUriArray, |
|
426 CMPXMessageArray& aMessageArray, TBool aDeleteRecord); |
|
427 |
|
428 /** |
|
429 * Remove the episodes for a category from the podcast collection database |
|
430 * @param aCategory category type |
|
431 * @param aCategoryId category item |
|
432 * @param aUriArray a descriptor array to contain the URI of the deleted file |
|
433 * @param aMessageArray change events as result of the episode removal |
|
434 */ |
|
435 void DoRemoveEpisodesMatchingCategoryL(TMPXGeneralCategory aCategory, |
|
436 TUint32 aCategoryId, CDesCArray& aUriArray, CMPXMessageArray& aMessageArray); |
|
437 |
|
438 /** |
|
439 * Remove the episodes for a publish date category |
|
440 * @param aCategoryId identifies the publish date category |
|
441 * @param aUriArray a descriptor array to contain the URI of the deleted file |
|
442 * @param aMessageArray change events as result of the episode removal |
|
443 */ |
|
444 void DoRemoveEpisodesMatchingPublishDateCategoryL(TUint32 aCategoryId, |
|
445 CDesCArray& aUriArray, CMPXMessageArray& aMessageArray); |
|
446 |
|
447 /** |
|
448 * Delete records in all databases which have been marked as deleted |
|
449 */ |
|
450 void DoCleanupDeletedRecordsL(); |
|
451 |
|
452 /** |
|
453 * Makes sure all the folders specified in the array parameter are created, |
|
454 * otherwise it tries to create them. Updates the iDbDrives member variable |
|
455 * with the drives corresponding to the folders. |
|
456 * @param aFolders contains all the folders to be processed |
|
457 */ |
|
458 void ProcessPodcastFoldersL(const CDesCArray& aFolders); |
|
459 |
|
460 /** |
|
461 * Returns the CMPXDbCategory instance associated with the specified |
|
462 * category type |
|
463 * @param aCategory category type |
|
464 * @return corresponding CMPXDbCategory instance |
|
465 * @leave KErrNotSupported if invalid category |
|
466 */ |
|
467 CMPXDbCategory* DbCategoryL(TMPXGeneralCategory aCategory) const; |
|
468 |
|
469 /** |
|
470 * Verify the volume id for the databases |
|
471 */ |
|
472 void VerifyVolumeIdL(); |
|
473 |
|
474 /** |
|
475 * Checks if there is a drive that has a low disk space |
|
476 * @leave KErrDiskFull if the space on one of the drives is below the |
|
477 * critical level |
|
478 */ |
|
479 void CheckDiskSpaceOnDrivesL(); |
|
480 |
|
481 #if defined (__MTP_PROTOCOL_SUPPORT) |
|
482 /** |
|
483 * Reads the "save deleted records" MTP flag from CenRep and returns |
|
484 * the value. |
|
485 * @return value of the "save deleted records" MTP flag |
|
486 */ |
|
487 TBool SaveDeletedSongs(); |
|
488 #endif |
|
489 |
|
490 #ifdef RD_MULTIPLE_DRIVE |
|
491 /** |
|
492 * Retrieve all visible podcast folder locations |
|
493 */ |
|
494 CDesCArrayFlat* GetPodcastFoldersL(); |
|
495 #endif // RD_MULTIPLE_DRIVE |
|
496 |
|
497 private: // From MMPXDbPodcastObserver |
|
498 |
|
499 /** |
|
500 * @see MMPXDbPodcastObserver |
|
501 */ |
|
502 TUint32 AddCategoryItemL(TMPXGeneralCategory aCategory, const TDesC& aName, |
|
503 TInt aDriveId, CMPXMessageArray* aItemChangedMessages); |
|
504 |
|
505 /** |
|
506 * @see MMPXDbPodcastObserver |
|
507 */ |
|
508 void DeleteEpisodeForCategoryL(TMPXGeneralCategory aCategory, TUint32 aCategoryId, |
|
509 TInt aDriveId, CMPXMessageArray* aItemChangedMessages); |
|
510 |
|
511 private: |
|
512 /** |
|
513 * C++ constructor |
|
514 * @param file session |
|
515 */ |
|
516 CMPXPodcastDbHandler(RFs& aFs, CMPXResource& aResource); |
|
517 |
|
518 /** |
|
519 * Symbian 2nd phase constructor.. |
|
520 */ |
|
521 void ConstructL(); |
|
522 |
|
523 private: // Data |
|
524 |
|
525 // owned member variables |
|
526 CMPXPodcastDbManager* iDbManager; |
|
527 CMPXDbPodcast* iDbPodcast; |
|
528 CMPXDbCategory* iDbArtist; |
|
529 CMPXDbCategory* iDbAlbum; |
|
530 CMPXDbCategory* iDbGenre; |
|
531 CMPXDbCategory* iDbComposer; |
|
532 CMPXDbAuxiliary* iDbAuxiliary; |
|
533 |
|
534 CDesCArrayFlat* iPodcastPublishDateCat; // podcast publish date category |
|
535 RArray<TInt> iPodcastPublishDateIds; // podcast publish date ID |
|
536 RArray<TInt> iDbDrives; |
|
537 |
|
538 // not owned member variables |
|
539 RFs& iFs; |
|
540 CMPXResource& iResource; |
|
541 TBool iOutOfDisk; // Are we in out of disk mode? |
|
542 }; |
|
543 |
|
544 #endif // MPXPODCASTDBHANDLER_H |
|
545 |
|
546 // End of File |