minor fixes wrt commit 4e4a7563db
This commit is contained in:
parent
4e4a7563db
commit
3b70ad8c66
7 changed files with 46 additions and 34 deletions
|
@ -193,7 +193,7 @@ QT4_ADD_RESOURCES(cockatrice_RESOURCES_RCC ${cockatrice_RESOURCES})
|
||||||
INCLUDE(${QT_USE_FILE})
|
INCLUDE(${QT_USE_FILE})
|
||||||
INCLUDE_DIRECTORIES(../common)
|
INCLUDE_DIRECTORIES(../common)
|
||||||
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})
|
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})
|
||||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../common)
|
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/common)
|
||||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
|
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
|
||||||
INCLUDE_DIRECTORIES(${QT_MOBILITY_INCLUDE_DIR})
|
INCLUDE_DIRECTORIES(${QT_MOBILITY_INCLUDE_DIR})
|
||||||
INCLUDE_DIRECTORIES(${QT_MOBILITY_MULTIMEDIAKIT_INCLUDE_DIR})
|
INCLUDE_DIRECTORIES(${QT_MOBILITY_MULTIMEDIAKIT_INCLUDE_DIR})
|
||||||
|
|
|
@ -22,8 +22,10 @@
|
||||||
AbstractClient::AbstractClient(QObject *parent)
|
AbstractClient::AbstractClient(QObject *parent)
|
||||||
: QObject(parent), nextCmdId(0), status(StatusDisconnected)
|
: QObject(parent), nextCmdId(0), status(StatusDisconnected)
|
||||||
{
|
{
|
||||||
|
qRegisterMetaType<QVariant>("QVariant");
|
||||||
qRegisterMetaType<CommandContainer>("CommandContainer");
|
qRegisterMetaType<CommandContainer>("CommandContainer");
|
||||||
qRegisterMetaType<Response>("Response");
|
qRegisterMetaType<Response>("Response");
|
||||||
|
qRegisterMetaType<Response::ResponseCode>("Response::ResponseCode");
|
||||||
qRegisterMetaType<ClientStatus>("ClientStatus");
|
qRegisterMetaType<ClientStatus>("ClientStatus");
|
||||||
qRegisterMetaType<RoomEvent>("RoomEvent");
|
qRegisterMetaType<RoomEvent>("RoomEvent");
|
||||||
qRegisterMetaType<GameEventContainer>("GameEventContainer");
|
qRegisterMetaType<GameEventContainer>("GameEventContainer");
|
||||||
|
|
|
@ -24,18 +24,20 @@ RemoteClient::RemoteClient(QObject *parent)
|
||||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotSocketError(QAbstractSocket::SocketError)));
|
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotSocketError(QAbstractSocket::SocketError)));
|
||||||
|
|
||||||
connect(this, SIGNAL(serverIdentificationEventReceived(const Event_ServerIdentification &)), this, SLOT(processServerIdentificationEvent(const Event_ServerIdentification &)));
|
connect(this, SIGNAL(serverIdentificationEventReceived(const Event_ServerIdentification &)), this, SLOT(processServerIdentificationEvent(const Event_ServerIdentification &)));
|
||||||
|
connect(this, SIGNAL(sigConnectToServer(QString, unsigned int, QString, QString)), this, SLOT(doConnectToServer(QString, unsigned int, QString, QString)));
|
||||||
|
connect(this, SIGNAL(sigDisconnectFromServer()), this, SLOT(doDisconnectFromServer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteClient::~RemoteClient()
|
RemoteClient::~RemoteClient()
|
||||||
{
|
{
|
||||||
disconnectFromServer();
|
doDisconnectFromServer();
|
||||||
thread()->quit();
|
thread()->quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::slotSocketError(QAbstractSocket::SocketError /*error*/)
|
void RemoteClient::slotSocketError(QAbstractSocket::SocketError /*error*/)
|
||||||
{
|
{
|
||||||
QString errorString = socket->errorString();
|
QString errorString = socket->errorString();
|
||||||
disconnectFromServer();
|
doDisconnectFromServer();
|
||||||
emit socketError(errorString);
|
emit socketError(errorString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +120,7 @@ void RemoteClient::readData()
|
||||||
} while (!inputBuffer.isEmpty());
|
} while (!inputBuffer.isEmpty());
|
||||||
|
|
||||||
if (status == StatusDisconnecting)
|
if (status == StatusDisconnecting)
|
||||||
disconnectFromServer();
|
doDisconnectFromServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::sendCommandContainer(const CommandContainer &cont)
|
void RemoteClient::sendCommandContainer(const CommandContainer &cont)
|
||||||
|
@ -135,9 +137,9 @@ void RemoteClient::sendCommandContainer(const CommandContainer &cont)
|
||||||
socket->write(buf);
|
socket->write(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password)
|
void RemoteClient::doConnectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password)
|
||||||
{
|
{
|
||||||
disconnectFromServer();
|
doDisconnectFromServer();
|
||||||
|
|
||||||
userName = _userName;
|
userName = _userName;
|
||||||
password = _password;
|
password = _password;
|
||||||
|
@ -145,7 +147,7 @@ void RemoteClient::connectToServer(const QString &hostname, unsigned int port, c
|
||||||
setStatus(StatusConnecting);
|
setStatus(StatusConnecting);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteClient::disconnectFromServer()
|
void RemoteClient::doDisconnectFromServer()
|
||||||
{
|
{
|
||||||
timer->stop();
|
timer->stop();
|
||||||
|
|
||||||
|
@ -163,14 +165,15 @@ void RemoteClient::disconnectFromServer()
|
||||||
|
|
||||||
void RemoteClient::ping()
|
void RemoteClient::ping()
|
||||||
{
|
{
|
||||||
/* QMutableMapIterator<int, PendingCommand *> i(pendingCommands);
|
QMutableMapIterator<int, PendingCommand *> i(pendingCommands);
|
||||||
while (i.hasNext())
|
while (i.hasNext()) {
|
||||||
if (i.next().value()->tick() > maxTimeout) {
|
PendingCommand *pend = i.next().value();
|
||||||
CommandContainer *cont = i.value();
|
if (pend->tick() > maxTimeout) {
|
||||||
i.remove();
|
i.remove();
|
||||||
cont->deleteLater();
|
pend->deleteLater();
|
||||||
}
|
}
|
||||||
*/
|
}
|
||||||
|
|
||||||
int maxTime = timeRunning - lastDataReceived;
|
int maxTime = timeRunning - lastDataReceived;
|
||||||
emit maxPingTime(maxTime, maxTimeout);
|
emit maxPingTime(maxTime, maxTimeout);
|
||||||
if (maxTime >= maxTimeout) {
|
if (maxTime >= maxTimeout) {
|
||||||
|
@ -181,3 +184,13 @@ void RemoteClient::ping()
|
||||||
++timeRunning;
|
++timeRunning;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RemoteClient::connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password)
|
||||||
|
{
|
||||||
|
emit sigConnectToServer(hostname, port, _userName, _password);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoteClient::disconnectFromServer()
|
||||||
|
{
|
||||||
|
emit sigDisconnectFromServer();
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ signals:
|
||||||
void socketError(const QString &errorString);
|
void socketError(const QString &errorString);
|
||||||
void protocolVersionMismatch(int clientVersion, int serverVersion);
|
void protocolVersionMismatch(int clientVersion, int serverVersion);
|
||||||
void protocolError();
|
void protocolError();
|
||||||
|
void sigConnectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
|
||||||
|
void sigDisconnectFromServer();
|
||||||
private slots:
|
private slots:
|
||||||
void slotConnected();
|
void slotConnected();
|
||||||
void readData();
|
void readData();
|
||||||
|
@ -21,6 +23,8 @@ private slots:
|
||||||
void ping();
|
void ping();
|
||||||
void processServerIdentificationEvent(const Event_ServerIdentification &event);
|
void processServerIdentificationEvent(const Event_ServerIdentification &event);
|
||||||
void loginResponse(const Response &response);
|
void loginResponse(const Response &response);
|
||||||
|
void doConnectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
|
||||||
|
void doDisconnectFromServer();
|
||||||
private:
|
private:
|
||||||
static const int maxTimeout = 10;
|
static const int maxTimeout = 10;
|
||||||
int timeRunning, lastDataReceived;
|
int timeRunning, lastDataReceived;
|
||||||
|
@ -31,13 +35,12 @@ private:
|
||||||
|
|
||||||
QTimer *timer;
|
QTimer *timer;
|
||||||
QTcpSocket *socket;
|
QTcpSocket *socket;
|
||||||
|
protected slots:
|
||||||
void sendCommandContainer(const CommandContainer &cont);
|
void sendCommandContainer(const CommandContainer &cont);
|
||||||
public:
|
public:
|
||||||
RemoteClient(QObject *parent = 0);
|
RemoteClient(QObject *parent = 0);
|
||||||
~RemoteClient();
|
~RemoteClient();
|
||||||
QString peerName() const { return socket->peerName(); }
|
QString peerName() const { return socket->peerName(); }
|
||||||
|
|
||||||
void connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
|
void connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
|
||||||
void disconnectFromServer();
|
void disconnectFromServer();
|
||||||
};
|
};
|
||||||
|
|
|
@ -72,13 +72,19 @@ void CloseButton::paintEvent(QPaintEvent * /*event*/)
|
||||||
style()->drawPrimitive(QStyle::PE_IndicatorTabClose, &opt, &p, this);
|
style()->drawPrimitive(QStyle::PE_IndicatorTabClose, &opt, &p, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
TabSupervisor::TabSupervisor(QWidget *parent)
|
TabSupervisor::TabSupervisor(AbstractClient *_client, QWidget *parent)
|
||||||
: QTabWidget(parent), client(0), tabServer(0), tabDeckStorage(0), tabAdmin(0)
|
: QTabWidget(parent), client(_client), tabServer(0), tabDeckStorage(0), tabAdmin(0)
|
||||||
{
|
{
|
||||||
tabChangedIcon = new QIcon(":/resources/icon_tab_changed.svg");
|
tabChangedIcon = new QIcon(":/resources/icon_tab_changed.svg");
|
||||||
setElideMode(Qt::ElideRight);
|
setElideMode(Qt::ElideRight);
|
||||||
setIconSize(QSize(15, 15));
|
setIconSize(QSize(15, 15));
|
||||||
connect(this, SIGNAL(currentChanged(int)), this, SLOT(updateCurrent(int)));
|
connect(this, SIGNAL(currentChanged(int)), this, SLOT(updateCurrent(int)));
|
||||||
|
|
||||||
|
connect(client, SIGNAL(roomEventReceived(const RoomEvent &)), this, SLOT(processRoomEvent(const RoomEvent &)));
|
||||||
|
connect(client, SIGNAL(gameEventContainerReceived(const GameEventContainer &)), this, SLOT(processGameEventContainer(const GameEventContainer &)));
|
||||||
|
connect(client, SIGNAL(gameJoinedEventReceived(const Event_GameJoined &)), this, SLOT(gameJoined(const Event_GameJoined &)));
|
||||||
|
connect(client, SIGNAL(userMessageEventReceived(const Event_UserMessage &)), this, SLOT(processUserMessageEvent(const Event_UserMessage &)));
|
||||||
|
connect(client, SIGNAL(maxPingTime(int, int)), this, SLOT(updatePingTime(int, int)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TabSupervisor::~TabSupervisor()
|
TabSupervisor::~TabSupervisor()
|
||||||
|
@ -113,17 +119,10 @@ int TabSupervisor::myAddTab(Tab *tab)
|
||||||
return addTab(tab, tab->getTabText());
|
return addTab(tab, tab->getTabText());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabSupervisor::start(AbstractClient *_client, const ServerInfo_User &_userInfo)
|
void TabSupervisor::start(const ServerInfo_User &_userInfo)
|
||||||
{
|
{
|
||||||
client = _client;
|
|
||||||
userInfo = new ServerInfo_User(_userInfo);
|
userInfo = new ServerInfo_User(_userInfo);
|
||||||
|
|
||||||
connect(client, SIGNAL(roomEventReceived(const RoomEvent &)), this, SLOT(processRoomEvent(const RoomEvent &)));
|
|
||||||
connect(client, SIGNAL(gameEventContainerReceived(const GameEventContainer &)), this, SLOT(processGameEventContainer(const GameEventContainer &)));
|
|
||||||
connect(client, SIGNAL(gameJoinedEventReceived(const Event_GameJoined &)), this, SLOT(gameJoined(const Event_GameJoined &)));
|
|
||||||
connect(client, SIGNAL(userMessageEventReceived(const Event_UserMessage &)), this, SLOT(processUserMessageEvent(const Event_UserMessage &)));
|
|
||||||
connect(client, SIGNAL(maxPingTime(int, int)), this, SLOT(updatePingTime(int, int)));
|
|
||||||
|
|
||||||
tabServer = new TabServer(this, client);
|
tabServer = new TabServer(this, client);
|
||||||
connect(tabServer, SIGNAL(roomJoined(const ServerInfo_Room &, bool)), this, SLOT(addRoomTab(const ServerInfo_Room &, bool)));
|
connect(tabServer, SIGNAL(roomJoined(const ServerInfo_Room &, bool)), this, SLOT(addRoomTab(const ServerInfo_Room &, bool)));
|
||||||
myAddTab(tabServer);
|
myAddTab(tabServer);
|
||||||
|
@ -176,11 +175,6 @@ void TabSupervisor::stop()
|
||||||
if ((!client) && localClients.isEmpty())
|
if ((!client) && localClients.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (client) {
|
|
||||||
disconnect(client, 0, this, 0);
|
|
||||||
client = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!localClients.isEmpty()) {
|
if (!localClients.isEmpty()) {
|
||||||
for (int i = 0; i < localClients.size(); ++i)
|
for (int i = 0; i < localClients.size(); ++i)
|
||||||
localClients[i]->deleteLater();
|
localClients[i]->deleteLater();
|
||||||
|
|
|
@ -55,10 +55,10 @@ private:
|
||||||
int myAddTab(Tab *tab);
|
int myAddTab(Tab *tab);
|
||||||
void addCloseButtonToTab(Tab *tab, int tabIndex);
|
void addCloseButtonToTab(Tab *tab, int tabIndex);
|
||||||
public:
|
public:
|
||||||
TabSupervisor(QWidget *parent = 0);
|
TabSupervisor(AbstractClient *_client, QWidget *parent = 0);
|
||||||
~TabSupervisor();
|
~TabSupervisor();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void start(AbstractClient *_client, const ServerInfo_User &userInfo);
|
void start(const ServerInfo_User &userInfo);
|
||||||
void startLocal(const QList<AbstractClient *> &_clients);
|
void startLocal(const QList<AbstractClient *> &_clients);
|
||||||
void stop();
|
void stop();
|
||||||
int getGameCount() const { return gameTabs.size(); }
|
int getGameCount() const { return gameTabs.size(); }
|
||||||
|
|
|
@ -108,7 +108,7 @@ void MainWindow::statusChanged(ClientStatus _status)
|
||||||
|
|
||||||
void MainWindow::userInfoReceived(const ServerInfo_User &info)
|
void MainWindow::userInfoReceived(const ServerInfo_User &info)
|
||||||
{
|
{
|
||||||
tabSupervisor->start(client, info);
|
tabSupervisor->start(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
@ -352,7 +352,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
client->moveToThread(clientThread);
|
client->moveToThread(clientThread);
|
||||||
clientThread->start();
|
clientThread->start();
|
||||||
|
|
||||||
tabSupervisor = new TabSupervisor;
|
tabSupervisor = new TabSupervisor(client);
|
||||||
connect(tabSupervisor, SIGNAL(setMenu(QMenu *)), this, SLOT(updateTabMenu(QMenu *)));
|
connect(tabSupervisor, SIGNAL(setMenu(QMenu *)), this, SLOT(updateTabMenu(QMenu *)));
|
||||||
connect(tabSupervisor, SIGNAL(localGameEnded()), this, SLOT(localGameEnded()));
|
connect(tabSupervisor, SIGNAL(localGameEnded()), this, SLOT(localGameEnded()));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue