ipsservices/ipssosplugin/src/ipsplgsearchop.cpp
changeset 74 6c59112cfd31
parent 23 2dc6caa42ec3
equal deleted inserted replaced
69:4e54af54a4a1 74:6c59112cfd31
     1 /*
     1 /*
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    99     {
    99     {
   100     FUNC_LOG;
   100     FUNC_LOG;
   101     iState = EStarted;
   101     iState = EStarted;
   102 
   102 
   103     iSearcher = CIpsPlgTextSearcher::NewL( *this );
   103     iSearcher = CIpsPlgTextSearcher::NewL( *this );
   104     iSearcher->SetParametersL( 
   104     iSearcher->SetParametersL(
   105         iObserver.SearchStringsL(), 
   105         iObserver.SearchStringsL(),
   106         EIpsPlgCriteriaOperationOR,
   106         EIpsPlgCriteriaOperationOR,
   107         EFalse,
   107         EFalse,
   108         KIpsPlgSnippetLen );
   108         KIpsPlgSnippetLen );
   109 
   109 
   110     ActivateAndComplete();
   110     ActivateAndComplete();
   111     }
   111     }
   112 
   112 
   113 // ======== MEMBER FUNCTIONS ======== 
   113 // ======== MEMBER FUNCTIONS ========
   114 
   114 
   115 // ---------------------------------------------------------------------------
   115 // ---------------------------------------------------------------------------
   116 // From class CIpsPlgBaseOperation.
   116 // From class CIpsPlgBaseOperation.
   117 // CIpsPlgSearchOp::DoCancel()
   117 // CIpsPlgSearchOp::DoCancel()
   118 // ---------------------------------------------------------------------------
   118 // ---------------------------------------------------------------------------
   138             {
   138             {
   139             // Collect all message id's in the mailbox and sort them.
   139             // Collect all message id's in the mailbox and sort them.
   140             iObserver.CollectMessagesL();
   140             iObserver.CollectMessagesL();
   141             iObserver.Sort();
   141             iObserver.Sort();
   142             iState = ERunning;
   142             iState = ERunning;
   143             iRequiredPriority = EPriorityStandard; // priority changes may be decreased
   143             iRequiredPriority = EPriorityIdle; // priority changes may be decreased
   144             ActivateAndComplete();
   144             ActivateAndComplete();
   145             break;
   145             break;
   146             }
   146             }
   147         case ERunning:
   147         case ERunning:
   148             {
   148             {
   159                     {
   159                     {
   160                     FinalizeL();
   160                     FinalizeL();
   161                     return;
   161                     return;
   162                     }
   162                     }
   163             iState = ERunning;
   163             iState = ERunning;
   164 // When client wants call to contact the priority must be decreased 
   164 // When client wants call to contact the priority must be decreased
   165 // to enable search for contact which uses idle priority
   165 // to enable search for contact which uses idle priority
   166             TInt clientRequiredPriority(iRequiredPriority);
   166             TInt clientRequiredPriority(iRequiredPriority);
   167             iObserver.ClientRequiredSearchPriority( &clientRequiredPriority );
   167             iObserver.ClientRequiredSearchPriority( &clientRequiredPriority );
   168             iRequiredPriority = ((clientRequiredPriority > EPriorityIdle) ? EPriorityStandard : EPriorityIdle-1);
   168 
       
   169             if (clientRequiredPriority>EPriorityStandard) {
       
   170 			    clientRequiredPriority = EPriorityStandard;
       
   171 			}
       
   172             else if(clientRequiredPriority<EPriorityIdle-1) {
       
   173 			    clientRequiredPriority = EPriorityIdle-1;
       
   174 			}
       
   175             iRequiredPriority = clientRequiredPriority;
   169 
   176 
   170             ActivateAndComplete();
   177             ActivateAndComplete();
   171             break;
   178             break;
   172             }
   179             }
   173         default:
   180         default:
   199     // In case the operation is cancelled, do not try to any extra steps.
   206     // In case the operation is cancelled, do not try to any extra steps.
   200     if ( iState == ERunning )
   207     if ( iState == ERunning )
   201         {
   208         {
   202         // Delete object before creating new. Previous object is not needed.
   209         // Delete object before creating new. Previous object is not needed.
   203         delete iMessage;
   210         delete iMessage;
   204         iMessage = NULL;        
   211         iMessage = NULL;
   205         delete iHeader;
   212         delete iHeader;
   206         iHeader = NULL;
   213         iHeader = NULL;
   207         iMessage = iObserver.NextMessageL();        
   214         iMessage = iObserver.NextMessageL();
   208         
   215 
   209         // If message is not set, the search is finished. 
   216         // If message is not set, the search is finished.
   210         // Run down the operation.
   217         // Run down the operation.
   211         if ( !iMessage )
   218         if ( !iMessage )
   212             {
   219             {
   213             iState = EFinished;
   220             iState = EFinished;
   214             return EFalse;
   221             return EFalse;
   215             }        
   222             }
   216         
   223 
   217         // Retrieve the message header also.
   224         // Retrieve the message header also.
   218         iHeader = iObserver.MessageHeaderL();        
   225         iHeader = iObserver.MessageHeaderL();
   219         }
   226         }
   220     else
   227     else
   221         {
   228         {
   222         // Stop the loop, cancel should not continue.
   229         // Stop the loop, cancel should not continue.
   223         return EFalse;
   230         return EFalse;
   224         }
   231         }
   225     return ETrue;        
   232     return ETrue;
   226     }
   233     }
   227 
   234 
   228 // ---------------------------------------------------------------------------
   235 // ---------------------------------------------------------------------------
   229 // CIpsPlgSearchOp::HandleHtmlL()
   236 // CIpsPlgSearchOp::HandleHtmlL()
   230 // ---------------------------------------------------------------------------
   237 // ---------------------------------------------------------------------------
   252         CCharFormatLayer* chars = CCharFormatLayer::NewL();
   259         CCharFormatLayer* chars = CCharFormatLayer::NewL();
   253         CleanupStack::PushL( chars );
   260         CleanupStack::PushL( chars );
   254         CRichText* txt = CRichText::NewL( para, chars );
   261         CRichText* txt = CRichText::NewL( para, chars );
   255         CleanupStack::PushL( txt );
   262         CleanupStack::PushL( txt );
   256 
   263 
   257         iMessage->GetBodyTextL( 
   264         iMessage->GetBodyTextL(
   258             iObserver.CurrentMessage().Id(),
   265             iObserver.CurrentMessage().Id(),
   259             CImEmailMessage::EThisMessageOnly, 
   266             CImEmailMessage::EThisMessageOnly,
   260             *txt, 
   267             *txt,
   261             *para, 
   268             *para,
   262             *chars );    
   269             *chars );
   263 
   270 
   264         RBuf temp;
   271         RBuf temp;
   265         temp.CreateL( txt->DocumentLength() ); 
   272         temp.CreateL( txt->DocumentLength() );
   266         CleanupClosePushL( temp );
   273         CleanupClosePushL( temp );
   267         
   274 
   268         txt->Extract( temp );
   275         txt->Extract( temp );
   269         SearchFromStringL( temp );
   276         SearchFromStringL( temp );
   270         
   277 
   271         CleanupStack::PopAndDestroy( &temp );
   278         CleanupStack::PopAndDestroy( &temp );
   272         CleanupStack::PopAndDestroy( txt );    
   279         CleanupStack::PopAndDestroy( txt );
   273         CleanupStack::PopAndDestroy( chars );
   280         CleanupStack::PopAndDestroy( chars );
   274         CleanupStack::PopAndDestroy( para );
   281         CleanupStack::PopAndDestroy( para );
   275         }    
   282         }
   276     }
   283     }
   277 
   284 
   278 // ---------------------------------------------------------------------------
   285 // ---------------------------------------------------------------------------
   279 // CIpsPlgSearchOp::SearchFromArrayL()
   286 // CIpsPlgSearchOp::SearchFromArrayL()
   280 // ---------------------------------------------------------------------------
   287 // ---------------------------------------------------------------------------
   313 void CIpsPlgSearchOp::SearchL()
   320 void CIpsPlgSearchOp::SearchL()
   314     {
   321     {
   315     FUNC_LOG;
   322     FUNC_LOG;
   316     if ( iState == ERunning )
   323     if ( iState == ERunning )
   317         {
   324         {
   318         iSearcher->Cleanup();                       
   325         iSearcher->Cleanup();
   319         
   326 
   320         // Mail is fetched, search from entire mail.
   327         // Mail is fetched, search from entire mail.
   321         if ( iHeader )
   328         if ( iHeader )
   322             {                           
   329             {
   323             SearchFromEntireMailL(); 
   330             SearchFromEntireMailL();
   324             }
   331             }
   325         // Mail not fetched, search only from subject.            
   332         // Mail not fetched, search only from subject.
   326         else
   333         else
   327             {                                        
   334             {
   328             SearchFromSubjectL();                                             
   335             SearchFromSubjectL();
   329             }                       
   336             }
   330         iState = ( iState == EHit ) ? ERunning : iState;
   337         iState = ( iState == EHit ) ? ERunning : iState;
   331         }
   338         }
   332     }
   339     }
   333 
   340 
   334 // ---------------------------------------------------------------------------
   341 // ---------------------------------------------------------------------------
   335 // CIpsPlgSearchOp::HitL()
   342 // CIpsPlgSearchOp::HitL()
   336 // ---------------------------------------------------------------------------
   343 // ---------------------------------------------------------------------------
   337 //
   344 //
   338 void CIpsPlgSearchOp::HitL( 
   345 void CIpsPlgSearchOp::HitL(
   339     const TDesC& /* aSnippet */, 
   346     const TDesC& /* aSnippet */,
   340     TInt /* aSnippetCharPos */, 
   347     TInt /* aSnippetCharPos */,
   341     TBool /* aStartIncomplete */, 
   348     TBool /* aStartIncomplete */,
   342     TBool /* aEndIncomplete */ )
   349     TBool /* aEndIncomplete */ )
   343     {
   350     {
   344     FUNC_LOG;
   351     FUNC_LOG;
   345     iObserver.MatchFoundL();
   352     iObserver.MatchFoundL();
   346     iState = EHit;
   353     iState = EHit;
   353 void CIpsPlgSearchOp::FinalizeL()
   360 void CIpsPlgSearchOp::FinalizeL()
   354     {
   361     {
   355     FUNC_LOG;
   362     FUNC_LOG;
   356     // In case of cancel, the stop should not be indicated.
   363     // In case of cancel, the stop should not be indicated.
   357     if ( iState == EFinished )
   364     if ( iState == EFinished )
   358         {        
   365         {
   359         iObserver.SearchFinishedL();
   366         iObserver.SearchFinishedL();
   360         iState = EStopped;
   367         iState = EStopped;
   361         }
   368         }
   362     }
   369     }
   363 
   370 
   366 // ---------------------------------------------------------------------------
   373 // ---------------------------------------------------------------------------
   367 //
   374 //
   368 void CIpsPlgSearchOp::ActivateAndComplete( )
   375 void CIpsPlgSearchOp::ActivateAndComplete( )
   369     {
   376     {
   370     FUNC_LOG;
   377     FUNC_LOG;
   371     iStatus = KRequestPending; 
   378     iStatus = KRequestPending;
   372 // When client wants call to contact the priority must be decreased 
   379 // When client wants call to contact the priority must be decreased
   373 // to enable search for contact made with idle priority
   380 // to enable search for contact made with idle priority
   374     if ( Priority() != iRequiredPriority ) // <cmail>
   381     if ( Priority() != iRequiredPriority ) // <cmail>
   375     	SetPriority(iRequiredPriority);
   382     	SetPriority(iRequiredPriority);
   376 
   383 
   377     SetActive();    
   384     SetActive();
   378     TRequestStatus* status = &iStatus;
   385     TRequestStatus* status = &iStatus;
   379     User::RequestComplete( status, KErrNone );    
   386     User::RequestComplete( status, KErrNone );
   380     }
   387     }
   381     
   388 
   382 // ---------------------------------------------------------------------------
   389 // ---------------------------------------------------------------------------
   383 // CIpsPlgSearchOp::SearchFromEntireMailL( )
   390 // CIpsPlgSearchOp::SearchFromEntireMailL( )
   384 // ---------------------------------------------------------------------------
   391 // ---------------------------------------------------------------------------
   385 //
   392 //
   386 void CIpsPlgSearchOp::SearchFromEntireMailL( )
   393 void CIpsPlgSearchOp::SearchFromEntireMailL( )
   387     {
   394     {
   388     FUNC_LOG;
   395     FUNC_LOG;
   389     if ( SearchFromStringL( iHeader->Subject() ) ) 
   396     if ( SearchFromStringL( iHeader->Subject() ) )
   390         {
   397         {
   391         return;
   398         return;
   392         }
   399         }
   393     if ( SearchFromStringL( iHeader->From() ) )
   400     if ( SearchFromStringL( iHeader->From() ) )
   394         {
   401         {
   415     RBuf subject;
   422     RBuf subject;
   416     CleanupClosePushL( subject );
   423     CleanupClosePushL( subject );
   417     iObserver.GetSubjectL( subject );
   424     iObserver.GetSubjectL( subject );
   418     TBool found = SearchFromStringL( subject );
   425     TBool found = SearchFromStringL( subject );
   419     CleanupStack::PopAndDestroy( &subject );
   426     CleanupStack::PopAndDestroy( &subject );
   420     
   427 
   421     if ( !found )
   428     if ( !found )
   422         {
   429         {
   423         RBuf sender;
   430         RBuf sender;
   424         CleanupClosePushL( sender );
   431         CleanupClosePushL( sender );
   425         iObserver.GetSenderL( sender );
   432         iObserver.GetSenderL( sender );
   426         found = SearchFromStringL( sender );
   433         found = SearchFromStringL( sender );
   427         CleanupStack::PopAndDestroy( &sender );  
   434         CleanupStack::PopAndDestroy( &sender );
   428         }
   435         }
   429     }
   436     }
   430     
   437 
   431 // End of File
   438 // End of File
   432 
   439