diff --git a/mailnews/base/search/public/nsIMsgSearchNotify.idl b/mailnews/base/search/public/nsIMsgSearchNotify.idl index 1c232dda7b8..30f815eef69 100644 --- a/mailnews/base/search/public/nsIMsgSearchNotify.idl +++ b/mailnews/base/search/public/nsIMsgSearchNotify.idl @@ -34,6 +34,8 @@ interface nsIMsgSearchNotify : nsISupports { void onSearchHit(in nsIMsgDBHdr header, in nsIMsgFolder folder); + // notification that a search has finished. + void onSearchDone(in nsresult status); /* * until we can encode searches with a URI, this will be an * out-of-bound way to connect a set of search terms to a datasource diff --git a/mailnews/base/search/src/nsMsgSearchDataSource.cpp b/mailnews/base/search/src/nsMsgSearchDataSource.cpp index 56ac31a8660..41fef5cc1ed 100644 --- a/mailnews/base/search/src/nsMsgSearchDataSource.cpp +++ b/mailnews/base/search/src/nsMsgSearchDataSource.cpp @@ -100,6 +100,13 @@ nsMsgSearchDataSource::OnSearchHit(nsIMsgDBHdr* aMsgHdr, nsIMsgFolder *folder) return NS_OK; } +NS_IMETHODIMP +nsMsgSearchDataSource::OnSearchDone(nsresult status) +{ + return NS_OK; +} + + // for now also acts as a way of resetting the search datasource NS_IMETHODIMP nsMsgSearchDataSource::OnNewSearch() diff --git a/mailnews/base/search/src/nsMsgSearchSession.cpp b/mailnews/base/search/src/nsMsgSearchSession.cpp index d5d0414bba2..76f76013402 100644 --- a/mailnews/base/search/src/nsMsgSearchSession.cpp +++ b/mailnews/base/search/src/nsMsgSearchSession.cpp @@ -326,7 +326,19 @@ NS_IMETHODIMP nsMsgSearchSession::Search(nsIMsgWindow *aWindow) /* void InterruptSearch (); */ NS_IMETHODIMP nsMsgSearchSession::InterruptSearch() { - return NS_OK; + if (m_window) + { + m_idxRunningScope = m_scopeList.Count(); // this'll make us not run another url + m_window->StopUrls(); + } + if (m_backgroundTimer) + { + m_backgroundTimer->Cancel(); + NotifyListenersDone(NS_OK); // ### is there a cancelled status? + + m_backgroundTimer = nsnull; + } + return NS_OK; } NS_IMETHODIMP nsMsgSearchSession::PauseSearch() @@ -408,6 +420,8 @@ NS_IMETHODIMP nsMsgSearchSession::OnStopRunningUrl(nsIURI *url, nsresult aExitCo m_idxRunningScope++; if (m_idxRunningScope < m_scopeList.Count()) GetNextUrl(); + else + NotifyListenersDone(aExitCode); return NS_OK; } @@ -436,6 +450,9 @@ nsresult nsMsgSearchSession::Initialize() if (m_scopeList.Count() == 0) return NS_MSG_ERROR_INVALID_SEARCH_SCOPE; + m_urlQueue.Clear(); // clear out old urls, if any. + m_idxRunningScope = 0; + // If this term list (loosely specified here by the first term) should be // scheduled in parallel, build up a list of scopes to do the round-robin scheduling scopeTerm = m_scopeList.ElementAt(0); @@ -534,6 +551,7 @@ nsresult nsMsgSearchSession::AddUrl(const char *url) { aTimer->Cancel(); searchSession->m_backgroundTimer = nsnull; + searchSession->NotifyListenersDone(NS_OK); } } @@ -586,6 +604,25 @@ NS_IMETHODIMP nsMsgSearchSession::AddSearchHit(nsIMsgDBHdr *header, nsIMsgFolder return NS_OK; } +nsresult nsMsgSearchSession::NotifyListenersDone(nsresult status) +{ + if (m_listenerList) + { + PRUint32 count; + m_listenerList->Count(&count); + for (PRUint32 i = 0; i < count; i++) + { + nsCOMPtr pListener; + m_listenerList->QueryElementAt(i, NS_GET_IID(nsIMsgSearchNotify), + (void **)getter_AddRefs(pListener)); + if (pListener) + pListener->OnSearchDone(status); + + } + } + return NS_OK; +} + NS_IMETHODIMP nsMsgSearchSession::AddResultElement (nsMsgResultElement *element) { diff --git a/mailnews/base/search/src/nsMsgSearchSession.h b/mailnews/base/search/src/nsMsgSearchSession.h index bac76249b70..0a33e7cafc0 100644 --- a/mailnews/base/search/src/nsMsgSearchSession.h +++ b/mailnews/base/search/src/nsMsgSearchSession.h @@ -58,6 +58,7 @@ protected: nsresult AddUrl(const char *url); nsresult SearchWOUrls (); nsresult GetNextUrl(); + nsresult NotifyListenersDone(nsresult status); nsMsgSearchScopeTermArray m_scopeList; nsCOMPtr m_termList; @@ -69,6 +70,7 @@ protected: void DestroyScopeList (); void DestroyResultList (); + static void TimerCallback(nsITimer *aTimer, void *aClosure); // support for searching multiple scopes in serial nsresult TimeSliceSerial (PRBool *aDone);