MythTV  master
programs/mythfrontend/services/frontend.h
Go to the documentation of this file.
1 #ifndef FRONTEND_H
2 #define FRONTEND_H
3 
4 #include <QScriptEngine>
6 #include "service.h"
7 
8 class Frontend : public FrontendServices
9 {
10  friend class MythFEXML;
11 
12  Q_OBJECT
13 
14  public:
15  Q_INVOKABLE explicit Frontend(QObject *parent = nullptr) : FrontendServices(parent) { }
16 
17  public:
18  DTC::FrontendStatus* GetStatus(void) override; // FrontendServices
19  bool SendMessage(const QString &Message,
20  uint Timeout) override; // FrontendServices
21  bool SendNotification(bool Error,
22  const QString &Type,
23  const QString &Message,
24  const QString &Origin,
25  const QString &Description,
26  const QString &Image,
27  const QString &Extra,
28  const QString &ProgressText,
29  float Progress,
30  int Timeout,
31  bool Fullscreen,
32  uint Visibility, uint Priority) override; // FrontendServices
33 
34  bool SendAction(const QString &Action,
35  const QString &Value,
36  uint Width, uint Height) override; // FrontendServices
37  bool PlayRecording(int RecordedId, int ChanId,
38  const QDateTime &StartTime) override; // FrontendServices
39  bool PlayVideo(const QString &Id, bool UseBookmark) override; // FrontendServices
40  QStringList GetContextList(void) override; // FrontendServices
41  DTC::FrontendActionList* GetActionList(const QString &Context) override; // FrontendServices
42 
43 
44  static bool IsValidAction(const QString &action);
45  static void InitialiseActions(void);
46  bool SendKey(const QString &Key) override; // FrontendServices
47 
48  protected:
49  static QStringList gActionList;
50  static QHash<QString,QStringList> gActionDescriptions;
51 };
52 
53 // --------------------------------------------------------------------------
54 // The following class wrapper is due to a limitation in Qt Script Engine. It
55 // requires all methods that return pointers to user classes that are derived from
56 // QObject actually return QObject* (not the user class *). If the user class pointer
57 // is returned, the script engine treats it as a QVariant and doesn't create a
58 // javascript prototype wrapper for it.
59 //
60 // This class allows us to keep the rich return types in the main API class while
61 // offering the script engine a class it can work with.
62 //
63 // Only API Classes that return custom classes needs to implement these wrappers.
64 //
65 // We should continue to look for a cleaning solution to this problem.
66 // --------------------------------------------------------------------------
67 
68 class ScriptableFrontend : public QObject
69 {
70  Q_OBJECT
71 
72  private:
74  QScriptEngine *m_pEngine;
75 
76  public:
77  Q_INVOKABLE ScriptableFrontend( QScriptEngine *pEngine, QObject *parent = nullptr ) : QObject( parent )
78  {
79  m_pEngine = pEngine;
80  }
81  public slots:
82  QObject* GetStatus(void) { SCRIPT_CATCH_EXCEPTION( nullptr,
83  return m_obj.GetStatus(); ) }
84 };
85 
87 
88 #endif // FRONTEND_H
unsigned int slots[4]
Definition: element.c:38
QHash< QString, Action * > Context
Definition: action.h:75
static QHash< QString, QStringList > gActionDescriptions
unsigned int uint
Definition: compat.h:140
Q_INVOKABLE ScriptableFrontend(QScriptEngine *pEngine, QObject *parent=nullptr)
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 Timeout, bool Fullscreen, uint Visibility, uint Priority) override
Definition: frontend.cpp:58
QStringList GetContextList(void) override
Definition: frontend.cpp:248
DTC::FrontendActionList * GetActionList(const QString &Context) override
Definition: frontend.cpp:254
An action (for this plugin) consists of a description, and a set of key sequences.
Definition: action.h:38
static void InitialiseActions(void)
Definition: frontend.cpp:301
#define SCRIPT_CATCH_EXCEPTION(default, code)
Definition: service.h:83
bool PlayRecording(int RecordedId, int ChanId, const QDateTime &StartTime) override
Definition: frontend.cpp:128
bool SendMessage(const QString &Message, uint Timeout) override
Definition: frontend.cpp:44
Q_SCRIPT_DECLARE_QMETAOBJECT_MYTHTV(ScriptableFrontend, QObject *)
bool PlayVideo(const QString &Id, bool UseBookmark) override
Definition: frontend.cpp:192
bool SendAction(const QString &Action, const QString &Value, uint Width, uint Height) override
Definition: frontend.cpp:87
DTC::FrontendStatus * GetStatus(void) override
Definition: frontend.cpp:32
Q_INVOKABLE Frontend(QObject *parent=nullptr)
Definition: image.h:30
static bool IsValidAction(const QString &action)
Definition: frontend.cpp:279
bool SendKey(const QString &Key) override
Definition: frontend.cpp:335