MythTV  master
image.h
Go to the documentation of this file.
1 // Program Name: image.h
3 // Created : Jul. 27, 2012
4 //
5 // Copyright (c) 2012 Robert Siebert <trebor_s@web.de>
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or at your option any later version of the LGPL.
11 //
12 // This library 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 GNU
15 // Lesser General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public
18 // License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 //
21 
22 #ifndef IMAGE_H
23 #define IMAGE_H
24 
25 #include "libmythbase/mythconfig.h"
26 #if CONFIG_QTSCRIPT
27 #include <QScriptEngine>
28 #endif
31 
32 
33 class Image : public ImageServices
34 {
35  Q_OBJECT
36 
37 public:
38  Q_INVOKABLE explicit Image( QObject */*parent*/ = nullptr ) {}
39 
40 public:
41  QString GetImageInfo ( int id,
42  const QString &tag ) override; // ImageServices
43 
44  DTC::ImageMetadataInfoList* GetImageInfoList ( int id ) override; // ImageServices
45 
46  bool RemoveImage ( int id ) override; // ImageServices
47  bool RenameImage ( int id,
48  const QString &newName ) override; // ImageServices
49 
50  bool StartSync ( void ) override; // ImageServices
51  bool StopSync ( void ) override; // ImageServices
52  DTC::ImageSyncInfo* GetSyncStatus ( void ) override; // ImageServices
53 
54  bool CreateThumbnail (int id) override; // ImageServices
55 
56 };
57 
58 // --------------------------------------------------------------------------
59 // The following class wrapper is due to a limitation in Qt Script Engine. It
60 // requires all methods that return pointers to user classes that are derived from
61 // QObject actually return QObject* (not the user class *). If the user class pointer
62 // is returned, the script engine treats it as a QVariant and doesn't create a
63 // javascript prototype wrapper for it.
64 //
65 // This class allows us to keep the rich return types in the main API class while
66 // offering the script engine a class it can work with.
67 //
68 // Only API Classes that return custom classes needs to implement these wrappers.
69 //
70 // We should continue to look for a cleaning solution to this problem.
71 // --------------------------------------------------------------------------
72 
73 #if CONFIG_QTSCRIPT
74 class ScriptableImage : public QObject
75 {
76  Q_OBJECT
77 
78  private:
79 
80  Image m_obj;
81  QScriptEngine *m_pEngine;
82 
83  public:
84 
85  Q_INVOKABLE explicit ScriptableImage( QScriptEngine *pEngine, QObject *parent = nullptr ) : QObject( parent )
86  {
87  m_pEngine = pEngine;
88  }
89 
90  public slots:
91 
92  QString GetImageInfo( int Id,
93  const QString &Tag )
94  {
95  SCRIPT_CATCH_EXCEPTION( QString(),
96  return m_obj.GetImageInfo( Id, Tag );
97  )
98  }
99 
100  QObject* GetImageInfoList( int Id )
101  {
102  SCRIPT_CATCH_EXCEPTION( nullptr,
103  return m_obj.GetImageInfoList( Id );
104  )
105  }
106 
107  bool RemoveImage( int Id )
108  {
109  SCRIPT_CATCH_EXCEPTION( false,
110  return m_obj.RemoveImage( Id );
111  )
112  }
113 
114  bool RenameImage( int Id,
115  const QString &NewName )
116  {
117  SCRIPT_CATCH_EXCEPTION( false,
118  return m_obj.RenameImage( Id, NewName );
119  )
120  }
121 
122  bool StartSync( void )
123  {
124  SCRIPT_CATCH_EXCEPTION( false,
125  return m_obj.StartSync();
126  )
127  }
128 
129  bool StopSync( void )
130  {
131  SCRIPT_CATCH_EXCEPTION( false,
132  return m_obj.StopSync();
133  )
134  }
135 
136  QObject* GetSyncStatus( void )
137  {
138  SCRIPT_CATCH_EXCEPTION( nullptr,
139  return m_obj.GetSyncStatus();
140  )
141  }
142 
143  bool CreateThumbnail ( int Id )
144  {
145  SCRIPT_CATCH_EXCEPTION( false,
146  return m_obj.CreateThumbnail( Id );
147  )
148  }
149 };
150 
151 // NOLINTNEXTLINE(modernize-use-auto)
152 Q_SCRIPT_DECLARE_QMETAOBJECT_MYTHTV( ScriptableImage, QObject*)
153 #endif
154 
155 #endif
DTC::ImageSyncInfo
Definition: imageSyncInfo.h:14
ImageServices::StartSync
virtual bool StartSync(void)=0
Image::Image
Q_INVOKABLE Image(QObject *=nullptr)
Definition: image.h:38
ImageServices::GetImageInfo
virtual QString GetImageInfo(int Id, const QString &Tag)=0
imagemanager.h
Manages a collection of images.
ImageServices::GetSyncStatus
virtual DTC::ImageSyncInfo * GetSyncStatus(void)=0
ImageServices::RemoveImage
virtual bool RemoveImage(int Id)=0
ImageServices
Definition: imageServices.h:14
Q_SCRIPT_DECLARE_QMETAOBJECT_MYTHTV
#define Q_SCRIPT_DECLARE_QMETAOBJECT_MYTHTV(T, _Arg1)
Definition: service.h:113
ImageServices::StopSync
virtual bool StopSync(void)=0
imageServices.h
ImageServices::CreateThumbnail
virtual bool CreateThumbnail(int Id)=0
SCRIPT_CATCH_EXCEPTION
#define SCRIPT_CATCH_EXCEPTION(default, code)
Definition: service.h:85
DTC::ImageMetadataInfoList
Definition: imageMetadataInfoList.h:15
ImageServices::RenameImage
virtual bool RenameImage(int Id, const QString &NewName)=0
ImageServices::GetImageInfoList
virtual DTC::ImageMetadataInfoList * GetImageInfoList(int Id)=0