Rename methods `title()` into `getTitle()`.

Same for all attributes.
This commit is contained in:
Matthieu Gautier 2018-09-06 15:24:55 +02:00
parent e0704b3b21
commit 1e8f85eaff
4 changed files with 80 additions and 79 deletions

View File

@ -66,25 +66,25 @@ class Book
string getHumanReadableIdFromPath();
bool readOnly() const { return m_readOnly; }
const string& id() const { return m_id; }
const string& path() const { return m_path; }
const string& indexPath() const { return m_indexPath; }
const supportedIndexType& indexType() const { return m_indexType; }
const string& title() const { return m_title; }
const string& description() const { return m_description; }
const string& language() const { return m_language; }
const string& creator() const { return m_creator; }
const string& publisher() const { return m_publisher; }
const string& date() const { return m_date; }
const string& url() const { return m_url; }
const string& name() const { return m_name; }
const string& tags() const { return m_tags; }
const string& origId() const { return m_origId; }
const uint64_t& articleCount() const { return m_articleCount; }
const uint64_t& mediaCount() const { return m_mediaCount; }
const uint64_t& size() const { return m_size; }
const string& favicon() const { return m_favicon; }
const string& faviconMimeType() const { return m_faviconMimeType; }
const string& getId() const { return m_id; }
const string& getPath() const { return m_path; }
const string& getIndexPath() const { return m_indexPath; }
const supportedIndexType& getIndexType() const { return m_indexType; }
const string& getTitle() const { return m_title; }
const string& getDescription() const { return m_description; }
const string& getLanguage() const { return m_language; }
const string& getCreator() const { return m_creator; }
const string& getPublisher() const { return m_publisher; }
const string& getDate() const { return m_date; }
const string& getUrl() const { return m_url; }
const string& getName() const { return m_name; }
const string& getTags() const { return m_tags; }
const string& getOrigId() const { return m_origId; }
const uint64_t& getArticleCount() const { return m_articleCount; }
const uint64_t& getMediaCount() const { return m_mediaCount; }
const uint64_t& getSize() const { return m_size; }
const string& getFavicon() const { return m_favicon; }
const string& getFaviconMimeType() const { return m_faviconMimeType; }
void setReadOnly(bool readOnly) { m_readOnly = readOnly; }
void setId(const std::string& id) { m_id = id; }

View File

