Made the callback work. Updated error messages.

This commit is contained in:
lotodore
2007-02-18 19:16:34 +00:00
parent a97a1df8f7
commit 4e40f11f90
6 changed files with 63 additions and 42 deletions
@@ -19,73 +19,69 @@
***************************************************************************/ ***************************************************************************/
#include "connecttoserverdialogimpl.h" #include "connecttoserverdialogimpl.h"
// #include "configfile.h" // #include "configfile.h"
#include <net/socket_msg.h>
connectToServerDialogImpl::connectToServerDialogImpl(QWidget *parent) connectToServerDialogImpl::connectToServerDialogImpl(QWidget *parent)
: QDialog(parent) : QDialog(parent)
{ {
setupUi(this); setupUi(this);
} }
void connectToServerDialogImpl::refresh(int actionID) { void connectToServerDialogImpl::refresh(int actionID) {
int maxStateNumber = 4;
switch (actionID) { switch (actionID) {
case 0: { label_actionMessage->setText("msg0"); } case MSG_SOCK_INIT_DONE: { label_actionMessage->setText("Resolving address..."); }
break; break;
case 1: { label_actionMessage->setText("msg1"); } case MSG_SOCK_RESOLVE_DONE: { label_actionMessage->setText("Connecting to server..."); }
break; break;
case 2: { label_actionMessage->setText("msg2"); } case MSG_SOCK_CONNECT_DONE: { label_actionMessage->setText("Connection established."); }
break;
case 3: { label_actionMessage->setText("msg3"); }
break;
case 4: { label_actionMessage->setText("msg4"); }
break; break;
default: { label_actionMessage->setText("ERROR"); } 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) { 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) { switch (errorID) {
case 0: { QMessageBox::warning(this, tr("Connection Error"), case ERR_SOCK_SERVERADDR_NOT_SET:
tr("Error0 occured during Connection"), {QMessageBox::warning(this, tr("Network Error"),
tr("Server address was not set."),
QMessageBox::Close); } QMessageBox::Close); }
break; break;
case 1: {QMessageBox::warning(this, tr("Connection Error"), case ERR_SOCK_INVALID_PORT:
tr("Error1 occured during Connection"), { QMessageBox::warning(this, tr("Network Error"),
tr("An invalid port was set (ports 0-1023 are not allowed)."),
QMessageBox::Close); } QMessageBox::Close); }
break; break;
case 2: { QMessageBox::warning(this, tr("Connection Error"), case ERR_SOCK_CREATION_FAILED:
tr("Error2 occured during Connection"), { QMessageBox::warning(this, tr("Network Error"),
tr("Could not create socket."),
QMessageBox::Close); } QMessageBox::Close); }
break; break;
case 3: { QMessageBox::warning(this, tr("Connection Error"), case ERR_SOCK_SET_PORT_FAILED:
tr("Error3 occured during Connection"), { QMessageBox::warning(this, tr("Network Error"),
tr("Could not set the port for this type of address."),
QMessageBox::Close); } QMessageBox::Close); }
break; break;
case 4: { QMessageBox::warning(this, tr("Connection Error"), case ERR_SOCK_RESOLVE_FAILED:
tr("Error4 occured during Connection"), { QMessageBox::warning(this, tr("Network Error"),
tr("The server name could not be resolved."),
QMessageBox::Close); } QMessageBox::Close); }
break; 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"), tr("DEFAULT ERROR"),
QMessageBox::Close); } QMessageBox::Close); }
} }
+12 -2
View File
@@ -23,6 +23,14 @@
using namespace std; 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) GuiWrapper::GuiWrapper() : myLog(0), myW(0)
{ {
@@ -34,6 +42,8 @@ GuiWrapper::GuiWrapper() : myLog(0), myW(0)
myLog = new Log(myW); myLog = new Log(myW);
myConnectToServerDialog = new connectToServerDialogImpl(); myConnectToServerDialog = new connectToServerDialogImpl();
myNetSignalDispatcher = new NetSignalDispatcher(myConnectToServerDialog);
myConfig = new ConfigFile; 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::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::logNewGameHandMsg(int gameID, int handID) { myLog->logNewGameHandMsg(gameID, handID); }
void GuiWrapper::SignalNetClientSuccess(int actionID) { myConnectToServerDialog->refresh(actionID); } void GuiWrapper::SignalNetClientSuccess(int actionID) { myNetSignalDispatcher->SignalNetClientSuccess(actionID); }
void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myConnectToServerDialog->error(errorID, osErrorID); } void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myNetSignalDispatcher->SignalNetClientError(errorID, osErrorID); }
+13
View File
@@ -34,6 +34,18 @@
#include "session.h" #include "session.h"
#include "game.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 class GuiWrapper : public GuiInterface
{ {
public: public:
@@ -95,6 +107,7 @@ private:
Log *myLog; Log *myLog;
mainWindowImpl *myW; mainWindowImpl *myW;
ConfigFile *myConfig; ConfigFile *myConfig;
NetSignalDispatcher *myNetSignalDispatcher;
connectToServerDialogImpl *myConnectToServerDialog; connectToServerDialogImpl *myConnectToServerDialog;
+1 -1
View File
@@ -545,13 +545,13 @@ void mainWindowImpl::callAboutPokerthDialog() {
void mainWindowImpl::callJoinNetworkGameDialog() { void mainWindowImpl::callJoinNetworkGameDialog() {
joinNetworkGameDialogImpl *v = new joinNetworkGameDialogImpl(); joinNetworkGameDialogImpl *v = new joinNetworkGameDialogImpl();
connectToServerDialogImpl *w = new connectToServerDialogImpl();
v->setSession(mySession); v->setSession(mySession);
v->exec(); v->exec();
if (v->result() == QDialog::Accepted ) { if (v->result() == QDialog::Accepted ) {
//Dialog mit Statusbalken //Dialog mit Statusbalken
connectToServerDialogImpl *w = new connectToServerDialogImpl();
w->exec(); w->exec();
if (w->result() == QDialog::Rejected ) { if (w->result() == QDialog::Rejected ) {
+3 -3
View File
@@ -58,8 +58,8 @@ ClientStateInit::Process(ClientThread &client)
if (data.serverAddr.empty()) if (data.serverAddr.empty())
throw ClientException(ERR_SOCK_SERVERADDR_NOT_SET, 0); throw ClientException(ERR_SOCK_SERVERADDR_NOT_SET, 0);
if (data.serverPort < 1024) // if (data.serverPort < 1024)
throw ClientException(ERR_SOCK_INVALID_PORT, 0); // throw ClientException(ERR_SOCK_INVALID_PORT, 0);
data.sockfd = socket(data.addrFamily, SOCK_STREAM, 0); data.sockfd = socket(data.addrFamily, SOCK_STREAM, 0);
if (!IS_VALID_SOCKET(data.sockfd)) if (!IS_VALID_SOCKET(data.sockfd))
@@ -161,7 +161,7 @@ ClientStateConnect::Process(ClientThread &client)
client.SetState(ClientStateFinal::Instance()); client.SetState(ClientStateFinal::Instance());
return MSG_SOCK_RESOLVE_DONE; return MSG_SOCK_CONNECT_DONE;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
+6 -4
View File
@@ -22,10 +22,10 @@
#define ERR_SOCK_SERVERADDR_NOT_SET 1 #define ERR_SOCK_SERVERADDR_NOT_SET 1
#define ERR_SOCK_INVALID_PORT 2 #define ERR_SOCK_INVALID_PORT 2
#define ERR_SOCK_CREATION_FAILED 10 #define ERR_SOCK_CREATION_FAILED 3
#define ERR_SOCK_SET_PORT_FAILED 11 #define ERR_SOCK_SET_PORT_FAILED 4
#define ERR_SOCK_RESOLVE_FAILED 12 #define ERR_SOCK_RESOLVE_FAILED 5
#define ERR_SOCK_CONNECT_FAILED 13 #define ERR_SOCK_CONNECT_FAILED 6
// This is an internal message which is not reported. // This is an internal message which is not reported.
#define MSG_SOCK_INTERNAL_PENDING 0 #define MSG_SOCK_INTERNAL_PENDING 0
@@ -35,5 +35,7 @@
#define MSG_SOCK_RESOLVE_DONE 2 #define MSG_SOCK_RESOLVE_DONE 2
#define MSG_SOCK_CONNECT_DONE 3 #define MSG_SOCK_CONNECT_DONE 3
#define MSG_SOCK_LAST MSG_SOCK_CONNECT_DONE
#endif #endif