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 explicit 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 
86 // NOLINTNEXTLINE(modernize-use-auto)
88 
89 #endif // FRONTEND_H
ScriptableFrontend
Definition: programs/mythfrontend/services/frontend.h:69
ScriptableFrontend::m_obj
Frontend m_obj
Definition: programs/mythfrontend/services/frontend.h:73
Frontend::GetStatus
DTC::FrontendStatus * GetStatus(void) override
Definition: frontend.cpp:32
Frontend::PlayVideo
bool PlayVideo(const QString &Id, bool UseBookmark) override
Definition: frontend.cpp:193
service.h
FrontendServices
Definition: frontendServices.h:9
MythFEXML
Definition: mythfexml.h:25
Frontend::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 Timeout, bool Fullscreen, uint Visibility, uint Priority) override
Definition: frontend.cpp:58
Context
QHash< QString, Action * > Context
Definition: action.h:77
Image
Definition: image.h:31
Action
An action (for this plugin) consists of a description, and a set of key sequences.
Definition: action.h:41
frontendServices.h
Frontend::GetActionList
DTC::FrontendActionList * GetActionList(const QString &Context) override
Definition: frontend.cpp:255
ScriptableFrontend::m_pEngine
QScriptEngine * m_pEngine
Definition: programs/mythfrontend/services/frontend.h:74
Frontend
Definition: backendcontext.h:29
ScriptableFrontend::GetStatus
QObject * GetStatus(void)
Definition: programs/mythfrontend/services/frontend.h:82
Frontend::SendKey
bool SendKey(const QString &Key) override
Definition: frontend.cpp:336
uint
unsigned int uint
Definition: compat.h:140
SCRIPT_CATCH_EXCEPTION
#define SCRIPT_CATCH_EXCEPTION(default, code)
Definition: service.h:83
DTC::FrontendStatus
Definition: frontendStatus.h:10
Frontend::gActionList
static QStringList gActionList
Definition: programs/mythfrontend/services/frontend.h:49
Frontend::GetContextList
QStringList GetContextList(void) override
Definition: frontend.cpp:249
DTC::FrontendActionList
Definition: frontendActionList.h:10
Frontend::PlayRecording
bool PlayRecording(int RecordedId, int ChanId, const QDateTime &StartTime) override
Definition: frontend.cpp:130
Frontend::gActionDescriptions
static QHash< QString, QStringList > gActionDescriptions
Definition: programs/mythfrontend/services/frontend.h:50
ScriptableFrontend::ScriptableFrontend
Q_INVOKABLE ScriptableFrontend(QScriptEngine *pEngine, QObject *parent=nullptr)
Definition: programs/mythfrontend/services/frontend.h:77
build_compdb.action
action
Definition: build_compdb.py:9
Frontend::Frontend
Q_INVOKABLE Frontend(QObject *parent=nullptr)
Definition: programs/mythfrontend/services/frontend.h:15
Frontend::SendMessage
bool SendMessage(const QString &Message, uint Timeout) override
Definition: frontend.cpp:44
Frontend::SendAction
bool SendAction(const QString &Action, const QString &Value, uint Width, uint Height) override
Definition: frontend.cpp:87
Frontend::IsValidAction
static bool IsValidAction(const QString &action)
Definition: frontend.cpp:280
Frontend::InitialiseActions
static void InitialiseActions(void)
Definition: frontend.cpp:302
Q_SCRIPT_DECLARE_QMETAOBJECT_MYTHTV
Q_SCRIPT_DECLARE_QMETAOBJECT_MYTHTV(ScriptableFrontend, QObject *)
Priority
Definition: channelsettings.cpp:192