if(widgetStylesPrinted != true) {document.write('');}var widgetStylesPrinted = true;var content = '
#include <tpproto/gamelayer.h> #include <tpproto/gamestatuslistener.h> #include <QDockWidget> #include <QLabel> #include <QTableView> #include <QTimer> #include <QTreeView> #include <QVariant> #include <kaction.h> #include <kicon.h> #include <kled.h> #include <kmenu.h> #include <kmenubar.h> #include <kmessagebox.h> #include <kstatusbar.h> #include <kstandardaction.h> #include "connecttoserverdialog.h" //#include "connecttoserverdialog.moc" #include "loggerwidget.h" //#include "loggerwidget.moc" #include "mainwindow.h" //#include "mainwindow.moc" #include "version.h" using namespace std; using namespace TPProto; { setupGame(); setupActions(); setupMenus(); setupStatusBar(); setupDockWindows(); connect(statuslistener, SIGNAL(signalConnected()),this,SLOT(connected())); connect(statuslistener, SIGNAL(signalDisconnected()),this,SLOT(disconnected())); connect(statuslistener, SIGNAL(signalAccountCreated(bool)) ,this, SLOT(accountCreated(bool))); connect(statuslistener, SIGNAL(signalLoggedIn(bool)),this,SLOT(loggedIn(bool))); connect(statuslistener, SIGNAL(signalTimeToEot(quint32)),this,SLOT(timeToEot(quint32))); connect(statuslistener, SIGNAL(signalEotEnded()),this,SLOT(eotEnded())); connect(statuslistener, SIGNAL(signalTimeToEot(quint32)),this,SLOT(timeToEot(quint32))); } void MainWindow::setupGame() { eventloop = new ParsekEventLoop(); statuslistener = new ParsekStatusListener(); game = new GameLayer(); game->setClientString(string("parsek/") + PARSEK_VERSION); game->setEventLoop(eventloop); game->setGameStatusListener(statuslistener); } void MainWindow::setupActions() { connectAction = new KAction(this); connectAction->setIcon(KIcon("network-connect")); connectAction->setText(i18n("&Connect")); connectAction->setStatusTip(i18n("Connect to a game server")); connect(connectAction, SIGNAL(triggered()),this, SLOT(connectToServer())); quitAction = KStandardAction::quit(this, SLOT(quitGame()), this); quitAction->setStatusTip(i18n("Quit the game")); } void MainWindow::setupMenus() { gameMenu = new KMenu(i18n("&Game")); gameMenu->addAction(connectAction); gameMenu->addSeparator(); gameMenu->addAction(quitAction); help = helpMenu(); menuBar()->addMenu(gameMenu); menuBar()->addMenu(help); } void MainWindow::setupStatusBar() { connectionLed = new KLed(Qt::red); statusBar()->addWidget(statusLabel, 1); statusBar()->addWidget(connectionLed); } void MainWindow::setupDockWindows() { logger = new LoggerWidget(); game->setLogger(logger); loggerDock->setAllowedAreas(Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea); loggerDock->setWidget(logger); addDockWidget(Qt::BottomDockWidgetArea, loggerDock); } void MainWindow::connectToServer() { statusLabel->clear(); ConnectToServerDialog connectionDialog(this); if (connectionDialog.exec()) { qApp->processEvents(); string address = connectionDialog.serversHistoryCombo->currentText().toUtf8().constData(); string user = connectionDialog.usernameLine->text().toUtf8().constData(); string pass = connectionDialog.passwordLine->text().toUtf8().constData(); if (game->connect(address)) { logger->parsek("Connecting"); connectionLed->setColor(Qt::yellow); } //At this point the gameStatus should be gsConnected //if the connect callback is properly handled and can proceed to login //otherwise gameStatus will be stuck at gsConnecting if (game->getStatus() == gsConnected) { logger->parsek("Connected"); if (game->login(user,pass)) { logger->parsek("Logged in"); connectionLed->setColor(Qt::green); } } } else { statusLabel->setText(i18n("Connection failed.")); connectionLed->setColor(Qt::red); KMessageBox::error(0L, i18n("It is not possible to connect to the server."), i18n("Could Not Connect")); } } void MainWindow::quitGame() { if (game->getStatus() != gsDisconnected) game->disconnect(); close(); } void MainWindow::connected() { statusLabel->setText(i18n("Connected")); } void MainWindow::accountCreated(bool) { statusLabel->setText(i18n("Account Created")); } void MainWindow::loggedIn(bool success) { statusLabel->setText(i18n("Logged in")); } void MainWindow::disconnected() { statusLabel->setText(i18n("Disconnected")); } void MainWindow::timeToEot(quint32 timetoeot) { } void MainWindow::eotEnded() { } void MainWindow::eotStarted() { }