Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
ScriptManager.h
Go to the documentation of this file.
1#pragma once
2
3#include <QSettings>
4#include <QTimer>
5#include <QWidget>
8
9namespace sf
10{
11
12class ScriptManagerListModel;
13
14class ScriptEntry;
15
19class ScriptManager : public QObject
20{
21 Q_OBJECT
22
23 public:
27 explicit ScriptManager(QSettings* settings, QObject* parent);
28
32 ~ScriptManager() override;
33
40 [[nodiscard]] QString getScriptFilePath(const QString& base_name = QString()) const;
41
45 static QString getFileSuffix();
46
53
57 void storeSettings(bool save);
58
62 [[nodiscard]] bool isModified() const;
63
67 void addAt(qsizetype index = -1);
68
72 void remove(qsizetype index);
73
77 void start(qsizetype index = -1);
78
82 void stop(qsizetype index = -1);
83
87 ScriptEntry* getEntry(qsizetype index);
88
92 void setModified(QObject* caller);
93
97 const ScriptEntry* getEntryByFilepath(const QString& filepath);
98
99 private:
103 void backgroundRun();
104
108 [[nodiscard]] QStringList getFilenames() const;
109
113 QSettings* _settings;
117 QList<ScriptEntry*> _list;
121 bool _modified{false};
125 QString _subDirectory;
129 QTimer* _timer{nullptr};
130
131 friend ScriptManagerListModel;
132 friend ScriptEntry;
133};
134
138class ScriptEntry : public QObject
139{
140 Q_OBJECT
141
142 public:
155
156 Q_ENUM(EBackgroundMode)
157
158
161 explicit ScriptEntry(ScriptManager* parent)
162 : QObject(parent)
163 , _manager(parent)
164 {}
165
171 bool start();
172
176 void stop();
177
178 [[nodiscard]] const QKeySequence& getKeySequence() const;
179
180 void setKeySequence(const QKeySequence& ks);
181
182 [[nodiscard]] QString getDisplayName() const;
183
184 void setDisplayName(const QString& name);
185
186 [[nodiscard]] QString getScriptName() const;
187
188 void setScriptName(const QString& name);
189
190 [[nodiscard]] const QString& getFilename() const
191 {
192 return _filename;
193 }
194
195 void setFilename(const QString& name);
196
197 [[nodiscard]] EBackgroundMode getBackgroundMode() const
198 {
199 return _background;
200 }
201
203
204 void setInterpreter(const QSharedPointer<ScriptInterpreter>& interpreter)
205 {
206 _interpreter = interpreter;
207 }
208
209 [[nodiscard]] const QSharedPointer<ScriptInterpreter>& getInterpreter() const
210 {
211 return _interpreter;
212 }
213
214 [[nodiscard]] QString getStateName() const;
215
219 [[nodiscard]] bool isGlobal() const;
220
224 void setGlobal(bool);
225
226 private:
230 QString _filename{};
234 EBackgroundMode _background{bmNo};
238 QSharedPointer<ScriptInterpreter> _interpreter;
242 ScriptManager* _manager{nullptr};
246 QKeySequence _keySequence{};
250 GlobalShortcut* _globalShortcut{nullptr};
254 bool _global{false};
255};
256
257}// namespace sf
Script entry for the list contained by the manager.
Definition ScriptManager.h:139
const QKeySequence & getKeySequence() const
QString getDisplayName() const
bool start()
Compiles and initializes the script.
bool isGlobal() const
Sets the global shortcut global flag.
void setKeySequence(const QKeySequence &ks)
void setGlobal(bool)
Sets the global shortcut global flag.
void setBackgroundMode(EBackgroundMode bm)
void setInterpreter(const QSharedPointer< ScriptInterpreter > &interpreter)
Definition ScriptManager.h:204
QString getScriptName() const
void setScriptName(const QString &name)
EBackgroundMode getBackgroundMode() const
Definition ScriptManager.h:197
QString getStateName() const
void setFilename(const QString &name)
EBackgroundMode
Available background modes.
Definition ScriptManager.h:147
@ bmOnce
Definition ScriptManager.h:151
@ bmContinuous
Definition ScriptManager.h:153
@ bmNo
Definition ScriptManager.h:149
void setDisplayName(const QString &name)
void stop()
Stops a script from running in the background.
const QString & getFilename() const
Definition ScriptManager.h:190
const QSharedPointer< ScriptInterpreter > & getInterpreter() const
Definition ScriptManager.h:209
Manages scripts for the application.
Definition ScriptManager.h:20
void storeSettings(bool save)
Saves and restores the entries from settings.
void addAt(qsizetype index=-1)
Adds and empty entry to the list.
const ScriptEntry * getEntryByFilepath(const QString &filepath)
Gets the entry pointer form the passed absolute file path.
void remove(qsizetype index)
Removes an entry in the list.
ScriptManager(QSettings *settings, QObject *parent)
Constructor.
ScriptEntry * getEntry(qsizetype index)
Gets the entry from the list by index.
~ScriptManager() override
Overridden destructor.
void start(qsizetype index=-1)
Compiles and initializes script at passed position or all scripts when passing -1.
QString getScriptFilePath(const QString &base_name=QString()) const
Gets the full file path of a script name passed.
void stop(qsizetype index=-1)
Stops script at passed position or all scripts when passing -1.
static QString getFileSuffix()
Gets the file extension used for scripts.
void setModified(QObject *caller)
Sets the modified flag and notifies ...
bool isModified() const
Gets status whether to save to settings is needed.
void shortcutActivated(ScriptEntry *entry)
Gets called from an entry when a shortcut is activated.
Definition Application.h:10