--- a/mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbhgplugin/src/mpxdbcategory.cpp Wed Sep 01 12:32:02 2010 +0100
+++ b/mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbhgplugin/src/mpxdbcategory.cpp Tue Sep 14 21:14:08 2010 +0300
@@ -30,6 +30,7 @@
#include "mpxdbpluginqueries.h"
#include "mpxdbutil.h"
#include "mpxdbcategory.h"
+#include "mpxmediamusicdefs.h"
// CONSTANTS
@@ -79,23 +80,26 @@
// ----------------------------------------------------------------------------
//
TUint32 CMPXDbCategory::AddItemL(
- const TDesC& aName,
+ TMPXGeneralCategory aCategory,
+ const CMPXMedia& aMedia,
TInt aDriveId,
TBool& aNewRecord,
TBool aCaseSensitive)
{
MPX_FUNC("CMPXDbCategory::AddItemL");
+ TPtrC itemName(ItemNameL(aCategory, aMedia));
+
// try to find the item first
TUint32 rowId(MPXDbCommonUtil::GenerateUniqueIdL(iDbManager.Fs(), iCategory,
- aName, aCaseSensitive));
+ itemName, aCaseSensitive));
aNewRecord = !CategoryItemExistsL(aDriveId, rowId);
if (aNewRecord)
{
// insert new
HBufC* query = PreProcessStringLC(KQueryCategoryInsert);
- HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(aName);
+ HBufC* name = MPXDbCommonUtil::ProcessSingleQuotesLC(itemName);
iDbManager.ExecuteQueryL(aDriveId, *query, rowId, name, 1);
@@ -112,7 +116,7 @@
return rowId;
}
-
+
// ----------------------------------------------------------------------------
// CMPXDbCategory::GetNameL
// ----------------------------------------------------------------------------
@@ -240,20 +244,37 @@
}
// construct criteria string
- HBufC* criteriaStr = MPXDbCommonUtil::StringFromArrayLC(*criteriaArray, KMCAndKeyword);
+ HBufC* criteriaStr = NULL;
+ if (criteriaArray->Count() > 0)
+ {
+ criteriaStr = MPXDbCommonUtil::StringFromArrayLC(*criteriaArray, KMCAndKeyword);
+ }
+ else
+ {
+ _LIT(KCriteriaTrue, "1");
+ criteriaStr = KCriteriaTrue().AllocLC();
+ }
+
+ RSqlStatement recordset;
+ if (iCategory == EMPXArtist)
+ {
+ recordset = iDbManager.ExecuteSelectQueryL(KQueryArtistItems, criteriaStr);
+ CleanupStack::PopAndDestroy(2, criteriaArray); //criteriaStr, criteriaArray
+ }
+ else
+ {
+ HBufC* query = PreProcessStringLC(KQueryCategoryItems);
+ recordset = iDbManager.ExecuteSelectQueryL(*query, criteriaStr);
+ CleanupStack::PopAndDestroy(3, criteriaArray); //query, criteriaStr, criteriaArray
+ }
- // either get all items or items filtered based on criteria
- HBufC* query = PreProcessStringLC(criteriaStr->Length() ?
- KQueryCategoryItems() : KQueryCategoryAll());
- RSqlStatement recordset(iDbManager.ExecuteSelectQueryL(*query, criteriaStr));
- CleanupStack::PopAndDestroy(3, criteriaArray); // query, criteriaStr, criteriaArray
CleanupClosePushL(recordset);
// process the results
ProcessRecordsetL(aAttrs, recordset, aMediaArray);
CleanupStack::PopAndDestroy(&recordset);
}
-
+
// ----------------------------------------------------------------------------
// CMPXDbCategory::DecrementSongsForCategoryL
// ----------------------------------------------------------------------------
@@ -486,7 +507,9 @@
TInt /*aDriveId*/,
CMPXMessageArray* /*aItemChangedMessages*/)
{
- // nothing
+ MPX_FUNC("CMPXDbCategory::UpdateItemL");
+
+ // do nothing
}
// ----------------------------------------------------------------------------
@@ -574,7 +597,7 @@
// ----------------------------------------------------------------------------
// CMPXDbCategory::ProcessRecordsetL
-// Unknown item is stored in the database as NULL (name field). This ensures the
+// Unknown item is stored in the database as empty string (name field). This ensures the
// unknown item to be the 1st found record if it exists. This will save time in
// searching for the unknown record among the results and avoid performing
// descriptor comparison. If the 1st record is the unknown item, it won't be
@@ -666,6 +689,46 @@
}
// ----------------------------------------------------------------------------
+// CMPXDbCategory::ItemNameL
+// ----------------------------------------------------------------------------
+//
+TPtrC CMPXDbCategory::ItemNameL(
+ TMPXGeneralCategory aCategory,
+ const CMPXMedia& aMedia)
+ {
+ MPX_FUNC("CMPXDbCategory::ItemNameL");
+
+ TMPXAttribute attribute;
+ switch(aCategory)
+ {
+ case EMPXGenre:
+ {
+ attribute = KMPXMediaMusicGenre;
+ break;
+ }
+ case EMPXComposer:
+ {
+ attribute = KMPXMediaMusicComposer;
+ break;
+ }
+ default:
+ {
+ User::Leave(KErrArgument);
+ break;
+ }
+ }
+
+ if (aMedia.IsSupported(attribute))
+ {
+ return aMedia.ValueText(attribute).Left(KMCMaxTextLen);
+ }
+ else
+ {
+ return KNullDesC();
+ }
+ }
+
+// ----------------------------------------------------------------------------
// CMPXDbCategory::CreateTableL
// ----------------------------------------------------------------------------
//