continued work on contentManager lib

This commit is contained in:
reg_ 2011-10-29 16:22:04 +00:00
parent 8d192f634e
commit 5f42ef4272
3 changed files with 163 additions and 172 deletions

View File

@ -91,53 +91,42 @@ bool ContentManager::AddBookFromPath(string &path) {
return false; return false;
} }
/*bool ContentManager::RemoveBookById(const char* &id, bool *retVal) { bool ContentManager::RemoveBookById(string &id) {
*retVal = PR_FALSE;
const char *cid; try {
NS_CStringGetData(id, &cid); return this->manager.removeBookById(id.c_str());
} catch (exception &e) {
try { cerr << e.what() << endl;
if (this->manager.removeBookById(cid)) { return false;
*retVal = PR_TRUE;
} }
} catch (exception &e) { return false;
cerr << e.what() << endl;
}
return NS_OK;
} }
bool ContentManager::SetCurrentBookId(const char* &id, bool *retVal) { bool ContentManager::SetCurrentBookId(string &id) {
*retVal = PR_FALSE;
const char *cid; try {
NS_CStringGetData(id, &cid); return this->manager.setCurrentBookId(id.c_str());
} catch (exception &e) {
try { cerr << e.what() << endl;
if (this->manager.setCurrentBookId(cid)) { return false;
*retVal = PR_TRUE;
} }
} catch (exception &e) {
cerr << e.what() << endl; return false;
} }
return NS_OK; string ContentManager::GetCurrentBookId() {
string none = "";
try {
return this->manager.getCurrentBookId();
} catch (exception &e) {
cerr << e.what() << endl;
return none;
}
return none;
} }
bool ContentManager::GetCurrentBookId(char* &id, bool *retVal) { /*bool ContentManager::GetBookById(const char* &id,
*retVal = PR_FALSE;
try {
string current = this->manager.getCurrentBookId();
id = nsDependentCString(current.data(), current.size());
*retVal = PR_TRUE;
} catch (exception &e) {
cerr << e.what() << endl;
}
return NS_OK;
}
bool ContentManager::GetBookById(const char* &id,
char* &path, char* &path,
char* &title, char* &title,
char* &indexPath, char* &indexPath,
@ -193,38 +182,33 @@ bool ContentManager::GetBookById(const char* &id,
} }
return NS_OK; return NS_OK;
} }*/
bool ContentManager::UpdateBookLastOpenDateById(const char* &id, bool *retVal) { bool ContentManager::UpdateBookLastOpenDateById(string &id) {
*retVal = PR_FALSE; try {
const char *cid; return this->manager.updateBookLastOpenDateById(id.c_str());
NS_CStringGetData(id, &cid); } catch (exception &e) {
cerr << e.what() << endl;
try { return false;
if (this->manager.updateBookLastOpenDateById(cid)) {
*retVal = PR_TRUE;
} }
} catch (exception &e) {
cerr << e.what() << endl; return false;
}
return NS_OK;
} }
bool ContentManager::GetBookCount(const bool localBooks, const bool remoteBooks, PRUint32 *count, bool *retVal) { unsigned int ContentManager::GetBookCount(const bool localBooks, const bool remoteBooks) {
*retVal = PR_TRUE; int count = 0;
*count = 0;
try { try {
*count = this->manager.getBookCount(localBooks, remoteBooks); return this->manager.getBookCount(localBooks, remoteBooks);
} catch (exception &e) { } catch (exception &e) {
cerr << e.what() << endl; cerr << e.what() << endl;
} return count;
}
return NS_OK; return count;
} }
bool ContentManager::ListBooks(const char* &mode, const char* &sortBy, PRUint32 maxSize, /*bool ContentManager::ListBooks(const char* &mode, const char* &sortBy, PRUint32 maxSize,
const char* &language, const char* &publisher, const char* &search, bool *retVal) { const char* &language, const char* &publisher, const char* &search, bool *retVal) {
*retVal = PR_FALSE; *retVal = PR_FALSE;
const char *cmode; NS_CStringGetData(mode, &cmode); const char *cmode; NS_CStringGetData(mode, &cmode);
@ -265,100 +249,69 @@ bool ContentManager::ListBooks(const char* &mode, const char* &sortBy, PRUint32
} }
return NS_OK;
}
bool ContentManager::GetListNextBookId(char* &id, bool *retVal) {
*retVal = PR_FALSE;
try {
if (!this->manager.bookIdList.empty()) {
string idString = *(this->manager.bookIdList.begin());
id = nsDependentCString(idString.data(), idString.size());
this->manager.bookIdList.erase(this->manager.bookIdList.begin());
*retVal = PR_TRUE;
}
} catch (exception &e) {
cerr << e.what() << endl;
}
return NS_OK;
}
bool ContentManager::SetBookIndex(const char* &id, const string &path, const char* &indexType, bool *retVal) {
*retVal = PR_FALSE;
const char *cid;
NS_CStringGetData(id, &cid);
const char *cindexType;
NS_CStringGetData(indexType, &cindexType);
const char *pathToSave = strdup(nsStringToUTF8(path));
try {
kiwix::supportedIndexType iType;
if (std::string(cindexType) == "clucene") {
iType = kiwix::CLUCENE;
} else {
iType = kiwix::XAPIAN;
}
if (this->manager.setBookIndex(cid, pathToSave, iType)) {
*retVal = PR_TRUE;
}
} catch (exception &e) {
cerr << e.what() << endl;
}
free((void*)pathToSave);
return NS_OK;
}
bool ContentManager::SetBookPath(const char* &id, const string &path, bool *retVal) {
*retVal = PR_FALSE;
const char *cid;
NS_CStringGetData(id, &cid);
const char *pathToSave = strdup(nsStringToUTF8(path));
try {
if (this->manager.setBookPath(cid, pathToSave)) {
*retVal = PR_TRUE;
}
} catch (exception &e) {
cerr << e.what() << endl;
}
free((void*)pathToSave);
return NS_OK;
}
bool ContentManager::GetBooksLanguages(char* &languages, bool *retVal) {
*retVal = PR_TRUE;
string languagesStr = "";
vector<string> booksLanguages = this->manager.getBooksLanguages();
vector<string>::iterator itr;
for ( itr = booksLanguages.begin(); itr != booksLanguages.end(); ++itr ) {
languagesStr += *itr + ";";
}
languages = nsDependentCString(languagesStr.data(), languagesStr.size());
return NS_OK;
}
bool ContentManager::GetBooksPublishers(char* &publishers, bool *retVal) {
*retVal = PR_TRUE;
string publishersStr = "";
vector<string> booksPublishers = this->manager.getBooksPublishers();
vector<string>::iterator itr;
for ( itr = booksPublishers.begin(); itr != booksPublishers.end(); ++itr ) {
publishersStr += *itr + ";";
}
publishers = nsDependentCString(publishersStr.data(), publishersStr.size());
return NS_OK; return NS_OK;
}*/ }*/
const char* ContentManager::GetListNextBookId() {
string id;
try {
if (!this->manager.bookIdList.empty()) {
id = *(this->manager.bookIdList.begin());
this->manager.bookIdList.erase(this->manager.bookIdList.begin());
}
} catch (exception &e) {
cerr << e.what() << endl;
}
return id.c_str();
}
bool ContentManager::SetBookIndex(string &id, string &path, string &indexType) {
try {
kiwix::supportedIndexType iType;
if (indexType == "clucene") {
iType = kiwix::CLUCENE;
} else {
iType = kiwix::XAPIAN;
}
return this->manager.setBookIndex(id.c_str(), path.c_str(), iType);
} catch (exception &e) {
cerr << e.what() << endl;
return false;
}
return false;
}
bool ContentManager::SetBookPath(string &id, string &path) {
try {
return this->manager.setBookPath(id.c_str(), path.c_str());
} catch (exception &e) {
cerr << e.what() << endl;
return false;
}
return false;
}
string ContentManager::GetBooksLanguages() {
string languagesStr = "";
vector<string> booksLanguages = this->manager.getBooksLanguages();
vector<string>::iterator itr;
for ( itr = booksLanguages.begin(); itr != booksLanguages.end(); ++itr ) {
languagesStr += *itr + ";";
}
return languagesStr;
}
string ContentManager::GetBooksPublishers() {
string publishersStr = "";
vector<string> booksPublishers = this->manager.getBooksPublishers();
vector<string>::iterator itr;
for ( itr = booksPublishers.begin(); itr != booksPublishers.end(); ++itr ) {
publishersStr += *itr + ";";
}
return publishersStr;
}

