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