mpserviceplugins/mpxsqlitedbhgplugin/src/mpxdbhandler.cpp
changeset 38 b93f525c9244
parent 37 eb79a7c355bf
child 45 612c4815aebe
equal deleted inserted replaced
37:eb79a7c355bf 38:b93f525c9244
  1587             curTime.HomeTime();
  1587             curTime.HomeTime();
  1588             SetLastRefreshedTimeL(curTime);
  1588             SetLastRefreshedTimeL(curTime);
  1589             }
  1589             }
  1590 
  1590 
  1591 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
  1591 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
  1592         //for AbstractAlbum garbage collection
  1592     //for AbstractAlbum garbage collection
  1593         //can not leave
  1593     TRAP_IGNORE( iDbAbstractAlbum->AbstractAlbumCleanUpL() );
  1594         TRAP_IGNORE( AbstractAlbumCleanUpL() );
       
  1595 #endif
  1594 #endif
  1596    
  1595    
  1597 #ifdef __RAMDISK_PERF_ENABLE
  1596 #ifdef __RAMDISK_PERF_ENABLE
  1598         iDbManager->CopyDBsFromRamL();
  1597         iDbManager->CopyDBsFromRamL();
  1599 #endif //__RAMDISK_PERF_ENABLE
  1598 #endif //__RAMDISK_PERF_ENABLE
  1620             }
  1619             }
  1621     #endif //__RAMDISK_PERF_ENABLE
  1620     #endif //__RAMDISK_PERF_ENABLE
  1622     
  1621     
  1623         iDbManager->BeginL();
  1622         iDbManager->BeginL();
  1624         }
  1623         }
       
  1624     //create Thumbnail manager session for cleanup for abstractalbum when MTP end.
       
  1625     //because when MTP end comes, in case of mode switching, we need to do it as fast as possible, 
       
  1626     //hence we don’t want the delay happens on that time.    
       
  1627 #ifdef RD_MPX_TNM_INTEGRATION           
       
  1628     iDbAbstractAlbum->CreateTNMSessionL();
       
  1629 #endif  //RD_MPX_TNM_INTEGRATION
  1625     MPX_DEBUG1("<--CMPXDbHandler::MtpStartL");
  1630     MPX_DEBUG1("<--CMPXDbHandler::MtpStartL");
  1626     }
  1631     }
  1627 
  1632 
  1628 // ----------------------------------------------------------------------------
  1633 // ----------------------------------------------------------------------------
  1629 // Notification of Mtp status change
  1634 // Notification of Mtp status change
  1645         MPX_DEBUG2("CMPXDbHandler::MtpEndL error=%d", err);
  1650         MPX_DEBUG2("CMPXDbHandler::MtpEndL error=%d", err);
  1646         }
  1651         }
  1647 #endif //__RAMDISK_PERF_ENABLE
  1652 #endif //__RAMDISK_PERF_ENABLE
  1648 
  1653 
  1649 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
  1654 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
  1650     TRAP(err, RemoveAbstractAlbumsWithNoSongL());
  1655     BeginTransactionL();
       
  1656     TRAP(err, iDbAbstractAlbum->RemoveAbstractAlbumsWithNoSongL());
  1651     if ( err != KErrNone )
  1657     if ( err != KErrNone )
  1652         {
  1658         {
  1653         MPX_DEBUG2("CMPXDbHandler::MtpEndL error happened when cleanup albstractalbum with no songs association[%d]", err);
  1659         MPX_DEBUG2("CMPXDbHandler::MtpEndL error happened when cleanup albstractalbum with no songs association[%d]", err);
  1654         }
  1660         }
       
  1661     EndTransactionL(err);
  1655 #endif
  1662 #endif
  1656     MPX_DEBUG1("<--CMPXDbHandler::MtpEndL");
  1663     MPX_DEBUG1("<--CMPXDbHandler::MtpEndL");
  1657     }
  1664     }
  1658 
  1665 
  1659 // ----------------------------------------------------------------------------
  1666 // ----------------------------------------------------------------------------
  2381     // Send a message on the song in the playlist that is deleted
  2388     // Send a message on the song in the playlist that is deleted
  2382     MPXDbCommonUtil::AddItemChangedMessageL(aItemChangedMessages, aSongId, EMPXItemDeleted,
  2389     MPXDbCommonUtil::AddItemChangedMessageL(aItemChangedMessages, aSongId, EMPXItemDeleted,
  2383         EMPXSong, KDBPluginUid);
  2390         EMPXSong, KDBPluginUid);
  2384     }
  2391     }
  2385     
  2392     
  2386 #ifdef ABSTRACTAUDIOALBUM_INCLUDED  
       
  2387 // ----------------------------------------------------------------------------
       
  2388 // Remove abstractalbums which have no songs associated.
       
  2389 // ----------------------------------------------------------------------------
       
  2390 //
       
  2391 void CMPXDbHandler::RemoveAbstractAlbumsWithNoSongL()
       
  2392     {
       
  2393     MPX_FUNC("CMPXDbHandler::RemoveAbstractAlbumsWithNoSongL");
       
  2394     
       
  2395     BeginTransactionL();
       
  2396     RArray<TUint32> iItemsIds;
       
  2397     CleanupClosePushL(iItemsIds);
       
  2398       //get all abstractalbum with no songs associated.
       
  2399     iDbAbstractAlbum->GetAllItemsWithNoSongL(iItemsIds);
       
  2400     TInt count = iItemsIds.Count();
       
  2401     TInt err = KErrNone;
       
  2402     if (count)
       
  2403         {
       
  2404         MPX_DEBUG2("CMPXDbHandler::RemoveAbstractAlbumsWithNoSongL, abstractalbum count[%d] ", iItemsIds.Count());
       
  2405         CMPXMessageArray* itemChangedMessages = CMPXMediaArray::NewL();
       
  2406         CleanupStack::PushL(itemChangedMessages);
       
  2407 
       
  2408         //go through each one to delete
       
  2409         for (TInt i=0; i< count; i++)
       
  2410             {
       
  2411             TRAP(err, RemoveAbstractAlbumL(iItemsIds[i], *itemChangedMessages, EFalse));
       
  2412             if (err != KErrNone)
       
  2413                 {
       
  2414                 MPX_DEBUG2("CMPXDbHandler::RemoveAbstractAlbumsWithNoSongL, error happens when delete abstractalbum, err ", err);
       
  2415                 }
       
  2416             }
       
  2417        CleanupStack::PopAndDestroy(itemChangedMessages);
       
  2418        }
       
  2419     CleanupStack::PopAndDestroy(&iItemsIds);
       
  2420     EndTransactionL(err); 
       
  2421   }
       
  2422   
       
  2423 // ----------------------------------------------------------------------------
       
  2424 // Remove .alb entry from AbstractAlnum table, TN table if .alb files deleted 
       
  2425 // from file manager when refresh library
       
  2426 // ----------------------------------------------------------------------------
       
  2427 //
       
  2428 void CMPXDbHandler::AbstractAlbumCleanUpL()
       
  2429     {
       
  2430     MPX_FUNC("CMPXDbHandler::AbstractAlbumCleanUpL");
       
  2431     RArray<TMPXAttribute> attributes;
       
  2432     CleanupClosePushL(attributes);
       
  2433     attributes.AppendL(KMPXMediaGeneralUri);
       
  2434     CMPXMediaArray* mediaArray = CMPXMediaArray::NewL();
       
  2435     CleanupStack::PushL(mediaArray);
       
  2436     
       
  2437     iDbAbstractAlbum->GetAllCategoryItemsL(attributes.Array(), *mediaArray);
       
  2438 
       
  2439     TInt count(mediaArray->Count());
       
  2440     if (count)
       
  2441         {
       
  2442         CMPXMessageArray* itemChangedMessages = CMPXMediaArray::NewL();
       
  2443         CleanupStack::PushL(itemChangedMessages);
       
  2444         for (TInt i = 0; i < count; i++)
       
  2445             {
       
  2446             CMPXMedia* element = mediaArray->AtL(i);
       
  2447             const TDesC& uri = element->ValueText(KMPXMediaGeneralUri);                                 
       
  2448 
       
  2449             //check if the file exists in file system
       
  2450             if (!(BaflUtils::FileExists(iFs, uri)))
       
  2451                 {
       
  2452                 //generate abstractalbum UID with the Uri
       
  2453                 TUint32 abstractAlbumId(MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXAbstractAlbum, uri, EFalse));
       
  2454                 RemoveAbstractAlbumL(abstractAlbumId, *itemChangedMessages, ETrue);             
       
  2455                 }
       
  2456             }
       
  2457             CleanupStack::PopAndDestroy(itemChangedMessages);
       
  2458         }
       
  2459         CleanupStack::PopAndDestroy(mediaArray);       
       
  2460         CleanupStack::PopAndDestroy(&attributes);     
       
  2461     }
       
  2462 #endif //ABSTRACTAUDIOALBUM_INCLUDED
       
  2463 
  2393 
  2464 // ----------------------------------------------------------------------------
  2394 // ----------------------------------------------------------------------------
  2465 // CMPXDbHandler::DoCleanupDeletedRecordsL
  2395 // CMPXDbHandler::DoCleanupDeletedRecordsL
  2466 // ----------------------------------------------------------------------------
  2396 // ----------------------------------------------------------------------------
  2467 //
  2397 //
  2909             User::Leave(KErrArgument);
  2839             User::Leave(KErrArgument);
  2910             }
  2840             }
  2911 
  2841 
  2912         // append the drive to the drive list
  2842         // append the drive to the drive list
  2913         iDbDrives.AppendL(driveUnit);
  2843         iDbDrives.AppendL(driveUnit);
  2914 
       
  2915         // make sure the folder is created
       
  2916         TVolumeInfo info;
       
  2917         if (iFs.Volume(info, driveUnit) == KErrNone)
       
  2918            {
       
  2919             if (!BaflUtils::PathExists(iFs, folder))
       
  2920                 {
       
  2921                 // create music folder if necessary
       
  2922                 TInt err(iFs.MkDirAll(folder));
       
  2923                 MPX_DEBUG3("Try to create music folder %S return code %d", &folder, err);
       
  2924                 if (err != KErrAlreadyExists)
       
  2925                     {
       
  2926                     User::LeaveIfError(err);
       
  2927                     }
       
  2928                 }
       
  2929             }
       
  2930         }
  2844         }
  2931     }
  2845     }
  2932 
  2846 
  2933 // ----------------------------------------------------------------------------
  2847 // ----------------------------------------------------------------------------
  2934 // CMPXDbHandler::DbCategoryL
  2848 // CMPXDbHandler::DbCategoryL
  3200     }
  3114     }
  3201 
  3115 
  3202 TUint32 CMPXDbHandler::AddCategoryItemL(
  3116 TUint32 CMPXDbHandler::AddCategoryItemL(
  3203         TMPXGeneralCategory aCategory,
  3117         TMPXGeneralCategory aCategory,
  3204         const TDesC& aName,
  3118         const TDesC& aName,
  3205         TUint32 aArtist,
  3119         const TDesC& aArtistName,
  3206         const TDesC& aArt,
  3120         const TDesC& aArt,
  3207         TInt aDriveId,
  3121         TInt aDriveId,
  3208         CMPXMessageArray* aItemChangedMessages,
  3122         CMPXMessageArray* aItemChangedMessages,
  3209         TBool& aItemExist)
  3123         TBool& aItemExist)
  3210 	{
  3124 	{
  3213     MPX_PERF_START(CMPXDbHandler_AddCategoryItemL);
  3127     MPX_PERF_START(CMPXDbHandler_AddCategoryItemL);
  3214 
  3128 
  3215     TBool newRecord(EFalse);
  3129     TBool newRecord(EFalse);
  3216 
  3130 
  3217     TUint32 id = 0;
  3131     TUint32 id = 0;
  3218     if ( aArtist )
  3132     if(aCategory == EMPXAlbum)
  3219         {
  3133         {
  3220         id = iDbAlbum->AddItemL(aName, aArtist, aArt, aDriveId, newRecord, (aCategory != EMPXGenre));
  3134         id = iDbAlbum->AddItemL(aName, aArtistName, aArt, aDriveId, newRecord, (aCategory != EMPXGenre));
  3221         }
  3135         }
  3222     else
  3136     else
  3223         {
  3137         {
  3224         id = iDbArtist->AddItemL(aName, aArt, aDriveId, newRecord, (aCategory != EMPXGenre));
  3138         id = iDbArtist->AddItemL(aName, aArt, aDriveId, newRecord, (aCategory != EMPXGenre));
  3225         }
  3139         }
  3377 
  3291 
  3378 // ---------------------------------------------------------------------------
  3292 // ---------------------------------------------------------------------------
  3379 // CMPXDbHandler::HandleArtistForAlbumL
  3293 // CMPXDbHandler::HandleArtistForAlbumL
  3380 // ---------------------------------------------------------------------------
  3294 // ---------------------------------------------------------------------------
  3381 //
  3295 //
  3382 TUint32 CMPXDbHandler::HandleArtistForAlbumL(const TUint32 aAlbumId)
  3296 HBufC* CMPXDbHandler::HandleArtistForAlbumL(const TUint32 aAlbumId)
  3383     {
  3297     {
  3384     return iDbMusic->ArtistForAlbumL(aAlbumId);
  3298 
       
  3299     TUint32 artistId = iDbMusic->ArtistForAlbumL(aAlbumId);
       
  3300     HBufC* artistname = GetNameMatchingIdL(artistId);
       
  3301     return artistname;
  3385     }
  3302     }
  3386 
  3303 
  3387 // ---------------------------------------------------------------------------
  3304 // ---------------------------------------------------------------------------
  3388 // CMPXDbHandler::HandleAlbumartForAlbumL
  3305 // CMPXDbHandler::HandleAlbumartForAlbumL
  3389 // ---------------------------------------------------------------------------
  3306 // ---------------------------------------------------------------------------