Added a couple of utility files for our RDF datasources with functions and declarations

that can be used by all.
This commit is contained in:
putterman%netscape.com 1999-04-20 18:15:16 +00:00
Родитель f22482f1a6
Коммит b9a24dabe4
9 изменённых файлов: 175 добавлений и 215 удалений

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

@ -55,6 +55,7 @@ CPPSRCS = \
nsMsgFolderDataSource.cpp \
nsMsgMessageDataSource.cpp \
nsMessageViewDataSource.cpp \
nsMsgRDFUtils.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a static lib.

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

@ -42,6 +42,7 @@ CPPSRCS= \
nsMsgAccount.cpp \
nsMsgFolderDataSource.cpp \
nsMsgMessageDataSource.cpp \
nsMsgRDFUtils.obj \
$(NULL)
@ -62,6 +63,7 @@ CPP_OBJS= \
.\$(OBJDIR)\nsMsgAccount.obj \
.\$(OBJDIR)\nsMsgFolderDataSource.obj \
.\$(OBJDIR)\nsMsgMessageDataSource.obj \
.\$(OBJDIR)\nsMsgRDFUtils.obj \
$(NULL)

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

@ -21,6 +21,7 @@
#include "nsRDFCID.h"
#include "nsIServiceManager.h"
#include "nsXPIDLString.h"
#include "nsMsgRDFUtils.h"
#include "plstr.h"
@ -41,13 +42,6 @@ nsIRDFResource* nsMessageViewDataSource::kNC_Sender;
nsIRDFResource* nsMessageViewDataSource::kNC_Date;
nsIRDFResource* nsMessageViewDataSource::kNC_Status;
#define NC_NAMESPACE_URI "http://home.netscape.com/NC-rdf#"
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, MessageChild);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Subject);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Sender);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Date);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Status);
NS_IMPL_ADDREF(nsMessageViewDataSource)
NS_IMPL_RELEASE(nsMessageViewDataSource)

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

@ -21,6 +21,8 @@
#include "nsMsgFolderDataSource.h"
#include "nsMsgFolderFlags.h"
#include "nsMsgFolder.h"
#include "nsMsgRDFUtils.h"
#include "rdf.h"
#include "nsIRDFService.h"
@ -32,14 +34,6 @@
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
// this is used for notification of observers using nsVoidArray
typedef struct _nsMsgRDFNotification {
nsIRDFResource *subject;
nsIRDFResource *property;
nsIRDFNode *object;
} nsMsgRDFNotification;
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
@ -61,89 +55,7 @@ nsIRDFResource* nsMsgFolderDataSource::kNC_TotalUnreadMessages;
nsIRDFResource* nsMsgFolderDataSource::kNC_Delete;
nsIRDFResource* nsMsgFolderDataSource::kNC_NewFolder;
#define NC_NAMESPACE_URI "http://home.netscape.com/NC-rdf#"
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, MessageChild);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Name);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Folder);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, SpecialFolder);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, TotalMessages);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, TotalUnreadMessages);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Delete);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, NewFolder);
////////////////////////////////////////////////////////////////////////
// Utilities
static PRBool
peq(nsIRDFResource* r1, nsIRDFResource* r2)
{
PRBool result;
if (NS_SUCCEEDED(r1->EqualsResource(r2, &result)) && result) {
return PR_TRUE;
} else {
return PR_FALSE;
}
}
static PRBool
peqSort(nsIRDFResource* r1, nsIRDFResource* r2, PRBool *isSort)
{
if(!isSort)
return PR_FALSE;
char *r1Str, *r2Str;
nsString r1nsStr, r2nsStr, r1nsSortStr;
r1->GetValue(&r1Str);
r2->GetValue(&r2Str);
r1nsStr = r1Str;
r2nsStr = r2Str;
r1nsSortStr = r1Str;
delete[] r1Str;
delete[] r2Str;
//probably need to not assume this will always come directly after property.
r1nsSortStr +="?sort=true";
if(r1nsStr == r2nsStr)
{
*isSort = PR_FALSE;
return PR_TRUE;
}
else if(r1nsSortStr == r2nsStr)
{
*isSort = PR_TRUE;
return PR_TRUE;
}
else
{
//In case the resources are equal but the values are different. I'm not sure if this
//could happen but it is feasible given interface.
*isSort = PR_FALSE;
return(peq(r1, r2));
}
}
void nsMsgFolderDataSource::createNode(nsString& str, nsIRDFNode **node) const
{
nsIRDFLiteral * value;
*node = nsnull;
if(NS_SUCCEEDED(mRDFService->GetLiteral((const PRUnichar*)str, &value))) {
*node = value;
}
}
void nsMsgFolderDataSource::createNode(PRUint32 value, nsIRDFNode **node) const
{
char *valueStr = PR_smprintf("%d", value);
nsString str(valueStr);
createNode(str, node);
PR_smprintf_free(valueStr);
}
nsMsgFolderDataSource::nsMsgFolderDataSource():
mURI(nsnull),

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

