From 9d4fd28ba61da0677f023a1b39a584d1f3e03cec Mon Sep 17 00:00:00 2001 From: kelson42 Date: Fri, 18 Nov 2011 14:25:21 +0000 Subject: [PATCH] * In the library, pressing in your local library directly open the file * Greying "Load random article" menu entry if no content is loaded (ID: 3439112) * Add the support of the "publisher" ZIM Metadata --- src/common/kiwix/library.cpp | 5 +++++ src/common/kiwix/library.h | 2 ++ src/common/kiwix/manager.cpp | 41 ++++++++++++++++++++++++++++++------ src/common/kiwix/manager.h | 5 +++-- src/common/kiwix/reader.cpp | 6 ++++++ src/common/kiwix/reader.h | 1 + 6 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/common/kiwix/library.cpp b/src/common/kiwix/library.cpp index 4741b5add..0388f76c8 100644 --- a/src/common/kiwix/library.cpp +++ b/src/common/kiwix/library.cpp @@ -33,6 +33,7 @@ namespace kiwix { language(""), date(""), creator(""), + publisher(""), url(""), articleCount(""), mediaCount(""), @@ -63,6 +64,10 @@ namespace kiwix { } bool Book::sortByPublisher(const kiwix::Book &a, const kiwix::Book &b) { + return strcmp(a.publisher.c_str(), b.publisher.c_str()) < 0; + } + + bool Book::sortByCreator(const kiwix::Book &a, const kiwix::Book &b) { return strcmp(a.creator.c_str(), b.creator.c_str()) < 0; } diff --git a/src/common/kiwix/library.h b/src/common/kiwix/library.h index ac85eb90c..5fdeebd99 100644 --- a/src/common/kiwix/library.h +++ b/src/common/kiwix/library.h @@ -44,6 +44,7 @@ namespace kiwix { static bool sortByTitle(const Book &a, const Book &b); static bool sortBySize(const Book &a, const Book &b); static bool sortByDate(const Book &a, const Book &b); + static bool sortByCreator(const Book &a, const Book &b); static bool sortByPublisher(const Book &a, const Book &b); static bool sortByLanguage(const Book &a, const Book &b); @@ -58,6 +59,7 @@ namespace kiwix { string description; string language; string creator; + string publisher; string date; string url; string articleCount; diff --git a/src/common/kiwix/manager.cpp b/src/common/kiwix/manager.cpp index 17041dd09..fb02927e4 100644 --- a/src/common/kiwix/manager.cpp +++ b/src/common/kiwix/manager.cpp @@ -54,6 +54,7 @@ namespace kiwix { book.language = bookNode.attribute("language").value(); book.date = bookNode.attribute("date").value(); book.creator = bookNode.attribute("creator").value(); + book.publisher = bookNode.attribute("publisher").value(); book.url = bookNode.attribute("url").value(); book.articleCount = bookNode.attribute("articleCount").value(); book.mediaCount = bookNode.attribute("mediaCount").value(); @@ -161,6 +162,9 @@ namespace kiwix { if (itr->creator != "") bookNode.append_attribute("creator") = itr->creator.c_str(); + + if (itr->publisher != "") + bookNode.append_attribute("publisher") = itr->publisher.c_str(); if (itr->url != "") bookNode.append_attribute("url") = itr->url.c_str(); @@ -237,6 +241,7 @@ namespace kiwix { book.language = reader.getLanguage(); book.date = reader.getDate(); book.creator = reader.getCreator(); + book.publisher = reader.getPublisher(); std::ostringstream articleCountStream; articleCountStream << reader.getArticleCount(); @@ -293,6 +298,22 @@ namespace kiwix { return booksLanguages; } + vector Manager::getBooksCreators() { + std::vector booksCreators; + std::vector::iterator itr; + std::map booksCreatorsMap; + + std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByCreator); + for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) { + if (booksCreatorsMap.find(itr->creator) == booksCreatorsMap.end()) { + booksCreatorsMap[itr->creator] = true; + booksCreators.push_back(itr->creator); + } + } + + return booksCreators; + } + vector Manager::getBooksPublishers() { std::vector booksPublishers; std::vector::iterator itr; @@ -300,9 +321,9 @@ namespace kiwix { std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByPublisher); for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) { - if (booksPublishersMap.find(itr->creator) == booksPublishersMap.end()) { - booksPublishersMap[itr->creator] = true; - booksPublishers.push_back(itr->creator); + if (booksPublishersMap.find(itr->publisher) == booksPublishersMap.end()) { + booksPublishersMap[itr->publisher] = true; + booksPublishers.push_back(itr->publisher); } } @@ -385,8 +406,9 @@ namespace kiwix { return result; } - bool Manager::listBooks(const supportedListMode mode, const supportedListSortBy sortBy, const unsigned int maxSize, - const string language, const string publisher, const string search) { + bool Manager::listBooks(const supportedListMode mode, const supportedListSortBy sortBy, + const unsigned int maxSize, const string language, const string creator, + const string publisher, const string search) { this->bookIdList.clear(); std::vector::iterator itr; @@ -397,6 +419,8 @@ namespace kiwix { std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortBySize); } else if (sortBy == DATE) { std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByDate); + } else if (sortBy == CREATOR) { + std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByCreator); } else if (sortBy == PUBLISHER) { std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByPublisher); } @@ -424,8 +448,11 @@ namespace kiwix { if (ok == true && !language.empty() && itr->language != language) ok = false; - - if (ok == true && !publisher.empty() && itr->creator != publisher) + + if (ok == true && !creator.empty() && itr->creator != creator) + ok = false; + + if (ok == true && !publisher.empty() && itr->publisher != publisher) ok = false; if ((ok == true && !search.empty()) && !(matchRegex(itr->title, search) || matchRegex(itr->description, search))) diff --git a/src/common/kiwix/manager.h b/src/common/kiwix/manager.h index 5e5fc1d9b..09a6269d6 100644 --- a/src/common/kiwix/manager.h +++ b/src/common/kiwix/manager.h @@ -37,7 +37,7 @@ using namespace std; namespace kiwix { enum supportedListMode { LASTOPEN, REMOTE, LOCAL }; - enum supportedListSortBy { TITLE, SIZE, DATE, PUBLISHER }; + enum supportedListSortBy { TITLE, SIZE, DATE, CREATOR, PUBLISHER }; class Manager { @@ -64,8 +64,9 @@ namespace kiwix { bool updateBookLastOpenDateById(const string id); void removeBookPaths(); bool listBooks(const supportedListMode mode, const supportedListSortBy sortBy, const unsigned int maxSize, - const string language, const string publisher, const string search); + const string language, const string creator, const string publisher, const string search); vector getBooksLanguages(); + vector getBooksCreators(); vector getBooksPublishers(); string writableLibraryPath; diff --git a/src/common/kiwix/reader.cpp b/src/common/kiwix/reader.cpp index 462234bfa..f6c5e5ca8 100644 --- a/src/common/kiwix/reader.cpp +++ b/src/common/kiwix/reader.cpp @@ -197,6 +197,12 @@ namespace kiwix { return value; } + string Reader::getPublisher() { + string value; + this->getMetatag("Publisher", 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 14cbbf44e..5c9a03ee0 100644 --- a/src/common/kiwix/reader.h +++ b/src/common/kiwix/reader.h @@ -51,6 +51,7 @@ namespace kiwix { string getLanguage(); string getDate(); string getCreator(); + string getPublisher(); bool getFavicon(string &content, string &mimeType); bool getPageUrlFromTitle(const string &title, string &url); bool getContentByUrl(const string &url, string &content, unsigned int &contentLength, string &contentType);