| 1 |
#ifndef MPSERVERSMODEL_H |
| 2 |
#define MPSERVERSMODEL_H |
| 3 |
|
| 4 |
#include <QAbstractListModel> |
| 5 |
|
| 6 |
#include <Network/RemoteXMLRequest.hxx> |
| 7 |
|
| 8 |
|
| 9 |
class MPServersModel : public QAbstractListModel |
| 10 |
{ |
| 11 |
Q_OBJECT |
| 12 |
|
| 13 |
Q_PROPERTY(bool valid READ valid NOTIFY validChanged) |
| 14 |
|
| 15 |
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) |
| 16 |
|
| 17 |
Q_PROPERTY(QString currentServer READ currentServer NOTIFY currentIndexChanged) |
| 18 |
Q_PROPERTY(int currentPort READ currentPort NOTIFY currentIndexChanged) |
| 19 |
public: |
| 20 |
MPServersModel(QObject* parent = nullptr); |
| 21 |
~MPServersModel() override; |
| 22 |
|
| 23 |
int rowCount(const QModelIndex& index) const override; |
| 24 |
|
| 25 |
QVariant data(const QModelIndex& index, int role) const override; |
| 26 |
|
| 27 |
QHash<int, QByteArray> roleNames() const override; |
| 28 |
|
| 29 |
void onRefreshMPServersDone(simgear::HTTP::Request*); |
| 30 |
void onRefreshMPServersFailed(simgear::HTTP::Request*); |
| 31 |
int findMPServerPort(const std::string& host); |
| 32 |
void restoreMPServerSelection(); |
| 33 |
|
| 34 |
void refresh(); |
| 35 |
|
| 36 |
void requestRestore(); |
| 37 |
|
| 38 |
QString currentServer() const; |
| 39 |
int currentPort() const; |
| 40 |
|
| 41 |
bool valid() const; |
| 42 |
|
| 43 |
int currentIndex() const |
| 44 |
{ |
| 45 |
return m_currentIndex; |
| 46 |
} |
| 47 |
|
| 48 |
public slots: |
| 49 |
void setCurrentIndex(int currentIndex); |
| 50 |
|
| 51 |
signals: |
| 52 |
void validChanged(); |
| 53 |
void currentIndexChanged(int currentIndex); |
| 54 |
|
| 55 |
private: |
| 56 |
|
| 57 |
SGSharedPtr<RemoteXMLRequest> m_mpServerRequest; |
| 58 |
bool m_doRestoreMPServer = false; |
| 59 |
|
| 60 |
struct ServerInfo |
| 61 |
{ |
| 62 |
ServerInfo(QString n, QString l, QString h, int port); |
| 63 |
|
| 64 |
QString name, location, host; |
| 65 |
int port = 0; |
| 66 |
}; |
| 67 |
|
| 68 |
std::vector<ServerInfo> m_servers; |
| 69 |
int m_currentIndex = 0; |
| 70 |
}; |
| 71 |
|
| 72 |
#endif |