@ -129,25 +129,18 @@ protected:
nsIRDFNode *object, PRBool assert);
nsresult GetSenderName(nsAutoString& sender, nsAutoString *senderUserName);
void createNode(nsString& str, nsIRDFNode **node) const;
void createNode(PRUint32 value, nsIRDFNode **node) const;
nsresult createFolderNode(nsIMsgFolder *folder, nsIRDFResource* property,
nsresult createFolderNode(nsIMsgFolder *folder, nsIRDFResource* property,
nsIRDFNode **target);
nsresult createFolderNameNode(nsIMsgFolder *folder, nsIRDFNode **target);
nsresult createFolderSpecialNode(nsIMsgFolder *folder, nsIRDFNode **target);
nsresult createFolderNameNode(nsIMsgFolder *folder, nsIRDFNode **target);
nsresult createFolderSpecialNode(nsIMsgFolder *folder, nsIRDFNode **target);
nsresult createTotalMessagesNode(nsIMsgFolder *folder, nsIRDFNode **target);
nsresult createUnreadMessagesNode(nsIMsgFolder *folder, nsIRDFNode **target);
nsresult createFolderChildNode(nsIMsgFolder *folder, nsIRDFNode **target);
nsresult createFolderMessageNode(nsIMsgFolder *folder, nsIRDFNode **target);
nsresult createFolderChildNode(nsIMsgFolder *folder, nsIRDFNode **target);
nsresult createFolderMessageNode(nsIMsgFolder *folder, nsIRDFNode **target);
nsresult createMessageNode(nsIMessage *message, nsIRDFResource *property,
nsresult createMessageNode(nsIMessage *message, nsIRDFResource *property,
nsIRDFNode **target);
static nsresult getMessageArcLabelsOut(nsIMessage *message,
nsISupportsArray **arcs);
static nsresult getFolderArcLabelsOut(nsIMsgFolder *folder,
nsISupportsArray **arcs);

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

@ -19,39 +19,15 @@
#include "msgCore.h" // precompiled header...
#include "nsMsgMessageDataSource.h"
//#include "prlog.h"
#include "nsMsgRDFUtils.h"
#include "nsIRDFService.h"
//#include "nsIServiceManager.h"
#include "nsRDFCID.h"
#include "rdf.h"
//#include "nsIRDFResourceFactory.h"
//#include "nsIRDFObserver.h"
//#include "nsIRDFNode.h"
//#include "plstr.h"
//#include "prmem.h"
//#include "prio.h"
//#include "prprf.h"
//#include "nsString.h"
//#include "nsIMsgFolder.h"
//#include "nsISupportsArray.h"
//#include "nsFileSpec.h"
//#include "nsMsgFolderFlags.h"
#include "nsRDFCursorUtils.h"
#include "nsIMessage.h"
//#include "nsMsgFolder.h"
//#include "nsIMsgHeaderParser.h"
//#include "nsMsgBaseCID.h"
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
// this is used for notification of observers using nsVoidArray
typedef struct _nsMsgRDFNotification {
nsIRDFResource *subject;
nsIRDFResource *property;
nsIRDFNode *object;
} nsMsgRDFNotification;
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kMsgHeaderParserCID, NS_MSGHEADERPARSER_CID);
@ -69,85 +45,7 @@ nsIRDFResource* nsMsgMessageDataSource::kNC_Date;
nsIRDFResource* nsMsgMessageDataSource::kNC_Status;
#define NC_NAMESPACE_URI "http://home.netscape.com/NC-rdf#"
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Subject);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Sender);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Date);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Status);
////////////////////////////////////////////////////////////////////////
// Utilities
static PRBool
peq(nsIRDFResource* r1, nsIRDFResource* r2)
{
PRBool result;
if (NS_SUCCEEDED(r1->EqualsResource(r2, &result)) && result) {
return PR_TRUE;
} else {
return PR_FALSE;
}
}
static PRBool
peqSort(nsIRDFResource* r1, nsIRDFResource* r2, PRBool *isSort)
{
if(!isSort)
return PR_FALSE;
char *r1Str, *r2Str;
nsString r1nsStr, r2nsStr, r1nsSortStr;
r1->GetValue(&r1Str);
r2->GetValue(&r2Str);
r1nsStr = r1Str;
r2nsStr = r2Str;
r1nsSortStr = r1Str;
delete[] r1Str;
delete[] r2Str;
//probably need to not assume this will always come directly after property.
r1nsSortStr +="?sort=true";
if(r1nsStr == r2nsStr)
{
*isSort = PR_FALSE;
return PR_TRUE;
}
else if(r1nsSortStr == r2nsStr)
{
*isSort = PR_TRUE;
return PR_TRUE;
}
else
{
//In case the resources are equal but the values are different. I'm not sure if this
//could happen but it is feasible given interface.
*isSort = PR_FALSE;
return(peq(r1, r2));
}
}
void nsMsgMessageDataSource::createNode(nsString& str, nsIRDFNode **node) const
{
nsIRDFLiteral * value;
*node = nsnull;
if(NS_SUCCEEDED(mRDFService->GetLiteral((const PRUnichar*)str, &value))) {
*node = value;
}
}
void nsMsgMessageDataSource::createNode(PRUint32 value, nsIRDFNode **node) const
{
char *valueStr = PR_smprintf("%d", value);
nsString str(valueStr);
createNode(str, node);
PR_smprintf_free(valueStr);
}
nsMsgMessageDataSource::nsMsgMessageDataSource():
mURI(nsnull),

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

