mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-03 18:47:53 +00:00
Un-hardcoded column info. This is now provided by a resource: RDF file (like LocalStore.rdf).
This commit is contained in:
parent
b455e672a8
commit
c5203f3f54
@ -45,7 +45,7 @@ static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
||||
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
|
||||
static const char kURI_bookmarks[] = "rdf:bookmarks"; // XXX?
|
||||
static const char kURINC_BookmarksRoot[] = "NC:BookmarksRoot"; // XXX?
|
||||
|
||||
#define NC_NAMESPACE_URI "http://home.netscape.com/NC-rdf#"
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child);
|
||||
@ -55,13 +55,6 @@ DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Folder);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Name);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, PersonalToolbarFolderCategory);
|
||||
|
||||
// XXX these are here until we can undo the hard-coding of the column
|
||||
// info in the data source. See BookmarkParser::AddColumns() for more
|
||||
// info.
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Column);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Columns);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Title);
|
||||
|
||||
|
||||
#define WEB_NAMESPACE_URI "http://home.netscape.com/WEB-rdf#"
|
||||
DEFINE_RDF_VOCAB(WEB_NAMESPACE_URI, WEB, LastVisitDate);
|
||||
@ -117,8 +110,6 @@ protected:
|
||||
const nsString& predicateURI,
|
||||
const nsString& time);
|
||||
|
||||
nsresult AddColumns(void);
|
||||
|
||||
public:
|
||||
BookmarkParser(void);
|
||||
~BookmarkParser();
|
||||
@ -175,7 +166,6 @@ BookmarkParser::Parse(PRFileDesc* file, nsIRDFDataSource* dataSource)
|
||||
mLastItem = nsnull;
|
||||
mLine.Truncate();
|
||||
|
||||
nsresult rv;
|
||||
char buf[1024];
|
||||
PRInt32 len;
|
||||
|
||||
@ -183,75 +173,10 @@ BookmarkParser::Parse(PRFileDesc* file, nsIRDFDataSource* dataSource)
|
||||
Tokenize(buf, len);
|
||||
|
||||
NS_IF_RELEASE(mLastItem);
|
||||
|
||||
rv = AddColumns();
|
||||
return rv;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
BookmarkParser::AddColumns(void)
|
||||
{
|
||||
// XXX this is unsavory. I really don't like hard-coding the
|
||||
// columns that should be displayed here. What we should do is
|
||||
// merge in a "style" graph that contains just a wee bit of
|
||||
// information about columns, etc.
|
||||
nsresult rv;
|
||||
|
||||
nsIRDFResource* columns = nsnull;
|
||||
|
||||
static const char* gColumnTitles[] = {
|
||||
"Name",
|
||||
"Date Added",
|
||||
"Last Visited",
|
||||
"Last Modified",
|
||||
nsnull
|
||||
};
|
||||
|
||||
static const char* gColumnURIs[] = {
|
||||
kURINC_Name,
|
||||
kURINC_BookmarkAddDate,
|
||||
kURIWEB_LastVisitDate,
|
||||
kURIWEB_LastModifiedDate,
|
||||
nsnull
|
||||
};
|
||||
|
||||
const char* const* columnTitle = gColumnTitles;
|
||||
const char* const* columnURI = gColumnURIs;
|
||||
|
||||
if (NS_FAILED(rv = rdf_CreateAnonymousResource(mRDFService, &columns)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = rdf_MakeSeq(mRDFService, mDataSource, columns)))
|
||||
goto done;
|
||||
|
||||
while (*columnTitle && *columnURI) {
|
||||
nsIRDFResource* column = nsnull;
|
||||
|
||||
if (NS_SUCCEEDED(rv = rdf_CreateAnonymousResource(mRDFService, &column))) {
|
||||
rdf_Assert(mRDFService, mDataSource, column, kURINC_Title, *columnTitle);
|
||||
rdf_Assert(mRDFService, mDataSource, column, kURINC_Column, *columnURI);
|
||||
|
||||
rdf_ContainerAddElement(mRDFService, mDataSource, columns, column);
|
||||
NS_IF_RELEASE(column);
|
||||
}
|
||||
|
||||
++columnTitle;
|
||||
++columnURI;
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
}
|
||||
|
||||
rdf_Assert(mRDFService, mDataSource, kURI_bookmarks, kURINC_Columns, columns);
|
||||
|
||||
done:
|
||||
NS_IF_RELEASE(columns);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
BookmarkParser::Tokenize(const char* buf, PRInt32 size)
|
||||
{
|
||||
@ -291,7 +216,7 @@ BookmarkParser::NextToken(void)
|
||||
if (mStack.Count() > 0) {
|
||||
// a regular old folder
|
||||
|
||||
nsAutoString folderURI(kURI_bookmarks);
|
||||
nsAutoString folderURI(kURINC_BookmarksRoot);
|
||||
folderURI.Append('#');
|
||||
folderURI.Append(++mCounter, 10);
|
||||
|
||||
@ -303,7 +228,7 @@ BookmarkParser::NextToken(void)
|
||||
}
|
||||
else {
|
||||
// it's the root
|
||||
if (NS_FAILED(mRDFService->GetResource(kURI_bookmarks, &folder)))
|
||||
if (NS_FAILED(mRDFService->GetResource(kURINC_BookmarksRoot, &folder)))
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// RDF property & resource declarations
|
||||
|
||||
static const char kURIMailRoot[] = "MailRoot";
|
||||
static const char kURINC_MailRoot[] = "NC:MailRoot";
|
||||
|
||||
#define NC_NAMESPACE_URI "http://home.netscape.com/NC-rdf#"
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child);
|
||||
@ -233,9 +233,6 @@ MailDataSource::Init(const char* uri)
|
||||
(void**) &mMiscMailData)))
|
||||
return rv;
|
||||
|
||||
if (NS_FAILED(rv = AddColumns()))
|
||||
return rv;
|
||||
|
||||
gRDFService->GetResource(kURINC_child, &mResourceChild);
|
||||
gRDFService->GetResource(kURINC_Folder, &mResourceFolder);
|
||||
gRDFService->GetResource(kURINC_from, &mResourceFrom);
|
||||
@ -246,7 +243,7 @@ MailDataSource::Init(const char* uri)
|
||||
gRDFService->GetResource(kURINC_account, &mResourceAccount);
|
||||
gRDFService->GetResource(kURINC_Name, &mResourceName);
|
||||
gRDFService->GetResource(kURINC_Columns, &mResourceColumns);
|
||||
gRDFService->GetResource(kURIMailRoot, &mMailRoot);
|
||||
gRDFService->GetResource(kURINC_MailRoot, &mMailRoot);
|
||||
|
||||
if (NS_FAILED(rv = InitAccountList()))
|
||||
return rv;
|
||||
@ -472,66 +469,6 @@ MailDataSource::InitAccountList(void)
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
MailDataSource::AddColumns(void)
|
||||
{
|
||||
// XXX this is unsavory. I really don't like hard-coding the
|
||||
// columns that should be displayed here. What we should do is
|
||||
// merge in a "style" graph that contains just a wee bit of
|
||||
// information about columns, etc.
|
||||
nsresult rv;
|
||||
|
||||
nsIRDFResource* columns = nsnull;
|
||||
|
||||
static const char* gColumnTitles[] = {
|
||||
"subject",
|
||||
"date",
|
||||
"from",
|
||||
nsnull
|
||||
};
|
||||
|
||||
static const char* gColumnURIs[] = {
|
||||
kURINC_subject,
|
||||
kURINC_date,
|
||||
kURINC_from,
|
||||
nsnull
|
||||
};
|
||||
|
||||
const char* const* columnTitle = gColumnTitles;
|
||||
const char* const* columnURI = gColumnURIs;
|
||||
|
||||
if (NS_FAILED(rv = rdf_CreateAnonymousResource(gRDFService, &columns)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = rdf_MakeSeq(gRDFService, mMiscMailData, columns)))
|
||||
goto done;
|
||||
|
||||
while (*columnTitle && *columnURI) {
|
||||
nsIRDFResource* column = nsnull;
|
||||
|
||||
if (NS_SUCCEEDED(rv = rdf_CreateAnonymousResource(gRDFService, &column))) {
|
||||
rdf_Assert(gRDFService, mMiscMailData, column, kURINC_Title, *columnTitle);
|
||||
rdf_Assert(gRDFService, mMiscMailData, column, kURINC_Column, *columnURI);
|
||||
|
||||
rdf_ContainerAddElement(gRDFService, mMiscMailData, columns, column);
|
||||
NS_IF_RELEASE(column);
|
||||
}
|
||||
|
||||
++columnTitle;
|
||||
++columnURI;
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
}
|
||||
|
||||
rdf_Assert(gRDFService, mMiscMailData, kURIMailRoot, kURINC_Columns, columns);
|
||||
|
||||
done:
|
||||
NS_IF_RELEASE(columns);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user