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 ProfileSubmit ( void ) override; // MythServices
133 
134  bool ProfileDelete ( void ) override; // MythServices
135 
136  QString ProfileURL ( void ) override; // MythServices
137 
138  QString ProfileUpdated ( void ) override; // MythServices
139 
140  QString ProfileText ( void ) override; // MythServices
141 
142  DTC::BackendInfo* GetBackendInfo ( void ) override; // MythServices
143 
144  bool ManageDigestUser ( const QString &Action,
145  const QString &UserName,
146  const QString &Password,
147  const QString &NewPassword,
148  const QString &AdminPassword ) override; // MythServices
149 
150  bool ManageUrlProtection ( const QString &Services,
151  const QString &AdminPassword ) override; // MythServices
152 };
153 
154 // --------------------------------------------------------------------------
155 // The following class wrapper is due to a limitation in Qt Script Engine. It
156 // requires all methods that return pointers to user classes that are derived from
157 // QObject actually return QObject* (not the user class *). If the user class pointer
158 // is returned, the script engine treats it as a QVariant and doesn't create a
159 // javascript prototype wrapper for it.
160 //
161 // This class allows us to keep the rich return types in the main API class while
162 // offering the script engine a class it can work with.
163 //
164 // Only API Classes that return custom classes needs to implement these wrappers.
165 //
166 // We should continue to look for a cleaning solution to this problem.
167 // --------------------------------------------------------------------------
168 
169 class ScriptableMyth : public QObject
170 {
171  Q_OBJECT
172 
173  private:
174 
176  QScriptEngine *m_pEngine;
177 
178  public:
179 
180  Q_INVOKABLE ScriptableMyth( QScriptEngine *pEngine, QObject *parent = nullptr ) : QObject( parent )
181  {
182  m_pEngine = pEngine;
183  }
184 
185  public slots:
186 
187  QObject* GetConnectionInfo ( const QString &Pin )
188  {
189  SCRIPT_CATCH_EXCEPTION( nullptr,
190  return m_obj.GetConnectionInfo( Pin );
191  )
192  }
193 
194  QString GetHostName()
195  {
196  SCRIPT_CATCH_EXCEPTION( QString(),
197  return m_obj.GetHostName();
198  )
199  }
200 
201  QStringList GetHosts()
202  {
203  SCRIPT_CATCH_EXCEPTION( QStringList(),
204  return m_obj.GetHosts();
205  )
206  }
207 
208  QStringList GetKeys()
209  {
210  SCRIPT_CATCH_EXCEPTION( QStringList(),
211  return m_obj.GetKeys();
212  )
213  }
214 
215  QObject* GetStorageGroupDirs ( const QString &GroupName,
216  const QString &HostName )
217  {
218  SCRIPT_CATCH_EXCEPTION( nullptr,
219  return m_obj.GetStorageGroupDirs( GroupName, HostName );
220  )
221  }
222 
223  bool AddStorageGroupDir ( const QString &GroupName,
224  const QString &DirName,
225  const QString &HostName )
226  {
227  SCRIPT_CATCH_EXCEPTION( false,
228  return m_obj.AddStorageGroupDir( GroupName, DirName, HostName );
229  )
230  }
231 
232  bool RemoveStorageGroupDir ( const QString &GroupName,
233  const QString &DirName,
234  const QString &HostName )
235  {
236  SCRIPT_CATCH_EXCEPTION( false,
237  return m_obj.RemoveStorageGroupDir( GroupName, DirName, HostName );
238  )
239  }
240 
241  QObject* GetTimeZone()
242  {
243  SCRIPT_CATCH_EXCEPTION( nullptr,
244  return m_obj.GetTimeZone( );
245  )
246  }
247 
248  QString GetFormatDate( const QDateTime& Date,
249  bool ShortDate = false )
250  {
251  SCRIPT_CATCH_EXCEPTION( QString(),
252  return m_obj.GetFormatDate( Date, ShortDate );
253  )
254  }
255 
256  QString GetFormatDateTime( const QDateTime& DateTime,
257  bool ShortDate = false )
258  {
259  SCRIPT_CATCH_EXCEPTION( QString(),
260  return m_obj.GetFormatDateTime( DateTime, ShortDate );
261  )
262  }
263 
264  QString GetFormatTime( const QDateTime& Time )
265  {
266  SCRIPT_CATCH_EXCEPTION( QString(),
267  return m_obj.GetFormatTime( Time );
268  )
269  }
270 
271  QDateTime ParseISODateString( const QString &DateTime )
272  {
273  SCRIPT_CATCH_EXCEPTION( QDateTime(),
274  return m_obj.ParseISODateString(DateTime);
275  )
276  }
277 
278  QObject* GetLogs( const QString &HostName,
279  const QString &Application,
280  int PID,
281  int TID,
282  const QString &Thread,
283  const QString &Filename,
284  int Line,
285  const QString &Function,
286  const QDateTime &FromTime,
287  const QDateTime &ToTime,
288  const QString &Level,
289  const QString &MsgContains )
290  {
291  SCRIPT_CATCH_EXCEPTION( nullptr,
292  return m_obj.GetLogs( HostName, Application, PID, TID, Thread,
293  Filename, Line, Function, FromTime, ToTime,
294  Level, MsgContains );
295  )
296  }
297 
298  QObject* GetFrontends( bool OnLine )
299  {
300  SCRIPT_CATCH_EXCEPTION( nullptr,
301  return m_obj.GetFrontends( OnLine );
302  )
303  }
304 
305  QString GetSetting ( const QString &HostName,
306  const QString &Key,
307  const QString &Default )
308  {
309  SCRIPT_CATCH_EXCEPTION( QString(),
310  return m_obj.GetSetting( HostName, Key, Default );
311  )
312  }
313 
314  QObject* GetSettingList ( const QString &HostName )
315  {
316  SCRIPT_CATCH_EXCEPTION( nullptr,
317  return m_obj.GetSettingList( HostName );
318  )
319  }
320 
321  bool PutSetting( const QString &HostName,
322  const QString &Key,
323  const QString &Value )
324  {
325  SCRIPT_CATCH_EXCEPTION( false,
326  return m_obj.PutSetting( HostName, Key, Value );
327  )
328  }
329 
330  bool TestDBSettings( const QString &HostName,
331  const QString &UserName,
332  const QString &Password,
333  const QString &DBName,
334  int dbPort)
335  {
336  SCRIPT_CATCH_EXCEPTION( false,
337  return m_obj.TestDBSettings( HostName, UserName, Password,
338  DBName, dbPort );
339  )
340  }
341 
342  bool SendMessage( const QString &Message,
343  const QString &Address,
344  int udpPort,
345  int Timeout)
346  {
347  SCRIPT_CATCH_EXCEPTION( false,
348  return m_obj.SendMessage( Message, Address, udpPort, Timeout );
349  )
350  }
351 
352  bool BackupDatabase( void )
353  {
354  SCRIPT_CATCH_EXCEPTION( false,
355  return m_obj.BackupDatabase();
356  )
357  }
358 
359  bool CheckDatabase( bool Repair )
360  {
361  SCRIPT_CATCH_EXCEPTION( false,
362  return m_obj.CheckDatabase( Repair );
363  )
364  }
365 
366  bool ProfileSubmit( void )
367  {
368  SCRIPT_CATCH_EXCEPTION( false,
369  return m_obj.ProfileSubmit();
370  )
371  }
372 
373  bool ProfileDelete( void )
374  {
375  SCRIPT_CATCH_EXCEPTION( false,
376  return m_obj.ProfileDelete();
377  )
378  }
379 
380  QString ProfileURL( void )
381  {
382  SCRIPT_CATCH_EXCEPTION( QString(),
383  return m_obj.ProfileURL();
384  )
385  }
386 
387  QString ProfileUpdated( void )
388  {
389  SCRIPT_CATCH_EXCEPTION( QString(),
390  return m_obj.ProfileUpdated();
391  )
392  }
393 
394  QString ProfileText( void )
395  {
396  SCRIPT_CATCH_EXCEPTION( QString(),
397  return m_obj.ProfileText();
398  )
399  }
400 
401  QObject* GetBackendInfo( void )
402  {
403  SCRIPT_CATCH_EXCEPTION( nullptr,
404  return m_obj.GetBackendInfo();
405  )
406  }
407  bool ManageDigestUser( const QString &Action,
408  const QString &UserName,
409  const QString &Password,
410  const QString &NewPassword,
411  const QString &AdminPassword )
412  {
413  SCRIPT_CATCH_EXCEPTION( false,
414  return m_obj.ManageDigestUser( Action,
415  UserName,
416  Password,
417  NewPassword,
418  AdminPassword );
419  )
420  }
421  bool ManageUrlProtection( const QString &Services,
422  const QString &AdminPassword )
423  {
424  SCRIPT_CATCH_EXCEPTION( false,
425  return m_obj.ManageUrlProtection( Services, AdminPassword );
426  )
427  }
428 };
429 
431 
432 #endif
DTC::TimeZoneInfo * GetTimeZone() override
Definition: myth.cpp:394
bool PutSetting(const QString &HostName, const QString &Key, const QString &Value)
Definition: myth.h:321
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:462
bool SendMessage(const QString &Message, const QString &Address, int udpPort, int Timeout)
Definition: myth.h:342
bool ProfileDelete(void)
Definition: myth.h:373
bool AddStorageGroupDir(const QString &GroupName, const QString &DirName, const QString &HostName)
Definition: myth.h:223
unsigned int slots[4]
Definition: element.c:38
QDateTime ParseISODateString(const QString &DateTime) override
Definition: myth.cpp:448
QString GetHostName()
Definition: myth.h:194
DTC::ConnectionInfo * GetConnectionInfo(const QString &Pin) override
Definition: myth.cpp:54
bool TestDBSettings(const QString &HostName, const QString &UserName, const QString &Password, const QString &DBName, int dbPort)
Definition: myth.h:330
bool ChangePassword(const QString &UserName, const QString &OldPassword, const QString &NewPassword) override
Definition: myth.cpp:729
QString GetFormatDateTime(QDateTime DateTime, bool ShortDate) override
Definition: myth.cpp:424
QScriptEngine * m_pEngine
Definition: myth.h:176
QStringList GetHosts()
Definition: myth.h:201
QString GetFormatDateTime(const QDateTime &DateTime, bool ShortDate=false)
Definition: myth.h:256
bool PutSetting(const QString &HostName, const QString &Key, const QString &Value) override
Definition: myth.cpp:713
QString ProfileURL(void) override
Definition: myth.cpp:978
DTC::FrontendList * GetFrontends(bool OnLine) override
Definition: myth.cpp:594
unsigned int uint
Definition: compat.h:140
QString GetFormatDate(const QDateTime &Date, bool ShortDate=false)
Definition: myth.h:248
QString ProfileUpdated(void)
Definition: myth.h:387
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:823
DTC::StorageGroupDirList * GetStorageGroupDirs(const QString &GroupName, const QString &HostName) override
Definition: myth.cpp:215
QObject * GetConnectionInfo(const QString &Pin)
Definition: myth.h:187
bool CheckDatabase(bool Repair) override
Definition: myth.cpp:928
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:366
QString GetHostName() override
Definition: myth.cpp:135
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:298
Definition: myth.h:34
DTC::SettingList * GetSettingList(const QString &HostName) override
Definition: myth.cpp:660
QString GetFormatTime(const QDateTime &Time)
Definition: myth.h:264
QObject * GetBackendInfo(void)
Definition: myth.h:401
QObject * GetTimeZone()
Definition: myth.h:241
QString ProfileText(void) override
Definition: myth.cpp:1012
bool ManageUrlProtection(const QString &Services, const QString &AdminPassword) override
Definition: myth.cpp:1094
bool BackupDatabase(void)
Definition: myth.h:352
QStringList GetHosts() override
Definition: myth.cpp:146
bool SendMessage(const QString &Message, const QString &Address, int udpPort, int Timeout) override
Definition: myth.cpp:770
bool RemoveStorageGroupDir(const QString &GroupName, const QString &DirName, const QString &HostName)
Definition: myth.h:232
QString GetFormatTime(QDateTime Time) override
Definition: myth.cpp:439
Q_INVOKABLE ScriptableMyth(QScriptEngine *pEngine, QObject *parent=nullptr)
Definition: myth.h:180
DTC::BackendInfo * GetBackendInfo(void) override
Definition: myth.cpp:1026
static StandardSetting * Password(bool enabled)
Setting for changing password.
bool BackupDatabase(void) override
Definition: myth.cpp:901
bool TestDBSettings(const QString &HostName, const QString &UserName, const QString &Password, const QString &DBName, int dbPort) override
Definition: myth.cpp:744
QString ProfileText(void)
Definition: myth.h:394
bool RemoveStorageGroupDir(const QString &GroupName, const QString &DirName, const QString &HostName) override
Definition: myth.cpp:353
QDateTime ParseISODateString(const QString &DateTime)
Definition: myth.h:271
Q_SCRIPT_DECLARE_QMETAOBJECT_MYTHTV(ScriptableMyth, QObject *)
bool AddStorageGroupDir(const QString &GroupName, const QString &DirName, const QString &HostName) override
Definition: myth.cpp:291
bool ManageUrlProtection(const QString &Services, const QString &AdminPassword)
Definition: myth.h:421
bool ManageDigestUser(const QString &Action, const QString &UserName, const QString &Password, const QString &NewPassword, const QString &AdminPassword)
Definition: myth.h:407
QString ProfileURL(void)
Definition: myth.h:380
QString GetFormatDate(QDateTime Date, bool ShortDate) override
Definition: myth.cpp:409
Definition: image.h:30
QString GetSetting(const QString &HostName, const QString &Key, const QString &Default) override
Definition: myth.cpp:622
bool ProfileSubmit(void) override
Definition: myth.cpp:946
QString ProfileUpdated(void) override
Definition: myth.cpp:994
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:278
bool ProfileDelete(void) override
Definition: myth.cpp:962
QStringList GetKeys() override
Definition: myth.cpp:181
QString GetSetting(const QString &HostName, const QString &Key, const QString &Default)
Definition: myth.h:305
bool CheckDatabase(bool Repair)
Definition: myth.h:359
QStringList GetKeys()
Definition: myth.h:208
bool ManageDigestUser(const QString &Action, const QString &UserName, const QString &Password, const QString &NewPassword, const QString &AdminPassword) override
Definition: myth.cpp:1060
Myth m_obj
Definition: myth.h:175
QObject * GetSettingList(const QString &HostName)
Definition: myth.h:314
QObject * GetStorageGroupDirs(const QString &GroupName, const QString &HostName)
Definition: myth.h:215