diff --git a/src/gui/qt/connecttoserverdialog/connecttoserverdialogimpl.cpp b/src/gui/qt/connecttoserverdialog/connecttoserverdialogimpl.cpp index a86e18a6..9c871fa5 100644 --- a/src/gui/qt/connecttoserverdialog/connecttoserverdialogimpl.cpp +++ b/src/gui/qt/connecttoserverdialog/connecttoserverdialogimpl.cpp @@ -19,73 +19,69 @@ ***************************************************************************/ #include "connecttoserverdialogimpl.h" // #include "configfile.h" +#include connectToServerDialogImpl::connectToServerDialogImpl(QWidget *parent) : QDialog(parent) { setupUi(this); - - - } void connectToServerDialogImpl::refresh(int actionID) { - int maxStateNumber = 4; - switch (actionID) { - case 0: { label_actionMessage->setText("msg0"); } + case MSG_SOCK_INIT_DONE: { label_actionMessage->setText("Resolving address..."); } break; - case 1: { label_actionMessage->setText("msg1"); } + case MSG_SOCK_RESOLVE_DONE: { label_actionMessage->setText("Connecting to server..."); } break; - case 2: { label_actionMessage->setText("msg2"); } - break; - case 3: { label_actionMessage->setText("msg3"); } - break; - case 4: { label_actionMessage->setText("msg4"); } + case MSG_SOCK_CONNECT_DONE: { label_actionMessage->setText("Connection established."); } break; default: { label_actionMessage->setText("ERROR"); } } - progressBar->setValue(actionID*(100/maxStateNumber)); + progressBar->setValue(actionID*(100/MSG_SOCK_LAST)); - if (actionID*(100/maxStateNumber == 100)) { QTimer::singleShot(500, this, SLOT(hide())); } + if (actionID == MSG_SOCK_LAST) + QTimer::singleShot(500, this, SLOT(hide())); } void connectToServerDialogImpl::error(int errorID, int osErrorID) { - if(osErrorID) { - QMessageBox::warning(this, tr("Connection Error"), - tr("An Operating System Error occured during Connection"), - QMessageBox::Close); - return; - } - switch (errorID) { - case 0: { QMessageBox::warning(this, tr("Connection Error"), - tr("Error0 occured during Connection"), + case ERR_SOCK_SERVERADDR_NOT_SET: + {QMessageBox::warning(this, tr("Network Error"), + tr("Server address was not set."), QMessageBox::Close); } break; - case 1: {QMessageBox::warning(this, tr("Connection Error"), - tr("Error1 occured during Connection"), + case ERR_SOCK_INVALID_PORT: + { QMessageBox::warning(this, tr("Network Error"), + tr("An invalid port was set (ports 0-1023 are not allowed)."), QMessageBox::Close); } break; - case 2: { QMessageBox::warning(this, tr("Connection Error"), - tr("Error2 occured during Connection"), + case ERR_SOCK_CREATION_FAILED: + { QMessageBox::warning(this, tr("Network Error"), + tr("Could not create socket."), QMessageBox::Close); } break; - case 3: { QMessageBox::warning(this, tr("Connection Error"), - tr("Error3 occured during Connection"), + case ERR_SOCK_SET_PORT_FAILED: + { QMessageBox::warning(this, tr("Network Error"), + tr("Could not set the port for this type of address."), QMessageBox::Close); } break; - case 4: { QMessageBox::warning(this, tr("Connection Error"), - tr("Error4 occured during Connection"), + case ERR_SOCK_RESOLVE_FAILED: + { QMessageBox::warning(this, tr("Network Error"), + tr("The server name could not be resolved."), QMessageBox::Close); } break; - default: { QMessageBox::warning(this, tr("Connection Error"), + case ERR_SOCK_CONNECT_FAILED: + { QMessageBox::warning(this, tr("Network Error"), + tr("Could not connect to server."), + QMessageBox::Close); } + break; + default: { QMessageBox::warning(this, tr("Network Error"), tr("DEFAULT ERROR"), QMessageBox::Close); } } diff --git a/src/gui/qt/guiwrapper.cpp b/src/gui/qt/guiwrapper.cpp index 7e109b43..f0d2c9d8 100644 --- a/src/gui/qt/guiwrapper.cpp +++ b/src/gui/qt/guiwrapper.cpp @@ -23,6 +23,14 @@ using namespace std; +NetSignalDispatcher::NetSignalDispatcher(connectToServerDialogImpl *dialog) +{ + connect(this, SIGNAL(SignalNetClientSuccess(int)), + dialog, SLOT(refresh(int))); + connect(this, SIGNAL(SignalNetClientError(int, int)), + dialog, SLOT(error(int, int))); +} + GuiWrapper::GuiWrapper() : myLog(0), myW(0) { @@ -34,6 +42,8 @@ GuiWrapper::GuiWrapper() : myLog(0), myW(0) myLog = new Log(myW); myConnectToServerDialog = new connectToServerDialogImpl(); + myNetSignalDispatcher = new NetSignalDispatcher(myConnectToServerDialog); + myConfig = new ConfigFile; } @@ -90,5 +100,5 @@ void GuiWrapper::meInAction() const { myW->meInAction(); } void GuiWrapper::logPlayerActionMsg(string playerName, int action, int setValue) { myLog->logPlayerActionMsg(playerName, action, setValue); } void GuiWrapper::logNewGameHandMsg(int gameID, int handID) { myLog->logNewGameHandMsg(gameID, handID); } -void GuiWrapper::SignalNetClientSuccess(int actionID) { myConnectToServerDialog->refresh(actionID); } -void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myConnectToServerDialog->error(errorID, osErrorID); } +void GuiWrapper::SignalNetClientSuccess(int actionID) { myNetSignalDispatcher->SignalNetClientSuccess(actionID); } +void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myNetSignalDispatcher->SignalNetClientError(errorID, osErrorID); } diff --git a/src/gui/qt/guiwrapper.h b/src/gui/qt/guiwrapper.h index dd97db70..2d7da1f5 100644 --- a/src/gui/qt/guiwrapper.h +++ b/src/gui/qt/guiwrapper.h @@ -34,6 +34,18 @@ #include "session.h" #include "game.h" +class NetSignalDispatcher : public QObject, public ClientCallback +{ +Q_OBJECT +public: + NetSignalDispatcher(connectToServerDialogImpl *dialog); + +signals: + void SignalNetClientSuccess(int actionID); + void SignalNetClientError(int errorID, int osErrorID); +friend class GuiWrapper; +}; + class GuiWrapper : public GuiInterface { public: @@ -95,6 +107,7 @@ private: Log *myLog; mainWindowImpl *myW; ConfigFile *myConfig; + NetSignalDispatcher *myNetSignalDispatcher; connectToServerDialogImpl *myConnectToServerDialog; diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index 0531bb67..2832657f 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -545,13 +545,13 @@ void mainWindowImpl::callAboutPokerthDialog() { void mainWindowImpl::callJoinNetworkGameDialog() { joinNetworkGameDialogImpl *v = new joinNetworkGameDialogImpl(); + connectToServerDialogImpl *w = new connectToServerDialogImpl(); v->setSession(mySession); v->exec(); if (v->result() == QDialog::Accepted ) { //Dialog mit Statusbalken - connectToServerDialogImpl *w = new connectToServerDialogImpl(); w->exec(); if (w->result() == QDialog::Rejected ) { diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index f532345a..60ac83cd 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -58,8 +58,8 @@ ClientStateInit::Process(ClientThread &client) if (data.serverAddr.empty()) throw ClientException(ERR_SOCK_SERVERADDR_NOT_SET, 0); - if (data.serverPort < 1024) - throw ClientException(ERR_SOCK_INVALID_PORT, 0); +// if (data.serverPort < 1024) +// throw ClientException(ERR_SOCK_INVALID_PORT, 0); data.sockfd = socket(data.addrFamily, SOCK_STREAM, 0); if (!IS_VALID_SOCKET(data.sockfd)) @@ -161,7 +161,7 @@ ClientStateConnect::Process(ClientThread &client) client.SetState(ClientStateFinal::Instance()); - return MSG_SOCK_RESOLVE_DONE; + return MSG_SOCK_CONNECT_DONE; } //----------------------------------------------------------------------------- diff --git a/src/net/socket_msg.h b/src/net/socket_msg.h index 4571a57d..f94f28e9 100644 --- a/src/net/socket_msg.h +++ b/src/net/socket_msg.h @@ -22,10 +22,10 @@ #define ERR_SOCK_SERVERADDR_NOT_SET 1 #define ERR_SOCK_INVALID_PORT 2 -#define ERR_SOCK_CREATION_FAILED 10 -#define ERR_SOCK_SET_PORT_FAILED 11 -#define ERR_SOCK_RESOLVE_FAILED 12 -#define ERR_SOCK_CONNECT_FAILED 13 +#define ERR_SOCK_CREATION_FAILED 3 +#define ERR_SOCK_SET_PORT_FAILED 4 +#define ERR_SOCK_RESOLVE_FAILED 5 +#define ERR_SOCK_CONNECT_FAILED 6 // This is an internal message which is not reported. #define MSG_SOCK_INTERNAL_PENDING 0 @@ -35,5 +35,7 @@ #define MSG_SOCK_RESOLVE_DONE 2 #define MSG_SOCK_CONNECT_DONE 3 +#define MSG_SOCK_LAST MSG_SOCK_CONNECT_DONE + #endif