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