mirror of https://github.com/kiwix/libkiwix.git
+ 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:
parent
bf58cf6b76
commit
97548d4798
|
@ -197,7 +197,8 @@ namespace kiwix {
|
||||||
return library.current;
|
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;
|
kiwix::Book book;
|
||||||
|
|
||||||
if (this->readBookFromPath(pathToOpen, book)) {
|
if (this->readBookFromPath(pathToOpen, book)) {
|
||||||
|
@ -212,13 +213,18 @@ namespace kiwix {
|
||||||
(checkMetaData && !book.title.empty() && !book.language.empty() && !book.date.empty())) {
|
(checkMetaData && !book.title.empty() && !book.language.empty() && !book.date.empty())) {
|
||||||
book.url = url;
|
book.url = url;
|
||||||
library.addBook(book);
|
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) {
|
bool Manager::readBookFromPath(const string path, kiwix::Book &book) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -337,7 +343,8 @@ namespace kiwix {
|
||||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
if ( itr->id == id) {
|
if ( itr->id == id) {
|
||||||
itr->indexPath = path;
|
itr->indexPath = path;
|
||||||
itr->indexPathAbsolute = path;
|
itr->indexPathAbsolute = isRelativePath(path) ?
|
||||||
|
computeAbsolutePath(removeLastPathElement(writableLibraryPath, true, false), path) : path;
|
||||||
itr->indexType = type;
|
itr->indexType = type;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -351,7 +358,8 @@ namespace kiwix {
|
||||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
if ( itr->id == id) {
|
if ( itr->id == id) {
|
||||||
itr->path = path;
|
itr->path = path;
|
||||||
itr->pathAbsolute = path;
|
itr->pathAbsolute = isRelativePath(path) ?
|
||||||
|
computeAbsolutePath(removeLastPathElement(writableLibraryPath, true, false), path) : path;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,10 @@ namespace kiwix {
|
||||||
bool setBookIndex(const string id, const string path, const supportedIndexType type);
|
bool setBookIndex(const string id, const string path, const supportedIndexType type);
|
||||||
bool setBookPath(const string id, const string path);
|
bool setBookPath(const string id, const string path);
|
||||||
string getCurrentBookId();
|
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();
|
Library cloneLibrary();
|
||||||
bool getBookById(const string id, Book &book);
|
bool getBookById(const string id, Book &book);
|
||||||
unsigned int getBookCount(const bool localBooks, const bool remoteBooks);
|
unsigned int getBookCount(const bool localBooks, const bool remoteBooks);
|
||||||
|
|
Loading…
Reference in New Issue