mirror of https://github.com/kiwix/libkiwix.git
+ imp. of kiwix-manage
This commit is contained in:
parent
355ca7057e
commit
6b8112b88b
|
@ -32,7 +32,10 @@ namespace kiwix {
|
||||||
description(""),
|
description(""),
|
||||||
language(""),
|
language(""),
|
||||||
date(""),
|
date(""),
|
||||||
creator("") {
|
creator(""),
|
||||||
|
url(""),
|
||||||
|
articleCount(""),
|
||||||
|
mediaCount("") {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Destructor */
|
/* Destructor */
|
||||||
|
|
|
@ -45,6 +45,9 @@ namespace kiwix {
|
||||||
string language;
|
string language;
|
||||||
string creator;
|
string creator;
|
||||||
string date;
|
string date;
|
||||||
|
string url;
|
||||||
|
string articleCount;
|
||||||
|
string mediaCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Library {
|
class Library {
|
||||||
|
|
|
@ -50,6 +50,9 @@ namespace kiwix {
|
||||||
book.language = bookNode.attribute("language").value();
|
book.language = bookNode.attribute("language").value();
|
||||||
book.date = bookNode.attribute("date").value();
|
book.date = bookNode.attribute("date").value();
|
||||||
book.creator = bookNode.attribute("creator").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);
|
library.addBook(book);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +66,9 @@ namespace kiwix {
|
||||||
|
|
||||||
/* Add the library node */
|
/* Add the library node */
|
||||||
pugi::xml_node libraryNode = doc.append_child("library");
|
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 */
|
/* Add each book */
|
||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
|
@ -98,6 +103,15 @@ namespace kiwix {
|
||||||
if (itr->creator != "")
|
if (itr->creator != "")
|
||||||
bookNode.append_attribute("creator") = itr->creator.c_str();
|
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 */
|
/* saving file */
|
||||||
|
@ -106,7 +120,7 @@ namespace kiwix {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::addBookFromPath(const string path) {
|
bool Manager::addBookFromPath(const string path, const string url) {
|
||||||
kiwix::Book book;
|
kiwix::Book book;
|
||||||
|
|
||||||
/* Open the ZIM file */
|
/* Open the ZIM file */
|
||||||
|
@ -118,7 +132,18 @@ namespace kiwix {
|
||||||
book.language = reader.getLanguage();
|
book.language = reader.getLanguage();
|
||||||
book.date = reader.getDate();
|
book.date = reader.getDate();
|
||||||
book.creator = reader.getCreator();
|
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);
|
library.addBook(book);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace kiwix {
|
||||||
bool readFile(const string path);
|
bool readFile(const string path);
|
||||||
bool writeFile(const string path);
|
bool writeFile(const string path);
|
||||||
bool removeBookByIndex(const unsigned int bookIndex);
|
bool removeBookByIndex(const unsigned int bookIndex);
|
||||||
bool addBookFromPath(const string path);
|
bool addBookFromPath(const string path, const string url = "");
|
||||||
kiwix::Library cloneLibrary();
|
kiwix::Library cloneLibrary();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -49,6 +49,7 @@ namespace kiwix {
|
||||||
this->lastArticleOffset = this->zimFileHandler->getNamespaceEndOffset('A');
|
this->lastArticleOffset = this->zimFileHandler->getNamespaceEndOffset('A');
|
||||||
this->currentArticleOffset = this->firstArticleOffset;
|
this->currentArticleOffset = this->firstArticleOffset;
|
||||||
this->articleCount = this->zimFileHandler->getNamespaceCount('A');
|
this->articleCount = this->zimFileHandler->getNamespaceCount('A');
|
||||||
|
this->mediaCount = this->zimFileHandler->getNamespaceCount('I');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize random seed: */
|
/* initialize random seed: */
|
||||||
|
@ -71,6 +72,10 @@ namespace kiwix {
|
||||||
unsigned int Reader::getArticleCount() {
|
unsigned int Reader::getArticleCount() {
|
||||||
return this->articleCount;
|
return this->articleCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int Reader::getMediaCount() {
|
||||||
|
return this->mediaCount;
|
||||||
|
}
|
||||||
|
|
||||||
/* Return the UID of the ZIM file */
|
/* Return the UID of the ZIM file */
|
||||||
string Reader::getId() {
|
string Reader::getId() {
|
||||||
|
|
|
@ -40,6 +40,7 @@ namespace kiwix {
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
unsigned int getArticleCount();
|
unsigned int getArticleCount();
|
||||||
|
unsigned int getMediaCount();
|
||||||
string getId();
|
string getId();
|
||||||
string getRandomPageUrl();
|
string getRandomPageUrl();
|
||||||
string getFirstPageUrl();
|
string getFirstPageUrl();
|
||||||
|
@ -56,13 +57,14 @@ namespace kiwix {
|
||||||
bool getNextSuggestion(string &title);
|
bool getNextSuggestion(string &title);
|
||||||
bool canCheckIntegrity();
|
bool canCheckIntegrity();
|
||||||
bool isCorrupted();
|
bool isCorrupted();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
zim::File* zimFileHandler;
|
zim::File* zimFileHandler;
|
||||||
zim::size_type firstArticleOffset;
|
zim::size_type firstArticleOffset;
|
||||||
zim::size_type lastArticleOffset;
|
zim::size_type lastArticleOffset;
|
||||||
zim::size_type currentArticleOffset;
|
zim::size_type currentArticleOffset;
|
||||||
zim::size_type articleCount;
|
zim::size_type articleCount;
|
||||||
|
zim::size_type mediaCount;
|
||||||
|
|
||||||
std::vector<std::string> suggestions;
|
std::vector<std::string> suggestions;
|
||||||
std::vector<std::string>::iterator suggestionsOffset;
|
std::vector<std::string>::iterator suggestionsOffset;
|
||||||
|
|
Loading…
Reference in New Issue