ipsservices/ipssosplugin/src/ipsplgmsgkey.cpp
changeset 23 2dc6caa42ec3
parent 18 578830873419
child 51 d845db10c0d4
equal deleted inserted replaced
20:ecc8def7944a 23:2dc6caa42ec3
    13 *
    13 *
    14 * Description:  Key class for message sorting
    14 * Description:  Key class for message sorting
    15 *
    15 *
    16 */
    16 */
    17 
    17 
       
    18 // <qmail> Are AknUtils available in 10.1?
       
    19 // <cmail>
       
    20 #include <AknUtils.h>
       
    21 // </cmail>
       
    22 // </qmail>
    18 
    23 
    19 #include "emailtrace.h"
    24 #include "emailtrace.h"
    20 #include "ipsplgheaders.h"
    25 #include "ipsplgheaders.h"
    21 
    26 
    22 const TInt KLessThan = -1;
    27 const TInt KLessThan = -1;
    23 const TInt KMoreThan = 1;
    28 const TInt KMoreThan = 1;
    24 const TInt KEqual = 0;
    29 const TInt KEqual = 0;
    25 
    30 
    26 _LIT(KDefaultSubjectPrefixSeparator,": ");
    31 _LIT(KDefaultSubjectPrefixSeparator,": ");
       
    32 // <cmail>
       
    33 // <qmail> Cmail bugfix uses AknUtils (available in 10.1?) - commented out until it is clear
       
    34 //_LIT( KCharsToReplace, "\r\n\t\x2028\x2029" );
       
    35 // <qmail>
       
    36 // </cmail>
    27 
    37 
    28 // ---------------------------------------------------------------------------
    38 // ---------------------------------------------------------------------------
    29 // Basic sonstructor
    39 // Basic sonstructor
    30 // ---------------------------------------------------------------------------
    40 // ---------------------------------------------------------------------------
    31 
    41 
    92                     leftEntry.iDetails.CompareC( rightEntry.iDetails );
   102                     leftEntry.iDetails.CompareC( rightEntry.iDetails );
    93                 break;
   103                 break;
    94                 }
   104                 }
    95             case EFSMailSortBySubject:
   105             case EFSMailSortBySubject:
    96                 {
   106                 {
    97                 result = CompareSubjects( 
   107                 // <cmail> due to changes in CompareSubject method
    98                     leftEntry.iDescription, rightEntry.iDescription );
   108                 TRAP_IGNORE( result = CompareSubjectsL( 
       
   109                     leftEntry.iDescription, rightEntry.iDescription ) );
       
   110                 // </cmail>
    99                 break;
   111                 break;
   100                 }
   112                 }
   101             case EFSMailSortByPriority:
   113             case EFSMailSortByPriority:
   102                 // The values of TMsvPriority are defined so that the highest
   114                 // The values of TMsvPriority are defined so that the highest
   103                 // priority has the smallest value
   115                 // priority has the smallest value
   132                 {
   144                 {
   133                 // In this context, an unread message is 'greater' than
   145                 // In this context, an unread message is 'greater' than
   134                 // a read one
   146                 // a read one
   135                 if ( !leftEntry.Unread() && rightEntry.Unread() ) 
   147                 if ( !leftEntry.Unread() && rightEntry.Unread() ) 
   136                     {
   148                     {
   137                     result = KLessThan;
   149                     result = KMoreThan; // <cmail> changed from KLessThan 
   138                     }
   150                     }
   139                 else if ( leftEntry.Unread() && !rightEntry.Unread() ) 
   151                 else if ( leftEntry.Unread() && !rightEntry.Unread() ) 
   140                     {
   152                     {
   141                     result = KMoreThan;
   153                     result = KLessThan; // <cmail> changed from KMoreThan
   142                     }
   154                     }
   143                 break;
   155                 break;
   144                 }
   156                 }
   145             case EFSMailSortBySize:
   157             case EFSMailSortBySize:
   146                 {
   158                 {
   198 
   210 
   199 // ---------------------------------------------------------------------------
   211 // ---------------------------------------------------------------------------
   200 // Strips the subject prefixes before comparing the strings
   212 // Strips the subject prefixes before comparing the strings
   201 // ---------------------------------------------------------------------------
   213 // ---------------------------------------------------------------------------
   202 
   214 
   203 TInt TIpsPlgMsgKey::CompareSubjects( 
   215 TInt TIpsPlgMsgKey::CompareSubjectsL( 
   204     const TDesC& aLeft, 
   216     const TDesC& aLeft, 
   205     const TDesC& aRight ) const
   217     const TDesC& aRight ) const
   206     {
   218     {
   207     FUNC_LOG;
   219     FUNC_LOG;
   208     TInt  result( KEqual );
   220     TInt  result( KEqual );
   213     
   225     
   214     leftPtr.Set( 
   226     leftPtr.Set( 
   215         leftPtr.Ptr() + leftOffset, leftPtr.Length() - leftOffset );
   227         leftPtr.Ptr() + leftOffset, leftPtr.Length() - leftOffset );
   216     rightPtr.Set( 
   228     rightPtr.Set( 
   217         rightPtr.Ptr() + rightOffset, rightPtr.Length() - rightOffset );
   229         rightPtr.Ptr() + rightOffset, rightPtr.Length() - rightOffset );
       
   230     
       
   231 // <qmail> Are AknUtils available in 10.1?
       
   232     // <cmail> for unifying with UI - remove all white spaces
       
   233     /*HBufC* croppedLeft = leftPtr.AllocLC();
       
   234     TPtr croppedLeftPtr = croppedLeft->Des();
       
   235     HBufC* croppedRight = rightPtr.AllocLC();
       
   236     TPtr croppedRightPtr = croppedRight->Des();
   218         
   237         
   219     result = leftPtr.CompareC( rightPtr );
   238     AknTextUtils::ReplaceCharacters( croppedLeftPtr, KCharsToReplace, ' ' );
       
   239     croppedLeftPtr.TrimAll();
       
   240     AknTextUtils::ReplaceCharacters( croppedRightPtr, KCharsToReplace, ' ' );
       
   241     croppedRightPtr.TrimAll();
       
   242     
       
   243     result = croppedLeftPtr.CompareC( croppedRightPtr );
       
   244     
       
   245     CleanupStack::PopAndDestroy( croppedRight );
       
   246     CleanupStack::PopAndDestroy( croppedLeft );*/
       
   247     // </cmail>
       
   248 // </qmail>
       
   249 
       
   250 // <qmail> Remove line if above code is valid in 10.1
       
   251 	result = leftPtr.CompareC( rightPtr );
       
   252 // </qmail>
   220         
   253         
   221     return result;
   254     return result;
   222     }
   255     }
   223     
   256     
   224 // ---------------------------------------------------------------------------
   257 // ---------------------------------------------------------------------------
   230 // ---------------------------------------------------------------------------
   263 // ---------------------------------------------------------------------------
   231 
   264 
   232 TInt TIpsPlgMsgKey::FindSubjectStart( const TDesC& aSubject ) const
   265 TInt TIpsPlgMsgKey::FindSubjectStart( const TDesC& aSubject ) const
   233     {
   266     {
   234     FUNC_LOG;
   267     FUNC_LOG;
   235 	TPtrC ptr(aSubject);
   268     TInt offset(0);
   236 	TInt offset(0);
   269     // <cmail> removed and replaced with the code from UI
   237 	TInt current(0);
   270     // TFsEmailUiUtility::CreateSubjectWithoutLocalisedPrefixLC
   238 	TInt skipLength = iSubjectPrefixSeparator.Length();
   271     // to have the same subject here and there
   239 	
   272     // there was sorting problem when subjects where handled
   240 	// Loop while separators are found
   273     // different here and in UI while creating mails' list.  
   241 	do
   274     
   242 		{
   275     /*TPtrC ptr(aSubject);
   243 		current = ptr.FindF( iSubjectPrefixSeparator );
   276     TInt current(0);
   244 
   277     TInt skipLength = iSubjectPrefixSeparator.Length();
   245 		if ( current != KErrNotFound )
   278     
   246 			{
   279     // Loop while separators are found
   247 			offset += current + skipLength;
   280     do
   248 			ptr.Set( aSubject.Ptr() + offset, aSubject.Length() - offset );
   281         {
   249 			}
   282         current = ptr.FindF( iSubjectPrefixSeparator );
   250 		} while ( current != KErrNotFound );
   283 
   251 
   284         if ( current != KErrNotFound )
   252 	return offset;
   285             {
   253     }
   286             offset += current + skipLength;
   254 
   287             ptr.Set( aSubject.Ptr() + offset, aSubject.Length() - offset );
   255 
   288             }
   256 
   289         } while ( current != KErrNotFound );*/
   257 
   290     
   258 
   291     TBool prefixFound = EFalse;
       
   292     TPtrC croppedSubject;
       
   293     croppedSubject.Set( aSubject );
       
   294     
       
   295     do
       
   296         {
       
   297         prefixFound = EFalse;
       
   298     
       
   299         // Remove leading white space before trying to find the prefix
       
   300         while( croppedSubject.Length() && 
       
   301                TChar( croppedSubject[0] ).IsSpace() )
       
   302             {
       
   303             croppedSubject.Set( croppedSubject.Mid(1) );
       
   304             offset++;
       
   305             }
       
   306     
       
   307         // try to find ":" at the beginning
       
   308         // Locate : character on location 1,2 and 3
       
   309         static const TInt KPrefixMinLength = 1;
       
   310         static const TInt KPrefixMaxLength = 3;
       
   311         static const TText KPrefixSeparator = ':';
       
   312         TInt separatorPosition = croppedSubject.Locate( KPrefixSeparator );
       
   313         if ( separatorPosition >= KPrefixMinLength &&
       
   314              separatorPosition <= KPrefixMaxLength )
       
   315             {
       
   316             TPtrC prefixCandidate = croppedSubject.Left( separatorPosition );
       
   317             // Only fully alphabetic prefixes are cropped
       
   318             TBool isAlpha = ETrue;
       
   319             for ( TInt i = 0 ; i < prefixCandidate.Length() ; ++i )
       
   320                 {
       
   321                 if ( !TChar( prefixCandidate[i] ).IsAlpha() )
       
   322                     {
       
   323                     isAlpha = EFalse;
       
   324                     }
       
   325                 }
       
   326             if ( isAlpha )
       
   327                 {
       
   328                 croppedSubject.Set( croppedSubject.Mid( 
       
   329                         separatorPosition + 1 ) );
       
   330                 offset += separatorPosition + 1;
       
   331                 prefixFound = ETrue;
       
   332                 }
       
   333             }
       
   334         }
       
   335     while ( prefixFound );
       
   336     // </cmail>
       
   337 
       
   338     return offset;
       
   339     }