|
1 /* |
|
2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Plugin for calendarplugin information search. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 //System Includes |
|
21 #include <utf.h> |
|
22 #include <calinstance.h> |
|
23 #include <calentry.h> |
|
24 #include <calalarm.h> |
|
25 #include <searchcondition.h> |
|
26 #include <searchtextsearcher.h> |
|
27 #include <searchpluginobserver.h> |
|
28 #include <searchresult.h> |
|
29 #include <searchlightresult.h> |
|
30 #include <searchcommon.h> |
|
31 #include <searchdocumentid.h> |
|
32 #include <avkon.rsg> |
|
33 #include <barsc.h> |
|
34 #include <barsread.h> |
|
35 #include <bautils.h> |
|
36 #include <data_caging_path_literals.hrh> |
|
37 |
|
38 #include "calendarsearcher.h" |
|
39 #include "calentrydetails.h" |
|
40 #include "calendarsearchpluginpanic.h" |
|
41 #include "defines.h" |
|
42 |
|
43 const int KBufferLength = 60; |
|
44 const int KBigBufferLength = 120; |
|
45 _LIT( KAvkonResoureFilePath, "avkon.Rsc" ); |
|
46 _LIT( KEmptySpace, " " ); |
|
47 const int KHour = 23; |
|
48 const int KMinute = 59; |
|
49 |
|
50 // ============================ MEMBER FUNCTIONS =============================== |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CCalendarSearcher::NewL |
|
54 // Symbian OS 2 phased constructor. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CCalendarSearcher* CCalendarSearcher::NewL( const RArray<TUid>& aContentIdArray, |
|
58 const CSearchCondition& aCondition, |
|
59 const TUid& aPluginId, |
|
60 MSearchPluginObserver& aObserver ) |
|
61 { |
|
62 CCalendarSearcher* self = new( ELeave )CCalendarSearcher( aPluginId ); |
|
63 CleanupStack::PushL ( self ); |
|
64 self->ConstructL( aContentIdArray, aCondition,aObserver); |
|
65 CleanupStack::Pop( self ); |
|
66 return self; |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CCalendarSearcher::CCalendarSearcher |
|
71 // Destructor. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 CCalendarSearcher::~CCalendarSearcher() |
|
75 { |
|
76 iFsSession.Close(); |
|
77 |
|
78 |
|
79 delete iTextSearcher; |
|
80 iTextSearcher = NULL; |
|
81 |
|
82 delete iReadDateBuffer; |
|
83 iReadDateBuffer = NULL; |
|
84 |
|
85 |
|
86 delete iReadTimeBuffer; |
|
87 iReadTimeBuffer = NULL; |
|
88 |
|
89 if(0 < iHeavyResultsArray.Count()) |
|
90 { |
|
91 iHeavyResultsArray.Reset(); |
|
92 } |
|
93 |
|
94 iCalDesCArray.ResetAndDestroy(); |
|
95 iCalLocalUidArray.Close(); |
|
96 |
|
97 delete iEntry; |
|
98 |
|
99 delete iEntryView; |
|
100 delete iInstanceView; |
|
101 delete iSession; |
|
102 iSession = NULL; |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CCalendarSearcher::GetIfEntryExists |
|
107 // Check if the entry exists in calander |
|
108 // ----------------------------------------------------------------------------- |
|
109 |
|
110 TBool CCalendarSearcher::GetIfEntryExistsL (TCalLocalUid aId) |
|
111 { |
|
112 |
|
113 CCalEntry * temp = iEntryView->FetchL(aId); |
|
114 if(temp) |
|
115 { |
|
116 delete temp; |
|
117 temp = NULL; |
|
118 return ETrue; |
|
119 } |
|
120 return EFalse; |
|
121 |
|
122 |
|
123 } |
|
124 // CCalendarSearcher::StartSearchL |
|
125 // Start search, set active |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 void CCalendarSearcher::StartSearchL() |
|
129 { |
|
130 if( iNeedToCallReportFinishedL ) |
|
131 { |
|
132 ReportFinishedL( iErrorCode ); |
|
133 return; |
|
134 } |
|
135 |
|
136 // set the active object in pending state until the CCalEntryView is created |
|
137 iStatus = KRequestPending; // change Kiran |
|
138 SetActive(); |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CCalendarSearcher::Destroy |
|
143 // Performs the Cleanup operations. |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 void CCalendarSearcher::Destroy() |
|
147 { |
|
148 iSearchNotCancelled = EFalse; |
|
149 if(IsActive()) |
|
150 { |
|
151 CActive::Cancel(); |
|
152 } |
|
153 else |
|
154 { |
|
155 Cleanup(); |
|
156 } |
|
157 |
|
158 |
|
159 if(0 < iHeavyResultsArray.Count()) |
|
160 { |
|
161 iHeavyResultsArray.ResetAndDestroy(); |
|
162 } |
|
163 |
|
164 iCalDesCArray.ResetAndDestroy(); |
|
165 delete this; |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CCalendarSearcher::SearchL |
|
170 // Performs a Search Operation |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 void CCalendarSearcher::SearchL() |
|
174 { |
|
175 |
|
176 iSearchNotCancelled = ETrue; |
|
177 iCalDesCArray.ResetAndDestroy(); |
|
178 |
|
179 if(0 < iHeavyResultsArray.Count()) |
|
180 { |
|
181 iHeavyResultsArray.ResetAndDestroy(); |
|
182 } |
|
183 |
|
184 // Check if plug-in was constructed for searching and if not panic |
|
185 __ASSERT_ALWAYS( this, User::Panic( KCalendarSearchPlugIn, |
|
186 ECalendarSearchPlugInWrongConstructionParameters ) ); |
|
187 |
|
188 if( !iFilter ) |
|
189 { |
|
190 ReportFinishedL( KErrNone ); |
|
191 return; |
|
192 } |
|
193 |
|
194 // ASSERT_ here when already searching |
|
195 __ASSERT_ALWAYS( !IsSearching(), User::Panic( KCalendarSearchPlugIn, |
|
196 ECalendarSearchPlugInActiveSearchingExist) ); |
|
197 |
|
198 if( iSetParamsDone ) |
|
199 { |
|
200 InitializationL(); |
|
201 } |
|
202 else |
|
203 { |
|
204 ReportFinishedL( iErrorCode ); |
|
205 } |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CCalendarSearcher::IsSearching |
|
210 // Checks wheather a Search Operation is going or not. |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 TBool CCalendarSearcher::IsSearching() |
|
214 { |
|
215 return IsActive(); |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CCalendarSearcher::CancelSearch |
|
220 // Canels the Search operation. |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void CCalendarSearcher::CancelSearch() |
|
224 { |
|
225 iSearchNotCancelled = EFalse; |
|
226 CActive::Cancel(); |
|
227 Cleanup(); |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CCalendarSearcher::GetResultsL |
|
232 // Results are passed in aDocumentIdArray. |
|
233 // ---------------------------------------------------------f-------------------- |
|
234 // |
|
235 void CCalendarSearcher::GetResultsL( const RPointerArray<CSearchDocumentId>& aDocumentIdArray ) |
|
236 { |
|
237 RPointerArray<CSearchResult> aSearchResultArray; |
|
238 _LIT8(KText,"MIME/TEXT"); |
|
239 TBufC8<KBufferLength> tempBuf(KText); |
|
240 |
|
241 for( TInt i = 0 ; i < aDocumentIdArray.Count() ; i++ ) |
|
242 { |
|
243 for( TInt j = 0 ; j < iHeavyResultsArray.Count() ; j++ ) |
|
244 { |
|
245 |
|
246 if( (aDocumentIdArray[i]->DocumentId() == |
|
247 (iHeavyResultsArray[j]->Result()).DocumentId().DocumentId() ) && |
|
248 (aDocumentIdArray[i]->PluginId().iUid == iPluginId.iUid ) && |
|
249 (aDocumentIdArray[i]->RepositoryId() == KSearchCClassCalendarUid.iUid) |
|
250 ) |
|
251 |
|
252 { |
|
253 CSearchResult* tempHeavy = iHeavyResultsArray[j]; |
|
254 if((&tempHeavy->Title() != NULL) && (&tempHeavy->Snippet() != NULL)) |
|
255 { |
|
256 aSearchResultArray.Append( iHeavyResultsArray[j]); |
|
257 continue; |
|
258 } |
|
259 |
|
260 TBufC8<KBufferLength> tempString; |
|
261 TPtr8 tempPtr8( tempString.Des() ); |
|
262 CnvUtfConverter::ConvertFromUnicodeToUtf8( tempPtr8, |
|
263 *( iCalDesCArray[j]->GetSnippet()) ); |
|
264 |
|
265 HBufC* tmpTitlte = (iCalDesCArray[j]->GetSummary())->AllocL(); |
|
266 if( tmpTitlte->Length() == 0 ) |
|
267 { |
|
268 _LIT(KUnNamed, "<Unnamed>"); |
|
269 TBufC<20> tmpBufTitle(KUnNamed); |
|
270 tmpTitlte = tmpBufTitle.AllocL(); |
|
271 } |
|
272 |
|
273 iHeavyResultsArray[j]->SetTitleL( *tmpTitlte ); |
|
274 delete tmpTitlte; |
|
275 tmpTitlte = NULL; |
|
276 iHeavyResultsArray[j]->SetSnippetL( tempPtr8 ); |
|
277 iHeavyResultsArray[j]->SetSnippetFormatL( tempBuf.Des() ); |
|
278 aSearchResultArray.AppendL( iHeavyResultsArray[j] ); |
|
279 } |
|
280 |
|
281 } |
|
282 } |
|
283 |
|
284 iObserver->ResultsRetrieveCompleteL( aSearchResultArray ); |
|
285 aSearchResultArray.Reset(); |
|
286 } |
|
287 |
|
288 // ----------------------------------------------------------------------------- |
|
289 // CCalendarSearcher::CancelResultsRetrieve |
|
290 // Cancels the operation of result retrieval. |
|
291 // ----------------------------------------------------------------------------- |
|
292 // |
|
293 void CCalendarSearcher::CancelResultsRetrieve() |
|
294 { |
|
295 |
|
296 } |
|
297 |
|
298 // ----------------------------------------------------------------------------- |
|
299 // CCalendarSearcher::GetSearchProgressL |
|
300 // |
|
301 // ----------------------------------------------------------------------------- |
|
302 // |
|
303 void CCalendarSearcher::GetSearchProgressL( TUid& aContentClassId, |
|
304 TInt& aCurrentDocument, |
|
305 TInt& aTotalDocuments ) |
|
306 { |
|
307 if( aContentClassId == KSearchCClassCalendarUid ) |
|
308 { |
|
309 aCurrentDocument = iCurrentDocumentSearching; |
|
310 aTotalDocuments = iTotalNumOfDocumentsSearched; |
|
311 } |
|
312 } |
|
313 |
|
314 // ----------------------------------------------------------------------------- |
|
315 // CCalendarSearcher::HitL |
|
316 // Called by TextObserver when Keyword is found. |
|
317 // ----------------------------------------------------------------------------- |
|
318 // |
|
319 void CCalendarSearcher::HitL( TInt aKeyWordPos ) |
|
320 { |
|
321 if( isFirstKeyWordHit && aKeyWordPos!= KErrNotFound ) |
|
322 { |
|
323 |
|
324 _LIT8( KNumber, "%d" ); |
|
325 HBufC8* buf8 = HBufC8::NewLC( KUidLength ); |
|
326 buf8->Des().Format( KNumber, iEntry->LocalUidL() ); |
|
327 CSearchDocumentId* documentId = CSearchDocumentId::NewL( iEntry->LocalUidL(), iPluginId ); |
|
328 documentId->SetRepositoryIdL( KSearchCClassCalendarUid.iUid); |
|
329 |
|
330 CSearchLightResult* searchLightResult = CSearchLightResult::NewL( documentId ); |
|
331 searchLightResult->SetContentClassId( KSearchCClassCalendarUid ); |
|
332 |
|
333 iTotalNumOfDocumentsSearched++; |
|
334 |
|
335 if( iEntry->EntryTypeL() == CCalEntry::EAnniv ) |
|
336 { |
|
337 searchLightResult->SetContentFolderId( KSearchCFolderAnniversaryUid ); |
|
338 } |
|
339 |
|
340 if( ( iEntry->EntryTypeL() == CCalEntry::EAppt ) || |
|
341 ( iEntry->EntryTypeL() == CCalEntry::EReminder ) ) |
|
342 { |
|
343 searchLightResult->SetContentFolderId( KSearchCFolderMeetingsUid ); |
|
344 } |
|
345 |
|
346 if( iEntry->EntryTypeL() == CCalEntry::EEvent ) |
|
347 { |
|
348 searchLightResult->SetContentFolderId( KSearchCFolderMemoUid ); |
|
349 } |
|
350 |
|
351 if( iEntry->EntryTypeL() == CCalEntry::ETodo ) |
|
352 { |
|
353 searchLightResult->SetContentFolderId( KSearchCFolderToDoUid ); |
|
354 } |
|
355 |
|
356 searchLightResult->SetServiceId( KNullUid ); |
|
357 isFirstKeyWordHit = 0; |
|
358 |
|
359 CCalDesC* caldetail = new(ELeave) CCalDesC(); |
|
360 CleanupStack::PushL ( caldetail ); |
|
361 |
|
362 TTime startDateTime = iEntry->StartTimeL().TimeLocalL(); |
|
363 |
|
364 const TPtrC16 ptrReadDateBuffer(( TText16*) iReadDateBuffer->Ptr(), |
|
365 ( iReadDateBuffer->Length()+1 )>>1 ); |
|
366 HBufC16* dateBuffer=HBufC16::NewLC(ptrReadDateBuffer.Length()); |
|
367 *dateBuffer=ptrReadDateBuffer; |
|
368 |
|
369 TBufC<KBigBufferLength> dateString; |
|
370 TPtr tempDateStringPtr( dateString.Des() ); |
|
371 startDateTime.FormatL( tempDateStringPtr, *dateBuffer ); |
|
372 CCalAlarm* pAlarm = iEntry->AlarmL(); |
|
373 |
|
374 if( ( iEntry->EntryTypeL() == CCalEntry::EAppt ) || |
|
375 ( iEntry->EntryTypeL() == CCalEntry::EReminder ) || |
|
376 ( iEntry->EntryTypeL() == CCalEntry::EEvent && pAlarm )|| |
|
377 ( iEntry->EntryTypeL() == CCalEntry::ETodo && pAlarm ) ) |
|
378 { |
|
379 if( iEntry->EntryTypeL() == CCalEntry::EEvent || |
|
380 iEntry->EntryTypeL() == CCalEntry::ETodo ) |
|
381 { |
|
382 TTimeIntervalMinutes timeInterval = pAlarm->TimeOffset(); |
|
383 startDateTime = startDateTime - timeInterval; |
|
384 } |
|
385 |
|
386 const TPtrC16 ptrReadTimeBuffer(( TText16*) iReadTimeBuffer->Ptr(), |
|
387 ( iReadTimeBuffer->Length()+1 )>>1 ); |
|
388 HBufC16* timeBuffer=HBufC16::NewLC( ptrReadTimeBuffer.Length() ); |
|
389 *timeBuffer=ptrReadTimeBuffer; |
|
390 |
|
391 TBufC<KBufferLength> timeString; |
|
392 TPtr tempTimeStringPtr( timeString.Des() ); |
|
393 startDateTime.FormatL( tempTimeStringPtr, *timeBuffer ); |
|
394 tempDateStringPtr.Append( KEmptySpace ); |
|
395 tempDateStringPtr.Append( tempTimeStringPtr ); |
|
396 |
|
397 CleanupStack::PopAndDestroy( timeBuffer ); |
|
398 } |
|
399 |
|
400 caldetail->SetSnippetL( tempDateStringPtr ); |
|
401 caldetail->SetSummaryL( iEntry->SummaryL() ); |
|
402 caldetail->SetUidL( *buf8 ); |
|
403 iCalDesCArray.AppendL( caldetail ); |
|
404 |
|
405 CleanupStack::PopAndDestroy( dateBuffer ); |
|
406 CleanupStack::Pop( caldetail ); |
|
407 CleanupStack::PopAndDestroy( buf8 ); |
|
408 |
|
409 |
|
410 |
|
411 CSearchResult* searchResult = CSearchResult::NewL( searchLightResult); |
|
412 |
|
413 searchResult->SetSnippetL(KNullDesC8); |
|
414 searchResult->SetTitleL(KNullDesC); |
|
415 iHeavyResultsArray.Append( searchResult ); |
|
416 |
|
417 iObserver->ResultFoundL( searchLightResult, iCurrentDocumentSearching, |
|
418 iTotalNumOfDocumentsSearched ); |
|
419 } |
|
420 } |
|
421 |
|
422 |
|
423 HBufC8* CCalendarSearcher::LaunchInfoL( const CSearchDocumentId& aDocumentID ) |
|
424 { |
|
425 |
|
426 if((aDocumentID.PluginId() == iPluginId) && |
|
427 (aDocumentID.RepositoryId() == KSearchCClassCalendarUid.iUid)) |
|
428 { |
|
429 HBufC8 * launchInfo = HBufC8::NewL(256); |
|
430 TPtr8 docIdPtr = launchInfo->Des(); |
|
431 docIdPtr.AppendNum(aDocumentID.DocumentId()); |
|
432 return launchInfo; |
|
433 } |
|
434 |
|
435 return NULL; |
|
436 |
|
437 } |
|
438 |
|
439 // ----------------------------------------------------------------------------- |
|
440 // CCalendarSearcher::InitializationL |
|
441 // Initializes Search. Causes Search to start when contact to calendar server finished. |
|
442 // ----------------------------------------------------------------------------- |
|
443 // |
|
444 void CCalendarSearcher::InitializationL() |
|
445 { |
|
446 delete iEntryView; |
|
447 iEntryView = NULL; |
|
448 |
|
449 delete iInstanceView; |
|
450 iInstanceView = NULL; |
|
451 |
|
452 delete iSession; |
|
453 iSession = NULL; |
|
454 |
|
455 iSession = CCalSession::NewL(); |
|
456 |
|
457 TRAPD( error, iSession->OpenL( iSession->DefaultFileNameL() )); |
|
458 if ( error != KErrNone ) |
|
459 { |
|
460 ReportFinishedL( error ); |
|
461 return; |
|
462 } |
|
463 |
|
464 iCalendarState = ECreatingCalendarEntryView; |
|
465 iEntryView = CCalEntryView::NewL( *iSession, *this ); |
|
466 |
|
467 TRAPD( err, StartSearchL() ); |
|
468 if ( err != KErrNone ) |
|
469 { |
|
470 iNeedToCallReportFinishedL = ETrue; |
|
471 } |
|
472 |
|
473 } |
|
474 |
|
475 // ----------------------------------------------------------------------------- |
|
476 // CCalendarSearcher::Completed |
|
477 // Is called when classes related to Calendar connection are finished initializing. |
|
478 // This is called after CCalInstanceView::NewL and CCalEntryView::NewL. |
|
479 // When initialization is complete starts the search automatically. |
|
480 // ----------------------------------------------------------------------------- |
|
481 // |
|
482 void CCalendarSearcher::Completed(TInt aError) |
|
483 { |
|
484 switch ( iCalendarState ) |
|
485 { |
|
486 case ECreatingCalendarEntryView: |
|
487 { |
|
488 // CCalEntryView is constructed -> Active object must complete |
|
489 TRequestStatus* status = &iStatus; |
|
490 User::RequestComplete( status, aError ); |
|
491 break; |
|
492 } |
|
493 |
|
494 case ECreatingCalendarInstanceView: |
|
495 { |
|
496 // CCalInstanceView is constructed -> Active object must complete |
|
497 TRequestStatus* status = &iStatus; |
|
498 User::RequestComplete( status, aError ); |
|
499 break; |
|
500 } |
|
501 |
|
502 default: // If we get here, it's a program error |
|
503 { |
|
504 User::Panic( KCalendarSearchPlugIn, ECalendarSearchPlugWrongState ); |
|
505 } |
|
506 } |
|
507 |
|
508 } |
|
509 |
|
510 // ----------------------------------------------------------------------------- |
|
511 // CCalendarSearcher::ReportFinishedL |
|
512 // Tell observer search finished |
|
513 // ----------------------------------------------------------------------------- |
|
514 // |
|
515 void CCalendarSearcher::ReportFinishedL( TInt aSearchResult, TInt aTotalNumOfItems) |
|
516 { |
|
517 iObserver->SearchCompletedL( aSearchResult, aTotalNumOfItems ); |
|
518 } |
|
519 |
|
520 // ----------------------------------------------------------------------------- |
|
521 // CCalendarSearcher::ConstructL |
|
522 // Performs the second phase construction. |
|
523 // ----------------------------------------------------------------------------- |
|
524 // |
|
525 void CCalendarSearcher::ConstructL( const RArray<TUid>& aContentIdArray, |
|
526 const CSearchCondition& aCondition, |
|
527 MSearchPluginObserver& aObserver ) |
|
528 { |
|
529 iObserver = &aObserver; |
|
530 for( TInt ctr= 0 ; ctr < aContentIdArray.Count() ; ctr++ ) |
|
531 { |
|
532 if( aContentIdArray[ctr] == KSearchCClassCalendarUid ) |
|
533 { |
|
534 iFilter = CalCommon::EIncludeAll; |
|
535 break; |
|
536 } |
|
537 else |
|
538 { |
|
539 if ( aContentIdArray[ctr] == KSearchCFolderAnniversaryUid ) |
|
540 iFilter = iFilter || ( CalCommon::EIncludeAnnivs |
|
541 | CalCommon::EIncludeReminder ); |
|
542 |
|
543 if ( aContentIdArray[ctr] == KSearchCFolderMeetingsUid ) |
|
544 iFilter = iFilter || CalCommon::EIncludeAppts ; |
|
545 |
|
546 if ( aContentIdArray[ctr] == KSearchCFolderMemoUid ) |
|
547 iFilter = iFilter || CalCommon::EIncludeEvents; |
|
548 |
|
549 if ( aContentIdArray[ctr] == KSearchCFolderToDoUid ) |
|
550 iFilter = iFilter || ( CalCommon::EIncludeCompletedTodos |
|
551 | CalCommon::EIncludeIncompletedTodos ); |
|
552 } |
|
553 } |
|
554 |
|
555 SetPriority( EPriorityStandard ); |
|
556 iTextSearcher = CSearchTextSearcher::NewL( *this ); |
|
557 TRAPD(ParameterError, iTextSearcher->SetParametersL( aCondition )); |
|
558 User::LeaveIfError( iFsSession.Connect() ); |
|
559 |
|
560 |
|
561 TFileName resourceFileName; |
|
562 RResourceFile resourceFile; |
|
563 |
|
564 resourceFileName.Copy( TParsePtrC( RProcess().FileName() ).Drive() ); |
|
565 resourceFileName.Append( KDC_RESOURCE_FILES_DIR ); |
|
566 resourceFileName.Append( KAvkonResoureFilePath ); |
|
567 |
|
568 // Get language local file name of resource file. |
|
569 BaflUtils::NearestLanguageFile( iFsSession, resourceFileName ); |
|
570 resourceFile.OpenL(iFsSession, resourceFileName ); |
|
571 resourceFile.ConfirmSignatureL(); |
|
572 |
|
573 |
|
574 iReadDateBuffer = resourceFile.AllocReadL( R_QTN_DATE_SHORT ); |
|
575 iReadTimeBuffer = resourceFile.AllocReadL( R_QTN_TIME_USUAL ); |
|
576 |
|
577 |
|
578 if( ParameterError == KErrNone) |
|
579 { |
|
580 iSetParamsDone = ETrue; |
|
581 } |
|
582 else |
|
583 { |
|
584 iErrorCode = ParameterError; |
|
585 } |
|
586 resourceFile.Close(); |
|
587 |
|
588 } |
|
589 |
|
590 // ----------------------------------------------------------------------------- |
|
591 // CCalendarSearcher::CCalendarSearcher |
|
592 // Performs the first phase of two phase construction. |
|
593 // ----------------------------------------------------------------------------- |
|
594 // |
|
595 CCalendarSearcher::CCalendarSearcher( const TUid& aPluginId ) : |
|
596 CActive( CActive::EPriorityStandard ), iCurrentDocumentSearching( 0 ),iFilter( 0 ), |
|
597 iPluginId( aPluginId ), isFirstKeyWordHit( 0 ), |
|
598 iSetParamsDone( EFalse ), iNeedToCallReportFinishedL( EFalse ),iSearchNotCancelled( EFalse ) |
|
599 { |
|
600 CActiveScheduler::Add( this ); |
|
601 } |
|
602 |
|
603 // ----------------------------------------------------------------------------- |
|
604 // CCalendarSearcher::IsSearching |
|
605 // Does Cleanup for this class. |
|
606 // ----------------------------------------------------------------------------- |
|
607 // |
|
608 void CCalendarSearcher::Cleanup() |
|
609 { |
|
610 |
|
611 switch ( iCalendarState ) |
|
612 { |
|
613 case ECreatingCalendarEntryView: |
|
614 { |
|
615 // CCalEntryView does not have a Cancel function, thus delete is the only option |
|
616 // CCalendarSearcher::Completed will get called with KErrCancel |
|
617 delete iEntryView; |
|
618 iEntryView = NULL; |
|
619 break; |
|
620 } |
|
621 |
|
622 case ECreatingCalendarInstanceView: |
|
623 { |
|
624 // CCalInstanceView does not have a Cancel function, thus delete is the only option |
|
625 // CCalendarSearcher::Completed will get called with KErrCancel |
|
626 delete iInstanceView; |
|
627 iInstanceView = NULL; |
|
628 break; |
|
629 } |
|
630 |
|
631 case ESearching: |
|
632 { |
|
633 // Outstanding request is cancelled and search will not continue. |
|
634 break; |
|
635 } |
|
636 |
|
637 default: // If we get here, it's a program error |
|
638 { |
|
639 User::Panic( KCalendarSearchPlugIn, ECalendarSearchPlugWrongState ); |
|
640 } |
|
641 } |
|
642 |
|
643 //iInstanceArray.ResetAndDestroy(); |
|
644 |
|
645 } |
|
646 |
|
647 // ----------------------------------------------------------------------------- |
|
648 // CCalendarSearcher::DoActualSearchL |
|
649 // Search calendar database |
|
650 // ----------------------------------------------------------------------------- |
|
651 // |
|
652 TBool CCalendarSearcher::DoActualSearchL() |
|
653 { |
|
654 TBool calendarItems( ETrue ); |
|
655 TInt calEntriesInOneGoCounter(0); |
|
656 while ( calendarItems && iSearchNotCancelled && (calEntriesInOneGoCounter < KSearchThisManyCalEntriesInOneGo)) |
|
657 { |
|
658 delete iEntry; |
|
659 iEntry = NULL; |
|
660 iEntry = iEntryView->FetchL( iCalLocalUidArray[0] ); |
|
661 calEntriesInOneGoCounter++; |
|
662 isFirstKeyWordHit = 1; |
|
663 HBufC16* textToBeSearched = NULL; |
|
664 iTextSearcher->Cleanup(); |
|
665 iCurrentDocumentSearching++; |
|
666 TPtrC summaryLine = iEntry->SummaryL(); |
|
667 |
|
668 if( ( iEntry->EntryTypeL() == CCalEntry::EAppt ) || |
|
669 ( iEntry->EntryTypeL() == CCalEntry::EReminder ) ) |
|
670 { |
|
671 TPtrC locationLine = iEntry->LocationL(); |
|
672 TPtrC descriptionLine = iEntry->DescriptionL(); |
|
673 textToBeSearched = HBufC16::NewLC( summaryLine.Length() |
|
674 + descriptionLine.Length() |
|
675 + locationLine.Length() + 2 ); |
|
676 textToBeSearched->Des().Append(summaryLine); |
|
677 textToBeSearched->Des().Append( KEmptySpace ); |
|
678 textToBeSearched->Des().Append(descriptionLine); |
|
679 textToBeSearched->Des().Append( KEmptySpace ); |
|
680 textToBeSearched->Des().Append(locationLine); |
|
681 |
|
682 iTextSearcher->SearchL( *textToBeSearched ); |
|
683 CleanupStack::PopAndDestroy( textToBeSearched ); |
|
684 } |
|
685 else |
|
686 { |
|
687 iTextSearcher->SearchL( summaryLine ); |
|
688 } |
|
689 // Remove the element that was just searched |
|
690 iCalLocalUidArray.Remove ( 0 ); |
|
691 |
|
692 // Check hometime and check if more items need searching |
|
693 //now.HomeTime(); |
|
694 calendarItems = iCalLocalUidArray.Count() > 0; |
|
695 |
|
696 } |
|
697 |
|
698 if( !calendarItems ) |
|
699 { |
|
700 ReportFinishedL( KErrNone, iTotalNumOfDocumentsSearched ); |
|
701 return EFalse; |
|
702 } |
|
703 return ETrue; |
|
704 } |
|
705 |
|
706 TBool CCalendarSearcher::FetchAllCalendarIdsL() |
|
707 { |
|
708 // Minimum time allowed in the API |
|
709 TCalTime minTime; |
|
710 minTime.SetTimeLocalL( TCalTime::MinTime() ); |
|
711 |
|
712 // Check if there are items available for the search |
|
713 TCalTime nextInstanceTime = iInstanceView->NextInstanceL( iFilter, minTime ); |
|
714 if ( nextInstanceTime.TimeUtcL() == Time::NullTTime() ) |
|
715 { |
|
716 ReportFinishedL( KErrNone, iTotalNumOfDocumentsSearched ); |
|
717 return EFalse; // Indicate that no search is needed |
|
718 } |
|
719 |
|
720 // Because the minimum time allowed is used in the query, we get all items available in the db |
|
721 iCalLocalUidArray.Reset(); |
|
722 iCalLocalUidArray.Compress(); |
|
723 iEntryView->GetIdsModifiedSinceDateL( minTime, iCalLocalUidArray ); |
|
724 |
|
725 return ETrue; // Indicated that search must start |
|
726 } |
|
727 |
|
728 // ----------------------------------------------------------------------------- |
|
729 // CCalendarSearcher::RunL |
|
730 // Continue search |
|
731 // ----------------------------------------------------------------------------- |
|
732 // |
|
733 void CCalendarSearcher::RunL() |
|
734 { |
|
735 switch ( iCalendarState ) |
|
736 { |
|
737 case ECreatingCalendarEntryView: |
|
738 { |
|
739 delete iInstanceView; |
|
740 iInstanceView = NULL; |
|
741 // Next create the CCalInstanceView |
|
742 iInstanceView = CCalInstanceView::NewL( *iSession, *this ); |
|
743 iCalendarState = ECreatingCalendarInstanceView; |
|
744 |
|
745 iStatus = KRequestPending; |
|
746 SetActive(); |
|
747 break; |
|
748 } |
|
749 |
|
750 case ECreatingCalendarInstanceView: |
|
751 { |
|
752 // Fetch all calendar UIDs |
|
753 if ( FetchAllCalendarIdsL() ) |
|
754 { |
|
755 // Next we start the actual search |
|
756 iCalendarState = ESearching; |
|
757 TRequestStatus* status = &iStatus; |
|
758 User::RequestComplete( status, KErrNone ); |
|
759 SetActive(); |
|
760 } |
|
761 break; |
|
762 } |
|
763 |
|
764 case ESearching: |
|
765 { |
|
766 if ( DoActualSearchL() ) |
|
767 { |
|
768 // We keep searching until nothing to search anymore |
|
769 iCalendarState = ESearching; |
|
770 |
|
771 TRequestStatus* status = &iStatus; |
|
772 User::RequestComplete( status, KErrNone ); |
|
773 SetActive(); |
|
774 } |
|
775 break; |
|
776 } |
|
777 |
|
778 default: // If we get here, it's a program error |
|
779 { |
|
780 User::Panic( KCalendarSearchPlugIn, ECalendarSearchPlugWrongState ); |
|
781 } |
|
782 } |
|
783 |
|
784 } |
|
785 |
|
786 // ----------------------------------------------------------------------------- |
|
787 // CCalendarSearcher::DoCancel |
|
788 // Implements cancellation of an outstanding request. |
|
789 // This function is called as part of the active object's Cancel(). |
|
790 // ----------------------------------------------------------------------------- |
|
791 // |
|
792 void CCalendarSearcher::DoCancel() |
|
793 { |
|
794 Cleanup(); |
|
795 } |
|
796 |
|
797 // ----------------------------------------------------------------------------- |
|
798 // CCalendarSearcher::RunError |
|
799 // Called by system when RunL leave |
|
800 // ----------------------------------------------------------------------------- |
|
801 // |
|
802 TInt CCalendarSearcher::RunError( TInt aError ) |
|
803 { |
|
804 return aError; |
|
805 } |
|
806 |
|
807 |