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