QTfrontend/hwform.cpp
changeset 6616 f77bb02b669f
parent 6604 9cc612a24b43
child 6630 f8bbfa9a1a36
equal deleted inserted replaced
6615:65602f1ef0f8 6616:f77bb02b669f
   107 
   107 
   108 GameUIConfig* HWForm::config = NULL;
   108 GameUIConfig* HWForm::config = NULL;
   109 QSettings* HWForm::gameSettings = NULL;
   109 QSettings* HWForm::gameSettings = NULL;
   110 
   110 
   111 HWForm::HWForm(QWidget *parent, QString styleSheet)
   111 HWForm::HWForm(QWidget *parent, QString styleSheet)
   112   : QMainWindow(parent)
   112     : QMainWindow(parent)
   113   , game(0)
   113     , game(0)
   114   , pnetserver(0)
   114     , pnetserver(0)
   115   , pRegisterServer(0)
   115     , pRegisterServer(0)
   116   , editedTeam(0)
   116     , editedTeam(0)
   117   , hwnet(0)
   117     , hwnet(0)
   118 {
   118 {
   119     // set music track
   119     // set music track
   120     SDLInteraction::instance().setMusicTrack(
   120     SDLInteraction::instance().setMusicTrack(
   121         HWDataManager::instance().findFileForRead("Music/main_theme.ogg")
   121         HWDataManager::instance().findFileForRead("Music/main_theme.ogg")
   122     );
   122     );
   179     connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   179     connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   180     pageSwitchMapper->setMapping(ui.pageMain->BtnSetup, ID_PAGE_SETUP);
   180     pageSwitchMapper->setMapping(ui.pageMain->BtnSetup, ID_PAGE_SETUP);
   181 
   181 
   182     connect(ui.pageMain->BtnFeedback, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   182     connect(ui.pageMain->BtnFeedback, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   183     pageSwitchMapper->setMapping(ui.pageMain->BtnFeedback, ID_PAGE_FEEDBACK);
   183     pageSwitchMapper->setMapping(ui.pageMain->BtnFeedback, ID_PAGE_FEEDBACK);
   184     
   184 
   185     connect(ui.pageMain->BtnNet, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   185     connect(ui.pageMain->BtnNet, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   186     pageSwitchMapper->setMapping(ui.pageMain->BtnNet, ID_PAGE_NETTYPE);
   186     pageSwitchMapper->setMapping(ui.pageMain->BtnNet, ID_PAGE_NETTYPE);
   187 
   187 
   188     connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   188     connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   189     pageSwitchMapper->setMapping(ui.pageMain->BtnInfo, ID_PAGE_INFO);
   189     pageSwitchMapper->setMapping(ui.pageMain->BtnInfo, ID_PAGE_INFO);
   198 
   198 
   199     connect(ui.pageEditTeam, SIGNAL(teamEdited()), this, SLOT(AfterTeamEdit()));
   199     connect(ui.pageEditTeam, SIGNAL(teamEdited()), this, SLOT(AfterTeamEdit()));
   200 
   200 
   201     connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame()));
   201     connect(ui.pageMultiplayer->BtnStartMPGame, SIGNAL(clicked()), this, SLOT(StartMPGame()));
   202     connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)),
   202     connect(ui.pageMultiplayer->teamsSelect, SIGNAL(setEnabledGameStart(bool)),
   203         ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool)));
   203             ui.pageMultiplayer->BtnStartMPGame, SLOT(setEnabled(bool)));
   204     connect(ui.pageMultiplayer, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup()));
   204     connect(ui.pageMultiplayer, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup()));
   205     connect(ui.pageMultiplayer->gameCFG, SIGNAL(goToSchemes(int)), this, SLOT(GoToScheme(int)));
   205     connect(ui.pageMultiplayer->gameCFG, SIGNAL(goToSchemes(int)), this, SLOT(GoToScheme(int)));
   206     connect(ui.pageMultiplayer->gameCFG, SIGNAL(goToWeapons(int)), this, SLOT(GoToSelectWeaponSet(int)));
   206     connect(ui.pageMultiplayer->gameCFG, SIGNAL(goToWeapons(int)), this, SLOT(GoToSelectWeaponSet(int)));
   207     connect(ui.pageMultiplayer->gameCFG, SIGNAL(goToDrawMap()), pageSwitchMapper, SLOT(map()));
   207     connect(ui.pageMultiplayer->gameCFG, SIGNAL(goToDrawMap()), pageSwitchMapper, SLOT(map()));
   208     pageSwitchMapper->setMapping(ui.pageMultiplayer->gameCFG, ID_PAGE_DRAWMAP);
   208     pageSwitchMapper->setMapping(ui.pageMultiplayer->gameCFG, ID_PAGE_DRAWMAP);
   233     connect(ui.pageNet, SIGNAL(connectClicked(const QString &, quint16)), this, SLOT(NetConnectServer(const QString &, quint16)));
   233     connect(ui.pageNet, SIGNAL(connectClicked(const QString &, quint16)), this, SLOT(NetConnectServer(const QString &, quint16)));
   234 
   234 
   235     connect(ui.pageNetServer->BtnStart, SIGNAL(clicked()), this, SLOT(NetStartServer()));
   235     connect(ui.pageNetServer->BtnStart, SIGNAL(clicked()), this, SLOT(NetStartServer()));
   236 
   236 
   237     connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)),
   237     connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)),
   238         ui.pageNetGame->BtnStart, SLOT(setEnabled(bool)));
   238             ui.pageNetGame->BtnStart, SLOT(setEnabled(bool)));
   239     connect(ui.pageNetGame, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup()));
   239     connect(ui.pageNetGame, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup()));
   240     connect(ui.pageNetGame->pGameCFG, SIGNAL(goToSchemes(int)), this, SLOT(GoToScheme(int)));
   240     connect(ui.pageNetGame->pGameCFG, SIGNAL(goToSchemes(int)), this, SLOT(GoToScheme(int)));
   241     connect(ui.pageNetGame->pGameCFG, SIGNAL(goToWeapons(int)), this, SLOT(GoToSelectWeaponSet(int)));
   241     connect(ui.pageNetGame->pGameCFG, SIGNAL(goToWeapons(int)), this, SLOT(GoToSelectWeaponSet(int)));
   242     connect(ui.pageNetGame->pGameCFG, SIGNAL(goToDrawMap()), pageSwitchMapper, SLOT(map()));
   242     connect(ui.pageNetGame->pGameCFG, SIGNAL(goToDrawMap()), pageSwitchMapper, SLOT(map()));
   243     pageSwitchMapper->setMapping(ui.pageNetGame->pGameCFG, ID_PAGE_DRAWMAP);
   243     pageSwitchMapper->setMapping(ui.pageNetGame->pGameCFG, ID_PAGE_DRAWMAP);
   267     connect(ui.pageCampaign->BtnStartCampaign, SIGNAL(clicked()), this, SLOT(StartCampaign()));
   267     connect(ui.pageCampaign->BtnStartCampaign, SIGNAL(clicked()), this, SLOT(StartCampaign()));
   268     connect(ui.pageCampaign->CBTeam, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
   268     connect(ui.pageCampaign->CBTeam, SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateCampaignPage(int)));
   269 
   269 
   270 
   270 
   271     connect(ui.pageSelectWeapon->BtnDelete, SIGNAL(clicked()),
   271     connect(ui.pageSelectWeapon->BtnDelete, SIGNAL(clicked()),
   272         ui.pageSelectWeapon->pWeapons, SLOT(deleteWeaponsName())); // executed first
   272             ui.pageSelectWeapon->pWeapons, SLOT(deleteWeaponsName())); // executed first
   273     connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()),
   273     connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()),
   274         this, SLOT(UpdateWeapons())); // executed second
   274             this, SLOT(UpdateWeapons())); // executed second
   275     //connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()),
   275     //connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()),
   276     //    this, SLOT(GoBack())); // executed third
   276     //    this, SLOT(GoBack())); // executed third
   277 
   277 
   278 
   278 
   279     connect(ui.pageNetType->BtnLAN, SIGNAL(clicked()), this, SLOT(GoToNet()));
   279     connect(ui.pageNetType->BtnLAN, SIGNAL(clicked()), this, SLOT(GoToNet()));
   323         xfire_setvalue(XFIRE_SERVER, !hwnet->getHost().compare("netserver.hedgewars.org:46631") ? "Official server" : hwnet->getHost().toAscii());
   323         xfire_setvalue(XFIRE_SERVER, !hwnet->getHost().compare("netserver.hedgewars.org:46631") ? "Official server" : hwnet->getHost().toAscii());
   324         switch(hwnet->clientState())
   324         switch(hwnet->clientState())
   325         {
   325         {
   326             case HWNewNet::Connecting: // Connecting
   326             case HWNewNet::Connecting: // Connecting
   327             case HWNewNet::Connected:
   327             case HWNewNet::Connected:
   328             xfire_setvalue(XFIRE_STATUS, "Connecting");
   328                 xfire_setvalue(XFIRE_STATUS, "Connecting");
   329             xfire_setvalue(XFIRE_NICKNAME, "-");
   329                 xfire_setvalue(XFIRE_NICKNAME, "-");
   330             xfire_setvalue(XFIRE_ROOM, "-");
   330                 xfire_setvalue(XFIRE_ROOM, "-");
   331             case HWNewNet::InLobby: // In lobby
   331             case HWNewNet::InLobby: // In lobby
   332             xfire_setvalue(XFIRE_STATUS, "Online");
   332                 xfire_setvalue(XFIRE_STATUS, "Online");
   333             xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
   333                 xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
   334             xfire_setvalue(XFIRE_ROOM, "In game lobby");
   334                 xfire_setvalue(XFIRE_ROOM, "In game lobby");
   335             break;
   335                 break;
   336             case HWNewNet::InRoom: // In room
   336             case HWNewNet::InRoom: // In room
   337             xfire_setvalue(XFIRE_STATUS, "Online");
   337                 xfire_setvalue(XFIRE_STATUS, "Online");
   338             xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
   338                 xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
   339             xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (waiting for players)").toAscii());
   339                 xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (waiting for players)").toAscii());
   340             break;
   340                 break;
   341             case HWNewNet::InGame: // In game
   341             case HWNewNet::InGame: // In game
   342             xfire_setvalue(XFIRE_STATUS, "Online");
   342                 xfire_setvalue(XFIRE_STATUS, "Online");
   343             xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
   343                 xfire_setvalue(XFIRE_NICKNAME, hwnet->getNick().toAscii());
   344             xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (playing or spectating)").toAscii());
   344                 xfire_setvalue(XFIRE_ROOM, (hwnet->getRoom() + " (playing or spectating)").toAscii());
   345             break;
   345                 break;
   346             default:
   346             default:
   347             break;
   347                 break;
   348         }
   348         }
   349     }
   349     }
   350     else
   350     else
   351     {
   351     {
   352         xfire_setvalue(XFIRE_STATUS, "Offline");
   352         xfire_setvalue(XFIRE_STATUS, "Offline");
   358 }
   358 }
   359 #endif
   359 #endif
   360 
   360 
   361 void HWForm::onFrontendFullscreen(bool value)
   361 void HWForm::onFrontendFullscreen(bool value)
   362 {
   362 {
   363   if (value)
   363     if (value)
   364     setWindowState(windowState() | Qt::WindowFullScreen);
   364         setWindowState(windowState() | Qt::WindowFullScreen);
   365   else {
   365     else
   366     setWindowState(windowState() & static_cast<int>(!Qt::WindowFullScreen));
   366     {
   367   }
   367         setWindowState(windowState() & static_cast<int>(!Qt::WindowFullScreen));
       
   368     }
   368 }
   369 }
   369 
   370 
   370 void HWForm::onFrontendEffects(bool value)
   371 void HWForm::onFrontendEffects(bool value)
   371 {
   372 {
   372     wBackground->enabled = value;
   373     wBackground->enabled = value;
   377 }
   378 }
   378 
   379 
   379 /*
   380 /*
   380 void HWForm::keyReleaseEvent(QKeyEvent *event)
   381 void HWForm::keyReleaseEvent(QKeyEvent *event)
   381 {
   382 {
   382   if (event->key() == Qt::Key_Escape) 
   383   if (event->key() == Qt::Key_Escape)
   383     this->GoBack();
   384     this->GoBack();
   384 }
   385 }
   385 */
   386 */
   386 
   387 
   387 void HWForm::CustomizePalettes()
   388 void HWForm::CustomizePalettes()
   405     combos.push_back(ui.pageNetGame->pGameCFG->WeaponsName);
   406     combos.push_back(ui.pageNetGame->pGameCFG->WeaponsName);
   406     combos.push_back(ui.pageSelectWeapon->selectWeaponSet);
   407     combos.push_back(ui.pageSelectWeapon->selectWeaponSet);
   407 
   408 
   408     QStringList names = ui.pageSelectWeapon->pWeapons->getWeaponNames();
   409     QStringList names = ui.pageSelectWeapon->pWeapons->getWeaponNames();
   409 
   410 
   410     for(QVector<QComboBox*>::iterator it = combos.begin(); it != combos.end(); ++it) {
   411     for(QVector<QComboBox*>::iterator it = combos.begin(); it != combos.end(); ++it)
       
   412     {
   411         (*it)->clear();
   413         (*it)->clear();
   412 
   414 
   413         for(int i = 0; i < names.size(); ++i)
   415         for(int i = 0; i < names.size(); ++i)
   414             (*it)->addItem(names[i], ui.pageSelectWeapon->pWeapons->getWeaponsString(names[i]));
   416             (*it)->addItem(names[i], ui.pageSelectWeapon->pWeapons->getWeaponsString(names[i]));
   415 
   417 
   416         int pos = (*it)->findText("Default");
   418         int pos = (*it)->findText("Default");
   417         if (pos != -1) {
   419         if (pos != -1)
       
   420         {
   418             (*it)->setCurrentIndex(pos);
   421             (*it)->setCurrentIndex(pos);
   419         }
   422         }
   420     }
   423     }
   421 }
   424 }
   422 
   425 
   423 void HWForm::UpdateTeamsLists(const QStringList* editable_teams)
   426 void HWForm::UpdateTeamsLists(const QStringList* editable_teams)
   424 {
   427 {
   425     QStringList teamslist;
   428     QStringList teamslist;
   426     if(editable_teams) {
   429     if(editable_teams)
   427       teamslist =* editable_teams;
   430     {
   428     } else {
   431         teamslist =* editable_teams;
   429       teamslist = config->GetTeamsList();
   432     }
   430     }
   433     else
   431 
   434     {
   432     if(teamslist.empty()) {
   435         teamslist = config->GetTeamsList();
       
   436     }
       
   437 
       
   438     if(teamslist.empty())
       
   439     {
   433         HWTeam defaultTeam(tr("DefaultTeam"));
   440         HWTeam defaultTeam(tr("DefaultTeam"));
   434         defaultTeam.saveToFile();
   441         defaultTeam.saveToFile();
   435         teamslist.push_back(tr("DefaultTeam"));
   442         teamslist.push_back(tr("DefaultTeam"));
   436     }
   443     }
   437 
   444 
   505 #endif
   512 #endif
   506     if (id == ID_PAGE_DATADOWNLOAD)
   513     if (id == ID_PAGE_DATADOWNLOAD)
   507     {
   514     {
   508         ui.pageDataDownload->fetchList();
   515         ui.pageDataDownload->fetchList();
   509     }
   516     }
   510     if (id == ID_PAGE_DRAWMAP) {
   517     if (id == ID_PAGE_DRAWMAP)
       
   518     {
   511         DrawMapScene * scene;
   519         DrawMapScene * scene;
   512         if(lastid == ID_PAGE_MULTIPLAYER)
   520         if(lastid == ID_PAGE_MULTIPLAYER)
   513             scene = ui.pageMultiplayer->gameCFG->pMapContainer->getDrawMapScene();
   521             scene = ui.pageMultiplayer->gameCFG->pMapContainer->getDrawMapScene();
   514         else
   522         else
   515             scene = ui.pageNetGame->pGameCFG->pMapContainer->getDrawMapScene();
   523             scene = ui.pageNetGame->pGameCFG->pMapContainer->getDrawMapScene();
   516 
   524 
   517         ui.pageDrawMap->drawMapWidget->setScene(scene);
   525         ui.pageDrawMap->drawMapWidget->setScene(scene);
   518     }
   526     }
   519 
   527 
   520     if (lastid == ID_PAGE_DRAWMAP) {
   528     if (lastid == ID_PAGE_DRAWMAP)
       
   529     {
   521         if (id == ID_PAGE_MULTIPLAYER)
   530         if (id == ID_PAGE_MULTIPLAYER)
   522             ui.pageMultiplayer->gameCFG->pMapContainer->mapDrawingFinished();
   531             ui.pageMultiplayer->gameCFG->pMapContainer->mapDrawingFinished();
   523         else
   532         else
   524             ui.pageNetGame->pGameCFG->pMapContainer->mapDrawingFinished();
   533             ui.pageNetGame->pGameCFG->pMapContainer->mapDrawingFinished();
   525     }
   534     }
   526 
   535 
   527     if (id == ID_PAGE_ROOMSLIST) {
   536     if (id == ID_PAGE_ROOMSLIST)
   528         if (hwnet && game && game->gameState == gsStarted) { // abnormal exit - kick or room destruction - send kills.
   537     {
       
   538         if (hwnet && game && game->gameState == gsStarted)   // abnormal exit - kick or room destruction - send kills.
       
   539         {
   529             game->netSuspend = true;
   540             game->netSuspend = true;
   530             ui.pageRoomsList->displayWarning(tr("Game aborted"));
   541             ui.pageRoomsList->displayWarning(tr("Game aborted"));
   531             game->abort();
   542             game->abort();
   532         }
   543         }
   533     }
   544     }
   534 
   545 
   535     if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETGAME) {
   546     if (id == ID_PAGE_MULTIPLAYER || id == ID_PAGE_NETGAME)
       
   547     {
   536         QStringList tmNames = config->GetTeamsList();
   548         QStringList tmNames = config->GetTeamsList();
   537         TeamSelWidget* curTeamSelWidget;
   549         TeamSelWidget* curTeamSelWidget;
   538         ui.pageOptions->setTeamOptionsEnabled(false);
   550         ui.pageOptions->setTeamOptionsEnabled(false);
   539 
   551 
   540         if (id == ID_PAGE_MULTIPLAYER) {
   552         if (id == ID_PAGE_MULTIPLAYER)
       
   553         {
   541             curTeamSelWidget = ui.pageMultiplayer->teamsSelect;
   554             curTeamSelWidget = ui.pageMultiplayer->teamsSelect;
   542         } else {
   555         }
       
   556         else
       
   557         {
   543             curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget;
   558             curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget;
   544         }
   559         }
   545 
   560 
   546         QList<HWTeam> teamsList;
   561         QList<HWTeam> teamsList;
   547         for (QStringList::iterator it = tmNames.begin(); it != tmNames.end(); it++) {
   562         for (QStringList::iterator it = tmNames.begin(); it != tmNames.end(); it++)
       
   563         {
   548             HWTeam team(*it);
   564             HWTeam team(*it);
   549             team.loadFromFile();
   565             team.loadFromFile();
   550             teamsList.push_back(team);
   566             teamsList.push_back(team);
   551         }
   567         }
   552 
   568 
   553         if (lastid == ID_PAGE_SETUP || lastid == ID_PAGE_DRAWMAP) { // _TEAM
   569         if (lastid == ID_PAGE_SETUP || lastid == ID_PAGE_DRAWMAP)   // _TEAM
   554             if (editedTeam) {
   570         {
       
   571             if (editedTeam)
       
   572             {
   555                 curTeamSelWidget->addTeam(*editedTeam);
   573                 curTeamSelWidget->addTeam(*editedTeam);
   556             }
   574             }
   557         } else if (lastid != ID_PAGE_GAMESTATS
   575         }
   558                 && lastid != ID_PAGE_INGAME
   576         else if (lastid != ID_PAGE_GAMESTATS
   559                 && lastid != ID_PAGE_SCHEME
   577                  && lastid != ID_PAGE_INGAME
   560                 && lastid != ID_PAGE_SELECTWEAPON) {
   578                  && lastid != ID_PAGE_SCHEME
       
   579                  && lastid != ID_PAGE_SELECTWEAPON)
       
   580         {
   561             curTeamSelWidget->resetPlayingTeams(teamsList);
   581             curTeamSelWidget->resetPlayingTeams(teamsList);
   562         }
   582         }
   563     } else
   583     }
   564         if (id == ID_PAGE_GAMESTATS) {
   584     else if (id == ID_PAGE_GAMESTATS)
   565             ui.pageGameStats->renderStats();
   585     {
   566         }
   586         ui.pageGameStats->renderStats();
   567 
   587     }
   568     if (id == ID_PAGE_MAIN) {
   588 
       
   589     if (id == ID_PAGE_MAIN)
       
   590     {
   569         ui.pageOptions->setTeamOptionsEnabled(true);
   591         ui.pageOptions->setTeamOptionsEnabled(true);
   570     }
   592     }
   571 
   593 
   572     // load and save ignore/friends lists
   594     // load and save ignore/friends lists
   573     if (lastid == ID_PAGE_NETGAME) // leaving a room
   595     if (lastid == ID_PAGE_NETGAME) // leaving a room
   575     else if(lastid == ID_PAGE_ROOMSLIST) // leaving the lobby
   597     else if(lastid == ID_PAGE_ROOMSLIST) // leaving the lobby
   576         ui.pageRoomsList->chatWidget->saveLists(ui.pageOptions->editNetNick->text());
   598         ui.pageRoomsList->chatWidget->saveLists(ui.pageOptions->editNetNick->text());
   577 
   599 
   578     if (id == ID_PAGE_NETGAME) // joining a room
   600     if (id == ID_PAGE_NETGAME) // joining a room
   579         ui.pageNetGame->pChatWidget->loadLists(ui.pageOptions->editNetNick->text());
   601         ui.pageNetGame->pChatWidget->loadLists(ui.pageOptions->editNetNick->text());
   580 // joining the lobby 
   602 // joining the lobby
   581     else if (id == ID_PAGE_ROOMSLIST)
   603     else if (id == ID_PAGE_ROOMSLIST)
   582         ui.pageRoomsList->chatWidget->loadLists(ui.pageOptions->editNetNick->text());
   604         ui.pageRoomsList->chatWidget->loadLists(ui.pageOptions->editNetNick->text());
   583 
   605 
   584 }
   606 }
   585 
   607 
   780 
   802 
   781 void HWForm::exit()
   803 void HWForm::exit()
   782 {
   804 {
   783 //   if (eggTimer.elapsed() < 3000){
   805 //   if (eggTimer.elapsed() < 3000){
   784 #ifdef __APPLE__
   806 #ifdef __APPLE__
   785         panel->showInstallController();
   807     panel->showInstallController();
   786 #endif
   808 #endif
   787         close();
   809     close();
   788 // TODO reactivate egg
   810 // TODO reactivate egg
   789 /*    }
   811     /*    }
   790     else
   812         else
   791     {
   813         {
   792         QPushButton * btn = findChild<QPushButton *>("imageButt");
   814             QPushButton * btn = findChild<QPushButton *>("imageButt");
   793         if (btn)
   815             if (btn)
   794         {
   816             {
   795             btn->setIcon(QIcon(":/res/bonus.png"));
   817                 btn->setIcon(QIcon(":/res/bonus.png"));
   796         }
   818             }
   797     } */
   819         } */
   798 }
   820 }
   799 
   821 
   800 void HWForm::IntermediateSetup()
   822 void HWForm::IntermediateSetup()
   801 {
   823 {
   802     quint8 id=ui.Pages->currentIndex();
   824     quint8 id=ui.Pages->currentIndex();
   803     TeamSelWidget* curTeamSelWidget;
   825     TeamSelWidget* curTeamSelWidget;
   804 
   826 
   805     if(id == ID_PAGE_MULTIPLAYER) {
   827     if(id == ID_PAGE_MULTIPLAYER)
       
   828     {
   806         curTeamSelWidget = ui.pageMultiplayer->teamsSelect;
   829         curTeamSelWidget = ui.pageMultiplayer->teamsSelect;
   807     } else {
   830     }
       
   831     else
       
   832     {
   808         curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget;
   833         curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget;
   809     }
   834     }
   810 
   835 
   811     QStringList tmnames;
   836     QStringList tmnames;
   812 
   837 
   813     foreach(HWTeam team, curTeamSelWidget->getNotPlayingTeams())
   838     foreach(HWTeam team, curTeamSelWidget->getNotPlayingTeams())
   814         tmnames += team.name();
   839     tmnames += team.name();
   815 
   840 
   816     //UpdateTeamsLists(&tmnames); // FIXME: still need more work if teamname is updated while configuring
   841     //UpdateTeamsLists(&tmnames); // FIXME: still need more work if teamname is updated while configuring
   817     UpdateTeamsLists();
   842     UpdateTeamsLists();
   818 
   843 
   819     GoToPage(ID_PAGE_SETUP);
   844     GoToPage(ID_PAGE_SETUP);
   848 }
   873 }
   849 
   874 
   850 void HWForm::DeleteScheme()
   875 void HWForm::DeleteScheme()
   851 {
   876 {
   852     ui.pageScheme->selectScheme->setCurrentIndex(ui.pageOptions->SchemesName->currentIndex());
   877     ui.pageScheme->selectScheme->setCurrentIndex(ui.pageOptions->SchemesName->currentIndex());
   853     if (ui.pageOptions->SchemesName->currentIndex() < ammoSchemeModel->numberOfDefaultSchemes) {
   878     if (ui.pageOptions->SchemesName->currentIndex() < ammoSchemeModel->numberOfDefaultSchemes)
       
   879     {
   854         QMessageBox::warning(0, QMessageBox::tr("Schemes"), QMessageBox::tr("Can not delete default scheme '%1'!").arg(ui.pageOptions->SchemesName->currentText()));
   880         QMessageBox::warning(0, QMessageBox::tr("Schemes"), QMessageBox::tr("Can not delete default scheme '%1'!").arg(ui.pageOptions->SchemesName->currentText()));
   855     } else {
   881     }
       
   882     else
       
   883     {
   856         ui.pageScheme->deleteRow();
   884         ui.pageScheme->deleteRow();
   857         ammoSchemeModel->Save();
   885         ammoSchemeModel->Save();
   858     }
   886     }
   859 }
   887 }
   860 
   888 
   874 {
   902 {
   875     QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem();
   903     QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem();
   876     if (!curritem)
   904     if (!curritem)
   877     {
   905     {
   878         QMessageBox::critical(this,
   906         QMessageBox::critical(this,
   879                 tr("Error"),
   907                               tr("Error"),
   880                 tr("Please select record from the list above"),
   908                               tr("Please select record from the list above"),
   881                 tr("OK"));
   909                               tr("OK"));
   882         return;
   910         return;
   883     }
   911     }
   884     CreateGame(0, 0, 0);
   912     CreateGame(0, 0, 0);
   885     game->PlayDemo(curritem->data(Qt::UserRole).toString(), ui.pagePlayDemo->isSave());
   913     game->PlayDemo(curritem->data(Qt::UserRole).toString(), ui.pagePlayDemo->isSave());
   886 }
   914 }
   913     // If the password is blank, ask the user to enter one in
   941     // If the password is blank, ask the user to enter one in
   914     if (passLength == 0)
   942     if (passLength == 0)
   915     {
   943     {
   916         QString password = QInputDialog::getText(this, tr("Password"), tr("Your nickname %1 is\nregistered on Hedgewars.org\nPlease provide your password below\nor pick another nickname in game config:").arg(nick), QLineEdit::Password, passLength==0?NULL:QString(passLength,'\0'), &ok);
   944         QString password = QInputDialog::getText(this, tr("Password"), tr("Your nickname %1 is\nregistered on Hedgewars.org\nPlease provide your password below\nor pick another nickname in game config:").arg(nick), QLineEdit::Password, passLength==0?NULL:QString(passLength,'\0'), &ok);
   917 
   945 
   918         if (!ok) {
   946         if (!ok)
       
   947         {
   919             ForcedDisconnect(tr("No password supplied."));
   948             ForcedDisconnect(tr("No password supplied."));
   920             return;
   949             return;
   921         }
   950         }
   922 
   951 
   923         hash = QCryptographicHash::hash(password.toLatin1(), QCryptographicHash::Md5).toHex();
   952         hash = QCryptographicHash::hash(password.toLatin1(), QCryptographicHash::Md5).toHex();
   932 void HWForm::NetNickTaken(const QString & nick)
   961 void HWForm::NetNickTaken(const QString & nick)
   933 {
   962 {
   934     bool ok = false;
   963     bool ok = false;
   935     QString newNick = QInputDialog::getText(this, tr("Nickname"), tr("Some one already uses\n your nickname %1\non the server.\nPlease pick another nickname:").arg(nick), QLineEdit::Normal, nick, &ok);
   964     QString newNick = QInputDialog::getText(this, tr("Nickname"), tr("Some one already uses\n your nickname %1\non the server.\nPlease pick another nickname:").arg(nick), QLineEdit::Normal, nick, &ok);
   936 
   965 
   937     if (!ok || newNick.isEmpty()) {
   966     if (!ok || newNick.isEmpty())
   938             ForcedDisconnect(tr("No nickname supplied."));
   967     {
       
   968         ForcedDisconnect(tr("No nickname supplied."));
   939         return;
   969         return;
   940     }
   970     }
   941 
   971 
   942     hwnet->NewNick(newNick);
   972     hwnet->NewNick(newNick);
   943     config->setValue("net/nick", newNick);
   973     config->setValue("net/nick", newNick);
   968             // no break
   998             // no break
   969         case ID_PAGE_NETGAME:
   999         case ID_PAGE_NETGAME:
   970             ui.pageNetGame->displayError(errmsg);
  1000             ui.pageNetGame->displayError(errmsg);
   971             break;
  1001             break;
   972         default:
  1002         default:
   973         ui.pageRoomsList->displayError(errmsg);
  1003             ui.pageRoomsList->displayError(errmsg);
   974     }
  1004     }
   975 }
  1005 }
   976 
  1006 
   977 void HWForm::NetWarning(const QString & wrnmsg)
  1007 void HWForm::NetWarning(const QString & wrnmsg)
   978 {
  1008 {
   982         ui.pageRoomsList->displayWarning(wrnmsg);
  1012         ui.pageRoomsList->displayWarning(wrnmsg);
   983 }
  1013 }
   984 
  1014 
   985 void HWForm::_NetConnect(const QString & hostName, quint16 port, QString nick)
  1015 void HWForm::_NetConnect(const QString & hostName, quint16 port, QString nick)
   986 {
  1016 {
   987     if(hwnet) {
  1017     if(hwnet)
       
  1018     {
   988         hwnet->Disconnect();
  1019         hwnet->Disconnect();
   989         delete hwnet;
  1020         delete hwnet;
   990         hwnet=0;
  1021         hwnet=0;
   991     }
  1022     }
   992 
  1023 
  1008     connect(hwnet, SIGNAL(AuthFailed()), this, SLOT(NetAuthFailed()));
  1039     connect(hwnet, SIGNAL(AuthFailed()), this, SLOT(NetAuthFailed()));
  1009     //connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom()));
  1040     //connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom()));
  1010 
  1041 
  1011 // rooms list page stuff
  1042 // rooms list page stuff
  1012     connect(hwnet, SIGNAL(roomsList(const QStringList&)),
  1043     connect(hwnet, SIGNAL(roomsList(const QStringList&)),
  1013         ui.pageRoomsList, SLOT(setRoomsList(const QStringList&)));
  1044             ui.pageRoomsList, SLOT(setRoomsList(const QStringList&)));
  1014     connect(hwnet, SIGNAL(adminAccess(bool)),
  1045     connect(hwnet, SIGNAL(adminAccess(bool)),
  1015         ui.pageRoomsList, SLOT(setAdmin(bool)));
  1046             ui.pageRoomsList, SLOT(setAdmin(bool)));
  1016     connect(hwnet, SIGNAL(adminAccess(bool)),
  1047     connect(hwnet, SIGNAL(adminAccess(bool)),
  1017         ui.pageRoomsList->chatWidget, SLOT(adminAccess(bool)));
  1048             ui.pageRoomsList->chatWidget, SLOT(adminAccess(bool)));
  1018 
  1049 
  1019     connect(hwnet, SIGNAL(serverMessage(const QString&)),
  1050     connect(hwnet, SIGNAL(serverMessage(const QString&)),
  1020         ui.pageRoomsList->chatWidget, SLOT(onServerMessage(const QString&)));
  1051             ui.pageRoomsList->chatWidget, SLOT(onServerMessage(const QString&)));
  1021 
  1052 
  1022     connect(ui.pageRoomsList, SIGNAL(askForCreateRoom(const QString &)),
  1053     connect(ui.pageRoomsList, SIGNAL(askForCreateRoom(const QString &)),
  1023         hwnet, SLOT(CreateRoom(const QString&)));
  1054             hwnet, SLOT(CreateRoom(const QString&)));
  1024     connect(ui.pageRoomsList, SIGNAL(askForJoinRoom(const QString &)),
  1055     connect(ui.pageRoomsList, SIGNAL(askForJoinRoom(const QString &)),
  1025         hwnet, SLOT(JoinRoom(const QString&)));
  1056             hwnet, SLOT(JoinRoom(const QString&)));
  1026 //  connect(ui.pageRoomsList, SIGNAL(askForCreateRoom(const QString &)),
  1057 //  connect(ui.pageRoomsList, SIGNAL(askForCreateRoom(const QString &)),
  1027 //      this, SLOT(NetGameMaster()));
  1058 //      this, SLOT(NetGameMaster()));
  1028 //  connect(ui.pageRoomsList, SIGNAL(askForJoinRoom(const QString &)),
  1059 //  connect(ui.pageRoomsList, SIGNAL(askForJoinRoom(const QString &)),
  1029 //      this, SLOT(NetGameSlave()));
  1060 //      this, SLOT(NetGameSlave()));
  1030     connect(ui.pageRoomsList, SIGNAL(askForRoomList()),
  1061     connect(ui.pageRoomsList, SIGNAL(askForRoomList()),
  1031         hwnet, SLOT(askRoomsList()));
  1062             hwnet, SLOT(askRoomsList()));
  1032 
  1063 
  1033 // room status stuff
  1064 // room status stuff
  1034     connect(hwnet, SIGNAL(roomMaster(bool)),
  1065     connect(hwnet, SIGNAL(roomMaster(bool)),
  1035         this, SLOT(NetGameChangeStatus(bool)));
  1066             this, SLOT(NetGameChangeStatus(bool)));
  1036 
  1067 
  1037 // net page stuff
  1068 // net page stuff
  1038     connect(hwnet, SIGNAL(chatStringFromNet(const QString&)),
  1069     connect(hwnet, SIGNAL(chatStringFromNet(const QString&)),
  1039         ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)));
  1070             ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)));
  1040     connect(hwnet, SIGNAL(setReadyStatus(const QString &, bool)),
  1071     connect(hwnet, SIGNAL(setReadyStatus(const QString &, bool)),
  1041         ui.pageNetGame->pChatWidget, SLOT(setReadyStatus(const QString &, bool)));
  1072             ui.pageNetGame->pChatWidget, SLOT(setReadyStatus(const QString &, bool)));
  1042     connect(hwnet, SIGNAL(chatStringFromMe(const QString&)),
  1073     connect(hwnet, SIGNAL(chatStringFromMe(const QString&)),
  1043         ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)));
  1074             ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)));
  1044     connect(hwnet, SIGNAL(roomMaster(bool)),
  1075     connect(hwnet, SIGNAL(roomMaster(bool)),
  1045         ui.pageNetGame->pChatWidget, SLOT(adminAccess(bool)));
  1076             ui.pageNetGame->pChatWidget, SLOT(adminAccess(bool)));
  1046     connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)),
  1077     connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)),
  1047         hwnet, SLOT(chatLineToNet(const QString&)));
  1078             hwnet, SLOT(chatLineToNet(const QString&)));
  1048     connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady()));
  1079     connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady()));
  1049     connect(hwnet, SIGNAL(setMyReadyStatus(bool)),
  1080     connect(hwnet, SIGNAL(setMyReadyStatus(bool)),
  1050         ui.pageNetGame, SLOT(setReadyStatus(bool)));
  1081             ui.pageNetGame, SLOT(setReadyStatus(bool)));
  1051 
  1082 
  1052 // chat widget actions
  1083 // chat widget actions
  1053     connect(ui.pageNetGame->pChatWidget, SIGNAL(kick(const QString&)),
  1084     connect(ui.pageNetGame->pChatWidget, SIGNAL(kick(const QString&)),
  1054         hwnet, SLOT(kickPlayer(const QString&)));
  1085             hwnet, SLOT(kickPlayer(const QString&)));
  1055     connect(ui.pageNetGame->pChatWidget, SIGNAL(ban(const QString&)),
  1086     connect(ui.pageNetGame->pChatWidget, SIGNAL(ban(const QString&)),
  1056         hwnet, SLOT(banPlayer(const QString&)));
  1087             hwnet, SLOT(banPlayer(const QString&)));
  1057     connect(ui.pageNetGame->pChatWidget, SIGNAL(info(const QString&)),
  1088     connect(ui.pageNetGame->pChatWidget, SIGNAL(info(const QString&)),
  1058         hwnet, SLOT(infoPlayer(const QString&)));
  1089             hwnet, SLOT(infoPlayer(const QString&)));
  1059     connect(ui.pageNetGame->pChatWidget, SIGNAL(follow(const QString&)),
  1090     connect(ui.pageNetGame->pChatWidget, SIGNAL(follow(const QString&)),
  1060         hwnet, SLOT(followPlayer(const QString&)));
  1091             hwnet, SLOT(followPlayer(const QString&)));
  1061     connect(ui.pageRoomsList->chatWidget, SIGNAL(kick(const QString&)),
  1092     connect(ui.pageRoomsList->chatWidget, SIGNAL(kick(const QString&)),
  1062         hwnet, SLOT(kickPlayer(const QString&)));
  1093             hwnet, SLOT(kickPlayer(const QString&)));
  1063     connect(ui.pageRoomsList->chatWidget, SIGNAL(ban(const QString&)),
  1094     connect(ui.pageRoomsList->chatWidget, SIGNAL(ban(const QString&)),
  1064         hwnet, SLOT(banPlayer(const QString&)));
  1095             hwnet, SLOT(banPlayer(const QString&)));
  1065     connect(ui.pageRoomsList->chatWidget, SIGNAL(info(const QString&)),
  1096     connect(ui.pageRoomsList->chatWidget, SIGNAL(info(const QString&)),
  1066         hwnet, SLOT(infoPlayer(const QString&)));
  1097             hwnet, SLOT(infoPlayer(const QString&)));
  1067     connect(ui.pageRoomsList->chatWidget, SIGNAL(follow(const QString&)),
  1098     connect(ui.pageRoomsList->chatWidget, SIGNAL(follow(const QString&)),
  1068         hwnet, SLOT(followPlayer(const QString&)));
  1099             hwnet, SLOT(followPlayer(const QString&)));
  1069 
  1100 
  1070 // chatting
  1101 // chatting
  1071     connect(ui.pageRoomsList->chatWidget, SIGNAL(chatLine(const QString&)),
  1102     connect(ui.pageRoomsList->chatWidget, SIGNAL(chatLine(const QString&)),
  1072         hwnet, SLOT(chatLineToLobby(const QString&)));
  1103             hwnet, SLOT(chatLineToLobby(const QString&)));
  1073     connect(hwnet, SIGNAL(chatStringLobby(const QString&)),
  1104     connect(hwnet, SIGNAL(chatStringLobby(const QString&)),
  1074         ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)));
  1105             ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)));
  1075     connect(hwnet, SIGNAL(chatStringLobby(const QString&, const QString&)),
  1106     connect(hwnet, SIGNAL(chatStringLobby(const QString&, const QString&)),
  1076         ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&, const QString&)));
  1107             ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&, const QString&)));
  1077     connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)),
  1108     connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)),
  1078         ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)));
  1109             ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)));
  1079 
  1110 
  1080 // nick list stuff
  1111 // nick list stuff
  1081     connect(hwnet, SIGNAL(nickAdded(const QString&, bool)),
  1112     connect(hwnet, SIGNAL(nickAdded(const QString&, bool)),
  1082         ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&, bool)));
  1113             ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&, bool)));
  1083     connect(hwnet, SIGNAL(nickRemoved(const QString&)),
  1114     connect(hwnet, SIGNAL(nickRemoved(const QString&)),
  1084         ui.pageNetGame->pChatWidget, SLOT(nickRemoved(const QString&)));
  1115             ui.pageNetGame->pChatWidget, SLOT(nickRemoved(const QString&)));
  1085     connect(hwnet, SIGNAL(nickAddedLobby(const QString&, bool)),
  1116     connect(hwnet, SIGNAL(nickAddedLobby(const QString&, bool)),
  1086         ui.pageRoomsList->chatWidget, SLOT(nickAdded(const QString&, bool)));
  1117             ui.pageRoomsList->chatWidget, SLOT(nickAdded(const QString&, bool)));
  1087     connect(hwnet, SIGNAL(nickRemovedLobby(const QString&)),
  1118     connect(hwnet, SIGNAL(nickRemovedLobby(const QString&)),
  1088         ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&)));
  1119             ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&)));
  1089 
  1120 
  1090 // teams selecting stuff
  1121 // teams selecting stuff
  1091     connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)),
  1122     connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)),
  1092         hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&)));
  1123             hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&)));
  1093     connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamColorChanged(const HWTeam&)),
  1124     connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamColorChanged(const HWTeam&)),
  1094         hwnet, SLOT(onTeamColorChanged(const HWTeam&)));
  1125             hwnet, SLOT(onTeamColorChanged(const HWTeam&)));
  1095     connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam)));
  1126     connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam)));
  1096     connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(acceptRequested(HWTeam)), hwnet, SLOT(AddTeam(HWTeam)));
  1127     connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(acceptRequested(HWTeam)), hwnet, SLOT(AddTeam(HWTeam)));
  1097     connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamNotPlaying(const HWTeam&)), hwnet, SLOT(RemoveTeam(const HWTeam&)));
  1128     connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamNotPlaying(const HWTeam&)), hwnet, SLOT(RemoveTeam(const HWTeam&)));
  1098     connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)),
  1129     connect(hwnet, SIGNAL(hhnumChanged(const HWTeam&)),
  1099         ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&)));
  1130             ui.pageNetGame->pNetTeamsWidget, SLOT(changeHHNum(const HWTeam&)));
  1100     connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)),
  1131     connect(hwnet, SIGNAL(teamColorChanged(const HWTeam&)),
  1101         ui.pageNetGame->pNetTeamsWidget, SLOT(changeTeamColor(const HWTeam&)));
  1132             ui.pageNetGame->pNetTeamsWidget, SLOT(changeTeamColor(const HWTeam&)));
  1102 
  1133 
  1103 // admin stuff
  1134 // admin stuff
  1104     connect(hwnet, SIGNAL(serverMessageNew(const QString&)), ui.pageAdmin, SLOT(serverMessageNew(const QString &)));
  1135     connect(hwnet, SIGNAL(serverMessageNew(const QString&)), ui.pageAdmin, SLOT(serverMessageNew(const QString &)));
  1105     connect(hwnet, SIGNAL(serverMessageOld(const QString&)), ui.pageAdmin, SLOT(serverMessageOld(const QString &)));
  1136     connect(hwnet, SIGNAL(serverMessageOld(const QString&)), ui.pageAdmin, SLOT(serverMessageOld(const QString &)));
  1106     connect(hwnet, SIGNAL(latestProtocolVar(int)), ui.pageAdmin, SLOT(protocol(int)));
  1137     connect(hwnet, SIGNAL(latestProtocolVar(int)), ui.pageAdmin, SLOT(protocol(int)));
  1116 // config stuff
  1147 // config stuff
  1117     connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &)));
  1148     connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &)));
  1118     connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &)));
  1149     connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &)));
  1119     connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig()));
  1150     connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig()));
  1120 
  1151 
  1121     while (nick.isEmpty()) {
  1152     while (nick.isEmpty())
       
  1153     {
  1122         nick = QInputDialog::getText(this,
  1154         nick = QInputDialog::getText(this,
  1123                  QObject::tr("Nickname"),
  1155                                      QObject::tr("Nickname"),
  1124                  QObject::tr("Please enter your nickname"),
  1156                                      QObject::tr("Please enter your nickname"),
  1125                  QLineEdit::Normal,
  1157                                      QLineEdit::Normal,
  1126                  QDir::home().dirName());
  1158                                      QDir::home().dirName());
  1127         config->setValue("net/nick",nick);
  1159         config->setValue("net/nick",nick);
  1128         config->updNetNick();
  1160         config->updNetNick();
  1129     }
  1161     }
  1130 
  1162 
  1131     ui.pageRoomsList->setUser(nick);
  1163     ui.pageRoomsList->setUser(nick);
  1156 
  1188 
  1157     pnetserver = new HWNetServer;
  1189     pnetserver = new HWNetServer;
  1158     if(!pnetserver->StartServer(ui.pageNetServer->sbPort->value()))
  1190     if(!pnetserver->StartServer(ui.pageNetServer->sbPort->value()))
  1159     {
  1191     {
  1160         QMessageBox::critical(0, tr("Error"),
  1192         QMessageBox::critical(0, tr("Error"),
  1161                 tr("Unable to start the server"));
  1193                               tr("Unable to start the server"));
  1162         delete pnetserver;
  1194         delete pnetserver;
  1163         pnetserver = 0;
  1195         pnetserver = 0;
  1164         return;
  1196         return;
  1165     }
  1197     }
  1166 
  1198 
  1167     QTimer::singleShot(250, this, SLOT(AsyncNetServerStart()));
  1199     QTimer::singleShot(250, this, SLOT(AsyncNetServerStart()));
  1168 
  1200 
  1169     pRegisterServer = new HWNetUdpServer(0,
  1201     pRegisterServer = new HWNetUdpServer(0,
  1170             ui.pageNetServer->leServerDescr->text(),
  1202                                          ui.pageNetServer->leServerDescr->text(),
  1171             ui.pageNetServer->sbPort->value());
  1203                                          ui.pageNetServer->sbPort->value());
  1172 }
  1204 }
  1173 
  1205 
  1174 void HWForm::AsyncNetServerStart()
  1206 void HWForm::AsyncNetServerStart()
  1175 {
  1207 {
  1176     NetConnectServer("localhost", pnetserver->getRunningPort());
  1208     NetConnectServer("localhost", pnetserver->getRunningPort());
  1177 }
  1209 }
  1178 
  1210 
  1179 void HWForm::NetDisconnect()
  1211 void HWForm::NetDisconnect()
  1180 {
  1212 {
  1181     if(pnetserver) {
  1213     if(pnetserver)
       
  1214     {
  1182         if (pRegisterServer)
  1215         if (pRegisterServer)
  1183         {
  1216         {
  1184             pRegisterServer->unregister();
  1217             pRegisterServer->unregister();
  1185             pRegisterServer = 0;
  1218             pRegisterServer = 0;
  1186         }
  1219         }
  1195 }
  1228 }
  1196 
  1229 
  1197 void HWForm::ForcedDisconnect(const QString & reason)
  1230 void HWForm::ForcedDisconnect(const QString & reason)
  1198 {
  1231 {
  1199     if(pnetserver) return; // we have server - let it care of all things
  1232     if(pnetserver) return; // we have server - let it care of all things
  1200     if (hwnet) {
  1233     if (hwnet)
       
  1234     {
  1201         QMessageBox::warning(this, QMessageBox::tr("Network"),
  1235         QMessageBox::warning(this, QMessageBox::tr("Network"),
  1202                 QMessageBox::tr("Connection to server is lost") + (reason.isEmpty()?"":("\n\n" + HWNewNet::tr("Quit reason: ") + '"' + reason +'"')));
  1236                              QMessageBox::tr("Connection to server is lost") + (reason.isEmpty()?"":("\n\n" + HWNewNet::tr("Quit reason: ") + '"' + reason +'"')));
  1203 
  1237 
  1204     }
  1238     }
  1205     if (ui.Pages->currentIndex() != ID_PAGE_NET) GoBack();
  1239     if (ui.Pages->currentIndex() != ID_PAGE_NET) GoBack();
  1206 }
  1240 }
  1207 
  1241 
  1228 
  1262 
  1229 void HWForm::StartMPGame()
  1263 void HWForm::StartMPGame()
  1230 {
  1264 {
  1231     QString ammo;
  1265     QString ammo;
  1232     ammo = ui.pageMultiplayer->gameCFG->WeaponsName->itemData(
  1266     ammo = ui.pageMultiplayer->gameCFG->WeaponsName->itemData(
  1233         ui.pageMultiplayer->gameCFG->WeaponsName->currentIndex()
  1267                ui.pageMultiplayer->gameCFG->WeaponsName->currentIndex()
  1234         ).toString();
  1268            ).toString();
  1235 
  1269 
  1236     CreateGame(ui.pageMultiplayer->gameCFG, ui.pageMultiplayer->teamsSelect, ammo);
  1270     CreateGame(ui.pageMultiplayer->gameCFG, ui.pageMultiplayer->teamsSelect, ammo);
  1237 
  1271 
  1238     game->StartLocal();
  1272     game->StartLocal();
  1239 }
  1273 }
  1240 
  1274 
  1241 void HWForm::GameStateChanged(GameState gameState)
  1275 void HWForm::GameStateChanged(GameState gameState)
  1242 {
  1276 {
  1243     quint8 id = ui.Pages->currentIndex();
  1277     quint8 id = ui.Pages->currentIndex();
  1244     switch(gameState) {
  1278     switch(gameState)
  1245         case gsStarted: {
  1279     {
       
  1280         case gsStarted:
       
  1281         {
  1246             Music(false);
  1282             Music(false);
  1247             if (wBackground) wBackground->stopAnimation();
  1283             if (wBackground) wBackground->stopAnimation();
  1248             if (!hwnet || (!hwnet->isRoomChief() || !hwnet->isInRoom())) GoToPage(ID_PAGE_INGAME);
  1284             if (!hwnet || (!hwnet->isRoomChief() || !hwnet->isInRoom())) GoToPage(ID_PAGE_INGAME);
  1249             ui.pageGameStats->clear();
  1285             ui.pageGameStats->clear();
  1250             if (pRegisterServer)
  1286             if (pRegisterServer)
  1254             }
  1290             }
  1255             //setVisible(false);
  1291             //setVisible(false);
  1256             setFocusPolicy(Qt::NoFocus);
  1292             setFocusPolicy(Qt::NoFocus);
  1257             break;
  1293             break;
  1258         }
  1294         }
  1259         case gsFinished: {
  1295         case gsFinished:
       
  1296         {
  1260             //setVisible(true);
  1297             //setVisible(true);
  1261             setFocusPolicy(Qt::StrongFocus);
  1298             setFocusPolicy(Qt::StrongFocus);
  1262             if (id == ID_PAGE_INGAME) GoBack();
  1299             if (id == ID_PAGE_INGAME) GoBack();
  1263             Music(ui.pageOptions->CBEnableFrontendMusic->isChecked());
  1300             Music(ui.pageOptions->CBEnableFrontendMusic->isChecked());
  1264             if (wBackground) wBackground->startAnimation();
  1301             if (wBackground) wBackground->startAnimation();
  1265             GoToPage(ID_PAGE_GAMESTATS);
  1302             GoToPage(ID_PAGE_GAMESTATS);
  1266             if (hwnet && (!game || !game->netSuspend)) hwnet->gameFinished(true);
  1303             if (hwnet && (!game || !game->netSuspend)) hwnet->gameFinished(true);
  1267             if (game) game->netSuspend = false;
  1304             if (game) game->netSuspend = false;
  1268             break;
  1305             break;
  1269         }
  1306         }
  1270         default: {
  1307         default:
       
  1308         {
  1271             //setVisible(true);
  1309             //setVisible(true);
  1272             setFocusPolicy(Qt::StrongFocus);
  1310             setFocusPolicy(Qt::StrongFocus);
  1273             quint8 id = ui.Pages->currentIndex();
  1311             quint8 id = ui.Pages->currentIndex();
  1274             if (id == ID_PAGE_INGAME ||
  1312             if (id == ID_PAGE_INGAME ||
  1275 // was room chief and the game was aborted
  1313 // was room chief and the game was aborted
  1276                 (hwnet && hwnet->isRoomChief() && hwnet->isInRoom() && 
  1314                     (hwnet && hwnet->isRoomChief() && hwnet->isInRoom() &&
  1277                     (gameState == gsInterrupted || gameState == gsStopped || gameState == gsDestroyed || gameState == gsHalted))) {
  1315                      (gameState == gsInterrupted || gameState == gsStopped || gameState == gsDestroyed || gameState == gsHalted)))
       
  1316             {
  1278                 if (id == ID_PAGE_INGAME) GoBack();
  1317                 if (id == ID_PAGE_INGAME) GoBack();
  1279                 Music(ui.pageOptions->CBEnableFrontendMusic->isChecked());
  1318                 Music(ui.pageOptions->CBEnableFrontendMusic->isChecked());
  1280                 if (wBackground) wBackground->startAnimation();
  1319                 if (wBackground) wBackground->startAnimation();
  1281                 if (hwnet) hwnet->gameFinished(false);
  1320                 if (hwnet) hwnet->gameFinished(false);
  1282             }
  1321             }
  1296 }
  1335 }
  1297 
  1336 
  1298 void HWForm::ShowErrorMessage(const QString & msg)
  1337 void HWForm::ShowErrorMessage(const QString & msg)
  1299 {
  1338 {
  1300     QMessageBox::warning(this,
  1339     QMessageBox::warning(this,
  1301             "Hedgewars",
  1340                          "Hedgewars",
  1302             msg);
  1341                          msg);
  1303 }
  1342 }
  1304 
  1343 
  1305 void HWForm::GetRecord(bool isDemo, const QByteArray & record)
  1344 void HWForm::GetRecord(bool isDemo, const QByteArray & record)
  1306 {
  1345 {
  1307     QString filename;
  1346     QString filename;
  1308     QByteArray demo = record;
  1347     QByteArray demo = record;
  1309     QString recordFileName =
  1348     QString recordFileName =
  1310             config->appendDateTimeToRecordName() ?
  1349         config->appendDateTimeToRecordName() ?
  1311                 QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm") :
  1350         QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm") :
  1312                 "LastRound";
  1351         "LastRound";
  1313 
  1352 
  1314     QStringList versionParts = cVersionString->split('-');
  1353     QStringList versionParts = cVersionString->split('-');
  1315     if ( (versionParts.size() == 2) && (!versionParts[1].isEmpty()) && (versionParts[1].contains(':')) )
  1354     if ( (versionParts.size() == 2) && (!versionParts[1].isEmpty()) && (versionParts[1].contains(':')) )
  1316         recordFileName = recordFileName + "_" + versionParts[1].replace(':','-');
  1355         recordFileName = recordFileName + "_" + versionParts[1].replace(':','-');
  1317 
  1356 
  1320         demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD"));
  1359         demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD"));
  1321         demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD"));
  1360         demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD"));
  1322         demo.replace(QByteArray("\x02TS"), QByteArray("\x02TD"));
  1361         demo.replace(QByteArray("\x02TS"), QByteArray("\x02TD"));
  1323         filename = cfgdir->absolutePath() + "/Demos/" + recordFileName + "." + *cProtoVer + ".hwd";
  1362         filename = cfgdir->absolutePath() + "/Demos/" + recordFileName + "." + *cProtoVer + ".hwd";
  1324         m_lastDemo = demo;
  1363         m_lastDemo = demo;
  1325     } else
  1364     }
       
  1365     else
  1326     {
  1366     {
  1327         demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS"));
  1367         demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS"));
  1328         demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS"));
  1368         demo.replace(QByteArray("\x02TN"), QByteArray("\x02TS"));
  1329         filename = cfgdir->absolutePath() + "/Saves/" + recordFileName + "." + *cProtoVer + ".hws";
  1369         filename = cfgdir->absolutePath() + "/Saves/" + recordFileName + "." + *cProtoVer + ".hws";
  1330     }
  1370     }
  1356 
  1396 
  1357 void HWForm::CreateNetGame()
  1397 void HWForm::CreateNetGame()
  1358 {
  1398 {
  1359     QString ammo;
  1399     QString ammo;
  1360     ammo = ui.pageNetGame->pGameCFG->WeaponsName->itemData(
  1400     ammo = ui.pageNetGame->pGameCFG->WeaponsName->itemData(
  1361             ui.pageNetGame->pGameCFG->WeaponsName->currentIndex()
  1401                ui.pageNetGame->pGameCFG->WeaponsName->currentIndex()
  1362             ).toString();
  1402            ).toString();
  1363 
  1403 
  1364     CreateGame(ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget, ammo);
  1404     CreateGame(ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget, ammo);
  1365 
  1405 
  1366     connect(game, SIGNAL(SendNet(const QByteArray &)), hwnet, SLOT(SendNet(const QByteArray &)));
  1406     connect(game, SIGNAL(SendNet(const QByteArray &)), hwnet, SLOT(SendNet(const QByteArray &)));
  1367     connect(game, SIGNAL(SendChat(const QString &)), hwnet, SLOT(chatLineToNet(const QString &)));
  1407     connect(game, SIGNAL(SendChat(const QString &)), hwnet, SLOT(chatLineToNet(const QString &)));
  1417         ui.pageNetGame->setRoomName(hwnet->getRoom());
  1457         ui.pageNetGame->setRoomName(hwnet->getRoom());
  1418         ui.pageNetGame->restrictJoins->disconnect(hwnet);
  1458         ui.pageNetGame->restrictJoins->disconnect(hwnet);
  1419         ui.pageNetGame->restrictTeamAdds->disconnect(hwnet);
  1459         ui.pageNetGame->restrictTeamAdds->disconnect(hwnet);
  1420         connect(ui.pageNetGame->BtnStart, SIGNAL(clicked()), hwnet, SLOT(startGame()));
  1460         connect(ui.pageNetGame->BtnStart, SIGNAL(clicked()), hwnet, SLOT(startGame()));
  1421         connect(ui.pageNetGame, SIGNAL(askForUpdateRoomName(const QString &)),
  1461         connect(ui.pageNetGame, SIGNAL(askForUpdateRoomName(const QString &)),
  1422             hwnet, SLOT(updateRoomName(const QString &)));
  1462                 hwnet, SLOT(updateRoomName(const QString &)));
  1423         connect(ui.pageNetGame->restrictJoins, SIGNAL(triggered()), hwnet, SLOT(toggleRestrictJoins()));
  1463         connect(ui.pageNetGame->restrictJoins, SIGNAL(triggered()), hwnet, SLOT(toggleRestrictJoins()));
  1424         connect(ui.pageNetGame->restrictTeamAdds, SIGNAL(triggered()), hwnet, SLOT(toggleRestrictTeamAdds()));
  1464         connect(ui.pageNetGame->restrictTeamAdds, SIGNAL(triggered()), hwnet, SLOT(toggleRestrictTeamAdds()));
  1425         connect(ui.pageNetGame->pGameCFG->GameSchemes->model(),
  1465         connect(ui.pageNetGame->pGameCFG->GameSchemes->model(),
  1426                 SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
  1466                 SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
  1427                 ui.pageNetGame->pGameCFG,
  1467                 ui.pageNetGame->pGameCFG,
  1428                 SLOT(resendSchemeData())
  1468                 SLOT(resendSchemeData())
  1429                 );
  1469                );
  1430     }
  1470     }
  1431 }
  1471 }
  1432 
  1472 
  1433 void HWForm::NetGameSlave()
  1473 void HWForm::NetGameSlave()
  1434 {
  1474 {
  1468 
  1508 
  1469 void HWForm::resizeEvent(QResizeEvent * event)
  1509 void HWForm::resizeEvent(QResizeEvent * event)
  1470 {
  1510 {
  1471     int w = event->size().width();
  1511     int w = event->size().width();
  1472     int h = event->size().height();
  1512     int h = event->size().height();
  1473     if (wBackground) {
  1513     if (wBackground)
       
  1514     {
  1474         wBackground->setFixedSize(w, h);
  1515         wBackground->setFixedSize(w, h);
  1475         wBackground->move(0, 0);
  1516         wBackground->move(0, 0);
  1476     }
  1517     }
  1477 }
  1518 }
  1478 
  1519 
  1482 
  1523 
  1483     HWTeam team(ui.pageCampaign->CBTeam->currentText());
  1524     HWTeam team(ui.pageCampaign->CBTeam->currentText());
  1484     ui.pageCampaign->CBSelect->clear();
  1525     ui.pageCampaign->CBSelect->clear();
  1485 
  1526 
  1486     QStringList entries = HWDataManager::instance().entryList(
  1527     QStringList entries = HWDataManager::instance().entryList(
  1487                                                         "Missions/Campaign",
  1528                               "Missions/Campaign",
  1488                                                         QDir::Files,
  1529                               QDir::Files,
  1489                                                         QStringList("*#*.lua")
  1530                               QStringList("*#*.lua")
  1490                                                     );
  1531                           );
  1491     
  1532 
  1492     unsigned int n = entries.count();
  1533     unsigned int n = entries.count();
  1493     for(unsigned int i = 0; (i < n) && (i <= team.campaignProgress()); i++) {
  1534     for(unsigned int i = 0; (i < n) && (i <= team.campaignProgress()); i++)
       
  1535     {
  1494         ui.pageCampaign->CBSelect->addItem(QString(entries[i]).replace(QRegExp("^(\\d+)#(.+)\\.lua"), QComboBox::tr("Mission") + " \\1: \\2").replace("_", " "), QString(entries[i]).replace(QRegExp("^(.*)\\.lua"), "\\1"));
  1536         ui.pageCampaign->CBSelect->addItem(QString(entries[i]).replace(QRegExp("^(\\d+)#(.+)\\.lua"), QComboBox::tr("Mission") + " \\1: \\2").replace("_", " "), QString(entries[i]).replace(QRegExp("^(.*)\\.lua"), "\\1"));
  1495     }
  1537     }
  1496 }
  1538 }
  1497 
  1539 
  1498 // used for --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]
  1540 // used for --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]
  1499 QString HWForm::getDemoArguments()
  1541 QString HWForm::getDemoArguments()
  1500 {
  1542 {
  1501     QRect resolution = config->vid_Resolution();
  1543     QRect resolution = config->vid_Resolution();
  1502     return QString(QString::number(resolution.width()) + " "
  1544     return QString(QString::number(resolution.width()) + " "
  1503      + QString::number(resolution.height()) + " "
  1545                    + QString::number(resolution.height()) + " "
  1504      + QString::number(config->bitDepth()) + " " // bpp
  1546                    + QString::number(config->bitDepth()) + " " // bpp
  1505      + QString::number(config->volume()) + " " // sound volume
  1547                    + QString::number(config->volume()) + " " // sound volume
  1506      + (config->isMusicEnabled() ? "1" : "0") + " "
  1548                    + (config->isMusicEnabled() ? "1" : "0") + " "
  1507      + (config->isSoundEnabled() ? "1" : "0") + " "
  1549                    + (config->isSoundEnabled() ? "1" : "0") + " "
  1508      + config->language() + ".txt "
  1550                    + config->language() + ".txt "
  1509      + (config->vid_Fullscreen() ? "1" : "0") + " "
  1551                    + (config->vid_Fullscreen() ? "1" : "0") + " "
  1510      + (config->isShowFPSEnabled() ? "1" : "0") + " "
  1552                    + (config->isShowFPSEnabled() ? "1" : "0") + " "
  1511      + (config->isAltDamageEnabled() ? "1" : "0") + " "
  1553                    + (config->isAltDamageEnabled() ? "1" : "0") + " "
  1512      + QString::number(config->timerInterval()) + " "
  1554                    + QString::number(config->timerInterval()) + " "
  1513      + QString::number(config->translateQuality()));
  1555                    + QString::number(config->translateQuality()));
  1514 }
  1556 }
  1515 
  1557 
  1516 void HWForm::AssociateFiles()
  1558 void HWForm::AssociateFiles()
  1517 {
  1559 {
  1518     bool success = true;
  1560     bool success = true;
  1560         QString fileName;
  1602         QString fileName;
  1561         bool ok = false;
  1603         bool ok = false;
  1562         do
  1604         do
  1563         {
  1605         {
  1564             fileName = QInputDialog::getText(this, tr("Demo name"), tr("Demo name:"));
  1606             fileName = QInputDialog::getText(this, tr("Demo name"), tr("Demo name:"));
  1565             
  1607 
  1566             if(!fileName.isEmpty())
  1608             if(!fileName.isEmpty())
  1567             {
  1609             {
  1568                 QString filePath = cfgdir->absolutePath() + "/Demos/" + fileName + "." + *cProtoVer + ".hwd";
  1610                 QString filePath = cfgdir->absolutePath() + "/Demos/" + fileName + "." + *cProtoVer + ".hwd";
  1569                 QFile demofile(filePath);
  1611                 QFile demofile(filePath);
  1570                 ok = demofile.open(QIODevice::WriteOnly);
  1612                 ok = demofile.open(QIODevice::WriteOnly);
  1574                 {
  1616                 {
  1575                     ok = -1 != demofile.write(m_lastDemo);
  1617                     ok = -1 != demofile.write(m_lastDemo);
  1576                     demofile.close();
  1618                     demofile.close();
  1577                 }
  1619                 }
  1578             }
  1620             }
  1579         } while(!fileName.isEmpty() && !ok);
  1621         }
       
  1622         while(!fileName.isEmpty() && !ok);
  1580     }
  1623     }
  1581 }
  1624 }
  1582 
  1625 
  1583 void HWForm::SendFeedback()
  1626 void HWForm::SendFeedback()
  1584 {
  1627 {
  1585     //Create Xml representation of google code issue first
  1628     //Create Xml representation of google code issue first
  1586     if (!CreateIssueXml())
  1629     if (!CreateIssueXml())
  1587     {
  1630     {
  1588         QMessageBox::warning(this, QMessageBox::tr("Fields required"),
  1631         QMessageBox::warning(this, QMessageBox::tr("Fields required"),
  1589               QMessageBox::tr("Please fill out all fields"));
  1632                              QMessageBox::tr("Please fill out all fields"));
  1590         return;
  1633         return;
  1591     }
  1634     }
  1592     
  1635 
  1593     //Google login using fake account (feedback.hedgewars@gmail.com)
  1636     //Google login using fake account (feedback.hedgewars@gmail.com)
  1594     nam = new QNetworkAccessManager(this);
  1637     nam = new QNetworkAccessManager(this);
  1595     connect(nam, SIGNAL(finished(QNetworkReply*)),
  1638     connect(nam, SIGNAL(finished(QNetworkReply*)),
  1596 	this, SLOT(finishedSlot(QNetworkReply*)));
  1639             this, SLOT(finishedSlot(QNetworkReply*)));
  1597 
  1640 
  1598     QUrl url(string(string("https://www.google.com/accounts/ClientLogin?"
  1641     QUrl url(string(string("https://www.google.com/accounts/ClientLogin?"
  1599              "accountType=GOOGLE&Email=feedback.hedgewars@gmail.com&Passwd=hwfeedback&service=code&source=HedgewarsFoundation-Hedgewars-")
  1642                            "accountType=GOOGLE&Email=feedback.hedgewars@gmail.com&Passwd=hwfeedback&service=code&source=HedgewarsFoundation-Hedgewars-")
  1600 	     + (cVersionString?(*cVersionString):QString("")).toStdString()).c_str());
  1643                     + (cVersionString?(*cVersionString):QString("")).toStdString()).c_str());
  1601     nam->get(QNetworkRequest(url));
  1644     nam->get(QNetworkRequest(url));
  1602 
  1645 
  1603 }
  1646 }
  1604 
  1647 
  1605 bool HWForm::CreateIssueXml()
  1648 bool HWForm::CreateIssueXml()
  1607     QString summary = ui.pageFeedback->summary->text();
  1650     QString summary = ui.pageFeedback->summary->text();
  1608     QString description = ui.pageFeedback->description->toPlainText();
  1651     QString description = ui.pageFeedback->description->toPlainText();
  1609 
  1652 
  1610     //Check if all necessary information is entered
  1653     //Check if all necessary information is entered
  1611     if (summary.isEmpty() || description.isEmpty())
  1654     if (summary.isEmpty() || description.isEmpty())
  1612 	return false;
  1655         return false;
  1613 
  1656 
  1614     issueXml =
  1657     issueXml =
  1615 	"<?xml version='1.0' encoding='UTF-8'?>"
  1658         "<?xml version='1.0' encoding='UTF-8'?>"
  1616 	"<entry xmlns='http://www.w3.org/2005/Atom' xmlns:issues='http://code.google.com/p/hedgewars/issues/list'>"
  1659         "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:issues='http://code.google.com/p/hedgewars/issues/list'>"
  1617         "<title>";
  1660         "<title>";
  1618     issueXml.append(summary);
  1661     issueXml.append(summary);
  1619     issueXml.append("</title><content type='html'>");
  1662     issueXml.append("</title><content type='html'>");
  1620     issueXml.append(description);
  1663     issueXml.append(description);
  1621     issueXml.append("</content><author><name>feedback.hedgewars</name></author></entry>");
  1664     issueXml.append("</content><author><name>feedback.hedgewars</name></author></entry>");
  1625 
  1668 
  1626 void HWForm::finishedSlot(QNetworkReply* reply)
  1669 void HWForm::finishedSlot(QNetworkReply* reply)
  1627 {
  1670 {
  1628     if (reply && reply->error() == QNetworkReply::NoError)
  1671     if (reply && reply->error() == QNetworkReply::NoError)
  1629     {
  1672     {
  1630 	QByteArray array = reply->readAll();
  1673         QByteArray array = reply->readAll();
  1631         QString str(array);
  1674         QString str(array);
  1632 
  1675 
  1633         if (authToken.length() != 0)
  1676         if (authToken.length() != 0)
  1634 	{
  1677         {
  1635 	   QMessageBox::information(this, QMessageBox::tr("Success"),
  1678             QMessageBox::information(this, QMessageBox::tr("Success"),
  1636               QMessageBox::tr("Successfully posted the issue on code.google.com!"));
  1679                                      QMessageBox::tr("Successfully posted the issue on code.google.com!"));
  1637 	   ui.pageFeedback->summary->clear();
  1680             ui.pageFeedback->summary->clear();
  1638 	   ui.pageFeedback->description->clear();
  1681             ui.pageFeedback->description->clear();
  1639 	   authToken = "";
  1682             authToken = "";
  1640 	   return;
  1683             return;
  1641 	}
  1684         }
  1642 
  1685 
  1643 	if(!getAuthToken(str))
  1686         if(!getAuthToken(str))
  1644 	{
  1687         {
  1645 	   QMessageBox::warning(this, QMessageBox::tr("Network"),
  1688             QMessageBox::warning(this, QMessageBox::tr("Network"),
  1646               QMessageBox::tr("Error during authentication with www.google.com"));
  1689                                  QMessageBox::tr("Error during authentication with www.google.com"));
  1647 	   return;
  1690             return;
  1648 	}
  1691         }
  1649 
  1692 
  1650 	QByteArray body(issueXml.toStdString().c_str());
  1693         QByteArray body(issueXml.toStdString().c_str());
  1651 	QNetworkRequest header(QUrl("https://code.google.com/feeds/issues/p/hedgewars/issues/full"));
  1694         QNetworkRequest header(QUrl("https://code.google.com/feeds/issues/p/hedgewars/issues/full"));
  1652 	header.setRawHeader("Content-Length", QString::number(issueXml.length()).toAscii());
  1695         header.setRawHeader("Content-Length", QString::number(issueXml.length()).toAscii());
  1653 	header.setRawHeader("Content-Type", "application/atom+xml");
  1696         header.setRawHeader("Content-Type", "application/atom+xml");
  1654 	header.setRawHeader("Authorization", string(
  1697         header.setRawHeader("Authorization", string(
  1655 	   string("GoogleLogin auth=") + authToken.toStdString()).c_str());
  1698                                 string("GoogleLogin auth=") + authToken.toStdString()).c_str());
  1656 	nam->post(header, body);
  1699         nam->post(header, body);
  1657 
  1700 
  1658     }
  1701     }
  1659     else if (authToken.length() == 0)
  1702     else if (authToken.length() == 0)
  1660 	QMessageBox::warning(this, QMessageBox::tr("Network"),
  1703         QMessageBox::warning(this, QMessageBox::tr("Network"),
  1661               QMessageBox::tr("Error during authentication with www.google.com"));
  1704                              QMessageBox::tr("Error during authentication with www.google.com"));
  1662     else
  1705     else
  1663     {
  1706     {
  1664 	QMessageBox::warning(this, QMessageBox::tr("Network"),
  1707         QMessageBox::warning(this, QMessageBox::tr("Network"),
  1665               QMessageBox::tr("Error creating the issue"));
  1708                              QMessageBox::tr("Error creating the issue"));
  1666 	authToken = "";
  1709         authToken = "";
  1667     }
  1710     }
  1668 	
  1711 
  1669 }
  1712 }
  1670 
  1713 
  1671 bool HWForm::getAuthToken(QString str)
  1714 bool HWForm::getAuthToken(QString str)
  1672 {
  1715 {
  1673    QRegExp ex("Auth=(.+)");
  1716     QRegExp ex("Auth=(.+)");
  1674 
  1717 
  1675    if (-1 == ex.indexIn(str))
  1718     if (-1 == ex.indexIn(str))
  1676 	return false;
  1719         return false;
  1677    
  1720 
  1678    authToken = ex.cap(1);
  1721     authToken = ex.cap(1);
  1679    authToken.remove(QChar('\n'));
  1722     authToken.remove(QChar('\n'));
  1680 
  1723 
  1681    return true;
  1724     return true;
  1682 }
  1725 }
  1683 
  1726 
  1684 
  1727 
  1685 
  1728