View File

@ -16,22 +16,22 @@ class ContentManager
bool WriteLibrary(); bool WriteLibrary();
bool WriteLibraryToFile(string&); bool WriteLibraryToFile(string&);
bool AddBookFromPath(string&); bool AddBookFromPath(string&);
/*bool RemoveBookById(string); bool RemoveBookById(string&);
bool GetBookById(string, string, string, bool SetCurrentBookId(string&);
string GetCurrentBookId();
/*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 SetCurrentBookId(string); bool UpdateBookLastOpenDateById(string&);
bool GetCurrentBookId(string); unsigned int GetBookCount(bool, bool);
bool GetListNextBookId(string); const char* GetListNextBookId();
bool SetBookIndex(string, string, string); bool SetBookIndex(string&, string&, string&);
bool SetBookPath(string, string); bool SetBookPath(string&, string&);
bool UpdateBookLastOpenDateById(string); string GetBooksLanguages();
bool ListBooks(string, string, unsigned int, string, string, string); string GetBooksPublishers();
bool GetBookCount(bool, bool, unsigned int); //bool ListBooks(string, string, unsigned int, string, string, string);
bool GetBooksLanguages(string);
bool GetBooksPublishers(string);*/
protected: protected:
kiwix::Manager manager; kiwix::Manager manager;

