more work on threading interfaces, plus i18n change

This commit is contained in:
bienvenu%netscape.com 1999-04-06 05:44:37 +00:00
Родитель 151da4bcb4
Коммит a3caca534e
4 изменённых файлов: 176 добавлений и 88 удалений

Просмотреть файл

@ -1,56 +0,0 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1999 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _nsIMsgThread_H
#define _nsIMsgThread_H
#include "nsISupports.h"
#include "nsString.h"
#include "MailNewsTypes.h"
#include "mdb.h"
class nsIMessage;
#define NS_IMSGTHREAD_IID \
{/* df64af90-e2da-11d2-8d6c-00805f8a6617 */ \
0xdf64af90, \
0xe2da, \
0x11d2, \
0x8d, 0x6c, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0x17 \
}
class nsIMsgThread : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IMSGTHREAD_IID; return iid; }
NS_IMETHOD SetThreadKey(nsMsgKey threadKey) = 0;
NS_IMETHOD GetThreadKey(nsMsgKey *result) = 0;
NS_IMETHOD GetFlags(PRUint32 *result) = 0;
NS_IMETHOD SetFlags(PRUint32 flags) = 0;
NS_IMETHOD GetNumChildren(PRUint32 *result) = 0;
NS_IMETHOD GetNumUnreadChildren (PRUint32 *result) = 0;
NS_IMETHOD AddChild(nsIMessage *child, PRBool threadInThread) = 0;
NS_IMETHOD GetChildAt(PRUint32 index, nsIMessage **result) = 0;
NS_IMETHOD GetChild(nsMsgKey msgKey, nsIMessage **result) = 0;
NS_IMETHOD GetChildHdrAt(PRUint32 index, nsIMessage **result) = 0;
NS_IMETHOD RemoveChildAt(PRUint32 index) = 0;
NS_IMETHOD RemoveChild(nsMsgKey msgKey) = 0;
NS_IMETHOD MarkChildRead(PRBool bRead) = 0;
};
#endif

Просмотреть файл

@ -42,12 +42,13 @@ public:
NS_IMETHOD GetNumChildren(PRUint32 *result);
NS_IMETHOD GetNumUnreadChildren (PRUint32 *result);
NS_IMETHOD AddChild(nsIMessage *child, PRBool threadInThread);
NS_IMETHOD GetChildAt(PRUint32 index, nsIMessage **result);
NS_IMETHOD GetChildAt(PRInt32 index, nsIMessage **result);
NS_IMETHOD GetChild(nsMsgKey msgKey, nsIMessage **result);
NS_IMETHOD GetChildHdrAt(PRUint32 index, nsIMessage **result);
NS_IMETHOD RemoveChildAt(PRUint32 index);
NS_IMETHOD GetChildHdrAt(PRInt32 index, nsIMessage **result);
NS_IMETHOD RemoveChildAt(PRInt32 index);
NS_IMETHOD RemoveChild(nsMsgKey msgKey);
NS_IMETHOD MarkChildRead(PRBool bRead);
NS_IMETHOD EnumerateMessages(nsMsgKey parent, nsIEnumerator* *result);
// non-interface methods
nsIMdbTable *GetMDBTable() {return m_mdbTable;}

Просмотреть файл

@ -2089,33 +2089,45 @@ nsresult nsMsgDatabase::RowCellColumnToCollationKey(nsIMdbRow *row, mdb_token co
// get a locale factory
err = nsComponentManager::FindFactory(kLocaleFactoryCID, (nsIFactory**)&localeFactory);
// do this for a new db if no UI to be provided for locale selection
err = localeFactory->GetApplicationLocale(&locale);
// or generate a locale from a stored locale name ("en_US", "fr_FR")
err = localeFactory->NewLocale(&localeName, &locale);
// and locale name can be taken as below, category should be one of the following
// probably NSILOCALE_COLLATE is appropriate
nsString catagory = "NSILOCALE_COLLATE";
err = locale->GetCatagory(&catagory, &localeName);
nsICollationFactory *f;
err = nsComponentManager::CreateInstance(kCollationFactoryCID, NULL,
kICollationFactoryIID, (void**) &f);
nsICollation *inst;
// get a collation interface instance
err = f->CreateCollation(locale, &inst);
if (NS_SUCCEEDED(err) && inst)
if (NS_SUCCEEDED(err) && localeFactory)
{
err = inst->CreateSortKey( kCollationCaseSensitive, nakedString, resultStr) ;
}
}
// do this for a new db if no UI to be provided for locale selection
err = localeFactory->GetApplicationLocale(&locale);
// or generate a locale from a stored locale name ("en_US", "fr_FR")
//err = localeFactory->NewLocale(&localeName, &locale);
// release locale factory
NS_RELEASE(localeFactory);
// and locale name can be taken as below, category should be one of the following
// probably NSILOCALE_COLLATE is appropriate
nsString catagory = "NSILOCALE_COLLATE";
err = locale->GetCatagory(&catagory, &localeName);
nsICollationFactory *f;
err = nsComponentManager::CreateInstance(kCollationFactoryCID, NULL,
kICollationFactoryIID, (void**) &f);
if (NS_SUCCEEDED(err) && f)
{
nsICollation *inst;
// get a collation interface instance
err = f->CreateCollation(nsnull/*locale*/, &inst); // Temporary: pass null until bug#3867 is fixed
// release locale, collation factory
NS_RELEASE(locale);
NS_RELEASE(f);
if (NS_SUCCEEDED(err) && inst)
{
err = inst->CreateSortKey( kCollationCaseSensitive, nakedString, resultStr) ;
NS_RELEASE(inst);
}
}
}
}
return err;
}

