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