Get information about the total number of book of a search.

When we do a search and paging the result, we need to display to the
user the total number of book, not only the `itemsPerPage`.

So, we need to parse correctly the xml to keep information of the total
number of book.
This commit is contained in:
Matthieu Gautier 2018-11-02 17:04:55 +01:00
parent 5f4c04e79e
commit 9ab44e6a5f
2 changed files with 13 additions and 1 deletions

View File

@ -196,7 +196,10 @@ class Manager
std::string writableLibraryPath; std::string writableLibraryPath;
std::vector<std::string> bookIdList; bool m_hasSearchResult = false;
uint64_t m_totalBooks = 0;
uint64_t m_startIndex = 0;
uint64_t m_itemsPerPage = 0;
protected: protected:
kiwix::LibraryManipulator* manipulator; kiwix::LibraryManipulator* manipulator;

View File

@ -95,6 +95,15 @@ bool Manager::parseOpdsDom(const pugi::xml_document& doc, const std::string& url
{ {
pugi::xml_node libraryNode = doc.child("feed"); pugi::xml_node libraryNode = doc.child("feed");
try {
m_totalBooks = strtoull(libraryNode.child("totalResults").child_value(), 0, 0);
m_startIndex = strtoull(libraryNode.child("startIndex").child_value(), 0, 0);
m_itemsPerPage = strtoull(libraryNode.child("itemsPerPage").child_value(), 0, 0);
m_hasSearchResult = true;
} catch(...) {
m_hasSearchResult = false;
}
for (pugi::xml_node entryNode = libraryNode.child("entry"); entryNode; for (pugi::xml_node entryNode = libraryNode.child("entry"); entryNode;
entryNode = entryNode.next_sibling("entry")) { entryNode = entryNode.next_sibling("entry")) {
kiwix::Book book; kiwix::Book book;