From 6b8112b88b5f32d8315d91ae962d10e6fd064f73 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Wed, 20 Apr 2011 19:20:51 +0000 Subject: [PATCH] + imp. of kiwix-manage --- src/common/kiwix/library.cpp | 5 ++++- src/common/kiwix/library.h | 3 +++ src/common/kiwix/manager.cpp | 29 +++++++++++++++++++++++++++-- src/common/kiwix/manager.h | 2 +- src/common/kiwix/reader.cpp | 5 +++++ src/common/kiwix/reader.h | 4 +++- 6 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/common/kiwix/library.cpp b/src/common/kiwix/library.cpp index 4b0713d29..d9805f84c 100644 --- a/src/common/kiwix/library.cpp +++ b/src/common/kiwix/library.cpp @@ -32,7 +32,10 @@ namespace kiwix { description(""), language(""), date(""), - creator("") { + creator(""), + url(""), + articleCount(""), + mediaCount("") { } /* Destructor */ diff --git a/src/common/kiwix/library.h b/src/common/kiwix/library.h index c6a74ca76..f655c1ac9 100644 --- a/src/common/kiwix/library.h +++ b/src/common/kiwix/library.h @@ -45,6 +45,9 @@ namespace kiwix { string language; string creator; string date; + string url; + string articleCount; + string mediaCount; }; class Library { diff --git a/src/common/kiwix/manager.cpp b/src/common/kiwix/manager.cpp index 4a74b9be7..61cf89666 100644 --- a/src/common/kiwix/manager.cpp +++ b/src/common/kiwix/manager.cpp @@ -50,6 +50,9 @@ namespace kiwix { book.language = bookNode.attribute("language").value(); book.date = bookNode.attribute("date").value(); book.creator = bookNode.attribute("creator").value(); + book.url = bookNode.attribute("url").value(); + book.articleCount = bookNode.attribute("articleCount").value(); + book.mediaCount = bookNode.attribute("mediaCount").value(); library.addBook(book); } @@ -63,7 +66,9 @@ namespace kiwix { /* Add the library node */ pugi::xml_node libraryNode = doc.append_child("library"); - libraryNode.append_attribute("current") = library.current.c_str(); + + if (library.current != "") + libraryNode.append_attribute("current") = library.current.c_str(); /* Add each book */ std::vector::iterator itr; @@ -98,6 +103,15 @@ namespace kiwix { if (itr->creator != "") bookNode.append_attribute("creator") = itr->creator.c_str(); + if (itr->url != "") + bookNode.append_attribute("url") = itr->url.c_str(); + + if (itr->articleCount != "") + bookNode.append_attribute("articleCount") = itr->articleCount.c_str(); + + if (itr->mediaCount != "") + bookNode.append_attribute("mediaCount") = itr->mediaCount.c_str(); + } /* saving file */ @@ -106,7 +120,7 @@ namespace kiwix { return true; } - bool Manager::addBookFromPath(const string path) { + bool Manager::addBookFromPath(const string path, const string url) { kiwix::Book book; /* Open the ZIM file */ @@ -118,7 +132,18 @@ namespace kiwix { book.language = reader.getLanguage(); book.date = reader.getDate(); book.creator = reader.getCreator(); + book.url = url; + + std::ostringstream articleCountStream; + articleCountStream << reader.getArticleCount(); + book.articleCount = articleCountStream.str(); + + std::ostringstream mediaCountStream; + mediaCountStream << reader.getMediaCount(); + book.mediaCount = mediaCountStream.str(); + library.addBook(book); + return true; } diff --git a/src/common/kiwix/manager.h b/src/common/kiwix/manager.h index fd5ef16f1..4b887dda0 100644 --- a/src/common/kiwix/manager.h +++ b/src/common/kiwix/manager.h @@ -39,7 +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); + bool addBookFromPath(const string path, const string url = ""); kiwix::Library cloneLibrary(); protected: diff --git a/src/common/kiwix/reader.cpp b/src/common/kiwix/reader.cpp index 1cbf2397e..5ace9cb17 100644 --- a/src/common/kiwix/reader.cpp +++ b/src/common/kiwix/reader.cpp @@ -49,6 +49,7 @@ namespace kiwix { this->lastArticleOffset = this->zimFileHandler->getNamespaceEndOffset('A'); this->currentArticleOffset = this->firstArticleOffset; this->articleCount = this->zimFileHandler->getNamespaceCount('A'); + this->mediaCount = this->zimFileHandler->getNamespaceCount('I'); } /* initialize random seed: */ @@ -71,6 +72,10 @@ namespace kiwix { unsigned int Reader::getArticleCount() { return this->articleCount; } + + unsigned int Reader::getMediaCount() { + return this->mediaCount; + } /* Return the UID of the ZIM file */ string Reader::getId() { diff --git a/src/common/kiwix/reader.h b/src/common/kiwix/reader.h index 6229e1c3f..604bcaeca 100644 --- a/src/common/kiwix/reader.h +++ b/src/common/kiwix/reader.h @@ -40,6 +40,7 @@ namespace kiwix { void reset(); unsigned int getArticleCount(); + unsigned int getMediaCount(); string getId(); string getRandomPageUrl(); string getFirstPageUrl(); @@ -56,13 +57,14 @@ namespace kiwix { bool getNextSuggestion(string &title); bool canCheckIntegrity(); bool isCorrupted(); - + protected: zim::File* zimFileHandler; zim::size_type firstArticleOffset; zim::size_type lastArticleOffset; zim::size_type currentArticleOffset; zim::size_type articleCount; + zim::size_type mediaCount; std::vector suggestions; std::vector::iterator suggestionsOffset;