if(widgetStylesPrinted != true) {document.write('');}var widgetStylesPrinted = true;var content = '
MainWindow
cpp-qt
  1. #include <tpproto/gamelayer.h>
  2. #include <tpproto/gamestatuslistener.h>
  3.  
  4. #include <QDockWidget>
  5. #include <QLabel>
  6. #include <QTableView>
  7. #include <QTimer>
  8. #include <QTreeView>
  9. #include <QVariant>
  10.  
  11. #include <kaction.h>
  12. #include <kicon.h>
  13. #include <kled.h>
  14. #include <kmenu.h>
  15. #include <kmenubar.h>
  16. #include <kmessagebox.h>
  17. #include <kstatusbar.h>
  18. #include <kstandardaction.h>
  19.  
  20. #include "connecttoserverdialog.h"
  21. //#include "connecttoserverdialog.moc"
  22. #include "loggerwidget.h"
  23. //#include "loggerwidget.moc"
  24. #include "mainwindow.h"
  25. //#include "mainwindow.moc"
  26. #include "version.h"
  27.  
  28. using namespace std;
  29. using namespace TPProto;
  30.  
  31. MainWindow::MainWindow(QWidget *parent) : KMainWindow(parent)
  32. {
  33. setupGame();
  34. setupActions();
  35. setupMenus();
  36. setupStatusBar();
  37. setupDockWindows();
  38.  
  39. connect(statuslistener, SIGNAL(signalConnected()),this,SLOT(connected()));
  40. connect(statuslistener, SIGNAL(signalDisconnected()),this,SLOT(disconnected()));
  41. connect(statuslistener, SIGNAL(signalAccountCreated(bool)) ,this, SLOT(accountCreated(bool)));
  42. connect(statuslistener, SIGNAL(signalLoggedIn(bool)),this,SLOT(loggedIn(bool)));
  43. connect(statuslistener, SIGNAL(signalTimeToEot(quint32)),this,SLOT(timeToEot(quint32)));
  44. connect(statuslistener, SIGNAL(signalEotEnded()),this,SLOT(eotEnded()));
  45. connect(statuslistener, SIGNAL(signalTimeToEot(quint32)),this,SLOT(timeToEot(quint32)));
  46. }
  47.  
  48. void MainWindow::setupGame()
  49. {
  50. eventloop = new ParsekEventLoop();
  51. statuslistener = new ParsekStatusListener();
  52. game = new GameLayer();
  53. game->setClientString(string("parsek/") + PARSEK_VERSION);
  54. game->setEventLoop(eventloop);
  55. game->setGameStatusListener(statuslistener);
  56. }
  57.  
  58. void MainWindow::setupActions()
  59. {
  60. connectAction = new KAction(this);
  61. connectAction->setIcon(KIcon("network-connect"));
  62. connectAction->setText(i18n("&Connect"));
  63. connectAction->setStatusTip(i18n("Connect to a game server"));
  64. connect(connectAction, SIGNAL(triggered()),this, SLOT(connectToServer()));
  65. quitAction = KStandardAction::quit(this, SLOT(quitGame()), this);
  66. quitAction->setStatusTip(i18n("Quit the game"));
  67. }
  68.  
  69. void MainWindow::setupMenus()
  70. {
  71. gameMenu = new KMenu(i18n("&Game"));
  72. gameMenu->addAction(connectAction);
  73. gameMenu->addSeparator();
  74. gameMenu->addAction(quitAction);
  75. help = helpMenu();
  76. menuBar()->addMenu(gameMenu);
  77. menuBar()->addMenu(help);
  78. }
  79.  
  80. void MainWindow::setupStatusBar()
  81. {
  82. statusLabel = new QLabel(i18n("Welcome to Parsek!"));
  83. connectionLed = new KLed(Qt::red);
  84. statusBar()->addWidget(statusLabel, 1);
  85. statusBar()->addWidget(connectionLed);
  86. }
  87.  
  88. void MainWindow::setupDockWindows()
  89. {
  90. logger = new LoggerWidget();
  91. game->setLogger(logger);
  92. QDockWidget *loggerDock = new QDockWidget(i18n("Log"), this);
  93. loggerDock->setAllowedAreas(Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea);
  94. loggerDock->setWidget(logger);
  95. addDockWidget(Qt::BottomDockWidgetArea, loggerDock);
  96. }
  97.  
  98. void MainWindow::connectToServer()
  99. {
  100. statusLabel->clear();
  101. ConnectToServerDialog connectionDialog(this);
  102. if (connectionDialog.exec())
  103. {
  104. qApp->processEvents();
  105. string address = connectionDialog.serversHistoryCombo->currentText().toUtf8().constData();
  106. string user = connectionDialog.usernameLine->text().toUtf8().constData();
  107. string pass = connectionDialog.passwordLine->text().toUtf8().constData();
  108. if (game->connect(address)) {
  109. logger->parsek("Connecting");
  110. connectionLed->setColor(Qt::yellow);
  111. }
  112. //At this point the gameStatus should be gsConnected
  113. //if the connect callback is properly handled and can proceed to login
  114. //otherwise gameStatus will be stuck at gsConnecting
  115. if (game->getStatus() == gsConnected) {
  116. logger->parsek("Connected");
  117. if (game->login(user,pass)) {
  118. logger->parsek("Logged in");
  119. connectionLed->setColor(Qt::green);
  120. }
  121. }
  122. }
  123. else
  124. {
  125. statusLabel->setText(i18n("Connection failed."));
  126. connectionLed->setColor(Qt::red);
  127. KMessageBox::error(0L,
  128. i18n("It is not possible to connect to the server."),
  129. i18n("Could Not Connect"));
  130. }
  131. }
  132.  
  133. void MainWindow::quitGame()
  134. {
  135. if (game->getStatus() != gsDisconnected) game->disconnect();
  136. close();
  137. }
  138.  
  139. void MainWindow::connected()
  140. {
  141. statusLabel->setText(i18n("Connected"));
  142. }
  143.  
  144. void MainWindow::accountCreated(bool)
  145. {
  146. statusLabel->setText(i18n("Account Created"));
  147. }
  148.  
  149. void MainWindow::loggedIn(bool success)
  150. {
  151. statusLabel->setText(i18n("Logged in"));
  152. }
  153.  
  154. void MainWindow::disconnected()
  155. {
  156. statusLabel->setText(i18n("Disconnected"));
  157. }
  158.  
  159. void MainWindow::timeToEot(quint32 timetoeot)
  160. {
  161. }
  162.  
  163. void MainWindow::eotEnded()
  164. {
  165. }
  166.  
  167. void MainWindow::eotStarted()
  168. {
  169. }
  170.  
';document.write(content);