new nsIMAPGroupRecord

This commit is contained in:
alecf%netscape.com 1999-01-15 00:00:49 +00:00
parent c26be2a26c
commit d66c4dc9d5
3 changed files with 183 additions and 2 deletions

View File

@ -22,10 +22,15 @@ srcdir = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE=nntp
LIBRARY_NAME=nntp
MODULE=imap
LIBRARY_NAME=imap
EXPORTS = \
nsIMAPGroupRecord.h \
$(NULL)
CPPSRCS = \
nsIMAPGroupRecord.cpp \
$(NULL)
include $(topsrcdir)/config/config.mk

View File

@ -0,0 +1,96 @@
/* -*- 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) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsIMAPGroupRecord.h"
#include "plstr.h"
#include "prmem.h"
extern int MSG_GROUPNAME_FLAG_IMAP_NOSELECT;
nsIMAPGroupRecord*
nsIMAPGroupRecord::Create(nsIMAPGroupRecord* parent, const char* folderName,
char delimiter, PRBool filledInGroup, PRBool folderIsNamespace)
{
char* tmp = NULL;
char* partname = NULL;
nsIMAPGroupRecord* result = NULL;
if (folderName)
{
tmp = PL_strdup(folderName);
partname = PL_strrchr(tmp, '/');
if (!partname || !delimiter || folderIsNamespace) // if delimiter == NULL, partname is the full folderName
partname = tmp;
else
partname++;
}
#ifdef DEBUG_slowAndParanoid
if (parent->m_partname) {
char* parentname = parent->GetFullName();
PR_ASSERT(partname > tmp && partname[-1] == m_delimiter);
partname[-1] = '\0';
PR_ASSERT(PL_strcmp(parentname, tmp) == 0);
partname[-1] = m_delimiter;
delete [] parentname;
parentname = NULL;
} else {
PR_ASSERT(partname == tmp);
}
#endif
result = nsIMAPGroupRecord::CreateFromPartname(parent, partname, delimiter, filledInGroup);
if (result) {
result->m_flags = 0;
result->SetFolderIsNamespace(folderIsNamespace);
}
PR_Free(tmp);
return result;
}
nsIMAPGroupRecord*
nsIMAPGroupRecord::CreateFromPartname(nsIMAPGroupRecord* parent, const char* partname, char delimiter, PRBool filledInGroup)
{
nsIMAPGroupRecord* result = new nsIMAPGroupRecord(parent, partname, delimiter, filledInGroup);
if (result && partname && !result->m_partname) {
// We ran out of memory.
delete result;
result = NULL;
}
result->InitializeSibling();
return result;
}
nsIMAPGroupRecord::nsIMAPGroupRecord(nsIMAPGroupRecord* parent,
const char* partname, char delimiter, PRBool filledInGroup) : nsMsgGroupRecord(parent, partname, 0, 0, 0, '/')
{
m_flags = 0;
m_allGrandChildrenDiscovered = PR_FALSE;
m_filledInGroup = filledInGroup;
m_onlineDelimiter = delimiter;
}
PRBool nsIMAPGroupRecord::GetCanToggleSubscribe()
{
return !GetFolderIsNamespace() && !(GetFlags() & MSG_GROUPNAME_FLAG_IMAP_NOSELECT);
}

View File

@ -0,0 +1,80 @@
/* -*- 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) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
// This class should only be used by the subscribe UI and by newshost.cpp.
// And, well, a bit by the category code. Everyone else should use the stuff
// in newshost.h.
#ifndef _nsIMAPGroupRecord_h__
#define _nsIMAPGroupRecord_h__
#include "nsMsgGroupRecord.h"
#include "prlog.h"
class nsIMAPGroupRecord : public nsMsgGroupRecord {
public:
static nsIMAPGroupRecord* Create(nsIMAPGroupRecord* parent,
const char* folderName,
char delimiter,
PRBool filledInGroup,
PRBool folderIsNamespace);
static nsIMAPGroupRecord* CreateFromPartname(nsIMAPGroupRecord* parent, const char* partname, char delimiter,
PRBool filledInGroup);
virtual PRBool IsCategory() { return PR_FALSE;}
virtual PRBool IsCategoryContainer() { return PR_FALSE; }
virtual int SetIsCategoryContainer(PRBool /* value */) { PR_ASSERT(0); return 0; }
virtual PRBool IsIMAPGroupRecord() { return PR_TRUE; }
virtual nsIMAPGroupRecord *GetIMAPGroupRecord() { return this; }
virtual PRBool IsGroup() { return PR_TRUE; }
virtual char GetHierarchySeparator() { return m_onlineDelimiter; }
void SetHierarchySeparator(char delimiter) { m_onlineDelimiter = delimiter; }
PRBool GetAllGrandChildrenDiscovered() { return m_allGrandChildrenDiscovered; }
void SetAllGrandChildrenDiscovered(PRBool discovered) { m_allGrandChildrenDiscovered = discovered; }
PRBool GetIsGroupFilledIn() { return m_filledInGroup; }
void SetIsGroupFilledIn(PRBool filledIn) { m_filledInGroup = filledIn; }
void SetFlags(PRUint32 flags) { m_flags = flags; }
PRUint32 GetFlags() { return m_flags; }
void SetFolderIsNamespace(PRBool isNamespace) { m_folderIsNamespace = isNamespace; }
PRBool GetFolderIsNamespace() { return m_folderIsNamespace; }
PRBool GetCanToggleSubscribe();
protected:
nsIMAPGroupRecord(nsIMAPGroupRecord* parent, const char* partname, char delimiter, PRBool filledInGroup);
PRBool m_allGrandChildrenDiscovered;
PRBool m_filledInGroup;
PRBool m_folderIsNamespace;
char m_onlineDelimiter;
PRUint32 m_flags;
};
#endif