diff -r d189ee25cf9d -r 3533d4323edc emailservices/emailclientapi/src/emailmessagesearch.cpp --- a/emailservices/emailclientapi/src/emailmessagesearch.cpp Tue Aug 31 15:04:17 2010 +0300 +++ b/emailservices/emailclientapi/src/emailmessagesearch.cpp Wed Sep 01 12:28:57 2010 +0100 @@ -1,5 +1,5 @@ /* -* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" @@ -29,32 +29,34 @@ // --------------------------------------------------------------------------- // CEmailMessageSearchAsync::NewL // --------------------------------------------------------------------------- +// CEmailMessageSearchAsync* CEmailMessageSearchAsync::NewL( CPluginData& aPluginData, const TMailboxId& aMailboxId ) { - CEmailMessageSearchAsync* self = - new ( ELeave ) CEmailMessageSearchAsync( aPluginData, aMailboxId ); + CEmailMessageSearchAsync* self = new (ELeave) CEmailMessageSearchAsync(aPluginData, aMailboxId); CleanupStack::PushL( self ); self->ConstructL(); - CleanupStack::Pop( self ); + CleanupStack::Pop(); return self; } + // --------------------------------------------------------------------------- // // --------------------------------------------------------------------------- +// void CEmailMessageSearchAsync::ConstructL() { iPlugin = iPluginData.ClaimInstanceL(); // Open existing semaphore, or create a new one - if ( KErrNone != iGate.OpenGlobal( KGlobalSemaphoreToPreventParallelCall, EOwnerProcess ) ) + if (KErrNone != iGate.OpenGlobal(KGlobalSemaphoreToPreventParallelCall, EOwnerProcess)) { - User::LeaveIfError( - iGate.CreateGlobal( KGlobalSemaphoreToPreventParallelCall, 1, EOwnerProcess ) ); + User::LeaveIfError(iGate.CreateGlobal(KGlobalSemaphoreToPreventParallelCall, 1, EOwnerProcess)); } } + // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -62,10 +64,11 @@ CPluginData& aPluginData, const TMailboxId& aMailboxId ) : iPluginData( aPluginData ), iMailboxId( aMailboxId.iId ), - iCriteria(), iObserver( NULL ), iRemote( EFalse ) - { + iCriteria(), iObserver(NULL), iRemote(EFalse) + { } + // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -83,7 +86,7 @@ { return KEmailIFUidSearch; } - + // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -96,60 +99,63 @@ delete this; } -// ----------------------------------------------------------------------------- -// Sets sort order for search results. -// Leaves KErrNotReady if search is ongoing. -// ----------------------------------------------------------------------------- -void CEmailMessageSearchAsync::SetSortCriteriaL( const TEmailSortCriteria& aCriteria ) - { - IsSearchGoingOnL(); - +/** +* Sets sort order for search results. +* Leaves KErrNotReady if search is ongoing. +*/ +void CEmailMessageSearchAsync::SetSortCriteriaL( const TEmailSortCriteria& aCriteria ) + { + if (KErrNone != iGate.Wait(1)) + { + // Leave now, search is going on + User::Leave( KErrNotReady ); + } switch (aCriteria.iField) { case TEmailSortCriteria::EDontCare: iCriteria.iField = EFSMailDontCare; break; - + case TEmailSortCriteria::EByDate: iCriteria.iField = EFSMailSortByDate; break; - + case TEmailSortCriteria::EBySender: iCriteria.iField = EFSMailSortBySender; break; - + case TEmailSortCriteria::EByRecipient: iCriteria.iField = EFSMailSortByRecipient; break; - + case TEmailSortCriteria::EBySubject: iCriteria.iField = EFSMailSortBySubject; break; - + case TEmailSortCriteria::EByPriority: iCriteria.iField = EFSMailSortByPriority; break; - + case TEmailSortCriteria::EByFlagStatus: iCriteria.iField = EFSMailSortByFlagStatus; break; - + case TEmailSortCriteria::EByUnread: iCriteria.iField = EFSMailSortByUnread; break; - + case TEmailSortCriteria::EBySize: iCriteria.iField = EFSMailSortBySize; break; - + case TEmailSortCriteria::EByAttachment: iCriteria.iField = EFSMailSortByAttachment; break; - + default: User::Leave( KErrNotSupported ); break; - + } if (aCriteria.iAscending) { @@ -157,63 +163,73 @@ } else { - iCriteria.iOrder = EFSMailDescending; + iCriteria.iOrder = EFSMailDescending; } // Release gate - iGate.Signal(); + iGate.Signal(); } -// ----------------------------------------------------------------------------- -// Adds a search key. Leaves KErrNotReady if search is ongoing. -// ----------------------------------------------------------------------------- +/** +* Adds a search key. Leaves KErrNotReady if search is ongoing. +*/ void CEmailMessageSearchAsync::AddSearchKeyL( const TDesC& aSearchKey ) { - IsSearchGoingOnL(); - + if (KErrNone != iGate.Wait(1)) + { + // Leave now, search is going on + User::Leave( KErrNotReady ); + } iSearchStrings.AppendL(&aSearchKey); // Release gate iGate.Signal(); } - -/// ----------------------------------------------------------------------------- -// Enables/disables search from remote email server. -// Leaves KErrNotReady if search is ongoing. -// ----------------------------------------------------------------------------- + +/** +* Enables/disables search from remote email server. +* Leaves KErrNotReady if search is ongoing. +*/ void CEmailMessageSearchAsync::SetRemoteSearchL( TBool aRemote ) { - IsSearchGoingOnL(); - + if (KErrNone != iGate.Wait(1)) + { + // Leave now, search is going on + User::Leave( KErrNotReady ); + } iRemote = aRemote; // Release gate iGate.Signal(); // Currently plugins do not support this function User::Leave( KErrNotSupported ); - } + } -// ----------------------------------------------------------------------------- -// Indicates whether remote search is enabled. -// ----------------------------------------------------------------------------- -TBool CEmailMessageSearchAsync::IsRemoteSearch() const +/** +* Indicates whether remote search is enabled. +*/ +TBool CEmailMessageSearchAsync::IsRemoteSearch() const { // Currently plugins do not support this function return EFalse; } -// ----------------------------------------------------------------------------- -// Starts search, all methods affecting search attribures leave -// KErrNotReady while search is ongoing. -// @param aObserver called when results are available. -// -void CEmailMessageSearchAsync::StartSearchL( MEmailSearchObserver& aObserver ) +/** + * Starts search, all methods affecting search attribures leave + * KErrNotReady while search is ongoing. + * @param aObserver called when results are available. + */ +void CEmailMessageSearchAsync::StartSearchL( MEmailSearchObserver& aObserver ) { - IsSearchGoingOnL(); - + if (KErrNone != iGate.Wait(1)) + { + // Leave now, search is going on + User::Leave( KErrNotReady ); + } iObserver = &aObserver; const TFSMailMsgId fsMailboxId( iPluginData.Uid(), iMailboxId.iId ); RArray folderIds; - + CleanupClosePushL( folderIds ); + /** Search API */ - + /** * Asyncronous call for starting search for given string. Only one search can be * performed at a time. @@ -240,20 +256,21 @@ * @param aSortCriteria sort criteria for the results * @param aSearchObserver client observer that will be notified about search status. * - */ + */ iPlugin->SearchL( fsMailboxId, folderIds, iSearchStrings, iCriteria, *this ); - // Gate is kept closed as search is asynchronous. Gate will be reopen after search is completed, i.e. + // Gate is kept closed as search is asynchronous. Gate will be reopen after search is completed, i.e. // CEmailMessageSearchAsync::SearchCompleted. + CleanupStack::PopAndDestroy( &folderIds ); } -// ----------------------------------------------------------------------------- -// Cancels search. -// ----------------------------------------------------------------------------- -void CEmailMessageSearchAsync::Cancel() +/** + * Cancels search. + */ +void CEmailMessageSearchAsync::Cancel() { if (KErrNone != iGate.Wait(1)) { @@ -272,18 +289,18 @@ iGate.Signal(); } } - -// ----------------------------------------------------------------------------- -// * @return search status: -// * < 0 : Search has failed -// * KRequestPending : search is ongoing. note that status may be -// * KRequestPending after HandleResultL callback because results -// * may be given in chunks of results. Size of chunk depends on -// * implementation and may vary. -// * KErrNone : initial state, or search has finished -// ----------------------------------------------------------------------------- -TInt CEmailMessageSearchAsync::Status() const - { + +/** returns search status + * @return search status: + * < 0 : Search has failed + * KRequestPending : search is ongoing. note that status may be + * KRequestPending after HandleResultL callback because results + * may be given in chunks of results. Size of chunk depends on + * implementation and may vary. + * KErrNone : initial state, or search has finished + */ +TInt CEmailMessageSearchAsync::Status() const + { if (KErrNone != iGate.Wait(1)) { // Search is going on @@ -294,16 +311,16 @@ // Release gate iGate.Signal(); } - + return KErrNone; } -// ----------------------------------------------------------------------------- -// Resets all search attribures. Cancels search if ongoing. -// ----------------------------------------------------------------------------- -void CEmailMessageSearchAsync::Reset() - { - if ( KErrNone != iGate.Wait( 1 ) ) +/** + * Resets all search attribures. Cancels search if ongoing. + */ +void CEmailMessageSearchAsync::Reset() + { + if (KErrNone != iGate.Wait(1)) { this->Cancel(); } @@ -316,47 +333,36 @@ }; -// ----------------------------------------------------------------------------- -// Notifies the email search API client that a match has been found -// -// @param aMatchMessage contains a pointer to the matched message. -// Ownership is transfered to the observer. -// ----------------------------------------------------------------------------- +/** + * Notifies the email search API client that a match has been found + * + * @param aMatchMessage contains a pointer to the matched message. + * Ownership is transfered to the observer. + * + */ void CEmailMessageSearchAsync::MatchFoundL( CFSMailMessage* aMatchMessage ) { - User::LeaveIfNull( iObserver ); CEmailMessage *result = CEmailMessage::NewL(iPluginData, aMatchMessage, EClientOwns ); - iObserver->HandleResultL( result ); + iObserver->HandleResultL(result); } -// ----------------------------------------------------------------------------- -// Notifies the email search API client that the search has completed -// ----------------------------------------------------------------------------- +/** + * Notifies the email search API client that the search has completed + * + */ void CEmailMessageSearchAsync::SearchCompletedL() { - User::LeaveIfNull( iObserver ); - iObserver->SearchCompletedL(); + iObserver->SearchCompletedL(); // Search is now complete, release gate. iGate.Signal(); } -// ----------------------------------------------------------------------------- -// Asks client if search engine should change search priority -// ----------------------------------------------------------------------------- -void CEmailMessageSearchAsync::ClientRequiredSearchPriority(TInt* /*apRequiredSearchPriority*/) +// + /** + * Asks client if search engine should change search priority + */ +void CEmailMessageSearchAsync::ClientRequiredSearchPriority(TInt * /* apRequiredSearchPriority */ ) { - } - -// ----------------------------------------------------------------------------- -// Function leaves if search is going on. Otherwise it doesn't do anything. -// ----------------------------------------------------------------------------- -void CEmailMessageSearchAsync::IsSearchGoingOnL() const - { - if ( KErrNone != iGate.Wait( 1 ) ) - { - // Leave now, search is going on - User::Leave( KErrNotReady ); - } - } - -// End of file + return; + } +//