+ imp. of kiwix-manage

This commit is contained in:
kelson42 2011-04-20 19:20:51 +00:00
parent 355ca7057e
commit 6b8112b88b
6 changed files with 43 additions and 5 deletions

View File

@ -32,7 +32,10 @@ namespace kiwix {
description(""),
language(""),
date(""),
creator("") {
creator(""),
url(""),
articleCount(""),
mediaCount("") {
}
/* Destructor */

View File

@ -45,6 +45,9 @@ namespace kiwix {
string language;
string creator;
string date;
string url;
string articleCount;
string mediaCount;
};
class Library {

View File

@ -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,6 +66,8 @@ namespace kiwix {
/* Add the library node */
pugi::xml_node libraryNode = doc.append_child("library");
if (library.current != "")
libraryNode.append_attribute("current") = library.current.c_str();
/* Add each book */
@ -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;
}

View File

@ -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:

View File

@ -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: */
@ -72,6 +73,10 @@ namespace kiwix {
return this->articleCount;
}
unsigned int Reader::getMediaCount() {
return this->mediaCount;
}
/* Return the UID of the ZIM file */
string Reader::getId() {
std::ostringstream s;

View File

@ -40,6 +40,7 @@ namespace kiwix {
void reset();
unsigned int getArticleCount();
unsigned int getMediaCount();
string getId();
string getRandomPageUrl();
string getFirstPageUrl();
@ -63,6 +64,7 @@ namespace kiwix {
zim::size_type lastArticleOffset;
zim::size_type currentArticleOffset;
zim::size_type articleCount;
zim::size_type mediaCount;
std::vector<std::string> suggestions;
std::vector<std::string>::iterator suggestionsOffset;