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 #include <QTimer>
11 
12 #include "rssparse.h"
13 #include "mythexp.h"
14 #include "mythsystemlegacy.h"
15 
16 class MPUBLIC GrabberScript : public QObject, public MThread
17 {
18 
19  Q_OBJECT
20 
21  public:
22 
23  GrabberScript(const QString& title,
24  const QString& image,
25  const ArticleType& type,
26  const QString& author,
27  const bool& search,
28  const bool& tree,
29  const QString& description,
30  const QString& commandline,
31  const double& version);
32  ~GrabberScript();
33 
34  const QString& GetTitle() const { return m_title; }
35  const QString& GetImage() const { return m_image; }
36  const ArticleType& GetType() const { return m_type; }
37  const QString& GetAuthor() const { return m_author; }
38  const bool& GetSearch() const { return m_search; }
39  const bool& GetTree() const { return m_tree; }
40  const QString& GetDescription() const { return m_description; }
41  const QString& GetCommandline() const { return m_commandline; }
42  const double& GetVersion() const { return m_version; }
43 
44  void run(void) override; // MThread
45 
46  typedef QList<GrabberScript *> scriptList;
47 
48  signals:
49 
50  void finished(void);
51 
52  private:
53 
54  void parseDBTree(const QString &feedtitle, const QString &path,
55  const QString &pathThumb, QDomElement& domElem,
56  const ArticleType &type);
57  mutable QMutex m_lock {QMutex::Recursive};
58 
59  QString m_title;
60  QString m_image;
62  QString m_author;
63  bool m_search;
64  bool m_tree;
65  QString m_description;
66  QString m_commandline;
67  double m_version;
68 };
70 
71 class MPUBLIC GrabberManager : public QObject
72 {
73  Q_OBJECT
74 
75  public:
77  ~GrabberManager();
78  void startTimer();
79  void stopTimer();
80  void doUpdate();
81  void refreshAll();
82 
83  signals:
84  void finished(void);
85 
86  private slots:
87  void timeout(void);
88 
89  private:
90 
91  mutable QMutex m_lock {QMutex::Recursive};
92  QTimer *m_timer {nullptr};
94  uint m_updateFreq {24 * 3600 * 1000};
95  uint m_runningCount {0};
96  bool m_refreshAll {false};
97 };
98 
99 const int kGrabberUpdateEventType = QEvent::User + 5000;
100 
101 class MPUBLIC GrabberUpdateEvent : public QEvent
102 {
103  public:
105  : QEvent((QEvent::Type)kGrabberUpdateEventType) {}
106  ~GrabberUpdateEvent() = default;
107 };
108 
109 class MPUBLIC GrabberDownloadThread : public QObject, public MThread
110 {
111  Q_OBJECT
112 
113  public:
114 
115  explicit GrabberDownloadThread(QObject *parent);
117 
118  void refreshAll();
119  void cancel();
120 
121  signals:
122  void finished();
123 
124  protected:
125 
126  void run() override; // MThread
127 
128  private:
129 
130  QObject *m_parent {nullptr};
131  QList<GrabberScript*> m_scripts;
132  QMutex m_mutex;
133  bool m_refreshAll {false};
134 
135 };
136 
137 class MPUBLIC Search : public QObject
138 {
139  friend class MRSSParser;
140  Q_OBJECT
141 
142  public:
143 
144  Search();
145  ~Search();
146 
147  void resetSearch(void);
148  void executeSearch(const QString &script, const QString &query,
149  const QString &pagenum = "");
150  void process(void);
151 
152  QByteArray GetData() { return m_data; };
153  void SetData(QByteArray data);
154 
155  uint numResults() { return m_numResults; };
156  uint numReturned() { return m_numReturned; };
157  uint numIndex() { return m_numIndex; };
158  QString nextPageToken() { return m_nextPageToken; }
159  QString prevPageToken() { return m_prevPageToken; }
160 
161  ResultItem::resultList GetVideoList() { return m_videoList; };
162 
163  private:
164 
165  MythSystemLegacy *m_searchProcess {nullptr};
166 
167  QByteArray m_data;
168  QDomDocument m_document;
170 
171  uint m_numResults {0};
172  uint m_numReturned {0};
173  uint m_numIndex {0};
174 
177 
178  signals:
179 
180  void finishedSearch(Search *item);
181  void searchTimedOut(Search *item);
182 
183  private slots:
184 
185  void slotProcessSearchExit(uint exitcode = 0);
186 };
187 
188 #endif
QString m_nextPageToken
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
unsigned int slots[4]
Definition: element.c:38
const ArticleType & GetType() const
const bool & GetTree() const
#define MPUBLIC
Definition: mythexp.h:10
const int kGrabberUpdateEventType
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
const bool & GetSearch() const
uint numIndex()
const QString & GetTitle() const
unsigned int uint
Definition: compat.h:140
QList< GrabberScript * > scriptList
uint numReturned()
Q_DECLARE_METATYPE(GrabberScript *)
QString m_prevPageToken
const QString & GetCommandline() const
uint numResults()
ResultItem::resultList m_videoList
QString prevPageToken()
QByteArray GetData()
ResultItem::resultList GetVideoList()
GrabberScript::scriptList m_scripts
QDomDocument m_document
const QString & GetImage() const
QList< GrabberScript * > m_scripts
QString nextPageToken()
const QString & GetDescription() const
const QString & GetAuthor() const
QList< ResultItem * > resultList
Definition: rssparse.h:114
QByteArray m_data
enum ArticleTypes ArticleType
const double & GetVersion() const
ArticleType m_type