2017-02-21 11:01:06 +00:00
|
|
|
#ifndef MPSERVERSMODEL_H
|
|
|
|
#define MPSERVERSMODEL_H
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
|
|
|
|
#include <Network/RemoteXMLRequest.hxx>
|
|
|
|
|
|
|
|
|
|
|
|
class MPServersModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2018-05-28 16:39:35 +00:00
|
|
|
Q_PROPERTY(bool valid READ valid NOTIFY validChanged)
|
2018-10-25 11:10:42 +00:00
|
|
|
|
|
|
|
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
|
|
|
|
|
|
|
|
Q_PROPERTY(QString currentServer READ currentServer NOTIFY currentIndexChanged)
|
|
|
|
Q_PROPERTY(int currentPort READ currentPort NOTIFY currentIndexChanged)
|
2017-02-21 11:01:06 +00:00
|
|
|
public:
|
|
|
|
MPServersModel(QObject* parent = nullptr);
|
2018-10-25 11:10:42 +00:00
|
|
|
~MPServersModel() override;
|
2017-02-21 11:01:06 +00:00
|
|
|
|
|
|
|
int rowCount(const QModelIndex& index) const override;
|
|
|
|
|
|
|
|
QVariant data(const QModelIndex& index, int role) const override;
|
|
|
|
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
|
|
|
|
void onRefreshMPServersDone(simgear::HTTP::Request*);
|
|
|
|
void onRefreshMPServersFailed(simgear::HTTP::Request*);
|
|
|
|
int findMPServerPort(const std::string& host);
|
|
|
|
void restoreMPServerSelection();
|
|
|
|
|
|
|
|
void refresh();
|
|
|
|
|
|
|
|
void requestRestore();
|
|
|
|
|
2018-10-25 11:10:42 +00:00
|
|
|
QString currentServer() const;
|
|
|
|
int currentPort() const;
|
2018-05-28 16:39:35 +00:00
|
|
|
|
|
|
|
bool valid() const;
|
|
|
|
|
2018-10-25 11:10:42 +00:00
|
|
|
int currentIndex() const
|
|
|
|
{
|
|
|
|
return m_currentIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void setCurrentIndex(int currentIndex);
|
|
|
|
|
2017-02-21 11:01:06 +00:00
|
|
|
signals:
|
2018-05-28 16:39:35 +00:00
|
|
|
void validChanged();
|
2018-10-25 11:10:42 +00:00
|
|
|
void currentIndexChanged(int currentIndex);
|
2018-05-28 16:39:35 +00:00
|
|
|
|
2017-02-21 11:01:06 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
SGSharedPtr<RemoteXMLRequest> m_mpServerRequest;
|
|
|
|
bool m_doRestoreMPServer = false;
|
|
|
|
|
|
|
|
struct ServerInfo
|
|
|
|
{
|
|
|
|
ServerInfo(QString n, QString l, QString h, int port);
|
|
|
|
|
|
|
|
QString name, location, host;
|
|
|
|
int port = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<ServerInfo> m_servers;
|
2021-02-21 04:29:55 +00:00
|
|
|
int m_currentIndex = 0;
|
2017-02-21 11:01:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // MPSERVERSMODEL_H
|