1
0
Fork 0
flightgear/utils/fgqcanvas/applicationcontroller.h

202 lines
5.1 KiB
C
Raw Normal View History

//
// 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;
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)
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)
public:
explicit ApplicationController(QObject *parent = nullptr);
~ApplicationController();
2018-06-24 13:11:38 +00:00
void setWindow(QWindow* window);
void restoreWindowState();
2018-06-24 13:11:38 +00:00
void loadFromFile(QString path);
void setDaemonMode();
Q_INVOKABLE void query();
Q_INVOKABLE void cancelQuery();
Q_INVOKABLE void clearQuery();
2017-11-05 13:21:28 +00:00
Q_INVOKABLE void save(QString configName);
Q_INVOKABLE void restoreConfig(int index);
Q_INVOKABLE void deleteConfig(int index);
Q_INVOKABLE void saveConfigChanges(int index);
Q_INVOKABLE void openCanvas(QString path);
2018-11-06 17:58:44 +00:00
Q_INVOKABLE void closeCanvas(CanvasConnection* canvas);
2017-11-05 13:21:28 +00:00
Q_INVOKABLE void saveSnapshot(QString snapshotName);
Q_INVOKABLE void restoreSnapshot(int index);
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;
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);
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;
private slots:
void onFinishedGetCanvasList();
2018-11-06 17:58:44 +00:00
void onUIIdleTimeout();
private:
void setStatus(Status newStatus);
void rebuildConfigData();
2017-11-05 13:21:28 +00:00
void rebuildSnapshotData();
void clearConnections();
void doSaveToFile(QString path, QString configName);
QByteArray saveState(QString name) const;
void restoreState(QByteArray bytes);
2017-11-05 13:21:28 +00:00
QByteArray createSnapshot(QString name) const;
QString m_host;
unsigned int m_port;
QVariantList m_canvases;
QList<CanvasConnection*> m_activeCanvases;
QNetworkAccessManager* m_netAccess;
Status m_status;
QVariantList m_configs;
QNetworkReply* m_query = nullptr;
2017-11-05 13:21:28 +00:00
QVariantList m_snapshots;
2018-06-24 13:11:38 +00:00
QWindow* m_window = nullptr;
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;
};
#endif // APPLICATIONCONTROLLER_H