mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbhgplugin/src/mpxdbhandler.cpp
branchRCL_3
changeset 21 cb96c29156b2
parent 17 70a8526f03f2
equal deleted inserted replaced
19:a12246c97fcc 21:cb96c29156b2
  1535     if(err == KErrDiskFull)
  1535     if(err == KErrDiskFull)
  1536         {
  1536         {
  1537             iOutOfDisk = ETrue;
  1537             iOutOfDisk = ETrue;
  1538         }
  1538         }
  1539 
  1539 
       
  1540     User::LeaveIfError( err );
       
  1541     	
  1540     if(!iOutOfDisk)
  1542     if(!iOutOfDisk)
  1541     {
  1543     {
  1542         MPX_TRAP(err,CheckDiskSpaceOnDrivesL());
  1544         MPX_TRAP(err,CheckDiskSpaceOnDrivesL());
  1543 
  1545 
  1544         if(err == KErrDiskFull)
  1546         if(err == KErrDiskFull)
  1559 // ----------------------------------------------------------------------------
  1561 // ----------------------------------------------------------------------------
  1560 //
  1562 //
  1561 void CMPXDbHandler::RefreshEndL()
  1563 void CMPXDbHandler::RefreshEndL()
  1562     {
  1564     {
  1563     MPX_FUNC("CMPXDbHandler::RefreshEndL");
  1565     MPX_FUNC("CMPXDbHandler::RefreshEndL");
  1564     iRefresh = EFalse;
  1566     if ( iRefresh )
  1565     EndTransactionL(KErrNone);
  1567         { 
  1566     if (!iOutOfDisk)
  1568         iRefresh = EFalse;
  1567         {
  1569         EndTransactionL(KErrNone);
  1568         // Write last refreshed time as current time
  1570         if (!iOutOfDisk)
  1569         // This also sets corrupt = 0
  1571             {
  1570         TTime curTime;
  1572             // Write last refreshed time as current time
  1571         curTime.HomeTime();
  1573             // This also sets corrupt = 0
  1572         SetLastRefreshedTimeL(curTime);
  1574             TTime curTime;
  1573         }
  1575             curTime.HomeTime();
       
  1576             SetLastRefreshedTimeL(curTime);
       
  1577             }
  1574 
  1578 
  1575 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
  1579 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
  1576     //for AbstractAlbum garbage collection
  1580     //for AbstractAlbum garbage collection
  1577     //can not leave
  1581     TRAP_IGNORE( iDbAbstractAlbum->AbstractAlbumCleanUpL() );
  1578     TRAP_IGNORE( AbstractAlbumCleanUpL() );
       
  1579 #endif
  1582 #endif
  1580    
  1583    
  1581 #ifdef __RAMDISK_PERF_ENABLE
  1584 #ifdef __RAMDISK_PERF_ENABLE
  1582     iDbManager->CopyDBsFromRamL();
  1585         iDbManager->CopyDBsFromRamL();
  1583 #endif //__RAMDISK_PERF_ENABLE
  1586 #endif //__RAMDISK_PERF_ENABLE
       
  1587         }
  1584     }
  1588     }
  1585 
  1589 
  1586 // ----------------------------------------------------------------------------
  1590 // ----------------------------------------------------------------------------
  1587 // Notification of Mtp status change
  1591 // Notification of Mtp status change
  1588 // ----------------------------------------------------------------------------
  1592 // ----------------------------------------------------------------------------
  1603             }
  1607             }
  1604     #endif //__RAMDISK_PERF_ENABLE
  1608     #endif //__RAMDISK_PERF_ENABLE
  1605     
  1609     
  1606         iDbManager->BeginL();
  1610         iDbManager->BeginL();
  1607         }
  1611         }
       
  1612 //create Thumbnail manager session for cleanup for abstractalbum when MTP end.
       
  1613 //because when MTP end comes, in case of mode switching, we need to do it as fast as possible, 
       
  1614 //hence we don’t want the delay happens on that time.    
       
  1615 #ifdef RD_MPX_TNM_INTEGRATION           
       
  1616     iDbAbstractAlbum->CreateTNMSessionL();
       
  1617 #endif  //RD_MPX_TNM_INTEGRATION
  1608     MPX_DEBUG1("<--CMPXDbHandler::MtpStartL");
  1618     MPX_DEBUG1("<--CMPXDbHandler::MtpStartL");
  1609     }
  1619     }
  1610 
  1620 
  1611 // ----------------------------------------------------------------------------
  1621 // ----------------------------------------------------------------------------
  1612 // Notification of Mtp status change
  1622 // Notification of Mtp status change
  1628         MPX_DEBUG2("CMPXDbHandler::MtpEndL error=%d", err);
  1638         MPX_DEBUG2("CMPXDbHandler::MtpEndL error=%d", err);
  1629         }
  1639         }
  1630 #endif //__RAMDISK_PERF_ENABLE
  1640 #endif //__RAMDISK_PERF_ENABLE
  1631 
  1641 
  1632 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
  1642 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
  1633     TRAP(err, RemoveAbstractAlbumsWithNoSongL());
  1643     BeginTransactionL();
       
  1644     TRAP(err, iDbAbstractAlbum->RemoveAbstractAlbumsWithNoSongL());
  1634     if ( err != KErrNone )
  1645     if ( err != KErrNone )
  1635         {
  1646         {
  1636         MPX_DEBUG2("CMPXDbHandler::MtpEndL error happened when cleanup albstractalbum with no songs association[%d]", err);
  1647         MPX_DEBUG2("CMPXDbHandler::MtpEndL error happened when cleanup albstractalbum with no songs association[%d]", err);
  1637         }
  1648         }
       
  1649     EndTransactionL(err);
  1638 #endif
  1650 #endif
  1639     MPX_DEBUG1("<--CMPXDbHandler::MtpEndL");
  1651     MPX_DEBUG1("<--CMPXDbHandler::MtpEndL");
  1640     }
  1652     }
  1641 
  1653 
  1642 // ----------------------------------------------------------------------------
  1654 // ----------------------------------------------------------------------------
  2364     // Send a message on the song in the playlist that is deleted
  2376     // Send a message on the song in the playlist that is deleted
  2365     MPXDbCommonUtil::AddItemChangedMessageL(aItemChangedMessages, aSongId, EMPXItemDeleted,
  2377     MPXDbCommonUtil::AddItemChangedMessageL(aItemChangedMessages, aSongId, EMPXItemDeleted,
  2366         EMPXSong, KDBPluginUid);
  2378         EMPXSong, KDBPluginUid);
  2367     }
  2379     }
  2368     
  2380     
  2369 #ifdef ABSTRACTAUDIOALBUM_INCLUDED  
       
  2370 // ----------------------------------------------------------------------------
       
  2371 // Remove abstractalbums which have no songs associated.
       
  2372 // ----------------------------------------------------------------------------
       
  2373 //
       
  2374 void CMPXDbHandler::RemoveAbstractAlbumsWithNoSongL()
       
  2375     {
       
  2376     MPX_FUNC("CMPXDbHandler::RemoveAbstractAlbumsWithNoSongL");
       
  2377     
       
  2378     BeginTransactionL();
       
  2379     RArray<TUint32> iItemsIds;
       
  2380     CleanupClosePushL(iItemsIds);
       
  2381       //get all abstractalbum with no songs associated.
       
  2382     iDbAbstractAlbum->GetAllItemsWithNoSongL(iItemsIds);
       
  2383     TInt count = iItemsIds.Count();
       
  2384     TInt err = KErrNone;
       
  2385     if (count)
       
  2386         {
       
  2387         MPX_DEBUG2("CMPXDbHandler::RemoveAbstractAlbumsWithNoSongL, abstractalbum count[%d] ", iItemsIds.Count());
       
  2388         CMPXMessageArray* itemChangedMessages = CMPXMediaArray::NewL();
       
  2389         CleanupStack::PushL(itemChangedMessages);
       
  2390 
       
  2391         //go through each one to delete
       
  2392         for (TInt i=0; i< count; i++)
       
  2393             {
       
  2394             TRAP(err, RemoveAbstractAlbumL(iItemsIds[i], *itemChangedMessages, EFalse));
       
  2395             if (err != KErrNone)
       
  2396                 {
       
  2397                 MPX_DEBUG2("CMPXDbHandler::RemoveAbstractAlbumsWithNoSongL, error happens when delete abstractalbum, err ", err);
       
  2398                 }
       
  2399             }
       
  2400        CleanupStack::PopAndDestroy(itemChangedMessages);
       
  2401        }
       
  2402     CleanupStack::PopAndDestroy(&iItemsIds);
       
  2403     EndTransactionL(err); 
       
  2404   }
       
  2405   
       
  2406 // ----------------------------------------------------------------------------
       
  2407 // Remove .alb entry from AbstractAlnum table, TN table if .alb files deleted 
       
  2408 // from file manager when refresh library
       
  2409 // ----------------------------------------------------------------------------
       
  2410 //
       
  2411 void CMPXDbHandler::AbstractAlbumCleanUpL()
       
  2412     {
       
  2413     MPX_FUNC("CMPXDbHandler::AbstractAlbumCleanUpL");
       
  2414     RArray<TMPXAttribute> attributes;
       
  2415     CleanupClosePushL(attributes);
       
  2416     attributes.AppendL(KMPXMediaGeneralUri);
       
  2417     CMPXMediaArray* mediaArray = CMPXMediaArray::NewL();
       
  2418     CleanupStack::PushL(mediaArray);
       
  2419     
       
  2420     iDbAbstractAlbum->GetAllCategoryItemsL(attributes.Array(), *mediaArray);
       
  2421 
       
  2422     TInt count(mediaArray->Count());
       
  2423     if (count)
       
  2424         {
       
  2425         CMPXMessageArray* itemChangedMessages = CMPXMediaArray::NewL();
       
  2426         CleanupStack::PushL(itemChangedMessages);
       
  2427         for (TInt i = 0; i < count; i++)
       
  2428             {
       
  2429             CMPXMedia* element = mediaArray->AtL(i);
       
  2430             const TDesC& uri = element->ValueText(KMPXMediaGeneralUri);                                 
       
  2431 
       
  2432             //check if the file exists in file system
       
  2433             if (!(BaflUtils::FileExists(iFs, uri)))
       
  2434                 {
       
  2435                 //generate abstractalbum UID with the Uri
       
  2436                 TUint32 abstractAlbumId(MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXAbstractAlbum, uri, EFalse));
       
  2437                 RemoveAbstractAlbumL(abstractAlbumId, *itemChangedMessages, ETrue);             
       
  2438                 }
       
  2439             }
       
  2440             CleanupStack::PopAndDestroy(itemChangedMessages);
       
  2441         }
       
  2442         CleanupStack::PopAndDestroy(mediaArray);       
       
  2443         CleanupStack::PopAndDestroy(&attributes);     
       
  2444     }
       
  2445 #endif //ABSTRACTAUDIOALBUM_INCLUDED
       
  2446 
  2381 
  2447 // ----------------------------------------------------------------------------
  2382 // ----------------------------------------------------------------------------
  2448 // CMPXDbHandler::DoCleanupDeletedRecordsL
  2383 // CMPXDbHandler::DoCleanupDeletedRecordsL
  2449 // ----------------------------------------------------------------------------
  2384 // ----------------------------------------------------------------------------
  2450 //
  2385 //
  2892             User::Leave(KErrArgument);
  2827             User::Leave(KErrArgument);
  2893             }
  2828             }
  2894 
  2829 
  2895         // append the drive to the drive list
  2830         // append the drive to the drive list
  2896         iDbDrives.AppendL(driveUnit);
  2831         iDbDrives.AppendL(driveUnit);
  2897 
       
  2898         // make sure the folder is created
       
  2899         TVolumeInfo info;
       
  2900         if (iFs.Volume(info, driveUnit) == KErrNone)
       
  2901            {
       
  2902             if (!BaflUtils::PathExists(iFs, folder))
       
  2903                 {
       
  2904                 // create music folder if necessary
       
  2905                 TInt err(iFs.MkDirAll(folder));
       
  2906                 MPX_DEBUG3("Try to create music folder %S return code %d", &folder, err);
       
  2907                 if (err != KErrAlreadyExists)
       
  2908                     {
       
  2909                     User::LeaveIfError(err);
       
  2910                     }
       
  2911                 }
       
  2912             }
       
  2913         }
  2832         }
  2914     }
  2833     }
  2915 
  2834 
  2916 // ----------------------------------------------------------------------------
  2835 // ----------------------------------------------------------------------------
  2917 // CMPXDbHandler::DbCategoryL
  2836 // CMPXDbHandler::DbCategoryL
  3183     }
  3102     }
  3184 
  3103 
  3185 TUint32 CMPXDbHandler::AddCategoryItemL(
  3104 TUint32 CMPXDbHandler::AddCategoryItemL(
  3186         TMPXGeneralCategory aCategory,
  3105         TMPXGeneralCategory aCategory,
  3187         const TDesC& aName,
  3106         const TDesC& aName,
  3188         TUint32 aArtist,
  3107         const TDesC& aArtistName,
  3189         const TDesC& aArt,
  3108         const TDesC& aArt,
  3190         TInt aDriveId,
  3109         TInt aDriveId,
  3191         CMPXMessageArray* aItemChangedMessages,
  3110         CMPXMessageArray* aItemChangedMessages,
  3192         TBool& aItemExist)
  3111         TBool& aItemExist)
  3193 	{
  3112 	{
  3196     MPX_PERF_START(CMPXDbHandler_AddCategoryItemL);
  3115     MPX_PERF_START(CMPXDbHandler_AddCategoryItemL);
  3197 
  3116 
  3198     TBool newRecord(EFalse);
  3117     TBool newRecord(EFalse);
  3199 
  3118 
  3200     TUint32 id = 0;
  3119     TUint32 id = 0;
  3201     if ( aArtist )
  3120     if(aCategory == EMPXAlbum)
  3202         {
  3121         {
  3203         id = iDbAlbum->AddItemL(aName, aArtist, aArt, aDriveId, newRecord, (aCategory != EMPXGenre));
  3122         id = iDbAlbum->AddItemL(aName, aArtistName, aArt, aDriveId, newRecord, (aCategory != EMPXGenre));
  3204         }
  3123         }
  3205     else
  3124     else
  3206         {
  3125         {
  3207         id = iDbArtist->AddItemL(aName, aArt, aDriveId, newRecord, (aCategory != EMPXGenre));
  3126         id = iDbArtist->AddItemL(aName, aArt, aDriveId, newRecord, (aCategory != EMPXGenre));
  3208         }
  3127         }
  3360 
  3279 
  3361 // ---------------------------------------------------------------------------
  3280 // ---------------------------------------------------------------------------
  3362 // CMPXDbHandler::HandleArtistForAlbumL
  3281 // CMPXDbHandler::HandleArtistForAlbumL
  3363 // ---------------------------------------------------------------------------
  3282 // ---------------------------------------------------------------------------
  3364 //
  3283 //
  3365 TUint32 CMPXDbHandler::HandleArtistForAlbumL(const TUint32 aAlbumId)
  3284 HBufC* CMPXDbHandler::HandleArtistForAlbumL(const TUint32 aAlbumId)
  3366     {
  3285     {
  3367     return iDbMusic->ArtistForAlbumL(aAlbumId);
  3286 
       
  3287     TUint32 artistId = iDbMusic->ArtistForAlbumL(aAlbumId);
       
  3288     HBufC* artistname = GetNameMatchingIdL(artistId);
       
  3289     return artistname;
  3368     }
  3290     }
  3369 
  3291 
  3370 // ---------------------------------------------------------------------------
  3292 // ---------------------------------------------------------------------------
  3371 // CMPXDbHandler::HandleAlbumartForAlbumL
  3293 // CMPXDbHandler::HandleAlbumartForAlbumL
  3372 // ---------------------------------------------------------------------------
  3294 // ---------------------------------------------------------------------------