31 const TFSMailDetails aDetails, |
31 const TFSMailDetails aDetails, |
32 const RArray<TFSMailSortCriteria>& aSorting) |
32 const RArray<TFSMailSortCriteria>& aSorting) |
33 { |
33 { |
34 FUNC_LOG; |
34 FUNC_LOG; |
35 CIpsPlgMsgIterator* self = |
35 CIpsPlgMsgIterator* self = |
36 new( ELeave ) CIpsPlgMsgIterator( aPlugin, aMailboxId, aDetails, |
36 new( ELeave ) CIpsPlgMsgIterator( aPlugin, aMailboxId, aDetails ); |
37 aSorting ); |
|
38 CleanupStack::PushL( self ); |
37 CleanupStack::PushL( self ); |
39 self->ConstructL( aMsvSession, aFolderId, aSorting ); |
38 self->ConstructL( aMsvSession, aFolderId, aSorting ); |
40 CleanupStack::Pop( self ); |
39 CleanupStack::Pop( self ); |
41 return self; |
40 return self; |
42 } |
41 } |
51 const TFSMailDetails aDetails, |
50 const TFSMailDetails aDetails, |
52 const RArray<TFSMailSortCriteria>& aSorting) |
51 const RArray<TFSMailSortCriteria>& aSorting) |
53 { |
52 { |
54 FUNC_LOG; |
53 FUNC_LOG; |
55 CIpsPlgMsgIterator* self = |
54 CIpsPlgMsgIterator* self = |
56 new( ELeave ) CIpsPlgMsgIterator( aPlugin, aMailboxId, aDetails, |
55 new( ELeave ) CIpsPlgMsgIterator( aPlugin, aMailboxId, aDetails ); |
57 aSorting ); |
|
58 CleanupStack::PushL( self ); |
56 CleanupStack::PushL( self ); |
59 self->ConstructL( aFolderEntry, aSorting ); |
57 self->ConstructL( aFolderEntry, aSorting ); |
60 CleanupStack::Pop( self ); |
58 CleanupStack::Pop( self ); |
61 return self; |
59 return self; |
62 } |
60 } |
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 |
229 Sort(); |
229 Sort(); |
230 |
230 |
231 CMsvEntrySelection* messages = FilterMessagesL(); |
231 CMsvEntrySelection* messages = FilterMessagesL(); |
232 CleanupStack::PushL( messages ); |
232 CleanupStack::PushL( messages ); |
233 |
233 |
234 status = SearchL( messages, aStartWith, baseIndex ); |
234 status = SearchL( iMessages, aStartWith, baseIndex ); |
235 |
235 |
236 if ( status == KErrNone ) |
236 if ( status == KErrNone ) |
237 { |
237 { |
238 result = PreviousL(baseIndex, messages, aCount, aMessages); |
238 result = PreviousL(baseIndex, iMessages, aCount, aMessages); |
239 } |
239 } |
240 |
240 |
241 CleanupStack::PopAndDestroy(messages); |
|
242 return result; |
241 return result; |
243 } |
242 } |
244 |
243 |
245 // --------------------------------------------------------------------------- |
244 // --------------------------------------------------------------------------- |
246 // Loops over the requested messages noticing the ends of the message array |
245 // Loops over the requested messages noticing the ends of the message array |
265 (( entry.iMtm != KSenduiMtmImap4Uid ) || !entry.DeletedIMAP4Flag() ) && |
264 (( entry.iMtm != KSenduiMtmImap4Uid ) || !entry.DeletedIMAP4Flag() ) && |
266 ( entry.iType == KUidMsvMessageEntry ) ) |
265 ( entry.iType == KUidMsvMessageEntry ) ) |
267 { |
266 { |
268 fsMsg = iMsgMapper->GetMailMessageL( iMailboxId, entry, |
267 fsMsg = iMsgMapper->GetMailMessageL( iMailboxId, entry, |
269 iRequestedDetails ); |
268 iRequestedDetails ); |
270 aMessages.Append( fsMsg ); |
269 aMessages.AppendL( fsMsg ); |
271 counter++; |
270 counter++; |
272 } |
271 } |
273 i++; |
272 i++; |
274 } |
273 } |
275 |
274 |
305 (( entry.iMtm != KSenduiMtmImap4Uid ) || !entry.DeletedIMAP4Flag() ) && |
304 (( entry.iMtm != KSenduiMtmImap4Uid ) || !entry.DeletedIMAP4Flag() ) && |
306 ( entry.iType == KUidMsvMessageEntry ) ) |
305 ( entry.iType == KUidMsvMessageEntry ) ) |
307 { |
306 { |
308 fsMsg = iMsgMapper->GetMailMessageL( iMailboxId, entry, |
307 fsMsg = iMsgMapper->GetMailMessageL( iMailboxId, entry, |
309 iRequestedDetails ); |
308 iRequestedDetails ); |
310 aMessages.Insert( fsMsg, 0 ); |
309 aMessages.InsertL( fsMsg, 0 ); |
311 counter++; |
310 counter++; |
312 } |
311 } |
313 i--; |
312 i--; |
314 } |
313 } |
315 |
314 |
321 // --------------------------------------------------------------------------- |
320 // --------------------------------------------------------------------------- |
322 // |
321 // |
323 CIpsPlgMsgIterator::CIpsPlgMsgIterator( |
322 CIpsPlgMsgIterator::CIpsPlgMsgIterator( |
324 CIpsPlgSosBasePlugin& aPlugin, |
323 CIpsPlgSosBasePlugin& aPlugin, |
325 const TFSMailMsgId& aMailboxId, |
324 const TFSMailMsgId& aMailboxId, |
326 const TFSMailDetails aDetails, |
325 const TFSMailDetails aDetails ) |
327 const RArray<TFSMailSortCriteria>& aSorting ) |
|
328 : iPlugin( aPlugin ), iRequestedDetails( aDetails ), |
326 : iPlugin( aPlugin ), iRequestedDetails( aDetails ), |
329 iSortingCriteria( aSorting ), iMailboxId( aMailboxId ) |
327 iMailboxId( aMailboxId ) |
330 { |
328 { |
331 FUNC_LOG; |
329 FUNC_LOG; |
332 // none |
330 // none |
333 } |
331 } |
334 |
332 |
342 const TFSMailMsgId aFolderId, |
340 const TFSMailMsgId aFolderId, |
343 const RArray<TFSMailSortCriteria>& aSorting ) |
341 const RArray<TFSMailSortCriteria>& aSorting ) |
344 { |
342 { |
345 FUNC_LOG; |
343 FUNC_LOG; |
346 iFolderEntry = aMsvSession.GetEntryL( aFolderId.Id() ); |
344 iFolderEntry = aMsvSession.GetEntryL( aFolderId.Id() ); |
347 iMsgSortKey = new (ELeave) TIpsPlgMsgKey( *iFolderEntry, aSorting ); |
345 |
|
346 StoreSortCriteriaL(aSorting); |
|
347 iMsgSortKey = new (ELeave) TIpsPlgMsgKey( *iFolderEntry, iSortingCriteria ); |
348 iMsgSwapper = new (ELeave) TIpsPlgMsgSwap( *iFolderEntry ); |
348 iMsgSwapper = new (ELeave) TIpsPlgMsgSwap( *iFolderEntry ); |
349 iSortingOn = |
349 iSortingOn = |
350 ( aSorting.Count() > 0 ) && ( aSorting[0].iField != EFSMailDontCare); |
350 ( aSorting.Count() > 0 ) && ( aSorting[0].iField != EFSMailDontCare); |
351 iMsgMapper = CIpsPlgMsgMapper::NewL( aMsvSession, iPlugin ); |
351 iMsgMapper = CIpsPlgMsgMapper::NewL( aMsvSession, iPlugin ); |
352 iMsvSession = &aMsvSession; |
352 iMsvSession = &aMsvSession; |
361 CMsvEntry* aFolderEntry, |
361 CMsvEntry* aFolderEntry, |
362 const RArray<TFSMailSortCriteria>& aSorting ) |
362 const RArray<TFSMailSortCriteria>& aSorting ) |
363 { |
363 { |
364 FUNC_LOG; |
364 FUNC_LOG; |
365 iFolderEntry = aFolderEntry; |
365 iFolderEntry = aFolderEntry; |
366 iMsgSortKey = new (ELeave) TIpsPlgMsgKey( *iFolderEntry, aSorting ); |
366 StoreSortCriteriaL(aSorting); |
|
367 iMsgSortKey = new (ELeave) TIpsPlgMsgKey( *iFolderEntry, iSortingCriteria ); |
367 iMsgSwapper = new (ELeave) TIpsPlgMsgSwap( *iFolderEntry ); |
368 iMsgSwapper = new (ELeave) TIpsPlgMsgSwap( *iFolderEntry ); |
368 iSortingOn = |
369 iSortingOn = |
369 ( aSorting.Count() > 0 ) && ( aSorting[0].iField != EFSMailDontCare); |
370 ( aSorting.Count() > 0 ) && ( aSorting[0].iField != EFSMailDontCare); |
370 iMsgMapper = CIpsPlgMsgMapper::NewL( aFolderEntry->Session(), iPlugin ); |
371 iMsgMapper = CIpsPlgMsgMapper::NewL( aFolderEntry->Session(), iPlugin ); |
371 iMsvSession = NULL; |
372 iMsvSession = NULL; |
480 filteredEntries = iFolderEntry->ChildrenWithServiceL( iMailboxId.Id() ); |
481 filteredEntries = iFolderEntry->ChildrenWithServiceL( iMailboxId.Id() ); |
481 } |
482 } |
482 return filteredEntries; |
483 return filteredEntries; |
483 } |
484 } |
484 |
485 |
|
486 // ----------------------------------------------------------------------------- |
|
487 // stores sort criteria given by user |
|
488 // ----------------------------------------------------------------------------- |
|
489 void CIpsPlgMsgIterator::StoreSortCriteriaL( |
|
490 const RArray<TFSMailSortCriteria>& aSorting ) |
|
491 { |
|
492 for ( TInt i=0; i < aSorting.Count(); i++ ) |
|
493 { |
|
494 const TFSMailSortCriteria& criteria = aSorting[i]; |
|
495 TFSMailSortCriteria fsCriteria; |
|
496 fsCriteria.iField = criteria.iField; |
|
497 fsCriteria.iOrder = criteria.iOrder; |
|
498 iSortingCriteria.AppendL(fsCriteria); |
|
499 } |
|
500 } |
|
501 |