Sanmill/NineChess/src/client.h

79 lines
2.1 KiB
C++

/*****************************************************************************
* Copyright (C) 2019 NineChess authors
*
* Authors: Calcitem <calcitem@outlook.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 CLIENT_H
#define CLIENT_H
#include <QDataStream>
#include <QDialog>
#include <QTcpSocket>
QT_BEGIN_NAMESPACE
class QComboBox;
class QLabel;
class QLineEdit;
class QPushButton;
class QTcpSocket;
class QNetworkSession;
QT_END_NAMESPACE
class Client : public QDialog
{
Q_OBJECT
public:
explicit Client(QWidget *parent = nullptr, uint16_t port = 33333);
signals:
void command(const QString &cmd, bool update = true);
private slots:
void requestNewAction();
void readAction();
void displayError(QAbstractSocket::SocketError socketError);
void enableGetActionButton();
void sessionOpened();
void setPort(uint16_t port)
{
this->port = port;
}
uint16_t getPort()
{
return port;
}
private:
QComboBox *hostCombo = nullptr;
QLineEdit *portLineEdit = nullptr;
QLabel *statusLabel = nullptr;
QPushButton *getActionButton = nullptr;
QTcpSocket *tcpSocket = nullptr;
QDataStream in;
QString currentAction;
QNetworkSession *networkSession = nullptr;
uint16_t port;
};
#endif // CLIENT_H