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