MythTV  master
guide.h
Go to the documentation of this file.
1 // Program Name: guide.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 GUIDE_H
27 #define GUIDE_H
28 
29 #include <QScriptEngine>
30 
31 #include "serviceUtil.h"
32 
33 #include "services/guideServices.h"
34 
38 #include "programinfo.h"
39 
40 class Guide : public GuideServices
41 {
42  Q_OBJECT
43 
44  public:
45 
46  Q_INVOKABLE explicit Guide( QObject */*parent*/ = nullptr ) {}
47 
48  public:
49 
50 
51  DTC::ProgramGuide* GetProgramGuide ( const QDateTime &StartTime ,
52  const QDateTime &EndTime ,
53  bool Details,
54  int ChannelGroupId,
55  int StartIndex,
56  int Count,
57  bool WithInvisible) override; // GuideServices
58 
59  DTC::ProgramList* GetProgramList ( int StartIndex,
60  int Count,
61  const QDateTime &StartTime ,
62  const QDateTime &EndTime ,
63  int ChanId,
64  const QString &TitleFilter,
65  const QString &CategoryFilter,
66  const QString &PersonFilter,
67  const QString &KeywordFilter,
68  bool OnlyNew,
69  bool Details,
70  const QString &Sort,
71  bool Descending,
72  bool WithInvisible) override; // GuideServices
73 
74  DTC::Program* GetProgramDetails ( int ChanId,
75  const QDateTime &StartTime ) override; // GuideServices
76 
77  QFileInfo GetChannelIcon ( int ChanId,
78  int Width ,
79  int Height ) override; // GuideServices
80 
81  DTC::ChannelGroupList* GetChannelGroupList ( bool IncludeEmpty ) override; // GuideServices
82 
83  QStringList GetCategoryList ( ) override; // GuideServices
84 
85  QStringList GetStoredSearches( const QString &Type ) override; // GuideServices
86 
87  bool AddToChannelGroup ( int ChannelGroupId,
88  int ChanId ) override; // GuideServices
89 
90  bool RemoveFromChannelGroup ( int ChannelGroupId,
91  int ChanId ) override; // GuideServices
92 };
93 
94 // --------------------------------------------------------------------------
95 // The following class wrapper is due to a limitation in Qt Script Engine. It
96 // requires all methods that return pointers to user classes that are derived from
97 // QObject actually return QObject* (not the user class *). If the user class pointer
98 // is returned, the script engine treats it as a QVariant and doesn't create a
99 // javascript prototype wrapper for it.
100 //
101 // This class allows us to keep the rich return types in the main API class while
102 // offering the script engine a class it can work with.
103 //
104 // Only API Classes that return custom classes needs to implement these wrappers.
105 //
106 // We should continue to look for a cleaning solution to this problem.
107 // --------------------------------------------------------------------------
108 
109 class ScriptableGuide : public QObject
110 {
111  Q_OBJECT
112 
113  private:
114 
116  QScriptEngine *m_pEngine;
117 
118  public:
119 
120  Q_INVOKABLE ScriptableGuide( QScriptEngine *pEngine, QObject *parent = nullptr ) : QObject( parent )
121  {
122  m_pEngine = pEngine;
123  }
124 
125  public slots:
126 
127  QObject* GetProgramGuide( const QDateTime &StartTime ,
128  const QDateTime &EndTime ,
129  bool Details,
130  int ChannelGroupId,
131  int StartIndex,
132  int Count,
133  bool WithInvisible)
134  {
135  SCRIPT_CATCH_EXCEPTION( nullptr,
136  return m_obj.GetProgramGuide( StartTime, EndTime, Details,
137  ChannelGroupId, StartIndex, Count,
138  WithInvisible );
139  )
140  }
141 
142  QObject* GetProgramList(int StartIndex,
143  int Count,
144  const QDateTime &StartTime,
145  const QDateTime &EndTime,
146  int ChanId,
147  const QString &TitleFilter,
148  const QString &CategoryFilter,
149  const QString &PersonFilter,
150  const QString &KeywordFilter,
151  bool OnlyNew,
152  bool Details,
153  const QString &Sort,
154  bool Descending,
155  bool WithInvisible)
156  {
157  SCRIPT_CATCH_EXCEPTION( nullptr,
158  return m_obj.GetProgramList( StartIndex, Count,
159  StartTime, EndTime, ChanId,
160  TitleFilter, CategoryFilter,
161  PersonFilter, KeywordFilter,
162  OnlyNew, Details,
163  Sort, Descending, WithInvisible );
164  )
165  }
166 
167  QObject* GetProgramDetails( int ChanId, const QDateTime &StartTime )
168  {
169  SCRIPT_CATCH_EXCEPTION( nullptr,
170  return m_obj.GetProgramDetails( ChanId, StartTime );
171  )
172  }
173 
174  //QFileInfo GetChannelIcon( int ChanId, int Width, int Height )
175  //{
176  // return m_obj.GetChannelIcon( ChanId, Width, Height );
177  //}
178 
179  QObject* GetChannelGroupList( bool IncludeEmpty = false )
180  {
181  SCRIPT_CATCH_EXCEPTION( nullptr,
182  return m_obj.GetChannelGroupList( IncludeEmpty );
183  )
184  }
185 
186  QStringList GetCategoryList( )
187  {
188  SCRIPT_CATCH_EXCEPTION( QStringList(),
189  return m_obj.GetCategoryList();
190  )
191  }
192 
193  QStringList GetStoredSearches( const QString& Type )
194  {
195  SCRIPT_CATCH_EXCEPTION( QStringList(),
196  return m_obj.GetStoredSearches( Type );
197  )
198  }
199 
200  bool AddToChannelGroup( int ChannelGroupId,
201  int ChanId )
202  {
203  SCRIPT_CATCH_EXCEPTION( false,
204  return m_obj.AddToChannelGroup( ChannelGroupId, ChanId );
205  )
206  }
207 
208  bool RemoveFromChannelGroup( int ChannelGroupId,
209  int ChanId )
210  {
211  SCRIPT_CATCH_EXCEPTION( false,
212  return m_obj.RemoveFromChannelGroup( ChannelGroupId, ChanId );
213  )
214  }
215 };
216 
218 
219 #endif
Q_INVOKABLE Guide(QObject *=nullptr)
Definition: guide.h:46
unsigned int slots[4]
Definition: element.c:38
QScriptEngine * m_pEngine
Definition: guide.h:116
DTC::ChannelGroupList * GetChannelGroupList(bool IncludeEmpty) override
Definition: guide.cpp:501
CategoryFilter
Definition: videofilter.h:35
Definition: guide.h:40
QStringList GetCategoryList()
Definition: guide.h:186
bool RemoveFromChannelGroup(int ChannelGroupId, int ChanId) override
Definition: guide.cpp:593
QObject * GetProgramList(int StartIndex, int Count, const QDateTime &StartTime, const QDateTime &EndTime, int ChanId, const QString &TitleFilter, const QString &CategoryFilter, const QString &PersonFilter, const QString &KeywordFilter, bool OnlyNew, bool Details, const QString &Sort, bool Descending, bool WithInvisible)
Definition: guide.h:142
bool AddToChannelGroup(int ChannelGroupId, int ChanId) override
Definition: guide.cpp:576
QObject * GetProgramGuide(const QDateTime &StartTime, const QDateTime &EndTime, bool Details, int ChannelGroupId, int StartIndex, int Count, bool WithInvisible)
Definition: guide.h:127
DTC::ProgramList * GetProgramList(int StartIndex, int Count, const QDateTime &StartTime, const QDateTime &EndTime, int ChanId, const QString &TitleFilter, const QString &CategoryFilter, const QString &PersonFilter, const QString &KeywordFilter, bool OnlyNew, bool Details, const QString &Sort, bool Descending, bool WithInvisible) override
Definition: guide.cpp:170
#define SCRIPT_CATCH_EXCEPTION(default, code)
Definition: service.h:83
bool RemoveFromChannelGroup(int ChannelGroupId, int ChanId)
Definition: guide.h:208
QStringList GetCategoryList() override
Definition: guide.cpp:520
Guide m_obj
Definition: guide.h:115
QObject * GetChannelGroupList(bool IncludeEmpty=false)
Definition: guide.h:179
QStringList GetStoredSearches(const QString &Type)
Definition: guide.h:193
QObject * GetProgramDetails(int ChanId, const QDateTime &StartTime)
Definition: guide.h:167
DTC::ProgramGuide * GetProgramGuide(const QDateTime &StartTime, const QDateTime &EndTime, bool Details, int ChannelGroupId, int StartIndex, int Count, bool WithInvisible) override
Definition: guide.cpp:48
bool AddToChannelGroup(int ChannelGroupId, int ChanId)
Definition: guide.h:200
DTC::Program * GetProgramDetails(int ChanId, const QDateTime &StartTime) override
Definition: guide.cpp:345
Q_INVOKABLE ScriptableGuide(QScriptEngine *pEngine, QObject *parent=nullptr)
Definition: guide.h:120
QStringList GetStoredSearches(const QString &Type) override
Definition: guide.cpp:543
QFileInfo GetChannelIcon(int ChanId, int Width, int Height) override
Definition: guide.cpp:376
Q_SCRIPT_DECLARE_QMETAOBJECT_MYTHTV(ScriptableGuide, QObject *)