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