зеркало из https://github.com/mozilla/pjs.git
scriptify and COMify the validity manager and tables - make the validity manager into a service instead of a global variable
This commit is contained in:
Родитель
c3cd558ae1
Коммит
ed7fa6e50d
|
@ -1,4 +1,4 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
|
@ -24,9 +24,12 @@
|
|||
#define _nsMsgSearchAdapter_H_
|
||||
|
||||
#include "nsMsgSearchCore.h"
|
||||
#include "nsIMsgSearchAdapter.h"
|
||||
#include "nsMsgSearchArray.h"
|
||||
|
||||
#include "nsIMsgSearchAdapter.h"
|
||||
#include "nsIMsgSearchValidityTable.h"
|
||||
#include "nsIMsgSearchValidityManager.h"
|
||||
|
||||
#include "nsMsgSearchArray.h"
|
||||
class nsIMsgSearchScopeTerm;
|
||||
class nsINNTPHost;
|
||||
|
||||
|
@ -134,18 +137,12 @@ protected:
|
|||
// servers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class nsMsgSearchValidityTable
|
||||
class nsMsgSearchValidityTable : public nsIMsgSearchValidityTable
|
||||
{
|
||||
public:
|
||||
nsMsgSearchValidityTable ();
|
||||
void SetAvailable (int attrib, int op, PRBool);
|
||||
void SetEnabled (int attrib, int op, PRBool);
|
||||
void SetValidButNotShown (int attrib, int op, PRBool);
|
||||
PRBool GetAvailable (int attrib, int op);
|
||||
PRBool GetEnabled (int attrib, int op);
|
||||
PRBool GetValidButNotShown (int attrib, int op);
|
||||
nsresult ValidateTerms (nsMsgSearchTermArray&);
|
||||
int GetNumAvailAttribs(); // number of attribs with at least one available operator
|
||||
NS_DECL_NSIMSGSEARCHVALIDITYTABLE
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
protected:
|
||||
int m_numAvailAttribs; // number of rows with at least one available operator
|
||||
|
@ -160,26 +157,32 @@ protected:
|
|||
|
||||
// Using getters and setters seems a little nicer then dumping the 2-D array
|
||||
// syntax all over the code
|
||||
inline void nsMsgSearchValidityTable::SetAvailable (int a, int o, PRBool b)
|
||||
{ m_table [a][o].bitAvailable = b; }
|
||||
inline void nsMsgSearchValidityTable::SetEnabled (int a, int o, PRBool b)
|
||||
{ m_table [a][o].bitEnabled = b; }
|
||||
inline void nsMsgSearchValidityTable::SetValidButNotShown (int a, int o, PRBool b)
|
||||
{ m_table [a][o].bitValidButNotShown = b; }
|
||||
inline nsresult nsMsgSearchValidityTable::SetAvailable (int a, int o, PRBool b)
|
||||
{ m_table [a][o].bitAvailable = b; return NS_OK;}
|
||||
inline nsresult nsMsgSearchValidityTable::SetEnabled (int a, int o, PRBool b)
|
||||
{ m_table [a][o].bitEnabled = b; return NS_OK; }
|
||||
inline nsresult nsMsgSearchValidityTable::SetValidButNotShown (int a, int o, PRBool b)
|
||||
{ m_table [a][o].bitValidButNotShown = b; return NS_OK;}
|
||||
|
||||
inline PRBool nsMsgSearchValidityTable::GetAvailable (int a, int o)
|
||||
{ return m_table [a][o].bitAvailable; }
|
||||
inline PRBool nsMsgSearchValidityTable::GetEnabled (int a, int o)
|
||||
{ return m_table [a][o].bitEnabled; }
|
||||
inline PRBool nsMsgSearchValidityTable::GetValidButNotShown (int a, int o)
|
||||
{ return m_table [a][o].bitValidButNotShown; }
|
||||
inline nsresult nsMsgSearchValidityTable::GetAvailable (int a, int o, PRBool *aResult)
|
||||
{ *aResult = m_table [a][o].bitAvailable; return NS_OK;}
|
||||
inline nsresult nsMsgSearchValidityTable::GetEnabled (int a, int o, PRBool *aResult)
|
||||
{ *aResult = m_table [a][o].bitEnabled; return NS_OK;}
|
||||
inline nsresult nsMsgSearchValidityTable::GetValidButNotShown (int a, int o, PRBool *aResult)
|
||||
{ *aResult = m_table [a][o].bitValidButNotShown; return NS_OK;}
|
||||
|
||||
class nsMsgSearchValidityManager
|
||||
class nsMsgSearchValidityManager : public nsIMsgSearchValidityManager
|
||||
{
|
||||
public:
|
||||
nsMsgSearchValidityManager ();
|
||||
~nsMsgSearchValidityManager ();
|
||||
|
||||
protected:
|
||||
virtual ~nsMsgSearchValidityManager ();
|
||||
|
||||
public:
|
||||
NS_DECL_NSIMSGSEARCHVALIDITYMANAGER
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsresult GetTable (int, nsMsgSearchValidityTable**);
|
||||
|
||||
nsresult PostProcessValidityTable (nsINNTPHost*);
|
||||
|
@ -199,14 +202,14 @@ protected:
|
|||
// this with static members of the adapter classes, but having a dedicated
|
||||
// object makes cleanup of these tables (at shutdown-time) automagic.
|
||||
|
||||
nsMsgSearchValidityTable *m_offlineMailTable;
|
||||
nsMsgSearchValidityTable *m_onlineMailTable;
|
||||
nsMsgSearchValidityTable *m_onlineMailFilterTable;
|
||||
nsMsgSearchValidityTable *m_newsTable;
|
||||
nsMsgSearchValidityTable *m_newsExTable;
|
||||
nsMsgSearchValidityTable *m_localNewsTable; // used for local news searching or offline news searching...
|
||||
nsCOMPtr<nsIMsgSearchValidityTable> m_offlineMailTable;
|
||||
nsCOMPtr<nsIMsgSearchValidityTable> m_onlineMailTable;
|
||||
nsCOMPtr<nsIMsgSearchValidityTable> m_onlineMailFilterTable;
|
||||
nsCOMPtr<nsIMsgSearchValidityTable> m_newsTable;
|
||||
nsCOMPtr<nsIMsgSearchValidityTable> m_newsExTable;
|
||||
nsCOMPtr<nsIMsgSearchValidityTable> m_localNewsTable; // used for local news searching or offline news searching...
|
||||
|
||||
nsresult NewTable (nsMsgSearchValidityTable **);
|
||||
nsresult NewTable (nsIMsgSearchValidityTable **);
|
||||
|
||||
nsresult InitOfflineMailTable ();
|
||||
nsresult InitOnlineMailTable ();
|
||||
|
@ -218,8 +221,4 @@ protected:
|
|||
void EnableLdapAttribute (nsMsgSearchAttribValue, PRBool enabled = PR_TRUE);
|
||||
};
|
||||
|
||||
extern nsMsgSearchValidityManager gValidityMgr;
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -291,8 +291,8 @@ nsresult nsMsgSearchOnlineMail::Encode (nsCString *pEncoding, nsMsgSearchTermArr
|
|||
|
||||
nsresult nsMsgSearchValidityManager::InitOfflineMailTable ()
|
||||
{
|
||||
PR_ASSERT (nsnull == m_offlineMailTable);
|
||||
nsresult err = NewTable (&m_offlineMailTable);
|
||||
NS_ASSERTION (nsnull == m_offlineMailTable, "offline mail table already initted");
|
||||
nsresult err = NewTable (getter_AddRefs(m_offlineMailTable));
|
||||
|
||||
if (NS_SUCCEEDED(err))
|
||||
{
|
||||
|
@ -413,8 +413,8 @@ nsresult nsMsgSearchValidityManager::InitOfflineMailTable ()
|
|||
|
||||
nsresult nsMsgSearchValidityManager::InitOnlineMailTable ()
|
||||
{
|
||||
PR_ASSERT (nsnull == m_onlineMailTable);
|
||||
nsresult err = NewTable (&m_onlineMailTable);
|
||||
NS_ASSERTION (nsnull == m_onlineMailTable, "Online mail table already initted!");
|
||||
nsresult err = NewTable (getter_AddRefs(m_onlineMailTable));
|
||||
|
||||
if (NS_SUCCEEDED(err))
|
||||
{
|
||||
|
@ -490,8 +490,8 @@ nsresult nsMsgSearchValidityManager::InitOnlineMailFilterTable ()
|
|||
// is supposed to be the same as offline mail, except that the body
|
||||
// attribute is omitted
|
||||
|
||||
PR_ASSERT (nsnull == m_onlineMailFilterTable);
|
||||
nsresult err = NewTable (&m_onlineMailFilterTable);
|
||||
NS_ASSERTION (nsnull == m_onlineMailFilterTable, "online filter table already initted");
|
||||
nsresult err = NewTable (getter_AddRefs(m_onlineMailFilterTable));
|
||||
|
||||
if (NS_SUCCEEDED(err))
|
||||
{
|
||||
|
|
|
@ -32,6 +32,10 @@
|
|||
#include "nsMsgSearchTerm.h"
|
||||
#include "nsMsgResultElement.h"
|
||||
|
||||
#include "nsMsgBaseCID.h"
|
||||
|
||||
static NS_DEFINE_CID(kValidityManagerCID, NS_MSGSEARCHVALIDITYMANAGER_CID);
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern int MK_MSG_SEARCH_STATUS;
|
||||
|
@ -252,8 +256,14 @@ nsresult nsMsgSearchIMAPOfflineMail::ValidateTerms ()
|
|||
// if (!XP_Stat (m_scope->GetMailPath(), &fileStatus, xpMailFolder))
|
||||
// {
|
||||
// Make sure the terms themselves are valid
|
||||
nsMsgSearchValidityTable *table = nsnull;
|
||||
err = gValidityMgr.GetTable (nsMsgSearchValidityManager::offlineMail, &table);
|
||||
nsCOMPtr<nsIMsgValidityManager> validityManager =
|
||||
do_GetService(kValidityManagerCID, &err);
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIMsgSearchValidityTable> table;
|
||||
err = validityManager->GetTable (nsMsgSearchValidityManager::offlineMail,
|
||||
getter_AddRefs(table));
|
||||
if (NS_OK == err)
|
||||
{
|
||||
NS_ASSERTION (table, "found validity table");
|
||||
|
@ -304,8 +314,14 @@ nsresult nsMsgSearchOfflineMail::ValidateTerms ()
|
|||
if (!XP_Stat (m_scope->GetMailPath(), &fileStatus, xpMailFolder))
|
||||
{
|
||||
// Make sure the terms themselves are valid
|
||||
nsMsgSearchValidityTable *table = nsnull;
|
||||
err = gValidityMgr.GetTable (nsMsgSearchValidityManager::offlineMail, &table);
|
||||
nsCOMPtr<nsIMsgValidityManager> validityManager =
|
||||
do_GetService(kValidityManagerCID, &err);
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIMsgSearchValidityTable> table;
|
||||
err = validityManager->GetTable(nsMsgSearchValidityManager::offlineMail,
|
||||
getter_AddRefs(table));
|
||||
if (NS_OK == err)
|
||||
{
|
||||
NS_ASSERTION (table, "didn't get validity table");
|
||||
|
|
|
@ -786,31 +786,41 @@ char *nsMsgSearchAdapter::TransformSpacesToStars (const char *spaceString, msg_T
|
|||
|
||||
nsMsgSearchValidityTable::nsMsgSearchValidityTable ()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
// Set everything to be unavailable and disabled
|
||||
for (int i = 0; i < nsMsgSearchAttrib::kNumMsgSearchAttributes; i++)
|
||||
for (int j = 0; j < nsMsgSearchOp::kNumMsgSearchOperators; j++)
|
||||
{
|
||||
SetAvailable (i, j, FALSE);
|
||||
SetEnabled (i, j, FALSE);
|
||||
SetValidButNotShown (i,j, FALSE);
|
||||
SetAvailable (i, j, PR_FALSE);
|
||||
SetEnabled (i, j, PR_FALSE);
|
||||
SetValidButNotShown (i,j, PR_FALSE);
|
||||
}
|
||||
m_numAvailAttribs = 0; // # of attributes marked with at least one available operator
|
||||
}
|
||||
|
||||
int nsMsgSearchValidityTable::GetNumAvailAttribs()
|
||||
NS_IMPL_ISUPPORTS1(nsMsgSearchValidityTable, nsIMsgSearchValidityTable)
|
||||
|
||||
|
||||
nsresult
|
||||
nsMsgSearchValidityTable::GetNumAvailAttribs(PRInt32 *aResult)
|
||||
{
|
||||
m_numAvailAttribs = 0;
|
||||
for (int i = 0; i < nsMsgSearchAttrib::kNumMsgSearchAttributes; i++)
|
||||
for (int j = 0; j < nsMsgSearchOp::kNumMsgSearchOperators; j++)
|
||||
if (GetAvailable(i, j))
|
||||
for (int j = 0; j < nsMsgSearchOp::kNumMsgSearchOperators; j++) {
|
||||
PRBool available;
|
||||
GetAvailable(i, j, &available);
|
||||
if (available)
|
||||
{
|
||||
m_numAvailAttribs++;
|
||||
break;
|
||||
}
|
||||
return m_numAvailAttribs;
|
||||
}
|
||||
*aResult = m_numAvailAttribs;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsMsgSearchValidityTable::ValidateTerms (nsMsgSearchTermArray &termList)
|
||||
nsresult
|
||||
nsMsgSearchValidityTable::ValidateTerms (nsMsgSearchTermArray &termList)
|
||||
{
|
||||
nsresult err = NS_OK;
|
||||
|
||||
|
@ -818,10 +828,16 @@ nsresult nsMsgSearchValidityTable::ValidateTerms (nsMsgSearchTermArray &termList
|
|||
{
|
||||
nsMsgSearchTerm *term = termList.ElementAt(i);
|
||||
// XP_ASSERT(term->IsValid());
|
||||
if (!GetEnabled(term->m_attribute, term->m_operator) ||
|
||||
!GetAvailable(term->m_attribute, term->m_operator))
|
||||
PRBool enabled;
|
||||
PRBool available;
|
||||
GetEnabled(term->m_attribute, term->m_operator, &enabled);
|
||||
GetAvailable(term->m_attribute, term->m_operator, &available);
|
||||
if (!enabled || !available)
|
||||
{
|
||||
if (!GetValidButNotShown(term->m_attribute, term->m_operator))
|
||||
PRBool validNotShown;
|
||||
GetValidButNotShown(term->m_attribute, term->m_operator,
|
||||
&validNotShown);
|
||||
if (!validNotShown)
|
||||
err = NS_MSG_ERROR_INVALID_SEARCH_SCOPE;
|
||||
}
|
||||
}
|
||||
|
@ -829,49 +845,57 @@ nsresult nsMsgSearchValidityTable::ValidateTerms (nsMsgSearchTermArray &termList
|
|||
return err;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgSearchValidityTable::GetAvailableAttributes(PRInt32 *length,
|
||||
nsMsgSearchAttribValue **aResult)
|
||||
{
|
||||
// count first
|
||||
PRInt32 totalAttributes=0;
|
||||
PRInt32 i, j;
|
||||
for (i = 0; i< nsMsgSearchAttrib::kNumMsgSearchAttributes; i++) {
|
||||
for (j=0; j< nsMsgSearchOp::kNumMsgSearchOperators; j++) {
|
||||
if (m_table[i][j].bitAvailable) {
|
||||
totalAttributes++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// global variable with destructor allows automatic cleanup
|
||||
nsMsgSearchValidityManager gValidityMgr;
|
||||
nsMsgSearchAttribValue *array = new nsMsgSearchAttribValue[totalAttributes];
|
||||
if (!array) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
PRInt32 numStored=0;
|
||||
|
||||
for (i = 0; i< nsMsgSearchAttrib::kNumMsgSearchAttributes; i++) {
|
||||
for (j=0; j< nsMsgSearchOp::kNumMsgSearchOperators; j++) {
|
||||
if (m_table[i][j].bitAvailable) {
|
||||
array[numStored++] = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_ASSERTION(totalAttributes == numStored, "Search Attributes not lining up");
|
||||
*length = totalAttributes;
|
||||
*aResult = array;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsMsgSearchValidityManager::nsMsgSearchValidityManager ()
|
||||
{
|
||||
m_offlineMailTable = nsnull;
|
||||
m_onlineMailTable = nsnull;
|
||||
m_onlineMailFilterTable = nsnull;
|
||||
m_newsTable = nsnull;
|
||||
m_localNewsTable = nsnull;
|
||||
#ifdef DOING_EXNEWSSEARCH
|
||||
m_newsExTable = nsnull;
|
||||
#endif
|
||||
#ifdef DOING_LDAP
|
||||
m_ldapTable = nsnull;
|
||||
#endif
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
|
||||
nsMsgSearchValidityManager::~nsMsgSearchValidityManager ()
|
||||
{
|
||||
if (nsnull != m_offlineMailTable)
|
||||
delete m_offlineMailTable;
|
||||
if (nsnull != m_onlineMailTable)
|
||||
delete m_onlineMailTable;
|
||||
if (nsnull != m_onlineMailFilterTable)
|
||||
delete m_onlineMailFilterTable;
|
||||
if (nsnull != m_newsTable)
|
||||
delete m_newsTable;
|
||||
if (nsnull != m_localNewsTable)
|
||||
delete m_localNewsTable;
|
||||
#ifdef DOING_EXNEWSSEARCH
|
||||
if (nsnull != m_newsExTable)
|
||||
delete m_newsExTable;
|
||||
#endif
|
||||
#ifdef DOING_LDAP
|
||||
if (nsnull != m_ldapTable)
|
||||
delete m_ldapTable;
|
||||
#endif
|
||||
// tables released by nsCOMPtr
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsMsgSearchValidityManager, nsIMsgSearchValidityManager)
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Bottleneck accesses to the objects so we can allocate and initialize them
|
||||
|
@ -879,7 +903,7 @@ nsMsgSearchValidityManager::~nsMsgSearchValidityManager ()
|
|||
// user actually searches that scope.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
nsresult nsMsgSearchValidityManager::GetTable (int whichTable, nsMsgSearchValidityTable **ppOutTable)
|
||||
nsresult nsMsgSearchValidityManager::GetTable (int whichTable, nsIMsgSearchValidityTable **ppOutTable)
|
||||
{
|
||||
NS_ENSURE_ARG(ppOutTable);
|
||||
|
||||
|
@ -945,13 +969,15 @@ nsresult nsMsgSearchValidityManager::GetTable (int whichTable, nsMsgSearchValidi
|
|||
|
||||
|
||||
|
||||
nsresult nsMsgSearchValidityManager::NewTable(nsMsgSearchValidityTable **aTable)
|
||||
nsresult
|
||||
nsMsgSearchValidityManager::NewTable(nsIMsgSearchValidityTable **aTable)
|
||||
{
|
||||
NS_ENSURE_ARG (aTable);
|
||||
*aTable = new nsMsgSearchValidityTable;
|
||||
if (nsnull == *aTable)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
NS_ADDREF(*aTable);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -90,8 +90,8 @@ char *nsMsgSearchNews::EncodeValue (const char *value)
|
|||
if (nsCRT::IsAsciiAlpha(*value))
|
||||
{
|
||||
*walkValue++ = '[';
|
||||
*walkValue++ = toupper(*value);
|
||||
*walkValue++ = tolower(*value);
|
||||
*walkValue++ = (char)nsCRT::ToUpper((PRUnichar)*value);
|
||||
*walkValue++ = (char)nsCRT::ToLower((PRUnichar)*value);
|
||||
*walkValue++ = ']';
|
||||
}
|
||||
else
|
||||
|
@ -311,7 +311,7 @@ void nsMsgSearchNews::PreExitFunction (URL_Struct * /*url*/, int status, MWConte
|
|||
PRBool nsMsgSearchNews::DuplicateHit(PRUint32 artNum)
|
||||
// ASSUMES m_hits is sorted!!
|
||||
{
|
||||
PRInt32 index;
|
||||
PRUint32 index;
|
||||
for (index = 0; index < m_hits.GetSize(); index++)
|
||||
if (artNum == m_hits.ElementAt(index))
|
||||
return PR_TRUE;
|
||||
|
@ -746,7 +746,7 @@ SEARCH_API int MSG_AddProfileGroup (MSG_Pane *pane, MSG_NewsHost* host,
|
|||
nsresult nsMsgSearchValidityManager::InitNewsTable ()
|
||||
{
|
||||
NS_ASSERTION (nsnull == m_newsTable,"don't call this twice!");
|
||||
nsresult err = NewTable (&m_newsTable);
|
||||
nsresult err = NewTable (getter_AddRefs(m_newsTable));
|
||||
|
||||
if (NS_OK == err)
|
||||
{
|
||||
|
@ -779,7 +779,7 @@ nsresult nsMsgSearchValidityManager::InitNewsExTable (nsINNTPHost *newsHost)
|
|||
nsresult err = NS_OK;
|
||||
|
||||
if (!m_newsExTable)
|
||||
err = NewTable (&m_newsExTable);
|
||||
err = NewTable (getter_AddRefs(m_newsExTable));
|
||||
|
||||
if (NS_OK == err)
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
nsMsgSearchValueImpl::nsMsgSearchValueImpl(nsMsgSearchValue *aInitialValue)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mValue = *aInitialValue;
|
||||
// XXX TODO - make a copy of the string if it's a string attribute
|
||||
// (right now we dont' know when it's a string!)
|
||||
|
|
Загрузка…
Ссылка в новой задаче