nsresult nsMsgSearchSession::GetNextUrl()
{
    nsCString nextUrl;
    nsCOMPtr <nsIMsgMessageService> msgService;

    PRBool stopped = PR_FALSE;
    nsCOMPtr<nsIMsgWindow> msgWindow(do_QueryReferent(m_msgWindowWeak));
    if (msgWindow)
        msgWindow->GetStopped(&stopped);
    if (stopped)
        return NS_OK;

    m_urlQueue.CStringAt(m_urlQueueIndex, nextUrl);
    nsMsgSearchScopeTerm *currentTerm = GetRunningScope();
    EnableFolderNotifications(PR_FALSE);
    nsCOMPtr <nsIMsgFolder> folder = currentTerm->m_folder;
    if (folder)
    {
        nsCString folderUri;
        folder->GetURI(folderUri);
        nsresult rv = GetMessageServiceFromURI(folderUri, getter_AddRefs(msgService));

        if (NS_SUCCEEDED(rv) && msgService && currentTerm)
            msgService->Search(this, msgWindow, currentTerm->m_folder, nextUrl.get());

        return rv;
    }
    return NS_OK;
}
/* void InterruptSearch (); */
NS_IMETHODIMP nsMsgSearchSession::InterruptSearch()
{
    nsCOMPtr<nsIMsgWindow> msgWindow(do_QueryReferent(m_msgWindowWeak));
    if (msgWindow)
    {
        EnableFolderNotifications(PR_TRUE);
        if (m_idxRunningScope < m_scopeList.Count())
            msgWindow->StopUrls();

        while (m_idxRunningScope < m_scopeList.Count())
        {
            ReleaseFolderDBRef();
            m_idxRunningScope++;
        }
        //m_idxRunningScope = m_scopeList.Count() so it will make us not run another url
    }
    if (m_backgroundTimer)
    {
        m_backgroundTimer->Cancel();
        NotifyListenersDone(NS_OK); // ### is there a cancelled status?

        m_backgroundTimer = nsnull;
    }
    return NS_OK;
}
Beispiel #3
0
nsresult nsMsgSearchSession::GetNextUrl()
{
  nsCString nextUrl;
  nsCOMPtr<nsIMsgMessageService> msgService;

  bool stopped = false;
  nsCOMPtr<nsIMsgWindow> msgWindow(do_QueryReferent(m_msgWindowWeak));
  if (msgWindow)
    msgWindow->GetStopped(&stopped);
  if (stopped)
    return NS_OK;

  nextUrl = m_urlQueue[m_urlQueueIndex];
  nsMsgSearchScopeTerm *currentTerm = GetRunningScope();
  NS_ENSURE_TRUE(currentTerm, NS_ERROR_NULL_POINTER);
  EnableFolderNotifications(false);
  nsCOMPtr<nsIMsgFolder> folder = currentTerm->m_folder;
  if (folder)
  {
    nsCString folderUri;
    folder->GetURI(folderUri);
    nsresult rv = GetMessageServiceFromURI(folderUri, getter_AddRefs(msgService));

    if (NS_SUCCEEDED(rv) && msgService && currentTerm)
      msgService->Search(this, msgWindow, currentTerm->m_folder, nextUrl.get());

    return rv;
  }
  return NS_OK;
}
nsresult nsMsgSearchSession::TimeSliceSerial (PRBool *aDone)
{
    // This version of TimeSlice runs each scope term one at a time, and waits until one
    // scope term is finished before starting another one. When we're searching the local
    // disk, this is the fastest way to do it.

    NS_ENSURE_ARG(aDone);
    nsresult rv = NS_OK;
    nsMsgSearchScopeTerm *scope = GetRunningScope();
    if (scope)
    {
        rv = scope->TimeSlice (aDone);
        if (NS_FAILED(rv))
            *aDone = PR_TRUE;
        if (*aDone || NS_FAILED(rv))
        {
            EnableFolderNotifications(PR_TRUE);
            ReleaseFolderDBRef();
            m_idxRunningScope++;
            EnableFolderNotifications(PR_FALSE);
            // check if the next scope is an online search; if so,
            // set *aDone to true so that we'll try to run the next
            // search in TimerCallback.
            scope = GetRunningScope();
            if (scope && (scope->m_attribute == nsMsgSearchScope::onlineMail ||
                          (scope->m_attribute == nsMsgSearchScope::news && scope->m_searchServer)))
            {
                *aDone = PR_TRUE;
                return rv;
            }

        }
        *aDone = PR_FALSE;
        return rv;
    }
    else
    {
        *aDone = PR_TRUE;
        return NS_OK;
    }
}
/* void OnStopRunningUrl (in nsIURI url, in nsresult aExitCode); */
NS_IMETHODIMP nsMsgSearchSession::OnStopRunningUrl(nsIURI *url, nsresult aExitCode)
{
    nsCOMPtr <nsIMsgSearchAdapter> runningAdapter;

    nsresult rv = GetRunningAdapter (getter_AddRefs(runningAdapter));
    // tell the current adapter that the current url has run.
    if (NS_SUCCEEDED(rv) && runningAdapter)
    {
        runningAdapter->CurrentUrlDone(aExitCode);
        EnableFolderNotifications(PR_TRUE);
        ReleaseFolderDBRef();
    }
    m_idxRunningScope++;
    if (++m_urlQueueIndex < m_urlQueue.Count())
        GetNextUrl();
    else if (m_idxRunningScope < m_scopeList.Count())
        DoNextSearch();
    else
        NotifyListenersDone(aExitCode);
    return NS_OK;
}
nsresult nsMsgSearchSession::SearchWOUrls ()
{
    EnableFolderNotifications(PR_FALSE);
    return StartTimer();
}