View File

@ -66,6 +66,44 @@ int main(int argc, char* argv[])
else else
cout << "Unable to write library to " << lpath << endl; cout << "Unable to write library to " << lpath << endl;
string bookid = "57b0b7c3-25a5-431e-431e-dce1771ee052963f";
/*if (cont->RemoveBookById(bookid))
cout << "Successfully removed book " << bookid << endl;
else
cout << "Unable to remove book " << bookid << endl;*/
if (cont->SetCurrentBookId(bookid))
cout << "Successfully set current book " << bookid << endl;
else
cout << "Unable to set current book " << bookid << endl;
cout << "Current Book ID: " << cont->GetCurrentBookId() << endl;
if (cont->UpdateBookLastOpenDateById(bookid))
cout << "Successfully updated last open date for book " << bookid << endl;
else
cout << "Unable to update last open date for book " << bookid << endl;
cout << "Total book count: " << cont->GetBookCount(true, true) << endl;
cout << "Next Book: " << cont->GetListNextBookId() << endl;
string indexPath = "/home/reg/wksw.index";
string indexMethod = "xapian";
if (cont->SetBookIndex(bookid, indexPath, indexMethod))
cout << "Successfully set index for book " << bookid << endl;
else
cout << "Unable to set index for book " << bookid << endl;
if (cont->SetBookPath(bookid, zimPath))
cout << "Successfully set path for book " << bookid << endl;
else
cout << "Unable to set path for book " << bookid << endl;
cout << "Languages: " << cont->GetBooksLanguages() << endl;
cout << "Publishers: " << cont->GetBooksPublishers() << endl;
cont->WriteLibraryToFile(lpath); cont->WriteLibraryToFile(lpath);
delete cont; delete cont;