@ -113,8 +113,6 @@ protected:
nsresult GetSenderName(nsAutoString& sender, nsAutoString *senderUserName);
void createNode(nsString& str, nsIRDFNode **node) const;
void createNode(PRUint32 value, nsIRDFNode **node) const;
nsresult createMessageNode(nsIMessage *message, nsIRDFResource *property,
nsIRDFNode **target);

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

@ -0,0 +1,97 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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.
*/
#include "nsMsgRDFUtils.h"
#include "nsIRDFService.h"
#include "nsRDFCID.h"
#include "nsIServiceManager.h"
#include "prprf.h"
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
PRBool
peq(nsIRDFResource* r1, nsIRDFResource* r2)
{
PRBool result;
if (NS_SUCCEEDED(r1->EqualsResource(r2, &result)) && result) {
return PR_TRUE;
} else {
return PR_FALSE;
}
}
PRBool
peqSort(nsIRDFResource* r1, nsIRDFResource* r2, PRBool *isSort)
{
if(!isSort)
return PR_FALSE;
char *r1Str, *r2Str;
nsString r1nsStr, r2nsStr, r1nsSortStr;
r1->GetValue(&r1Str);
r2->GetValue(&r2Str);
r1nsStr = r1Str;
r2nsStr = r2Str;
r1nsSortStr = r1Str;
delete[] r1Str;
delete[] r2Str;
//probably need to not assume this will always come directly after property.
r1nsSortStr +="?sort=true";
if(r1nsStr == r2nsStr)
{
*isSort = PR_FALSE;
return PR_TRUE;
}
else if(r1nsSortStr == r2nsStr)
{
*isSort = PR_TRUE;
return PR_TRUE;
}
else
{
//In case the resources are equal but the values are different. I'm not sure if this
//could happen but it is feasible given interface.
*isSort = PR_FALSE;
return(peq(r1, r2));
}
}
void createNode(nsString& str, nsIRDFNode **node)
{
*node = nsnull;
nsresult rv;
NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv);
if (NS_FAILED(rv)) return; // always check this before proceeding
nsIRDFLiteral * value;
if(NS_SUCCEEDED(rdf->GetLiteral((const PRUnichar*)str, &value))) {
*node = value;
}
}
void createNode(PRUint32 value, nsIRDFNode **node)
{
char *valueStr = PR_smprintf("%d", value);
nsString str(valueStr);
createNode(str, node);
PR_smprintf_free(valueStr);
}

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

@ -0,0 +1,65 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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.
*/
//This file holds some useful utility functions and declarations used by our datasources.
#include "rdf.h"
#include "nsIRDFNode.h"
#include "nsString.h"
// this is used for notification of observers using nsVoidArray
typedef struct _nsMsgRDFNotification {
nsIRDFResource *subject;
nsIRDFResource *property;
nsIRDFNode *object;
} nsMsgRDFNotification;
//Some property declarations
#define NC_NAMESPACE_URI "http://home.netscape.com/NC-rdf#"
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Subject);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Sender);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Date);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Status);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, MessageChild);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Name);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Folder);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, SpecialFolder);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, TotalMessages);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, TotalUnreadMessages);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Delete);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, NewFolder);
//Returns PR_TRUE if r1 is equal to r2
PRBool
peq(nsIRDFResource* r1, nsIRDFResource* r2);
//Returns PR_TRUE if r1 is equal to r2 and r2 is the sort property.
PRBool
peqSort(nsIRDFResource* r1, nsIRDFResource* r2, PRBool *isSort);
//Given an nsString, create an nsIRDFNode
void createNode(nsString& str, nsIRDFNode **node);
//Given a PRUint32, create an nsiIRDFNode.
void createNode(PRUint32 value, nsIRDFNode **node);