MythTV  master
music.h
Go to the documentation of this file.
1 // Program Name: music.h
3 // Created : July 20, 2017
4 //
5 // Copyright (c) 2017 Paul Harrison <pharrison@mythtv.org>
6 //
7 // Licensed under the GPL v2 or later, see COPYING for details
8 //
10 
11 #ifndef MUSIC_H
12 #define MUSIC_H
13 
14 #include <QScriptEngine>
15 #include "services/musicServices.h"
16 
17 class Music : public MusicServices
18 {
19  Q_OBJECT
20 
21  public:
22 
23  Q_INVOKABLE explicit Music( QObject */*parent*/ = nullptr ) {}
24 
25  public:
26 
27  /* Music Metadata Methods */
28 
29  DTC::MusicMetadataInfoList* GetTrackList ( int StartIndex,
30  int Count ) override; // MusicServices
31 
32  DTC::MusicMetadataInfo* GetTrack ( int Id ) override; // MusicServices
33 
34 
35 };
36 
37 // --------------------------------------------------------------------------
38 // The following class wrapper is due to a limitation in Qt Script Engine. It
39 // requires all methods that return pointers to user classes that are derived from
40 // QObject actually return QObject* (not the user class *). If the user class pointer
41 // is returned, the script engine treats it as a QVariant and doesn't create a
42 // javascript prototype wrapper for it.
43 //
44 // This class allows us to keep the rich return types in the main API class while
45 // offering the script engine a class it can work with.
46 //
47 // Only API Classes that return custom classes needs to implement these wrappers.
48 //
49 // We should continue to look for a cleaning solution to this problem.
50 // --------------------------------------------------------------------------
51 
52 class ScriptableMusic : public QObject
53 {
54  Q_OBJECT
55 
56  private:
57 
59  QScriptEngine *m_pEngine;
60 
61  public:
62 
63  Q_INVOKABLE ScriptableMusic( QScriptEngine *pEngine, QObject *parent = nullptr ) : QObject( parent )
64  {
65  m_pEngine = pEngine;
66  }
67 
68  public slots:
69 
70  QObject* GetTrackList( int StartIndex,
71  int Count )
72  {
73  SCRIPT_CATCH_EXCEPTION( nullptr,
74  return m_obj.GetTrackList(StartIndex, Count );
75  )
76  }
77 
78  QObject* GetTrack( int Id )
79  {
80  SCRIPT_CATCH_EXCEPTION( nullptr,
81  return m_obj.GetTrack( Id );
82  )
83  }
84 };
85 
87 
88 #endif
QScriptEngine * m_pEngine
Definition: music.h:59
unsigned int slots[4]
Definition: element.c:38
DTC::MusicMetadataInfo * GetTrack(int Id) override
Definition: music.cpp:89
DTC::MusicMetadataInfoList * GetTrackList(int StartIndex, int Count) override
Definition: music.cpp:25
QObject * GetTrackList(int StartIndex, int Count)
Definition: music.h:70
Q_INVOKABLE Music(QObject *=nullptr)
Definition: music.h:23
#define SCRIPT_CATCH_EXCEPTION(default, code)
Definition: service.h:83
Music m_obj
Definition: music.h:58
Q_SCRIPT_DECLARE_QMETAOBJECT_MYTHTV(ScriptableMusic, QObject *)
QObject * GetTrack(int Id)
Definition: music.h:78
Q_INVOKABLE ScriptableMusic(QScriptEngine *pEngine, QObject *parent=nullptr)
Definition: music.h:63
Definition: music.h:17