MythTV  master
newssite.h
Go to the documentation of this file.
1 #ifndef NEWSSITE_H
2 #define NEWSSITE_H
3 
4 // C++ headers
5 #include <vector>
6 
7 // QT headers
8 #include <QByteArray>
9 #include <QDateTime>
10 #include <QDomDocument>
11 #include <QObject>
12 #include <QString>
13 #include <QUrl>
14 #include <QVariant>
15 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
16 #include <QMutex>
17 #else
18 #include <QRecursiveMutex>
19 #endif
20 
21 // MythTV headers
22 #include <libmythbase/stringutil.h>
23 
24 // MythNews headers
25 #include "newsarticle.h"
26 
28 {
29  public:
30  using List = std::vector<NewsSiteItem>;
31 
32  QString m_name;
33  QString m_category;
34  QString m_url;
35  QString m_ico;
36  bool m_inDB { false };
37  bool m_podcast { false };
38 };
40 
42 {
43  public:
44  using List = std::vector<NewsCategory>;
45 
46  QString m_name;
48 
49  void clear(void) { m_siteList.clear(); }
50 };
52 
53 class NewsSite;
54 class NewsSite : public QObject
55 {
56  Q_OBJECT
57 
58  public:
59 
60  enum State {
65  };
66 
67  class List : public std::vector<NewsSite*>
68  {
69  public:
70  void clear(void)
71  {
72  while (!empty())
73  {
74  NewsSite *tmp = back();
75  pop_back();
76  tmp->deleteLater();
77  }
78  }
79  };
80 
81  NewsSite(QString name, const QString &url,
82  QDateTime updated, bool podcast);
83  virtual void deleteLater();
84 
85  void customEvent(QEvent *event) override; // QObject
86 
87  QString url(void) const;
88  QString name(void) const;
89  QString sortName(void) const;
90  QString description(void) const;
91  QDateTime lastUpdated(void) const;
92  QString imageURL(void) const;
93  bool podcast(void) const;
94  std::chrono::minutes timeSinceLastUpdate(void) const;
95 
96  void insertNewsArticle(const NewsArticle &item);
97  void clearNewsArticles(void);
98 
100 
101  void retrieve(void);
102  void stop(void);
103  void process(void);
104  void parseRSS(const QDomDocument& domDoc);
105  void parseAtom(const QDomDocument& domDoc);
106  static inline bool sortByName(NewsSite *a, NewsSite *b)
107  { return StringUtil::naturalCompare(a->m_sortName, b->m_sortName) < 0; }
108 
109  bool successful(void) const;
110  QString errorMsg(void) const;
111 
112  private:
113  ~NewsSite() override;
114 
115 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
116  mutable QMutex m_lock {QMutex::Recursive};
117 #else
118  mutable QRecursiveMutex m_lock;
119 #endif
120  QString m_name;
121  QString m_sortName;
122  QString m_url;
123  QUrl m_urlReq;
124  QString m_desc;
125  QDateTime m_updated;
126  QString m_destDir;
127  QByteArray m_data;
129  QString m_errorString;
131  QString m_imageURL;
132  bool m_podcast;
133 
135  static QString ReplaceHtmlChar(const QString &orig);
136 
137  signals:
138 
139  void finished(NewsSite *item);
140 };
142 
143 #endif // NEWSSITE_H
NewsSite::Success
@ Success
Definition: newssite.h:64
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(GrabberScript *)
NewsSite::stop
void stop(void)
Definition: newssite.cpp:71
NewsSite::url
QString url(void) const
Definition: newssite.cpp:90
NewsSite::imageURL
QString imageURL(void) const
Definition: newssite.cpp:128
NewsSiteItem::m_inDB
bool m_inDB
Definition: newssite.h:36
NewsCategory
Definition: newssite.h:41
NewsSite::RetrieveFailed
@ RetrieveFailed
Definition: newssite.h:62
NewsSite::podcast
bool podcast(void) const
Definition: newssite.cpp:108
back
static guint32 * back
Definition: goom_core.cpp:25
NewsSite::List::clear
void clear(void)
Definition: newssite.h:70
NewsSiteItem::m_category
QString m_category
Definition: newssite.h:33
NewsSite::customEvent
void customEvent(QEvent *event) override
Definition: newssite.cpp:155
NewsSite::finished
void finished(NewsSite *item)
NewsCategory::m_siteList
NewsSiteItem::List m_siteList
Definition: newssite.h:47
NewsSite::description
QString description(void) const
Definition: newssite.cpp:114
NewsSite::m_data
QByteArray m_data
Definition: newssite.h:127
NewsCategory::List
std::vector< NewsCategory > List
Definition: newssite.h:44
NewsSiteItem::m_podcast
bool m_podcast
Definition: newssite.h:37
NewsSite::sortByName
static bool sortByName(NewsSite *a, NewsSite *b)
Definition: newssite.h:106
NewsSite::m_articleList
NewsArticle::List m_articleList
Definition: newssite.h:134
NewsSite::ReplaceHtmlChar
static QString ReplaceHtmlChar(const QString &orig)
Definition: newssite.cpp:492
tmp
static guint32 * tmp
Definition: goom_core.cpp:26
NewsSite::Retrieving
@ Retrieving
Definition: newssite.h:61
NewsSiteItem
Definition: newssite.h:27
NewsSite::m_urlReq
QUrl m_urlReq
Definition: newssite.h:123
NewsSite::m_destDir
QString m_destDir
Definition: newssite.h:126
NewsCategory::clear
void clear(void)
Definition: newssite.h:49
NewsSite::m_updateErrorString
QString m_updateErrorString
Definition: newssite.h:130
NewsSite::m_podcast
bool m_podcast
Definition: newssite.h:132
NewsSite::m_state
State m_state
Definition: newssite.h:128
NewsSite::m_lock
QRecursiveMutex m_lock
Definition: newssite.h:118
NewsSiteItem::m_url
QString m_url
Definition: newssite.h:34
NewsArticle
Definition: newsarticle.h:10
NewsSite::WriteFailed
@ WriteFailed
Definition: newssite.h:63
NewsSite::errorMsg
QString errorMsg(void) const
Definition: newssite.cpp:84
NewsSite::m_imageURL
QString m_imageURL
Definition: newssite.h:131
NewsSite::timeSinceLastUpdate
std::chrono::minutes timeSinceLastUpdate(void) const
Definition: newssite.cpp:146
StringUtil::naturalCompare
MBASE_PUBLIC int naturalCompare(const QString &_a, const QString &_b, Qt::CaseSensitivity caseSensitivity=Qt::CaseSensitive)
This method chops the input a and b into pieces of digits and non-digits (a1.05 becomes a | 1 | .
Definition: stringutil.cpp:160
NewsSite::clearNewsArticles
void clearNewsArticles(void)
Definition: newssite.cpp:52
stringutil.h
NewsSite::name
QString name(void) const
Definition: newssite.cpp:96
NewsSite::lastUpdated
QDateTime lastUpdated(void) const
Definition: newssite.cpp:140
NewsSite::GetArticleList
NewsArticle::List GetArticleList(void) const
Definition: newssite.cpp:134
NewsSite::State
State
Definition: newssite.h:60
NewsSite::m_errorString
QString m_errorString
Definition: newssite.h:129
NewsSite
Definition: newssite.h:54
NewsSiteItem::m_name
QString m_name
Definition: newssite.h:32
NewsSite::process
void process(void)
Definition: newssite.cpp:225
NewsSite::List
Definition: newssite.h:67
NewsArticle::List
std::vector< NewsArticle > List
Definition: newsarticle.h:13
NewsSite::m_name
QString m_name
Definition: newssite.h:120
NewsSite::retrieve
void retrieve(void)
Definition: newssite.cpp:58
NewsSite::deleteLater
virtual void deleteLater()
Definition: newssite.cpp:30
NewsSite::m_url
QString m_url
Definition: newssite.h:122
NewsSite::m_desc
QString m_desc
Definition: newssite.h:124
NewsSite::insertNewsArticle
void insertNewsArticle(const NewsArticle &item)
Definition: newssite.cpp:46
NewsSite::~NewsSite
~NewsSite() override
Definition: newssite.cpp:39
NewsSite::NewsSite
NewsSite(QString name, const QString &url, QDateTime updated, bool podcast)
Definition: newssite.cpp:19
NewsSiteItem::m_ico
QString m_ico
Definition: newssite.h:35
NewsSite::m_sortName
QString m_sortName
Definition: newssite.h:121
NewsSiteItem::List
std::vector< NewsSiteItem > List
Definition: newssite.h:30
NewsCategory::m_name
QString m_name
Definition: newssite.h:46
NewsSite::m_updated
QDateTime m_updated
Definition: newssite.h:125
NewsSite::parseAtom
void parseAtom(const QDomDocument &domDoc)
Definition: newssite.cpp:461
newsarticle.h
NewsSite::successful
bool successful(void) const
Definition: newssite.cpp:78
NewsSite::parseRSS
void parseRSS(const QDomDocument &domDoc)
Definition: newssite.cpp:305
NewsSite::sortName
QString sortName(void) const
Definition: newssite.cpp:102