phonebookui/Phonebook2/UIPolicy/src/CPbk2ContactViewSortPolicy.cpp
branchRCL_3
changeset 18 d4f567ce2e7c
parent 0 e686773b3f54
equal deleted inserted replaced
17:2666d9724c76 18:d4f567ce2e7c
    41 #include <SortUtil.h>
    41 #include <SortUtil.h>
    42 
    42 
    43 // Debugging headers
    43 // Debugging headers
    44 #include <Pbk2Profile.h>
    44 #include <Pbk2Profile.h>
    45 
    45 
       
    46 #include <vpbkeng.rsg>
       
    47 
       
    48 // Greater than any practical top contact number string
       
    49 // which is in form like '0000000001'.
       
    50 _LIT(KBigNumStr, "9999999999");
       
    51 
    46 
    52 
    47 /// Unnamed namespace for local definitions
    53 /// Unnamed namespace for local definitions
    48 namespace {
    54 namespace {
    49 
    55 
    50 _LIT(KResourceFile, "Pbk2UIPolicyRes.rsc");
    56 _LIT(KResourceFile, "Pbk2UIPolicyRes.rsc");
   170         iRightSortKeyArray = CPbk2SortKeyArray::NewL();
   176         iRightSortKeyArray = CPbk2SortKeyArray::NewL();
   171 
   177 
   172         iSortOrder = CVPbkSortOrder::NewL(aParam->iSortOrder);
   178         iSortOrder = CVPbkSortOrder::NewL(aParam->iSortOrder);
   173         iFieldMapper.SetSortOrder(*iSortOrder);
   179         iFieldMapper.SetSortOrder(*iSortOrder);
   174 
   180 
       
   181         iTopContactId = GetTopContactFieldIndex();
       
   182 
   175         RPbk2LocalizedResourceFile resFile(aParam->iFs);
   183         RPbk2LocalizedResourceFile resFile(aParam->iFs);
   176         resFile.OpenLC( KPbk2RomFileDrive, KDC_RESOURCE_FILES_DIR,
   184         resFile.OpenLC( KPbk2RomFileDrive, KDC_RESOURCE_FILES_DIR,
   177             KResourceFile );
   185             KResourceFile );
   178 
   186 
   179         HBufC8* selectorBuf = resFile.AllocReadLC
   187         HBufC8* selectorBuf = resFile.AllocReadLC
   203 
   211 
   204     CVPbkSortOrder* sortOrder = CVPbkSortOrder::NewL( aSortOrder );
   212     CVPbkSortOrder* sortOrder = CVPbkSortOrder::NewL( aSortOrder );
   205     delete iSortOrder;
   213     delete iSortOrder;
   206     iSortOrder = sortOrder;
   214     iSortOrder = sortOrder;
   207     iFieldMapper.SetSortOrder( *iSortOrder );
   215     iFieldMapper.SetSortOrder( *iSortOrder );
       
   216 
       
   217     iTopContactId = GetTopContactFieldIndex();
   208     }
   218     }
   209 
   219 
   210 // --------------------------------------------------------------------------
   220 // --------------------------------------------------------------------------
   211 // CPbk2ContactViewSortPolicy::SortStartL
   221 // CPbk2ContactViewSortPolicy::SortStartL
   212 // --------------------------------------------------------------------------
   222 // --------------------------------------------------------------------------
   273 
   283 
   274         iFieldMapper.SetContactFields( aLhs.Fields() );
   284         iFieldMapper.SetContactFields( aLhs.Fields() );
   275         const TInt lhsCount = iFieldMapper.FieldCount();
   285         const TInt lhsCount = iFieldMapper.FieldCount();
   276         for ( i = 0; i < lhsCount; ++i )
   286         for ( i = 0; i < lhsCount; ++i )
   277             {
   287             {
   278             const MVPbkBaseContactField* lhsField =
   288             SetSortKey( iLeftSortKeyArray, iFieldMapper.FieldAt(i), i );
   279                 iFieldMapper.FieldAt( i );
       
   280             if ( lhsField )
       
   281                 {
       
   282                 iLeftSortKeyArray->SetText( MVPbkContactFieldTextData::Cast
       
   283                     ( lhsField->FieldData() ).Text(), i );
       
   284                 }
       
   285             else
       
   286                 {
       
   287                 iLeftSortKeyArray->SetText( KNullDesC, i );
       
   288                 }
       
   289             }
   289             }
   290 
   290 
   291         iFieldMapper.SetContactFields( aRhs.Fields() );
   291         iFieldMapper.SetContactFields( aRhs.Fields() );
   292         const TInt rhsCount = iFieldMapper.FieldCount();
   292         const TInt rhsCount = iFieldMapper.FieldCount();
   293         for ( i = 0; i < rhsCount; ++i )
   293         for ( i = 0; i < rhsCount; ++i )
   294             {
   294             {
   295             const MVPbkBaseContactField* rhsField =
   295             SetSortKey( iRightSortKeyArray, iFieldMapper.FieldAt(i), i );
   296                 iFieldMapper.FieldAt( i );
       
   297             if ( rhsField )
       
   298                 {
       
   299                 iRightSortKeyArray->SetText( MVPbkContactFieldTextData::Cast
       
   300                     ( rhsField->FieldData() ).Text(), i );
       
   301                 }
       
   302             else
       
   303                 {
       
   304                 iRightSortKeyArray->SetText( KNullDesC, i );
       
   305                 }
       
   306             }
   296             }
   307 
   297 
   308 PBK2_PROFILE_END( Pbk2Profile::ESortPolicyCompareContacts );
   298 PBK2_PROFILE_END( Pbk2Profile::ESortPolicyCompareContacts );
   309 
   299 
   310 
   300 
   390         }
   380         }
   391 
   381 
   392     return result;
   382     return result;
   393     }
   383     }
   394 
   384 
       
   385 // --------------------------------------------------------------------------
       
   386 // CPbk2ContactViewSortPolicy::GetTopContactFieldIndex
       
   387 // --------------------------------------------------------------------------
       
   388 //
       
   389 TInt CPbk2ContactViewSortPolicy::GetTopContactFieldIndex()
       
   390     {
       
   391     TInt index = KErrNotFound;
       
   392     for ( TInt i=0; i<iSortOrder->FieldTypeCount(); i++ )
       
   393         {
       
   394         // Resource id of top contact field is R_VPBK_FIELD_TYPE_TOPCONTACT.
       
   395         if ( iSortOrder->FieldTypeAt( i ).FieldTypeResId() == 
       
   396                 R_VPBK_FIELD_TYPE_TOPCONTACT )
       
   397             {
       
   398             index = i;
       
   399             break;
       
   400             }
       
   401         }
       
   402     return index;
       
   403     }
       
   404 
       
   405 // --------------------------------------------------------------------------
       
   406 // CPbk2ContactViewSortPolicy::SetSortKey
       
   407 // --------------------------------------------------------------------------
       
   408 //
       
   409 void CPbk2ContactViewSortPolicy::SetSortKey(
       
   410         CPbk2SortKeyArray* aSortKeyArray,
       
   411         const MVPbkBaseContactField* aField,
       
   412         TInt aIndex )
       
   413     {
       
   414     TInt textLen = 0;
       
   415     if ( aField )
       
   416         {
       
   417         TPtrC text = MVPbkContactFieldTextData::Cast
       
   418             ( aField->FieldData() ).Text();
       
   419         aSortKeyArray->SetText( text, aIndex );
       
   420         textLen = text.Length();
       
   421         }
       
   422     if ( textLen == 0 )
       
   423         {
       
   424         if ( aIndex == iTopContactId )
       
   425             {
       
   426             // For some variants such as Chinese variant, 
       
   427             // empty string is less than not empty string. 
       
   428             // This will make topic contacts which have substantial top contact
       
   429             // id strings after those with empty id strings.
       
   430             // To prevent this, use a big number string instead of empty string 
       
   431             // and make sure top contacts in front of other contacts.
       
   432             aSortKeyArray->SetText( KBigNumStr, aIndex );
       
   433             }
       
   434         else
       
   435             {
       
   436             aSortKeyArray->SetText( KNullDesC, aIndex );
       
   437             }
       
   438         }
       
   439     }
       
   440 
   395 //  End of File
   441 //  End of File