--- a/phonebookui/Phonebook2/UIPolicy/src/CPbk2ContactViewSortPolicy.cpp Thu Jul 15 18:22:55 2010 +0300
+++ b/phonebookui/Phonebook2/UIPolicy/src/CPbk2ContactViewSortPolicy.cpp Thu Aug 19 09:41:07 2010 +0300
@@ -43,6 +43,12 @@
// Debugging headers
#include <Pbk2Profile.h>
+#include <vpbkeng.rsg>
+
+// Greater than any practical top contact number string
+// which is in form like '0000000001'.
+_LIT(KBigNumStr, "9999999999");
+
/// Unnamed namespace for local definitions
namespace {
@@ -172,6 +178,8 @@
iSortOrder = CVPbkSortOrder::NewL(aParam->iSortOrder);
iFieldMapper.SetSortOrder(*iSortOrder);
+ iTopContactId = GetTopContactFieldIndex();
+
RPbk2LocalizedResourceFile resFile(aParam->iFs);
resFile.OpenLC( KPbk2RomFileDrive, KDC_RESOURCE_FILES_DIR,
KResourceFile );
@@ -205,6 +213,8 @@
delete iSortOrder;
iSortOrder = sortOrder;
iFieldMapper.SetSortOrder( *iSortOrder );
+
+ iTopContactId = GetTopContactFieldIndex();
}
// --------------------------------------------------------------------------
@@ -275,34 +285,14 @@
const TInt lhsCount = iFieldMapper.FieldCount();
for ( i = 0; i < lhsCount; ++i )
{
- const MVPbkBaseContactField* lhsField =
- iFieldMapper.FieldAt( i );
- if ( lhsField )
- {
- iLeftSortKeyArray->SetText( MVPbkContactFieldTextData::Cast
- ( lhsField->FieldData() ).Text(), i );
- }
- else
- {
- iLeftSortKeyArray->SetText( KNullDesC, i );
- }
+ SetSortKey( iLeftSortKeyArray, iFieldMapper.FieldAt(i), i );
}
iFieldMapper.SetContactFields( aRhs.Fields() );
const TInt rhsCount = iFieldMapper.FieldCount();
for ( i = 0; i < rhsCount; ++i )
{
- const MVPbkBaseContactField* rhsField =
- iFieldMapper.FieldAt( i );
- if ( rhsField )
- {
- iRightSortKeyArray->SetText( MVPbkContactFieldTextData::Cast
- ( rhsField->FieldData() ).Text(), i );
- }
- else
- {
- iRightSortKeyArray->SetText( KNullDesC, i );
- }
+ SetSortKey( iRightSortKeyArray, iFieldMapper.FieldAt(i), i );
}
PBK2_PROFILE_END( Pbk2Profile::ESortPolicyCompareContacts );
@@ -392,4 +382,60 @@
return result;
}
+// --------------------------------------------------------------------------
+// CPbk2ContactViewSortPolicy::GetTopContactFieldIndex
+// --------------------------------------------------------------------------
+//
+TInt CPbk2ContactViewSortPolicy::GetTopContactFieldIndex()
+ {
+ TInt index = KErrNotFound;
+ for ( TInt i=0; i<iSortOrder->FieldTypeCount(); i++ )
+ {
+ // Resource id of top contact field is R_VPBK_FIELD_TYPE_TOPCONTACT.
+ if ( iSortOrder->FieldTypeAt( i ).FieldTypeResId() ==
+ R_VPBK_FIELD_TYPE_TOPCONTACT )
+ {
+ index = i;
+ break;
+ }
+ }
+ return index;
+ }
+
+// --------------------------------------------------------------------------
+// CPbk2ContactViewSortPolicy::SetSortKey
+// --------------------------------------------------------------------------
+//
+void CPbk2ContactViewSortPolicy::SetSortKey(
+ CPbk2SortKeyArray* aSortKeyArray,
+ const MVPbkBaseContactField* aField,
+ TInt aIndex )
+ {
+ TInt textLen = 0;
+ if ( aField )
+ {
+ TPtrC text = MVPbkContactFieldTextData::Cast
+ ( aField->FieldData() ).Text();
+ aSortKeyArray->SetText( text, aIndex );
+ textLen = text.Length();
+ }
+ if ( textLen == 0 )
+ {
+ if ( aIndex == iTopContactId )
+ {
+ // For some variants such as Chinese variant,
+ // empty string is less than not empty string.
+ // This will make topic contacts which have substantial top contact
+ // id strings after those with empty id strings.
+ // To prevent this, use a big number string instead of empty string
+ // and make sure top contacts in front of other contacts.
+ aSortKeyArray->SetText( KBigNumStr, aIndex );
+ }
+ else
+ {
+ aSortKeyArray->SetText( KNullDesC, aIndex );
+ }
+ }
+ }
+
// End of File