@ -229,11 +229,11 @@ bool Library::addBook(const Book& book)
/* Try to find it */
std::vector<kiwix::Book>::iterator itr;
try {
auto& oldbook = books.at(book.id());
auto& oldbook = books.at(book.getId());
oldbook.update(book);
return false;
} catch (std::out_of_range&) {
books[book.id()] = book;
books[book.getId()] = book;
return true;
}
}
@ -255,8 +255,8 @@ unsigned int Library::getBookCount(const bool localBooks,
unsigned int result = 0;
for (auto& pair: books) {
auto& book = pair.second;
if ((!book.path().empty() && localBooks)
|| (book.path().empty() && remoteBooks)) {
if ((!book.getPath().empty() && localBooks)
|| (book.getPath().empty() && remoteBooks)) {
result++;
}
}
@ -272,8 +272,8 @@ Library Library::filter(const std::string& search) {
for(auto& pair:books) {
auto& book = pair.second;
if (matchRegex(book.title(), "\\Q" + search + "\\E")
|| matchRegex(book.description(), "\\Q" + search + "\\E")) {
if (matchRegex(book.getTitle(), "\\Q" + search + "\\E")
|| matchRegex(book.getDescription(), "\\Q" + search + "\\E")) {
library.addBook(book);
}
}
@ -283,6 +283,7 @@ Library Library::filter(const std::string& search) {
bool Library::writeToFile(const std::string& path) {
pugi::xml_document doc;
auto baseDir = removeLastPathElement(path, true, false);
/* Add the library node */
pugi::xml_node libraryNode = doc.append_child("library");
@ -295,67 +296,67 @@ bool Library::writeToFile(const std::string& path) {
auto& book = pair.second;
if (!book.readOnly()) {
pugi::xml_node bookNode = libraryNode.append_child("book");
bookNode.append_attribute("id") = book.id().c_str();
bookNode.append_attribute("id") = book.getId().c_str();
if (!book.path().empty()) {
if (!book.getPath().empty()) {
bookNode.append_attribute("path") = computeRelativePath(
removeLastPathElement(path, true, false), book.path()).c_str();
baseDir, book.getPath()).c_str();
}
if (!book.indexPath().empty()) {
if (!book.getIndexPath().empty()) {
bookNode.append_attribute("indexPath") = computeRelativePath(
removeLastPathElement(path, true, false), book.indexPath()).c_str();
baseDir, book.getIndexPath()).c_str();
bookNode.append_attribute("indexType") = "xapian";
}
if (book.origId().empty()) {
if (!book.title().empty())
bookNode.append_attribute("title") = book.title().c_str();
if (book.getOrigId().empty()) {
if (!book.getTitle().empty())
bookNode.append_attribute("title") = book.getTitle().c_str();
if (!book.name().empty())
bookNode.append_attribute("name") = book.name().c_str();
if (!book.getName().empty())
bookNode.append_attribute("name") = book.getName().c_str();
if (!book.tags().empty())
bookNode.append_attribute("tags") = book.tags().c_str();
if (!book.getTags().empty())
bookNode.append_attribute("tags") = book.getTags().c_str();
if (!book.description().empty())
bookNode.append_attribute("description") = book.description().c_str();
if (!book.getDescription().empty())
bookNode.append_attribute("description") = book.getDescription().c_str();
if (!book.language().empty())
bookNode.append_attribute("language") = book.language().c_str();
if (!book.getLanguage().empty())
bookNode.append_attribute("language") = book.getLanguage().c_str();
if (!book.creator().empty())
bookNode.append_attribute("creator") = book.creator().c_str();
if (!book.getCreator().empty())
bookNode.append_attribute("creator") = book.getCreator().c_str();
if (!book.publisher().empty())
bookNode.append_attribute("publisher") = book.publisher().c_str();
if (!book.getPublisher().empty())
bookNode.append_attribute("publisher") = book.getPublisher().c_str();
if (!book.favicon().empty())
bookNode.append_attribute("favicon") = base64_encode(book.favicon()).c_str();
if (!book.getFavicon().empty())
bookNode.append_attribute("favicon") = base64_encode(book.getFavicon()).c_str();
if (!book.faviconMimeType().empty())
if (!book.getFaviconMimeType().empty())
bookNode.append_attribute("faviconMimeType")
= book.faviconMimeType().c_str();
= book.getFaviconMimeType().c_str();
} else {
bookNode.append_attribute("origId") = book.origId().c_str();
bookNode.append_attribute("origId") = book.getOrigId().c_str();
}
if (!book.date().empty()) {
bookNode.append_attribute("date") = book.date().c_str();
if (!book.getDate().empty()) {
bookNode.append_attribute("date") = book.getDate().c_str();
}
if (!book.url().empty()) {
bookNode.append_attribute("url") = book.url().c_str();
if (!book.getUrl().empty()) {
bookNode.append_attribute("url") = book.getUrl().c_str();
}
if (!book.articleCount())
bookNode.append_attribute("articleCount") = to_string(book.articleCount()).c_str();
if (!book.getArticleCount())
bookNode.append_attribute("articleCount") = to_string(book.getArticleCount()).c_str();
if (!book.mediaCount())
bookNode.append_attribute("mediaCount") = to_string(book.mediaCount()).c_str();
if (!book.getMediaCount())
bookNode.append_attribute("mediaCount") = to_string(book.getMediaCount()).c_str();
if (!book.size()) {
bookNode.append_attribute("size") = to_string(book.size()).c_str();
if (!book.getSize()) {
bookNode.append_attribute("size") = to_string(book.getSize()).c_str();
}
}
}
@ -371,9 +372,9 @@ std::vector<std::string> Library::getBooksLanguages()
for (auto& pair: books) {
auto& book = pair.second;
auto& language = book.language();
auto& language = book.getLanguage();
if (booksLanguagesMap.find(language) == booksLanguagesMap.end()) {
if (book.origId().empty()) {
if (book.getOrigId().empty()) {
booksLanguagesMap[language] = true;
booksLanguages.push_back(language);
}
@ -390,9 +391,9 @@ std::vector<std::string> Library::getBooksCreators()
for (auto& pair: books) {
auto& book = pair.second;
auto& creator = book.creator();
auto& creator = book.getCreator();
if (booksCreatorsMap.find(creator) == booksCreatorsMap.end()) {
if (book.origId().empty()) {
if (book.getOrigId().empty()) {
booksCreatorsMap[creator] = true;
booksCreators.push_back(creator);
}
@ -420,9 +421,9 @@ std::vector<std::string> Library::getBooksPublishers()
for (auto& pair:books) {
auto& book = pair.second;
auto& publisher = book.publisher();
auto& publisher = book.getPublisher();
if (booksPublishersMap.find(publisher) == booksPublishersMap.end()) {
if (book.origId().empty()) {
if (book.getOrigId().empty()) {
booksPublishersMap[publisher] = true;
booksPublishers.push_back(publisher);
}

View File

@ -52,8 +52,8 @@ bool Manager::parseXmlDom(const pugi::xml_document& doc,
if (libraryVersion.empty()
|| atoi(libraryVersion.c_str()) <= atoi(KIWIX_LIBRARY_VERSION)) {
ok = false;
if (!book.path().empty()) {
ok = this->readBookFromPath(book.path());
if (!book.getPath().empty()) {
ok = this->readBookFromPath(book.getPath());
}
}
@ -183,11 +183,11 @@ string Manager::addBookFromPathAndGetId(const string pathToOpen,
}
if (!checkMetaData
|| (checkMetaData && !book.title().empty() && !book.language().empty()
&& !book.date().empty())) {
|| (checkMetaData && !book.getTitle().empty() && !book.getLanguage().empty()
&& !book.getDate().empty())) {
book.setUrl(url);
library->addBook(book);
return book.id();
return book.getId();
}
}

View File

@ -54,30 +54,30 @@ std::string gen_date_str()
pugi::xml_node OPDSDumper::handleBook(Book book, pugi::xml_node root_node) {
auto entry_node = root_node.append_child("entry");
ADD_TEXT_ENTRY(entry_node, "title", book.title());
ADD_TEXT_ENTRY(entry_node, "id", "urn:uuid:"+book.id());
ADD_TEXT_ENTRY(entry_node, "title", book.getTitle());
ADD_TEXT_ENTRY(entry_node, "id", "urn:uuid:"+book.getId());
ADD_TEXT_ENTRY(entry_node, "icon", rootLocation + "/meta?name=favicon&content=" + book.getHumanReadableIdFromPath());
ADD_TEXT_ENTRY(entry_node, "updated", date);
ADD_TEXT_ENTRY(entry_node, "summary", book.description());
ADD_TEXT_ENTRY(entry_node, "summary", book.getDescription());
auto content_node = entry_node.append_child("link");
content_node.append_attribute("type") = "text/html";
content_node.append_attribute("href") = (rootLocation + "/" + book.getHumanReadableIdFromPath()).c_str();
auto author_node = entry_node.append_child("author");
ADD_TEXT_ENTRY(author_node, "name", book.creator());
ADD_TEXT_ENTRY(author_node, "name", book.getCreator());
if (! book.url().empty()) {
if (! book.getUrl().empty()) {
auto acquisition_link = entry_node.append_child("link");
acquisition_link.append_attribute("rel") = "http://opds-spec.org/acquisition/open-access";
acquisition_link.append_attribute("type") = "application/x-zim";
acquisition_link.append_attribute("href") = book.url().c_str();
acquisition_link.append_attribute("href") = book.getUrl().c_str();
}
if (! book.faviconMimeType().empty() ) {
if (! book.getFaviconMimeType().empty() ) {
auto image_link = entry_node.append_child("link");
image_link.append_attribute("rel") = "http://opds-spec.org/image/thumbnail";
image_link.append_attribute("type") = book.faviconMimeType().c_str();
image_link.append_attribute("type") = book.getFaviconMimeType().c_str();
image_link.append_attribute("href") = (rootLocation + "/meta?name=favicon&content=" + book.getHumanReadableIdFromPath()).c_str();
}
return entry_node;