continued work on contentManager lib

This commit is contained in:
reg_ 2011-10-31 09:23:10 +00:00
parent 5f42ef4272
commit e95baea90f
3 changed files with 118 additions and 99 deletions

View File

@ -126,63 +126,60 @@ string ContentManager::GetCurrentBookId() {
return none; return none;
} }
/*bool ContentManager::GetBookById(const char* &id, bool ContentManager::GetBookById(string &id,
char* &path, string &path,
char* &title, string &title,
char* &indexPath, string &indexPath,
char* &indexType, string &indexType,
char* &description, string &description,
char* &articleCount, string &articleCount,
char* &mediaCount, string &mediaCount,
char* &size, string &size,
char* &creator, string &creator,
char* &date, string &date,
char* &language, string &language,
char* &favicon, string &favicon,
char* &url, bool *retVal) { string &url) {
*retVal = PR_FALSE;
const char *cid;
NS_CStringGetData(id, &cid);
try { try {
kiwix::Book book; kiwix::Book book;
if (this->manager.getBookById(cid, book)) { if (this->manager.getBookById(id.c_str(), book)) {
path = nsDependentCString(book.pathAbsolute.data(), book.pathAbsolute.size()); path = book.pathAbsolute.data();
title = nsDependentCString(book.title.data(), book.title.size()); title = book.title.data();
indexPath = nsDependentCString(book.indexPathAbsolute.data(), book.indexPathAbsolute.size()); indexPath = book.indexPathAbsolute.data();
articleCount = nsDependentCString(book.articleCount.data(), book.articleCount.size()); articleCount = book.articleCount.data();
mediaCount = nsDependentCString(book.mediaCount.data(), book.mediaCount.size()); mediaCount = book.mediaCount.data();
size = nsDependentCString(book.size.data(), book.size.size()); size = book.size.data();
creator = nsDependentCString(book.creator.data(), book.creator.size()); creator = book.creator.data();
date = nsDependentCString(book.date.data(), book.date.size()); date = book.date.data();
language = nsDependentCString(book.language.data(), book.language.size()); language = book.language.data();
url = nsDependentCString(book.url.data(), book.url.size()); url = book.url.data();
string faviconUrl = "";
if (!book.faviconMimeType.empty()) {
faviconUrl = "url(data:" + book.faviconMimeType + ";base64," + book.favicon + ")";
}
favicon = nsDependentCString(faviconUrl.data(), faviconUrl.size());
string indexTypeString = ""; string faviconUrl = "";
if (book.indexType == kiwix::XAPIAN) { if (!book.faviconMimeType.empty()) {
indexTypeString = "xapian"; faviconUrl = "url(data:" + book.faviconMimeType + ";base64," + book.favicon + ")";
} else if (book.indexType == kiwix::CLUCENE) { }
indexTypeString = "clucene"; favicon = faviconUrl.data();
}
indexType = nsDependentCString(indexTypeString.data(), indexTypeString.size());
description = nsDependentCString(book.description.data(), book.description.size()); string indexTypeString = "";
if (book.indexType == kiwix::XAPIAN) {
indexTypeString = "xapian";
} else if (book.indexType == kiwix::CLUCENE) {
indexTypeString = "clucene";
}
indexType = indexTypeString.data();
*retVal = PR_TRUE; description = book.description.data();
return true;
}
} catch (exception &e) {
cerr << e.what() << endl;
return false;
} }
} catch (exception &e) { return false;
cerr << e.what() << endl; }
}
return NS_OK;
}*/
bool ContentManager::UpdateBookLastOpenDateById(string &id) { bool ContentManager::UpdateBookLastOpenDateById(string &id) {
try { try {
@ -208,49 +205,39 @@ unsigned int ContentManager::GetBookCount(const bool localBooks, const bool remo
return count; return count;
} }
/*bool ContentManager::ListBooks(const char* &mode, const char* &sortBy, PRUint32 maxSize, bool ContentManager::ListBooks(string &mode, string &sortBy, unsigned int maxSize,
const char* &language, const char* &publisher, const char* &search, bool *retVal) { string &language, string &publisher, string &search) {
*retVal = PR_FALSE; try {
const char *cmode; NS_CStringGetData(mode, &cmode);
const char *csortBy; NS_CStringGetData(sortBy, &csortBy);
const char *clanguage; NS_CStringGetData(language, &clanguage);
const char *cpublisher; NS_CStringGetData(publisher, &cpublisher);
const char *csearch; NS_CStringGetData(search, &csearch);
try { // Set the mode enum
kiwix::supportedListMode listMode;
if (mode == "lastOpen") {
listMode = kiwix::LASTOPEN;
} else if ( mode == "remote") {
listMode = kiwix::REMOTE;
} else {
listMode = kiwix::LOCAL;
}
// Set the mode enum // Set the sortBy enum
kiwix::supportedListMode listMode; kiwix::supportedListSortBy listSortBy;
if (std::string(cmode) == "lastOpen") { if (sortBy == "publisher") {
listMode = kiwix::LASTOPEN; listSortBy = kiwix::PUBLISHER;
} else if ( std::string(cmode) == "remote") { } else if ( sortBy == "date") {
listMode = kiwix::REMOTE; listSortBy = kiwix::DATE;
} else { } else if ( sortBy == "size") {
listMode = kiwix::LOCAL; listSortBy = kiwix::SIZE;
} else {
listSortBy = kiwix::TITLE;
}
return this->manager.listBooks(listMode, listSortBy, maxSize, language.c_str(), publisher.c_str(), search.c_str());
} catch (exception &e) {
cerr << e.what() << endl;
return false;
} }
return false;
// Set the sortBy enum }
kiwix::supportedListSortBy listSortBy;
if (std::string(csortBy) == "publisher") {
listSortBy = kiwix::PUBLISHER;
} else if ( std::string(csortBy) == "date") {
listSortBy = kiwix::DATE;
} else if ( std::string(csortBy) == "size") {
listSortBy = kiwix::SIZE;
} else {
listSortBy = kiwix::TITLE;
}
if (this->manager.listBooks(listMode, listSortBy, maxSize, clanguage, cpublisher, csearch)) {
*retVal = PR_TRUE;
}
} catch (exception &e) {
cerr << e.what() << endl;
}
return NS_OK;
}*/
const char* ContentManager::GetListNextBookId() { const char* ContentManager::GetListNextBookId() {

View File

@ -19,11 +19,11 @@ class ContentManager
bool RemoveBookById(string&); bool RemoveBookById(string&);
bool SetCurrentBookId(string&); bool SetCurrentBookId(string&);
string GetCurrentBookId(); string GetCurrentBookId();
/*bool GetBookById(string, string, string, bool GetBookById(string&, string&, string&,
string, string, string, string&, string&, string&,
string, string, string, string&, string&, string&,
string, string, string, string&, string&, string&,
string, string);*/ string&, string&);
bool UpdateBookLastOpenDateById(string&); bool UpdateBookLastOpenDateById(string&);
unsigned int GetBookCount(bool, bool); unsigned int GetBookCount(bool, bool);
const char* GetListNextBookId(); const char* GetListNextBookId();
@ -31,7 +31,7 @@ class ContentManager
bool SetBookPath(string&, string&); bool SetBookPath(string&, string&);
string GetBooksLanguages(); string GetBooksLanguages();
string GetBooksPublishers(); string GetBooksPublishers();
//bool ListBooks(string, string, unsigned int, string, string, string); bool ListBooks(string&, string&, unsigned int, string&, string&, string&);
protected: protected:
kiwix::Manager manager; kiwix::Manager manager;

View File

@ -86,8 +86,6 @@ int main(int argc, char* argv[])
cout << "Total book count: " << cont->GetBookCount(true, true) << endl; cout << "Total book count: " << cont->GetBookCount(true, true) << endl;
cout << "Next Book: " << cont->GetListNextBookId() << endl;
string indexPath = "/home/reg/wksw.index"; string indexPath = "/home/reg/wksw.index";
string indexMethod = "xapian"; string indexMethod = "xapian";
if (cont->SetBookIndex(bookid, indexPath, indexMethod)) if (cont->SetBookIndex(bookid, indexPath, indexMethod))
@ -104,6 +102,40 @@ int main(int argc, char* argv[])
cout << "Publishers: " << cont->GetBooksPublishers() << endl; cout << "Publishers: " << cont->GetBooksPublishers() << endl;
string id;
string path;
string title;
string rindexPath;
string indexType;
string description;
string articleCount;
string mediaCount;
string size;
string creator;
string date;
string language;
string favicon;
string url;
if (cont->GetBookById(bookid, path, title, rindexPath, indexType, description, articleCount, mediaCount, size, creator, date, language, favicon, url)) {
cout << "Successfully retrieved book " << bookid << endl;
cout << "\ttitle: " << title << endl;
cout << "\tURL: " << url << endl;
cout << "\tarticleCount: " << articleCount << endl;
} else
cout << "Unable to set path for book " << bookid << endl;
string lmode = "lastOpen";
string lsortBy = "size";
unsigned int lmaxSize = 0;
string llanguage = "";
string lpublisher = "";
string lsearch = "";
if (cont->ListBooks(lmode, lsortBy, lmaxSize, llanguage, lpublisher, lsearch)) {
cout << "Successfully listed books" << endl;
cout << "Next Book: " << cont->GetListNextBookId() << endl;
} else
cout << "Unable to list books " << endl;
cont->WriteLibraryToFile(lpath); cont->WriteLibraryToFile(lpath);
delete cont; delete cont;