1 /*
2  * Copyright 2011 Emmanuel Engelhart <kelson@kiwix.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU  General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17  * MA 02110-1301, USA.
18  */
19 
20 #ifndef KIWIX_BOOK_H
21 #define KIWIX_BOOK_H
22 
23 #include <string>
24 
25 namespace pugi {
26 class xml_node;
27 }
28 
29 namespace kiwix
30 {
31 
32 class OPDSDumper;
33 class Reader;
34 
35 /**
36  * A class to store information about a book (a zim file)
37  */
38 class Book
39 {
40  public:
41   Book();
42   ~Book();
43 
44   bool update(const Book& other);
45   void update(const Reader& reader);
46   void updateFromXml(const pugi::xml_node& node, const std::string& baseDir);
47   void updateFromOpds(const pugi::xml_node& node, const std::string& urlHost);
48   std::string getHumanReadableIdFromPath() const;
49 
readOnly()50   bool readOnly() const { return m_readOnly; }
getId()51   const std::string& getId() const { return m_id; }
getPath()52   const std::string& getPath() const { return m_path; }
isPathValid()53   bool isPathValid() const { return m_pathValid; }
getTitle()54   const std::string& getTitle() const { return m_title; }
getDescription()55   const std::string& getDescription() const { return m_description; }
getLanguage()56   const std::string& getLanguage() const { return m_language; }
getCreator()57   const std::string& getCreator() const { return m_creator; }
getPublisher()58   const std::string& getPublisher() const { return m_publisher; }
getDate()59   const std::string& getDate() const { return m_date; }
getUrl()60   const std::string& getUrl() const { return m_url; }
getName()61   const std::string& getName() const { return m_name; }
getTags()62   const std::string& getTags() const { return m_tags; }
63   std::string getTagStr(const std::string& tagName) const;
64   bool getTagBool(const std::string& tagName) const;
getFlavour()65   const std::string& getFlavour() const { return m_flavour; }
getOrigId()66   const std::string& getOrigId() const { return m_origId; }
getArticleCount()67   const uint64_t& getArticleCount() const { return m_articleCount; }
getMediaCount()68   const uint64_t& getMediaCount() const { return m_mediaCount; }
getSize()69   const uint64_t& getSize() const { return m_size; }
70   const std::string& getFavicon() const;
getFaviconUrl()71   const std::string& getFaviconUrl() const { return m_faviconUrl; }
getFaviconMimeType()72   const std::string& getFaviconMimeType() const { return m_faviconMimeType; }
getDownloadId()73   const std::string& getDownloadId() const { return m_downloadId; }
74 
setReadOnly(bool readOnly)75   void setReadOnly(bool readOnly) { m_readOnly = readOnly; }
setId(const std::string & id)76   void setId(const std::string& id) { m_id = id; }
77   void setPath(const std::string& path);
setPathValid(bool valid)78   void setPathValid(bool valid) { m_pathValid = valid; }
setTitle(const std::string & title)79   void setTitle(const std::string& title) { m_title = title; }
setDescription(const std::string & description)80   void setDescription(const std::string& description) { m_description = description; }
setLanguage(const std::string & language)81   void setLanguage(const std::string& language) { m_language = language; }
setCreator(const std::string & creator)82   void setCreator(const std::string& creator) { m_creator = creator; }
setPublisher(const std::string & publisher)83   void setPublisher(const std::string& publisher) { m_publisher = publisher; }
setDate(const std::string & date)84   void setDate(const std::string& date) { m_date = date; }
setUrl(const std::string & url)85   void setUrl(const std::string& url) { m_url = url; }
setName(const std::string & name)86   void setName(const std::string& name) { m_name = name; }
setFlavour(const std::string & flavour)87   void setFlavour(const std::string& flavour) { m_flavour = flavour; }
setTags(const std::string & tags)88   void setTags(const std::string& tags) { m_tags = tags; }
setOrigId(const std::string & origId)89   void setOrigId(const std::string& origId) { m_origId = origId; }
setArticleCount(uint64_t articleCount)90   void setArticleCount(uint64_t articleCount) { m_articleCount = articleCount; }
setMediaCount(uint64_t mediaCount)91   void setMediaCount(uint64_t mediaCount) { m_mediaCount = mediaCount; }
setSize(uint64_t size)92   void setSize(uint64_t size) { m_size = size; }
setFavicon(const std::string & favicon)93   void setFavicon(const std::string& favicon) { m_favicon = favicon; }
setFaviconMimeType(const std::string & faviconMimeType)94   void setFaviconMimeType(const std::string& faviconMimeType) { m_faviconMimeType = faviconMimeType; }
setDownloadId(const std::string & downloadId)95   void setDownloadId(const std::string& downloadId) { m_downloadId = downloadId; }
96 
97  protected:
98   std::string m_id;
99   std::string m_downloadId;
100   std::string m_path;
101   bool m_pathValid = false;
102   std::string m_title;
103   std::string m_description;
104   std::string m_language;
105   std::string m_creator;
106   std::string m_publisher;
107   std::string m_date;
108   std::string m_url;
109   std::string m_name;
110   std::string m_flavour;
111   std::string m_tags;
112   std::string m_origId;
113   uint64_t m_articleCount = 0;
114   uint64_t m_mediaCount = 0;
115   bool m_readOnly = false;
116   uint64_t m_size = 0;
117   mutable std::string m_favicon;
118   std::string m_faviconUrl;
119   std::string m_faviconMimeType;
120 };
121 
122 }
123 
124 #endif
125