ipsservices/ipssosplugin/src/ipsplgmsgiterator.cpp
branchRCL_3
changeset 52 efd4f1afd43e
parent 29 6b8f3b30d0ec
child 63 d189ee25cf9d
equal deleted inserted replaced
29:6b8f3b30d0ec 52:efd4f1afd43e
    69     FUNC_LOG;
    69     FUNC_LOG;
    70     delete iFolderEntry;
    70     delete iFolderEntry;
    71     delete iMsgMapper;
    71     delete iMsgMapper;
    72     delete iMsgSortKey;
    72     delete iMsgSortKey;
    73     delete iMsgSwapper;
    73     delete iMsgSwapper;
    74     
    74     delete iMessages;
    75     iSortingCriteria.Reset();
    75     iSortingCriteria.Reset();
    76     }
    76     }
    77 
    77 
    78 // ---------------------------------------------------------------------------
    78 // ---------------------------------------------------------------------------
    79 // Searches the message matching with aCurrentMessageId and requests the
    79 // Searches the message matching with aCurrentMessageId and requests the
    87     {
    87     {
    88     FUNC_LOG;
    88     FUNC_LOG;
    89     TBool result = EFalse;
    89     TBool result = EFalse;
    90     TInt baseIndex;
    90     TInt baseIndex;
    91     
    91     
    92     // Messages are sorted always before reading the messages 
    92     if ( !iMessages )
    93     Sort();
    93         {
    94     
    94         // Messages are sorted before first reading the messages 
    95     CMsvEntrySelection* messages = FilterMessagesL();
    95         Sort();
    96     CleanupStack::PushL( messages );
    96         iMessages = FilterMessagesL();
       
    97         }
    97 
    98 
    98     if ( !aCurrentMessageId.IsNullId() )
    99     if ( !aCurrentMessageId.IsNullId() )
    99         {
   100         {
   100         baseIndex = messages->Find( aCurrentMessageId.Id() );
   101         baseIndex = iMessages->Find( aCurrentMessageId.Id() );
   101         
   102         
   102         // aCurrentMessageId is not included to the result set
   103         // aCurrentMessageId is not included to the result set
   103         if ( baseIndex != KErrNotFound )
   104         if ( baseIndex != KErrNotFound )
   104             {
   105             {
   105             baseIndex += 1;
   106             baseIndex += 1;
   110         // start from the beginning of the message list
   111         // start from the beginning of the message list
   111         baseIndex = 0;
   112         baseIndex = 0;
   112         }
   113         }
   113         
   114         
   114     if ( ( baseIndex != KErrNotFound ) && 
   115     if ( ( baseIndex != KErrNotFound ) && 
   115          ( baseIndex < messages->Count() ) )
   116          ( baseIndex < iMessages->Count() ) )
   116         {
   117         {
   117         result = NextL(baseIndex, messages, aCount, aMessages);
   118         result = NextL(baseIndex, iMessages, aCount, aMessages);
   118         }
   119         }
   119 
   120 
   120     CleanupStack::PopAndDestroy(messages);
       
   121     return result;
   121     return result;
   122     }
   122     }
   123 
   123 
   124 // ---------------------------------------------------------------------------
   124 // ---------------------------------------------------------------------------
   125 // Searches message matching with the search string and returns a chunk of
   125 // Searches message matching with the search string and returns a chunk of
   134     FUNC_LOG;
   134     FUNC_LOG;
   135     TBool result = EFalse;
   135     TBool result = EFalse;
   136     TInt status;
   136     TInt status;
   137     TInt baseIndex;
   137     TInt baseIndex;
   138     
   138     
   139     // Messages are sorted always before reading the messages 
   139     if ( !iMessages )
   140     Sort();
   140         {
   141 
   141         // Messages are sorted before first reading the messages 
   142     CMsvEntrySelection* messages = FilterMessagesL();
   142         Sort();
   143     CleanupStack::PushL( messages );
   143         iMessages = FilterMessagesL();
   144 
   144         }
   145     status = SearchL( messages, aStartWith, baseIndex );
   145 
       
   146     status = SearchL( iMessages, aStartWith, baseIndex );
   146     
   147     
   147     if ( status == KErrNone )
   148     if ( status == KErrNone )
   148         {
   149         {
   149         result = NextL(baseIndex, messages, aCount, aMessages);
   150         result = NextL( baseIndex, iMessages, aCount, aMessages );
   150         }
   151         }
   151 
   152 
   152     CleanupStack::PopAndDestroy(messages);
       
   153     return result;
   153     return result;
   154     }
   154     }
   155 
   155 
   156 // ---------------------------------------------------------------------------
   156 // ---------------------------------------------------------------------------
   157 // Like NextL() with similar parameters, the method searches the message 
   157 // Like NextL() with similar parameters, the method searches the message 
   166     {
   166     {
   167     FUNC_LOG;
   167     FUNC_LOG;
   168     TBool result = EFalse;
   168     TBool result = EFalse;
   169     TInt baseIndex;
   169     TInt baseIndex;
   170     
   170     
   171     // Messages are sorted always before reading the messages 
   171     if ( !iMessages )
   172     Sort();
   172         {
   173 
   173         // Messages are sorted before first reading the messages 
   174     CMsvEntrySelection* messages = FilterMessagesL();
   174         Sort();
   175     CleanupStack::PushL(messages);
   175         iMessages = FilterMessagesL();
       
   176         }
   176 
   177 
   177     if ( !aCurrentMessageId.IsNullId() )
   178     if ( !aCurrentMessageId.IsNullId() )
   178         {
   179         {
   179         baseIndex = messages->Find(aCurrentMessageId.Id());
   180         baseIndex = iMessages->Find(aCurrentMessageId.Id());
   180         
   181         
   181         // aCurrentMessageId is not included to the result set
   182         // aCurrentMessageId is not included to the result set
   182         if ( baseIndex != KErrNotFound )
   183         if ( baseIndex != KErrNotFound )
   183             {
   184             {
   184             baseIndex -= 1;
   185             baseIndex -= 1;
   186         }
   187         }
   187     else
   188     else
   188         {
   189         {
   189         // check whether we should start from the end of 
   190         // check whether we should start from the end of 
   190         // the message list in the case of a NULL ID
   191         // the message list in the case of a NULL ID
   191         baseIndex = messages->Count() - 1;
   192         baseIndex = iMessages->Count() - 1;
   192         }
   193         }
   193 
   194 
   194     // Actually, if the matching message is the first one, baseIndex is equal
   195     // Actually, if the matching message is the first one, baseIndex is equal
   195     // to -1 which is also the value of KErrNotFound. So, the condition could be
   196     // to -1 which is also the value of KErrNotFound. So, the condition could be
   196     // simpler, but it would not inappropriate to trust that the numerical value 
   197     // simpler, but it would not inappropriate to trust that the numerical value 
   197     // of the error code is known.
   198     // of the error code is known.
   198     if ( ( baseIndex != KErrNotFound ) &&
   199     if ( ( baseIndex != KErrNotFound ) &&
   199          ( baseIndex >= 0 ) )
   200          ( baseIndex >= 0 ) )
   200         {
   201         {
   201         result = PreviousL(baseIndex, messages, aCount, aMessages);
   202         result = PreviousL(baseIndex, iMessages, aCount, aMessages);
   202         }
   203         }
   203 
   204 
   204     CleanupStack::PopAndDestroy(messages);
       
   205     return result;
   205     return result;
   206     }
   206     }
   207 
   207 
   208 // ---------------------------------------------------------------------------
   208 // ---------------------------------------------------------------------------
   209 // Searches the first message matching with the search string and requests
   209 // Searches the first message matching with the search string and requests
   223     FUNC_LOG;
   223     FUNC_LOG;
   224     TBool result = EFalse;
   224     TBool result = EFalse;
   225     TInt status;
   225     TInt status;
   226     TInt baseIndex;
   226     TInt baseIndex;
   227     
   227     
   228     // Messages are sorted always before reading the messages 
   228     if ( !iMessages )
   229     Sort();
   229         {
   230 
   230         // Messages are sorted before first reading the messages 
   231     CMsvEntrySelection* messages = FilterMessagesL();
   231         Sort();
   232     CleanupStack::PushL( messages );
   232         iMessages = FilterMessagesL();
   233 
   233         }
   234     status = SearchL( messages, aStartWith, baseIndex );
   234 
       
   235     status = SearchL( iMessages, aStartWith, baseIndex );
   235     
   236     
   236     if (  status == KErrNone ) 
   237     if (  status == KErrNone ) 
   237         {
   238         {
   238         result = PreviousL(baseIndex, messages, aCount, aMessages);
   239         result = PreviousL(baseIndex, iMessages, aCount, aMessages);
   239         }
   240         }
   240 
   241 
   241     CleanupStack::PopAndDestroy(messages);
       
   242     return result;
   242     return result;
   243     }
   243     }
   244 
   244 
   245 // ---------------------------------------------------------------------------
   245 // ---------------------------------------------------------------------------
   246 // Loops over the requested messages noticing the ends of the message array
   246 // Loops over the requested messages noticing the ends of the message array