зеркало из https://github.com/mozilla/gecko-dev.git
Make it possible to get an nsMsgKeyArray from an nsMsgKeySet, and to get the list of NEW messages from nsIMsgDatabase (bug 170841). r=naving@netscape.com, sr=bienvenu@netscape.com
This commit is contained in:
Родитель
b3ac5276f0
Коммит
399c89c164
|
@ -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 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998, 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
|
@ -42,6 +42,7 @@
|
|||
#include "nsMsgKeySet.h"
|
||||
#include "prprf.h"
|
||||
#include "prmem.h"
|
||||
#include "nsMsgKeyArray.h"
|
||||
|
||||
#if defined(DEBUG_seth_) || defined(DEBUG_sspitzer_)
|
||||
#define DEBUG_MSGKEYSET 1
|
||||
|
@ -1174,7 +1175,66 @@ nsMsgKeySet::LastMissingRange(PRInt32 min, PRInt32 max,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a copy of this as an nsMsgKeyArray, which is much easier for
|
||||
* callers to manipulate. Normal XPCOM calling conventions, although the
|
||||
* array itself isn't refcounted, so the caller should free when done
|
||||
* using NS_DELETEXPCOM().
|
||||
*/
|
||||
nsresult
|
||||
nsMsgKeySet::ToMsgKeyArray(nsMsgKeyArray **aArray)
|
||||
{
|
||||
PRInt32 size;
|
||||
PRInt32 *head;
|
||||
PRInt32 *tail;
|
||||
PRInt32 *end;
|
||||
PRInt32 last_art = -1;
|
||||
|
||||
nsMsgKeyArray *array;
|
||||
NS_NEWXPCOM(array, nsMsgKeyArray);
|
||||
if (!array)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
size = m_length;
|
||||
head = m_data;
|
||||
tail = head;
|
||||
end = head + size;
|
||||
|
||||
while (tail < end) {
|
||||
PRInt32 from;
|
||||
PRInt32 to;
|
||||
|
||||
if (*tail < 0) {
|
||||
/* it's a range */
|
||||
from = tail[1];
|
||||
to = from + (-(tail[0]));
|
||||
tail += 2;
|
||||
}
|
||||
else /* it's a literal */
|
||||
{
|
||||
from = *tail;
|
||||
to = from;
|
||||
tail++;
|
||||
}
|
||||
if (from == 0) {
|
||||
from = 1; /* See 'hack' comment above ### */
|
||||
}
|
||||
if (from <= last_art) from = last_art + 1;
|
||||
if (from <= to) {
|
||||
if (from < to) {
|
||||
for (PRInt32 i = from; i < to ; ++i ) {
|
||||
array->Add(i);
|
||||
}
|
||||
} else {
|
||||
array->Add(from);
|
||||
}
|
||||
last_art = to;
|
||||
}
|
||||
}
|
||||
|
||||
*aArray = array;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG /* A lot of test cases for the above */
|
||||
|
|
|
@ -40,6 +40,8 @@
|
|||
|
||||
#include "msgCore.h"
|
||||
|
||||
class nsMsgKeyArray;
|
||||
|
||||
// nsMsgKeySet represents a set of articles. Typically, it is the set of
|
||||
// read articles from a .newsrc file, but it can be used for other purposes
|
||||
// too.
|
||||
|
@ -99,6 +101,14 @@ public:
|
|||
void SetLastMember(PRInt32 highWaterMark);
|
||||
// For debugging only...
|
||||
PRInt32 getLength() {return m_length;}
|
||||
|
||||
/**
|
||||
* Return a copy of this as an nsMsgKeyArray, which is much easier for
|
||||
* callers to manipulate. Normal XPCOM calling conventions, although the
|
||||
* array itself isn't refcounted, so the caller should free when done
|
||||
* using NS_DELETEXPCOM().
|
||||
*/
|
||||
nsresult ToMsgKeyArray(nsMsgKeyArray **aArray);
|
||||
|
||||
#ifdef DEBUG
|
||||
static void RunTests();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
|
@ -273,5 +273,15 @@ interface nsIMsgDatabase : nsIDBChangeAnnouncer {
|
|||
attribute unsigned long msgHdrCacheSize;
|
||||
|
||||
void setFolderStream(in nsIOFileStream aFileStream);
|
||||
|
||||
/**
|
||||
* The list of messages currently in the NEW state.
|
||||
*
|
||||
* If there are no such messages, a null pointer may be returned.
|
||||
* Note that the since the structure itself is not refcounted,
|
||||
* the caller should free when done using NS_DELETEXPCOM().
|
||||
*/
|
||||
[noscript]
|
||||
readonly attribute nsMsgKeyArrayPtr newList;
|
||||
};
|
||||
|
||||
|
|
|
@ -4425,3 +4425,20 @@ NS_IMETHODIMP nsMsgDatabase::SetFolderStream(nsIOFileStream *aFileStream)
|
|||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* [noscript] readonly attribute nsMsgKeySetPtr newList;
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsMsgDatabase::GetNewList(nsMsgKeyArray * *aNewList)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aNewList);
|
||||
|
||||
if (m_newSet) {
|
||||
return m_newSet->ToMsgKeyArray(aNewList);
|
||||
}
|
||||
|
||||
// if there were no new messages, signal this by returning a null pointer
|
||||
//
|
||||
*aNewList = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче