27 // ======== MEMBER FUNCTIONS ======== |
27 // ======== MEMBER FUNCTIONS ======== |
28 |
28 |
29 // --------------------------------------------------------------------------- |
29 // --------------------------------------------------------------------------- |
30 // CEmailMessageSearchAsync::NewL |
30 // CEmailMessageSearchAsync::NewL |
31 // --------------------------------------------------------------------------- |
31 // --------------------------------------------------------------------------- |
32 // |
|
33 CEmailMessageSearchAsync* CEmailMessageSearchAsync::NewL( |
32 CEmailMessageSearchAsync* CEmailMessageSearchAsync::NewL( |
34 CPluginData& aPluginData, |
33 CPluginData& aPluginData, |
35 const TMailboxId& aMailboxId ) |
34 const TMailboxId& aMailboxId ) |
36 { |
35 { |
37 CEmailMessageSearchAsync* self = new (ELeave) CEmailMessageSearchAsync(aPluginData, aMailboxId); |
36 CEmailMessageSearchAsync* self = |
|
37 new ( ELeave ) CEmailMessageSearchAsync( aPluginData, aMailboxId ); |
38 CleanupStack::PushL( self ); |
38 CleanupStack::PushL( self ); |
39 self->ConstructL(); |
39 self->ConstructL(); |
40 CleanupStack::Pop(); |
40 CleanupStack::Pop( self ); |
41 return self; |
41 return self; |
42 } |
42 } |
43 |
|
44 |
43 |
45 // --------------------------------------------------------------------------- |
44 // --------------------------------------------------------------------------- |
46 // |
45 // |
47 // --------------------------------------------------------------------------- |
46 // --------------------------------------------------------------------------- |
48 // |
|
49 void CEmailMessageSearchAsync::ConstructL() |
47 void CEmailMessageSearchAsync::ConstructL() |
50 { |
48 { |
51 iPlugin = iPluginData.ClaimInstanceL(); |
49 iPlugin = iPluginData.ClaimInstanceL(); |
52 // Open existing semaphore, or create a new one |
50 // Open existing semaphore, or create a new one |
53 if (KErrNone != iGate.OpenGlobal(KGlobalSemaphoreToPreventParallelCall, EOwnerProcess)) |
51 if ( KErrNone != iGate.OpenGlobal( KGlobalSemaphoreToPreventParallelCall, EOwnerProcess ) ) |
54 { |
52 { |
55 User::LeaveIfError(iGate.CreateGlobal(KGlobalSemaphoreToPreventParallelCall, 1, EOwnerProcess)); |
53 User::LeaveIfError( |
56 } |
54 iGate.CreateGlobal( KGlobalSemaphoreToPreventParallelCall, 1, EOwnerProcess ) ); |
57 } |
55 } |
58 |
56 } |
59 |
57 |
60 // ----------------------------------------------------------------------------- |
58 // ----------------------------------------------------------------------------- |
61 // |
59 // |
62 // ----------------------------------------------------------------------------- |
60 // ----------------------------------------------------------------------------- |
63 CEmailMessageSearchAsync::CEmailMessageSearchAsync( |
61 CEmailMessageSearchAsync::CEmailMessageSearchAsync( |
64 CPluginData& aPluginData, |
62 CPluginData& aPluginData, |
65 const TMailboxId& aMailboxId ) |
63 const TMailboxId& aMailboxId ) |
66 : iPluginData( aPluginData ), iMailboxId( aMailboxId.iId ), |
64 : iPluginData( aPluginData ), iMailboxId( aMailboxId.iId ), |
67 iCriteria(), iObserver(NULL), iRemote(EFalse) |
65 iCriteria(), iObserver( NULL ), iRemote( EFalse ) |
68 { |
66 { |
69 } |
67 } |
70 |
|
71 |
68 |
72 // ----------------------------------------------------------------------------- |
69 // ----------------------------------------------------------------------------- |
73 // |
70 // |
74 // ----------------------------------------------------------------------------- |
71 // ----------------------------------------------------------------------------- |
75 CEmailMessageSearchAsync::~CEmailMessageSearchAsync() |
72 CEmailMessageSearchAsync::~CEmailMessageSearchAsync() |
97 this->Cancel(); |
94 this->Cancel(); |
98 } |
95 } |
99 delete this; |
96 delete this; |
100 } |
97 } |
101 |
98 |
102 /** |
99 // ----------------------------------------------------------------------------- |
103 * Sets sort order for search results. |
100 // Sets sort order for search results. |
104 * Leaves KErrNotReady if search is ongoing. |
101 // Leaves KErrNotReady if search is ongoing. |
105 */ |
102 // ----------------------------------------------------------------------------- |
106 void CEmailMessageSearchAsync::SetSortCriteriaL( const TEmailSortCriteria& aCriteria ) |
103 void CEmailMessageSearchAsync::SetSortCriteriaL( const TEmailSortCriteria& aCriteria ) |
107 { |
104 { |
108 if (KErrNone != iGate.Wait(1)) |
105 IsSearchGoingOnL(); |
109 { |
106 |
110 // Leave now, search is going on |
|
111 User::Leave( KErrNotReady ); |
|
112 } |
|
113 switch (aCriteria.iField) |
107 switch (aCriteria.iField) |
114 { |
108 { |
115 case TEmailSortCriteria::EDontCare: |
109 case TEmailSortCriteria::EDontCare: |
116 iCriteria.iField = EFSMailDontCare; |
110 iCriteria.iField = EFSMailDontCare; |
117 break; |
111 break; |
118 |
112 |
119 case TEmailSortCriteria::EByDate: |
113 case TEmailSortCriteria::EByDate: |
120 iCriteria.iField = EFSMailSortByDate; |
114 iCriteria.iField = EFSMailSortByDate; |
121 break; |
115 break; |
122 |
116 |
123 case TEmailSortCriteria::EBySender: |
117 case TEmailSortCriteria::EBySender: |
124 iCriteria.iField = EFSMailSortBySender; |
118 iCriteria.iField = EFSMailSortBySender; |
125 break; |
119 break; |
126 |
120 |
127 case TEmailSortCriteria::EByRecipient: |
121 case TEmailSortCriteria::EByRecipient: |
128 iCriteria.iField = EFSMailSortByRecipient; |
122 iCriteria.iField = EFSMailSortByRecipient; |
129 break; |
123 break; |
130 |
124 |
131 case TEmailSortCriteria::EBySubject: |
125 case TEmailSortCriteria::EBySubject: |
132 iCriteria.iField = EFSMailSortBySubject; |
126 iCriteria.iField = EFSMailSortBySubject; |
133 break; |
127 break; |
134 |
128 |
135 case TEmailSortCriteria::EByPriority: |
129 case TEmailSortCriteria::EByPriority: |
136 iCriteria.iField = EFSMailSortByPriority; |
130 iCriteria.iField = EFSMailSortByPriority; |
137 break; |
131 break; |
138 |
132 |
139 case TEmailSortCriteria::EByFlagStatus: |
133 case TEmailSortCriteria::EByFlagStatus: |
140 iCriteria.iField = EFSMailSortByFlagStatus; |
134 iCriteria.iField = EFSMailSortByFlagStatus; |
141 break; |
135 break; |
142 |
136 |
143 case TEmailSortCriteria::EByUnread: |
137 case TEmailSortCriteria::EByUnread: |
144 iCriteria.iField = EFSMailSortByUnread; |
138 iCriteria.iField = EFSMailSortByUnread; |
145 break; |
139 break; |
146 |
140 |
147 case TEmailSortCriteria::EBySize: |
141 case TEmailSortCriteria::EBySize: |
148 iCriteria.iField = EFSMailSortBySize; |
142 iCriteria.iField = EFSMailSortBySize; |
149 break; |
143 break; |
150 |
144 |
151 case TEmailSortCriteria::EByAttachment: |
145 case TEmailSortCriteria::EByAttachment: |
152 iCriteria.iField = EFSMailSortByAttachment; |
146 iCriteria.iField = EFSMailSortByAttachment; |
153 break; |
147 break; |
154 |
148 |
155 default: |
149 default: |
156 User::Leave( KErrNotSupported ); |
150 User::Leave( KErrNotSupported ); |
157 break; |
151 break; |
158 |
152 |
159 } |
153 } |
160 if (aCriteria.iAscending) |
154 if (aCriteria.iAscending) |
161 { |
155 { |
162 iCriteria.iOrder = EFSMailAscending; |
156 iCriteria.iOrder = EFSMailAscending; |
163 } |
157 } |
164 else |
158 else |
165 { |
159 { |
166 iCriteria.iOrder = EFSMailDescending; |
160 iCriteria.iOrder = EFSMailDescending; |
167 } |
161 } |
168 // Release gate |
162 // Release gate |
169 iGate.Signal(); |
163 iGate.Signal(); |
170 } |
164 } |
171 |
165 |
172 /** |
166 // ----------------------------------------------------------------------------- |
173 * Adds a search key. Leaves KErrNotReady if search is ongoing. |
167 // Adds a search key. Leaves KErrNotReady if search is ongoing. |
174 */ |
168 // ----------------------------------------------------------------------------- |
175 void CEmailMessageSearchAsync::AddSearchKeyL( const TDesC& aSearchKey ) |
169 void CEmailMessageSearchAsync::AddSearchKeyL( const TDesC& aSearchKey ) |
176 { |
170 { |
177 if (KErrNone != iGate.Wait(1)) |
171 IsSearchGoingOnL(); |
178 { |
172 |
179 // Leave now, search is going on |
|
180 User::Leave( KErrNotReady ); |
|
181 } |
|
182 iSearchStrings.AppendL(&aSearchKey); |
173 iSearchStrings.AppendL(&aSearchKey); |
183 // Release gate |
174 // Release gate |
184 iGate.Signal(); |
175 iGate.Signal(); |
185 } |
176 } |
186 |
177 |
187 /** |
178 /// ----------------------------------------------------------------------------- |
188 * Enables/disables search from remote email server. |
179 // Enables/disables search from remote email server. |
189 * Leaves KErrNotReady if search is ongoing. |
180 // Leaves KErrNotReady if search is ongoing. |
190 */ |
181 // ----------------------------------------------------------------------------- |
191 void CEmailMessageSearchAsync::SetRemoteSearchL( TBool aRemote ) |
182 void CEmailMessageSearchAsync::SetRemoteSearchL( TBool aRemote ) |
192 { |
183 { |
193 if (KErrNone != iGate.Wait(1)) |
184 IsSearchGoingOnL(); |
194 { |
185 |
195 // Leave now, search is going on |
|
196 User::Leave( KErrNotReady ); |
|
197 } |
|
198 iRemote = aRemote; |
186 iRemote = aRemote; |
199 // Release gate |
187 // Release gate |
200 iGate.Signal(); |
188 iGate.Signal(); |
201 // Currently plugins do not support this function |
189 // Currently plugins do not support this function |
202 User::Leave( KErrNotSupported ); |
190 User::Leave( KErrNotSupported ); |
203 } |
191 } |
204 |
192 |
205 /** |
193 // ----------------------------------------------------------------------------- |
206 * Indicates whether remote search is enabled. |
194 // Indicates whether remote search is enabled. |
207 */ |
195 // ----------------------------------------------------------------------------- |
208 TBool CEmailMessageSearchAsync::IsRemoteSearch() const |
196 TBool CEmailMessageSearchAsync::IsRemoteSearch() const |
209 { |
197 { |
210 // Currently plugins do not support this function |
198 // Currently plugins do not support this function |
211 return EFalse; |
199 return EFalse; |
212 } |
200 } |
213 |
201 |
214 /** |
202 // ----------------------------------------------------------------------------- |
215 * Starts search, all methods affecting search attribures leave |
203 // Starts search, all methods affecting search attribures leave |
216 * KErrNotReady while search is ongoing. |
204 // KErrNotReady while search is ongoing. |
217 * @param aObserver called when results are available. |
205 // @param aObserver called when results are available. |
218 */ |
206 // |
219 void CEmailMessageSearchAsync::StartSearchL( MEmailSearchObserver& aObserver ) |
207 void CEmailMessageSearchAsync::StartSearchL( MEmailSearchObserver& aObserver ) |
220 { |
208 { |
221 if (KErrNone != iGate.Wait(1)) |
209 IsSearchGoingOnL(); |
222 { |
210 |
223 // Leave now, search is going on |
|
224 User::Leave( KErrNotReady ); |
|
225 } |
|
226 iObserver = &aObserver; |
211 iObserver = &aObserver; |
227 const TFSMailMsgId fsMailboxId( iPluginData.Uid(), iMailboxId.iId ); |
212 const TFSMailMsgId fsMailboxId( iPluginData.Uid(), iMailboxId.iId ); |
228 RArray <TFSMailMsgId> folderIds; |
213 RArray <TFSMailMsgId> folderIds; |
229 CleanupClosePushL( folderIds ); |
214 |
230 |
|
231 /** Search API */ |
215 /** Search API */ |
232 |
216 |
233 /** |
217 /** |
234 * Asyncronous call for starting search for given string. Only one search can be |
218 * Asyncronous call for starting search for given string. Only one search can be |
235 * performed at a time. |
219 * performed at a time. |
236 * |
220 * |
237 * |
221 * |
254 * global or folder specific search depends on the size of array is 0 or not. |
238 * global or folder specific search depends on the size of array is 0 or not. |
255 * @param aSearchStrings text strings that will be searched from different message fields. |
239 * @param aSearchStrings text strings that will be searched from different message fields. |
256 * @param aSortCriteria sort criteria for the results |
240 * @param aSortCriteria sort criteria for the results |
257 * @param aSearchObserver client observer that will be notified about search status. |
241 * @param aSearchObserver client observer that will be notified about search status. |
258 * |
242 * |
259 */ |
243 */ |
260 iPlugin->SearchL( fsMailboxId, |
244 iPlugin->SearchL( fsMailboxId, |
261 folderIds, |
245 folderIds, |
262 iSearchStrings, |
246 iSearchStrings, |
263 iCriteria, |
247 iCriteria, |
264 *this ); |
248 *this ); |
265 // Gate is kept closed as search is asynchronous. Gate will be reopen after search is completed, i.e. |
249 // Gate is kept closed as search is asynchronous. Gate will be reopen after search is completed, i.e. |
266 // CEmailMessageSearchAsync::SearchCompleted. |
250 // CEmailMessageSearchAsync::SearchCompleted. |
267 CleanupStack::PopAndDestroy( &folderIds ); |
251 } |
268 } |
252 |
269 |
253 // ----------------------------------------------------------------------------- |
270 /** |
254 // Cancels search. |
271 * Cancels search. |
255 // ----------------------------------------------------------------------------- |
272 */ |
256 void CEmailMessageSearchAsync::Cancel() |
273 void CEmailMessageSearchAsync::Cancel() |
|
274 { |
257 { |
275 if (KErrNone != iGate.Wait(1)) |
258 if (KErrNone != iGate.Wait(1)) |
276 { |
259 { |
277 |
260 |
278 /** |
261 /** |
287 { |
270 { |
288 // Release gate |
271 // Release gate |
289 iGate.Signal(); |
272 iGate.Signal(); |
290 } |
273 } |
291 } |
274 } |
292 |
275 |
293 /** returns search status |
276 // ----------------------------------------------------------------------------- |
294 * @return search status: |
277 // * @return search status: |
295 * < 0 : Search has failed |
278 // * < 0 : Search has failed |
296 * KRequestPending : search is ongoing. note that status may be |
279 // * KRequestPending : search is ongoing. note that status may be |
297 * KRequestPending after HandleResultL callback because results |
280 // * KRequestPending after HandleResultL callback because results |
298 * may be given in chunks of results. Size of chunk depends on |
281 // * may be given in chunks of results. Size of chunk depends on |
299 * implementation and may vary. |
282 // * implementation and may vary. |
300 * KErrNone : initial state, or search has finished |
283 // * KErrNone : initial state, or search has finished |
301 */ |
284 // ----------------------------------------------------------------------------- |
302 TInt CEmailMessageSearchAsync::Status() const |
285 TInt CEmailMessageSearchAsync::Status() const |
303 { |
286 { |
304 if (KErrNone != iGate.Wait(1)) |
287 if (KErrNone != iGate.Wait(1)) |
305 { |
288 { |
306 // Search is going on |
289 // Search is going on |
307 return KRequestPending; |
290 return KRequestPending; |
308 } |
291 } |
309 else |
292 else |
310 { |
293 { |
311 // Release gate |
294 // Release gate |
312 iGate.Signal(); |
295 iGate.Signal(); |
313 } |
296 } |
314 |
297 |
315 return KErrNone; |
298 return KErrNone; |
316 } |
299 } |
317 |
300 |
318 /** |
301 // ----------------------------------------------------------------------------- |
319 * Resets all search attribures. Cancels search if ongoing. |
302 // Resets all search attribures. Cancels search if ongoing. |
320 */ |
303 // ----------------------------------------------------------------------------- |
321 void CEmailMessageSearchAsync::Reset() |
304 void CEmailMessageSearchAsync::Reset() |
322 { |
305 { |
323 if (KErrNone != iGate.Wait(1)) |
306 if ( KErrNone != iGate.Wait( 1 ) ) |
324 { |
307 { |
325 this->Cancel(); |
308 this->Cancel(); |
326 } |
309 } |
327 |
310 |
328 iCriteria = TFSMailSortCriteria(); |
311 iCriteria = TFSMailSortCriteria(); |
331 // Release gate |
314 // Release gate |
332 iGate.Signal(); |
315 iGate.Signal(); |
333 |
316 |
334 }; |
317 }; |
335 |
318 |
336 /** |
319 // ----------------------------------------------------------------------------- |
337 * Notifies the email search API client that a match has been found |
320 // Notifies the email search API client that a match has been found |
338 * |
321 // |
339 * @param aMatchMessage contains a pointer to the matched message. |
322 // @param aMatchMessage contains a pointer to the matched message. |
340 * Ownership is transfered to the observer. |
323 // Ownership is transfered to the observer. |
341 * |
324 // ----------------------------------------------------------------------------- |
342 */ |
|
343 void CEmailMessageSearchAsync::MatchFoundL( CFSMailMessage* aMatchMessage ) |
325 void CEmailMessageSearchAsync::MatchFoundL( CFSMailMessage* aMatchMessage ) |
344 { |
326 { |
|
327 User::LeaveIfNull( iObserver ); |
345 CEmailMessage *result = CEmailMessage::NewL(iPluginData, aMatchMessage, EClientOwns ); |
328 CEmailMessage *result = CEmailMessage::NewL(iPluginData, aMatchMessage, EClientOwns ); |
346 iObserver->HandleResultL(result); |
329 iObserver->HandleResultL( result ); |
347 } |
330 } |
348 |
331 |
349 /** |
332 // ----------------------------------------------------------------------------- |
350 * Notifies the email search API client that the search has completed |
333 // Notifies the email search API client that the search has completed |
351 * |
334 // ----------------------------------------------------------------------------- |
352 */ |
|
353 void CEmailMessageSearchAsync::SearchCompletedL() |
335 void CEmailMessageSearchAsync::SearchCompletedL() |
354 { |
336 { |
355 iObserver->SearchCompletedL(); |
337 User::LeaveIfNull( iObserver ); |
|
338 iObserver->SearchCompletedL(); |
356 // Search is now complete, release gate. |
339 // Search is now complete, release gate. |
357 iGate.Signal(); |
340 iGate.Signal(); |
358 } |
341 } |
359 |
342 |
360 // |
343 // ----------------------------------------------------------------------------- |
361 /** |
344 // Asks client if search engine should change search priority |
362 * Asks client if search engine should change search priority |
345 // ----------------------------------------------------------------------------- |
363 */ |
346 void CEmailMessageSearchAsync::ClientRequiredSearchPriority(TInt* /*apRequiredSearchPriority*/) |
364 void CEmailMessageSearchAsync::ClientRequiredSearchPriority(TInt * /* apRequiredSearchPriority */ ) |
347 { |
365 { |
348 } |
366 return; |
349 |
367 } |
350 // ----------------------------------------------------------------------------- |
368 // |
351 // Function leaves if search is going on. Otherwise it doesn't do anything. |
|
352 // ----------------------------------------------------------------------------- |
|
353 void CEmailMessageSearchAsync::IsSearchGoingOnL() const |
|
354 { |
|
355 if ( KErrNone != iGate.Wait( 1 ) ) |
|
356 { |
|
357 // Leave now, search is going on |
|
358 User::Leave( KErrNotReady ); |
|
359 } |
|
360 } |
|
361 |
|
362 // End of file |