MythTV  master
myth.h
Go to the documentation of this file.
1 // Program Name: myth.h
3 // Created : Jan. 19, 2010
4 //
5 // Copyright (c) 2010 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 MYTH_H
27 #define MYTH_H
28 
29 #include <QScriptEngine>
30 
31 #include "services/mythServices.h"
32 #include <datacontracts/frontend.h>
33 
34 class Myth : public MythServices
35 {
36  Q_OBJECT
37 
38  public:
39 
40  Q_INVOKABLE explicit Myth( QObject *parent = nullptr ) : MythServices( parent ) {}
41 
42  public:
43 
44  DTC::ConnectionInfo* GetConnectionInfo ( const QString &Pin ) override; // MythServices
45 
46  QString GetHostName ( ) override; // MythServices
47  QStringList GetHosts ( ) override; // MythServices
48  QStringList GetKeys ( ) override; // MythServices
49 
50  DTC::StorageGroupDirList* GetStorageGroupDirs ( const QString &GroupName,
51  const QString &HostName ) override; // MythServices
52 
53  bool AddStorageGroupDir ( const QString &GroupName,
54  const QString &DirName,
55  const QString &HostName ) override; // MythServices
56 
57  bool RemoveStorageGroupDir( const QString &GroupName,
58  const QString &DirName,
59  const QString &HostName ) override; // MythServices
60 
61  DTC::TimeZoneInfo* GetTimeZone ( ) override; // MythServices
62 
63  QString GetFormatDate ( QDateTime Date,
64  bool ShortDate ) override; // MythServices
65  QString GetFormatDateTime ( QDateTime DateTime,
66  bool ShortDate ) override; // MythServices
67  QString GetFormatTime ( QDateTime Time ) override; // MythServices
68  QDateTime ParseISODateString ( const QString &DateTime ) override; // MythServices
69 
70  DTC::LogMessageList* GetLogs ( const QString &HostName,
71  const QString &Application,
72  int PID,
73  int TID,
74  const QString &Thread,
75  const QString &Filename,
76  int Line,
77  const QString &Function,
78  const QDateTime &FromTime,
79  const QDateTime &ToTime,
80  const QString &Level,
81  const QString &MsgContains
82  ) override; // MythServices
83 
84 
85  DTC::FrontendList* GetFrontends ( bool OnLine ) override; // MythServices
86 
87  QString GetSetting ( const QString &HostName,
88  const QString &Key,
89  const QString &Default ) override; // MythServices
90 
91  DTC::SettingList* GetSettingList ( const QString &HostName ) override; // MythServices
92 
93  bool PutSetting ( const QString &HostName,
94  const QString &Key,
95  const QString &Value ) override; // MythServices
96 
97  bool ChangePassword ( const QString &UserName,
98  const QString &OldPassword,
99  const QString &NewPassword ) override; // MythServices
100 
101  bool TestDBSettings ( const QString &HostName,
102  const QString &UserName,
103  const QString &Password,
104  const QString &DBName,
105  int dbPort) override; // MythServices
106 
107  bool SendMessage ( const QString &Message,
108  const QString &Address,
109  int udpPort,
110  int Timeout) override; // MythServices
111 
112  bool SendNotification ( bool Error,
113  const QString &Type,
114  const QString &Message,
115  const QString &Origin,
116  const QString &Description,
117  const QString &Image,
118  const QString &Extra,
119  const QString &ProgressText,
120  float Progress,
121  int Duration,
122  bool Fullscreen,
123  uint Visibility,
124  uint Priority,
125  const QString &Address,
126  int udpPort ) override; // MythServices
127 
128  bool BackupDatabase ( void ) override; // MythServices
129 
130  bool CheckDatabase ( bool Repair ) override; // MythServices
131 
132  bool DelayShutdown ( void ) override; // MythServices
133 
134  bool ProfileSubmit ( void ) override; // MythServices
135 
136  bool ProfileDelete ( void ) override; // MythServices
137 
138  QString ProfileURL ( void ) override; // MythServices
139 
140  QString ProfileUpdated ( void ) override; // MythServices
141 
142  QString ProfileText ( void ) override; // MythServices
143 
144  DTC::BackendInfo* GetBackendInfo ( void ) override; // MythServices
145 
146  bool ManageDigestUser ( const QString &Action,
147  const QString &UserName,
148  const QString &Password,
149  const QString &NewPassword,
150  const QString &AdminPassword ) override; // MythServices
151 
152  bool ManageUrlProtection ( const QString &Services,
153  const QString &AdminPassword ) override; // MythServices
154 };
155 
156 // --------------------------------------------------------------------------
157 // The following class wrapper is due to a limitation in Qt Script Engine. It
158 // requires all methods that return pointers to user classes that are derived from
159 // QObject actually return QObject* (not the user class *). If the user class pointer
160 // is returned, the script engine treats it as a QVariant and doesn't create a
161 // javascript prototype wrapper for it.
162 //
163 // This class allows us to keep the rich return types in the main API class while
164 // offering the script engine a class it can work with.
165 //
166 // Only API Classes that return custom classes needs to implement these wrappers.
167 //
168 // We should continue to look for a cleaning solution to this problem.
169 // --------------------------------------------------------------------------
170 
171 class ScriptableMyth : public QObject
172 {
173  Q_OBJECT
174 
175  private:
176 
178  QScriptEngine *m_pEngine;
179 
180  public:
181 
182  Q_INVOKABLE ScriptableMyth( QScriptEngine *pEngine, QObject *parent = nullptr ) : QObject( parent )
183  {
184  m_pEngine = pEngine;
185  }
186 
187  public slots:
188 
189  QObject* GetConnectionInfo ( const QString &Pin )
190  {
191  SCRIPT_CATCH_EXCEPTION( nullptr,
192  return m_obj.GetConnectionInfo( Pin );
193  )
194  }
195 
196  QString GetHostName()
197  {
198  SCRIPT_CATCH_EXCEPTION( QString(),
199  return m_obj.GetHostName();
200  )
201  }
202 
203  QStringList GetHosts()
204  {
205  SCRIPT_CATCH_EXCEPTION( QStringList(),
206  return m_obj.GetHosts();
207  )
208  }
209 
210  QStringList GetKeys()
211  {
212  SCRIPT_CATCH_EXCEPTION( QStringList(),
213  return m_obj.GetKeys();
214  )
215  }
216 
217  QObject* GetStorageGroupDirs ( const QString &GroupName,
218  const QString &HostName )
219  {
220  SCRIPT_CATCH_EXCEPTION( nullptr,
221  return m_obj.GetStorageGroupDirs( GroupName, HostName );
222  )
223  }
224 
225  bool AddStorageGroupDir ( const QString &GroupName,
226  const QString &DirName,
227  const QString &HostName )
228  {
229  SCRIPT_CATCH_EXCEPTION( false,
230  return m_obj.AddStorageGroupDir( GroupName, DirName, HostName );
231  )
232  }
233 
234  bool RemoveStorageGroupDir ( const QString &GroupName,
235  const QString &DirName,
236  const QString &HostName )
237  {
238  SCRIPT_CATCH_EXCEPTION( false,
239  return m_obj.RemoveStorageGroupDir( GroupName, DirName, HostName );
240  )
241  }
242 
243  QObject* GetTimeZone()
244  {
245  SCRIPT_CATCH_EXCEPTION( nullptr,
246  return m_obj.GetTimeZone( );
247  )
248  }
249 
250  QString GetFormatDate( const QDateTime& Date,
251  bool ShortDate = false )
252  {
253  SCRIPT_CATCH_EXCEPTION( QString(),
254  return m_obj.GetFormatDate( Date, ShortDate );
255  )
256  }
257 
258  QString GetFormatDateTime( const QDateTime& DateTime,
259  bool ShortDate = false )
260  {
261  SCRIPT_CATCH_EXCEPTION( QString(),
262  return m_obj.GetFormatDateTime( DateTime, ShortDate );
263  )
264  }
265 
266  QString GetFormatTime( const QDateTime& Time )
267  {
268  SCRIPT_CATCH_EXCEPTION( QString(),
269  return m_obj.GetFormatTime( Time );
270  )
271  }
272 
273  QDateTime ParseISODateString( const QString &DateTime )
274  {
275  SCRIPT_CATCH_EXCEPTION( QDateTime(),
276  return m_obj.ParseISODateString(DateTime);
277  )
278  }
279 
280  QObject* GetLogs( const QString &HostName,
281  const QString &Application,
282  int PID,
283  int TID,
284  const QString &Thread,
285  const QString &Filename,
286  int Line,
287  const QString &Function,
288  const QDateTime &FromTime,
289  const QDateTime &ToTime,
290  const QString &Level,
291  const QString &MsgContains )
292  {
293  SCRIPT_CATCH_EXCEPTION( nullptr,
294  return m_obj.GetLogs( HostName, Application, PID, TID, Thread,
295  Filename, Line, Function, FromTime, ToTime,
296  Level, MsgContains );
297  )
298  }
299 
300  QObject* GetFrontends( bool OnLine )
301  {
302  SCRIPT_CATCH_EXCEPTION( nullptr,
303  return m_obj.GetFrontends( OnLine );
304  )
305  }
306 
307  QString GetSetting ( const QString &HostName,
308  const QString &Key,
309  const QString &Default )
310  {
311  SCRIPT_CATCH_EXCEPTION( QString(),
312  return m_obj.GetSetting( HostName, Key, Default );
313  )
314  }
315 
316  QObject* GetSettingList ( const QString &HostName )
317  {
318  SCRIPT_CATCH_EXCEPTION( nullptr,
319  return m_obj.GetSettingList( HostName );
320  )
321  }
322 
323  bool PutSetting( const QString &HostName,
324  const QString &Key,
325  const QString &Value )
326  {
327  SCRIPT_CATCH_EXCEPTION( false,
328  return m_obj.PutSetting( HostName, Key, Value );
329  )
330  }
331 
332  bool TestDBSettings( const QString &HostName,
333  const QString &UserName,
334  const QString &Password,
335  const QString &DBName,
336  int dbPort)
337  {
338  SCRIPT_CATCH_EXCEPTION( false,
339  return m_obj.TestDBSettings( HostName, UserName, Password,
340  DBName, dbPort );
341  )
342  }
343 
344  bool SendMessage( const QString &Message,
345  const QString &Address,
346  int udpPort,
347  int Timeout)
348  {
349  SCRIPT_CATCH_EXCEPTION( false,
350  return m_obj.SendMessage( Message, Address, udpPort, Timeout );
351  )
352  }
353 
354  bool BackupDatabase( void )
355  {
356  SCRIPT_CATCH_EXCEPTION( false,
357  return m_obj.BackupDatabase();
358  )
359  }
360 
361  bool CheckDatabase( bool Repair )
362  {
363  SCRIPT_CATCH_EXCEPTION( false,
364  return m_obj.CheckDatabase( Repair );
365  )
366  }
367 
368  bool DelayShutdown( void )
369  {
370  SCRIPT_CATCH_EXCEPTION( false,
371  return m_obj.DelayShutdown();
372  )
373  }
374 
375  bool ProfileSubmit( void )
376  {
377  SCRIPT_CATCH_EXCEPTION( false,
378  return m_obj.ProfileSubmit();
379  )
380  }
381 
382  bool ProfileDelete( void )
383  {
384  SCRIPT_CATCH_EXCEPTION( false,
385  return m_obj.ProfileDelete();
386  )
387  }
388 
389  QString ProfileURL( void )
390  {
391  SCRIPT_CATCH_EXCEPTION( QString(),
392  return m_obj.ProfileURL();
393  )
394  }
395 
396  QString ProfileUpdated( void )
397  {
398  SCRIPT_CATCH_EXCEPTION( QString(),
399  return m_obj.ProfileUpdated();
400  )
401  }
402 
403  QString ProfileText( void )
404  {
405  SCRIPT_CATCH_EXCEPTION( QString(),
406  return m_obj.ProfileText();
407  )
408  }
409 
410  QObject* GetBackendInfo( void )
411  {
412  SCRIPT_CATCH_EXCEPTION( nullptr,
413  return m_obj.GetBackendInfo();
414  )
415  }
416  bool ManageDigestUser( const QString &Action,
417  const QString &UserName,
418  const QString &Password,
419  const QString &NewPassword,
420  const QString &AdminPassword )
421  {
422  SCRIPT_CATCH_EXCEPTION( false,
423  return m_obj.ManageDigestUser( Action,
424  UserName,
425  Password,
426  NewPassword,
427  AdminPassword );
428  )
429  }
430  bool ManageUrlProtection( const QString &Services,
431  const QString &AdminPassword )
432  {
433  SCRIPT_CATCH_EXCEPTION( false,
434  return m_obj.ManageUrlProtection( Services, AdminPassword );
435  )
436  }
437 };
438 
440 
441 #endif
DTC::TimeZoneInfo * GetTimeZone() override
Definition: myth.cpp:395
bool PutSetting(const QString &HostName, const QString &Key, const QString &Value)
Definition: myth.h:323
DTC::LogMessageList * GetLogs(const QString &HostName, const QString &Application, int PID, int TID, const QString &Thread, const QString &Filename, int Line, const QString &Function, const QDateTime &FromTime, const QDateTime &ToTime, const QString &Level, const QString &MsgContains) override
Definition: myth.cpp:459
bool SendMessage(const QString &Message, const QString &Address, int udpPort, int Timeout)
Definition: myth.h:344
bool ProfileDelete(void)
Definition: myth.h:382
bool AddStorageGroupDir(const QString &GroupName, const QString &DirName, const QString &HostName)
Definition: myth.h:225
unsigned int slots[4]
Definition: element.c:38
QDateTime ParseISODateString(const QString &DateTime) override
Definition: myth.cpp:445
QString GetHostName()
Definition: myth.h:196
DTC::ConnectionInfo * GetConnectionInfo(const QString &Pin) override
Definition: myth.cpp:55
bool TestDBSettings(const QString &HostName, const QString &UserName, const QString &Password, const QString &DBName, int dbPort)
Definition: myth.h:332
bool ChangePassword(const QString &UserName, const QString &OldPassword, const QString &NewPassword) override
Definition: myth.cpp:726
QString GetFormatDateTime(QDateTime DateTime, bool ShortDate) override
Definition: myth.cpp:423
QScriptEngine * m_pEngine
Definition: myth.h:178
QStringList GetHosts()
Definition: myth.h:203
QString GetFormatDateTime(const QDateTime &DateTime, bool ShortDate=false)
Definition: myth.h:258
bool PutSetting(const QString &HostName, const QString &Key, const QString &Value) override
Definition: myth.cpp:710
QString ProfileURL(void) override
Definition: myth.cpp:983
DTC::FrontendList * GetFrontends(bool OnLine) override
Definition: myth.cpp:591
unsigned int uint
Definition: compat.h:140
bool DelayShutdown(void)
Definition: myth.h:368
QString GetFormatDate(const QDateTime &Date, bool ShortDate=false)
Definition: myth.h:250
QString ProfileUpdated(void)
Definition: myth.h:396
bool SendNotification(bool Error, const QString &Type, const QString &Message, const QString &Origin, const QString &Description, const QString &Image, const QString &Extra, const QString &ProgressText, float Progress, int Duration, bool Fullscreen, uint Visibility, uint Priority, const QString &Address, int udpPort) override
Definition: myth.cpp:820
DTC::StorageGroupDirList * GetStorageGroupDirs(const QString &GroupName, const QString &HostName) override
Definition: myth.cpp:216
QObject * GetConnectionInfo(const QString &Pin)
Definition: myth.h:189
bool CheckDatabase(bool Repair) override
Definition: myth.cpp:925
An action (for this plugin) consists of a description, and a set of key sequences.
Definition: action.h:38
bool ProfileSubmit(void)
Definition: myth.h:375
bool DelayShutdown(void) override
Definition: myth.cpp:939
QString GetHostName() override
Definition: myth.cpp:136
Q_INVOKABLE Myth(QObject *parent=nullptr)
Definition: myth.h:40
#define SCRIPT_CATCH_EXCEPTION(default, code)
Definition: service.h:83
QObject * GetFrontends(bool OnLine)
Definition: myth.h:300
Definition: myth.h:34
DTC::SettingList * GetSettingList(const QString &HostName) override
Definition: myth.cpp:657
QString GetFormatTime(const QDateTime &Time)
Definition: myth.h:266
QObject * GetBackendInfo(void)
Definition: myth.h:410
QObject * GetTimeZone()
Definition: myth.h:243
QString ProfileText(void) override
Definition: myth.cpp:1017
bool ManageUrlProtection(const QString &Services, const QString &AdminPassword) override
Definition: myth.cpp:1097
bool BackupDatabase(void)
Definition: myth.h:354
QStringList GetHosts() override
Definition: myth.cpp:147
bool SendMessage(const QString &Message, const QString &Address, int udpPort, int Timeout) override
Definition: myth.cpp:767
bool RemoveStorageGroupDir(const QString &GroupName, const QString &DirName, const QString &HostName)
Definition: myth.h:234
QString GetFormatTime(QDateTime Time) override
Definition: myth.cpp:436
Q_INVOKABLE ScriptableMyth(QScriptEngine *pEngine, QObject *parent=nullptr)
Definition: myth.h:182
DTC::BackendInfo * GetBackendInfo(void) override
Definition: myth.cpp:1031
static StandardSetting * Password(bool enabled)
Setting for changing password.
bool BackupDatabase(void) override
Definition: myth.cpp:898
bool TestDBSettings(const QString &HostName, const QString &UserName, const QString &Password, const QString &DBName, int dbPort) override
Definition: myth.cpp:741
QString ProfileText(void)
Definition: myth.h:403
bool RemoveStorageGroupDir(const QString &GroupName, const QString &DirName, const QString &HostName) override
Definition: myth.cpp:354
QDateTime ParseISODateString(const QString &DateTime)
Definition: myth.h:273
Q_SCRIPT_DECLARE_QMETAOBJECT_MYTHTV(ScriptableMyth, QObject *)
bool AddStorageGroupDir(const QString &GroupName, const QString &DirName, const QString &HostName) override
Definition: myth.cpp:292
bool ManageUrlProtection(const QString &Services, const QString &AdminPassword)
Definition: myth.h:430
bool ManageDigestUser(const QString &Action, const QString &UserName, const QString &Password, const QString &NewPassword, const QString &AdminPassword)
Definition: myth.h:416
QString ProfileURL(void)
Definition: myth.h:389
QString GetFormatDate(QDateTime Date, bool ShortDate) override
Definition: myth.cpp:410
Definition: image.h:30
QString GetSetting(const QString &HostName, const QString &Key, const QString &Default) override
Definition: myth.cpp:619
bool ProfileSubmit(void) override
Definition: myth.cpp:951
QString ProfileUpdated(void) override
Definition: myth.cpp:999
QObject * GetLogs(const QString &HostName, const QString &Application, int PID, int TID, const QString &Thread, const QString &Filename, int Line, const QString &Function, const QDateTime &FromTime, const QDateTime &ToTime, const QString &Level, const QString &MsgContains)
Definition: myth.h:280
bool ProfileDelete(void) override
Definition: myth.cpp:967
QStringList GetKeys() override
Definition: myth.cpp:182
QString GetSetting(const QString &HostName, const QString &Key, const QString &Default)
Definition: myth.h:307
bool CheckDatabase(bool Repair)
Definition: myth.h:361
QStringList GetKeys()
Definition: myth.h:210
bool ManageDigestUser(const QString &Action, const QString &UserName, const QString &Password, const QString &NewPassword, const QString &AdminPassword) override
Definition: myth.cpp:1065
Myth m_obj
Definition: myth.h:177
QObject * GetSettingList(const QString &HostName)
Definition: myth.h:316
QObject * GetStorageGroupDirs(const QString &GroupName, const QString &HostName)
Definition: myth.h:217