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 <QScriptEngine>
26 #include "services/imageServices.h"
27 #include "imagemanager.h"
28 
29 
30 class Image : public ImageServices
31 {
32  Q_OBJECT
33 
34 public:
35  Q_INVOKABLE explicit Image( QObject */*parent*/ = nullptr ) {}
36 
37 public:
38  QString GetImageInfo ( int id,
39  const QString &tag ) override; // ImageServices
40 
41  DTC::ImageMetadataInfoList* GetImageInfoList ( int id ) override; // ImageServices
42 
43  bool RemoveImage ( int id ) override; // ImageServices
44  bool RenameImage ( int id,
45  const QString &newName ) override; // ImageServices
46 
47  bool StartSync ( void ) override; // ImageServices
48  bool StopSync ( void ) override; // ImageServices
49  DTC::ImageSyncInfo* GetSyncStatus ( void ) override; // ImageServices
50 
51  bool CreateThumbnail (int id) override; // ImageServices
52 
53 };
54 
55 // --------------------------------------------------------------------------
56 // The following class wrapper is due to a limitation in Qt Script Engine. It
57 // requires all methods that return pointers to user classes that are derived from
58 // QObject actually return QObject* (not the user class *). If the user class pointer
59 // is returned, the script engine treats it as a QVariant and doesn't create a
60 // javascript prototype wrapper for it.
61 //
62 // This class allows us to keep the rich return types in the main API class while
63 // offering the script engine a class it can work with.
64 //
65 // Only API Classes that return custom classes needs to implement these wrappers.
66 //
67 // We should continue to look for a cleaning solution to this problem.
68 // --------------------------------------------------------------------------
69 
70 class ScriptableImage : public QObject
71 {
72  Q_OBJECT
73 
74  private:
75 
77  QScriptEngine *m_pEngine;
78 
79  public:
80 
81  Q_INVOKABLE ScriptableImage( QScriptEngine *pEngine, QObject *parent = nullptr ) : QObject( parent )
82  {
83  m_pEngine = pEngine;
84  }
85 
86  public slots:
87 
88  QString GetImageInfo( int Id,
89  const QString &Tag )
90  {
91  SCRIPT_CATCH_EXCEPTION( QString(),
92  return m_obj.GetImageInfo( Id, Tag );
93  )
94  }
95 
96  QObject* GetImageInfoList( int Id )
97  {
98  SCRIPT_CATCH_EXCEPTION( nullptr,
99  return m_obj.GetImageInfoList( Id );
100  )
101  }
102 
103  bool RemoveImage( int Id )
104  {
105  SCRIPT_CATCH_EXCEPTION( false,
106  return m_obj.RemoveImage( Id );
107  )
108  }
109 
110  bool RenameImage( int Id,
111  const QString &NewName )
112  {
113  SCRIPT_CATCH_EXCEPTION( false,
114  return m_obj.RenameImage( Id, NewName );
115  )
116  }
117 
118  bool StartSync( void )
119  {
120  SCRIPT_CATCH_EXCEPTION( false,
121  return m_obj.StartSync();
122  )
123  }
124 
125  bool StopSync( void )
126  {
127  SCRIPT_CATCH_EXCEPTION( false,
128  return m_obj.StopSync();
129  )
130  }
131 
132  QObject* GetSyncStatus( void )
133  {
134  SCRIPT_CATCH_EXCEPTION( nullptr,
135  return m_obj.GetSyncStatus();
136  )
137  }
138 
139  bool CreateThumbnail ( int Id )
140  {
141  SCRIPT_CATCH_EXCEPTION( false,
142  return m_obj.CreateThumbnail( Id );
143  )
144  }
145 };
146 
148 
149 #endif
unsigned int slots[4]
Definition: element.c:38
bool RenameImage(int id, const QString &newName) override
Renames the file to the new name.
Definition: image.cpp:148
Manages a collection of images.
QObject * GetSyncStatus(void)
Definition: image.h:132
bool RenameImage(int Id, const QString &NewName)
Definition: image.h:110
QScriptEngine * m_pEngine
Definition: image.h:77
bool CreateThumbnail(int Id)
Definition: image.h:139
QObject * GetImageInfoList(int Id)
Definition: image.h:96
DTC::ImageMetadataInfoList * GetImageInfoList(int id) override
Returns all values from all available exif tags.
Definition: image.cpp:75
bool StopSync(void) override
Stops the image synchronization if its running.
Definition: image.cpp:172
#define SCRIPT_CATCH_EXCEPTION(default, code)
Definition: service.h:83
Image m_obj
Definition: image.h:76
Q_INVOKABLE ScriptableImage(QScriptEngine *pEngine, QObject *parent=nullptr)
Definition: image.h:81
bool CreateThumbnail(int id) override
Request creation of a thumbnail.
Definition: image.cpp:219
bool StopSync(void)
Definition: image.h:125
QString GetImageInfo(int id, const QString &tag) override
Returns the value of the specified exif tag from the image file.
Definition: image.cpp:40
bool RemoveImage(int Id)
Definition: image.h:103
QString GetImageInfo(int Id, const QString &Tag)
Definition: image.h:88
DTC::ImageSyncInfo * GetSyncStatus(void) override
Returns a list with information if the synchronization is currently running, the already synchronized...
Definition: image.cpp:186
#define Q_SCRIPT_DECLARE_QMETAOBJECT_MYTHTV(T, _Arg1)
Definition: service.h:110
bool RemoveImage(int id) override
Deletes an image file or dir subtree from filesystem and database.
Definition: image.cpp:134
bool StartSync(void) override
Starts the synchronization of the images with the database.
Definition: image.cpp:160
Definition: image.h:30
bool StartSync(void)
Definition: image.h:118
Q_INVOKABLE Image(QObject *=nullptr)
Definition: image.h:35