QTfrontend/hwform.cpp
branchwebgl
changeset 9127 e350500c4edb
parent 8833 c13ebed437cb
parent 9100 3f5e0280db4d
child 9197 e4e366013e9a
equal deleted inserted replaced
8860:bde641cf53c8 9127:e350500c4edb
     1 /*
     1 /*
     2  * Hedgewars, a free turn based strategy game
     2  * Hedgewars, a free turn based strategy game
     3  * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
     3  * Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com>
     4  *
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation; version 2 of the License
     7  * the Free Software Foundation; version 2 of the License
     8  *
     8  *
    43 #include <QDesktopWidget>
    43 #include <QDesktopWidget>
    44 #include <QApplication>
    44 #include <QApplication>
    45 #include <QInputDialog>
    45 #include <QInputDialog>
    46 #include <QPropertyAnimation>
    46 #include <QPropertyAnimation>
    47 #include <QSettings>
    47 #include <QSettings>
       
    48 #include <QSortFilterProxyModel>
    48 
    49 
    49 #if (QT_VERSION >= 0x040600)
    50 #if (QT_VERSION >= 0x040600)
    50 #include <QGraphicsEffect>
    51 #include <QGraphicsEffect>
    51 #include <QParallelAnimationGroup>
    52 #include <QParallelAnimationGroup>
    52 #endif
    53 #endif
   148     //setFocusPolicy(Qt::StrongFocus);
   149     //setFocusPolicy(Qt::StrongFocus);
   149     CustomizePalettes();
   150     CustomizePalettes();
   150 
   151 
   151     ui.pageOptions->CBResolution->addItems(SDLInteraction::instance().getResolutions());
   152     ui.pageOptions->CBResolution->addItems(SDLInteraction::instance().getResolutions());
   152 
   153 
   153     config = new GameUIConfig(this, "physfs://hedgewars.ini");
   154     config = new GameUIConfig(this, DataManager::instance().settingsFileName());
   154     frontendEffects = config->value("frontend/effects", true).toBool();
   155     frontendEffects = config->value("frontend/effects", true).toBool();
   155     playerHash = QString(QCryptographicHash::hash(config->value("net/nick","").toString().toUtf8(), QCryptographicHash::Md5).toHex());
   156     playerHash = QString(QCryptographicHash::hash(config->value("net/nick",tr("Guest")+QString("%1").arg(rand())).toString().toUtf8(), QCryptographicHash::Md5).toHex());
   156 
   157 
   157     ui.pageRoomsList->setSettings(config);
   158     ui.pageRoomsList->setSettings(config);
   158     ui.pageNetGame->setSettings(config);
   159     ui.pageNetGame->setSettings(config);
   159     ui.pageNetGame->chatWidget->setSettings(config);
   160     ui.pageNetGame->chatWidget->setSettings(config);
   160     ui.pageRoomsList->chatWidget->setSettings(config);
   161     ui.pageRoomsList->chatWidget->setSettings(config);
   283     pageSwitchMapper->setMapping(ui.pageRoomsList->BtnAdmin, ID_PAGE_ADMIN);
   284     pageSwitchMapper->setMapping(ui.pageRoomsList->BtnAdmin, ID_PAGE_ADMIN);
   284 
   285 
   285     connect(ui.pageInfo->BtnSnapshots, SIGNAL(clicked()), this, SLOT(OpenSnapshotFolder()));
   286     connect(ui.pageInfo->BtnSnapshots, SIGNAL(clicked()), this, SLOT(OpenSnapshotFolder()));
   286 
   287 
   287     connect(ui.pageGameStats, SIGNAL(saveDemoRequested()), this, SLOT(saveDemoWithCustomName()));
   288     connect(ui.pageGameStats, SIGNAL(saveDemoRequested()), this, SLOT(saveDemoWithCustomName()));
       
   289     connect(ui.pageGameStats, SIGNAL(restartGameRequested()), this, SLOT(restartGame()));
   288 
   290 
   289     connect(ui.pageSinglePlayer->BtnSimpleGamePage, SIGNAL(clicked()), this, SLOT(SimpleGame()));
   291     connect(ui.pageSinglePlayer->BtnSimpleGamePage, SIGNAL(clicked()), this, SLOT(SimpleGame()));
   290     connect(ui.pageSinglePlayer->BtnTrainPage, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   292     connect(ui.pageSinglePlayer->BtnTrainPage, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   291     pageSwitchMapper->setMapping(ui.pageSinglePlayer->BtnTrainPage, ID_PAGE_TRAINING);
   293     pageSwitchMapper->setMapping(ui.pageSinglePlayer->BtnTrainPage, ID_PAGE_TRAINING);
   292 
   294 
   314     //    this, SLOT(GoBack())); // executed third
   316     //    this, SLOT(GoBack())); // executed third
   315 
   317 
   316 
   318 
   317     connect(ui.pageMain->BtnNetLocal, SIGNAL(clicked()), this, SLOT(GoToNet()));
   319     connect(ui.pageMain->BtnNetLocal, SIGNAL(clicked()), this, SLOT(GoToNet()));
   318     connect(ui.pageMain->BtnNetOfficial, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer()));
   320     connect(ui.pageMain->BtnNetOfficial, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer()));
   319 
       
   320     connect(ui.pageConnecting, SIGNAL(cancelConnection()), this, SLOT(GoBack()));
       
   321 
   321 
   322     connect(ui.pageVideos, SIGNAL(goBack()), config, SLOT(SaveVideosOptions()));
   322     connect(ui.pageVideos, SIGNAL(goBack()), config, SLOT(SaveVideosOptions()));
   323 
   323 
   324     ammoSchemeModel = new AmmoSchemeModel(this, cfgdir->absolutePath() + "/schemes.ini");
   324     ammoSchemeModel = new AmmoSchemeModel(this, cfgdir->absolutePath() + "/schemes.ini");
   325     ui.pageScheme->setModel(ammoSchemeModel);
   325     ui.pageScheme->setModel(ammoSchemeModel);
   468 {
   468 {
   469     QStringList teamslist = config->GetTeamsList();
   469     QStringList teamslist = config->GetTeamsList();
   470 
   470 
   471     if(teamslist.empty())
   471     if(teamslist.empty())
   472     {
   472     {
   473         QString currentNickName = config->value("net/nick","").toString().toUtf8();
   473         QString currentNickName = config->value("net/nick",tr("Guest")+QString("%1").arg(rand())).toString().toUtf8();
   474         QString teamName;
   474         QString teamName;
   475 
   475 
   476         if (currentNickName.isEmpty())
   476         if (currentNickName.isEmpty())
   477         {
   477         {
   478             teamName = tr("DefaultTeam");
   478             teamName = tr("DefaultTeam");
   594 #ifdef USE_XFIRE
   594 #ifdef USE_XFIRE
   595     updateXfire();
   595     updateXfire();
   596 #endif
   596 #endif
   597 
   597 
   598     qDebug("Leaving %s, entering %s", qPrintable(stringifyPageId(lastid)), qPrintable(stringifyPageId(id)));
   598     qDebug("Leaving %s, entering %s", qPrintable(stringifyPageId(lastid)), qPrintable(stringifyPageId(id)));
       
   599     if (lastid == ID_PAGE_MAIN)
       
   600     {
       
   601         ui.pageMain->resetNetworkChoice();
       
   602     }
   599 
   603 
   600     // pageEnter and pageLeave events
   604     // pageEnter and pageLeave events
   601     ((AbstractPage*)ui.Pages->widget(lastid))->triggerPageLeave();
   605     ((AbstractPage*)ui.Pages->widget(lastid))->triggerPageLeave();
   602     ((AbstractPage*)ui.Pages->widget(id))->triggerPageEnter();
   606     ((AbstractPage*)ui.Pages->widget(id))->triggerPageEnter();
   603 
   607 
   668                  && lastid != ID_PAGE_INGAME
   672                  && lastid != ID_PAGE_INGAME
   669                  && lastid != ID_PAGE_SCHEME
   673                  && lastid != ID_PAGE_SCHEME
   670                  && lastid != ID_PAGE_SELECTWEAPON)
   674                  && lastid != ID_PAGE_SELECTWEAPON)
   671         {
   675         {
   672             curTeamSelWidget->resetPlayingTeams(teamsList);
   676             curTeamSelWidget->resetPlayingTeams(teamsList);
       
   677         }
       
   678     }
       
   679 
       
   680     if (id == ID_PAGE_GAMESTATS)
       
   681     {
       
   682         switch(lastGameType) {
       
   683         case gtLocal:
       
   684         case gtQLocal:
       
   685         case gtTraining:
       
   686         case gtCampaign:
       
   687             ui.pageGameStats->restartBtnVisible(true);
       
   688             break;
       
   689         default:
       
   690             ui.pageGameStats->restartBtnVisible(false);
       
   691             break;
   673         }
   692         }
   674     }
   693     }
   675 
   694 
   676     if (id == ID_PAGE_MAIN)
   695     if (id == ID_PAGE_MAIN)
   677     {
   696     {
  1244     connect(ui.pageRoomsList, SIGNAL(askForRoomList()),
  1263     connect(ui.pageRoomsList, SIGNAL(askForRoomList()),
  1245             hwnet, SLOT(askRoomsList()));
  1264             hwnet, SLOT(askRoomsList()));
  1246 
  1265 
  1247 // room status stuff
  1266 // room status stuff
  1248     connect(hwnet, SIGNAL(roomMaster(bool)),
  1267     connect(hwnet, SIGNAL(roomMaster(bool)),
  1249             this, SLOT(NetGameChangeStatus(bool)), Qt::QueuedConnection);
  1268             this, SLOT(NetGameChangeStatus(bool)));
  1250 
  1269 
  1251 // net page stuff
  1270 // net page stuff
  1252     connect(hwnet, SIGNAL(roomNameUpdated(const QString &)),
  1271     connect(hwnet, SIGNAL(roomNameUpdated(const QString &)),
  1253             ui.pageNetGame, SLOT(setRoomName(const QString &)), Qt::QueuedConnection);
  1272             ui.pageNetGame, SLOT(setRoomName(const QString &)), Qt::QueuedConnection);
  1254     connect(hwnet, SIGNAL(chatStringFromNet(const QString&)),
  1273     connect(hwnet, SIGNAL(roomChatAction(const QString&, const QString&)),
  1255             ui.pageNetGame->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
  1274             ui.pageNetGame->chatWidget, SLOT(onChatAction(const QString&, const QString&)), Qt::QueuedConnection);
  1256 
  1275     connect(hwnet, SIGNAL(roomChatMessage(const QString&, const QString&)),
  1257     connect(hwnet, SIGNAL(chatStringFromMe(const QString&)),
  1276             ui.pageNetGame->chatWidget, SLOT(onChatMessage(const QString&, const QString&)), Qt::QueuedConnection);
  1258             ui.pageNetGame->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
  1277 
  1259     connect(hwnet, SIGNAL(roomMaster(bool)),
  1278     connect(hwnet, SIGNAL(roomMaster(bool)),
  1260             ui.pageNetGame->chatWidget, SLOT(adminAccess(bool)), Qt::QueuedConnection);
  1279             ui.pageNetGame->chatWidget, SLOT(adminAccess(bool)), Qt::QueuedConnection);
  1261     connect(ui.pageNetGame->chatWidget, SIGNAL(chatLine(const QString&)),
  1280     connect(ui.pageNetGame->chatWidget, SIGNAL(chatLine(const QString&)),
  1262             hwnet, SLOT(chatLineToNet(const QString&)));
  1281             hwnet, SLOT(chatLineToNetWithEcho(const QString&)));
  1263     connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady()));
  1282     connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady()));
  1264     connect(hwnet, SIGNAL(setMyReadyStatus(bool)),
  1283     connect(hwnet, SIGNAL(setMyReadyStatus(bool)),
  1265             ui.pageNetGame, SLOT(setReadyStatus(bool)), Qt::QueuedConnection);
  1284             ui.pageNetGame, SLOT(setReadyStatus(bool)), Qt::QueuedConnection);
  1266 
  1285 
  1267 // chat widget actions
  1286 // chat widget actions
  1284     connect(ui.pageRoomsList->chatWidget, SIGNAL(follow(const QString&)),
  1303     connect(ui.pageRoomsList->chatWidget, SIGNAL(follow(const QString&)),
  1285             hwnet, SLOT(followPlayer(const QString&)));
  1304             hwnet, SLOT(followPlayer(const QString&)));
  1286     connect(ui.pageRoomsList->chatWidget, SIGNAL(consoleCommand(const QString&)),
  1305     connect(ui.pageRoomsList->chatWidget, SIGNAL(consoleCommand(const QString&)),
  1287             hwnet, SLOT(consoleCommand(const QString&)));
  1306             hwnet, SLOT(consoleCommand(const QString&)));
  1288 
  1307 
       
  1308 // player info
       
  1309     connect(hwnet, SIGNAL(playerInfo(const QString&, const QString&, const QString&, const QString&)),
       
  1310             ui.pageRoomsList->chatWidget, SLOT(onPlayerInfo(const QString&, const QString&, const QString&, const QString&)), Qt::QueuedConnection);
       
  1311     connect(hwnet, SIGNAL(playerInfo(const QString&, const QString&, const QString&, const QString&)),
       
  1312             ui.pageNetGame->chatWidget, SLOT(onPlayerInfo(const QString&, const QString&, const QString&, const QString&)), Qt::QueuedConnection);
       
  1313 
  1289 // chatting
  1314 // chatting
  1290     connect(ui.pageRoomsList->chatWidget, SIGNAL(chatLine(const QString&)),
  1315     connect(ui.pageRoomsList->chatWidget, SIGNAL(chatLine(const QString&)),
  1291             hwnet, SLOT(chatLineToLobby(const QString&)));
  1316             hwnet, SLOT(chatLineToLobby(const QString&)));
  1292     connect(hwnet, SIGNAL(chatStringLobby(const QString&)),
  1317     connect(hwnet, SIGNAL(lobbyChatAction(const QString&,const QString&)),
  1293             ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
  1318             ui.pageRoomsList->chatWidget, SLOT(onChatAction(const QString&,const QString&)), Qt::QueuedConnection);
  1294     connect(hwnet, SIGNAL(chatStringLobby(const QString&, const QString&)),
  1319     connect(hwnet, SIGNAL(lobbyChatMessage(const QString&, const QString&)),
  1295             ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&, const QString&)), Qt::QueuedConnection);
  1320             ui.pageRoomsList->chatWidget, SLOT(onChatMessage(const QString&, const QString&)), Qt::QueuedConnection);
  1296     connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)),
       
  1297             ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
       
  1298 
  1321 
  1299 // nick list stuff
  1322 // nick list stuff
  1300     connect(hwnet, SIGNAL(nickAdded(const QString&, bool)),
  1323     {
  1301             ui.pageNetGame->chatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection);
  1324         QSortFilterProxyModel * playersSortFilterModel = qobject_cast<QSortFilterProxyModel *>(hwnet->lobbyPlayersModel());
  1302     connect(hwnet, SIGNAL(nickRemoved(const QString&)),
  1325         if(playersSortFilterModel)
  1303             ui.pageNetGame->chatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection);
  1326         {
  1304     connect(hwnet, SIGNAL(nickAddedLobby(const QString&, bool)),
  1327             PlayersListModel * players = qobject_cast<PlayersListModel *>(playersSortFilterModel->sourceModel());
  1305             ui.pageRoomsList->chatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection);
  1328             connect(players, SIGNAL(nickAdded(const QString&, bool)),
  1306     connect(hwnet, SIGNAL(nickRemovedLobby(const QString&)),
  1329                     ui.pageNetGame->chatWidget, SLOT(nickAdded(const QString&, bool)));
  1307             ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection);
  1330             connect(players, SIGNAL(nickRemoved(const QString&)),
       
  1331                     ui.pageNetGame->chatWidget, SLOT(nickRemoved(const QString&)));
       
  1332             connect(players, SIGNAL(nickAddedLobby(const QString&, bool)),
       
  1333                     ui.pageRoomsList->chatWidget, SLOT(nickAdded(const QString&, bool)));
       
  1334             connect(players, SIGNAL(nickRemovedLobby(const QString&)),
       
  1335                     ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&)));
       
  1336             connect(players, SIGNAL(nickRemovedLobby(const QString&, const QString&)),
       
  1337                     ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&, const QString&)));
       
  1338         }
       
  1339     }
  1308 
  1340 
  1309 // teams selecting stuff
  1341 // teams selecting stuff
  1310     connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)),
  1342     connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(hhogsNumChanged(const HWTeam&)),
  1311             hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&)));
  1343             hwnet, SLOT(onHedgehogsNumChanged(const HWTeam&)));
  1312     connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamColorChanged(const HWTeam&)),
  1344     connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamColorChanged(const HWTeam&)),
  1340 // config stuff
  1372 // config stuff
  1341     connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &)));
  1373     connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &)));
  1342     connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &)));
  1374     connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &)));
  1343     connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig()));
  1375     connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig()));
  1344 
  1376 
       
  1377     // using proxy slot to prevent loss of game messages when they're sent to not yet connected slot of game object
       
  1378     connect(hwnet, SIGNAL(FromNet(const QByteArray &)), this, SLOT(FromNetProxySlot(const QByteArray &)), Qt::QueuedConnection);
       
  1379 
  1345     //nick and pass stuff
  1380     //nick and pass stuff
  1346     QString nickname = config->value("net/nick", "").toString();
       
  1347 
       
  1348     hwnet->m_private_game = !(hostName == NETGAME_DEFAULT_SERVER && port == NETGAME_DEFAULT_PORT);
  1381     hwnet->m_private_game = !(hostName == NETGAME_DEFAULT_SERVER && port == NETGAME_DEFAULT_PORT);
  1349     if (hwnet->m_private_game == false)
  1382     if (hwnet->m_private_game == false && AskForNickAndPwd() != 0)
  1350         if (AskForNickAndPwd() != 0)
  1383         return;
  1351             return;
  1384 
  1352 
  1385     QString nickname = config->value("net/nick",tr("Guest")+QString("%1").arg(rand())).toString();
  1353     ui.pageRoomsList->setUser(nickname);
  1386     ui.pageRoomsList->setUser(nickname);
  1354     ui.pageNetGame->setUser(nickname);
  1387     ui.pageNetGame->setUser(nickname);
  1355 
  1388 
  1356     hwnet->Connect(hostName, port, nickname);
  1389     hwnet->Connect(hostName, port, nickname);
  1357 }
  1390 }
  1360 {
  1393 {
  1361     //remove temppasswordhash just in case
  1394     //remove temppasswordhash just in case
  1362     config->clearTempHash();
  1395     config->clearTempHash();
  1363 
  1396 
  1364     //initialize
  1397     //initialize
  1365     QString hash = config->passwordHash();
  1398     QString hash;
  1366     QString temphash = config->tempHash();
  1399     QString temphash;
  1367     QString nickname = config->value("net/nick", "").toString();
  1400     QString nickname;
  1368     QString password;
  1401     QString password;
  1369 
  1402 
  1370     //if something from login is missing, start dialog loop
  1403     do {
  1371     if (nickname.isEmpty() || hash.isEmpty())
  1404         nickname = config->value("net/nick",tr("Guest")+QString("%1").arg(rand())).toString();
  1372     {
  1405         hash = config->passwordHash();
  1373         while (nickname.isEmpty() || (hash.isEmpty() && temphash.isEmpty())) //while a nickname, or both hashes are missing
  1406         temphash = config->tempHash();
  1374         {
  1407 
       
  1408         //if something from login is missing, start dialog loop
       
  1409         if (nickname.isEmpty() || hash.isEmpty()) {
  1375             //open dialog
  1410             //open dialog
  1376             HWPasswordDialog * pwDialog = new HWPasswordDialog(this);
  1411             HWPasswordDialog * pwDialog = new HWPasswordDialog(this);
  1377             // make the "new account" button dialog open a browser with the registration page
  1412             // make the "new account" button dialog open a browser with the registration page
  1378             connect(pwDialog->pbNewAccount, SIGNAL(clicked()), this, SLOT(openRegistrationPage()));
  1413             connect(pwDialog->pbNewAccount, SIGNAL(clicked()), this, SLOT(openRegistrationPage()));
  1379             pwDialog->cbSave->setChecked(config->value("net/savepassword", true).toBool());
  1414             pwDialog->cbSave->setChecked(config->value("net/savepassword", true).toBool());
  1386 
  1421 
  1387             //if dialog close, create an error message
  1422             //if dialog close, create an error message
  1388             if (pwDialog->exec() != QDialog::Accepted) {
  1423             if (pwDialog->exec() != QDialog::Accepted) {
  1389                 delete pwDialog;
  1424                 delete pwDialog;
  1390                 GoBack();
  1425                 GoBack();
  1391                 return -1;
  1426                 break;
  1392             }
  1427             }
  1393 
  1428 
  1394             //set nick and pass from the dialog
  1429             //set nick and pass from the dialog
  1395             nickname = pwDialog->leNickname->text();
  1430             nickname = pwDialog->leNickname->text();
  1396             password = pwDialog->lePassword->text();
  1431             password = pwDialog->lePassword->text();
       
  1432             bool save = pwDialog->cbSave->isChecked();
       
  1433             //clean up
       
  1434             delete pwDialog;
  1397 
  1435 
  1398             //check the nickname variable
  1436             //check the nickname variable
  1399             if (nickname.isEmpty()) {
  1437             if (nickname.isEmpty()) {
  1400                 int retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied."));
  1438                 int retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied."));
  1401                 GoBack();
  1439                 GoBack();
  1402                 delete pwDialog;
       
  1403                 if (retry) {
  1440                 if (retry) {
  1404                     if (hwnet->m_private_game) {
  1441                     if (hwnet->m_private_game) {
  1405                         QStringList list = hwnet->getHost().split(":");
  1442                         QStringList list = hwnet->getHost().split(":");
  1406                         NetConnectServer(list.at(0), list.at(1).toShort());
  1443                         NetConnectServer(list.at(0), list.at(1).toShort());
  1407                     } else
  1444                     } else
  1408                         NetConnectOfficialServer();
  1445                         NetConnectOfficialServer();
  1409                     }
  1446                 }
  1410                 return -1;
  1447                 break; //loop restart
       
  1448             } else {
       
  1449                 //update nickname if it's fine
       
  1450                 config->setValue("net/nick", nickname);
       
  1451                 config->updNetNick();
  1411             }
  1452             }
  1412 
  1453 
  1413             if (!password.isEmpty()) {
  1454             //check the password variable
       
  1455             if (password.isEmpty()) {
       
  1456                 config->clearPasswordHash();
       
  1457                 break;
       
  1458             }  else {
  1414                 //calculate temphash and set it into config
  1459                 //calculate temphash and set it into config
  1415                 temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex();
  1460                 temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex();
  1416                 config->setTempHash(temphash);
  1461                 config->setTempHash(temphash);
  1417 
  1462 
  1418                 //if user wants to save password
  1463                 //if user wants to save password
  1419                 bool save = pwDialog->cbSave->isChecked();
       
  1420                 config->setValue("net/savepassword", save);
  1464                 config->setValue("net/savepassword", save);
  1421                 if (save) // user wants to save password
  1465                 if (save) {
  1422                 {
  1466                     // user wants to save password
  1423                     ui.pageOptions->CBSavePassword->setChecked(true);
  1467                     ui.pageOptions->CBSavePassword->setChecked(true);
  1424                     config->setPasswordHash(temphash);
  1468                     config->setPasswordHash(temphash);
  1425                 }
  1469                 }
  1426             }
  1470             }
  1427             else {
  1471         }
  1428                 delete pwDialog;
  1472     } while (nickname.isEmpty() || (hash.isEmpty() && temphash.isEmpty())); //while a nickname, or both hashes are missing
  1429                 config->setValue("net/nick", nickname);
  1473 
  1430                 config->updNetNick();
       
  1431                 config->clearPasswordHash();
       
  1432                 break;
       
  1433             }
       
  1434 
       
  1435             delete pwDialog;
       
  1436 
       
  1437             //update nickname
       
  1438             config->setValue("net/nick", nickname);
       
  1439             config->updNetNick();
       
  1440 
       
  1441             //and all the variables
       
  1442             hash = config->passwordHash();
       
  1443             temphash = config->tempHash();
       
  1444             nickname = config->value("net/nick", "").toString();
       
  1445         }
       
  1446     }
       
  1447     return 0;
  1474     return 0;
  1448 }
  1475 }
  1449 
  1476 
  1450 void HWForm::NetConnect()
  1477 void HWForm::NetConnect()
  1451 {
  1478 {
  1514     if (reason == "Reconnected too fast") { //TODO: this is a hack, which should be remade
  1541     if (reason == "Reconnected too fast") { //TODO: this is a hack, which should be remade
  1515         bool retry = RetryDialog(tr("Hedgewars - Connection error"), tr("You reconnected too fast.\nPlease wait a few seconds and try again."));
  1542         bool retry = RetryDialog(tr("Hedgewars - Connection error"), tr("You reconnected too fast.\nPlease wait a few seconds and try again."));
  1516         if (retry) {
  1543         if (retry) {
  1517             if (hwnet->m_private_game) {
  1544             if (hwnet->m_private_game) {
  1518                 QStringList list = hwnet->getHost().split(":");
  1545                 QStringList list = hwnet->getHost().split(":");
  1519                 NetConnectServer(list.at(0), list.at(1).toShort());
  1546                 NetConnectServer(list.at(0), list.at(1).toUInt());
  1520             } else
  1547             } else
  1521                 NetConnectOfficialServer();
  1548                 NetConnectOfficialServer();
  1522         }
  1549         }
  1523         else {
  1550         else {
  1524             while (ui.Pages->currentIndex() != ID_PAGE_NET
  1551             while (ui.Pages->currentIndex() != ID_PAGE_NET
  1700     game->StartCampaign(camp, miss, campTeam);
  1727     game->StartCampaign(camp, miss, campTeam);
  1701 }
  1728 }
  1702 
  1729 
  1703 void HWForm::CreateNetGame()
  1730 void HWForm::CreateNetGame()
  1704 {
  1731 {
       
  1732     // go back in pages to prevent user from being stuck on certain pages
       
  1733     if(ui.Pages->currentIndex() == ID_PAGE_GAMESTATS ||
       
  1734        ui.Pages->currentIndex() == ID_PAGE_INGAME)
       
  1735         GoBack();
       
  1736 
  1705     QString ammo;
  1737     QString ammo;
  1706     ammo = ui.pageNetGame->pGameCFG->WeaponsName->itemData(
  1738     ammo = ui.pageNetGame->pGameCFG->WeaponsName->itemData(
  1707                ui.pageNetGame->pGameCFG->WeaponsName->currentIndex()
  1739                ui.pageNetGame->pGameCFG->WeaponsName->currentIndex()
  1708            ).toString();
  1740            ).toString();
  1709 
  1741 
  1710     CreateGame(ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget, ammo);
  1742     CreateGame(ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget, ammo);
  1711 
  1743 
  1712     connect(game, SIGNAL(SendNet(const QByteArray &)), hwnet, SLOT(SendNet(const QByteArray &)));
  1744     connect(game, SIGNAL(SendNet(const QByteArray &)), hwnet, SLOT(SendNet(const QByteArray &)));
  1713     connect(game, SIGNAL(SendChat(const QString &)), hwnet, SLOT(chatLineToNet(const QString &)));
  1745     connect(game, SIGNAL(SendChat(const QString &)), hwnet, SLOT(chatLineToNet(const QString &)));
  1714     connect(game, SIGNAL(SendTeamMessage(const QString &)), hwnet, SLOT(SendTeamMessage(const QString &)));
  1746     connect(game, SIGNAL(SendTeamMessage(const QString &)), hwnet, SLOT(SendTeamMessage(const QString &)));
  1715     connect(hwnet, SIGNAL(FromNet(const QByteArray &)), game, SLOT(FromNet(const QByteArray &)), Qt::QueuedConnection);
       
  1716     connect(hwnet, SIGNAL(chatStringFromNet(const QString &)), game, SLOT(FromNetChat(const QString &)), Qt::QueuedConnection);
  1747     connect(hwnet, SIGNAL(chatStringFromNet(const QString &)), game, SLOT(FromNetChat(const QString &)), Qt::QueuedConnection);
  1717 
  1748 
  1718     game->StartNet();
  1749     game->StartNet();
  1719 }
  1750 }
  1720 
  1751 
  1738         SDLInteraction::instance().stopMusic();
  1769         SDLInteraction::instance().stopMusic();
  1739 }
  1770 }
  1740 
  1771 
  1741 void HWForm::NetGameChangeStatus(bool isMaster)
  1772 void HWForm::NetGameChangeStatus(bool isMaster)
  1742 {
  1773 {
  1743     ui.pageNetGame->pGameCFG->setMaster(isMaster);
       
  1744     ui.pageNetGame->pNetTeamsWidget->setInteractivity(isMaster);
       
  1745 
       
  1746     if (isMaster)
  1774     if (isMaster)
  1747         NetGameMaster();
  1775         NetGameMaster();
  1748     else
  1776     else
  1749         NetGameSlave();
  1777         NetGameSlave();
  1750 }
  1778 }
  1792 
  1820 
  1793     if (hwnet)
  1821     if (hwnet)
  1794     {
  1822     {
  1795         NetAmmoSchemeModel * netAmmo = new NetAmmoSchemeModel(hwnet);
  1823         NetAmmoSchemeModel * netAmmo = new NetAmmoSchemeModel(hwnet);
  1796         connect(hwnet, SIGNAL(netSchemeConfig(QStringList &)), netAmmo, SLOT(setNetSchemeConfig(QStringList &)));
  1824         connect(hwnet, SIGNAL(netSchemeConfig(QStringList &)), netAmmo, SLOT(setNetSchemeConfig(QStringList &)));
       
  1825 
  1797         ui.pageNetGame->pGameCFG->GameSchemes->setModel(netAmmo);
  1826         ui.pageNetGame->pGameCFG->GameSchemes->setModel(netAmmo);
  1798 
  1827 
  1799         ui.pageNetGame->setRoomName(hwnet->getRoom());
  1828         ui.pageNetGame->setRoomName(hwnet->getRoom());
  1800 
  1829 
  1801         ui.pageNetGame->pGameCFG->GameSchemes->view()->disconnect(hwnet);
  1830         ui.pageNetGame->pGameCFG->GameSchemes->view()->disconnect(hwnet);
  1802         connect(hwnet, SIGNAL(netSchemeConfig(QStringList &)),
  1831         connect(hwnet, SIGNAL(netSchemeConfig(QStringList &)),
  1803                 this, SLOT(selectFirstNetScheme()));
  1832                 this, SLOT(selectFirstNetScheme()));
  1804     }
  1833     }
  1805 
  1834 
  1806     ui.pageNetGame->setMasterMode(false);
  1835     ui.pageNetGame->setMasterMode(false);
       
  1836 }
       
  1837 
       
  1838 void HWForm::FromNetProxySlot(const QByteArray & msg)
       
  1839 {
       
  1840     if(game)
       
  1841         game->FromNet(msg);
       
  1842 
  1807 }
  1843 }
  1808 
  1844 
  1809 void HWForm::selectFirstNetScheme()
  1845 void HWForm::selectFirstNetScheme()
  1810 {
  1846 {
  1811     ui.pageNetGame->pGameCFG->GameSchemes->setCurrentIndex(0);
  1847     ui.pageNetGame->pGameCFG->GameSchemes->setCurrentIndex(0);
  2000         }
  2036         }
  2001         while(!fileName.isEmpty() && !ok);
  2037         while(!fileName.isEmpty() && !ok);
  2002     }
  2038     }
  2003 }
  2039 }
  2004 
  2040 
       
  2041 void HWForm::restartGame()
       
  2042 {
       
  2043     // get rid off old game stats page
       
  2044     if(ui.Pages->currentIndex() == ID_PAGE_GAMESTATS)
       
  2045         GoBack();
       
  2046 
       
  2047     CreateGame(lastGameCfg, lastGameTeamSel, lastGameAmmo);
       
  2048 
       
  2049     switch(lastGameType) {
       
  2050     case gtTraining:
       
  2051         game->StartTraining(lastGameStartArgs.at(0).toString());
       
  2052         break;
       
  2053     case gtQLocal:
       
  2054         game->StartQuick();
       
  2055         break;
       
  2056     case gtCampaign:
       
  2057         game->StartCampaign(lastGameStartArgs.at(0).toString(), lastGameStartArgs.at(1).toString(), lastGameStartArgs.at(2).toString());
       
  2058         break;
       
  2059     case gtLocal:
       
  2060         game->StartLocal();
       
  2061         break;
       
  2062     default:
       
  2063         break;
       
  2064     }
       
  2065 }
  2005 
  2066 
  2006 void HWForm::ShowErrorMessage(const QString & msg)
  2067 void HWForm::ShowErrorMessage(const QString & msg)
  2007 {
  2068 {
  2008     MessageDialog::ShowErrorMessage(msg, this);
  2069     MessageDialog::ShowErrorMessage(msg, this);
  2009 }
  2070 }
  2010 
  2071 
  2011 void HWForm::showFeedbackDialog()
  2072 void HWForm::showFeedbackDialog()
  2012 {
  2073 {
  2013     FeedbackDialog dialog(this);
  2074     QNetworkRequest newRequest(QUrl("http://www.hedgewars.org"));
  2014     dialog.exec();
  2075 
       
  2076     QNetworkAccessManager *manager = new QNetworkAccessManager(this);
       
  2077     QNetworkReply *reply = manager->get(newRequest);
       
  2078     connect(reply, SIGNAL(finished()), this, SLOT(showFeedbackDialogNetChecked()));
       
  2079 }
       
  2080 
       
  2081 void HWForm::showFeedbackDialogNetChecked()
       
  2082 {
       
  2083     QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
       
  2084 
       
  2085     if (reply && (reply->error() == QNetworkReply::NoError)) {
       
  2086         FeedbackDialog dialog(this);
       
  2087         dialog.exec();
       
  2088     } else
       
  2089         MessageDialog::ShowErrorMessage(tr("This page requires an internet connection."), this);
  2015 }
  2090 }
  2016 
  2091 
  2017 void HWForm::startGame()
  2092 void HWForm::startGame()
  2018 {
  2093 {
  2019     QMessageBox questionMsg(this);
  2094     QMessageBox questionMsg(this);