+ better deal by SetIndexBook() and SetBookPath() with relative paths.

+ Add addBookFromPathAndGetId() to know which book id has the added book
This commit is contained in:
kelson42 2011-11-01 15:07:30 +00:00
parent bf58cf6b76
commit 97548d4798
2 changed files with 17 additions and 6 deletions

View File

@ -197,7 +197,8 @@ namespace kiwix {
return library.current;
}
bool Manager::addBookFromPath(const string pathToOpen, const string pathToSave, const string url, const bool checkMetaData) {
/* Add a book to the library. Return empty string if failed, book id otherwise */
string Manager::addBookFromPathAndGetId(const string pathToOpen, const string pathToSave, const string url, const bool checkMetaData) {
kiwix::Book book;
if (this->readBookFromPath(pathToOpen, book)) {
@ -212,13 +213,18 @@ namespace kiwix {
(checkMetaData && !book.title.empty() && !book.language.empty() && !book.date.empty())) {
book.url = url;
library.addBook(book);
return true;
return book.id;
}
}
return false;
return "";
}
/* Wrapper over Manager::addBookFromPath which return a bool instead of a string */
bool Manager::addBookFromPath(const string pathToOpen, const string pathToSave, const string url, const bool checkMetaData) {
return !(this->addBookFromPathAndGetId(pathToOpen, pathToSave, url, checkMetaData).empty());
}
bool Manager::readBookFromPath(const string path, kiwix::Book &book) {
try {
@ -337,7 +343,8 @@ namespace kiwix {
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
if ( itr->id == id) {
itr->indexPath = path;
itr->indexPathAbsolute = path;
itr->indexPathAbsolute = isRelativePath(path) ?
computeAbsolutePath(removeLastPathElement(writableLibraryPath, true, false), path) : path;
itr->indexType = type;
return true;
}
@ -351,7 +358,8 @@ namespace kiwix {
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
if ( itr->id == id) {
itr->path = path;
itr->pathAbsolute = path;
itr->pathAbsolute = isRelativePath(path) ?
computeAbsolutePath(removeLastPathElement(writableLibraryPath, true, false), path) : path;
return true;
}
}

View File

@ -54,7 +54,10 @@ namespace kiwix {
bool setBookIndex(const string id, const string path, const supportedIndexType type);
bool setBookPath(const string id, const string path);
string getCurrentBookId();
bool addBookFromPath(const string pathToOpen, const string pathToSave = "", const string url = "", const bool checkMetaData = false);
string addBookFromPathAndGetId(const string pathToOpen, const string pathToSave = "", const string url = "",
const bool checkMetaData = false);
bool addBookFromPath(const string pathToOpen, const string pathToSave = "", const string url = "",
const bool checkMetaData = false);
Library cloneLibrary();
bool getBookById(const string id, Book &book);
unsigned int getBookCount(const bool localBooks, const bool remoteBooks);