diff --git a/src/common/kiwix/library.cpp b/src/common/kiwix/library.cpp index 323d152ba..4b0713d29 100644 --- a/src/common/kiwix/library.cpp +++ b/src/common/kiwix/library.cpp @@ -27,7 +27,12 @@ namespace kiwix { path(""), last(""), indexPath(""), - indexType(XAPIAN) { + indexType(XAPIAN), + title(""), + description(""), + language(""), + date(""), + creator("") { } /* Destructor */ diff --git a/src/common/kiwix/library.h b/src/common/kiwix/library.h index ba4cd51c2..c6a74ca76 100644 --- a/src/common/kiwix/library.h +++ b/src/common/kiwix/library.h @@ -40,7 +40,11 @@ namespace kiwix { string last; string indexPath; supportedIndexType indexType; - + string title; + string description; + string language; + string creator; + string date; }; class Library { diff --git a/src/common/kiwix/manager.cpp b/src/common/kiwix/manager.cpp index 9570637ff..4a74b9be7 100644 --- a/src/common/kiwix/manager.cpp +++ b/src/common/kiwix/manager.cpp @@ -45,6 +45,11 @@ namespace kiwix { book.last = bookNode.attribute("last").value(); book.indexPath = bookNode.attribute("indexPath").value(); book.indexType = bookNode.attribute("indexType").value() == "xapian" ? XAPIAN: CLUCENE; + book.title = bookNode.attribute("title").value(); + book.description = bookNode.attribute("description").value(); + book.language = bookNode.attribute("language").value(); + book.date = bookNode.attribute("date").value(); + book.creator = bookNode.attribute("creator").value(); library.addBook(book); } @@ -61,6 +66,39 @@ namespace kiwix { libraryNode.append_attribute("current") = library.current.c_str(); /* Add each book */ + std::vector::iterator itr; + for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) { + pugi::xml_node bookNode = libraryNode.append_child("book"); + bookNode.append_attribute("id") = itr->id.c_str(); + bookNode.append_attribute("path") = itr->path.c_str(); + + if (itr->last != "") + bookNode.append_attribute("last") = itr->last.c_str(); + + if (itr->indexPath != "") { + bookNode.append_attribute("indexPath") = itr->indexPath.c_str(); + if (itr->indexType == XAPIAN) + bookNode.append_attribute("indexType") = "xapian"; + else + bookNode.append_attribute("indexType") = "clucene"; + } + + if (itr->title != "") + bookNode.append_attribute("title") = itr->title.c_str(); + + if (itr->description != "") + bookNode.append_attribute("description") = itr->description.c_str(); + + if (itr->language != "") + bookNode.append_attribute("language") = itr->language.c_str(); + + if (itr->date != "") + bookNode.append_attribute("date") = itr->date.c_str(); + + if (itr->creator != "") + bookNode.append_attribute("creator") = itr->creator.c_str(); + + } /* saving file */ doc.save_file(path.c_str()); @@ -68,6 +106,22 @@ namespace kiwix { return true; } + bool Manager::addBookFromPath(const string path) { + kiwix::Book book; + + /* Open the ZIM file */ + kiwix::Reader reader = kiwix::Reader(path); + book.path = path; + book.id = reader.getId(); + book.title = reader.getTitle(); + book.description = reader.getDescription(); + book.language = reader.getLanguage(); + book.date = reader.getDate(); + book.creator = reader.getCreator(); + library.addBook(book); + return true; + } + bool Manager::removeBookByIndex(const unsigned int bookIndex) { return this->library.removeBookByIndex(bookIndex); } diff --git a/src/common/kiwix/manager.h b/src/common/kiwix/manager.h index ebe5b8ec7..fd5ef16f1 100644 --- a/src/common/kiwix/manager.h +++ b/src/common/kiwix/manager.h @@ -20,11 +20,8 @@ #ifndef KIWIX_MANAGER_H #define KIWIX_MANAGER_H -#include -#include -#include -#include #include +#include #include #include #include "time.h" @@ -42,6 +39,7 @@ namespace kiwix { bool readFile(const string path); bool writeFile(const string path); bool removeBookByIndex(const unsigned int bookIndex); + bool addBookFromPath(const string path); kiwix::Library cloneLibrary(); protected: diff --git a/src/common/kiwix/reader.cpp b/src/common/kiwix/reader.cpp index 9f1dc559f..1cbf2397e 100644 --- a/src/common/kiwix/reader.cpp +++ b/src/common/kiwix/reader.cpp @@ -133,6 +133,36 @@ namespace kiwix { contentLength, contentType); } + string Reader::getTitle() { + string value=""; + this->getMetatag("Title", value); + return value; + } + + string Reader::getDescription() { + string value=""; + this->getMetatag("Description", value); + return value; + } + + string Reader::getLanguage() { + string value=""; + this->getMetatag("Language", value); + return value; + } + + string Reader::getDate() { + string value=""; + this->getMetatag("Date", value); + return value; + } + + string Reader::getCreator() { + string value=""; + this->getMetatag("Creator", value); + return value; + } + /* Return the first page URL */ string Reader::getFirstPageUrl() { string url = ""; diff --git a/src/common/kiwix/reader.h b/src/common/kiwix/reader.h index 186ff1185..6229e1c3f 100644 --- a/src/common/kiwix/reader.h +++ b/src/common/kiwix/reader.h @@ -45,6 +45,11 @@ namespace kiwix { string getFirstPageUrl(); string getMainPageUrl(); bool getMetatag(const string &url, string &content); + string getTitle(); + string getDescription(); + string getLanguage(); + string getDate(); + string getCreator(); bool getPageUrlFromTitle(const string &title, string &url); bool getContentByUrl(const string &url, string &content, unsigned int &contentLength, string &contentType); bool searchSuggestions(const string &prefix, unsigned int suggestionsCount);