MythTV  master
mythrssmanager.h
Go to the documentation of this file.
1 #ifndef MYTHRSSMANAGER_H
2 #define MYTHRSSMANAGER_H
3 
4 #include <vector>
5 
6 #include <QObject>
7 #include <QMetaType>
8 #include <QMutex>
9 #include <QTimer>
10 #include <QDateTime>
11 #include <QByteArray>
12 #include <QVariant>
13 #include <QNetworkReply>
14 
15 #include "rssparse.h"
16 
17 
18 class RSSSite;
19 class MPUBLIC RSSSite : public QObject
20 {
21  Q_OBJECT
22 
23  public:
24 
25  class List : public std::vector<RSSSite*>
26  {
27  public:
28  void clear(void)
29  {
30  while (!empty())
31  {
32  RSSSite *tmp = back();
33  pop_back();
34  tmp->deleteLater();
35  }
36  }
37  };
38 
39  RSSSite(QString title,
40  QString sortTitle,
41  QString image,
42  const ArticleType& type,
43  QString description,
44  QString url,
45  QString author,
46  const bool& download,
47  QDateTime updated);
48 
49  ~RSSSite() override = default;
50 
51  using rssList = QList<RSSSite *>;
52 
53  const QString& GetTitle() const { return m_title; }
54  const QString& GetSortTitle() const { return m_sortTitle; }
55  const QString& GetImage() const { return m_image; }
56  const ArticleType& GetType() const { return m_type; }
57  const QString& GetDescription() const { return m_description; }
58  const QString& GetURL() const { return m_url; }
59  const QString& GetAuthor() const { return m_author; }
60  const bool& GetDownload() const { return m_download; }
61  const QDateTime& GetUpdated() const { return m_updated; }
62 
63  unsigned int timeSinceLastUpdate(void) const; // in minutes
64 
65  void insertRSSArticle(ResultItem *item);
66  void clearRSSArticles(void);
67 
68  ResultItem::resultList GetVideoList(void) const;
69 
70  void retrieve(void);
71  void stop(void);
72  void process(void);
73 
74  private:
75 
76  static QUrl redirectUrl(const QUrl& possibleRedirectUrl,
77  const QUrl& oldRedirectUrl) ;
78 
79  QString m_title;
80  QString m_sortTitle;
81  QString m_image;
83  QString m_description;
84  QString m_url;
85  QUrl m_urlReq;
86  QString m_author;
87  bool m_download;
88  QDateTime m_updated;
89 
90  mutable QMutex m_lock {QMutex::Recursive};
91  QByteArray m_data;
92  QString m_imageURL;
93  bool m_podcast {false};
94 
96 
97  QNetworkReply *m_reply {nullptr};
98  QNetworkAccessManager *m_manager {nullptr};
99 
100  private slots:
101  void slotCheckRedirect(QNetworkReply* reply);
102 
103  signals:
104 
105  void finished(RSSSite *item);
106 
107 };
108 
109 class MPUBLIC RSSManager : public QObject
110 {
111  Q_OBJECT
112 
113  public:
114  RSSManager();
115  ~RSSManager() override;
116  void startTimer();
117  void stopTimer();
118 
119  signals:
120  void finished();
121 
122  public slots:
123  void doUpdate();
124 
125  private slots:
126  void slotRefreshRSS(void);
127  void slotRSSRetrieved(RSSSite *site);
128 
129  private:
130  void processAndInsertRSS(RSSSite *site);
131 
132  QTimer *m_timer {nullptr};
134  uint m_updateFreq {6 * 3600 * 1000};
136 };
137 
139 
140 #endif
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(GrabberScript *)
MPUBLIC
#define MPUBLIC
Definition: mythexp.h:10
RSSSite::GetDownload
const bool & GetDownload() const
Definition: mythrssmanager.h:60
back
static guint32 * back
Definition: goom_core.cpp:29
RSSSite::GetSortTitle
const QString & GetSortTitle() const
Definition: mythrssmanager.h:54
RSSSite::m_author
QString m_author
Definition: mythrssmanager.h:86
RSSSite::List
Definition: mythrssmanager.h:25
title
QString title
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:633
RSSManager
Definition: mythrssmanager.h:109
rssparse.h
RSSSite::GetType
const ArticleType & GetType() const
Definition: mythrssmanager.h:56
slots
unsigned int slots[4]
Definition: element.cpp:38
RSSSite::GetDescription
const QString & GetDescription() const
Definition: mythrssmanager.h:57
RSSManager::m_inprogress
RSSSite::rssList m_inprogress
Definition: mythrssmanager.h:135
RSSSite::m_description
QString m_description
Definition: mythrssmanager.h:83
RSSSite::m_image
QString m_image
Definition: mythrssmanager.h:81
RSSSite::m_title
QString m_title
Definition: mythrssmanager.h:79
tmp
static guint32 * tmp
Definition: goom_core.cpp:30
RSSSite::m_urlReq
QUrl m_urlReq
Definition: mythrssmanager.h:85
RSSSite::m_url
QString m_url
Definition: mythrssmanager.h:84
RSSSite::m_data
QByteArray m_data
Definition: mythrssmanager.h:91
RSSSite::m_type
ArticleType m_type
Definition: mythrssmanager.h:82
RSSManager::m_sites
RSSSite::rssList m_sites
Definition: mythrssmanager.h:133
RSSSite::List::clear
void clear(void)
Definition: mythrssmanager.h:28
uint
unsigned int uint
Definition: compat.h:140
RSSSite::GetAuthor
const QString & GetAuthor() const
Definition: mythrssmanager.h:59
ArticleType
ArticleType
Definition: rssparse.h:20
RSSSite::m_articleList
ResultItem::resultList m_articleList
Definition: mythrssmanager.h:95
RSSSite::GetUpdated
const QDateTime & GetUpdated() const
Definition: mythrssmanager.h:61
RSSSite::GetImage
const QString & GetImage() const
Definition: mythrssmanager.h:55
RSSSite::m_download
bool m_download
Definition: mythrssmanager.h:87
ResultItem
Definition: rssparse.h:109
RSSSite::GetTitle
const QString & GetTitle() const
Definition: mythrssmanager.h:53
RSSSite::m_updated
QDateTime m_updated
Definition: mythrssmanager.h:88
RSSSite::m_imageURL
QString m_imageURL
Definition: mythrssmanager.h:92
ResultItem::resultList
QList< ResultItem * > resultList
Definition: rssparse.h:114
clearRSSArticles
bool clearRSSArticles(const QString &feedtitle, ArticleType type)
Definition: netutils.cpp:722
RSSSite::m_sortTitle
QString m_sortTitle
Definition: mythrssmanager.h:80
RSSSite::GetURL
const QString & GetURL() const
Definition: mythrssmanager.h:58
RSSSite
Definition: mythrssmanager.h:19
RSSSite::rssList
QList< RSSSite * > rssList
Definition: mythrssmanager.h:51