Просмотреть файл

@ -171,7 +171,7 @@ NS_IMETHODIMP nsMsgThread::AddChild(nsIMessage *child, PRBool threadInThread)
}
NS_IMETHODIMP nsMsgThread::GetChildAt(PRUint32 index, nsIMessage **result)
NS_IMETHODIMP nsMsgThread::GetChildAt(PRInt32 index, nsIMessage **result)
{
nsresult ret = NS_OK;
@ -187,15 +187,34 @@ NS_IMETHODIMP nsMsgThread::GetChild(nsMsgKey msgKey, nsIMessage **result)
}
NS_IMETHODIMP nsMsgThread::GetChildHdrAt(PRUint32 index, nsIMessage **result)
NS_IMETHODIMP nsMsgThread::GetChildHdrAt(PRInt32 index, nsIMessage **result)
{
nsresult ret = NS_OK;
nsIMdbRow* resultRow;
mdb_pos pos = index;
nsIMdbTableRowCursor *rowCursor;
ret = m_mdbTable->GetTableRowCursor(m_mdbDB->GetEnv(), pos, &rowCursor);
ret = rowCursor->NextRow(m_mdbDB->GetEnv(), &resultRow, &pos);
NS_RELEASE(rowCursor);
if (NS_FAILED(ret))
return ret;
//Get key from row
mdbOid outOid;
nsMsgKey key;
if (resultRow->GetOid(m_mdbDB->GetEnv(), &outOid) == NS_OK)
key = outOid.mOid_Id;
ret = m_mdbDB->CreateMsgHdr(resultRow, m_mdbDB->m_dbName, key, result, PR_TRUE);
if (NS_FAILED(ret))
return ret;
return ret;
}
NS_IMETHODIMP nsMsgThread::RemoveChildAt(PRUint32 index)
NS_IMETHODIMP nsMsgThread::RemoveChildAt(PRInt32 index)
{
nsresult ret = NS_OK;
@ -218,6 +237,118 @@ NS_IMETHODIMP nsMsgThread::MarkChildRead(PRBool bRead)
return ret;
}
class nsMsgThreadEnumerator : public nsIEnumerator {
public:
NS_DECL_ISUPPORTS
// nsIEnumerator methods:
NS_IMETHOD First(void);
NS_IMETHOD Next(void);
NS_IMETHOD CurrentItem(nsISupports **aItem);
NS_IMETHOD IsDone(void);
// nsMsgThreadEnumerator methods:
typedef nsresult (*nsMsgThreadEnumeratorFilter)(nsIMessage* hdr, void* closure);
nsMsgThreadEnumerator(nsMsgThread *thread, nsMsgKey startKey,
nsMsgThreadEnumeratorFilter filter, void* closure);
virtual ~nsMsgThreadEnumerator();
protected:
nsIMdbTableRowCursor* mRowCursor;
nsIMessage* mResultHdr;
nsMsgThread* mThread;
nsMsgKey mCurKey;
PRInt32 mChildIndex;
PRBool mDone;
nsMsgThreadEnumeratorFilter mFilter;
void* mClosure;
};
nsMsgThreadEnumerator::nsMsgThreadEnumerator(nsMsgThread *thread, nsMsgKey startKey,
nsMsgThreadEnumeratorFilter filter, void* closure)
: mRowCursor(nsnull), mResultHdr(nsnull), mDone(PR_FALSE),
mFilter(filter), mClosure(closure)
{
NS_INIT_REFCNT();
mCurKey = startKey;
mChildIndex = -1;
mThread = thread;
NS_ADDREF(thread);
}
nsMsgThreadEnumerator::~nsMsgThreadEnumerator()
{
NS_RELEASE(mThread);
}
NS_IMPL_ISUPPORTS(nsMsgThreadEnumerator, nsIEnumerator::GetIID())
NS_IMETHODIMP nsMsgThreadEnumerator::First(void)
{
nsresult rv = 0;
if (!mThread)
return NS_ERROR_NULL_POINTER;
return Next();
}
NS_IMETHODIMP nsMsgThreadEnumerator::Next(void)
{
nsresult rv;
if (mCurKey == nsMsgKey_None)
{
rv = mThread->GetChildHdrAt(0, &mResultHdr);
mChildIndex = 0;
}
else
{
rv = mThread->GetChildHdrAt(mChildIndex++, &mResultHdr);
}
if (!mResultHdr)
{
mDone = PR_TRUE;
return NS_RDF_CURSOR_EMPTY;
}
if (NS_FAILED(rv))
{
mDone = PR_TRUE;
return rv;
}
return rv;
}
NS_IMETHODIMP nsMsgThreadEnumerator::CurrentItem(nsISupports **aItem)
{
if (mResultHdr) {
*aItem = mResultHdr;
NS_ADDREF(mResultHdr);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP nsMsgThreadEnumerator::IsDone(void)
{
return mDone ? NS_OK : NS_COMFALSE;
}
NS_IMETHODIMP nsMsgThread::EnumerateMessages(nsMsgKey parentKey, nsIEnumerator* *result)
{
nsresult ret = NS_OK;
nsMsgThreadEnumerator* e = new nsMsgThreadEnumerator(this, parentKey, nsnull, nsnull);
if (e == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(e);
*result = e;
return NS_OK;
return ret;
}
nsresult nsMsgThread::ChangeChildCount(PRInt32 delta)
{
nsresult ret = NS_OK;