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

125 lines
3 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;
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)
Q_PROPERTY(QQmlListProperty<CanvasConnection> activeCanvases READ activeCanvases NOTIFY activeCanvasesChanged)
Q_ENUMS(Status)
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
public:
explicit ApplicationController(QObject *parent = nullptr);
~ApplicationController();
Q_INVOKABLE void save(QString configName);
Q_INVOKABLE void query();
Q_INVOKABLE void restoreConfig(int index);
Q_INVOKABLE void openCanvas(QString path);
// void restore();
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;
}
signals:
void hostChanged(QString host);
void portChanged(unsigned int port);
void activeCanvasesChanged();
void canvasListChanged();
void statusChanged(Status status);
void configListChanged(QVariantList configs);
public slots:
void setHost(QString host);
void setPort(unsigned int port);
private slots:
void onFinishedGetCanvasList();
private:
void setStatus(Status newStatus);
void rebuildConfigData();
QByteArray saveState(QString name) const;
void restoreState(QByteArray bytes);
QString m_host;
unsigned int m_port;
QVariantList m_canvases;
QList<CanvasConnection*> m_activeCanvases;
QNetworkAccessManager* m_netAccess;
Status m_status;
QVariantList m_configs;
};
#endif // APPLICATIONCONTROLLER_H