MythTV  master
content.h
Go to the documentation of this file.
1 // Program Name: content.h
3 // Created : Mar. 7, 2011
4 //
5 // Copyright (c) 2011 David Blain <dblain@mythtv.org>
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //
25 
26 #ifndef CONTENT_H
27 #define CONTENT_H
28 
29 #include <QScriptEngine>
30 
32 
33 class Content : public ContentServices
34 {
35  Q_OBJECT
36 
37  public:
38 
39  Q_INVOKABLE explicit Content( QObject */*parent*/ = nullptr ) {}
40 
41  public:
42 
43  QFileInfo GetFile ( const QString &StorageGroup,
44  const QString &FileName ) override; // ContentServices
45 
46  QFileInfo GetImageFile ( const QString &StorageGroup,
47  const QString &FileName,
48  int Width, int Height ) override; // ContentServices
49 
50  QStringList GetFileList ( const QString &StorageGroup ) override; // ContentServices
51 
52  QStringList GetDirList ( const QString &StorageGroup ) override; // ContentServices
53 
54  QFileInfo GetRecordingArtwork ( const QString &Type,
55  const QString &Inetref,
56  int Season, int Width,
57  int Height) override; // ContentServices
58 
60  GetRecordingArtworkList( int RecordedId,
61  int ChanId,
62  const QDateTime &recstarttsRaw ) override; // ContentServices
63 
65  GetProgramArtworkList( const QString &Inetref,
66  int Season ) override; // ContentServices
67 
68  QFileInfo GetVideoArtwork ( const QString &Type,
69  int Id, int Width, int Height ) override; // ContentServices
70 
71  QFileInfo GetAlbumArt ( int Id, int Width, int Height ) override; // ContentServices
72 
73  QFileInfo GetPreviewImage ( int RecordedId,
74  int ChanId,
75  const QDateTime &recstarttsRaw,
76  int Width,
77  int Height,
78  int SecsIn,
79  const QString &Format) override; // ContentServices
80 
81  QFileInfo GetRecording ( int RecordedId,
82  int ChanId,
83  const QDateTime &recstarttsRaw ) override; // ContentServices
84 
85  QFileInfo GetMusic ( int Id ) override; // ContentServices
86  QFileInfo GetVideo ( int Id ) override; // ContentServices
87 
88  QString GetHash ( const QString &StorageGroup,
89  const QString &FileName ) override; // ContentServices
90 
91  bool DownloadFile ( const QString &URL,
92  const QString &StorageGroup ) override; // ContentServices
93 
94  // HTTP Live Streaming
96  const QString &FileName,
97  const QString &HostName,
98  int MaxSegments,
99  int Width,
100  int Height,
101  int Bitrate,
102  int AudioBitrate,
103  int SampleRate ) override; // ContentServices
104 
106  int ChanId,
107  const QDateTime &recstarttsRaw,
108  int MaxSegments,
109  int Width,
110  int Height,
111  int Bitrate,
112  int AudioBitrate,
113  int SampleRate ) override; // ContentServices
114 
116  int MaxSegments,
117  int Width,
118  int Height,
119  int Bitrate,
120  int AudioBitrate,
121  int SampleRate ) override; // ContentServices
122 
123  DTC::LiveStreamInfo *GetLiveStream ( int Id ) override; // ContentServices
124  DTC::LiveStreamInfoList *GetLiveStreamList ( const QString &FileName ) override; // ContentServices
125 
126  DTC::LiveStreamInfo *StopLiveStream ( int Id ) override; // ContentServices
127  bool RemoveLiveStream ( int Id ) override; // ContentServices
128 };
129 
130 // --------------------------------------------------------------------------
131 // The following class wrapper is due to a limitation in Qt Script Engine. It
132 // requires all methods that return pointers to user classes that are derived from
133 // QObject actually return QObject* (not the user class *). If the user class pointer
134 // is returned, the script engine treats it as a QVariant and doesn't create a
135 // javascript prototype wrapper for it.
136 //
137 // This class allows us to keep the rich return types in the main API class while
138 // offering the script engine a class it can work with.
139 //
140 // Only API Classes that return custom classes needs to implement these wrappers.
141 //
142 // We should continue to look for a cleaning solution to this problem.
143 // --------------------------------------------------------------------------
144 
145 class ScriptableContent : public QObject
146 {
147  Q_OBJECT
148 
149  private:
150 
152  QScriptEngine *m_pEngine;
153 
154  public:
155 
156  Q_INVOKABLE ScriptableContent( QScriptEngine *pEngine, QObject *parent = nullptr ) : QObject( parent )
157  {
158  m_pEngine = pEngine;
159  }
160 
161  public slots:
162 
163  QObject* GetRecordingArtworkList( int RecordedId )
164  {
165  SCRIPT_CATCH_EXCEPTION( nullptr,
166  return m_obj.GetRecordingArtworkList( RecordedId, 0, QDateTime() );
167  )
168  }
169 
170  QObject* GetProgramArtworkList( const QString &Inetref,
171  int Season )
172  {
173  SCRIPT_CATCH_EXCEPTION( nullptr,
174  return m_obj.GetProgramArtworkList( Inetref, Season );
175  )
176  }
177 
178  QString GetHash ( const QString &StorageGroup,
179  const QString &FileName )
180  {
181  SCRIPT_CATCH_EXCEPTION( QString(),
182  return m_obj.GetHash( StorageGroup, FileName );
183  )
184  }
185 
186  // HTTP Live Streaming
187  QObject* AddLiveStream ( const QString &StorageGroup,
188  const QString &FileName,
189  const QString &HostName,
190  int MaxSegments,
191  int Width,
192  int Height,
193  int Bitrate,
194  int AudioBitrate,
195  int SampleRate )
196  {
197  SCRIPT_CATCH_EXCEPTION( nullptr,
198  return m_obj.AddLiveStream(StorageGroup, FileName, HostName,
199  MaxSegments, Width, Height, Bitrate,
200  AudioBitrate, SampleRate);
201  )
202  }
203 
204  QObject* AddRecordingLiveStream (int RecordedId,
205  int MaxSegments,
206  int Width,
207  int Height,
208  int Bitrate,
209  int AudioBitrate,
210  int SampleRate )
211  {
212  SCRIPT_CATCH_EXCEPTION( nullptr,
213  return m_obj.AddRecordingLiveStream(RecordedId, 0, QDateTime(),
214  MaxSegments,
215  Width, Height, Bitrate,
216  AudioBitrate, SampleRate);
217  )
218  }
219 
220  QObject* AddVideoLiveStream( int Id,
221  int MaxSegments,
222  int Width,
223  int Height,
224  int Bitrate,
225  int AudioBitrate,
226  int SampleRate )
227  {
228  SCRIPT_CATCH_EXCEPTION( nullptr,
229  return m_obj.AddVideoLiveStream(Id, MaxSegments, Width, Height,
230  Bitrate, AudioBitrate, SampleRate);
231  )
232  }
233 
234  QObject* GetLiveStream( int Id )
235  {
236  SCRIPT_CATCH_EXCEPTION( nullptr,
237  return m_obj.GetLiveStream( Id );
238  )
239  }
240 
241  QObject* GetLiveStreamList( const QString &FileName )
242  {
243  SCRIPT_CATCH_EXCEPTION( nullptr,
244  return m_obj.GetLiveStreamList( FileName );
245  )
246  }
247 
248  QObject* StopLiveStream( int Id )
249  {
250  SCRIPT_CATCH_EXCEPTION( nullptr,
251  return m_obj.StopLiveStream(Id);
252  )
253  }
254 
255  bool RemoveLiveStream( int Id )
256  {
257  SCRIPT_CATCH_EXCEPTION( false,
258  return m_obj.RemoveLiveStream(Id);
259  )
260  }
261 };
262 
264 
265 #endif
QStringList GetDirList(const QString &StorageGroup) override
Definition: content.cpp:212
Q_INVOKABLE ScriptableContent(QScriptEngine *pEngine, QObject *parent=nullptr)
Definition: content.h:156
unsigned int slots[4]
Definition: element.c:38
QObject * GetProgramArtworkList(const QString &Inetref, int Season)
Definition: content.h:170
DTC::LiveStreamInfo * GetLiveStream(int Id) override
Definition: content.cpp:957
QString GetHash(const QString &StorageGroup, const QString &FileName) override
Definition: content.cpp:798
bool RemoveLiveStream(int Id) override
Definition: content.cpp:939
QFileInfo GetRecordingArtwork(const QString &Type, const QString &Inetref, int Season, int Width, int Height) override
Definition: content.cpp:252
QString GetHash(const QString &StorageGroup, const QString &FileName)
Definition: content.h:178
QStringList GetFileList(const QString &StorageGroup) override
Definition: content.cpp:232
Content m_obj
Definition: content.h:151
bool RemoveLiveStream(int Id)
Definition: content.h:255
static const char URL[]
Definition: cddb.cpp:29
QFileInfo GetAlbumArt(int Id, int Width, int Height) override
Definition: content.cpp:389
bool DownloadFile(const QString &URL, const QString &StorageGroup) override
Definition: content.cpp:831
DTC::LiveStreamInfoList * GetLiveStreamList(const QString &FileName) override
Definition: content.cpp:985
QObject * GetRecordingArtworkList(int RecordedId)
Definition: content.h:163
QFileInfo GetMusic(int Id) override
Definition: content.cpp:717
QScriptEngine * m_pEngine
Definition: content.h:152
QFileInfo GetPreviewImage(int RecordedId, int ChanId, const QDateTime &recstarttsRaw, int Width, int Height, int SecsIn, const QString &Format) override
Definition: content.cpp:486
DTC::LiveStreamInfo * AddLiveStream(const QString &StorageGroup, const QString &FileName, const QString &HostName, int MaxSegments, int Width, int Height, int Bitrate, int AudioBitrate, int SampleRate) override
Definition: content.cpp:865
DTC::ArtworkInfoList * GetProgramArtworkList(const QString &Inetref, int Season) override
Definition: content.cpp:316
QObject * GetLiveStream(int Id)
Definition: content.h:234
#define SCRIPT_CATCH_EXCEPTION(default, code)
Definition: service.h:83
DTC::ArtworkInfoList * GetRecordingArtworkList(int RecordedId, int ChanId, const QDateTime &recstarttsRaw) override
Definition: content.cpp:298
QFileInfo GetFile(const QString &StorageGroup, const QString &FileName) override
Definition: content.cpp:55
Q_INVOKABLE Content(QObject *=nullptr)
Definition: content.h:39
QObject * AddLiveStream(const QString &StorageGroup, const QString &FileName, const QString &HostName, int MaxSegments, int Width, int Height, int Bitrate, int AudioBitrate, int SampleRate)
Definition: content.h:187
DTC::LiveStreamInfo * StopLiveStream(int Id) override
Definition: content.cpp:948
DTC::LiveStreamInfo * AddRecordingLiveStream(int RecordedId, int ChanId, const QDateTime &recstarttsRaw, int MaxSegments, int Width, int Height, int Bitrate, int AudioBitrate, int SampleRate) override
Definition: content.cpp:994
QFileInfo GetRecording(int RecordedId, int ChanId, const QDateTime &recstarttsRaw) override
Definition: content.cpp:660
DTC::LiveStreamInfo * AddVideoLiveStream(int Id, int MaxSegments, int Width, int Height, int Bitrate, int AudioBitrate, int SampleRate) override
Definition: content.cpp:1067
Q_SCRIPT_DECLARE_QMETAOBJECT_MYTHTV(ScriptableContent, QObject *)
QFileInfo GetImageFile(const QString &StorageGroup, const QString &FileName, int Width, int Height) override
Definition: content.cpp:110
QFileInfo GetVideoArtwork(const QString &Type, int Id, int Width, int Height) override
Definition: content.cpp:330
QObject * GetLiveStreamList(const QString &FileName)
Definition: content.h:241
QObject * AddRecordingLiveStream(int RecordedId, int MaxSegments, int Width, int Height, int Bitrate, int AudioBitrate, int SampleRate)
Definition: content.h:204
QObject * StopLiveStream(int Id)
Definition: content.h:248
QFileInfo GetVideo(int Id) override
Definition: content.cpp:760
QObject * AddVideoLiveStream(int Id, int MaxSegments, int Width, int Height, int Bitrate, int AudioBitrate, int SampleRate)
Definition: content.h:220
enum MythDate::Formats Format