MythTV  master
netgrabbermanager.h
Go to the documentation of this file.
1 #ifndef NETGRABBERMANAGER_H
2 #define NETGRABBERMANAGER_H
3 
4 #include <QObject>
5 #include <QEvent>
6 #include <QDomElement>
7 #include "mthread.h"
8 #include <QMetaType>
9 #include <QMutex>
10 #if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
11 #include <QRecursiveMutex>
12 #endif
13 #include <QTimer>
14 
15 #include "rssparse.h"
16 #include "mythexp.h"
17 #include "mythsystemlegacy.h"
18 
19 class MPUBLIC GrabberScript : public QObject, public MThread
20 {
21 
22  Q_OBJECT
23 
24  public:
25 
26  GrabberScript(const QString& title,
27  const QString& image,
29  const QString& author,
30  bool search,
31  bool tree,
32  const QString& description,
33  const QString& commandline,
34  double version);
35  ~GrabberScript() override;
36 
37  const QString& GetTitle() const { return m_title; }
38  const QString& GetImage() const { return m_image; }
39  const ArticleType& GetType() const { return m_type; }
40  const QString& GetAuthor() const { return m_author; }
41  const bool& GetSearch() const { return m_search; }
42  const bool& GetTree() const { return m_tree; }
43  const QString& GetDescription() const { return m_description; }
44  const QString& GetCommandline() const { return m_commandline; }
45  const double& GetVersion() const { return m_version; }
46 
47  void run(void) override; // MThread
48 
49  using scriptList = QList<GrabberScript *>;
50 
51  signals:
52 
53  void finished(void);
54 
55  private:
56 
57  void parseDBTree(const QString &feedtitle, const QString &path,
58  const QString &pathThumb, QDomElement& domElem,
60 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
61  mutable QMutex m_lock {QMutex::Recursive};
62 #else
63  mutable QRecursiveMutex m_lock;
64 #endif
65 
66  QString m_title;
67  QString m_image;
69  QString m_author;
70  bool m_search;
71  bool m_tree;
72  QString m_description;
73  QString m_commandline;
74  double m_version;
75 };
77 
78 class MPUBLIC GrabberManager : public QObject
79 {
80  Q_OBJECT
81 
82  public:
84  ~GrabberManager() override;
85  void startTimer();
86  void stopTimer();
87  void doUpdate();
88  void refreshAll();
89 
90  signals:
91  void finished(void);
92 
93  private slots:
94  void timeout(void);
95 
96  private:
97 
98 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
99  mutable QMutex m_lock {QMutex::Recursive};
100 #else
101  mutable QRecursiveMutex m_lock;
102 #endif
103  QTimer *m_timer {nullptr};
105  std::chrono::hours m_updateFreq {24h};
106  uint m_runningCount {0};
107  bool m_refreshAll {false};
108 };
109 
110 const int kGrabberUpdateEventType = QEvent::User + 5000;
111 
112 class MPUBLIC GrabberUpdateEvent : public QEvent
113 {
114  public:
116  : QEvent((QEvent::Type)kGrabberUpdateEventType) {}
117  ~GrabberUpdateEvent() override = default;
118 };
119 
120 class MPUBLIC GrabberDownloadThread : public QObject, public MThread
121 {
122  Q_OBJECT
123 
124  public:
125 
126  explicit GrabberDownloadThread(QObject *parent);
127  ~GrabberDownloadThread() override;
128 
129  void refreshAll();
130  void cancel();
131 
132  signals:
133  void finished();
134 
135  protected:
136 
137  void run() override; // MThread
138 
139  private:
140 
141  QObject *m_parent {nullptr};
142  QList<GrabberScript*> m_scripts;
143  QMutex m_mutex;
144  bool m_refreshAll {false};
145 
146 };
147 
148 class MPUBLIC Search : public QObject
149 {
150  friend class MRSSParser;
151  Q_OBJECT
152 
153  public:
154 
155  Search();
156  ~Search() override;
157 
158  void resetSearch(void);
159  void executeSearch(const QString &script, const QString &query,
160  const QString &pagenum = "");
161  void process(void);
162 
163  QByteArray GetData() { return m_data; };
164  void SetData(QByteArray data);
165 
166  uint numResults() const { return m_numResults; };
167  uint numReturned() const { return m_numReturned; };
168  uint numIndex() const { return m_numIndex; };
169  QString nextPageToken() { return m_nextPageToken; }
170  QString prevPageToken() { return m_prevPageToken; }
171 
172  ResultItem::resultList GetVideoList() { return m_videoList; };
173 
174  private:
175 
176  MythSystemLegacy *m_searchProcess {nullptr};
177 
178  QByteArray m_data;
179  QDomDocument m_document;
181 
182  uint m_numResults {0};
183  uint m_numReturned {0};
184  uint m_numIndex {0};
185 
188 
189  signals:
190 
191  void finishedSearch(Search *item);
192  void searchTimedOut(Search *item);
193 
194  private slots:
195  void slotProcessSearchExit(uint exitcode);
196  void slotProcessSearchExit(void);
197 };
198 
199 #endif
GrabberScript::GetType
const ArticleType & GetType() const
Definition: netgrabbermanager.h:39
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(GrabberScript *)
GrabberScript::m_lock
QRecursiveMutex m_lock
Definition: netgrabbermanager.h:63
MPUBLIC
#define MPUBLIC
Definition: mythexp.h:10
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
GrabberScript::m_type
ArticleType m_type
Definition: netgrabbermanager.h:68
GrabberScript::GetAuthor
const QString & GetAuthor() const
Definition: netgrabbermanager.h:40
GrabberScript::GetCommandline
const QString & GetCommandline() const
Definition: netgrabbermanager.h:44
MythSystemLegacy
Definition: mythsystemlegacy.h:67
GrabberScript::m_author
QString m_author
Definition: netgrabbermanager.h:69
mythexp.h
Search::numReturned
uint numReturned() const
Definition: netgrabbermanager.h:167
GrabberScript::m_search
bool m_search
Definition: netgrabbermanager.h:70
rssparse.h
Search::m_videoList
ResultItem::resultList m_videoList
Definition: netgrabbermanager.h:180
GrabberManager::m_scripts
GrabberScript::scriptList m_scripts
Definition: netgrabbermanager.h:104
GrabberScript::GetImage
const QString & GetImage() const
Definition: netgrabbermanager.h:38
GrabberScript::GetDescription
const QString & GetDescription() const
Definition: netgrabbermanager.h:43
GrabberScript::GetTitle
const QString & GetTitle() const
Definition: netgrabbermanager.h:37
GrabberScript::m_commandline
QString m_commandline
Definition: netgrabbermanager.h:73
Search::m_nextPageToken
QString m_nextPageToken
Definition: netgrabbermanager.h:186
GrabberManager
Definition: netgrabbermanager.h:78
Search::prevPageToken
QString prevPageToken()
Definition: netgrabbermanager.h:170
Search::GetVideoList
ResultItem::resultList GetVideoList()
Definition: netgrabbermanager.h:172
GrabberScript::m_description
QString m_description
Definition: netgrabbermanager.h:72
mythsystemlegacy.h
GrabberScript::scriptList
QList< GrabberScript * > scriptList
Definition: netgrabbermanager.h:49
Search::m_document
QDomDocument m_document
Definition: netgrabbermanager.h:179
Search::m_prevPageToken
QString m_prevPageToken
Definition: netgrabbermanager.h:187
GrabberUpdateEvent::GrabberUpdateEvent
GrabberUpdateEvent(void)
Definition: netgrabbermanager.h:115
GrabberManager::m_lock
QRecursiveMutex m_lock
Definition: netgrabbermanager.h:101
GrabberScript
Definition: netgrabbermanager.h:19
GrabberUpdateEvent
Definition: netgrabbermanager.h:112
Search::nextPageToken
QString nextPageToken()
Definition: netgrabbermanager.h:169
GrabberScript::m_title
QString m_title
Definition: netgrabbermanager.h:66
uint
unsigned int uint
Definition: compat.h:144
Search
Definition: netgrabbermanager.h:148
GrabberScript::m_image
QString m_image
Definition: netgrabbermanager.h:67
kGrabberUpdateEventType
const int kGrabberUpdateEventType
Definition: netgrabbermanager.h:110
MThread::run
virtual void run(void)
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Definition: mthread.cpp:318
GrabberScript::m_version
double m_version
Definition: netgrabbermanager.h:74
GrabberScript::m_tree
bool m_tree
Definition: netgrabbermanager.h:71
ArticleType
ArticleType
Definition: rssparse.h:20
GrabberScript::GetVersion
const double & GetVersion() const
Definition: netgrabbermanager.h:45
Search::GetData
QByteArray GetData()
Definition: netgrabbermanager.h:163
GrabberScript::GetTree
const bool & GetTree() const
Definition: netgrabbermanager.h:42
Search::m_data
QByteArray m_data
Definition: netgrabbermanager.h:178
GrabberDownloadThread::m_mutex
QMutex m_mutex
Definition: netgrabbermanager.h:143
MRSSParser
Definition: rssparse.cpp:193
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:48
mthread.h
ResultItem::resultList
QList< ResultItem * > resultList
Definition: rssparse.h:114
GrabberDownloadThread::m_scripts
QList< GrabberScript * > m_scripts
Definition: netgrabbermanager.h:142
Search::numIndex
uint numIndex() const
Definition: netgrabbermanager.h:168
GrabberScript::GetSearch
const bool & GetSearch() const
Definition: netgrabbermanager.h:41
Search::numResults
uint numResults() const
Definition: netgrabbermanager.h:166
nv_python_libs.bbciplayer.bbciplayer_api.version
string version
Definition: bbciplayer_api.py:81
GrabberDownloadThread
Definition: netgrabbermanager.h:120