File indexing completed on 2023-10-01 08:01:44
0001 // Copyright (c) 2002-2004 Rob Kaper <cap@capsi.com> 0002 // 0003 // This program is free software; you can redistribute it and/or 0004 // modify it under the terms of the GNU General Public License 0005 // version 2 as published by the Free Software Foundation. 0006 // 0007 // This program is distributed in the hope that it will be useful, 0008 // but WITHOUT ANY WARRANTY; without even the implied warranty of 0009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0010 // General Public License for more details. 0011 // 0012 // You should have received a copy of the GNU General Public License 0013 // along with this program; see the file COPYING. If not, write to 0014 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0015 // Boston, MA 02110-1301, USA. 0016 0017 #ifndef ATLANTIK_SELECTSERVER_WIDGET_H 0018 #define ATLANTIK_SELECTSERVER_WIDGET_H 0019 0020 #include <QWidget> 0021 #include <QTreeWidgetItem> 0022 #include <QElapsedTimer> 0023 #include <QVector> 0024 0025 #include <ui_selectserver.h> 0026 0027 class QTcpSocket; 0028 0029 class Metatlantic; 0030 0031 class MetaserverEntry : public QObject, public QTreeWidgetItem 0032 { 0033 Q_OBJECT 0034 0035 public: 0036 enum { MetaserverType = UserType + 1 }; 0037 0038 MetaserverEntry(const QString &host, int port, const QString &version, int users); 0039 bool isDev() const; 0040 QString host() const; 0041 int port() const; 0042 0043 bool operator<(const QTreeWidgetItem &other) const override; 0044 0045 private Q_SLOTS: 0046 void resolved(); 0047 void connected(); 0048 0049 private: 0050 int m_latency; 0051 int m_users; 0052 int m_port; 0053 QTcpSocket *m_latencySocket; 0054 QElapsedTimer m_timer; 0055 bool m_isDev; 0056 }; 0057 0058 class SelectServer : public QWidget, private Ui::SelectServer 0059 { 0060 Q_OBJECT 0061 0062 public: 0063 SelectServer(bool hideDevelopmentServers, QWidget *parent); 0064 virtual ~SelectServer(); 0065 0066 void setHideDevelopmentServers(bool hideDevelopmentServers); 0067 0068 public Q_SLOTS: 0069 void validateConnectButton(); 0070 void validateCustomConnectButton(); 0071 void reloadServerList(); 0072 void slotMetatlanticAdd(const QString &host, int port, const QString &version, int users); 0073 0074 private Q_SLOTS: 0075 void slotConnect(); 0076 void customConnect(); 0077 void metatlanticFinished(); 0078 0079 Q_SIGNALS: 0080 void serverConnect(const QString &host, int port); 0081 void msgStatus(const QString &message); 0082 0083 private: 0084 void initMetaserver(); 0085 0086 Metatlantic *m_metatlantic; 0087 bool m_hideDevelopmentServers; 0088 QVector<MetaserverEntry *> m_developmentServers; 0089 }; 0090 0091 #endif