add new API to search for filters by name

This commit is contained in:
alecf%netscape.com 2000-05-16 05:58:47 +00:00
parent aca30a0c1c
commit e5206c1545
2 changed files with 32 additions and 0 deletions

View File

@ -56,6 +56,7 @@ interface nsIMsgFilterList : nsISupports {
readonly attribute unsigned long filterCount;
nsIMsgFilter GetFilterAt(in unsigned long filterIndex);
nsIMsgFilter getFilterNamed(in wstring filterName);
/* these methods don't delete filters - they just change the list.
* FE still must
* call MSG_DestroyFilter to delete a filter.

View File

@ -32,6 +32,7 @@
#include "nsFileStream.h"
#include "nsMsgUtils.h"
#include "nsMsgSearchTerm.h"
#include "nsXPIDLString.h"
// unicode "%s" format string
static const PRUnichar unicodeFormatter[] = {
@ -723,6 +724,36 @@ nsresult nsMsgFilterList::GetFilterAt(PRUint32 filterIndex, nsIMsgFilter **filte
return NS_OK;
}
nsresult
nsMsgFilterList::GetFilterNamed(const PRUnichar *aName, nsIMsgFilter **aResult)
{
nsresult rv;
NS_ENSURE_ARG_POINTER(aName);
NS_ENSURE_ARG_POINTER(aResult);
PRUint32 count=0;
m_filters->Count(&count);
*aResult = nsnull;
PRUint32 i;
for (i=0; i<count; i++) {
nsCOMPtr<nsISupports> filterSupports;
rv = m_filters->GetElementAt(i, getter_AddRefs(filterSupports));
if (NS_FAILED(rv)) continue;
// cast is safe because array is private
nsIMsgFilter *filter = (nsIMsgFilter *)filterSupports.get();
nsXPIDLString filterName;
filter->GetFilterName(getter_Copies(filterName));
if (nsCRT::strcmp(filterName, aName) == 0) {
*aResult = filter;
break;
}
}
NS_IF_ADDREF(*aResult);
return NS_OK;
}
nsresult nsMsgFilterList::SetFilterAt(PRUint32 filterIndex, nsIMsgFilter *filter)
{
m_filters->ReplaceElementAt(filter, filterIndex);