mpserviceplugins/mpxsqlitedbhgplugin/src/mpxdbabstractalbum.cpp
changeset 25 3ec52facab4d
parent 22 ecf06a08d4d9
child 29 8192e5b5c935
equal deleted inserted replaced
22:ecf06a08d4d9 25:3ec52facab4d
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Responsible for interation with the category tables:
    14 * Description:  Responsible for interation with the category tables:
    15 *                Artist, Album, Genre, Composer and AbstractAlbum
    15 *                Artist, Album, Genre, Composer and AbstractAlbum
    16 *
    16 *
       
    17 *
    17 */
    18 */
    18 
    19 
    19 
    20 
    20 // INCLUDE FILES
    21 // INCLUDE FILES
    21 #include <mpxlog.h>
    22 #include <mpxlog.h>
    34 #endif //RD_MPX_TNM_INTEGRATION
    35 #endif //RD_MPX_TNM_INTEGRATION
    35 
    36 
    36 
    37 
    37 // CONSTANTS
    38 // CONSTANTS
    38 
    39 
    39 
       
    40 
       
    41 
       
    42 // ============================ MEMBER FUNCTIONS ==============================
    40 // ============================ MEMBER FUNCTIONS ==============================
    43 
    41 
    44 // ----------------------------------------------------------------------------
    42 // ----------------------------------------------------------------------------
    45 // Two-phased constructor.
    43 // Two-phased constructor.
    46 // ----------------------------------------------------------------------------
    44 // ----------------------------------------------------------------------------
    47 //
    45 //
    48 CMPXDbAbstractAlbum* CMPXDbAbstractAlbum::NewL(
    46 CMPXDbAbstractAlbum* CMPXDbAbstractAlbum::NewL(
    49     CMPXDbManager& aDbManager,
    47     CMPXDbManager& aDbManager,
    50     TMPXGeneralCategory aCategory)
    48     TMPXGeneralCategory aCategory, RFs& aFs)
    51     {
    49     {
    52     MPX_FUNC("CMPXDbAbstractAlbum::NewL");
    50     MPX_FUNC("CMPXDbAbstractAlbum::NewL");
    53 
    51 
    54     CMPXDbAbstractAlbum* self = CMPXDbAbstractAlbum::NewLC(aDbManager, aCategory);
    52     CMPXDbAbstractAlbum* self = CMPXDbAbstractAlbum::NewLC(aDbManager, aCategory, aFs);
    55     CleanupStack::Pop(self);
    53     CleanupStack::Pop(self);
    56     return self;
    54     return self;
    57     }
    55     }
    58 
    56 
    59 // ----------------------------------------------------------------------------
    57 // ----------------------------------------------------------------------------
    60 // Two-phased constructor.
    58 // Two-phased constructor.
    61 // ----------------------------------------------------------------------------
    59 // ----------------------------------------------------------------------------
    62 //
    60 //
    63 CMPXDbAbstractAlbum* CMPXDbAbstractAlbum::NewLC(
    61 CMPXDbAbstractAlbum* CMPXDbAbstractAlbum::NewLC(
    64     CMPXDbManager& aDbManager,
    62     CMPXDbManager& aDbManager,
    65     TMPXGeneralCategory aCategory)
    63     TMPXGeneralCategory aCategory, RFs& aFs)
    66     {
    64     {
    67     MPX_FUNC("CMPXDbAbstractAlbum::NewLC");
    65     MPX_FUNC("CMPXDbAbstractAlbum::NewLC");
    68 
    66 
    69     CMPXDbAbstractAlbum* self = new (ELeave) CMPXDbAbstractAlbum(aDbManager, aCategory);
    67     CMPXDbAbstractAlbum* self = new (ELeave) CMPXDbAbstractAlbum(aDbManager, aCategory, aFs);
    70     CleanupStack::PushL(self);
    68     CleanupStack::PushL(self);
    71     self->ConstructL();
    69     self->ConstructL();
    72     return self;
    70     return self;
    73     }
    71     }
    74 
    72 
   100 // ----------------------------------------------------------------------------
    98 // ----------------------------------------------------------------------------
   101 // CMPXDbAbstractAlbum::AddItemL
    99 // CMPXDbAbstractAlbum::AddItemL
   102 // ----------------------------------------------------------------------------
   100 // ----------------------------------------------------------------------------
   103 //
   101 //
   104 TUint32 CMPXDbAbstractAlbum::AddItemL(
   102 TUint32 CMPXDbAbstractAlbum::AddItemL(
       
   103     const TDesC& aUri,
   105     const TDesC& aName,
   104     const TDesC& aName,
   106     const TDesC& aAlbumArtist,
   105     const TDesC& aAlbumArtist,
   107     const TDesC& aGenre,
       
   108     TInt aDriveId,
   106     TInt aDriveId,
   109     TBool& aNewRecord,
   107     TBool& aNewRecord,
   110     TBool aCaseSensitive)
   108     TBool aCaseSensitive)
   111     {
   109     {
   112     MPX_FUNC("CMPXDbAbstractAlbum::AddItemL");
   110     MPX_FUNC("CMPXDbAbstractAlbum::AddItemL");
   113 
   111 
   114     TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXAbstractAlbum,
   112     TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), EMPXAbstractAlbum,
   115         aName, aCaseSensitive));
   113         aUri, aCaseSensitive));
   116   
   114     aNewRecord = !CategoryItemExistsL(aDriveId, rowId);
       
   115 
   117     if ( aNewRecord )
   116     if ( aNewRecord )
   118         {
   117         {
       
   118         HBufC* uri = MPXDbCommonUtil::ProcessSingleQuotesLC(aUri);
   119         HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName);
   119         HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName);
   120         HBufC* albumartist = MPXDbCommonUtil::ProcessSingleQuotesLC(aAlbumArtist);
   120         HBufC* albumartist = MPXDbCommonUtil::ProcessSingleQuotesLC(aAlbumArtist);
   121         HBufC* genre = MPXDbCommonUtil::ProcessSingleQuotesLC(aGenre);
   121 
   122         
   122         iDbManager.ExecuteQueryL(aDriveId, KQueryAbstractAlbumInsert, rowId, uri, name, albumartist, 0, MPXDbCommonUtil::GetVolIdMatchDriveIdL(iDbManager.Fs(), aDriveId));
   123         iDbManager.ExecuteQueryL(aDriveId, KQueryAbstractAlbumInsert, rowId, name, albumartist, genre, 0, MPXDbCommonUtil::GetVolIdMatchDriveIdL(iDbManager.Fs(), aDriveId));
   123         CleanupStack::PopAndDestroy(3, uri);
   124         CleanupStack::PopAndDestroy(3, name);        
       
   125         }
   124         }
   126     else
   125     else
   127         {
   126         {
       
   127         MPX_DEBUG1("CMPXDbAbstractAlbum::AddItemL, increase song count for abstractalbum");
   128         // increment the number of songs for the category
   128         // increment the number of songs for the category
   129         HBufC* query = PreProcessStringLC(KQueryCategoryIncrementSongCount);
   129         HBufC* query = PreProcessStringLC(KQueryCategoryIncrementSongCount);
   130         iDbManager.ExecuteQueryL(aDriveId, *query, rowId);
   130         iDbManager.ExecuteQueryL(aDriveId, *query, rowId);
   131         CleanupStack::PopAndDestroy(query);
   131         CleanupStack::PopAndDestroy(query);
   132         }
   132         }
   133 
   133 
   134     return rowId;
   134     return rowId;
   135     }
   135     }
   136 
   136 
   137 
   137 // ----------------------------------------------------------------------------
       
   138 // CMPXDbAbstractAlbum::AddUpdatedItemL
       
   139 // ----------------------------------------------------------------------------
       
   140 //
       
   141 TUint32 CMPXDbAbstractAlbum::AddUpdatedItemL(TUint32 aOldId, const TDesC& newUri)
       
   142     {
       
   143     MPX_FUNC("CMPXDbAbstractAlbum::AddUpdatedItemL");
       
   144     iRenameTN = ETrue;
       
   145     
       
   146     //get the existing item based on aOldId
       
   147     HBufC* query = NULL;
       
   148     query = PreProcessStringLC(KQueryCategoryItem);
       
   149     RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query, aOldId));
       
   150     CleanupStack::PopAndDestroy(query);
       
   151     
       
   152     CleanupClosePushL(recordset);
       
   153     TBool newRecord(ETrue);
       
   154     if (recordset.Next() != KSqlAtRow)
       
   155         {
       
   156         User::Leave(KErrNotFound);
       
   157         }
       
   158     //save the existing entry fields values for renaming purpose
       
   159     const TDesC& name(MPXDbCommonUtil::GetColumnTextL (recordset, EAbstractAlbumName));
       
   160     const TDesC& albumartist(MPXDbCommonUtil::GetColumnTextL (recordset, EAbstractAlbumArtist));
       
   161 
       
   162     TUint32 itemId = AddItemL(newUri, name, albumartist, GetDriveIdL(aOldId), newRecord, EFalse);
       
   163     CleanupStack::PopAndDestroy(&recordset);
       
   164 
       
   165     return itemId;
       
   166     }
   138 
   167 
   139 // ----------------------------------------------------------------------------
   168 // ----------------------------------------------------------------------------
   140 // CMPXDbAbstractAlbum::DecrementSongsForCategoryL
   169 // CMPXDbAbstractAlbum::DecrementSongsForCategoryL
   141 // ----------------------------------------------------------------------------
   170 // ----------------------------------------------------------------------------
   142 //
   171 //
   148     TBool aMtpInUse)
   177     TBool aMtpInUse)
   149     {
   178     {
   150     MPX_FUNC("CMPXDbAbstractAlbum::DecrementSongsForCategoryL");
   179     MPX_FUNC("CMPXDbAbstractAlbum::DecrementSongsForCategoryL");
   151     
   180     
   152     TInt songCount = GetSongsCountL(aDriveId, aId);
   181     TInt songCount = GetSongsCountL(aDriveId, aId);
   153        // if just one song uses this category. Use <= just in case
   182     //while MTP connection, just decrease songCount in DB, do not do deletion.
   154        //while MTP connection, just decrease songCount in DB, do not do deletion.
       
   155     if ( songCount > 0 )
   183     if ( songCount > 0 )
   156         {
   184         {
   157         aItemExist = ETrue;
   185         aItemExist = ETrue;
   158         // decrement the number of songs for the category
   186         // decrement the number of songs for the category
   159         HBufC* query = PreProcessStringLC(KQueryCategoryDecrementSongCount);
   187         HBufC* query = PreProcessStringLC(KQueryCategoryDecrementSongCount);
   160         iDbManager.ExecuteQueryL(aDriveId, *query, aId);
   188         iDbManager.ExecuteQueryL(aDriveId, *query, aId);
   161         CleanupStack::PopAndDestroy(query);
   189         CleanupStack::PopAndDestroy(query);
   162         songCount--;
   190         songCount--;
   163         }
   191         }
       
   192     if (songCount == 0)
       
   193         {
       
   194         //get uri
       
   195         HBufC* uri = GetUriL(aId);
       
   196         CleanupStack::PushL(uri);
       
   197             
       
   198         if (!aMtpInUse)
       
   199 	        {       
       
   200 	        DeleteAbstractAlbumEntryL(aId, aDriveId);
       
   201 	        MPX_DEBUG1("CMPXDbAbstractAlbum::DecrementSongsForCategoryL,implicitly delete AbstractAlbum Object when it has 0 references");
       
   202 	        aItemExist = EFalse;
       
   203 	        if (aItemChangedMessages)
       
   204 	            {
       
   205 	            // add the item changed message
       
   206 	            MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aId, EMPXItemDeleted,
       
   207 	                EMPXAbstractAlbum, KDBPluginUid);
       
   208 	            }
       
   209 	        //delete .alb file from file system                
       
   210 	        TInt err = BaflUtils::DeleteFile(iFs, *uri);                       
       
   211 	        if(KErrNone != err)
       
   212 	            {
       
   213 	            MPX_DEBUG2("CMPXDbAbstractAlbum::DecrementSongsForCategoryL,File not deleted from file system with err=%d", err);
       
   214 	            }   
       
   215 	        }
       
   216         if(!iRenameTN)
       
   217 	        {
       
   218 	        HandleTNL(*uri);
       
   219 	        }   
       
   220         CleanupStack::PopAndDestroy(uri);
       
   221         }  
       
   222     }
       
   223 
       
   224 // ----------------------------------------------------------------------------
       
   225 // CMPXDbAbstractAlbum::RemoveAbstractAlbumL
       
   226 // ----------------------------------------------------------------------------
       
   227 //
       
   228 void CMPXDbAbstractAlbum::RemoveAbstractAlbumL(TUint32 aAbstractAlbumId, 
       
   229     CMPXMessageArray& aItemChangedMessages, TBool aFileDeleted)
       
   230     {
       
   231     MPX_FUNC("CMPXDbAbstractAlbum::RemoveAbstractAlbumL");
       
   232     HBufC* uri = GetUriL(aAbstractAlbumId);
       
   233     CleanupStack::PushL(uri);
   164     
   234     
   165     if ((songCount == 0) && !aMtpInUse)
   235     DeleteAbstractAlbumEntryL(aAbstractAlbumId);
   166         {
   236     HandleTNL(*uri);
   167         HBufC* uri = DeleteAbstractAlbumL(aId, aDriveId);
   237     if (!aFileDeleted)
   168         MPX_DEBUG1("CMPXDbAbstractAlbum::DeleteAbstractAlbumL,implicitly delete AbstractAlbum Object when it has 0 references");  
   238         {             
   169         aItemExist = EFalse;
   239         TInt err = BaflUtils::DeleteFile(iFs, *uri);                       
   170         if (aItemChangedMessages)
       
   171             {
       
   172             // add the item changed message
       
   173             MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aId, EMPXItemDeleted,
       
   174                 EMPXAbstractAlbum, KDBPluginUid);   
       
   175             }
       
   176         delete uri;
       
   177         }
       
   178     }
       
   179 
       
   180 
       
   181 // ----------------------------------------------------------------------------
       
   182 // CMPXDbAbstractAlbum::DeleteAbstractAlbumL
       
   183 // ----------------------------------------------------------------------------
       
   184 //
       
   185 HBufC* CMPXDbAbstractAlbum::DeleteAbstractAlbumL(
       
   186     TUint32 aAbstractAlbumId, TInt aDriveId)
       
   187     {
       
   188     MPX_FUNC("CMPXDbAbstractAlbum::DeleteAbstractAlbumL");
       
   189 
       
   190     //before delete category, get the abstract album path
       
   191     HBufC* uri = GetNameL(aAbstractAlbumId);
       
   192     // delete the category
       
   193     if (uri)
       
   194         {
       
   195         CleanupStack::PushL(uri);
       
   196          
       
   197     if (aDriveId)
       
   198         DeleteCategoryL(aAbstractAlbumId, aDriveId);
       
   199     else
       
   200         {
       
   201         TInt drive = MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(),
       
   202             ExecuteIntQueryL(KCriterionCategoryVolumeId, aAbstractAlbumId));
       
   203         DeleteCategoryL(aAbstractAlbumId, drive);
       
   204         }
       
   205 //delete abstract album .alb from TN table
       
   206 #ifdef RD_MPX_TNM_INTEGRATION
       
   207         // remove from thumbnail database table
       
   208         CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC(
       
   209                 *uri, KImageFileType );
       
   210         iTNManager->DeleteThumbnails( *source );
       
   211         CleanupStack::PopAndDestroy( source );
       
   212 #endif //RD_MPX_TNM_INTEGRATION
       
   213 
       
   214        
       
   215         //delete abstract album .alb file from file system
       
   216         RFs rFs;
       
   217         User::LeaveIfError( rFs.Connect() );
       
   218         CleanupClosePushL( rFs );
       
   219 
       
   220         TInt err = BaflUtils::DeleteFile(rFs, *uri);
       
   221         if(KErrNone != err)
   240         if(KErrNone != err)
   222             {
   241             {
   223             MPX_DEBUG2("CMPXDbAbstractAlbum::DeleteAbstractAlbumL,File not deleted from file system with err=%d", err);
   242             MPX_DEBUG2("CMPXDbAbstractAlbum::RemoveAbstractAlbumL,File not deleted from file system with err=%d", err);
   224             }
   243             }   
   225 
   244         }   
   226         CleanupStack::PopAndDestroy( &rFs );
   245     MPXDbCommonUtil::AddItemChangedMessageL(aItemChangedMessages, aAbstractAlbumId, EMPXItemDeleted, EMPXAbstractAlbum, KDBPluginUid);            
   227         }
   246     CleanupStack::PopAndDestroy(uri);
   228 
   247     }
   229     CleanupStack::Pop(uri);
   248 
   230     return uri;
   249 
   231     }
   250 // ----------------------------------------------------------------------------
       
   251 // CMPXDbAbstractAlbum::HandleTNL
       
   252 // ----------------------------------------------------------------------------
       
   253 //
       
   254 void CMPXDbAbstractAlbum::HandleTNL( const TDesC& aOldPath,
       
   255         const TDesC& aNewPath, TInt aPriority )
       
   256   {
       
   257   MPX_FUNC("CMPXDbAbstractAlbum::HandleTNL");
       
   258 
       
   259   if (aNewPath.Compare(KNullDesC)==0 && aOldPath.Compare(KNullDesC)!=0)
       
   260       {         
       
   261       // remove from thumbnail database table
       
   262       MPX_DEBUG1("CMPXDbAbstractAlbum::HandleTNL, delete TN");  
       
   263       CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC(
       
   264                aOldPath, KImageFileType );
       
   265       iTNManager->DeleteThumbnails( *source );
       
   266       CleanupStack::PopAndDestroy( source );
       
   267       }
       
   268    else if (aNewPath.Compare(KNullDesC)!=0)
       
   269       {
       
   270       //rename thumbnail
       
   271       MPX_DEBUG1("CMPXDbAbstractAlbum::HandleTNL, rename TN");
       
   272       // TODO: uncomment when RenameThumbnailsL is supported.
       
   273       //iTNManager->RenameThumbnailsL( aOldPath,  aNewPath, aPriority );
       
   274       //after rename, reset flag
       
   275       iRenameTN = EFalse;
       
   276       }
       
   277  }
   232 
   278 
   233 
   279 
   234 // ----------------------------------------------------------------------------
   280 // ----------------------------------------------------------------------------
   235 // CMPXDbAbstractAlbum::UpdateItemL
   281 // CMPXDbAbstractAlbum::UpdateItemL
   236 // ----------------------------------------------------------------------------
   282 // ----------------------------------------------------------------------------
   259         // execute the query
   305         // execute the query
   260         iDbManager.ExecuteQueryL(aDriveId, KQueryAbstractAlbumUpdate, setStr, aId);
   306         iDbManager.ExecuteQueryL(aDriveId, KQueryAbstractAlbumUpdate, setStr, aId);
   261         MPXDbCommonUtil::AddItemAlbumChangedMessageL(*aItemChangedMessages, aId, EMPXItemModified,
   307         MPXDbCommonUtil::AddItemAlbumChangedMessageL(*aItemChangedMessages, aId, EMPXItemModified,
   262                 EMPXAbstractAlbum, KDBPluginUid, ETrue, 0 );
   308                 EMPXAbstractAlbum, KDBPluginUid, ETrue, 0 );
   263         }
   309         }
   264 
       
   265     CleanupStack::PopAndDestroy(setStr);
   310     CleanupStack::PopAndDestroy(setStr);
   266     CleanupStack::PopAndDestroy(values);
   311     CleanupStack::PopAndDestroy(values);
   267     CleanupStack::PopAndDestroy(fields);
   312     CleanupStack::PopAndDestroy(fields);
   268     }
   313     }
       
   314 
       
   315 
       
   316 // ----------------------------------------------------------------------------
       
   317 // CMPXDbAbstractAlbum::GetUriL
       
   318 // ----------------------------------------------------------------------------
       
   319 //
       
   320 HBufC* CMPXDbAbstractAlbum::GetUriL(
       
   321     TUint32 aId)
       
   322     {
       
   323     MPX_FUNC("CMPXDbAbstractAlbum::GetUriL");
       
   324 
       
   325     RSqlStatement recordset(GetCategoryRecordL(aId));
       
   326     CleanupClosePushL(recordset);
       
   327 
       
   328     if (recordset.Next() != KSqlAtRow)
       
   329         {
       
   330         User::LeaveIfError(KErrNotFound);
       
   331         }
       
   332     HBufC* uri = MPXDbCommonUtil::GetColumnTextL(recordset, EAbstractAlbumUri).AllocL();
       
   333     CleanupStack::PopAndDestroy(&recordset);
       
   334     return uri;
       
   335     }
       
   336 
   269 
   337 
   270 // ----------------------------------------------------------------------------
   338 // ----------------------------------------------------------------------------
   271 // CMPXDbAbstractAlbum::UpdateMediaL
   339 // CMPXDbAbstractAlbum::UpdateMediaL
   272 // ----------------------------------------------------------------------------
   340 // ----------------------------------------------------------------------------
   273 //
   341 //
   274 void CMPXDbAbstractAlbum::UpdateMediaL(
   342 void CMPXDbAbstractAlbum::UpdateMediaL(
   275     RSqlStatement& aRecord,
   343     RSqlStatement& aRecord,
   276     const TArray<TMPXAttribute>& aAttrs,
   344     const TArray<TMPXAttribute>& aAttrs,
   277     CMPXMedia& aMedia)
   345     CMPXMedia& aMedia)
   278     {
   346     {
   279      MPX_FUNC("CMPXDbAbstractAlbum::UpdateMediaL");
   347     MPX_FUNC("CMPXDbAbstractAlbum::UpdateMediaL");
   280 
   348 
   281        TInt count(aAttrs.Count());
   349     TInt count(aAttrs.Count());
   282        for (TInt i = 0; i < count; ++i)
   350     for (TInt i = 0; i < count; ++i)
   283            {
   351        {
   284            TInt contentId(aAttrs[i].ContentId());
   352        TInt contentId(aAttrs[i].ContentId());
   285            TUint attributeId(aAttrs[i].AttributeId());
   353        TUint attributeId(aAttrs[i].AttributeId());
   286 
   354 
   287            if (contentId == KMPXMediaIdGeneral)
   355            if (contentId == KMPXMediaIdGeneral)
   288                {
   356                {
   289                if (attributeId & EMPXMediaGeneralId)
   357                if (attributeId & EMPXMediaGeneralId)
   290                    {
   358                    {
       
   359                    MPX_DEBUG1("    EMPXMediaGeneralId");
   291                    aMedia.SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId,
   360                    aMedia.SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId,
   292                        aRecord.ColumnInt64(EAbstractAlbumUniqueId));
   361                        aRecord.ColumnInt64(EAbstractAlbumUniqueId));
   293                    }
   362                    }
   294                if (attributeId & EMPXMediaGeneralTitle)
   363                if (attributeId & EMPXMediaGeneralTitle)
   295                    {
   364                    {
       
   365                    MPX_DEBUG1("    EMPXMediaGeneralTitle");
   296                    TPtrC title(MPXDbCommonUtil::GetColumnTextL(aRecord, EAbstractAlbumName));
   366                    TPtrC title(MPXDbCommonUtil::GetColumnTextL(aRecord, EAbstractAlbumName));
   297                    aMedia.SetTextValueL(KMPXMediaGeneralTitle, title);
   367                    aMedia.SetTextValueL(KMPXMediaGeneralTitle, title);
   298                    MPX_DEBUG2("    AbstractAlbumName[%S]", &title);
   368                    MPX_DEBUG2("    AbstractAlbumName[%S]", &title);
   299                    }                          
   369                    }
   300                if (attributeId & EMPXMediaGeneralCount)
   370                if (attributeId & EMPXMediaGeneralCount)
   301                    {
   371                    {
       
   372                    MPX_DEBUG1("    EMPXMediaGeneralCount");
   302                    TInt songCount = GetSongsCountL(KDbManagerAllDrives,
   373                    TInt songCount = GetSongsCountL(KDbManagerAllDrives,
   303                                 aRecord.ColumnInt64(EAbstractAlbumUniqueId));
   374                                 aRecord.ColumnInt64(EAbstractAlbumUniqueId));
   304                    aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralCount, songCount );
   375                    aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralCount, songCount );
   305                    }
   376                    }
   306                if (attributeId & EMPXMediaGeneralDrive)
   377                if (attributeId & EMPXMediaGeneralDrive ||
   307                    {
   378                     (attributeId & EMPXMediaGeneralUri))
       
   379                    {                       
   308                    TUint32 volId(aRecord.ColumnInt64(EAbstractAlbumVolumeId));
   380                    TUint32 volId(aRecord.ColumnInt64(EAbstractAlbumVolumeId));
   309                    TInt driveId = MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), volId);
   381                    TInt driveId = MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(), volId);
   310 
       
   311                    // LTAN-7GH6BZ, crash if eject memory card when adding song to existing AbstractAlbum
       
   312                    // due to special timing issue, it is possible drive number is -1 and create a
       
   313                    // panic when use for TDriveUnit
       
   314                    MPX_DEBUG3("volId = %d, driveId = %d", volId, driveId);
   382                    MPX_DEBUG3("volId = %d, driveId = %d", volId, driveId);
   315 
   383 
   316                    // handle possibly delay from framework notification
   384                    // handle possibly delay from framework notification
   317                    if (driveId < 0)
   385                    if (driveId < 0)
   318                        {
   386                        {
   319                        MPX_DEBUG1("invalid driveId, leave with KErrNotReady");
   387                        MPX_DEBUG1("invalid driveId, leave with KErrNotReady");
   320                        User::Leave(KErrNotReady);
   388                        User::Leave(KErrNotReady);
   321                        }
   389                        }
   322                    TDriveUnit driveUnit(driveId);
   390                    TDriveUnit driveUnit(driveId);
   323 
   391                    if (attributeId & EMPXMediaGeneralUri)
   324                    aMedia.SetTextValueL(KMPXMediaGeneralDrive, driveUnit.Name());
   392                        {                              
   325 
   393                        TPtrC uri(MPXDbCommonUtil::GetColumnTextL(aRecord, EAbstractAlbumUri));
       
   394                        aMedia.SetTextValueL(KMPXMediaGeneralUri, uri);
       
   395                        MPX_DEBUG2("    AbstractAlbum URI[%S]", &uri);
       
   396                        }
       
   397                   if (attributeId & EMPXMediaGeneralDrive)
       
   398                        {
       
   399                        aMedia.SetTextValueL(KMPXMediaGeneralDrive, driveUnit.Name());
       
   400                        }
   326                    }
   401                    }
   327                } // end if contentId == KMPXMediaIdGeneral          
   402                } // end if contentId == KMPXMediaIdGeneral
       
   403 
   328            else if ( contentId == KMPXMediaIdMusic)
   404            else if ( contentId == KMPXMediaIdMusic)
   329                {
   405                {
   330                if (attributeId & EMPXMediaMusicAlbumArtist)
   406                if (attributeId & EMPXMediaMusicAlbumArtist)
   331                    {         
   407                    {
       
   408                    MPX_DEBUG1("    EMPXMediaMusicAlbumArtist");
   332                    TPtrC albumartist(MPXDbCommonUtil::GetColumnTextL(aRecord, EAbstractAlbumArtist));
   409                    TPtrC albumartist(MPXDbCommonUtil::GetColumnTextL(aRecord, EAbstractAlbumArtist));
   333                    aMedia.SetTextValueL(KMPXMediaMusicAlbumArtist, albumartist);
   410                    aMedia.SetTextValueL(KMPXMediaMusicAlbumArtist, albumartist);
   334                    
       
   335                   
       
   336                    
       
   337                    MPX_DEBUG2("    albumartist[%S]", &albumartist);
   411                    MPX_DEBUG2("    albumartist[%S]", &albumartist);
   338                    } 
       
   339                if (attributeId & EMPXMediaMusicGenre)
       
   340                    {                 
       
   341                    TPtrC genre(MPXDbCommonUtil::GetColumnTextL(aRecord, EAbstractAlbumGenre));
       
   342                    aMedia.SetTextValueL(KMPXMediaMusicGenre, genre);
       
   343                    MPX_DEBUG2("    Genre[%S]", &genre);
       
   344                    }
   412                    }
   345                }
   413                }
   346                
   414 
   347            } // end for
   415            } // end for
   348        aMedia.SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem);
   416        aMedia.SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem);
   349        aMedia.SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXAbstractAlbum);
   417        aMedia.SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXAbstractAlbum);
   350     }
   418     }
   351 
   419 
   352 
   420 // ----------------------------------------------------------------------------
   353 // ----------------------------------------------------------------------------
   421 // CMPXDbAbstractAlbum::GetAllItemsWithNoSongL
   354 // CMPXDbAbstractAlbum::GenerateAlbumFieldsValuesL
   422 // ----------------------------------------------------------------------------
       
   423 //
       
   424 void CMPXDbAbstractAlbum::GetAllItemsWithNoSongL(RArray<TUint32>& aItemsIds)
       
   425     {
       
   426     MPX_FUNC("CMPXDbAbstractAlbum::GetAllItemsWithNoSongL");
       
   427     RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryAbstractAlbumsWithNoSong));
       
   428     CleanupClosePushL(recordset);
       
   429 
       
   430     TInt err(KErrNone);
       
   431     while ((err = recordset.Next()) == KSqlAtRow)
       
   432         {
       
   433         TUint32 uniqueID(recordset.ColumnInt64(EAbstractAlbumUniqueId));
       
   434         aItemsIds.AppendL(uniqueID);
       
   435         }
       
   436     CleanupStack::PopAndDestroy(&recordset);
       
   437     if (err!= KSqlAtEnd)
       
   438         {
       
   439         User::Leave(KErrCorrupt);
       
   440         } 	
       
   441     }
       
   442 
       
   443 
       
   444 // ----------------------------------------------------------------------------
       
   445 // CMPXDbAbstractAlbum::GenerateAbstractAlbumFieldsValuesL
   355 // ----------------------------------------------------------------------------
   446 // ----------------------------------------------------------------------------
   356 //
   447 //
   357 void CMPXDbAbstractAlbum::GenerateAbstractAlbumFieldsValuesL(const CMPXMedia& aMedia, CDesCArray& aFields, CDesCArray& aValues)
   448 void CMPXDbAbstractAlbum::GenerateAbstractAlbumFieldsValuesL(const CMPXMedia& aMedia, CDesCArray& aFields, CDesCArray& aValues)
   358     {
   449     {
   359     MPX_FUNC("CMPXDbAbstractAlbum::GenerateAbstractAlbumFieldsValuesL");
   450     MPX_FUNC("CMPXDbAbstractAlbum::GenerateAbstractAlbumFieldsValuesL");
   360 //support Winlogo use case
   451     //support Winlogo use case
   361    if (aMedia.IsSupported(KMPXMediaGeneralTitle))
   452     if (aMedia.IsSupported(KMPXMediaGeneralTitle))
   362         {
   453         {
   363         TPtrC truncatedName(aMedia.ValueText(KMPXMediaGeneralTitle).Left(KMCMaxTextLen));
   454         TPtrC truncatedName(aMedia.ValueText(KMPXMediaGeneralTitle).Left(KMCMaxTextLen));
   364         MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCCategoryName, truncatedName);
   455         MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCCategoryName, truncatedName);
   365         }
   456         }
   366 //support Winlogo use case
   457     //support Winlogo use case
   367    if (aMedia.IsSupported(KMPXMediaMusicAlbumArtist))
   458     if (aMedia.IsSupported(KMPXMediaMusicAlbumArtist))
   368         {
   459         {
   369         TPtrC truncatedAlbumArtist(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen));
   460         TPtrC truncatedAlbumArtist(aMedia.ValueText(KMPXMediaMusicAlbumArtist).Left(KMCMaxTextLen));
   370         MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicAlbumArtist, truncatedAlbumArtist);
   461         MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicAlbumArtist, truncatedAlbumArtist);
   371         }
   462         }
   372    if (aMedia.IsSupported(KMPXMediaMusicGenre))
   463      }
   373         {
   464 
   374         TPtrC truncatedGenre(aMedia.ValueText(KMPXMediaMusicGenre).Left(KMCMaxTextLen));
   465 // ----------------------------------------------------------------------------
   375         MPXDbCommonUtil::AppendValueL(aFields, aValues, KMCMusicGenre, truncatedGenre);    
   466 // CMPXDbAbstractAlbum::DeleteAbstractAlbumEntryL
   376         }
   467 // ----------------------------------------------------------------------------
   377     }
   468 //
   378 
   469 void CMPXDbAbstractAlbum::DeleteAbstractAlbumEntryL(
       
   470     TUint32 aAbstractAlbumId, TInt aDriveId)
       
   471     {
       
   472     MPX_FUNC("CMPXDbAbstractAlbum::DeleteAbstractAlbumEntryL");
       
   473 
       
   474     //delete entry from table        
       
   475     if (aDriveId)
       
   476         DeleteCategoryL(aAbstractAlbumId, aDriveId);
       
   477     else
       
   478         {
       
   479         TInt drive = MPXDbCommonUtil::GetDriveIdMatchVolIdL(iDbManager.Fs(),
       
   480         ExecuteIntQueryL(KCriterionCategoryVolumeId, aAbstractAlbumId));
       
   481         DeleteCategoryL(aAbstractAlbumId, drive);
       
   482         }
       
   483     }
   379 
   484 
   380 // ----------------------------------------------------------------------------
   485 // ----------------------------------------------------------------------------
   381 // CMPXDbAlbum::CreateTableL
   486 // CMPXDbAlbum::CreateTableL
   382 // ----------------------------------------------------------------------------
   487 // ----------------------------------------------------------------------------
   383 //
   488 //
   417 // Constructor
   522 // Constructor
   418 // ----------------------------------------------------------------------------
   523 // ----------------------------------------------------------------------------
   419 //
   524 //
   420 CMPXDbAbstractAlbum::CMPXDbAbstractAlbum(
   525 CMPXDbAbstractAlbum::CMPXDbAbstractAlbum(
   421     CMPXDbManager& aDbManager,
   526     CMPXDbManager& aDbManager,
   422     TMPXGeneralCategory aCategory) :
   527     TMPXGeneralCategory aCategory, RFs& aFs) :
   423     CMPXDbCategory(aDbManager, aCategory)
   528     CMPXDbCategory(aDbManager, aCategory),
       
   529     iFs(aFs)
   424     {
   530     {
   425     MPX_FUNC("CMPXDbAbstractAlbum::CMPXDbAbstractAlbum");
   531     MPX_FUNC("CMPXDbAbstractAlbum::CMPXDbAbstractAlbum");
   426     }
   532     }
   427 
   533 
   428 // ----------------------------------------------------------------------------
   534 // ----------------------------------------------------------------------------
   435 
   541 
   436     BaseConstructL();
   542     BaseConstructL();
   437 #ifdef RD_MPX_TNM_INTEGRATION
   543 #ifdef RD_MPX_TNM_INTEGRATION
   438     // Create Thumbnail Manager instance. This object is the observer.
   544     // Create Thumbnail Manager instance. This object is the observer.
   439     iTNManager = CThumbnailManager::NewL( *this );
   545     iTNManager = CThumbnailManager::NewL( *this );
       
   546     iRenameTN = EFalse;
   440 #endif //RD_MPX_TNM_INTEGRATION
   547 #endif //RD_MPX_TNM_INTEGRATION
   441     }
   548     }
   442 
   549 
   443 
   550 
   444 
       
   445 // ---------------------------------------------------------------------------
       
   446 // CMPXDbAbstractAlbum::ThumbnailReady 
       
   447 // Callback but not used here
       
   448 // ---------------------------------------------------------------------------
       
   449 void CMPXDbAbstractAlbum::ThumbnailPreviewReady( 
       
   450         MThumbnailData& /*aThumbnail*/, TThumbnailRequestId /*aId*/ )
       
   451     {
       
   452     }
       
   453         
       
   454 
   551 
   455 // ---------------------------------------------------------------------------
   552 // ---------------------------------------------------------------------------
   456 // CMPXDbAbstractAlbum::ThumbnailReady
   553 // CMPXDbAbstractAlbum::ThumbnailReady
   457 // Callback but not used here
   554 // Callback but not used here
   458 // ---------------------------------------------------------------------------
   555 // ---------------------------------------------------------------------------
   459 void CMPXDbAbstractAlbum::ThumbnailReady( TInt /*aError*/, 
   556 void CMPXDbAbstractAlbum::ThumbnailPreviewReady(
   460         MThumbnailData& /*aThumbnail*/, TThumbnailRequestId /*aId*/ )
   557         MThumbnailData& /*aThumbnail*/, TThumbnailRequestId /*aId*/ )
   461     {
   558     {
   462     }
   559     }
       
   560 
       
   561 
       
   562 // ---------------------------------------------------------------------------
       
   563 // CMPXDbAbstractAlbum::ThumbnailReady
       
   564 // Callback but not used here
       
   565 // ---------------------------------------------------------------------------
       
   566 void CMPXDbAbstractAlbum::ThumbnailReady( TInt /*aError*/,
       
   567         MThumbnailData& /*aThumbnail*/, TThumbnailRequestId /*aId*/ )
       
   568     {
       
   569     }
   463 // End of File
   570 // End of File