2017-11-02 17:20:42 +00:00
|
|
|
//
|
|
|
|
// Copyright (C) 2017 James Turner zakalawe@mac.com
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
#ifndef APPLICATIONCONTROLLER_H
|
|
|
|
#define APPLICATIONCONTROLLER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QQmlListProperty>
|
|
|
|
#include <QVariantList>
|
|
|
|
|
|
|
|
class CanvasConnection;
|
2018-06-24 13:11:38 +00:00
|
|
|
class QWindow;
|
2018-11-06 17:58:44 +00:00
|
|
|
class QTimer;
|
2017-11-02 17:20:42 +00:00
|
|
|
|
|
|
|
class ApplicationController : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
|
|
Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged)
|
|
|
|
Q_PROPERTY(unsigned int port READ port WRITE setPort NOTIFY portChanged)
|
|
|
|
|
|
|
|
Q_PROPERTY(QVariantList canvases READ canvases NOTIFY canvasListChanged)
|
|
|
|
Q_PROPERTY(QVariantList configs READ configs NOTIFY configListChanged)
|
2017-11-05 13:21:28 +00:00
|
|
|
Q_PROPERTY(QVariantList snapshots READ snapshots NOTIFY snapshotListChanged)
|
2017-11-02 17:20:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
Q_PROPERTY(QQmlListProperty<CanvasConnection> activeCanvases READ activeCanvases NOTIFY activeCanvasesChanged)
|
|
|
|
|
|
|
|
Q_ENUMS(Status)
|
|
|
|
|
|
|
|
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
|
2018-06-24 13:11:38 +00:00
|
|
|
|
2018-11-06 17:58:44 +00:00
|
|
|
Q_PROPERTY(bool showUI READ showUI NOTIFY showUIChanged)
|
|
|
|
Q_PROPERTY(bool blockUIIdle READ blockUIIdle WRITE setBlockUIIdle NOTIFY blockUIIdleChanged)
|
2018-11-08 08:40:53 +00:00
|
|
|
|
|
|
|
Q_PROPERTY(QString gettingStartedText READ gettingStartedText CONSTANT)
|
|
|
|
Q_PROPERTY(bool showGettingStarted READ showGettingStarted WRITE setShowGettingStarted NOTIFY showGettingStartedChanged)
|
2017-11-02 17:20:42 +00:00
|
|
|
public:
|
|
|
|
explicit ApplicationController(QObject *parent = nullptr);
|
|
|
|
~ApplicationController();
|
|
|
|
|
2018-06-24 13:11:38 +00:00
|
|
|
void setWindow(QWindow* window);
|
|
|
|
|
2018-06-26 22:23:49 +00:00
|
|
|
void restoreWindowState();
|
|
|
|
|
2018-06-24 13:11:38 +00:00
|
|
|
void loadFromFile(QString path);
|
|
|
|
|
2018-06-26 22:23:49 +00:00
|
|
|
void setDaemonMode();
|
|
|
|
|
2017-11-02 17:20:42 +00:00
|
|
|
Q_INVOKABLE void query();
|
2017-11-03 13:56:43 +00:00
|
|
|
Q_INVOKABLE void cancelQuery();
|
|
|
|
Q_INVOKABLE void clearQuery();
|
2017-11-02 17:20:42 +00:00
|
|
|
|
2017-11-05 13:21:28 +00:00
|
|
|
Q_INVOKABLE void save(QString configName);
|
2017-11-02 17:20:42 +00:00
|
|
|
Q_INVOKABLE void restoreConfig(int index);
|
2017-11-03 15:45:44 +00:00
|
|
|
Q_INVOKABLE void deleteConfig(int index);
|
|
|
|
Q_INVOKABLE void saveConfigChanges(int index);
|
2017-11-02 17:20:42 +00:00
|
|
|
|
|
|
|
Q_INVOKABLE void openCanvas(QString path);
|
2018-11-06 17:58:44 +00:00
|
|
|
Q_INVOKABLE void closeCanvas(CanvasConnection* canvas);
|
2017-11-02 17:20:42 +00:00
|
|
|
|
2017-11-05 13:21:28 +00:00
|
|
|
Q_INVOKABLE void saveSnapshot(QString snapshotName);
|
|
|
|
Q_INVOKABLE void restoreSnapshot(int index);
|
|
|
|
|
2017-11-02 17:20:42 +00:00
|
|
|
QString host() const;
|
|
|
|
|
|
|
|
unsigned int port() const;
|
|
|
|
|
|
|
|
QVariantList canvases() const;
|
|
|
|
|
|
|
|
QQmlListProperty<CanvasConnection> activeCanvases();
|
|
|
|
|
|
|
|
QNetworkAccessManager* netAccess() const;
|
|
|
|
|
|
|
|
enum Status {
|
|
|
|
Idle,
|
|
|
|
Querying,
|
|
|
|
SuccessfulQuery,
|
|
|
|
QueryFailed
|
|
|
|
};
|
|
|
|
|
|
|
|
Status status() const
|
|
|
|
{
|
|
|
|
return m_status;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariantList configs() const
|
|
|
|
{
|
|
|
|
return m_configs;
|
|
|
|
}
|
|
|
|
|
2017-11-05 13:21:28 +00:00
|
|
|
QVariantList snapshots() const
|
|
|
|
{
|
|
|
|
return m_snapshots;
|
|
|
|
}
|
|
|
|
|
2018-11-06 17:58:44 +00:00
|
|
|
bool showUI() const;
|
|
|
|
|
|
|
|
bool blockUIIdle() const
|
|
|
|
{
|
|
|
|
return m_blockUIIdle;
|
|
|
|
}
|
|
|
|
|
2018-11-08 08:40:53 +00:00
|
|
|
QString gettingStartedText() const;
|
|
|
|
|
|
|
|
bool showGettingStarted() const;
|
|
|
|
|
2017-11-02 17:20:42 +00:00
|
|
|
signals:
|
|
|
|
|
|
|
|
void hostChanged(QString host);
|
|
|
|
|
|
|
|
void portChanged(unsigned int port);
|
|
|
|
|
|
|
|
void activeCanvasesChanged();
|
|
|
|
|
|
|
|
void canvasListChanged();
|
|
|
|
void statusChanged(Status status);
|
|
|
|
|
|
|
|
void configListChanged(QVariantList configs);
|
|
|
|
|
2017-11-05 13:21:28 +00:00
|
|
|
void snapshotListChanged();
|
|
|
|
|
2018-11-06 17:58:44 +00:00
|
|
|
void showUIChanged();
|
|
|
|
void blockUIIdleChanged(bool blockUIIdle);
|
|
|
|
|
2018-11-08 08:40:53 +00:00
|
|
|
void showGettingStartedChanged(bool showGettingStarted);
|
|
|
|
|
2017-11-02 17:20:42 +00:00
|
|
|
public slots:
|
|
|
|
void setHost(QString host);
|
|
|
|
|
|
|
|
void setPort(unsigned int port);
|
|
|
|
|
2018-11-06 17:58:44 +00:00
|
|
|
void setBlockUIIdle(bool blockUIIdle)
|
|
|
|
{
|
|
|
|
if (m_blockUIIdle == blockUIIdle)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_blockUIIdle = blockUIIdle;
|
|
|
|
emit blockUIIdleChanged(m_blockUIIdle);
|
|
|
|
}
|
|
|
|
|
2018-11-08 08:40:53 +00:00
|
|
|
void setShowGettingStarted(bool showGettingStarted);
|
|
|
|
|
2018-11-06 17:58:44 +00:00
|
|
|
protected:
|
|
|
|
bool eventFilter(QObject* obj, QEvent* event) override;
|
|
|
|
|
2017-11-02 17:20:42 +00:00
|
|
|
private slots:
|
|
|
|
void onFinishedGetCanvasList();
|
2018-11-06 17:58:44 +00:00
|
|
|
void onUIIdleTimeout();
|
2017-11-02 17:20:42 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setStatus(Status newStatus);
|
|
|
|
|
|
|
|
void rebuildConfigData();
|
2017-11-05 13:21:28 +00:00
|
|
|
void rebuildSnapshotData();
|
2017-11-03 13:56:43 +00:00
|
|
|
void clearConnections();
|
2017-11-02 17:20:42 +00:00
|
|
|
|
2017-11-03 15:45:44 +00:00
|
|
|
void doSaveToFile(QString path, QString configName);
|
|
|
|
|
2017-11-02 17:20:42 +00:00
|
|
|
QByteArray saveState(QString name) const;
|
|
|
|
void restoreState(QByteArray bytes);
|
|
|
|
|
2017-11-05 13:21:28 +00:00
|
|
|
QByteArray createSnapshot(QString name) const;
|
|
|
|
|
2017-11-02 17:20:42 +00:00
|
|
|
QString m_host;
|
|
|
|
unsigned int m_port;
|
|
|
|
QVariantList m_canvases;
|
|
|
|
QList<CanvasConnection*> m_activeCanvases;
|
|
|
|
QNetworkAccessManager* m_netAccess;
|
|
|
|
Status m_status;
|
|
|
|
QVariantList m_configs;
|
2017-11-03 13:56:43 +00:00
|
|
|
QNetworkReply* m_query = nullptr;
|
2017-11-05 13:21:28 +00:00
|
|
|
QVariantList m_snapshots;
|
2018-06-26 22:23:49 +00:00
|
|
|
|
2018-06-24 13:11:38 +00:00
|
|
|
QWindow* m_window = nullptr;
|
2018-06-26 22:23:49 +00:00
|
|
|
Qt::WindowState m_windowState = Qt::WindowNoState;
|
|
|
|
|
|
|
|
bool m_daemonMode = false;
|
2018-11-06 17:58:44 +00:00
|
|
|
bool m_showUI = true;
|
|
|
|
bool m_blockUIIdle = false;
|
|
|
|
QTimer* m_uiIdleTimer;
|
2017-11-02 17:20:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // APPLICATIONCONTROLLER_H
|