зеркало из https://github.com/mozilla/pjs.git
107033 r=bienvenu sr=mscott a=asa Made the dbView hold a weak reference to searchSession object so that
it can match new hdrs before adding them to quick search view.
This commit is contained in:
Родитель
a73a08daa3
Коммит
0f50c91c2d
|
@ -44,6 +44,7 @@ interface nsIMessenger;
|
|||
interface nsIMsgDBHdr;
|
||||
interface nsIMsgDBViewCommandUpdater;
|
||||
interface nsIMsgDatabase;
|
||||
interface nsIMsgSearchSession;
|
||||
|
||||
typedef long nsMsgViewNotificationCodeValue;
|
||||
typedef long nsMsgViewCommandCheckStateValue;
|
||||
|
@ -299,6 +300,8 @@ interface nsIMsgDBView : nsISupports
|
|||
void onDeleteCompleted(in boolean succeeded);
|
||||
|
||||
readonly attribute nsIMsgDatabase db;
|
||||
|
||||
attribute nsIMsgSearchSession searchSession;
|
||||
};
|
||||
|
||||
/* this interface is rapidly morphing from a command updater interface into a more generic
|
||||
|
|
|
@ -165,6 +165,7 @@ function onSearch()
|
|||
outliner.boxObject.QueryInterface(Components.interfaces.nsIOutlinerBoxObject).view = outlinerView;
|
||||
}
|
||||
createSearchTerms();
|
||||
gDBView.searchSession = gSearchSession;
|
||||
try
|
||||
{
|
||||
gSearchSession.search(msgWindow);
|
||||
|
|
|
@ -68,5 +68,6 @@ interface nsIMsgSearchAdapter : nsISupports {
|
|||
[noscript] nsIMsgFolder FindTargetFolder([const] in nsMsgResultElement
|
||||
element);
|
||||
void Abort();
|
||||
void getSearchCharsets(out wstring srcCharset, out wstring destCharset);
|
||||
};
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ interface nsIMsgSearchAdapter;
|
|||
interface nsIMsgSearchTerm;
|
||||
interface nsIMsgSearchNotify;
|
||||
interface nsIMsgHdr;
|
||||
interface nsIMsgDatabase;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// The Msg Search Session is an interface designed to make constructing
|
||||
|
@ -122,6 +123,7 @@ interface nsIMsgSearchSession : nsISupports {
|
|||
in voidPtr param);
|
||||
|
||||
[noscript] void AddResultElement(in nsMsgResultElement element);
|
||||
boolean MatchHdr(in nsIMsgDBHdr aMsgHdr, in nsIMsgDatabase aDatabase);
|
||||
|
||||
void addSearchHit(in nsIMsgDBHdr header, in nsIMsgFolder folder);
|
||||
|
||||
|
|
|
@ -91,7 +91,6 @@ public:
|
|||
static nsresult EncodeImapValue(char *encoding, const char *value, PRBool useQuotes, PRBool reallyDredd);
|
||||
|
||||
static char *GetImapCharsetParam(const PRUnichar *destCharset);
|
||||
void GetSearchCharsets(nsString &srcCharset, nsString &destCharset);
|
||||
static PRUnichar *EscapeSearchUrl (const PRUnichar *nntpCommand);
|
||||
static PRUnichar *EscapeImapSearchProtocol(const PRUnichar *imapCommand);
|
||||
static PRUnichar *EscapeQuoteImapSearchProtocol(const PRUnichar *imapCommand);
|
||||
|
|
|
@ -60,7 +60,6 @@ public:
|
|||
NS_DECL_NSIMSGSEARCHSCOPETERM
|
||||
|
||||
nsresult TimeSlice (PRBool *aDone);
|
||||
|
||||
nsresult InitializeAdapter (nsISupportsArray *termList);
|
||||
|
||||
char *GetStatusBarName ();
|
||||
|
|
|
@ -712,8 +712,8 @@ nsresult nsMsgSearchOfflineMail::Search (PRBool *aDone)
|
|||
else
|
||||
{
|
||||
PRBool match = PR_FALSE;
|
||||
nsAutoString nullCharset, folderCharset;
|
||||
GetSearchCharsets(nullCharset, folderCharset);
|
||||
nsXPIDLString nullCharset, folderCharset;
|
||||
GetSearchCharsets(getter_Copies(nullCharset), getter_Copies(folderCharset));
|
||||
NS_ConvertUCS2toUTF8 charset(folderCharset);
|
||||
// Is this message a hit?
|
||||
err = MatchTermsForSearch (msgDBHdr, m_searchTerms, charset.get(), m_scope, m_db, &match);
|
||||
|
|
|
@ -317,10 +317,13 @@ char *nsMsgSearchAdapter::UnEscapeSearchUrl (const char *commandSpecificData)
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
nsMsgSearchAdapter::GetSearchCharsets(nsString &srcCharset, nsString& dstCharset)
|
||||
nsresult
|
||||
nsMsgSearchAdapter::GetSearchCharsets(PRUnichar **srcCharset, PRUnichar **dstCharset)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_ENSURE_ARG(srcCharset);
|
||||
NS_ENSURE_ARG(dstCharset);
|
||||
|
||||
if (m_defaultCharset.IsEmpty())
|
||||
{
|
||||
m_forceAsciiSearch = PR_FALSE; // set the default value in case of error
|
||||
|
@ -331,9 +334,9 @@ nsMsgSearchAdapter::GetSearchCharsets(nsString &srcCharset, nsString& dstCharset
|
|||
rv = prefs->GetBoolPref("mailnews.force_ascii_search", &m_forceAsciiSearch);
|
||||
}
|
||||
}
|
||||
srcCharset.Assign(m_defaultCharset.IsEmpty() ?
|
||||
*srcCharset = nsCRT::strdup(m_defaultCharset.IsEmpty() ?
|
||||
NS_LITERAL_STRING("ISO-8859-1").get() : m_defaultCharset.get());
|
||||
dstCharset = srcCharset;
|
||||
*dstCharset = nsCRT::strdup(*srcCharset);
|
||||
|
||||
if (m_scope)
|
||||
{
|
||||
|
@ -347,7 +350,7 @@ nsMsgSearchAdapter::GetSearchCharsets(nsString &srcCharset, nsString& dstCharset
|
|||
{
|
||||
nsXPIDLString folderCharset;
|
||||
folder->GetCharset(getter_Copies(folderCharset));
|
||||
dstCharset.Assign(folderCharset);
|
||||
*dstCharset = nsCRT::strdup(folderCharset);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -357,8 +360,8 @@ nsMsgSearchAdapter::GetSearchCharsets(nsString &srcCharset, nsString& dstCharset
|
|||
// the source. (CS_DEFAULT is an indication that the charset
|
||||
// was undefined or unavailable.)
|
||||
// ### well, it's not really anymore. Is there an equivalent?
|
||||
if (!nsCRT::strcmp(dstCharset.get(), m_defaultCharset.get()))
|
||||
dstCharset = srcCharset;
|
||||
if (!nsCRT::strcmp(*dstCharset, m_defaultCharset.get()))
|
||||
*dstCharset = nsCRT::strdup(*srcCharset);
|
||||
|
||||
if (m_forceAsciiSearch)
|
||||
{
|
||||
|
@ -369,8 +372,9 @@ nsMsgSearchAdapter::GetSearchCharsets(nsString &srcCharset, nsString& dstCharset
|
|||
// If the dest csid is ISO Latin 1 or MacRoman, attempt to convert the
|
||||
// source text to US-ASCII. (Not for now.)
|
||||
// if ((dst_csid == CS_LATIN1) || (dst_csid == CS_MAC_ROMAN))
|
||||
dstCharset.Assign(NS_LITERAL_STRING("us-ascii"));
|
||||
*dstCharset = nsCRT::strdup(NS_LITERAL_STRING("us-ascii").get());
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsMsgSearchAdapter::EncodeImapTerm (nsIMsgSearchTerm *term, PRBool reallyDredd, const PRUnichar *srcCharset, const PRUnichar *destCharset, char **ppOutTerm)
|
||||
|
|
|
@ -92,7 +92,6 @@ nsresult nsMsgSearchNews::Search (PRBool *aDone)
|
|||
return err;
|
||||
}
|
||||
|
||||
|
||||
PRUnichar *nsMsgSearchNews::EncodeToWildmat (const PRUnichar *value)
|
||||
{
|
||||
// Here we take advantage of XPAT's use of the wildmat format, which allows
|
||||
|
@ -503,8 +502,8 @@ nsresult nsMsgSearchNewsEx::Encode (nsCString *ppOutEncoding)
|
|||
char *imapTerms = nsnull;
|
||||
|
||||
// Figure out the charsets to use for the search terms and targets.
|
||||
nsString srcCharset, dstCharset;
|
||||
GetSearchCharsets(srcCharset, dstCharset);
|
||||
nsXPIDLString srcCharset, dstCharset;
|
||||
GetSearchCharsets(getter_Copies(srcCharset), getter_Copies(dstCharset));
|
||||
|
||||
nsresult err = EncodeImap (&imapTerms, m_searchTerms, srcCharset.get(), dstCharset.get(), PR_TRUE /*reallyDredd*/);
|
||||
#ifdef DOING_DREDD
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include "nsIMsgMailSession.h"
|
||||
#include "nsMsgBaseCID.h"
|
||||
#include "nsMsgFolderFlags.h"
|
||||
#include "nsMsgLocalSearch.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS4(nsMsgSearchSession, nsIMsgSearchSession, nsIUrlListener, nsIFolderListener, nsISupportsWeakReference)
|
||||
|
||||
|
@ -806,3 +807,21 @@ nsMsgSearchSession::OnItemPropertyFlagChanged(nsISupports *item,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
//this method is used for adding new hdrs to quick search view
|
||||
NS_IMETHODIMP
|
||||
nsMsgSearchSession::MatchHdr(nsIMsgDBHdr *aMsgHdr, nsIMsgDatabase *aDatabase, PRBool *aResult)
|
||||
{
|
||||
nsMsgSearchScopeTerm *scope = (nsMsgSearchScopeTerm *)m_scopeList.SafeElementAt(0);
|
||||
if (scope)
|
||||
{
|
||||
if (scope->m_adapter)
|
||||
{
|
||||
nsXPIDLString nullCharset, folderCharset;
|
||||
scope->m_adapter->GetSearchCharsets(getter_Copies(nullCharset), getter_Copies(folderCharset));
|
||||
NS_ConvertUCS2toUTF8 charset(folderCharset.get());
|
||||
nsMsgSearchOfflineMail::MatchTermsForSearch(aMsgHdr, m_termList, charset.get(), scope, aDatabase, aResult);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -1346,7 +1346,6 @@ nsresult nsMsgSearchScopeTerm::TimeSlice (PRBool *aDone)
|
|||
return m_adapter->Search(aDone);
|
||||
}
|
||||
|
||||
|
||||
nsresult nsMsgSearchScopeTerm::InitializeAdapter (nsISupportsArray *termList)
|
||||
{
|
||||
if (m_adapter)
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefBranchInternal.h"
|
||||
#include "nsIPrefLocalizedString.h"
|
||||
#include "nsIMsgSearchSession.h"
|
||||
|
||||
/* Implementation file */
|
||||
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
||||
|
@ -133,7 +134,7 @@ nsMsgDBView::nsMsgDBView()
|
|||
mRemovingRow = PR_FALSE;
|
||||
mIsSearchView = PR_FALSE;
|
||||
m_saveRestoreSelectionDepth = 0;
|
||||
|
||||
m_searchSession = nsnull;
|
||||
// initialize any static atoms or unicode strings
|
||||
if (gInstanceCount == 0)
|
||||
{
|
||||
|
@ -5122,3 +5123,18 @@ nsMsgDBView::OnNewSearch()
|
|||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgDBView::GetSearchSession(nsIMsgSearchSession* *aSession)
|
||||
{
|
||||
NS_ASSERTION(0, "GetSearchSession method is not implemented");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgDBView::SetSearchSession(nsIMsgSearchSession *aSession)
|
||||
{
|
||||
m_searchSession = getter_AddRefs(NS_GetWeakReference(aSession));
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
#include "nsIImapIncomingServer.h"
|
||||
#include "nsIMsgSearchNotify.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIWeakReference.h"
|
||||
#include "nsIObserver.h"
|
||||
|
||||
#include "nsIStringBundle.h"
|
||||
|
@ -323,7 +324,7 @@ protected:
|
|||
|
||||
nsCOMPtr <nsIMsgDatabase> m_db;
|
||||
nsCOMPtr <nsIMsgFolder> m_folder;
|
||||
|
||||
nsWeakPtr m_searchSession;
|
||||
nsMsgViewSortTypeValue m_sortType;
|
||||
nsMsgViewSortOrderValue m_sortOrder;
|
||||
nsMsgViewFlagsTypeValue m_viewFlags;
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "nsIMsgHdr.h"
|
||||
#include "nsIMsgThread.h"
|
||||
#include "nsIDBFolderInfo.h"
|
||||
#include "nsIMsgSearchSession.h"
|
||||
|
||||
#define MSGHDR_CACHE_LOOK_AHEAD_SIZE 25 // Allocate this more to avoid reallocation on new mail.
|
||||
#define MSGHDR_CACHE_MAX_SIZE 8192 // Max msghdr cache entries.
|
||||
|
@ -101,6 +102,7 @@ NS_IMETHODIMP nsMsgThreadedDBView::Close()
|
|||
NS_IMETHODIMP nsMsgThreadedDBView::ReloadFolderAfterQuickSearch()
|
||||
{
|
||||
mIsSearchView = PR_FALSE;
|
||||
m_searchSession = nsnull;
|
||||
m_sortValid = PR_FALSE; //force a sort
|
||||
nsresult rv = NS_OK;
|
||||
nsMsgKeyArray preservedSelection;
|
||||
|
@ -542,12 +544,7 @@ nsresult nsMsgThreadedDBView::InitSort(nsMsgViewSortTypeValue sortType, nsMsgVie
|
|||
|
||||
nsresult nsMsgThreadedDBView::OnNewHeader(nsMsgKey newKey, nsMsgKey aParentKey, PRBool ensureListed)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mIsSearchView)
|
||||
{
|
||||
OnHeaderAddedOrDeleted(); //db has changed and we are not adding hdr to view so clear the cached info..
|
||||
return NS_OK; // do not add a new message to search view.
|
||||
}
|
||||
nsresult rv;
|
||||
// views can override this behaviour, which is to append to view.
|
||||
// This is the mail behaviour, but threaded views want
|
||||
// to insert in order...
|
||||
|
@ -555,6 +552,16 @@ nsresult nsMsgThreadedDBView::OnNewHeader(nsMsgKey newKey, nsMsgKey aParentKey,
|
|||
rv = m_db->GetMsgHdrForKey(newKey, getter_AddRefs(msgHdr));
|
||||
if (NS_SUCCEEDED(rv) && msgHdr != nsnull)
|
||||
{
|
||||
if (mIsSearchView)
|
||||
{
|
||||
PRBool match=PR_FALSE;
|
||||
OnHeaderAddedOrDeleted(); //db has changed, so clear the cached info..
|
||||
nsCOMPtr <nsIMsgSearchSession> searchSession = do_QueryReferent(m_searchSession);
|
||||
if (searchSession)
|
||||
searchSession->MatchHdr(msgHdr, m_db, &match);
|
||||
if (!match)
|
||||
return NS_OK; // do not add a new message if there isn't a match.
|
||||
}
|
||||
PRUint32 msgFlags;
|
||||
msgHdr->GetFlags(&msgFlags);
|
||||
if ((m_viewFlags & nsMsgViewFlagsType::kUnreadOnly) && !ensureListed && (msgFlags & MSG_FLAG_READ))
|
||||
|
@ -562,7 +569,9 @@ nsresult nsMsgThreadedDBView::OnNewHeader(nsMsgKey newKey, nsMsgKey aParentKey,
|
|||
// Currently, we only add the header in a threaded view if it's a thread.
|
||||
// We used to check if this was the first header in the thread, but that's
|
||||
// a bit harder in the unreadOnly view. But we'll catch it below.
|
||||
if (! (m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay))// || msgHdr->GetMessageKey() == m_messageDB->GetKeyOfFirstMsgInThread(msgHdr->GetMessageKey()))
|
||||
|
||||
// for search view we don't support threaded display so just add it to the view.
|
||||
if (! (m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay) || mIsSearchView)// || msgHdr->GetMessageKey() == m_messageDB->GetKeyOfFirstMsgInThread(msgHdr->GetMessageKey()))
|
||||
rv = AddHdr(msgHdr);
|
||||
else // need to find the thread we added this to so we can change the hasnew flag
|
||||
// added message to existing thread, but not to view
|
||||
|
|
Загрузка…
Ссылка в новой задаче