mirror of
https://github.com/kiwix/libkiwix.git
synced 2025-06-28 05:49:35 +00:00
Modified Kiwix-manage to incorporate origID parameter for diff files in the kiwix library.
Book class and Manager class modified. -Kiran
This commit is contained in:
@ -67,6 +67,7 @@ namespace kiwix {
|
|||||||
string publisher;
|
string publisher;
|
||||||
string date;
|
string date;
|
||||||
string url;
|
string url;
|
||||||
|
string origID;
|
||||||
string articleCount;
|
string articleCount;
|
||||||
string mediaCount;
|
string mediaCount;
|
||||||
bool readOnly;
|
bool readOnly;
|
||||||
@ -76,7 +77,7 @@ namespace kiwix {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Library {
|
class Library {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Library();
|
Library();
|
||||||
~Library();
|
~Library();
|
||||||
|
@ -25,19 +25,19 @@ namespace kiwix {
|
|||||||
Manager::Manager() :
|
Manager::Manager() :
|
||||||
writableLibraryPath("") {
|
writableLibraryPath("") {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Destructor */
|
/* Destructor */
|
||||||
Manager::~Manager() {
|
Manager::~Manager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::parseXmlDom(const pugi::xml_document &doc, const bool readOnly, const string libraryPath) {
|
bool Manager::parseXmlDom(const pugi::xml_document &doc, const bool readOnly, const string libraryPath) {
|
||||||
pugi::xml_node libraryNode = doc.child("library");
|
pugi::xml_node libraryNode = doc.child("library");
|
||||||
|
|
||||||
if (strlen(libraryNode.attribute("current").value()))
|
if (strlen(libraryNode.attribute("current").value()))
|
||||||
this->setCurrentBookId(libraryNode.attribute("current").value());
|
this->setCurrentBookId(libraryNode.attribute("current").value());
|
||||||
|
|
||||||
string libraryVersion = libraryNode.attribute("version").value();
|
string libraryVersion = libraryNode.attribute("version").value();
|
||||||
|
|
||||||
for (pugi::xml_node bookNode = libraryNode.child("book"); bookNode; bookNode = bookNode.next_sibling("book")) {
|
for (pugi::xml_node bookNode = libraryNode.child("book"); bookNode; bookNode = bookNode.next_sibling("book")) {
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
kiwix::Book book;
|
kiwix::Book book;
|
||||||
@ -45,7 +45,7 @@ namespace kiwix {
|
|||||||
book.readOnly = readOnly;
|
book.readOnly = readOnly;
|
||||||
book.id = bookNode.attribute("id").value();
|
book.id = bookNode.attribute("id").value();
|
||||||
book.path = bookNode.attribute("path").value();
|
book.path = bookNode.attribute("path").value();
|
||||||
book.last = (std::string(bookNode.attribute("last").value()) != "undefined" ?
|
book.last = (std::string(bookNode.attribute("last").value()) != "undefined" ?
|
||||||
bookNode.attribute("last").value() : "");
|
bookNode.attribute("last").value() : "");
|
||||||
book.indexPath = bookNode.attribute("indexPath").value();
|
book.indexPath = bookNode.attribute("indexPath").value();
|
||||||
book.indexType = (std::string(bookNode.attribute("indexType").value()) == "xapian" ? XAPIAN : CLUCENE);
|
book.indexType = (std::string(bookNode.attribute("indexType").value()) == "xapian" ? XAPIAN : CLUCENE);
|
||||||
@ -56,14 +56,15 @@ namespace kiwix {
|
|||||||
book.creator = bookNode.attribute("creator").value();
|
book.creator = bookNode.attribute("creator").value();
|
||||||
book.publisher = bookNode.attribute("publisher").value();
|
book.publisher = bookNode.attribute("publisher").value();
|
||||||
book.url = bookNode.attribute("url").value();
|
book.url = bookNode.attribute("url").value();
|
||||||
|
book.origID = bookNode.attribute("origId").value();
|
||||||
book.articleCount = bookNode.attribute("articleCount").value();
|
book.articleCount = bookNode.attribute("articleCount").value();
|
||||||
book.mediaCount = bookNode.attribute("mediaCount").value();
|
book.mediaCount = bookNode.attribute("mediaCount").value();
|
||||||
book.size = bookNode.attribute("size").value();
|
book.size = bookNode.attribute("size").value();
|
||||||
book.favicon = bookNode.attribute("favicon").value();
|
book.favicon = bookNode.attribute("favicon").value();
|
||||||
book.faviconMimeType = bookNode.attribute("faviconMimeType").value();
|
book.faviconMimeType = bookNode.attribute("faviconMimeType").value();
|
||||||
|
|
||||||
/* Check absolute and relative paths */
|
/* Check absolute and relative paths */
|
||||||
this->checkAndCleanBookPaths(book, libraryPath);
|
this->checkAndCleanBookPaths(book, libraryPath);
|
||||||
|
|
||||||
/* Update the book properties with the new importer */
|
/* Update the book properties with the new importer */
|
||||||
if (libraryVersion.empty() || atoi(libraryVersion.c_str()) <= atoi(KIWIX_LIBRARY_VERSION)) {
|
if (libraryVersion.empty() || atoi(libraryVersion.c_str()) <= atoi(KIWIX_LIBRARY_VERSION)) {
|
||||||
@ -76,7 +77,7 @@ namespace kiwix {
|
|||||||
library.addBook(book);
|
library.addBook(book);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +129,7 @@ namespace kiwix {
|
|||||||
|
|
||||||
if (!library.version.empty())
|
if (!library.version.empty())
|
||||||
libraryNode.append_attribute("version") = library.version.c_str();
|
libraryNode.append_attribute("version") = library.version.c_str();
|
||||||
|
|
||||||
/* Add each book */
|
/* Add each book */
|
||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
@ -141,11 +142,11 @@ namespace kiwix {
|
|||||||
|
|
||||||
if (!itr->path.empty())
|
if (!itr->path.empty())
|
||||||
bookNode.append_attribute("path") = itr->path.c_str();
|
bookNode.append_attribute("path") = itr->path.c_str();
|
||||||
|
|
||||||
if (!itr->last.empty() && itr->last != "undefined") {
|
if (!itr->last.empty() && itr->last != "undefined") {
|
||||||
bookNode.append_attribute("last") = itr->last.c_str();
|
bookNode.append_attribute("last") = itr->last.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!itr->indexPath.empty())
|
if (!itr->indexPath.empty())
|
||||||
bookNode.append_attribute("indexPath") = itr->indexPath.c_str();
|
bookNode.append_attribute("indexPath") = itr->indexPath.c_str();
|
||||||
|
|
||||||
@ -155,31 +156,34 @@ namespace kiwix {
|
|||||||
else if (itr->indexType == CLUCENE)
|
else if (itr->indexType == CLUCENE)
|
||||||
bookNode.append_attribute("indexType") = "clucene";
|
bookNode.append_attribute("indexType") = "clucene";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!itr->title.empty())
|
if (!itr->title.empty())
|
||||||
bookNode.append_attribute("title") = itr->title.c_str();
|
bookNode.append_attribute("title") = itr->title.c_str();
|
||||||
|
|
||||||
if (itr->description != "")
|
if (itr->description != "")
|
||||||
bookNode.append_attribute("description") = itr->description.c_str();
|
bookNode.append_attribute("description") = itr->description.c_str();
|
||||||
|
|
||||||
if (itr->language != "")
|
if (itr->language != "")
|
||||||
bookNode.append_attribute("language") = itr->language.c_str();
|
bookNode.append_attribute("language") = itr->language.c_str();
|
||||||
|
|
||||||
if (itr->date != "")
|
if (itr->date != "")
|
||||||
bookNode.append_attribute("date") = itr->date.c_str();
|
bookNode.append_attribute("date") = itr->date.c_str();
|
||||||
|
|
||||||
if (itr->creator != "")
|
if (itr->creator != "")
|
||||||
bookNode.append_attribute("creator") = itr->creator.c_str();
|
bookNode.append_attribute("creator") = itr->creator.c_str();
|
||||||
|
|
||||||
if (itr->publisher != "")
|
if (itr->publisher != "")
|
||||||
bookNode.append_attribute("publisher") = itr->publisher.c_str();
|
bookNode.append_attribute("publisher") = itr->publisher.c_str();
|
||||||
|
|
||||||
if (itr->url != "")
|
if (itr->url != "")
|
||||||
bookNode.append_attribute("url") = itr->url.c_str();
|
bookNode.append_attribute("url") = itr->url.c_str();
|
||||||
|
|
||||||
|
if (itr->origID != "")
|
||||||
|
bookNode.append_attribute("origId") = itr->origID.c_str();
|
||||||
|
|
||||||
if (itr->articleCount != "")
|
if (itr->articleCount != "")
|
||||||
bookNode.append_attribute("articleCount") = itr->articleCount.c_str();
|
bookNode.append_attribute("articleCount") = itr->articleCount.c_str();
|
||||||
|
|
||||||
if (itr->mediaCount != "")
|
if (itr->mediaCount != "")
|
||||||
bookNode.append_attribute("mediaCount") = itr->mediaCount.c_str();
|
bookNode.append_attribute("mediaCount") = itr->mediaCount.c_str();
|
||||||
|
|
||||||
@ -211,13 +215,13 @@ namespace kiwix {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string Manager::getCurrentBookId() {
|
string Manager::getCurrentBookId() {
|
||||||
return library.current.empty() ?
|
return library.current.empty() ?
|
||||||
"" : library.current.top();
|
"" : library.current.top();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add a book to the library. Return empty string if failed, book id otherwise */
|
/* Add a book to the library. Return empty string if failed, book id otherwise */
|
||||||
string Manager::addBookFromPathAndGetId(const string pathToOpen, const string pathToSave,
|
string Manager::addBookFromPathAndGetId(const string pathToOpen, const string pathToSave,
|
||||||
const string url, const bool checkMetaData) {
|
const string url, const string origId, const bool checkMetaData) {
|
||||||
kiwix::Book book;
|
kiwix::Book book;
|
||||||
|
|
||||||
if (this->readBookFromPath(pathToOpen, &book)) {
|
if (this->readBookFromPath(pathToOpen, &book)) {
|
||||||
@ -228,9 +232,10 @@ namespace kiwix {
|
|||||||
computeAbsolutePath(removeLastPathElement(writableLibraryPath, true, false), pathToSave) : pathToSave;
|
computeAbsolutePath(removeLastPathElement(writableLibraryPath, true, false), pathToSave) : pathToSave;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!checkMetaData ||
|
if (!checkMetaData ||
|
||||||
(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;
|
||||||
|
book.origID=origId;
|
||||||
library.addBook(book);
|
library.addBook(book);
|
||||||
return book.id;
|
return book.id;
|
||||||
}
|
}
|
||||||
@ -238,16 +243,16 @@ namespace kiwix {
|
|||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wrapper over Manager::addBookFromPath which return a bool instead of a string */
|
/* 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) {
|
bool Manager::addBookFromPath(const string pathToOpen, const string pathToSave, const string url, const string origId, const bool checkMetaData) {
|
||||||
return !(this->addBookFromPathAndGetId(pathToOpen, pathToSave, url, checkMetaData).empty());
|
return !(this->addBookFromPathAndGetId(pathToOpen, pathToSave, url, origId, checkMetaData).empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::readBookFromPath(const string path, kiwix::Book *book) {
|
bool Manager::readBookFromPath(const string path, kiwix::Book *book) {
|
||||||
try {
|
try {
|
||||||
kiwix::Reader *reader = new kiwix::Reader(path);
|
kiwix::Reader *reader = new kiwix::Reader(path);
|
||||||
|
|
||||||
if (book != NULL) {
|
if (book != NULL) {
|
||||||
book->path = path;
|
book->path = path;
|
||||||
book->pathAbsolute = path;
|
book->pathAbsolute = path;
|
||||||
@ -258,18 +263,18 @@ namespace kiwix {
|
|||||||
book->creator = reader->getCreator();
|
book->creator = reader->getCreator();
|
||||||
book->publisher = reader->getPublisher();
|
book->publisher = reader->getPublisher();
|
||||||
book->title = reader->getTitle();
|
book->title = reader->getTitle();
|
||||||
|
|
||||||
std::ostringstream articleCountStream;
|
std::ostringstream articleCountStream;
|
||||||
articleCountStream << reader->getArticleCount();
|
articleCountStream << reader->getArticleCount();
|
||||||
book->articleCount = articleCountStream.str();
|
book->articleCount = articleCountStream.str();
|
||||||
|
|
||||||
std::ostringstream mediaCountStream;
|
std::ostringstream mediaCountStream;
|
||||||
mediaCountStream << reader->getMediaCount();
|
mediaCountStream << reader->getMediaCount();
|
||||||
book->mediaCount = mediaCountStream.str();
|
book->mediaCount = mediaCountStream.str();
|
||||||
|
|
||||||
ostringstream convert; convert << reader->getFileSize();
|
ostringstream convert; convert << reader->getFileSize();
|
||||||
book->size = convert.str();
|
book->size = convert.str();
|
||||||
|
|
||||||
string favicon;
|
string favicon;
|
||||||
string faviconMimeType;
|
string faviconMimeType;
|
||||||
if (reader->getFavicon(favicon, faviconMimeType)) {
|
if (reader->getFavicon(favicon, faviconMimeType)) {
|
||||||
@ -277,7 +282,7 @@ namespace kiwix {
|
|||||||
book->faviconMimeType = faviconMimeType;
|
book->faviconMimeType = faviconMimeType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete reader;
|
delete reader;
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << e.what() << std::endl;
|
std::cerr << e.what() << std::endl;
|
||||||
@ -294,7 +299,7 @@ namespace kiwix {
|
|||||||
bool Manager::removeBookById(const string id) {
|
bool Manager::removeBookById(const string id) {
|
||||||
unsigned int bookIndex = 0;
|
unsigned int bookIndex = 0;
|
||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
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) {
|
||||||
return this->library.removeBookByIndex(bookIndex);
|
return this->library.removeBookByIndex(bookIndex);
|
||||||
}
|
}
|
||||||
@ -308,14 +313,14 @@ namespace kiwix {
|
|||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
std::map<string, bool> booksLanguagesMap;
|
std::map<string, bool> booksLanguagesMap;
|
||||||
|
|
||||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByLanguage);
|
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByLanguage);
|
||||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
if (booksLanguagesMap.find(itr->language) == booksLanguagesMap.end()) {
|
if (booksLanguagesMap.find(itr->language) == booksLanguagesMap.end()) {
|
||||||
booksLanguagesMap[itr->language] = true;
|
booksLanguagesMap[itr->language] = true;
|
||||||
booksLanguages.push_back(itr->language);
|
booksLanguages.push_back(itr->language);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return booksLanguages;
|
return booksLanguages;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,14 +329,14 @@ namespace kiwix {
|
|||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
std::map<string, bool> booksCreatorsMap;
|
std::map<string, bool> booksCreatorsMap;
|
||||||
|
|
||||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByCreator);
|
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByCreator);
|
||||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
if (booksCreatorsMap.find(itr->creator) == booksCreatorsMap.end()) {
|
if (booksCreatorsMap.find(itr->creator) == booksCreatorsMap.end()) {
|
||||||
booksCreatorsMap[itr->creator] = true;
|
booksCreatorsMap[itr->creator] = true;
|
||||||
booksCreators.push_back(itr->creator);
|
booksCreators.push_back(itr->creator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return booksCreators;
|
return booksCreators;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,7 +348,7 @@ namespace kiwix {
|
|||||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
booksIds.push_back(itr->id);
|
booksIds.push_back(itr->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return booksIds;
|
return booksIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,14 +357,14 @@ namespace kiwix {
|
|||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
std::map<string, bool> booksPublishersMap;
|
std::map<string, bool> booksPublishersMap;
|
||||||
|
|
||||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByPublisher);
|
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByPublisher);
|
||||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
if (booksPublishersMap.find(itr->publisher) == booksPublishersMap.end()) {
|
if (booksPublishersMap.find(itr->publisher) == booksPublishersMap.end()) {
|
||||||
booksPublishersMap[itr->publisher] = true;
|
booksPublishersMap[itr->publisher] = true;
|
||||||
booksPublishers.push_back(itr->publisher);
|
booksPublishers.push_back(itr->publisher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return booksPublishers;
|
return booksPublishers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,7 +384,7 @@ namespace kiwix {
|
|||||||
|
|
||||||
bool Manager::getBookById(const string id, Book &book) {
|
bool Manager::getBookById(const string id, Book &book) {
|
||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
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) {
|
||||||
book = *itr;
|
book = *itr;
|
||||||
return true;
|
return true;
|
||||||
@ -390,7 +395,7 @@ namespace kiwix {
|
|||||||
|
|
||||||
bool Manager::updateBookLastOpenDateById(const string id) {
|
bool Manager::updateBookLastOpenDateById(const string id) {
|
||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
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) {
|
||||||
char unixdate[12];
|
char unixdate[12];
|
||||||
sprintf (unixdate, "%d", (int)time(NULL));
|
sprintf (unixdate, "%d", (int)time(NULL));
|
||||||
@ -404,7 +409,7 @@ namespace kiwix {
|
|||||||
|
|
||||||
bool Manager::setBookIndex(const string id, const string path, const supportedIndexType type) {
|
bool Manager::setBookIndex(const string id, const string path, const supportedIndexType type) {
|
||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
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 = isRelativePath(path) ?
|
itr->indexPathAbsolute = isRelativePath(path) ?
|
||||||
@ -419,7 +424,7 @@ namespace kiwix {
|
|||||||
|
|
||||||
bool Manager::setBookPath(const string id, const string path) {
|
bool Manager::setBookPath(const string id, const string path) {
|
||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
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 = isRelativePath(path) ?
|
itr->pathAbsolute = isRelativePath(path) ?
|
||||||
@ -433,7 +438,7 @@ namespace kiwix {
|
|||||||
|
|
||||||
void Manager::removeBookPaths() {
|
void Manager::removeBookPaths() {
|
||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
itr->path = "";
|
itr->path = "";
|
||||||
itr->pathAbsolute = "";
|
itr->pathAbsolute = "";
|
||||||
}
|
}
|
||||||
@ -449,7 +454,7 @@ namespace kiwix {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::listBooks(const supportedListMode mode, const supportedListSortBy sortBy,
|
bool Manager::listBooks(const supportedListMode mode, const supportedListSortBy sortBy,
|
||||||
const unsigned int maxSize, const string language, const string creator,
|
const unsigned int maxSize, const string language, const string creator,
|
||||||
const string publisher, const string search) {
|
const string publisher, const string search) {
|
||||||
this->bookIdList.clear();
|
this->bookIdList.clear();
|
||||||
@ -457,7 +462,7 @@ namespace kiwix {
|
|||||||
|
|
||||||
/* Sort */
|
/* Sort */
|
||||||
if (sortBy == TITLE) {
|
if (sortBy == TITLE) {
|
||||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByTitle);
|
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByTitle);
|
||||||
} else if (sortBy == SIZE) {
|
} else if (sortBy == SIZE) {
|
||||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortBySize);
|
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortBySize);
|
||||||
} else if (sortBy == DATE) {
|
} else if (sortBy == DATE) {
|
||||||
@ -467,7 +472,7 @@ namespace kiwix {
|
|||||||
} else if (sortBy == PUBLISHER) {
|
} else if (sortBy == PUBLISHER) {
|
||||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByPublisher);
|
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByPublisher);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Special sort for LASTOPEN */
|
/* Special sort for LASTOPEN */
|
||||||
if (mode == LASTOPEN) {
|
if (mode == LASTOPEN) {
|
||||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByLastOpen);
|
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByLastOpen);
|
||||||
@ -482,9 +487,9 @@ namespace kiwix {
|
|||||||
|
|
||||||
if (mode == LOCAL && itr->path.empty())
|
if (mode == LOCAL && itr->path.empty())
|
||||||
ok = false;
|
ok = false;
|
||||||
|
|
||||||
if (ok == true && mode == REMOTE && (!itr->path.empty() || itr->url.empty()))
|
if (ok == true && mode == REMOTE && (!itr->path.empty() || itr->url.empty()))
|
||||||
ok = false;
|
ok = false;
|
||||||
|
|
||||||
if (ok == true && maxSize != 0 && (unsigned int)atoi(itr->size.c_str()) > maxSize * 1024 * 1024)
|
if (ok == true && maxSize != 0 && (unsigned int)atoi(itr->size.c_str()) > maxSize * 1024 * 1024)
|
||||||
ok = false;
|
ok = false;
|
||||||
@ -497,7 +502,7 @@ namespace kiwix {
|
|||||||
|
|
||||||
if (ok == true && !publisher.empty() && itr->publisher != publisher)
|
if (ok == true && !publisher.empty() && itr->publisher != publisher)
|
||||||
ok = false;
|
ok = false;
|
||||||
|
|
||||||
if ((ok == true && !search.empty()) && !(matchRegex(itr->title, search) || matchRegex(itr->description, search)))
|
if ((ok == true && !search.empty()) && !(matchRegex(itr->title, search) || matchRegex(itr->description, search)))
|
||||||
ok = false;
|
ok = false;
|
||||||
|
|
||||||
@ -506,7 +511,7 @@ namespace kiwix {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -519,14 +524,14 @@ namespace kiwix {
|
|||||||
book.path = computeRelativePath(removeLastPathElement(libraryPath, true, false), book.pathAbsolute);
|
book.path = computeRelativePath(removeLastPathElement(libraryPath, true, false), book.pathAbsolute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!book.indexPath.empty()) {
|
if (!book.indexPath.empty()) {
|
||||||
if (isRelativePath(book.indexPath)) {
|
if (isRelativePath(book.indexPath)) {
|
||||||
book.indexPathAbsolute =
|
book.indexPathAbsolute =
|
||||||
computeAbsolutePath(removeLastPathElement(libraryPath, true, false), book.indexPath);
|
computeAbsolutePath(removeLastPathElement(libraryPath, true, false), book.indexPath);
|
||||||
} else {
|
} else {
|
||||||
book.indexPathAbsolute = book.indexPath;
|
book.indexPathAbsolute = book.indexPath;
|
||||||
book.indexPath =
|
book.indexPath =
|
||||||
computeRelativePath(removeLastPathElement(libraryPath, true, false), book.indexPathAbsolute);
|
computeRelativePath(removeLastPathElement(libraryPath, true, false), book.indexPathAbsolute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ namespace kiwix {
|
|||||||
enum supportedListSortBy { TITLE, SIZE, DATE, CREATOR, PUBLISHER };
|
enum supportedListSortBy { TITLE, SIZE, DATE, CREATOR, PUBLISHER };
|
||||||
|
|
||||||
class Manager {
|
class Manager {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Manager();
|
Manager();
|
||||||
~Manager();
|
~Manager();
|
||||||
@ -55,9 +55,9 @@ namespace kiwix {
|
|||||||
string getCurrentBookId();
|
string getCurrentBookId();
|
||||||
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 addBookFromPathAndGetId(const string pathToOpen, const string pathToSave = "", const string url = "",
|
string addBookFromPathAndGetId(const string pathToOpen, const string pathToSave = "", const string url = "", const string origID="",
|
||||||
const bool checkMetaData = false);
|
const bool checkMetaData = false);
|
||||||
bool addBookFromPath(const string pathToOpen, const string pathToSave = "", const string url = "",
|
bool addBookFromPath(const string pathToOpen, const string pathToSave = "", const string url = "", const string origID="",
|
||||||
const bool checkMetaData = false);
|
const bool checkMetaData = false);
|
||||||
Library cloneLibrary();
|
Library cloneLibrary();
|
||||||
bool getBookById(const string id, Book &book);
|
bool getBookById(const string id, Book &book);
|
||||||
@ -65,7 +65,7 @@ namespace kiwix {
|
|||||||
unsigned int getBookCount(const bool localBooks, const bool remoteBooks);
|
unsigned int getBookCount(const bool localBooks, const bool remoteBooks);
|
||||||
bool updateBookLastOpenDateById(const string id);
|
bool updateBookLastOpenDateById(const string id);
|
||||||
void removeBookPaths();
|
void removeBookPaths();
|
||||||
bool listBooks(const supportedListMode mode, const supportedListSortBy sortBy, const unsigned int maxSize,
|
bool listBooks(const supportedListMode mode, const supportedListSortBy sortBy, const unsigned int maxSize,
|
||||||
const string language, const string creator, const string publisher, const string search);
|
const string language, const string creator, const string publisher, const string search);
|
||||||
vector<string> getBooksLanguages();
|
vector<string> getBooksLanguages();
|
||||||
vector<string> getBooksCreators();
|
vector<string> getBooksCreators();
|
||||||
@ -75,10 +75,10 @@ namespace kiwix {
|
|||||||
string writableLibraryPath;
|
string writableLibraryPath;
|
||||||
|
|
||||||
vector<std::string> bookIdList;
|
vector<std::string> bookIdList;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
kiwix::Library library;
|
kiwix::Library library;
|
||||||
|
|
||||||
bool readBookFromPath(const string path, Book *book = NULL);
|
bool readBookFromPath(const string path, Book *book = NULL);
|
||||||
bool parseXmlDom(const pugi::xml_document &doc, const bool readOnly, const string libraryPath);
|
bool parseXmlDom(const pugi::xml_document &doc, const bool readOnly, const string libraryPath);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user