diff -r dcf0eedfc1a3 -r d189ee25cf9d emailservices/emailclientapi/src/emailmessagesearch.cpp --- a/emailservices/emailclientapi/src/emailmessagesearch.cpp Thu Aug 19 09:38:05 2010 +0300 +++ b/emailservices/emailclientapi/src/emailmessagesearch.cpp Tue Aug 31 15:04:17 2010 +0300 @@ -1,5 +1,5 @@ /* -* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* Copyright (c) 2010 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,34 +29,32 @@ // --------------------------------------------------------------------------- // 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(); + CleanupStack::Pop( self ); 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 ) ); } } - // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -64,11 +62,10 @@ CPluginData& aPluginData, const TMailboxId& aMailboxId ) : iPluginData( aPluginData ), iMailboxId( aMailboxId.iId ), - iCriteria(), iObserver(NULL), iRemote(EFalse) - { + iCriteria(), iObserver( NULL ), iRemote( EFalse ) + { } - // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -86,7 +83,7 @@ { return KEmailIFUidSearch; } - + // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- @@ -99,63 +96,60 @@ delete this; } -/** -* 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 ); - } +// ----------------------------------------------------------------------------- +// Sets sort order for search results. +// Leaves KErrNotReady if search is ongoing. +// ----------------------------------------------------------------------------- +void CEmailMessageSearchAsync::SetSortCriteriaL( const TEmailSortCriteria& aCriteria ) + { + IsSearchGoingOnL(); + 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) { @@ -163,73 +157,63 @@ } 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 ) { - if (KErrNone != iGate.Wait(1)) - { - // Leave now, search is going on - User::Leave( KErrNotReady ); - } + IsSearchGoingOnL(); + 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 ) { - if (KErrNone != iGate.Wait(1)) - { - // Leave now, search is going on - User::Leave( KErrNotReady ); - } + IsSearchGoingOnL(); + 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 ) { - if (KErrNone != iGate.Wait(1)) - { - // Leave now, search is going on - User::Leave( KErrNotReady ); - } + IsSearchGoingOnL(); + 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. @@ -256,21 +240,20 @@ * @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)) { @@ -289,18 +272,18 @@ iGate.Signal(); } } - -/** 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 - { + +// ----------------------------------------------------------------------------- +// * @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 @@ -311,16 +294,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(); } @@ -333,36 +316,47 @@ }; -/** - * 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() { - iObserver->SearchCompletedL(); + User::LeaveIfNull( iObserver ); + 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*/) { - return; - } -// + } + +// ----------------------------------------------------------------------------- +// 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