diff -r bdd9da0d70fe -r 1f1dad4af8f8 mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbhgplugin/src/mpxdbartist.cpp --- a/mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbhgplugin/src/mpxdbartist.cpp Wed Sep 15 12:09:46 2010 +0300 +++ b/mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbhgplugin/src/mpxdbartist.cpp Wed Oct 13 14:28:40 2010 +0300 @@ -42,11 +42,12 @@ // CMPXDbArtist* CMPXDbArtist::NewL( CMPXDbManager& aDbManager, - TMPXGeneralCategory aCategory) + TMPXGeneralCategory aCategory, + MMPXDbArtistObserver& aObserver) { MPX_FUNC("CMPXDbArtist::NewL"); - CMPXDbArtist* self = CMPXDbArtist::NewLC(aDbManager, aCategory); + CMPXDbArtist* self = CMPXDbArtist::NewLC(aDbManager, aCategory, aObserver); CleanupStack::Pop(self); return self; } @@ -57,11 +58,12 @@ // CMPXDbArtist* CMPXDbArtist::NewLC( CMPXDbManager& aDbManager, - TMPXGeneralCategory aCategory) + TMPXGeneralCategory aCategory, + MMPXDbArtistObserver& aObserver) { MPX_FUNC("CMPXDbArtist::NewLC"); - CMPXDbArtist* self = new (ELeave) CMPXDbArtist(aDbManager, aCategory); + CMPXDbArtist* self = new (ELeave) CMPXDbArtist(aDbManager, aCategory, aObserver); CleanupStack::PushL(self); self->ConstructL(); return self; @@ -82,8 +84,10 @@ // CMPXDbArtist::CMPXDbArtist( CMPXDbManager& aDbManager, - TMPXGeneralCategory aCategory) : - CMPXDbCategory(aDbManager, aCategory) + TMPXGeneralCategory aCategory, + MMPXDbArtistObserver& aObserver) : + CMPXDbCategory(aDbManager, aCategory), + iObserver(aObserver) { MPX_FUNC("CMPXDbArtist::CMPXDbArtist"); } @@ -104,63 +108,58 @@ // ---------------------------------------------------------------------------- // TUint32 CMPXDbArtist::AddItemL( - TMPXGeneralCategory /*aCategory*/, - const CMPXMedia& aMedia, + const TDesC& aName, + const TDesC& aArt, TInt aDriveId, TBool& aNewRecord, TBool aCaseSensitive) { MPX_FUNC("CMPXDbArtist::AddItemL"); - TPtrC artist(KNullDesC); - TPtrC albumArt(KNullDesC); - - if (aMedia.IsSupported(KMPXMediaMusicArtist)) - { - artist.Set(aMedia.ValueText(KMPXMediaMusicArtist).Left(KMCMaxTextLen)); - } - - if (aMedia.IsSupported(KMPXMediaMusicAlbumArtFileName)) - { - albumArt.Set(aMedia.ValueText(KMPXMediaMusicAlbumArtFileName).Left(KMCMaxTextLen)); - } - // try to find the item first TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), iCategory, - artist, aCaseSensitive)); + aName, aCaseSensitive)); + aNewRecord = !CategoryItemExistsL(aDriveId, rowId); - HBufC* query = PreProcessStringLC(KQueryCategoryItem); - RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(aDriveId, *query, rowId)); - CleanupStack::PopAndDestroy(query); - CleanupClosePushL(recordset); - - TInt result(recordset.Next()); - if (result == KSqlAtEnd) + if (aNewRecord) { - aNewRecord = result; - // insert new - HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(artist); - HBufC* art = MPXDbCommonUtil::ProcessSingleQuotesLC(albumArt); + HBufC* query = PreProcessStringLC(KQueryArtistInsert); + HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName); + HBufC* art = MPXDbCommonUtil::ProcessSingleQuotesLC(aArt); - iDbManager.ExecuteQueryL(aDriveId, KQueryArtistInsert, rowId, name, 1, 0, art); + iDbManager.ExecuteQueryL(aDriveId, *query, rowId, name, 1, art); CleanupStack::PopAndDestroy(art); CleanupStack::PopAndDestroy(name); + CleanupStack::PopAndDestroy(query); } - else if (result == KSqlAtRow) + else { - // retrieve Art from Artist table + // retrieve the existing record + HBufC* query = NULL; + query = PreProcessStringLC(KQueryCategoryItem); + RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query, rowId)); + CleanupStack::PopAndDestroy(query); + + CleanupClosePushL(recordset); + + if (recordset.Next() != KSqlAtRow) + { + User::Leave(KErrNotFound); + } + + // Album Art TPtrC art(KNullDesC); art.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EArtistArt)); // the current one is Unknown and the new one is Not Unknown - if ( art == KNullDesC && albumArt != KNullDesC ) + if ( art == KNullDesC && aArt != KNullDesC ) { HBufC* artReplaceSingleQuote = - MPXDbCommonUtil::ProcessSingleQuotesLC( albumArt ); + MPXDbCommonUtil::ProcessSingleQuotesLC( aArt ); _LIT( KFormatArt, "Art=\'%S\'" ); - HBufC* setStr = HBufC::NewLC(KMaxFileName); + HBufC* setStr = HBufC::NewLC(256); setStr->Des().Format( KFormatArt, artReplaceSingleQuote ); iDbManager.ExecuteQueryL(aDriveId, KQueryArtistUpdate, setStr, rowId); @@ -168,68 +167,35 @@ CleanupStack::PopAndDestroy(artReplaceSingleQuote); } + CleanupStack::PopAndDestroy(&recordset); + // increment the number of songs for the category query = PreProcessStringLC(KQueryCategoryIncrementSongCount); iDbManager.ExecuteQueryL(aDriveId, *query, rowId); CleanupStack::PopAndDestroy(query); } - else - { - MPX_DEBUG2("SQL error %d", result); - User::Leave(result); - } - - CleanupStack::PopAndDestroy(&recordset); - + return rowId; } - + // ---------------------------------------------------------------------------- -// CMPXDbArtist::DecrementSongsForCategoryL +// CMPXDbArtist::IsUnknownArtistL // ---------------------------------------------------------------------------- // -void CMPXDbArtist::DecrementSongsForCategoryL( - const TUint32 aId, - TInt aDriveId, - CMPXMessageArray* aItemChangedMessages, - TBool& aItemExist -#ifdef ABSTRACTAUDIOALBUM_INCLUDED - , - TBool /*aMTPInUse*/ -#endif //ABSTRACTAUDIOALBUM_INCLUDED - ) +TBool CMPXDbArtist::IsUnknownArtistL(TUint32 aId) { - MPX_FUNC("CMPXDbArtist::DecrementSongsForCategoryL"); - - TInt songsCount(0); - TInt albumsCount(0); - - GetSongsAndAlbumsCountL(aDriveId, aId, songsCount, albumsCount); - - MPX_DEBUG4("id %d, songsCount %d, albumsCount %d", aId, songsCount, albumsCount); - - // if just one song uses this category. Use <= just in case - if (songsCount <= 1 && albumsCount == 0) - { - aItemExist = EFalse; - // delete the category - DeleteCategoryL(aId, aDriveId); + MPX_FUNC("CMPXDbArtist::IsUnknownArtistL"); + + HBufC* name = GetNameL(aId); - if (aItemChangedMessages) - { - // add the item changed message - MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aId, EMPXItemDeleted, - iCategory, KDBPluginUid); - } - } - else if (songsCount > 0) - { - aItemExist = ETrue; - // decrement the number of songs for the category - HBufC* query = PreProcessStringLC(KQueryCategoryDecrementSongCount); - iDbManager.ExecuteQueryL(aDriveId, *query, aId); - CleanupStack::PopAndDestroy(query); - } + TInt ret = EFalse; + if (*name == KNullDesC) + { + ret = ETrue; + } + delete name; + + return ret; } // ---------------------------------------------------------------------------- @@ -271,6 +237,10 @@ } if (attributeId & EMPXMediaGeneralCount) { +// TInt albumCount = GetAlbumsCountL(aRecord.ColumnInt64(EArtistUniqueId)); +// aMedia.SetTObjectValueL(KMPXMediaGeneralCount,albumCount); +// MPX_DEBUG1(" EMPXMediaGeneralCount"); +// MPX_DEBUG2(" AlbumCount[%d]", albumCount); // get songs count from all drives TInt songCount = GetSongsCountL( KDbManagerAllDrives, aRecord.ColumnInt64( EArtistUniqueId ) ); @@ -311,6 +281,17 @@ } // ---------------------------------------------------------------------------- +// CMPXDbArtist::GetAlbumsCountL +// ---------------------------------------------------------------------------- +// +TInt CMPXDbArtist::GetAlbumsCountL(TUint32 aId) + { + MPX_FUNC("CMPXDbArtist::GetAlbumsCountL"); + + return iObserver.HandleGetAlbumsCountForArtistL(aId); + } + +// ---------------------------------------------------------------------------- // CMPXDbArtist::GetAllCategoryItemsL // ---------------------------------------------------------------------------- // @@ -319,7 +300,9 @@ CMPXMediaArray& aMediaArray) { MPX_FUNC("CMPXDbArtist::GetAllCategoryItemsL"); - RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(KQueryArtistAll())); + HBufC* query = PreProcessStringLC(KQueryArtistAll); + RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query)); + CleanupStack::PopAndDestroy(query); CleanupClosePushL(recordset); ProcessRecordsetL(aAttrs, recordset, aMediaArray); CleanupStack::PopAndDestroy(&recordset); @@ -360,169 +343,37 @@ CleanupStack::PopAndDestroy(values); CleanupStack::PopAndDestroy(fields); } - // ---------------------------------------------------------------------------- -// CMPXDbArtist::AddAlbumArtistL -// ---------------------------------------------------------------------------- -// -TUint32 CMPXDbArtist::AddAlbumArtistL( - const TDesC& aName, - const TDesC& aArt, - TInt aDriveId) - { - MPX_FUNC("CMPXDbArtist::AddAlbumArtistL"); - - // try to find the item first - TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), iCategory, - aName, ETrue)); - HBufC* query = PreProcessStringLC(KQueryCategoryItem); - RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(aDriveId, *query, rowId)); - CleanupStack::PopAndDestroy(query); - CleanupClosePushL(recordset); - - TInt result(recordset.Next()); - if (result == KSqlAtEnd) - { - // insert new - HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName); - HBufC* art = MPXDbCommonUtil::ProcessSingleQuotesLC(aArt); - - iDbManager.ExecuteQueryL(aDriveId, KQueryArtistInsert, rowId, name, 0, 1, art); - - CleanupStack::PopAndDestroy(art); - CleanupStack::PopAndDestroy(name); - } - else if (result == KSqlAtRow) - { - // retrieve Art from Artist table - TPtrC art(KNullDesC); - art.Set(MPXDbCommonUtil::GetColumnTextL(recordset, EArtistArt)); - - // the current one is Unknown and the new one is Not Unknown - if ( art == KNullDesC && aArt != KNullDesC ) - { - HBufC* artReplaceSingleQuote = - MPXDbCommonUtil::ProcessSingleQuotesLC( aArt ); - _LIT( KFormatArt, "Art=\'%S\'" ); - HBufC* setStr = HBufC::NewLC(KMaxFileName); - setStr->Des().Format( KFormatArt, artReplaceSingleQuote ); - - iDbManager.ExecuteQueryL(aDriveId, KQueryArtistUpdate, setStr, rowId); - CleanupStack::PopAndDestroy(setStr); - CleanupStack::PopAndDestroy(artReplaceSingleQuote); - } - - // increment the number of songs for the category - iDbManager.ExecuteQueryL(aDriveId, KQueryArtistIncrementAlbumCount, rowId); - } - else - { - MPX_DEBUG2("SQL error %d", result); - User::Leave(result); - } - - CleanupStack::PopAndDestroy(&recordset); - - return rowId; - } - -// ---------------------------------------------------------------------------- -// CMPXDbArtist::DecrementAlbumsForArtistL -// ---------------------------------------------------------------------------- -// -void CMPXDbArtist::DecrementAlbumsForArtistL( - const TUint32 aId, - TInt aDriveId, - CMPXMessageArray* aItemChangedMessages - ) - { - MPX_FUNC("CMPXDbArtist::DecrementAlbumsForCategoryL"); - - TInt songsCount(0); - TInt albumsCount(0); - - GetSongsAndAlbumsCountL(aDriveId, aId, songsCount, albumsCount); - - MPX_DEBUG4("id %d, songsCount %d, albumsCount %d", aId, songsCount, albumsCount); - - // if just one album uses this category. Use <= just in case - if (songsCount == 0 && albumsCount <= 1) - { - // delete the category - DeleteCategoryL(aId, aDriveId); - - if (aItemChangedMessages) - { - // add the item changed message - MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, aId, EMPXItemDeleted, - iCategory, KDBPluginUid); - } - } - else if (albumsCount > 0) - { - // decrement the number of albums for the category - iDbManager.ExecuteQueryL(aDriveId, KQueryArtistDecrementAlbumCount, aId); - } - } - -// ---------------------------------------------------------------------------- -// CMPXDbArtist::GetSongsAndAlbumsCountL -// ---------------------------------------------------------------------------- -// -void CMPXDbArtist::GetSongsAndAlbumsCountL( - TInt aDriveId, - TUint32 aId, - TInt& aSongCount, - TInt& aAlbumCount) - { - MPX_FUNC("CMPXDbArtist::GetSongsAndAlbumsCountL"); - - RSqlStatement recordset( - iDbManager.ExecuteSelectQueryL(aDriveId, KQueryArtistGetSongCountAndAlbumCount, aId)); - CleanupClosePushL(recordset); - - TInt err(KErrNone); - while ((err = recordset.Next()) == KSqlAtRow) - { - aSongCount += recordset.ColumnInt(KMPXTableDefaultIndex); - aAlbumCount += recordset.ColumnInt(KMPXTableDefaultIndex+1); - } - - if (err != KSqlAtEnd) - { - User::Leave(err); - } - - CleanupStack::PopAndDestroy(&recordset); - } - -// ---------------------------------------------------------------------------- -// CMPXDbArtist::CreateTableL +// CMPXDbAlbum::CreateTableL // ---------------------------------------------------------------------------- // void CMPXDbArtist::CreateTableL( RSqlDatabase& aDatabase, TBool /* aCorruptTable */) { - MPX_FUNC("CMPXDbArtist::CreateTableL"); + MPX_FUNC("CMPXDbCategory::CreateTableL"); // create the table - User::LeaveIfError(aDatabase.Exec(KArtistCreateTable)); + HBufC* query = PreProcessStringLC(KArtistCreateTable); + User::LeaveIfError(aDatabase.Exec(*query)); + CleanupStack::PopAndDestroy(query); // do not create an index on the Name field // as it only slows down the insert/update queries overall } // ---------------------------------------------------------------------------- -// CMPXDbArtist::CheckTableL +// CMPXDbAlbum::CheckTableL // ---------------------------------------------------------------------------- // TBool CMPXDbArtist::CheckTableL( RSqlDatabase& aDatabase) { - MPX_FUNC("CMPXDbArtist::CheckTableL"); + MPX_FUNC("CMPXDbCategory::CheckTableL"); - TBool check(DoCheckTable(aDatabase, KArtistCheckTable)); + HBufC* query = PreProcessStringLC(KArtistCheckTable); + TBool check(DoCheckTable(aDatabase, *query)); + CleanupStack::PopAndDestroy(query); return check; }