author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:28:40 +0300 | |
branch | RCL_3 |
changeset 66 | 1f1dad4af8f8 |
parent 53 | 3de6c4cf6b67 |
permissions | -rw-r--r-- |
53 | 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 is used by db plugin to add episodes into DB or |
|
15 |
* remove episodes from DB |
|
16 |
* |
|
17 |
*/ |
|
18 |
||
19 |
||
20 |
// INCLUDE FILES |
|
21 |
#include <PCRes.rsg> |
|
22 |
#include <bautils.h> |
|
23 |
#include <MetaDataUtility.h> |
|
24 |
#ifdef RD_MULTIPLE_DRIVE |
|
25 |
#include <driveinfo.h> |
|
26 |
#include <pathinfo.h> |
|
27 |
#endif //RD_MULTIPLE_DRIVE |
|
28 |
||
29 |
#include <mpxmediageneraldefs.h> |
|
30 |
#include <mpxmediacontainerdefs.h> |
|
31 |
#include <mpxmediamusicdefs.h> |
|
32 |
#include <mpxmediaaudiodefs.h> |
|
33 |
#include <mpxmedia.h> |
|
34 |
#include <mpxmediaarray.h> |
|
35 |
#include <mpxcollectionpath.h> |
|
36 |
#include <mpxlog.h> |
|
37 |
||
38 |
#include "mpxdbcommondef.h" |
|
39 |
#include "mpxresource.h" |
|
40 |
#include "mpxdbcommonutil.h" |
|
41 |
||
42 |
#include "mpxdbutil.h" |
|
43 |
#include "mpxpodcastcollectiondbdef.h" |
|
44 |
#include "mpxpodcastdbmanager.h" |
|
45 |
#include "mpxdbcategory.h" |
|
46 |
#include "mpxdbauxiliary.h" |
|
47 |
#include "mpxpodcastdbhandler.h" |
|
48 |
#include "mpxpodcastdbpluginqueries.h" |
|
49 |
||
50 |
// CONSTANTS |
|
51 |
#if defined (__MTP_PROTOCOL_SUPPORT) |
|
52 |
#include <centralrepository.h> |
|
53 |
||
54 |
const TUid KMPXMtpSettings = {0x101FFC53}; // MTP CenRep Key UID |
|
55 |
const TUint32 KMPXMtpSaveDeletedRecordFlag = 0x00000001; // MTP CenRep Key for Delete contents |
|
56 |
#endif |
|
57 |
const TInt KSqlDbCorrupted = -321; |
|
58 |
||
59 |
// ============================ MEMBER FUNCTIONS ============================== |
|
60 |
||
61 |
// ---------------------------------------------------------------------------- |
|
62 |
// Two-phased constructor. |
|
63 |
// ---------------------------------------------------------------------------- |
|
64 |
// |
|
65 |
CMPXPodcastDbHandler* CMPXPodcastDbHandler::NewL( |
|
66 |
RFs& aFs, |
|
67 |
CMPXResource& aResource) |
|
68 |
{ |
|
69 |
MPX_FUNC("CMPXPodcastDbHandler::NewL"); |
|
70 |
||
71 |
CMPXPodcastDbHandler* self = CMPXPodcastDbHandler::NewLC(aFs, aResource); |
|
72 |
CleanupStack::Pop(self); |
|
73 |
return self; |
|
74 |
} |
|
75 |
||
76 |
// ---------------------------------------------------------------------------- |
|
77 |
// Two-phased constructor. |
|
78 |
// ---------------------------------------------------------------------------- |
|
79 |
// |
|
80 |
CMPXPodcastDbHandler* CMPXPodcastDbHandler::NewLC( |
|
81 |
RFs& aFs, |
|
82 |
CMPXResource& aResource) |
|
83 |
{ |
|
84 |
MPX_FUNC("CMPXPodcastDbHandler::NewLC"); |
|
85 |
||
86 |
CMPXPodcastDbHandler* self = new (ELeave) CMPXPodcastDbHandler(aFs, aResource); |
|
87 |
CleanupStack::PushL( self ); |
|
88 |
self->ConstructL(); |
|
89 |
return self; |
|
90 |
} |
|
91 |
||
92 |
// ---------------------------------------------------------------------------- |
|
93 |
// Destructor |
|
94 |
// ---------------------------------------------------------------------------- |
|
95 |
// |
|
96 |
CMPXPodcastDbHandler::~CMPXPodcastDbHandler() |
|
97 |
{ |
|
98 |
MPX_FUNC("CMPXPodcastDbHandler::~CMPXPodcastDbHandler"); |
|
99 |
||
100 |
delete iDbPodcast; |
|
101 |
delete iDbArtist; |
|
102 |
delete iDbAlbum; |
|
103 |
delete iDbGenre; |
|
104 |
delete iDbComposer; |
|
105 |
delete iDbAuxiliary; |
|
106 |
delete iDbManager; |
|
107 |
||
108 |
delete iPodcastPublishDateCat; |
|
109 |
iPodcastPublishDateIds.Close(); |
|
110 |
iDbDrives.Close(); |
|
111 |
} |
|
112 |
||
113 |
// ---------------------------------------------------------------------------- |
|
114 |
// C++ default constructor can NOT contain any code, that might leave |
|
115 |
// ---------------------------------------------------------------------------- |
|
116 |
// |
|
117 |
CMPXPodcastDbHandler::CMPXPodcastDbHandler( |
|
118 |
RFs& aFs, |
|
119 |
CMPXResource& aResource) : |
|
120 |
iFs(aFs), |
|
121 |
iResource(aResource) |
|
122 |
{ |
|
123 |
MPX_FUNC("CMPXPodcastDbHandler::CMPXPodcastDbHandler"); |
|
124 |
} |
|
125 |
||
126 |
// ---------------------------------------------------------------------------- |
|
127 |
// Symbian 2nd phase constructor can leave. |
|
128 |
// ---------------------------------------------------------------------------- |
|
129 |
// |
|
130 |
void CMPXPodcastDbHandler::ConstructL() |
|
131 |
{ |
|
132 |
MPX_FUNC("CMPXPodcastDbHandler::ConstructL"); |
|
133 |
||
134 |
iPodcastPublishDateCat = iResource.ReadMenuArrayL(R_MPX_QTN_NMP_PUBLISH_DATE_ARRAY, |
|
135 |
iPodcastPublishDateIds); |
|
136 |
||
137 |
//create db manager |
|
138 |
iDbManager = CMPXPodcastDbManager::NewL(iFs); |
|
139 |
CDesCArrayFlat* podcastFolders = |
|
140 |
#ifdef RD_MULTIPLE_DRIVE |
|
141 |
GetPodcastFoldersL(); |
|
142 |
#else |
|
143 |
iResource.ReadDesCArrayL(R_MC_DEFAULT_MUSIC_FOLDERS); |
|
144 |
#endif |
|
145 |
||
146 |
// create the podcast folders and initialize iDbDrives |
|
147 |
CleanupStack::PushL(podcastFolders); |
|
148 |
ProcessPodcastFoldersL(*podcastFolders); |
|
149 |
CleanupStack::PopAndDestroy(podcastFolders); |
|
150 |
||
151 |
// create the db infrastructure |
|
152 |
iDbPodcast = CMPXDbPodcast::NewL(*iDbManager, iResource, *this); |
|
153 |
iDbArtist = CMPXDbCategory::NewL(*iDbManager, EMPXArtist); |
|
154 |
iDbAlbum = CMPXDbCategory::NewL(*iDbManager, EMPXAlbum); |
|
155 |
iDbGenre = CMPXDbCategory::NewL(*iDbManager, EMPXGenre); |
|
156 |
iDbComposer = CMPXDbCategory::NewL(*iDbManager, EMPXComposer); |
|
157 |
iDbAuxiliary = CMPXDbAuxiliary::NewL(*iDbManager); |
|
158 |
||
159 |
// make sure all databases are created and valid |
|
160 |
MPX_TRAPD(err, iDbManager->InitDatabasesL(iDbDrives)); |
|
161 |
||
162 |
// If KErrCorrupt is returned, a database file was found to be corrupted |
|
163 |
// and was replaced with a new one. The db plugin can ignore this error and continue |
|
164 |
// because a new db file was successfully created in a subsequent retry. |
|
165 |
if ((err != KErrNone) && (err != KErrCorrupt) && (err != KErrDiskFull)) |
|
166 |
{ |
|
167 |
// leave to signal the caller that there was an error why creating and opening |
|
168 |
// one or more of the databases |
|
169 |
User::Leave(err); |
|
170 |
} |
|
171 |
else if (err == KErrDiskFull) |
|
172 |
{ |
|
173 |
iOutOfDisk = ETrue; |
|
174 |
} |
|
175 |
else |
|
176 |
{ |
|
177 |
// do nothing |
|
178 |
} |
|
179 |
// Verify the volume ID Matches |
|
180 |
MPX_TRAP(err,VerifyVolumeIdL()); |
|
181 |
if ((err != KErrNone) && (err != KErrDiskFull)) |
|
182 |
{ |
|
183 |
// leave to signal the caller that there was an error why creating and opening |
|
184 |
// one or more of the databases |
|
185 |
User::Leave(err); |
|
186 |
} |
|
187 |
else if (err == KErrDiskFull) |
|
188 |
{ |
|
189 |
iOutOfDisk = ETrue; |
|
190 |
} |
|
191 |
||
192 |
// iDbManager->PrintDatabaseL(); |
|
193 |
||
194 |
MPX_DEBUG2("CMPXDbHandler::ConstructL DbCount[%d]", iDbManager->DatabaseCount()); |
|
195 |
} |
|
196 |
||
197 |
// ---------------------------------------------------------------------------- |
|
198 |
// Add episode into collection |
|
199 |
// ---------------------------------------------------------------------------- |
|
200 |
// |
|
201 |
TUint32 CMPXPodcastDbHandler::AddEpisodeL( |
|
202 |
const CMPXMedia& aMedia) |
|
203 |
{ |
|
204 |
MPX_FUNC("CMPXPodcastDbHandler::AddEpisodeL"); |
|
205 |
||
206 |
BeginTransactionL(); |
|
207 |
||
208 |
TUint32 episodeId(0); |
|
209 |
MPX_TRAPD(err, episodeId = DoAddEpisodeL(aMedia)); |
|
210 |
||
211 |
if (iOutOfDisk && (err == KErrNotFound)) |
|
212 |
{ |
|
213 |
err = KErrDiskFull; |
|
214 |
} |
|
215 |
EndTransactionL(err); |
|
216 |
||
217 |
return episodeId; |
|
218 |
} |
|
219 |
||
220 |
// ---------------------------------------------------------------------------- |
|
221 |
// Update a episode in the collection |
|
222 |
// ---------------------------------------------------------------------------- |
|
223 |
// |
|
224 |
CMPXDbActiveTask::TChangeVisibility CMPXPodcastDbHandler::UpdateEpisodeL( |
|
225 |
const CMPXMedia& aMedia, |
|
226 |
CMPXMessageArray& aItemChangedMessages) |
|
227 |
{ |
|
228 |
MPX_FUNC("CMPXPodcastDbHandler::UpdateEpisodeL"); |
|
229 |
||
230 |
BeginTransactionL(); |
|
231 |
CMPXDbActiveTask::TChangeVisibility visibleChange(CMPXDbActiveTask::ENotVisibile); |
|
232 |
MPX_TRAPD(err, visibleChange = DoUpdateEpisodeL(aMedia, aItemChangedMessages)); |
|
233 |
EndTransactionL(err); |
|
234 |
return visibleChange; |
|
235 |
} |
|
236 |
||
237 |
// ---------------------------------------------------------------------------- |
|
238 |
// Remove the entire podcast collection database |
|
239 |
// ---------------------------------------------------------------------------- |
|
240 |
// |
|
241 |
void CMPXPodcastDbHandler::RemoveEntireCollectionL() |
|
242 |
{ |
|
243 |
MPX_FUNC("CMPXPodcastDbHandler::RemoveEntireCollectionL"); |
|
244 |
||
245 |
BeginTransactionL(); |
|
246 |
MPX_TRAPD(err, iDbManager->RecreateAllDatabasesL()); |
|
247 |
EndTransactionL(err); |
|
248 |
} |
|
249 |
||
250 |
// ---------------------------------------------------------------------------- |
|
251 |
// Delete a episode from collection |
|
252 |
// The function notifies collection model to perform deletion |
|
253 |
// ---------------------------------------------------------------------------- |
|
254 |
// |
|
255 |
void CMPXPodcastDbHandler::RemoveEpisodeL( |
|
256 |
TUint32 aEpisodeId, |
|
257 |
CDesCArray& aUriArray, |
|
258 |
CMPXMessageArray& aItemChangedMessages, |
|
259 |
TBool aDeleteRecord) |
|
260 |
{ |
|
261 |
MPX_FUNC("CMPXPodcastDbHandler::RemoveEpisodeL"); |
|
262 |
||
263 |
BeginTransactionL(); |
|
264 |
MPX_TRAPD(err, DoRemoveEpisodeL(aEpisodeId, aUriArray, aItemChangedMessages, aDeleteRecord)); |
|
265 |
EndTransactionL(err); |
|
266 |
} |
|
267 |
||
268 |
// ---------------------------------------------------------------------------- |
|
269 |
// Removes a category of episodes from the podcast collection, and its |
|
270 |
// corresponding category in the lookup table |
|
271 |
// ---------------------------------------------------------------------------- |
|
272 |
// |
|
273 |
void CMPXPodcastDbHandler::RemoveEpisodesMatchingCategoryL( |
|
274 |
TMPXGeneralCategory aCategory, |
|
275 |
TUint32 aCategoryId, |
|
276 |
CDesCArray& aUriArray, |
|
277 |
CMPXMessageArray& aItemChangedMessages) |
|
278 |
{ |
|
279 |
MPX_FUNC("CMPXPodcastDbHandler::RemoveEpisodesMatchingCategoryL"); |
|
280 |
||
281 |
BeginTransactionL(); |
|
282 |
MPX_TRAPD(err, DoRemoveEpisodesMatchingCategoryL(aCategory, aCategoryId, |
|
283 |
aUriArray, aItemChangedMessages)); |
|
284 |
EndTransactionL(err); |
|
285 |
} |
|
286 |
||
287 |
// ---------------------------------------------------------------------------- |
|
288 |
// Delete episode(s) from collection belonging to specified publish date category |
|
289 |
// The function notifies collection model to perform deletion |
|
290 |
// ---------------------------------------------------------------------------- |
|
291 |
// |
|
292 |
void CMPXPodcastDbHandler::RemoveEpisodesMatchingPublishDateCategoryL( |
|
293 |
TUint32 aCategoryId, |
|
294 |
CDesCArray& aUriArray, |
|
295 |
CMPXMessageArray& aItemChangedMessages) |
|
296 |
{ |
|
297 |
MPX_FUNC("CMPXPodcastDbHandler::RemoveEpisodesMatchingPublishDateCategoryL"); |
|
298 |
||
299 |
BeginTransactionL(); |
|
300 |
MPX_TRAPD(err, DoRemoveEpisodesMatchingPublishDateCategoryL(aCategoryId, |
|
301 |
aUriArray, aItemChangedMessages)); |
|
302 |
EndTransactionL(err); |
|
303 |
} |
|
304 |
||
305 |
// ---------------------------------------------------------------------------- |
|
306 |
// Cleanup records marked as deleted. This is designated for MTP to clean up |
|
307 |
// records marked as deleted at the end of its session. |
|
308 |
// ---------------------------------------------------------------------------- |
|
309 |
// |
|
310 |
void CMPXPodcastDbHandler::CleanupDeletedRecordsL() |
|
311 |
{ |
|
312 |
MPX_FUNC("CMPXPodcastDbHandler::CleanupDeletedRecordsL"); |
|
313 |
||
314 |
BeginTransactionL(); |
|
315 |
MPX_TRAPD(err, DoCleanupDeletedRecordsL()); |
|
316 |
EndTransactionL(err); |
|
317 |
} |
|
318 |
||
319 |
// ---------------------------------------------------------------------------- |
|
320 |
// Read all episodes and cache them into an array ordered by episode name |
|
321 |
// ---------------------------------------------------------------------------- |
|
322 |
// |
|
323 |
void CMPXPodcastDbHandler::GetAllEpisodesL( |
|
324 |
const TArray<TMPXAttribute>& aAttrs, |
|
325 |
CMPXMediaArray& aMediaArray) |
|
326 |
{ |
|
327 |
MPX_FUNC("CMPXPodcastDbHandler::GetAllEpisodesL"); |
|
328 |
iDbPodcast->GetAllEpisodesL(aAttrs, aMediaArray); |
|
329 |
} |
|
330 |
||
331 |
// ---------------------------------------------------------------------------- |
|
332 |
// Retrieve the episode(s) with the specified title |
|
333 |
// ---------------------------------------------------------------------------- |
|
334 |
// |
|
335 |
void CMPXPodcastDbHandler::GetEpisodesMatchingTitleL( |
|
336 |
TUint aTitleId, |
|
337 |
const TArray<TMPXAttribute>& aAttrs, |
|
338 |
CMPXMediaArray& aMediaArray) |
|
339 |
{ |
|
340 |
MPX_FUNC("CMPXPodcastDbHandler::GetEpisodesMatchingTitleL"); |
|
341 |
iDbPodcast->GetEpisodesForCategoryL(EMPXAlbum, aTitleId, aAttrs, |
|
342 |
aMediaArray, ETrue); |
|
343 |
} |
|
344 |
||
345 |
// ---------------------------------------------------------------------------- |
|
346 |
// Retrieve the episode(s) belonging to the specified playlist |
|
347 |
// ---------------------------------------------------------------------------- |
|
348 |
// |
|
349 |
void CMPXPodcastDbHandler::GetEpisodesMatchingPlaylistL( |
|
350 |
TUint aPlaylistId, |
|
351 |
const TArray<TMPXAttribute>& aAttrs, |
|
352 |
CMPXMediaArray& aMediaArray, |
|
353 |
TInt& aIndexOfCurrentlyPlayingItem) |
|
354 |
{ |
|
355 |
MPX_FUNC("CMPXPodcastDbHandler::GetEpisodesMatchingPlaylistL"); |
|
356 |
||
357 |
switch (aPlaylistId) |
|
358 |
{ |
|
359 |
case KRecentlyAddedPlaylistUID: |
|
360 |
{ |
|
361 |
iDbPodcast->GetRecentlyAddedPlaylistEpisodesL(aAttrs, aMediaArray, |
|
362 |
aIndexOfCurrentlyPlayingItem); |
|
363 |
break; |
|
364 |
} |
|
365 |
case KNotPlayedPlaylistUID: |
|
366 |
{ |
|
367 |
iDbPodcast->GetNotYetPlayedPlaylistEpisodesL(aAttrs, aMediaArray, |
|
368 |
aIndexOfCurrentlyPlayingItem); |
|
369 |
break; |
|
370 |
} |
|
371 |
default: |
|
372 |
{ |
|
373 |
User::Leave(KErrNotSupported); |
|
374 |
} |
|
375 |
} |
|
376 |
} |
|
377 |
||
378 |
// ---------------------------------------------------------------------------- |
|
379 |
// Retrieve the episode with the specified ID |
|
380 |
// ---------------------------------------------------------------------------- |
|
381 |
// |
|
382 |
void CMPXPodcastDbHandler::GetEpisodeL( |
|
383 |
TUint32 aEpisodeId, |
|
384 |
const TArray<TMPXAttribute>& aAttrs, |
|
385 |
CMPXMediaArray& aMediaArray) |
|
386 |
{ |
|
387 |
MPX_FUNC("CMPXPodcastDbHandler::GetEpisodeL"); |
|
388 |
||
389 |
CMPXMedia* media = CMPXMedia::NewL(); |
|
390 |
CleanupStack::PushL(media); |
|
391 |
||
392 |
GetEpisodeL(aEpisodeId, aAttrs, *media); |
|
393 |
aMediaArray.AppendL(*media); |
|
394 |
||
395 |
CleanupStack::PopAndDestroy(media); |
|
396 |
} |
|
397 |
||
398 |
// ---------------------------------------------------------------------------- |
|
399 |
// Retrieve the episode with the specified ID |
|
400 |
// ---------------------------------------------------------------------------- |
|
401 |
// |
|
402 |
void CMPXPodcastDbHandler::GetEpisodeL( |
|
403 |
TUint32 aEpisodeId, |
|
404 |
const TArray<TMPXAttribute>& aAttrs, |
|
405 |
CMPXMedia& aMedia) |
|
406 |
{ |
|
407 |
MPX_FUNC("CMPXPodcastDbHandler::GetEpisodeL"); |
|
408 |
iDbPodcast->GetEpisodeL(aEpisodeId, aAttrs, aMedia); |
|
409 |
} |
|
410 |
||
411 |
// ---------------------------------------------------------------------------- |
|
412 |
// Retrieve the episode with the specified URI |
|
413 |
// ---------------------------------------------------------------------------- |
|
414 |
// |
|
415 |
TUint32 CMPXPodcastDbHandler::GetEpisodeIdMatchingUriL( |
|
416 |
const TDesC& aUri) |
|
417 |
{ |
|
418 |
MPX_FUNC("CMPXPodcastDbHandler::GetEpisodeIdMatchingUriL"); |
|
419 |
return MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXCollection, aUri, EFalse); |
|
420 |
} |
|
421 |
||
422 |
// ---------------------------------------------------------------------------- |
|
423 |
// Return all podcast title names |
|
424 |
// ---------------------------------------------------------------------------- |
|
425 |
// |
|
426 |
void CMPXPodcastDbHandler::GetAllPodcastTitlesL( |
|
427 |
const TArray<TMPXAttribute>& aAttrs, |
|
428 |
CMPXMediaArray& aMediaArray) |
|
429 |
{ |
|
430 |
MPX_FUNC("CMPXPodcastDbHandler::GetAllPodcastTitlesL"); |
|
431 |
iDbAlbum->GetAllCategoryItemsL(aAttrs, aMediaArray); |
|
432 |
} |
|
433 |
||
434 |
// ---------------------------------------------------------------------------- |
|
435 |
// Retrieve episodes matching the specified publish playlist id |
|
436 |
// ---------------------------------------------------------------------------- |
|
437 |
// |
|
438 |
TInt CMPXPodcastDbHandler::GetEpisodesMatchingPublishPlaylistL( |
|
439 |
TUint aPlaylistId, |
|
440 |
const TArray<TMPXAttribute>& aAttrs, |
|
441 |
TBool aPendingCategoryDeletionFlag, |
|
442 |
CMPXMediaArray& aMediaArray) |
|
443 |
{ |
|
444 |
MPX_FUNC("CMPXPodcastDbHandler::GetEpisodesMatchingPublishPlaylistL"); |
|
445 |
||
446 |
TInt numEpisodes(0); |
|
447 |
TMPXItemId podcastPublishDateCatId = 0; |
|
448 |
||
449 |
// the deletion helper is retrieving all the media within this category |
|
450 |
// to delete it so need to record category id within last item so |
|
451 |
// that the HandleChangeL callback can cause OpenL to be called after the |
|
452 |
// last item within the category is deleted |
|
453 |
if (aPendingCategoryDeletionFlag) |
|
454 |
{ |
|
455 |
TInt categoryID(EMPXOther); |
|
456 |
||
457 |
// pass in the category Id so that the helper method can add |
|
458 |
// the category Id to the last item in this category to aid |
|
459 |
// in deletion of a category |
|
460 |
podcastPublishDateCatId = (aPlaylistId - KPublishTodayPlaylistUID) | (categoryID << 28); |
|
461 |
} |
|
462 |
||
463 |
switch (aPlaylistId) |
|
464 |
{ |
|
465 |
case KPublishAllPlaylistUID: |
|
466 |
{ |
|
467 |
TInt itemCount(iPodcastPublishDateCat->Count()); |
|
468 |
for (TInt i = 0; i < itemCount; ++i) |
|
469 |
{ |
|
470 |
TMPXItemId itemId = iPodcastPublishDateIds[i]; |
|
471 |
TInt count(0); |
|
472 |
||
473 |
switch (iPodcastPublishDateIds[i] + KPublishTodayPlaylistUID) |
|
474 |
{ |
|
475 |
case KPublishTodayPlaylistUID: |
|
476 |
count = iDbPodcast->GetTodayEpisodesCountL(); |
|
477 |
break; |
|
478 |
case KPublishYesterdayPlaylistUID: |
|
479 |
count = iDbPodcast->GetYesterdayEpisodesCountL(); |
|
480 |
break; |
|
481 |
case KPublishThisWeekPlaylistUID: |
|
482 |
count = iDbPodcast->GetThisWeekEpisodesCountL(); |
|
483 |
break; |
|
484 |
case KPublishLastWeekPlaylistUID: |
|
485 |
count = iDbPodcast->GetLastWeekEpisodesCountL(); |
|
486 |
break; |
|
487 |
case KPublish2WeeksAgoPlaylistUID: |
|
488 |
count = iDbPodcast->Get2WeeksAgoEpisodesCountL(); |
|
489 |
break; |
|
490 |
case KPublish3WeeksAgoPlaylistUID: |
|
491 |
count = iDbPodcast->Get3WeeksAgoEpisodesCountL(); |
|
492 |
break; |
|
493 |
case KPublishLastMonthPlaylistUID: |
|
494 |
count = iDbPodcast->GetLastMonthEpisodesCountL(); |
|
495 |
break; |
|
496 |
case KPublishEarlierPlaylistUID: |
|
497 |
count = iDbPodcast->GetEarlierEpisodesCountL(); |
|
498 |
break; |
|
499 |
case KPublishUnknownPlaylistUID: |
|
500 |
count = iDbPodcast->GetUnknownEpisodesCountL(); |
|
501 |
break; |
|
502 |
default: |
|
503 |
User::Leave(KErrNotFound); |
|
504 |
break; |
|
505 |
}; |
|
506 |
||
507 |
if (count > 0) |
|
508 |
{ |
|
509 |
numEpisodes += count; |
|
510 |
MPXDbUtil::AppendMediaL(aMediaArray, iPodcastPublishDateCat->MdcaPoint(i), |
|
511 |
EMPXGroup, EMPXPlaylist, EMPXPodcastGroup, EMPXPubDate, itemId); |
|
512 |
} |
|
513 |
} |
|
514 |
break; |
|
515 |
} |
|
516 |
||
517 |
case KPublishTodayPlaylistUID: |
|
518 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::GetEpisodesMatchingPublishPlaylistL: Published Today")); |
|
519 |
iDbPodcast->GetTodayEpisodesL(podcastPublishDateCatId, aAttrs, aMediaArray); |
|
520 |
break; |
|
521 |
||
522 |
case KPublishYesterdayPlaylistUID: |
|
523 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::GetEpisodesMatchingPublishPlaylistL: Published Yesterday")); |
|
524 |
iDbPodcast->GetYesterdayEpisodesL(podcastPublishDateCatId, aAttrs, aMediaArray); |
|
525 |
break; |
|
526 |
||
527 |
case KPublishThisWeekPlaylistUID: |
|
528 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::GetEpisodesMatchingPublishPlaylistL: Published This Week")); |
|
529 |
iDbPodcast->GetThisWeekEpisodesL(podcastPublishDateCatId, aAttrs, aMediaArray); |
|
530 |
break; |
|
531 |
||
532 |
case KPublishLastWeekPlaylistUID: |
|
533 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::GetEpisodesMatchingPublishPlaylistL: Published Last Week")); |
|
534 |
iDbPodcast->GetLastWeekEpisodesL(podcastPublishDateCatId, aAttrs, aMediaArray); |
|
535 |
break; |
|
536 |
||
537 |
case KPublish2WeeksAgoPlaylistUID: |
|
538 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::GetEpisodesMatchingPublishPlaylistL: Published 2 Weeks Ago")); |
|
539 |
iDbPodcast->Get2WeeksAgoEpisodesL(podcastPublishDateCatId, aAttrs, aMediaArray); |
|
540 |
break; |
|
541 |
||
542 |
case KPublish3WeeksAgoPlaylistUID: |
|
543 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::GetEpisodesMatchingPublishPlaylistL: Published 3 Weeks Ago")); |
|
544 |
iDbPodcast->Get3WeeksAgoEpisodesL(podcastPublishDateCatId, aAttrs, aMediaArray); |
|
545 |
break; |
|
546 |
||
547 |
case KPublishLastMonthPlaylistUID: |
|
548 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::GetEpisodesMatchingPublishPlaylistL: Published Last Month")); |
|
549 |
iDbPodcast->GetLastMonthEpisodesL(podcastPublishDateCatId, aAttrs, aMediaArray); |
|
550 |
break; |
|
551 |
||
552 |
case KPublishEarlierPlaylistUID: |
|
553 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::GetEpisodesMatchingPublishPlaylistL: Published Earlier")); |
|
554 |
iDbPodcast->GetEarlierEpisodesL(podcastPublishDateCatId, aAttrs, aMediaArray); |
|
555 |
break; |
|
556 |
||
557 |
case KPublishUnknownPlaylistUID: |
|
558 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::GetEpisodesMatchingPublishPlaylistL: Published Unknown")); |
|
559 |
iDbPodcast->GetUnknownEpisodesL(podcastPublishDateCatId, aAttrs, aMediaArray); |
|
560 |
break; |
|
561 |
||
562 |
default: |
|
563 |
MPX_DEBUG2 (_L("CMPXPodcastDbHandler::GetEpisodesMatchingPublishPlaylistL: Invalid publish ID [%d]"), aPlaylistId); |
|
564 |
User::Leave(KErrNotFound); |
|
565 |
break; |
|
566 |
} |
|
567 |
||
568 |
if (aPlaylistId != KPublishAllPlaylistUID) |
|
569 |
{ |
|
570 |
numEpisodes = aMediaArray.Count(); |
|
571 |
} |
|
572 |
||
573 |
return numEpisodes; |
|
574 |
} |
|
575 |
||
576 |
// ---------------------------------------------------------------------------- |
|
577 |
// Get the name of the row matching the given ID |
|
578 |
// ---------------------------------------------------------------------------- |
|
579 |
// |
|
580 |
HBufC* CMPXPodcastDbHandler::GetTitleNameMatchingIdL( |
|
581 |
const TUint32 aId) |
|
582 |
{ |
|
583 |
MPX_FUNC("CMPXPodcastDbHandler::GetTitleNameMatchingIdL"); |
|
584 |
return iDbAlbum->GetNameL(aId); |
|
585 |
} |
|
586 |
||
587 |
// ---------------------------------------------------------------------------- |
|
588 |
// Get the URI of the row matching the given ID |
|
589 |
// ---------------------------------------------------------------------------- |
|
590 |
// |
|
591 |
HBufC* CMPXPodcastDbHandler::GetUriMatchingIdL( |
|
592 |
const TUint32 aId) |
|
593 |
{ |
|
594 |
MPX_FUNC("CMPXPodcastDbHandler::GetUriMatchingIdL"); |
|
595 |
||
596 |
return iDbPodcast->GetUriL(aId); |
|
597 |
} |
|
598 |
||
599 |
// ---------------------------------------------------------------------------- |
|
600 |
// Find episode(s) that satisfy the specified criteria |
|
601 |
// ---------------------------------------------------------------------------- |
|
602 |
// |
|
603 |
CMPXMedia* CMPXPodcastDbHandler::FindAllLC( |
|
604 |
const CMPXMedia& aCriteria, |
|
605 |
const TArray<TMPXAttribute>& aAttrs) |
|
606 |
{ |
|
607 |
MPX_FUNC("CMPXPodcastDbHandler::FindAllLC"); |
|
608 |
||
609 |
// leave if the given media doesn't contain the following attributes |
|
610 |
if (!aCriteria.IsSupported(KMPXMediaGeneralType) || |
|
611 |
!aCriteria.IsSupported(KMPXMediaGeneralCategory)) |
|
612 |
{ |
|
613 |
User::Leave(KErrArgument); |
|
614 |
} |
|
615 |
||
616 |
RArray<TInt> supportedIds; |
|
617 |
CleanupClosePushL(supportedIds); |
|
618 |
supportedIds.AppendL(KMPXMediaIdContainer); |
|
619 |
MPXDbCommonUtil::FillInSupportedUIDsL(aAttrs, supportedIds); |
|
620 |
||
621 |
CMPXMedia* entries = CMPXMedia::NewL(supportedIds.Array()); |
|
622 |
CleanupStack::PopAndDestroy(&supportedIds); |
|
623 |
CleanupStack::PushL(entries); |
|
624 |
||
625 |
CMPXMediaArray* array = CMPXMediaArray::NewL(); |
|
626 |
CleanupStack::PushL(array); |
|
627 |
||
628 |
FindAllL(aCriteria, aAttrs, *array); |
|
629 |
||
630 |
entries->SetTObjectValueL(KMPXMediaGeneralType, EMPXGroup); |
|
631 |
entries->SetTObjectValueL(KMPXMediaGeneralCategory, |
|
632 |
aCriteria.ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory)); |
|
633 |
entries->SetCObjectValueL(KMPXMediaArrayContents, array); |
|
634 |
entries->SetTObjectValueL(KMPXMediaArrayCount, array->Count()); |
|
635 |
||
636 |
CleanupStack::PopAndDestroy(array); |
|
637 |
return entries; |
|
638 |
} |
|
639 |
||
640 |
// ---------------------------------------------------------------------------- |
|
641 |
// Find the number of items in the database |
|
642 |
// ---------------------------------------------------------------------------- |
|
643 |
// |
|
644 |
TInt CMPXPodcastDbHandler::NumberOfItemsL( |
|
645 |
TMPXPodcastCategory aCategory) |
|
646 |
{ |
|
647 |
MPX_FUNC("CMPXPodcastDbHandler::NumberOfItemsL"); |
|
648 |
||
649 |
TInt numOfItems(0); |
|
650 |
||
651 |
switch(aCategory) |
|
652 |
{ |
|
653 |
case EMPXAll: |
|
654 |
case EMPXEpisode: |
|
655 |
{ |
|
656 |
numOfItems = iDbPodcast->CountL(); |
|
657 |
break; |
|
658 |
} |
|
659 |
case EMPXRecentlyAdded: |
|
660 |
{ |
|
661 |
numOfItems = iDbPodcast->GetRecentlyAddedEpisodesCountL(); |
|
662 |
break; |
|
663 |
} |
|
664 |
case EMPXNotYetPlayed: |
|
665 |
{ |
|
666 |
numOfItems = iDbPodcast->GetNotYetPlayedEpisodesCountL(); |
|
667 |
break; |
|
668 |
} |
|
669 |
case EMPXTitle: |
|
670 |
{ |
|
671 |
numOfItems = iDbPodcast->GetNotYetPlayedEpisodesCountL(); |
|
672 |
break; |
|
673 |
} |
|
674 |
default: |
|
675 |
{ |
|
676 |
User::Leave(KErrNotSupported); |
|
677 |
} |
|
678 |
} |
|
679 |
||
680 |
return numOfItems; |
|
681 |
} |
|
682 |
||
683 |
// ---------------------------------------------------------------------------- |
|
684 |
// Has the database been created? |
|
685 |
// ---------------------------------------------------------------------------- |
|
686 |
// |
|
687 |
TBool CMPXPodcastDbHandler::DatabaseCreated() |
|
688 |
{ |
|
689 |
MPX_FUNC("CMPXPodcastDbHandler::DatabaseCreated"); |
|
690 |
||
691 |
TBool AuxilaryDbIsRefreshed(EFalse); |
|
692 |
TRAP_IGNORE(AuxilaryDbIsRefreshed = iDbAuxiliary->IsRefreshedL()); |
|
693 |
// If none of the databases were available, ie out of disk |
|
694 |
// we return EFalse |
|
695 |
return iDbManager->IsInitialized() && AuxilaryDbIsRefreshed; |
|
696 |
} |
|
697 |
||
698 |
// ---------------------------------------------------------------------------- |
|
699 |
// CMPXPodcastDbHandler::GetAllEpisodesDurationL |
|
700 |
// ---------------------------------------------------------------------------- |
|
701 |
// |
|
702 |
TInt CMPXPodcastDbHandler::GetAllEpisodesDurationL() |
|
703 |
{ |
|
704 |
MPX_FUNC("CMPXPodcastDbHandler::GetAllEpisodesDurationL"); |
|
705 |
return iDbPodcast->AllEpisodesDurationL(); |
|
706 |
} |
|
707 |
||
708 |
// ---------------------------------------------------------------------------- |
|
709 |
// CMPXPodcastDbHandler::GetTitleDurationL |
|
710 |
// ---------------------------------------------------------------------------- |
|
711 |
// |
|
712 |
TInt CMPXPodcastDbHandler::GetTitleDurationL( |
|
713 |
TUint32 aTitleId) |
|
714 |
{ |
|
715 |
MPX_FUNC("CMPXPodcastDbHandler::GetTitleDurationL"); |
|
716 |
return iDbPodcast->TitleDurationL(aTitleId); |
|
717 |
} |
|
718 |
||
719 |
// ---------------------------------------------------------------------------- |
|
720 |
// CMPXPodcastDbHandler::GetNotPlayedDurationL |
|
721 |
// ---------------------------------------------------------------------------- |
|
722 |
// |
|
723 |
TInt CMPXPodcastDbHandler::GetNotPlayedDurationL() |
|
724 |
{ |
|
725 |
MPX_FUNC("CMPXPodcastDbHandler::GetNotPlayedDurationL"); |
|
726 |
return iDbPodcast->NotPlayedDurationL(); |
|
727 |
} |
|
728 |
||
729 |
// ---------------------------------------------------------------------------- |
|
730 |
// CMPXPodcastDbHandler::GetRecentlyAddedDurationL |
|
731 |
// ---------------------------------------------------------------------------- |
|
732 |
// |
|
733 |
TInt CMPXPodcastDbHandler::GetRecentlyAddedDurationL() |
|
734 |
{ |
|
735 |
MPX_FUNC("CMPXPodcastDbHandler::GetRecentlyAddedDurationL"); |
|
736 |
return iDbPodcast->RecentlyAddedDurationL(); |
|
737 |
} |
|
738 |
||
739 |
// ---------------------------------------------------------------------------- |
|
740 |
// Set the last refreshed time into the collection |
|
741 |
// ---------------------------------------------------------------------------- |
|
742 |
// |
|
743 |
void CMPXPodcastDbHandler::SetLastRefreshedTimeL( |
|
744 |
TTime aTime) |
|
745 |
{ |
|
746 |
MPX_FUNC("CMPXPodcastDbHandler::SetLastRefreshedTimeL"); |
|
747 |
||
748 |
BeginTransactionL(); |
|
749 |
MPX_TRAPD(err, iDbAuxiliary->SetLastRefreshedTimeL(aTime)); |
|
750 |
EndTransactionL(err); |
|
751 |
} |
|
752 |
||
753 |
// ---------------------------------------------------------------------------- |
|
754 |
// Get the last refreshed time into the collection |
|
755 |
// ---------------------------------------------------------------------------- |
|
756 |
// |
|
757 |
TTime CMPXPodcastDbHandler::GetLastRefreshedTimeL() |
|
758 |
{ |
|
759 |
MPX_FUNC("CMPXPodcastDbHandler::GetLastRefreshedTimeL"); |
|
760 |
return iDbAuxiliary->LastRefreshedTimeL(); |
|
761 |
} |
|
762 |
||
763 |
// ---------------------------------------------------------------------------- |
|
764 |
// Set the db corrupted state for all drives |
|
765 |
// ---------------------------------------------------------------------------- |
|
766 |
// |
|
767 |
void CMPXPodcastDbHandler::SetDBCorruptedL( |
|
768 |
TBool aCorrupted) |
|
769 |
{ |
|
770 |
MPX_FUNC("CMPXPodcastDbHandler::SetDBCorruptedL"); |
|
771 |
||
772 |
BeginTransactionL(); |
|
773 |
MPX_TRAPD(err, iDbAuxiliary->SetDBCorruptedL(aCorrupted)); |
|
774 |
EndTransactionL(err); |
|
775 |
} |
|
776 |
||
777 |
// ---------------------------------------------------------------------------- |
|
778 |
// Gets the db corrupted state for all drives |
|
779 |
// ---------------------------------------------------------------------------- |
|
780 |
// |
|
781 |
TBool CMPXPodcastDbHandler::IsDBCorruptedL() |
|
782 |
{ |
|
783 |
MPX_FUNC("CMPXPodcastDbHandler::IsDBCorruptedL"); |
|
784 |
return iDbAuxiliary->DBCorruptedL(); |
|
785 |
} |
|
786 |
||
787 |
// ---------------------------------------------------------------------------- |
|
788 |
// Opens a database |
|
789 |
// ---------------------------------------------------------------------------- |
|
790 |
// |
|
791 |
void CMPXPodcastDbHandler::OpenDatabaseL( |
|
792 |
TInt aDrive) |
|
793 |
{ |
|
794 |
MPX_FUNC("CMPXPodcastDbHandler::OpenDatabaseL"); |
|
795 |
iDbManager->OpenDatabaseL(aDrive); |
|
796 |
||
797 |
// Verify the volume ID after a remount event |
|
798 |
VerifyVolumeIdL( aDrive ); |
|
799 |
} |
|
800 |
||
801 |
// ---------------------------------------------------------------------------- |
|
802 |
// Close a database |
|
803 |
// ---------------------------------------------------------------------------- |
|
804 |
// |
|
805 |
void CMPXPodcastDbHandler::CloseDatabaseL( |
|
806 |
TInt aDrive) |
|
807 |
{ |
|
808 |
MPX_FUNC("CMPXPodcastDbHandler::CloseDatabaseL"); |
|
809 |
iDbManager->CloseDatabaseL(aDrive); |
|
810 |
} |
|
811 |
||
812 |
// ---------------------------------------------------------------------------- |
|
813 |
// Re-create all databases |
|
814 |
// ---------------------------------------------------------------------------- |
|
815 |
// |
|
816 |
void CMPXPodcastDbHandler::ReCreateDatabasesL() |
|
817 |
{ |
|
818 |
MPX_FUNC("CMPXPodcastDbHandler::ReCreateDatabasesL"); |
|
819 |
iDbManager->RecreateAllDatabasesL(); |
|
820 |
} |
|
821 |
||
66
1f1dad4af8f8
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
822 |
|
1f1dad4af8f8
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
823 |
// ---------------------------------------------------------------------------- |
1f1dad4af8f8
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
824 |
// Re-create a specified database file |
1f1dad4af8f8
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
825 |
// ---------------------------------------------------------------------------- |
1f1dad4af8f8
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
826 |
// |
1f1dad4af8f8
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
827 |
void CMPXPodcastDbHandler::RecreateDatabaseFileL( TInt aDrive ) |
1f1dad4af8f8
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
828 |
{ |
1f1dad4af8f8
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
829 |
MPX_FUNC("CMPXPodcastDbHandler::RecreateDatabaseFileL"); |
1f1dad4af8f8
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
830 |
MPX_DEBUG2( "CMPXPodcastDbHandler::RecreateDatabaseFileL drive: %i", aDrive ); |
1f1dad4af8f8
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
831 |
iDbManager->RecreateDatabaseFileL( aDrive ); |
1f1dad4af8f8
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
832 |
} |
1f1dad4af8f8
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
53
diff
changeset
|
833 |
|
53 | 834 |
// ---------------------------------------------------------------------------- |
835 |
// Set handler refresh status |
|
836 |
// ---------------------------------------------------------------------------- |
|
837 |
// |
|
838 |
void CMPXPodcastDbHandler::RefreshStartL() |
|
839 |
{ |
|
840 |
MPX_FUNC("CMPXPodcastDbHandler::RefreshStartL"); |
|
841 |
||
842 |
iOutOfDisk = EFalse; |
|
843 |
// Re-open databases |
|
844 |
// This is needed for the case where we were OOD before, but user |
|
845 |
// has cleared some space but now try to refresh |
|
846 |
MPX_TRAPD(err, iDbManager->InitDatabasesL(iDbDrives)); |
|
847 |
||
848 |
if(err == KErrDiskFull) |
|
849 |
{ |
|
850 |
iOutOfDisk = ETrue; |
|
851 |
} |
|
852 |
||
853 |
if(!iOutOfDisk) |
|
854 |
{ |
|
855 |
MPX_TRAP(err,CheckDiskSpaceOnDrivesL()); |
|
856 |
||
857 |
if(err == KErrDiskFull) |
|
858 |
{ |
|
859 |
iOutOfDisk = ETrue; |
|
860 |
} |
|
861 |
} |
|
862 |
BeginTransactionL(); |
|
863 |
} |
|
864 |
||
865 |
// ---------------------------------------------------------------------------- |
|
866 |
// Re-set handler refresh status |
|
867 |
// ---------------------------------------------------------------------------- |
|
868 |
// |
|
869 |
void CMPXPodcastDbHandler::RefreshEndL() |
|
870 |
{ |
|
871 |
MPX_FUNC("CMPXPodcastDbHandler::RefreshEndL"); |
|
872 |
||
873 |
EndTransactionL(KErrNone); |
|
874 |
||
875 |
if (!iOutOfDisk) |
|
876 |
{ |
|
877 |
// Write last refreshed time as current time |
|
878 |
// This also sets corrupt = 0 |
|
879 |
TTime curTime; |
|
880 |
curTime.HomeTime(); |
|
881 |
SetLastRefreshedTimeL(curTime); |
|
882 |
// iDbManager->PrintDatabaseL(); // PREQ2536 the files sqlrowsetutil.h and sqlrowsetutil.cpp has been removed |
|
883 |
} |
|
884 |
} |
|
885 |
||
886 |
// ---------------------------------------------------------------------------- |
|
887 |
// CMPXPodcastDbHandler::SetIsPlayingL |
|
888 |
// ---------------------------------------------------------------------------- |
|
889 |
// |
|
890 |
void CMPXPodcastDbHandler::SetIsPlayingL( |
|
891 |
const CMPXMedia& aMedia, |
|
892 |
TBool aIsPlaying) |
|
893 |
{ |
|
894 |
MPX_FUNC("CMPXPodcastDbHandler::SetIsPlayingL"); |
|
895 |
||
896 |
TUint32 episodeId(0); |
|
897 |
if (aMedia.IsSupported(KMPXMediaGeneralId)) |
|
898 |
{ |
|
899 |
episodeId = aMedia.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId); |
|
900 |
} |
|
901 |
else if (aMedia.IsSupported(KMPXMediaGeneralUri)) |
|
902 |
{ |
|
903 |
const TDesC& location(aMedia.ValueText(KMPXMediaGeneralUri)); |
|
904 |
episodeId = MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXCollection, location, EFalse); |
|
905 |
} |
|
906 |
else |
|
907 |
{ |
|
908 |
User::Leave(KErrArgument); |
|
909 |
} |
|
910 |
||
911 |
BeginTransactionL(); |
|
912 |
MPX_TRAPD(err, iDbPodcast->SetIsPlayingL(episodeId, aIsPlaying)); |
|
913 |
EndTransactionL(err); |
|
914 |
} |
|
915 |
||
916 |
// ---------------------------------------------------------------------------- |
|
917 |
// Get all records count for podcasts |
|
918 |
// ---------------------------------------------------------------------------- |
|
919 |
// |
|
920 |
TUint CMPXPodcastDbHandler::GetTotalCountL(TInt aDrive) |
|
921 |
{ |
|
922 |
MPX_FUNC("CMPXPodcastDbHandler::GetTotalCountL"); |
|
923 |
TUint total(0); |
|
924 |
||
925 |
total = iDbPodcast->GetDrivePodcastCountL(aDrive); |
|
926 |
||
927 |
return total; |
|
928 |
} |
|
929 |
||
930 |
// ---------------------------------------------------------------------------- |
|
931 |
// Get all records count for podcasts |
|
932 |
// ---------------------------------------------------------------------------- |
|
933 |
// |
|
934 |
void CMPXPodcastDbHandler::GetPodcastUriArrayL(TInt aDrive, TInt aFromID, TInt aRecords, |
|
935 |
CDesCArray& aUriArr, TInt& aLastID) |
|
936 |
{ |
|
937 |
MPX_FUNC("CMPXPodcastDbHandler::GetTotalUriArrayL"); |
|
938 |
||
939 |
iDbPodcast->GetPodcastUriArrayL(aDrive,aFromID,aRecords,aUriArr,aLastID); |
|
940 |
} |
|
941 |
||
942 |
// ---------------------------------------------------------------------------- |
|
943 |
// CMPXPodcastDbHandler::DoCleanupDeletedRecordsL |
|
944 |
// ---------------------------------------------------------------------------- |
|
945 |
// |
|
946 |
void CMPXPodcastDbHandler::DoCleanupDeletedRecordsL() |
|
947 |
{ |
|
948 |
MPX_FUNC("CMPXPodcastDbHandler::DoCleanupDeletedRecordsL"); |
|
949 |
||
950 |
// delete all marked records from the Music table |
|
951 |
iDbPodcast->CleanupL(); |
|
952 |
||
953 |
// reset the count in the Auxiliary table |
|
954 |
iDbAuxiliary->SetSaveDeletedRecordCountL(KDbManagerAllDrives,0); |
|
955 |
} |
|
956 |
||
957 |
// ---------------------------------------------------------------------------- |
|
958 |
// FindAllL helper |
|
959 |
// ---------------------------------------------------------------------------- |
|
960 |
// |
|
961 |
void CMPXPodcastDbHandler::FindAllL( |
|
962 |
const CMPXMedia& aCriteria, |
|
963 |
const TArray<TMPXAttribute>& aAttrs, |
|
964 |
CMPXMediaArray& aMediaArray) |
|
965 |
{ |
|
966 |
MPX_FUNC("CMPXPodcastDbHandler::FindAllL"); |
|
967 |
||
968 |
RArray<TMPXAttribute> attributes; |
|
969 |
CleanupClosePushL (attributes); |
|
970 |
MPXUser::MergeAttributeL(aAttrs, attributes); |
|
971 |
||
972 |
// TODO: b10liu: update all users to properly use podcast category? |
|
973 |
// Some users of FindAll still call without specifying a podcast category group(ie.. delete helper) |
|
974 |
// so need to check and use media category instead if not available. |
|
975 |
if (!aCriteria.IsSupported(KMPXMediaPodcastCategoryGroup)) |
|
976 |
{ |
|
977 |
if (!aCriteria.IsSupported(KMPXMediaGeneralCategory)) |
|
978 |
{ |
|
979 |
User::Leave(KErrArgument); |
|
980 |
} |
|
981 |
TMPXGeneralCategory category = aCriteria.ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory); |
|
982 |
||
983 |
switch (category) |
|
984 |
{ |
|
985 |
case EMPXAlbum: |
|
986 |
{ |
|
987 |
if (!aCriteria.IsSupported(KMPXMediaGeneralId)) |
|
988 |
{ |
|
989 |
User::Leave(KErrArgument); |
|
990 |
} |
|
991 |
// return all episodes within this title |
|
992 |
TMPXItemId episodeTitleId = aCriteria.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId); |
|
993 |
GetEpisodesMatchingTitleL(episodeTitleId, aAttrs, aMediaArray); |
|
994 |
break; |
|
995 |
} |
|
996 |
case EMPXPodcast: |
|
997 |
case EMPXSong: |
|
998 |
{ |
|
999 |
FindEpisodesL(aCriteria, attributes.Array(), aMediaArray); |
|
1000 |
break; |
|
1001 |
} |
|
1002 |
case EMPXGenre: |
|
1003 |
case EMPXPlaylist: |
|
1004 |
case EMPXArtist: |
|
1005 |
case EMPXComposer: |
|
1006 |
default: |
|
1007 |
{ |
|
1008 |
DbCategoryL(category)->FindAllL(aCriteria, attributes.Array(), aMediaArray); |
|
1009 |
break; |
|
1010 |
} |
|
1011 |
} |
|
1012 |
} |
|
1013 |
else |
|
1014 |
{ |
|
1015 |
TMPXPodcastCategory category = |
|
1016 |
aCriteria.ValueTObjectL<TMPXPodcastCategory>(KMPXMediaPodcastCategoryGroup); |
|
1017 |
||
1018 |
switch (category) |
|
1019 |
{ |
|
1020 |
case EMPXTitle: |
|
1021 |
{ |
|
1022 |
if (!aCriteria.IsSupported(KMPXMediaGeneralId)) |
|
1023 |
{ |
|
1024 |
User::Leave(KErrArgument); |
|
1025 |
} |
|
1026 |
// return all episodes within this title |
|
1027 |
TMPXItemId episodeTitleId = aCriteria.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId); |
|
1028 |
GetEpisodesMatchingTitleL(episodeTitleId, aAttrs, aMediaArray); |
|
1029 |
break; |
|
1030 |
} |
|
1031 |
case EMPXPubDate: |
|
1032 |
{ |
|
1033 |
if (!aCriteria.IsSupported(KMPXMediaGeneralId)) |
|
1034 |
{ |
|
1035 |
User::Leave(KErrArgument); |
|
1036 |
} |
|
1037 |
||
1038 |
TMPXItemId categoryId = aCriteria.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId); |
|
1039 |
||
1040 |
// zero out the high 4 bits which indicate the general category |
|
1041 |
categoryId.iId2 &= 0x00FFFFFF; |
|
1042 |
GetEpisodesMatchingPublishPlaylistL(categoryId.iId2 + KPublishTodayPlaylistUID, // offset by KPublishTodayPlaylistUID |
|
1043 |
aAttrs, EFalse, aMediaArray); |
|
1044 |
break; |
|
1045 |
} |
|
1046 |
case EMPXRecentlyAdded: |
|
1047 |
case EMPXNotYetPlayed: |
|
1048 |
{ |
|
1049 |
break; |
|
1050 |
} |
|
1051 |
case EMPXAll: |
|
1052 |
case EMPXEpisode: |
|
1053 |
case EMPXNew: |
|
1054 |
case EMPXPartlyPlayed: |
|
1055 |
case EMPXCompletelyPlayed: |
|
1056 |
{ |
|
1057 |
FindEpisodesL(aCriteria, attributes.Array(), aMediaArray); |
|
1058 |
break; |
|
1059 |
} |
|
1060 |
default: |
|
1061 |
User::Leave(KErrNotSupported); |
|
1062 |
} |
|
1063 |
} |
|
1064 |
||
1065 |
CleanupStack::PopAndDestroy(&attributes); |
|
1066 |
} |
|
1067 |
||
1068 |
// ---------------------------------------------------------------------------- |
|
1069 |
// Get episode(s) from the music table that match the given criteria |
|
1070 |
// ---------------------------------------------------------------------------- |
|
1071 |
// |
|
1072 |
void CMPXPodcastDbHandler::FindEpisodesL( |
|
1073 |
const CMPXMedia& aCriteria, |
|
1074 |
const TArray<TMPXAttribute>& aAttrs, |
|
1075 |
CMPXMediaArray& aMediaArray) |
|
1076 |
{ |
|
1077 |
MPX_FUNC("CMPXPodcastDbHandler::FindEpisodesL"); |
|
1078 |
||
1079 |
TMPXGeneralType type(EMPXNoType); |
|
1080 |
if (!aCriteria.IsSupported(KMPXMediaGeneralType)) |
|
1081 |
{ |
|
1082 |
User::Leave(KErrArgument); |
|
1083 |
} |
|
1084 |
type = aCriteria.ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType); |
|
1085 |
||
1086 |
TMPXPodcastType podcastType(EMPXPodcastNoType); |
|
1087 |
if (aCriteria.IsSupported(KMPXMediaPodcastType)) |
|
1088 |
{ |
|
1089 |
podcastType = aCriteria.ValueTObjectL<TMPXPodcastType>(KMPXMediaPodcastType); |
|
1090 |
} |
|
1091 |
||
1092 |
TUint32 id(0); |
|
1093 |
if (aCriteria.IsSupported(KMPXMediaGeneralId)) |
|
1094 |
{ |
|
1095 |
id = aCriteria.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId); |
|
1096 |
} |
|
1097 |
||
1098 |
TUint32 containerId(0); |
|
1099 |
if (aCriteria.IsSupported(KMPXMediaGeneralContainerId)) |
|
1100 |
{ |
|
1101 |
containerId = aCriteria.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralContainerId); |
|
1102 |
} |
|
1103 |
||
1104 |
MPX_TRAPD(err, iDbPodcast->FindEpisodesL(id, containerId, type, podcastType, |
|
1105 |
aCriteria, aAttrs, aMediaArray)); |
|
1106 |
if (err == KErrNotSupported) |
|
1107 |
{ |
|
1108 |
User::Leave(KErrNotFound); |
|
1109 |
} |
|
1110 |
||
1111 |
User::LeaveIfError(err); |
|
1112 |
} |
|
1113 |
||
1114 |
// ---------------------------------------------------------------------------- |
|
1115 |
// Add episode to collection |
|
1116 |
// ---------------------------------------------------------------------------- |
|
1117 |
// |
|
1118 |
TUint32 CMPXPodcastDbHandler::DoAddEpisodeL( |
|
1119 |
const CMPXMedia& aMedia) |
|
1120 |
{ |
|
1121 |
MPX_FUNC("CMPXPodcastDbHandler::DoAddEpisodeL"); |
|
1122 |
||
1123 |
if (!aMedia.IsSupported(KMPXMediaGeneralUri)) |
|
1124 |
{ |
|
1125 |
User::Leave(KErrArgument); |
|
1126 |
} |
|
1127 |
||
1128 |
TDriveUnit drive(aMedia.ValueText(KMPXMediaGeneralUri)); |
|
1129 |
return iDbPodcast->AddEpisodeL(aMedia, drive); |
|
1130 |
} |
|
1131 |
||
1132 |
// ---------------------------------------------------------------------------- |
|
1133 |
// Update a episode in the collection |
|
1134 |
// ---------------------------------------------------------------------------- |
|
1135 |
// |
|
1136 |
CMPXDbActiveTask::TChangeVisibility CMPXPodcastDbHandler::DoUpdateEpisodeL( |
|
1137 |
const CMPXMedia& aMedia, |
|
1138 |
CMPXMessageArray& aItemChangedMessages) |
|
1139 |
{ |
|
1140 |
MPX_FUNC("CMPXPodcastDbHandler::DoUpdateEpisodeL"); |
|
1141 |
||
1142 |
CMPXDbActiveTask::TChangeVisibility visibleChange(CMPXDbActiveTask::ENotVisibile); |
|
1143 |
TUint32 curId(0); |
|
1144 |
TUint32 newId(0); |
|
1145 |
TInt curDrive(KErrNotFound); |
|
1146 |
TInt newDrive(KErrNotFound); |
|
1147 |
||
1148 |
// find the episode by Id and update it |
|
1149 |
if( aMedia.IsSupported(KMPXMediaGeneralId)) |
|
1150 |
{ |
|
1151 |
curId = (aMedia.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId)).iId2; |
|
1152 |
curDrive = iDbPodcast->GetDriveL(curId); |
|
1153 |
} |
|
1154 |
// find the episode by URI and update it |
|
1155 |
if(aMedia.IsSupported(KMPXMediaGeneralUri)) |
|
1156 |
{ |
|
1157 |
const TDesC& uri = aMedia.ValueText(KMPXMediaGeneralUri); |
|
1158 |
if (uri.Length() == 0) |
|
1159 |
{ |
|
1160 |
User::Leave( KErrArgument ); |
|
1161 |
} |
|
1162 |
||
1163 |
newDrive = TDriveUnit(uri); |
|
1164 |
newId = MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXCollection, uri, EFalse); |
|
1165 |
} |
|
1166 |
if (!curId && !newId) |
|
1167 |
{ |
|
1168 |
User::Leave(KErrNotSupported); |
|
1169 |
} |
|
1170 |
||
1171 |
TInt driveId = (curDrive != KErrNotFound) ? curDrive : newDrive; |
|
1172 |
||
1173 |
if (driveId != KErrNotFound) |
|
1174 |
{ |
|
1175 |
TUint32 episodeId = curId ? curId : newId; |
|
1176 |
||
1177 |
// Update the Podcast table |
|
1178 |
visibleChange = iDbPodcast->UpdateEpisodeL(episodeId, aMedia, aItemChangedMessages); |
|
1179 |
} |
|
1180 |
||
1181 |
return visibleChange; |
|
1182 |
} |
|
1183 |
||
1184 |
// ---------------------------------------------------------------------------- |
|
1185 |
// CMPXPodcastDbHandler::DoRemoveEpisodeL |
|
1186 |
// ---------------------------------------------------------------------------- |
|
1187 |
// |
|
1188 |
void CMPXPodcastDbHandler::DoRemoveEpisodeL( |
|
1189 |
TUint32 aEpisodeId, |
|
1190 |
CDesCArray& aUriArray, |
|
1191 |
CMPXMessageArray& aItemChangedMessages, |
|
1192 |
TBool aDeleteRecord) |
|
1193 |
{ |
|
1194 |
MPX_FUNC("CMPXPodcastDbHandler::DoRemoveEpisodeL"); |
|
1195 |
||
1196 |
TBool deleteRecord(ETrue); |
|
1197 |
||
1198 |
#if defined (__MTP_PROTOCOL_SUPPORT) |
|
1199 |
// Mark the song record as deleted if the following is true; otherwise, delete the |
|
1200 |
// song record. |
|
1201 |
// |
|
1202 |
// A client other than MTP has initiated this song deletion (aDeleteRecord is EFalse) |
|
1203 |
// and MTP has turned on its cenrep key to save deleted records and current number of |
|
1204 |
// saved deleted records has not exceeded its maximum, KMCMaxSavedDeletedRecords. |
|
1205 |
// |
|
1206 |
// Songs are marked as deleted in order to support auto-sync. MTP will delete these |
|
1207 |
// marked records at the end of each session via CleanupDeletedMediasL. |
|
1208 |
// |
|
1209 |
// For performance consideration, if the number of saved records exceeds its maximum, |
|
1210 |
// song record will be deleted. |
|
1211 |
if (!aDeleteRecord && SaveDeletedSongs()) |
|
1212 |
{ |
|
1213 |
TUint32 savedDeletedRecordCount(iDbAuxiliary->SaveDeletedRecordCountL()); |
|
1214 |
MPX_DEBUG2("Current number of saved deleted record count is %d", savedDeletedRecordCount); |
|
1215 |
||
1216 |
if (savedDeletedRecordCount < KMCMaxSavedDeletedRecords) |
|
1217 |
{ |
|
1218 |
deleteRecord = EFalse; |
|
1219 |
TInt drive = iDbPodcast->GetDriveL(aEpisodeId); |
|
1220 |
TUint32 savedDeletedDriveRecordCount(iDbAuxiliary->SaveDeletedRecordCountL(drive)); |
|
1221 |
iDbAuxiliary->SetSaveDeletedRecordCountL(drive,++savedDeletedDriveRecordCount); |
|
1222 |
} |
|
1223 |
} |
|
1224 |
#endif |
|
1225 |
||
1226 |
// delete the episode |
|
1227 |
// IsAdd is passed EFalse to ensure the episode count will be decremented |
|
1228 |
iDbPodcast->DeleteEpisodeL(aEpisodeId, aUriArray, aItemChangedMessages, EFalse, deleteRecord); |
|
1229 |
} |
|
1230 |
||
1231 |
// ---------------------------------------------------------------------------- |
|
1232 |
// CMPXPodcastDbHandler::DoRemoveEpisodesMatchingCategoryL |
|
1233 |
// ---------------------------------------------------------------------------- |
|
1234 |
// |
|
1235 |
void CMPXPodcastDbHandler::DoRemoveEpisodesMatchingCategoryL( |
|
1236 |
TMPXGeneralCategory aCategory, |
|
1237 |
TUint32 aCategoryId, |
|
1238 |
CDesCArray& aUriArray, |
|
1239 |
CMPXMessageArray& aItemChangedMessages) |
|
1240 |
{ |
|
1241 |
MPX_FUNC("CMPXPodcastDbHandler::DoRemoveEpisodesMatchingCategoryL"); |
|
1242 |
iDbPodcast->DeleteCategoryL(aCategory, aCategoryId, aUriArray, |
|
1243 |
aItemChangedMessages); |
|
1244 |
} |
|
1245 |
||
1246 |
// ---------------------------------------------------------------------------- |
|
1247 |
// CMPXPodcastDbHandler::DoRemoveEpisodesMatchingPublishDateCategoryL |
|
1248 |
// ---------------------------------------------------------------------------- |
|
1249 |
// |
|
1250 |
void CMPXPodcastDbHandler::DoRemoveEpisodesMatchingPublishDateCategoryL( |
|
1251 |
TUint32 aCategoryId, |
|
1252 |
CDesCArray& aUriArray, |
|
1253 |
CMPXMessageArray& aItemChangedMessages) |
|
1254 |
{ |
|
1255 |
MPX_FUNC("CMPXPodcastDbHandler::DoRemoveEpisodesMatchingPublishDateCategoryL"); |
|
1256 |
||
1257 |
switch (aCategoryId + KPublishTodayPlaylistUID) |
|
1258 |
{ |
|
1259 |
case KPublishTodayPlaylistUID: |
|
1260 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::DoRemoveEpisodesMatchingPublishDateCategoryL: Published Today")); |
|
1261 |
iDbPodcast->DeleteTodayEpisodesL(aUriArray, aItemChangedMessages); |
|
1262 |
break; |
|
1263 |
||
1264 |
case KPublishYesterdayPlaylistUID: |
|
1265 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::DoRemoveEpisodesMatchingPublishDateCategoryL: Published Yesterday")); |
|
1266 |
iDbPodcast->DeleteYesterdayEpisodesL(aUriArray, aItemChangedMessages); |
|
1267 |
break; |
|
1268 |
||
1269 |
case KPublishThisWeekPlaylistUID: |
|
1270 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::DoRemoveEpisodesMatchingPublishDateCategoryL: Published This Week")); |
|
1271 |
iDbPodcast->DeleteThisWeekEpisodesL(aUriArray, aItemChangedMessages); |
|
1272 |
break; |
|
1273 |
||
1274 |
case KPublishLastWeekPlaylistUID: |
|
1275 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::DoRemoveEpisodesMatchingPublishDateCategoryL: Published Last Week")); |
|
1276 |
iDbPodcast->DeleteLastWeekEpisodesL(aUriArray, aItemChangedMessages); |
|
1277 |
break; |
|
1278 |
||
1279 |
case KPublish2WeeksAgoPlaylistUID: |
|
1280 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::DoRemoveEpisodesMatchingPublishDateCategoryL: Published 2 Weeks Ago")); |
|
1281 |
iDbPodcast->Delete2WeeksAgoEpisodesL(aUriArray, aItemChangedMessages); |
|
1282 |
break; |
|
1283 |
||
1284 |
case KPublish3WeeksAgoPlaylistUID: |
|
1285 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::DoRemoveEpisodesMatchingPublishDateCategoryL: Published 3 Weeks Ago")); |
|
1286 |
iDbPodcast->Delete3WeeksAgoEpisodesL(aUriArray, aItemChangedMessages); |
|
1287 |
break; |
|
1288 |
||
1289 |
case KPublishLastMonthPlaylistUID: |
|
1290 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::DoRemoveEpisodesMatchingPublishDateCategoryL: Published Last Month")); |
|
1291 |
iDbPodcast->DeleteLastMonthEpisodesL(aUriArray, aItemChangedMessages); |
|
1292 |
break; |
|
1293 |
||
1294 |
case KPublishEarlierPlaylistUID: |
|
1295 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::DoRemoveEpisodesMatchingPublishDateCategoryL: Published Earlier")); |
|
1296 |
iDbPodcast->DeleteEarlierEpisodesL(aUriArray, aItemChangedMessages); |
|
1297 |
break; |
|
1298 |
||
1299 |
case KPublishUnknownPlaylistUID: |
|
1300 |
MPX_DEBUG1 (_L("CMPXPodcastDbHandler::DoRemoveEpisodesMatchingPublishDateCategoryL: Published Unknown")); |
|
1301 |
iDbPodcast->DeleteUnknownEpisodesL(aUriArray, aItemChangedMessages); |
|
1302 |
break; |
|
1303 |
||
1304 |
default: |
|
1305 |
MPX_DEBUG2 (_L("CMPXPodcastDbHandler::DoRemoveEpisodesMatchingPublishDateCategoryL: Invalid publish date ID [%d]"), aCategoryId); |
|
1306 |
// TODO: Leave with error? |
|
1307 |
break; |
|
1308 |
} |
|
1309 |
} |
|
1310 |
||
1311 |
// ---------------------------------------------------------------------------- |
|
1312 |
// CMPXPodcastDbHandler::ProcessPodcastFoldersL |
|
1313 |
// ---------------------------------------------------------------------------- |
|
1314 |
// |
|
1315 |
void CMPXPodcastDbHandler::ProcessPodcastFoldersL( |
|
1316 |
const CDesCArray& aFolders) |
|
1317 |
{ |
|
1318 |
MPX_FUNC("CMPXPodcastDbHandler::ProcessPodcastFoldersL"); |
|
1319 |
||
1320 |
TInt count(aFolders.MdcaCount()); |
|
1321 |
for (TInt i = 0; i < count; ++i) |
|
1322 |
{ |
|
1323 |
TPtrC16 folder = aFolders.MdcaPoint(i); |
|
1324 |
||
1325 |
// check if disk is inserted and act accordingly |
|
1326 |
TDriveUnit driveUnit(folder); |
|
1327 |
if (!iFs.IsValidDrive(driveUnit)) |
|
1328 |
{ |
|
1329 |
User::Leave(KErrArgument); |
|
1330 |
} |
|
1331 |
||
1332 |
// append the drive to the drive list |
|
1333 |
iDbDrives.AppendL(driveUnit); |
|
1334 |
} |
|
1335 |
} |
|
1336 |
||
1337 |
// ---------------------------------------------------------------------------- |
|
1338 |
// CMPXPodcastDbHandler::DbCategoryL |
|
1339 |
// ---------------------------------------------------------------------------- |
|
1340 |
// |
|
1341 |
CMPXDbCategory* CMPXPodcastDbHandler::DbCategoryL( |
|
1342 |
TMPXGeneralCategory aCategory) const |
|
1343 |
{ |
|
1344 |
MPX_FUNC("CMPXPodcastDbHandler::DbCategoryL"); |
|
1345 |
||
1346 |
CMPXDbCategory* dbCategory(NULL); |
|
1347 |
switch (aCategory) |
|
1348 |
{ |
|
1349 |
case EMPXArtist: |
|
1350 |
{ |
|
1351 |
dbCategory = iDbArtist; |
|
1352 |
break; |
|
1353 |
} |
|
1354 |
case EMPXAlbum: |
|
1355 |
{ |
|
1356 |
dbCategory = iDbAlbum; |
|
1357 |
break; |
|
1358 |
} |
|
1359 |
case EMPXGenre: |
|
1360 |
{ |
|
1361 |
dbCategory = iDbGenre; |
|
1362 |
break; |
|
1363 |
} |
|
1364 |
case EMPXComposer: |
|
1365 |
{ |
|
1366 |
dbCategory = iDbComposer; |
|
1367 |
break; |
|
1368 |
} |
|
1369 |
default: |
|
1370 |
User::Leave(KErrNotSupported); |
|
1371 |
} |
|
1372 |
||
1373 |
return dbCategory; |
|
1374 |
} |
|
1375 |
||
1376 |
// ---------------------------------------------------------------------------- |
|
1377 |
// Starts a transaction on all databases |
|
1378 |
// ---------------------------------------------------------------------------- |
|
1379 |
// |
|
1380 |
void CMPXPodcastDbHandler::BeginTransactionL() |
|
1381 |
{ |
|
1382 |
MPX_FUNC("CMPXPodcastDbHandler::BeginTransactionL"); |
|
1383 |
iDbManager->BeginL(); |
|
1384 |
} |
|
1385 |
||
1386 |
// ---------------------------------------------------------------------------- |
|
1387 |
// Ends a transaction on all databases |
|
1388 |
// ---------------------------------------------------------------------------- |
|
1389 |
// |
|
1390 |
void CMPXPodcastDbHandler::EndTransactionL( |
|
1391 |
TInt aError) |
|
1392 |
{ |
|
1393 |
MPX_FUNC("CMPXPodcastDbHandler::EndTransactionL"); |
|
1394 |
||
1395 |
if (aError) |
|
1396 |
{ |
|
1397 |
iDbManager->RollbackL(); |
|
1398 |
||
1399 |
// KSqlDbCorrupted indicates DB corrupted, need to recreate. |
|
1400 |
if ( aError != KSqlDbCorrupted ) |
|
1401 |
{ |
|
1402 |
User::Leave(aError); |
|
1403 |
} |
|
1404 |
} |
|
1405 |
else |
|
1406 |
{ |
|
1407 |
iDbManager->CommitL(); |
|
1408 |
} |
|
1409 |
} |
|
1410 |
||
1411 |
// ---------------------------------------------------------------------------- |
|
1412 |
// Checks if the database is currently in a transaction |
|
1413 |
// ---------------------------------------------------------------------------- |
|
1414 |
// |
|
1415 |
TBool CMPXPodcastDbHandler::InTransaction() |
|
1416 |
{ |
|
1417 |
MPX_FUNC("CMPXPodcastDbHandler::InTransaction"); |
|
1418 |
return iDbManager->InTransaction(); |
|
1419 |
} |
|
1420 |
||
1421 |
// ---------------------------------------------------------------------------- |
|
1422 |
// Verifies that the volume ID of the database matches the drive |
|
1423 |
// ---------------------------------------------------------------------------- |
|
1424 |
// |
|
1425 |
void CMPXPodcastDbHandler::VerifyVolumeIdL( TInt aDrive ) |
|
1426 |
{ |
|
1427 |
MPX_DEBUG1("CMPXPodcastDbHandler::VerifyVolumeIdL <--"); |
|
1428 |
||
1429 |
if( iDbManager->IsOpen(aDrive) ) |
|
1430 |
{ |
|
1431 |
TVolumeInfo volInfo; |
|
1432 |
iFs.Volume(volInfo, aDrive ); |
|
1433 |
TUint curId(volInfo.iUniqueID); |
|
1434 |
||
1435 |
TInt volId = iDbAuxiliary->IdL( aDrive ); |
|
1436 |
||
1437 |
// New database, no volume id set, mask out top bit because this is an uint |
|
1438 |
// |
|
1439 |
MPX_DEBUG3("CMPXPodcastDbHandler::VerifyVolumeIdL drive:%i db:%i", curId, volId); |
|
1440 |
if( volId == 0 && (curId&0x7FFFFFFF) ) |
|
1441 |
{ |
|
1442 |
MPX_DEBUG1("CMPXPodcastDbHandler::VerifyVolumeIdL -- New ID"); |
|
1443 |
BeginTransactionL(); |
|
1444 |
TRAPD( err, iDbAuxiliary->SetIdL( aDrive, curId&0x7FFFFFFF ) ); |
|
1445 |
EndTransactionL( err ); |
|
1446 |
||
1447 |
// KSqlDbCorrupted indicates DB corrupted, need to recreate. |
|
1448 |
if ( err == KSqlDbCorrupted ) |
|
1449 |
{ |
|
1450 |
MPX_DEBUG1("CMPXPodcastDbHandler::VerifyVolumeIdL -- Corrupted DB"); |
|
1451 |
iDbManager->RecreateDatabaseL( aDrive ); |
|
1452 |
BeginTransactionL(); |
|
1453 |
TRAPD( err, iDbAuxiliary->SetDBCorruptedL( ETrue ) ); |
|
1454 |
EndTransactionL( err ); |
|
1455 |
} |
|
1456 |
} |
|
1457 |
// Unmatched volume id, mark db as corrupt |
|
1458 |
// |
|
1459 |
else if ( (curId&0x7FFFFFFF) != (volId&0x7FFFFFFFF) ) |
|
1460 |
{ |
|
1461 |
MPX_DEBUG1("CMPXPodcastDbHandler::VerifyVolumeIdL -- ID match FAILED"); |
|
1462 |
iDbManager->RecreateDatabaseL( aDrive ); |
|
1463 |
BeginTransactionL(); |
|
1464 |
TRAPD( err, iDbAuxiliary->SetDBCorruptedL( ETrue ) ); |
|
1465 |
EndTransactionL( err ); |
|
1466 |
} |
|
1467 |
} |
|
1468 |
MPX_DEBUG1("CMPXPodcastDbHandler::VerifyVolumeIdL -->"); |
|
1469 |
} |
|
1470 |
||
1471 |
||
1472 |
// ---------------------------------------------------------------------------- |
|
1473 |
// Verifies that the volume ID of the database matches the drive |
|
1474 |
// ---------------------------------------------------------------------------- |
|
1475 |
// |
|
1476 |
void CMPXPodcastDbHandler::VerifyVolumeIdL() |
|
1477 |
{ |
|
1478 |
MPX_DEBUG1("CMPXPodcastDbHandler::VerifyVolumeIdL <--"); |
|
1479 |
TInt count( iDbDrives.Count() ); |
|
1480 |
for( TInt i=0; i<count; ++i ) |
|
1481 |
{ |
|
1482 |
VerifyVolumeIdL(iDbDrives[i]); |
|
1483 |
} |
|
1484 |
MPX_DEBUG1("CMPXPodcastDbHandler::VerifyVolumeIdL -->"); |
|
1485 |
} |
|
1486 |
||
1487 |
// ---------------------------------------------------------------------------- |
|
1488 |
// Checks if there is a drive that has a low disk space |
|
1489 |
// ---------------------------------------------------------------------------- |
|
1490 |
// |
|
1491 |
void CMPXPodcastDbHandler::CheckDiskSpaceOnDrivesL() |
|
1492 |
{ |
|
1493 |
MPX_DEBUG1("CMPXPodcastDbHandler::CheckDiskSpaceOnDrivesL <--"); |
|
1494 |
||
1495 |
TInt count( iDbDrives.Count() ); |
|
1496 |
for( TInt index=0; index<count; ++index ) |
|
1497 |
{ |
|
1498 |
iDbManager->CheckDiskSpaceL(iDbDrives[index]); |
|
1499 |
} |
|
1500 |
MPX_DEBUG1("CMPXPodcastDbHandler::CheckDiskSpaceOnDrivesL -->"); |
|
1501 |
} |
|
1502 |
#if defined (__MTP_PROTOCOL_SUPPORT) |
|
1503 |
||
1504 |
// ---------------------------------------------------------------------------- |
|
1505 |
// CMPXPodcastDbHandler::SaveDeletedSongs |
|
1506 |
// ---------------------------------------------------------------------------- |
|
1507 |
// |
|
1508 |
TBool CMPXPodcastDbHandler::SaveDeletedSongs() |
|
1509 |
{ |
|
1510 |
MPX_FUNC("CMPXPodcastDbHandler::SaveDeletedSongs"); |
|
1511 |
||
1512 |
TBool saveDeletedSongs(ETrue); |
|
1513 |
CRepository* cenrep(NULL); |
|
1514 |
MPX_TRAPD(error, cenrep = CRepository::NewL(KMPXMtpSettings)); |
|
1515 |
if (!error) |
|
1516 |
{ |
|
1517 |
cenrep->Get(KMPXMtpSaveDeletedRecordFlag, saveDeletedSongs); |
|
1518 |
delete cenrep; |
|
1519 |
MPX_DEBUG2("MTP indicated to save deleted songs? %d", saveDeletedSongs); |
|
1520 |
} |
|
1521 |
||
1522 |
return saveDeletedSongs; |
|
1523 |
} |
|
1524 |
||
1525 |
#endif |
|
1526 |
||
1527 |
// ---------------------------------------------------------------------------- |
|
1528 |
// CMPXPodcastDbHandler::AddCategoryItemL |
|
1529 |
// ---------------------------------------------------------------------------- |
|
1530 |
// |
|
1531 |
TUint32 CMPXPodcastDbHandler::AddCategoryItemL( |
|
1532 |
TMPXGeneralCategory aCategory, |
|
1533 |
const TDesC& aName, |
|
1534 |
TInt aDriveId, |
|
1535 |
CMPXMessageArray* aItemChangedMessages) |
|
1536 |
{ |
|
1537 |
MPX_FUNC("CMPXPodcastDbHandler::AddCategoryItemL"); |
|
1538 |
||
1539 |
TBool newRecord(EFalse); |
|
1540 |
TUint32 id(DbCategoryL(aCategory)->AddItemL(aName, aDriveId, newRecord, |
|
1541 |
(aCategory != EMPXGenre))); |
|
1542 |
if (newRecord && aItemChangedMessages) |
|
1543 |
{ |
|
1544 |
MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, id, |
|
1545 |
EMPXItemInserted, aCategory, KDBPluginUid); |
|
1546 |
} |
|
1547 |
||
1548 |
return id; |
|
1549 |
} |
|
1550 |
||
1551 |
// ---------------------------------------------------------------------------- |
|
1552 |
// CMPXPodcastDbHandler::DeleteEpisodeForCategoryL |
|
1553 |
// ---------------------------------------------------------------------------- |
|
1554 |
// |
|
1555 |
void CMPXPodcastDbHandler::DeleteEpisodeForCategoryL( |
|
1556 |
TMPXGeneralCategory aCategory, |
|
1557 |
TUint32 aCategoryId, |
|
1558 |
TInt aDriveId, |
|
1559 |
CMPXMessageArray* aItemChangedMessages) |
|
1560 |
{ |
|
1561 |
MPX_FUNC("CMPXPodcastDbHandler::DeleteEpisodeForCategoryL"); |
|
1562 |
DbCategoryL(aCategory)->DecrementEpisodesForCategoryL(aCategoryId, aDriveId, |
|
1563 |
aItemChangedMessages); |
|
1564 |
} |
|
1565 |
||
1566 |
#ifdef RD_MULTIPLE_DRIVE |
|
1567 |
||
1568 |
// ---------------------------------------------------------------------------------------------------------- |
|
1569 |
// Retrieve all visible podcast folder locations |
|
1570 |
// ---------------------------------------------------------------------------------------------------------- |
|
1571 |
// |
|
1572 |
CDesCArrayFlat* CMPXPodcastDbHandler::GetPodcastFoldersL() |
|
1573 |
{ |
|
1574 |
MPX_FUNC("CMPXPodcastDbHandler::GetPodcastFoldersL()"); |
|
1575 |
TDriveList driveList; |
|
1576 |
TInt driveCount(0); |
|
1577 |
User::LeaveIfError(DriveInfo::GetUserVisibleDrives(iFs, driveList, driveCount)); |
|
1578 |
MPX_DEBUG2 ("CMPXDbHandler::GetPodcastFoldersL() - driveCount = %d", driveCount); |
|
1579 |
||
1580 |
CDesCArrayFlat* folders = new (ELeave) CDesCArrayFlat(1); // granularity |
|
1581 |
CleanupStack::PushL(folders); |
|
1582 |
||
1583 |
for (TInt i = EDriveA; i <= EDriveZ; i++) |
|
1584 |
{ |
|
1585 |
if ((driveList[i]) && (!IsRemoteDrive(static_cast<TDriveNumber>(i)))) |
|
1586 |
{ |
|
1587 |
if (i == EDriveC) |
|
1588 |
{ |
|
1589 |
// Append the default phone memory path to the list |
|
1590 |
// of music folders |
|
1591 |
TPtrC rootPath(PathInfo::PhoneMemoryRootPath()); |
|
1592 |
folders->AppendL(rootPath); |
|
1593 |
MPX_DEBUG2("CMPXDbHandler::GetPodcastFoldersL() - adding...%S", &rootPath); |
|
1594 |
} |
|
1595 |
else |
|
1596 |
{ |
|
1597 |
// Get drive letter |
|
1598 |
TChar driveChar; |
|
1599 |
User::LeaveIfError(iFs.DriveToChar(i, driveChar)); |
|
1600 |
||
1601 |
// Append visible drive to list of music folders |
|
1602 |
TBuf<2> drive; |
|
1603 |
drive.Append(driveChar); |
|
1604 |
drive.Append(_L(":")); |
|
1605 |
folders->AppendL(drive); |
|
1606 |
MPX_DEBUG2 ("CMPXDbHandler::GetPodcastFoldersL() - adding...%S", &drive); |
|
1607 |
} |
|
1608 |
} |
|
1609 |
} |
|
1610 |
||
1611 |
CleanupStack::Pop(folders); |
|
1612 |
return folders; |
|
1613 |
} |
|
1614 |
||
1615 |
#endif // RD_MULTIPLE_DRIVE |
|
1616 |
||
1617 |
// --------------------------------------------------------------------------- |
|
1618 |
// CMPXPodcastDbHandler::IsRemoteDrive |
|
1619 |
// --------------------------------------------------------------------------- |
|
1620 |
// |
|
1621 |
TBool CMPXPodcastDbHandler::IsRemoteDrive(TDriveNumber aDrive) |
|
1622 |
{ |
|
1623 |
return iDbManager->IsRemoteDrive(aDrive); |
|
1624 |
} |
|
1625 |
||
1626 |
// End of File |
|
1627 |
||
1628 |