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