mirror of https://github.com/kiwix/libkiwix.git
Move the code updating a book from a reader in the Book class.
This commit is contained in:
parent
04b05dd68b
commit
66a9a69480
|
@ -38,6 +38,7 @@ namespace kiwix
|
|||
enum supportedIndexType { UNKNOWN, XAPIAN };
|
||||
|
||||
class OPDSDumper;
|
||||
class Reader;
|
||||
|
||||
/**
|
||||
* A class to store information about a book (a zim file)
|
||||
|
@ -49,6 +50,7 @@ class Book
|
|||
~Book();
|
||||
|
||||
bool update(const Book& other);
|
||||
void update(const Reader& reader);
|
||||
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);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
#include "library.h"
|
||||
#include "reader.h"
|
||||
|
||||
#include <pugixml.hpp>
|
||||
|
||||
|
@ -97,6 +98,26 @@ bool Book::update(const kiwix::Book& other)
|
|||
return true;
|
||||
}
|
||||
|
||||
void Book::update(const kiwix::Reader& reader)
|
||||
{
|
||||
m_path = reader.getZimFilePath();
|
||||
m_id = reader.getId();
|
||||
m_description = reader.getDescription();
|
||||
m_language = reader.getLanguage();
|
||||
m_date = reader.getDate();
|
||||
m_creator = reader.getCreator();
|
||||
m_publisher = reader.getPublisher();
|
||||
m_title = reader.getTitle();
|
||||
m_name = reader.getName();
|
||||
m_tags = reader.getTags();
|
||||
m_origId = reader.getOrigId();
|
||||
m_articleCount = reader.getArticleCount();
|
||||
m_mediaCount = reader.getMediaCount();
|
||||
m_size = reader.getFileSize();
|
||||
|
||||
reader.getFavicon(m_favicon, m_faviconMimeType);
|
||||
}
|
||||
|
||||
std::string Book::getHumanReadableIdFromPath()
|
||||
{
|
||||
std::string id = m_path;
|
||||
|
|
|
@ -244,35 +244,8 @@ bool Manager::addBookFromPath(const string pathToOpen,
|
|||
bool Manager::readBookFromPath(const string path, kiwix::Book* book)
|
||||
{
|
||||
try {
|
||||
kiwix::Reader* reader = new kiwix::Reader(path);
|
||||
|
||||
if (book != NULL) {
|
||||
book->setPath(path);
|
||||
book->setId(reader->getId());
|
||||
book->setDescription(reader->getDescription());
|
||||
book->setLanguage(reader->getLanguage());
|
||||
book->setDate(reader->getDate());
|
||||
book->setCreator(reader->getCreator());
|
||||
book->setPublisher(reader->getPublisher());
|
||||
book->setTitle(reader->getTitle());
|
||||
book->setName(reader->getName());
|
||||
book->setTags(reader->getTags());
|
||||
book->setOrigId(reader->getOrigId());
|
||||
book->setArticleCount(reader->getArticleCount());
|
||||
book->setMediaCount(reader->getMediaCount());
|
||||
book->setSize(reader->getFileSize());
|
||||
|
||||
string favicon;
|
||||
string faviconMimeType;
|
||||
if (reader->getFavicon(favicon, faviconMimeType)) {
|
||||
book->setFavicon(base64_encode(
|
||||
reinterpret_cast<const unsigned char*>(favicon.c_str()),
|
||||
favicon.length()));
|
||||
book->setFaviconMimeType(faviconMimeType);
|
||||
}
|
||||
}
|
||||
|
||||
delete reader;
|
||||
kiwix::Reader reader(path);
|
||||
book->update(reader);
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue