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