mirror of https://github.com/kiwix/libkiwix.git
* In the library, pressing <ENTER> 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
This commit is contained in:
parent
97548d4798
commit
9d4fd28ba6
|
@ -33,6 +33,7 @@ namespace kiwix {
|
||||||
language(""),
|
language(""),
|
||||||
date(""),
|
date(""),
|
||||||
creator(""),
|
creator(""),
|
||||||
|
publisher(""),
|
||||||
url(""),
|
url(""),
|
||||||
articleCount(""),
|
articleCount(""),
|
||||||
mediaCount(""),
|
mediaCount(""),
|
||||||
|
@ -63,6 +64,10 @@ namespace kiwix {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Book::sortByPublisher(const kiwix::Book &a, const kiwix::Book &b) {
|
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;
|
return strcmp(a.creator.c_str(), b.creator.c_str()) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ namespace kiwix {
|
||||||
static bool sortByTitle(const Book &a, const Book &b);
|
static bool sortByTitle(const Book &a, const Book &b);
|
||||||
static bool sortBySize(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 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 sortByPublisher(const Book &a, const Book &b);
|
||||||
static bool sortByLanguage(const Book &a, const Book &b);
|
static bool sortByLanguage(const Book &a, const Book &b);
|
||||||
|
|
||||||
|
@ -58,6 +59,7 @@ namespace kiwix {
|
||||||
string description;
|
string description;
|
||||||
string language;
|
string language;
|
||||||
string creator;
|
string creator;
|
||||||
|
string publisher;
|
||||||
string date;
|
string date;
|
||||||
string url;
|
string url;
|
||||||
string articleCount;
|
string articleCount;
|
||||||
|
|
|
@ -54,6 +54,7 @@ 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.publisher = bookNode.attribute("publisher").value();
|
||||||
book.url = bookNode.attribute("url").value();
|
book.url = bookNode.attribute("url").value();
|
||||||
book.articleCount = bookNode.attribute("articleCount").value();
|
book.articleCount = bookNode.attribute("articleCount").value();
|
||||||
book.mediaCount = bookNode.attribute("mediaCount").value();
|
book.mediaCount = bookNode.attribute("mediaCount").value();
|
||||||
|
@ -162,6 +163,9 @@ 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->publisher != "")
|
||||||
|
bookNode.append_attribute("publisher") = itr->publisher.c_str();
|
||||||
|
|
||||||
if (itr->url != "")
|
if (itr->url != "")
|
||||||
bookNode.append_attribute("url") = itr->url.c_str();
|
bookNode.append_attribute("url") = itr->url.c_str();
|
||||||
|
|
||||||
|
@ -237,6 +241,7 @@ 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.publisher = reader.getPublisher();
|
||||||
|
|
||||||
std::ostringstream articleCountStream;
|
std::ostringstream articleCountStream;
|
||||||
articleCountStream << reader.getArticleCount();
|
articleCountStream << reader.getArticleCount();
|
||||||
|
@ -293,6 +298,22 @@ namespace kiwix {
|
||||||
return booksLanguages;
|
return booksLanguages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<string> Manager::getBooksCreators() {
|
||||||
|
std::vector<string> booksCreators;
|
||||||
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
|
std::map<string, bool> 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<string> Manager::getBooksPublishers() {
|
vector<string> Manager::getBooksPublishers() {
|
||||||
std::vector<string> booksPublishers;
|
std::vector<string> booksPublishers;
|
||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
|
@ -300,9 +321,9 @@ namespace kiwix {
|
||||||
|
|
||||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByPublisher);
|
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByPublisher);
|
||||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||||
if (booksPublishersMap.find(itr->creator) == booksPublishersMap.end()) {
|
if (booksPublishersMap.find(itr->publisher) == booksPublishersMap.end()) {
|
||||||
booksPublishersMap[itr->creator] = true;
|
booksPublishersMap[itr->publisher] = true;
|
||||||
booksPublishers.push_back(itr->creator);
|
booksPublishers.push_back(itr->publisher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,8 +406,9 @@ namespace kiwix {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Manager::listBooks(const supportedListMode mode, const supportedListSortBy sortBy, const unsigned int maxSize,
|
bool Manager::listBooks(const supportedListMode mode, const supportedListSortBy sortBy,
|
||||||
const string language, const string publisher, const string search) {
|
const unsigned int maxSize, const string language, const string creator,
|
||||||
|
const string publisher, const string search) {
|
||||||
this->bookIdList.clear();
|
this->bookIdList.clear();
|
||||||
std::vector<kiwix::Book>::iterator itr;
|
std::vector<kiwix::Book>::iterator itr;
|
||||||
|
|
||||||
|
@ -397,6 +419,8 @@ namespace kiwix {
|
||||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortBySize);
|
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortBySize);
|
||||||
} else if (sortBy == DATE) {
|
} else if (sortBy == DATE) {
|
||||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByDate);
|
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) {
|
} else if (sortBy == PUBLISHER) {
|
||||||
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByPublisher);
|
std::sort(library.books.begin(), library.books.end(), kiwix::Book::sortByPublisher);
|
||||||
}
|
}
|
||||||
|
@ -425,7 +449,10 @@ namespace kiwix {
|
||||||
if (ok == true && !language.empty() && itr->language != language)
|
if (ok == true && !language.empty() && itr->language != language)
|
||||||
ok = false;
|
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;
|
ok = false;
|
||||||
|
|
||||||
if ((ok == true && !search.empty()) && !(matchRegex(itr->title, search) || matchRegex(itr->description, search)))
|
if ((ok == true && !search.empty()) && !(matchRegex(itr->title, search) || matchRegex(itr->description, search)))
|
||||||
|
|
|
@ -37,7 +37,7 @@ using namespace std;
|
||||||
namespace kiwix {
|
namespace kiwix {
|
||||||
|
|
||||||
enum supportedListMode { LASTOPEN, REMOTE, LOCAL };
|
enum supportedListMode { LASTOPEN, REMOTE, LOCAL };
|
||||||
enum supportedListSortBy { TITLE, SIZE, DATE, PUBLISHER };
|
enum supportedListSortBy { TITLE, SIZE, DATE, CREATOR, PUBLISHER };
|
||||||
|
|
||||||
class Manager {
|
class Manager {
|
||||||
|
|
||||||
|
@ -64,8 +64,9 @@ namespace kiwix {
|
||||||
bool updateBookLastOpenDateById(const string id);
|
bool updateBookLastOpenDateById(const string id);
|
||||||
void removeBookPaths();
|
void removeBookPaths();
|
||||||
bool listBooks(const supportedListMode mode, const supportedListSortBy sortBy, const unsigned int maxSize,
|
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<string> getBooksLanguages();
|
vector<string> getBooksLanguages();
|
||||||
|
vector<string> getBooksCreators();
|
||||||
vector<string> getBooksPublishers();
|
vector<string> getBooksPublishers();
|
||||||
|
|
||||||
string writableLibraryPath;
|
string writableLibraryPath;
|
||||||
|
|
|
@ -197,6 +197,12 @@ namespace kiwix {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string Reader::getPublisher() {
|
||||||
|
string value;
|
||||||
|
this->getMetatag("Publisher", value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
/* Return the first page URL */
|
/* Return the first page URL */
|
||||||
string Reader::getFirstPageUrl() {
|
string Reader::getFirstPageUrl() {
|
||||||
string url;
|
string url;
|
||||||
|
|
|
@ -51,6 +51,7 @@ namespace kiwix {
|
||||||
string getLanguage();
|
string getLanguage();
|
||||||
string getDate();
|
string getDate();
|
||||||
string getCreator();
|
string getCreator();
|
||||||
|
string getPublisher();
|
||||||
bool getFavicon(string &content, string &mimeType);
|
bool getFavicon(string &content, string &mimeType);
|
||||||
bool getPageUrlFromTitle(const string &title, string &url);
|
bool getPageUrlFromTitle(const string &title, string &url);
|
||||||
bool getContentByUrl(const string &url, string &content, unsigned int &contentLength, string &contentType);
|
bool getContentByUrl(const string &url, string &content, unsigned int &contentLength, string &contentType);
|
||||||
|
|
Loading…
Reference in New Issue