mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbhgplugin/src/mpxdbabstractalbum.cpp
branchRCL_3
changeset 53 3de6c4cf6b67
child 56 2cbbefa9af78
equal deleted inserted replaced
52:14979e23cb5e 53:3de6c4cf6b67
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Responsible for interation with the category tables:
       
    15 *                Artist, Album, Genre, Composer and AbstractAlbum
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <mpxlog.h>
       
    23 #include <bautils.h>
       
    24 #include <mpxmediamusicdefs.h>
       
    25 #include "mpxdbabstractalbum.h"
       
    26 #include "mpxdbpluginqueries.h"
       
    27 #include "mpxdbmanager.h"
       
    28 #include "mpxdbcommonutil.h"
       
    29 #include "mpxcollectiondbstd.h"
       
    30 #include "mpxdbcommondef.h"
       
    31 #include "mpxcollectiondbdef.h"
       
    32 
       
    33 #ifdef RD_MPX_TNM_INTEGRATION
       
    34 _LIT( KImageFileType, "image/jpeg" );
       
    35 #endif //RD_MPX_TNM_INTEGRATION
       
    36 
       
    37 
       
    38 // CONSTANTS
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ==============================
       
    41 
       
    42 // ----------------------------------------------------------------------------
       
    43 // Two-phased constructor.
       
    44 // ----------------------------------------------------------------------------
       
    45 //
       
    46 CMPXDbAbstractAlbum* CMPXDbAbstractAlbum::NewL(
       
    47     CMPXDbManager& aDbManager,
       
    48     TMPXGeneralCategory aCategory, RFs& aFs)
       
    49     {
       
    50     MPX_FUNC("CMPXDbAbstractAlbum::NewL");
       
    51 
       
    52     CMPXDbAbstractAlbum* self = CMPXDbAbstractAlbum::NewLC(aDbManager, aCategory, aFs);
       
    53     CleanupStack::Pop(self);
       
    54     return self;
       
    55     }
       
    56 
       
    57 // ----------------------------------------------------------------------------
       
    58 // Two-phased constructor.
       
    59 // ----------------------------------------------------------------------------
       
    60 //
       
    61 CMPXDbAbstractAlbum* CMPXDbAbstractAlbum::NewLC(
       
    62     CMPXDbManager& aDbManager,
       
    63     TMPXGeneralCategory aCategory, RFs& aFs)
       
    64     {
       
    65     MPX_FUNC("CMPXDbAbstractAlbum::NewLC");
       
    66 
       
    67     CMPXDbAbstractAlbum* self = new (ELeave) CMPXDbAbstractAlbum(aDbManager, aCategory, aFs);
       
    68     CleanupStack::PushL(self);
       
    69     self->ConstructL();
       
    70     return self;
       
    71     }
       
    72 
       
    73 // ----------------------------------------------------------------------------
       
    74 // Destructor
       
    75 // ----------------------------------------------------------------------------
       
    76 //
       
    77 CMPXDbAbstractAlbum::~CMPXDbAbstractAlbum()
       
    78     {
       
    79     MPX_FUNC("CMPXDbAbstractAlbum::~CMPXDbAbstractAlbum");
       
    80 #ifdef RD_MPX_TNM_INTEGRATION
       
    81     if (iTNManager)
       
    82         delete iTNManager;
       
    83 #endif //RD_MPX_TNM_INTEGRATION
       
    84     }
       
    85 
       
    86 // ----------------------------------------------------------------------------
       
    87 // CMPXDbAbstractAlbum::GetDriveIdL
       
    88 // ----------------------------------------------------------------------------
       
    89 //
       
    90 TInt CMPXDbAbstractAlbum::GetDriveIdL(
       
    91     TUint32 aAbstractAlbumId)
       
    92     {
       
    93     MPX_FUNC("CMPXDbAbstractAlbum::GetDriveIdL");
       
    94     return MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(),
       
    95         ExecuteIntQueryL(KCriterionCategoryVolumeId, aAbstractAlbumId));
       
    96     }
       
    97 
       
    98 
       
    99 // ----------------------------------------------------------------------------
       
   100 // CMPXDbAbstractAlbum::AddItemL
       
   101 // ----------------------------------------------------------------------------
       
   102 //
       
   103 TUint32 CMPXDbAbstractAlbum::AddItemL(
       
   104     const TDesC& aUri,
       
   105     const TDesC& aName,
       
   106     const TDesC& aAlbumArtist,
       
   107     TInt aDriveId,
       
   108     TBool& aNewRecord,
       
   109     TBool aCaseSensitive)
       
   110     {
       
   111     MPX_FUNC("CMPXDbAbstractAlbum::AddItemL");
       
   112 
       
   113     TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXAbstractAlbum,
       
   114         aUri, aCaseSensitive));
       
   115     aNewRecord = !CategoryItemExistsL(aDriveId, rowId);
       
   116 
       
   117     if ( aNewRecord )
       
   118         {
       
   119         HBufC* uri = MPXDbCommonUtil::ProcessSingleQuotesLC(aUri);
       
   120         HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName);
       
   121         HBufC* albumartist = MPXDbCommonUtil::ProcessSingleQuotesLC(aAlbumArtist);
       
   122 
       
   123         iDbManager.ExecuteQueryL(aDriveId, KQueryAbstractAlbumInsert, rowId, uri, name, albumartist, 0, MPXDbCommonUtil::GetVolIdMatchDriveIdL(iDbManager.Fs(), aDriveId));
       
   124         CleanupStack::PopAndDestroy(3, uri);
       
   125         }
       
   126     else
       
   127         {
       
   128         MPX_DEBUG1("CMPXDbAbstractAlbum::AddItemL, increase song count for abstractalbum");
       
   129         // increment the number of songs for the category
       
   130         HBufC* query = PreProcessStringLC(KQueryCategoryIncrementSongCount);
       
   131         iDbManager.ExecuteQueryL(aDriveId, *query, rowId);
       
   132         CleanupStack::PopAndDestroy(query);
       
   133         }
       
   134 
       
   135     return rowId;
       
   136     }
       
   137 
       
   138 // ----------------------------------------------------------------------------
       
   139 // CMPXDbAbstractAlbum::AddUpdatedItemL
       
   140 // ----------------------------------------------------------------------------
       
   141 //
       
   142 TUint32 CMPXDbAbstractAlbum::AddUpdatedItemL(TUint32 aOldId, const TDesC& newUri)
       
   143     {
       
   144     MPX_FUNC("CMPXDbAbstractAlbum::AddUpdatedItemL");
       
   145     iRenameTN = ETrue;
       
   146     
       
   147     //get the existing item based on aOldId
       
   148     HBufC* query = NULL;
       
   149     query = PreProcessStringLC(KQueryCategoryItem);
       
   150     RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query, aOldId));
       
   151     CleanupStack::PopAndDestroy(query);
       
   152     
       
   153     CleanupClosePushL(recordset);
       
   154     TBool newRecord(ETrue);
       
   155     if (recordset.Next() != KSqlAtRow)
       
   156         {
       
   157         User::Leave(KErrNotFound);
       
   158         }
       
   159     //save the existing entry fields values for renaming purpose
       
   160     const TDesC& name(MPXDbCommonUtil::GetColumnTextL (recordset, EAbstractAlbumName));
       
   161     const TDesC& albumartist(MPXDbCommonUtil::GetColumnTextL (recordset, EAbstractAlbumArtist));
       
   162 
       
   163     TUint32 itemId = AddItemL(newUri, name, albumartist, GetDriveIdL(aOldId), newRecord, EFalse);
       
   164     CleanupStack::PopAndDestroy(&recordset);
       
   165 
       
   166     return itemId;
       
   167     }
       
   168 
       
   169 // ----------------------------------------------------------------------------
       
   170 // CMPXDbAbstractAlbum::DecrementSongsForCategoryL
       
   171 // ----------------------------------------------------------------------------
       
   172 //
       
   173 void CMPXDbAbstractAlbum::DecrementSongsForCategoryL(
       
   174     const TUint32 aId,
       
   175     TInt aDriveId,
       
   176     CMPXMessageArray* aItemChangedMessages,
       
   177     TBool& aItemExist,
       
   178     TBool aMtpInUse)
       
   179     {
       
   180     MPX_FUNC("CMPXDbAbstractAlbum::DecrementSongsForCategoryL");
       
   181     
       
   182     TInt songCount = GetSongsCountL(aDriveId, aId);
       
   183     //while MTP connection, just decrease songCount in DB, do not do deletion.
       
   184     if ( songCount > 0 )
       
   185         {
       
   186         aItemExist = ETrue;
       
   187         // decrement the number of songs for the category
       
   188         HBufC* query = PreProcessStringLC(KQueryCategoryDecrementSongCount);
       
   189         iDbManager.ExecuteQueryL(aDriveId, *query, aId);
       
   190         CleanupStack::PopAndDestroy(query);
       
   191         songCount--;
       
   192         }
       
   193     if (songCount == 0)
       
   194         {
       
   195         //get uri
       
   196         HBufC* uri = GetUriL(aId);
       
   197         CleanupStack::PushL(uri);
       
   198             
       
   199         if (!aMtpInUse)
       
   200 	        {       
       
   201 	        DeleteAbstractAlbumEntryL(aId, aDriveId);
       
   202 	        MPX_DEBUG1("CMPXDbAbstractAlbum::DecrementSongsForCategoryL,implicitly delete AbstractAlbum Object when it has 0 references");
       
   203 	        aItemExist = EFalse;
       
   204 	        if (aItemChangedMessages)
       
   205 	            {
       
   206 	            // add the item changed message
       
   207 	            MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aId, EMPXItemDeleted,
       
   208 	                EMPXAbstractAlbum, KDBPluginUid);
       
   209 	            }
       
   210 	        //delete .alb file from file system                
       
   211 	        TInt err = BaflUtils::DeleteFile(iFs, *uri);                       
       
   212 	        if(KErrNone != err)
       
   213 	            {
       
   214 	            MPX_DEBUG2("CMPXDbAbstractAlbum::DecrementSongsForCategoryL,File not deleted from file system with err=%d", err);
       
   215 	            }   
       
   216 	        }
       
   217         if(!iRenameTN)
       
   218 	        {
       
   219 	        HandleTNL(*uri);
       
   220 	        }   
       
   221         CleanupStack::PopAndDestroy(uri);
       
   222         }  
       
   223     }
       
   224 
       
   225 // ----------------------------------------------------------------------------
       
   226 // Remove abstractalbums which have no songs associated.
       
   227 // ----------------------------------------------------------------------------
       
   228 //
       
   229 void CMPXDbAbstractAlbum::RemoveAbstractAlbumsWithNoSongL()
       
   230     {
       
   231     MPX_FUNC("CMPXDbAbstractAlbum::RemoveAbstractAlbumsWithNoSongL");
       
   232     
       
   233     RArray<TUint32> iItemsIds;
       
   234     CleanupClosePushL(iItemsIds);
       
   235     
       
   236     //get all abstractalbum with no songs associated.
       
   237     GetAllItemsWithNoSongL(iItemsIds);
       
   238     TInt count = iItemsIds.Count();
       
   239     TInt err = KErrNone;
       
   240     if (count)
       
   241         {           	
       
   242         MPX_DEBUG2("CMPXDbAbstractAlbum::RemoveAbstractAlbumsWithNoSongL, abstractalbum count[%d] ", iItemsIds.Count());
       
   243         CMPXMessageArray* itemChangedMessages = CMPXMediaArray::NewL();
       
   244         CleanupStack::PushL(itemChangedMessages);
       
   245 
       
   246         //go through each one to delete
       
   247         for (TInt i=0; i< count; i++)
       
   248             {
       
   249             TRAP(err, RemoveAbstractAlbumL(iItemsIds[i], *itemChangedMessages, EFalse));
       
   250             if (err != KErrNone)
       
   251                 {
       
   252                 MPX_DEBUG2("CMPXDbAbstractAlbum::RemoveAbstractAlbumsWithNoSongL, error happens when delete abstractalbum, err ", err);
       
   253                 }
       
   254             }
       
   255        CleanupStack::PopAndDestroy(itemChangedMessages);
       
   256        }
       
   257     CleanupStack::PopAndDestroy(&iItemsIds);
       
   258   }
       
   259 
       
   260 // ----------------------------------------------------------------------------
       
   261 // Remove .alb entry from AbstractAlnum table, TN table if .alb files deleted 
       
   262 // from file manager when refresh library
       
   263 // ----------------------------------------------------------------------------
       
   264 //
       
   265 void CMPXDbAbstractAlbum::AbstractAlbumCleanUpL()
       
   266     {
       
   267     MPX_FUNC("CMPXDbAbstractAlbum::AbstractAlbumCleanUpL");
       
   268     RArray<TMPXAttribute> attributes;
       
   269     CleanupClosePushL(attributes);
       
   270     attributes.AppendL(KMPXMediaGeneralUri);
       
   271     CMPXMediaArray* mediaArray = CMPXMediaArray::NewL();
       
   272     CleanupStack::PushL(mediaArray);
       
   273     
       
   274     GetAllCategoryItemsL(attributes.Array(), *mediaArray);
       
   275 
       
   276     TInt count(mediaArray->Count());
       
   277     if (count)
       
   278         {      
       
   279         CMPXMessageArray* itemChangedMessages = CMPXMediaArray::NewL();
       
   280         CleanupStack::PushL(itemChangedMessages);
       
   281         for (TInt i = 0; i < count; i++)
       
   282             {
       
   283             CMPXMedia* element = mediaArray->AtL(i);
       
   284             const TDesC& uri = element->ValueText(KMPXMediaGeneralUri);                                 
       
   285 
       
   286             //check if the file exists in file system
       
   287             if (!(BaflUtils::FileExists(iFs, uri)))
       
   288                 {
       
   289                 //generate abstractalbum UID with the Uri
       
   290                 TUint32 abstractAlbumId(MPXDbCommonUtil::GenerateUniqueIdL(iFs, EMPXAbstractAlbum, uri, EFalse));
       
   291                 RemoveAbstractAlbumL(abstractAlbumId, *itemChangedMessages, ETrue);             
       
   292                 }
       
   293             }
       
   294             CleanupStack::PopAndDestroy(itemChangedMessages);
       
   295         }
       
   296         CleanupStack::PopAndDestroy(mediaArray);       
       
   297         CleanupStack::PopAndDestroy(&attributes);     
       
   298     }
       
   299 
       
   300 // ----------------------------------------------------------------------------
       
   301 // CMPXDbAbstractAlbum::RemoveAbstractAlbumL
       
   302 // ----------------------------------------------------------------------------
       
   303 //
       
   304 void CMPXDbAbstractAlbum::RemoveAbstractAlbumL(TUint32 aAbstractAlbumId, 
       
   305     CMPXMessageArray& aItemChangedMessages, TBool aFileDeleted)
       
   306     {
       
   307     MPX_FUNC("CMPXDbAbstractAlbum::RemoveAbstractAlbumL");
       
   308     HBufC* uri = GetUriL(aAbstractAlbumId);
       
   309     CleanupStack::PushL(uri);
       
   310     
       
   311     DeleteAbstractAlbumEntryL(aAbstractAlbumId);
       
   312     HandleTNL(*uri);
       
   313     if (!aFileDeleted)
       
   314         {             
       
   315         TInt err = BaflUtils::DeleteFile(iFs, *uri);                       
       
   316         if(KErrNone != err)
       
   317             {
       
   318             MPX_DEBUG2("CMPXDbAbstractAlbum::RemoveAbstractAlbumL,File not deleted from file system with err=%d", err);
       
   319             }   
       
   320         }   
       
   321     MPXDbCommonUtil::AddItemChangedMessageL(aItemChangedMessages, aAbstractAlbumId, EMPXItemDeleted, EMPXAbstractAlbum, KDBPluginUid);            
       
   322     CleanupStack::PopAndDestroy(uri);
       
   323     }
       
   324 
       
   325 
       
   326 // ----------------------------------------------------------------------------
       
   327 // CMPXDbAbstractAlbum::HandleTNL
       
   328 // ----------------------------------------------------------------------------
       
   329 //
       
   330 void CMPXDbAbstractAlbum::HandleTNL( const TDesC& aOldPath,
       
   331         const TDesC& aNewPath, TInt aPriority )
       
   332   {
       
   333   MPX_FUNC("CMPXDbAbstractAlbum::HandleTNL");
       
   334   if (!iTNManager)
       
   335       {
       
   336       CreateTNMSessionL();
       
   337       }
       
   338   if (aNewPath.Compare(KNullDesC)==0 && aOldPath.Compare(KNullDesC)!=0)
       
   339       {         
       
   340       // remove from thumbnail database table
       
   341       MPX_DEBUG1("CMPXDbAbstractAlbum::HandleTNL, delete TN");  
       
   342       CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC(
       
   343                aOldPath, KImageFileType );
       
   344       iTNManager->DeleteThumbnails( *source );
       
   345           
       
   346       CleanupStack::PopAndDestroy( source );
       
   347       }
       
   348    else if (aNewPath.Compare(KNullDesC)!=0)
       
   349       {
       
   350       //rename thumbnail
       
   351       MPX_DEBUG1("CMPXDbAbstractAlbum::HandleTNL, rename Thumbnail entry in Thumbnail table");
       
   352     
       
   353       iTNManager->RenameThumbnailsL( aOldPath,  aNewPath, aPriority );  
       
   354       //after rename, reset flag
       
   355       iRenameTN = EFalse;
       
   356       }
       
   357  }
       
   358 
       
   359 
       
   360 // ----------------------------------------------------------------------------
       
   361 // CMPXDbAbstractAlbum::UpdateItemL
       
   362 // ----------------------------------------------------------------------------
       
   363 //
       
   364 void CMPXDbAbstractAlbum::UpdateItemL(
       
   365     TUint32 aId,
       
   366     const CMPXMedia& aMedia,
       
   367     TInt aDriveId,
       
   368     CMPXMessageArray* aItemChangedMessages)
       
   369     {
       
   370     MPX_FUNC("CMPXDbAbstractAlbum::UpdateItemL");
       
   371 
       
   372     CDesCArrayFlat* fields = new (ELeave) CDesCArrayFlat(EAbstractAlbumFieldCount);
       
   373     CleanupStack::PushL(fields);
       
   374     CDesCArrayFlat* values = new (ELeave) CDesCArrayFlat(EAbstractAlbumFieldCount);
       
   375     CleanupStack::PushL(values);
       
   376 
       
   377     // process the media parameter and construct the fields and values array
       
   378     GenerateAbstractAlbumFieldsValuesL(aMedia, *fields, *values);
       
   379 
       
   380     // construct the SET string
       
   381     HBufC* setStr = MPXDbCommonUtil::StringFromArraysLC(*fields, *values, KMCEqualSign, KMCCommaSign);
       
   382 
       
   383     if (setStr->Length())
       
   384         {
       
   385         // execute the query
       
   386         iDbManager.ExecuteQueryL(aDriveId, KQueryAbstractAlbumUpdate, setStr, aId);
       
   387         MPXDbCommonUtil::AddItemAlbumChangedMessageL(*aItemChangedMessages, aId, EMPXItemModified,
       
   388                 EMPXAbstractAlbum, KDBPluginUid, ETrue, 0 );
       
   389         }
       
   390     CleanupStack::PopAndDestroy(setStr);
       
   391     CleanupStack::PopAndDestroy(values);
       
   392     CleanupStack::PopAndDestroy(fields);
       
   393     }
       
   394 
       
   395 
       
   396 // ----------------------------------------------------------------------------
       
   397 // CMPXDbAbstractAlbum::GetUriL
       
   398 // ----------------------------------------------------------------------------
       
   399 //
       
   400 HBufC* CMPXDbAbstractAlbum::GetUriL(
       
   401     TUint32 aId)
       
   402     {
       
   403     MPX_FUNC("CMPXDbAbstractAlbum::GetUriL");
       
   404 
       
   405     RSqlStatement recordset(GetCategoryRecordL(aId));
       
   406     CleanupClosePushL(recordset);
       
   407     HBufC* uri = NULL;
       
   408     if (recordset.Next() == KSqlAtRow)
       
   409         {
       
   410         uri = MPXDbCommonUtil::GetColumnTextL(recordset, EAbstractAlbumUri).AllocL();     
       
   411         }
       
   412     else
       
   413         {
       
   414         //entry is deleted due to garbage collection 
       
   415         MPX_DEBUG1("CMPXDbAbstractAlbum::GetUriL, no uri, entry is deleted due to garbage collection"); 
       
   416         TPtrC nullUri(KNullDesC);
       
   417         uri = nullUri.AllocL();
       
   418         }
       
   419     CleanupStack::PopAndDestroy(&recordset);    
       
   420     return uri;
       
   421     }
       
   422 
       
   423 
       
   424 // ----------------------------------------------------------------------------
       
   425 // CMPXDbAbstractAlbum::UpdateMediaL
       
   426 // ----------------------------------------------------------------------------
       
   427 //
       
   428 void CMPXDbAbstractAlbum::UpdateMediaL(
       
   429     RSqlStatement& aRecord,
       
   430     const TArray<TMPXAttribute>& aAttrs,
       
   431     CMPXMedia& aMedia)
       
   432     {
       
   433     MPX_FUNC("CMPXDbAbstractAlbum::UpdateMediaL");
       
   434 
       
   435     TInt count(aAttrs.Count());
       
   436     for (TInt i = 0; i < count; ++i)
       
   437        {
       
   438        TInt contentId(aAttrs[i].ContentId());
       
   439        TUint attributeId(aAttrs[i].AttributeId());
       
   440 
       
   441            if (contentId == KMPXMediaIdGeneral)
       
   442                {
       
   443                if (attributeId & EMPXMediaGeneralId)
       
   444                    {
       
   445                    MPX_DEBUG1("    EMPXMediaGeneralId");
       
   446                    aMedia.SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId,
       
   447                        aRecord.ColumnInt64(EAbstractAlbumUniqueId));
       
   448                    }
       
   449                if (attributeId & EMPXMediaGeneralTitle)
       
   450                    {
       
   451                    MPX_DEBUG1("    EMPXMediaGeneralTitle");
       
   452                    TPtrC title(MPXDbCommonUtil::GetColumnTextL(aRecord, EAbstractAlbumName));
       
   453                    aMedia.SetTextValueL(KMPXMediaGeneralTitle, title);
       
   454                    MPX_DEBUG2("    AbstractAlbumName[%S]", &title);
       
   455                    }
       
   456                if (attributeId & EMPXMediaGeneralCount)
       
   457                    {
       
   458                    MPX_DEBUG1("    EMPXMediaGeneralCount");
       
   459                    TInt songCount = GetSongsCountL(KDbManagerAllDrives,
       
   460                                 aRecord.ColumnInt64(EAbstractAlbumUniqueId));
       
   461                    aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralCount, songCount );
       
   462                    }
       
   463                if (attributeId & EMPXMediaGeneralDrive ||
       
   464                     (attributeId & EMPXMediaGeneralUri))
       
   465                    {                       
       
   466                    TUint32 volId(aRecord.ColumnInt64(EAbstractAlbumVolumeId));
       
   467                    TInt driveId = MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), volId);
       
   468                    MPX_DEBUG3("volId = %d, driveId = %d", volId, driveId);
       
   469 
       
   470                    // handle possibly delay from framework notification
       
   471                    if (driveId < 0)
       
   472                        {
       
   473                        MPX_DEBUG1("invalid driveId, leave with KErrNotReady");
       
   474                        User::Leave(KErrNotReady);
       
   475                        }
       
   476                    TDriveUnit driveUnit(driveId);
       
   477                    if (attributeId & EMPXMediaGeneralUri)
       
   478                        {                              
       
   479                        TPtrC uri(MPXDbCommonUtil::GetColumnTextL(aRecord, EAbstractAlbumUri));
       
   480                        aMedia.SetTextValueL(KMPXMediaGeneralUri, uri);
       
   481                        MPX_DEBUG2("    AbstractAlbum URI[%S]", &uri);
       
   482                        }
       
   483                   if (attributeId & EMPXMediaGeneralDrive)
       
   484                        {
       
   485                        aMedia.SetTextValueL(KMPXMediaGeneralDrive, driveUnit.Name());
       
   486                        }
       
   487                    }
       
   488                } // end if contentId == KMPXMediaIdGeneral
       
   489 
       
   490            else if ( contentId == KMPXMediaIdMusic)
       
   491                {
       
   492                if (attributeId & EMPXMediaMusicAlbumArtist)
       
   493                    {
       
   494                    MPX_DEBUG1("    EMPXMediaMusicAlbumArtist");
       
   495                    TPtrC albumartist(MPXDbCommonUtil::GetColumnTextL(aRecord, EAbstractAlbumArtist));
       
   496                    aMedia.SetTextValueL(KMPXMediaMusicAlbumArtist, albumartist);
       
   497                    MPX_DEBUG2("    albumartist[%S]", &albumartist);
       
   498                    }
       
   499                }
       
   500 
       
   501            } // end for
       
   502        aMedia.SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem);
       
   503        aMedia.SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXAbstractAlbum);
       
   504     }
       
   505 
       
   506 // ----------------------------------------------------------------------------
       
   507 // CMPXDbAbstractAlbum::GetAllItemsWithNoSongL
       
   508 // ----------------------------------------------------------------------------
       
   509 //
       
   510 void CMPXDbAbstractAlbum::GetAllItemsWithNoSongL(RArray<TUint32>& aItemsIds)
       
   511     {
       
   512     MPX_FUNC("CMPXDbAbstractAlbum::GetAllItemsWithNoSongL");
       
   513     RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryAbstractAlbumsWithNoSong));
       
   514     CleanupClosePushL(recordset);
       
   515 
       
   516     TInt err(KErrNone);
       
   517     while ((err = recordset.Next()) == KSqlAtRow)
       
   518         {
       
   519         TUint32 uniqueID(recordset.ColumnInt64(EAbstractAlbumUniqueId));
       
   520         aItemsIds.AppendL(uniqueID);
       
   521         }
       
   522     CleanupStack::PopAndDestroy(&recordset);
       
   523     if (err!= KSqlAtEnd)
       
   524         {
       
   525         User::Leave(KErrCorrupt);
       
   526         } 	
       
   527     }
       
   528 
       
   529 
       
   530 // ----------------------------------------------------------------------------
       
   531 // CMPXDbAbstractAlbum::GenerateAbstractAlbumFieldsValuesL
       
   532 // ----------------------------------------------------------------------------
       
   533 //
       
   534 void CMPXDbAbstractAlbum::GenerateAbstractAlbumFieldsValuesL(const CMPXMedia& aMedia, CDesCArray& aFields, CDesCArray& aValues)
       
   535     {
       
   536     MPX_FUNC("CMPXDbAbstractAlbum::GenerateAbstractAlbumFieldsValuesL");
       
   537     //support Winlogo use case
       
   538     if (aMedia.IsSupported(KMPXMediaGeneralTitle))
       
   539         {
       
   540         TPtrC truncatedName(aMedia.ValueText(KMPXMediaGeneralTitle).Left(KMCMaxTextLen));
       
   541         MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCCategoryName, truncatedName);
       
   542         }
       
   543     //support Winlogo use case
       
   544     if (aMedia.IsSupported(KMPXMediaMusicAlbumArtist))
       
   545         {
       
   546         TPtrC truncatedAlbumArtist(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen));
       
   547         MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicAlbumArtist, truncatedAlbumArtist);
       
   548         }
       
   549      }
       
   550 
       
   551 // ----------------------------------------------------------------------------
       
   552 // CMPXDbAbstractAlbum::DeleteAbstractAlbumEntryL
       
   553 // ----------------------------------------------------------------------------
       
   554 //
       
   555 void CMPXDbAbstractAlbum::DeleteAbstractAlbumEntryL(
       
   556     TUint32 aAbstractAlbumId, TInt aDriveId)
       
   557     {
       
   558     MPX_FUNC("CMPXDbAbstractAlbum::DeleteAbstractAlbumEntryL");
       
   559 
       
   560     //delete entry from table        
       
   561     if (aDriveId)
       
   562         DeleteCategoryL(aAbstractAlbumId, aDriveId);
       
   563     else
       
   564         {
       
   565         TInt drive = MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(),
       
   566         ExecuteIntQueryL(KCriterionCategoryVolumeId, aAbstractAlbumId));
       
   567         DeleteCategoryL(aAbstractAlbumId, drive);
       
   568         }
       
   569     }
       
   570 
       
   571 // ----------------------------------------------------------------------------
       
   572 // CMPXDbAlbum::CreateTableL
       
   573 // ----------------------------------------------------------------------------
       
   574 //
       
   575 void CMPXDbAbstractAlbum::CreateTableL(
       
   576     RSqlDatabase& aDatabase,
       
   577     TBool /* aCorruptTable */)
       
   578     {
       
   579     MPX_FUNC("CMPXDbAbstractAlbum::CreateTableL");
       
   580 
       
   581     // create the table
       
   582     HBufC* query = PreProcessStringLC(KAbstractAlbumCreateTable);
       
   583     User::LeaveIfError(aDatabase.Exec(*query));
       
   584     CleanupStack::PopAndDestroy(query);
       
   585 
       
   586     // do not create an index on the Name field
       
   587     // as it only slows down the insert/update queries overall
       
   588     }
       
   589 
       
   590 // ----------------------------------------------------------------------------
       
   591 // CMPXDbAlbum::CheckTableL
       
   592 // ----------------------------------------------------------------------------
       
   593 //
       
   594 TBool CMPXDbAbstractAlbum::CheckTableL(
       
   595     RSqlDatabase& aDatabase)
       
   596     {
       
   597     MPX_FUNC("CMPXDbAbstractAlbum::CheckTableL");
       
   598 
       
   599     HBufC* query = PreProcessStringLC(KAbstractAlbumCheckTable);
       
   600     TBool check(DoCheckTable(aDatabase, *query));
       
   601     CleanupStack::PopAndDestroy(query);
       
   602 
       
   603     return check;
       
   604     }
       
   605 
       
   606 
       
   607 // ----------------------------------------------------------------------------
       
   608 // Constructor
       
   609 // ----------------------------------------------------------------------------
       
   610 //
       
   611 CMPXDbAbstractAlbum::CMPXDbAbstractAlbum(
       
   612     CMPXDbManager& aDbManager,
       
   613     TMPXGeneralCategory aCategory, RFs& aFs) :
       
   614     CMPXDbCategory(aDbManager, aCategory),
       
   615     iTNManager(NULL),
       
   616     iFs(aFs)
       
   617     {
       
   618     MPX_FUNC("CMPXDbAbstractAlbum::CMPXDbAbstractAlbum");
       
   619     }
       
   620 
       
   621 // ----------------------------------------------------------------------------
       
   622 // Second phase constructor.
       
   623 // ----------------------------------------------------------------------------
       
   624 //
       
   625 void CMPXDbAbstractAlbum::ConstructL()
       
   626     {
       
   627     MPX_FUNC("CMPXDbAbstractAlbum::ConstructL");
       
   628 
       
   629     BaseConstructL();
       
   630     iRenameTN = EFalse;
       
   631     }
       
   632 
       
   633 
       
   634 
       
   635 // ---------------------------------------------------------------------------
       
   636 // CMPXDbAbstractAlbum::ThumbnailReady
       
   637 // Callback but not used here
       
   638 // ---------------------------------------------------------------------------
       
   639 void CMPXDbAbstractAlbum::ThumbnailPreviewReady(
       
   640         MThumbnailData& /*aThumbnail*/, TThumbnailRequestId /*aId*/ )
       
   641     {
       
   642     }
       
   643 
       
   644 
       
   645 // ---------------------------------------------------------------------------
       
   646 // CMPXDbAbstractAlbum::ThumbnailReady
       
   647 // Callback but not used here
       
   648 // ---------------------------------------------------------------------------
       
   649 void CMPXDbAbstractAlbum::ThumbnailReady( TInt /*aError*/,
       
   650         MThumbnailData& /*aThumbnail*/, TThumbnailRequestId /*aId*/ )
       
   651     {
       
   652     }
       
   653 
       
   654 // ---------------------------------------------------------------------------
       
   655 // CMPXDbAbstractAlbum::CreateTNMSessionL
       
   656 // Create thumbnail session
       
   657 // ---------------------------------------------------------------------------    
       
   658 void CMPXDbAbstractAlbum::CreateTNMSessionL()
       
   659     {
       
   660     if(!iTNManager)
       
   661         {
       
   662         iTNManager = CThumbnailManager::NewL( *this );
       
   663         }
       
   664     }
       
   665 // End of File