QTfrontend/hwform.cpp
changeset 8179 a1ffcb559f99
parent 8157 695f1eef72c8
child 8181 70e980278080
equal deleted inserted replaced
8178:8bd087478b48 8179:a1ffcb559f99
   109 // and this one flag does not warrant a static class
   109 // and this one flag does not warrant a static class
   110 bool frontendEffects = true;
   110 bool frontendEffects = true;
   111 QString playerHash;
   111 QString playerHash;
   112 
   112 
   113 GameUIConfig* HWForm::config = NULL;
   113 GameUIConfig* HWForm::config = NULL;
   114 QSettings* HWForm::gameSettings = NULL;
       
   115 
   114 
   116 HWForm::HWForm(QWidget *parent, QString styleSheet)
   115 HWForm::HWForm(QWidget *parent, QString styleSheet)
   117     : QMainWindow(parent)
   116     : QMainWindow(parent)
   118     , game(0)
   117     , game(0)
   119     , pnetserver(0)
   118     , pnetserver(0)
   125     SDLInteraction::instance().setMusicTrack("/Music/main_theme.ogg");
   124     SDLInteraction::instance().setMusicTrack("/Music/main_theme.ogg");
   126 
   125 
   127 #ifdef USE_XFIRE
   126 #ifdef USE_XFIRE
   128     xfire_init();
   127     xfire_init();
   129 #endif
   128 #endif
   130     gameSettings = new QSettings("physfs://hedgewars.ini", QSettings::IniFormat);
       
   131     frontendEffects = gameSettings->value("frontend/effects", true).toBool();
       
   132     playerHash = QString(QCryptographicHash::hash(gameSettings->value("net/nick","").toString().toUtf8(), QCryptographicHash::Md5).toHex());
       
   133 
       
   134     this->setStyleSheet(styleSheet);
   129     this->setStyleSheet(styleSheet);
   135     ui.setupUi(this);
   130     ui.setupUi(this);
   136     setMinimumSize(760, 580);
   131     setMinimumSize(760, 580);
   137     //setFocusPolicy(Qt::StrongFocus);
   132     //setFocusPolicy(Qt::StrongFocus);
   138     CustomizePalettes();
   133     CustomizePalettes();
   139 
   134 
   140     ui.pageOptions->CBResolution->addItems(SDLInteraction::instance().getResolutions());
   135     ui.pageOptions->CBResolution->addItems(SDLInteraction::instance().getResolutions());
   141 
   136 
   142     config = new GameUIConfig(this, "physfs://hedgewars.ini");
   137     config = new GameUIConfig(this, "physfs://hedgewars.ini");
   143 
   138     frontendEffects = config->value("frontend/effects", true).toBool();
       
   139     playerHash = QString(QCryptographicHash::hash(config->value("net/nick","").toString().toUtf8(), QCryptographicHash::Md5).toHex());
       
   140 
       
   141     ui.pageRoomsList->setSettings(config);
       
   142     ui.pageNetGame->chatWidget->setSettings(config);
       
   143     ui.pageRoomsList->chatWidget->setSettings(config);
   144     ui.pageVideos->init(config);
   144     ui.pageVideos->init(config);
   145 
   145 
   146 #ifdef __APPLE__
   146 #ifdef __APPLE__
   147     panel = new M3Panel;
   147     panel = new M3Panel;
   148 
   148 
   443 {
   443 {
   444     QStringList teamslist = config->GetTeamsList();
   444     QStringList teamslist = config->GetTeamsList();
   445 
   445 
   446     if(teamslist.empty())
   446     if(teamslist.empty())
   447     {
   447     {
   448         QString currentNickName = gameSettings->value("net/nick","").toString().toUtf8();
   448         QString currentNickName = config->value("net/nick","").toString().toUtf8();
   449         QString teamName;
   449         QString teamName;
   450 
   450 
   451         if (currentNickName.isEmpty())
   451         if (currentNickName.isEmpty())
   452         {
   452         {
   453             teamName = tr("DefaultTeam");
   453             teamName = tr("DefaultTeam");
   612     }
   612     }
   613 
   613 
   614     if (id == ID_PAGE_MAIN)
   614     if (id == ID_PAGE_MAIN)
   615     {
   615     {
   616         ui.pageOptions->setTeamOptionsEnabled(true);
   616         ui.pageOptions->setTeamOptionsEnabled(true);
   617     }
       
   618 
       
   619     if (id == ID_PAGE_SETUP)
       
   620     {
       
   621         config->reloadValues();
       
   622     }
       
   623 
       
   624     if (id == ID_PAGE_VIDEOS )
       
   625     {
       
   626         config->reloadVideosValues();
       
   627     }
   617     }
   628 }
   618 }
   629 
   619 
   630 void HWForm::GoToPage(int id)
   620 void HWForm::GoToPage(int id)
   631 {
   621 {
   968 }
   958 }
   969 
   959 
   970 void HWForm::NetPassword(const QString & nick)
   960 void HWForm::NetPassword(const QString & nick)
   971 {
   961 {
   972     int passLength = config->value("net/passwordlength", 0).toInt();
   962     int passLength = config->value("net/passwordlength", 0).toInt();
   973     QString hash = config->value("net/passwordhash", "").toString();
   963     QString hash = QString::fromLatin1(config->value("net/passwordhash", "").toByteArray());
   974 
   964 
   975     // If the password is blank, ask the user to enter one in
   965     // If the password is blank, ask the user to enter one in
   976     if (passLength == 0)
   966     if (passLength == 0)
   977     {
   967     {
   978         HWPasswordDialog * hpd = new HWPasswordDialog(this, tr("Your nickname %1 is\nregistered on Hedgewars.org\nPlease provide your password below\nor pick another nickname in game config:").arg(nick));
   968         HWPasswordDialog hpd(this, tr("Your nickname %1 is\nregistered on Hedgewars.org\nPlease provide your password below\nor pick another nickname in game config:").arg(nick));
   979         hpd->cbSave->setChecked(config->value("net/savepassword", true).toBool());
   969         hpd.cbSave->setChecked(config->value("net/savepassword", true).toBool());
   980         if (hpd->exec() != QDialog::Accepted)
   970         if (hpd.exec() != QDialog::Accepted)
   981         {
   971         {
   982             ForcedDisconnect(tr("No password supplied."));
   972             ForcedDisconnect(tr("No password supplied."));
   983             delete hpd;
       
   984             return;
   973             return;
   985         }
   974         }
   986 
   975 
   987         QString password = hpd->lePassword->text();
   976         QString password = hpd.lePassword->text();
   988         hash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex();
   977         hash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex();
   989 
   978 
   990         bool save = hpd->cbSave->isChecked();
   979         bool save = hpd.cbSave->isChecked();
   991         config->setValue("net/savepassword", save);
   980         config->setValue("net/savepassword", save);
   992         if (save) // user wants to save password
   981         if (save) // user wants to save password
   993         {
   982         {
   994             config->setValue("net/passwordhash", hash);
   983             config->setValue("net/passwordhash", hash.toLatin1());
   995             config->setValue("net/passwordlength", password.size());
   984             config->setValue("net/passwordlength", password.size());
   996             config->setNetPasswordLength(password.size());
   985             config->setNetPasswordLength(password.size());
   997         }
   986             config->sync();
   998 
   987         }
   999         delete hpd;
       
  1000     }
   988     }
  1001 
   989 
  1002     hwnet->SendPasswordHash(hash);
   990     hwnet->SendPasswordHash(hash);
  1003 }
   991 }
  1004 
   992 
  1082     connect(hwnet, SIGNAL(NickTaken(const QString&)), this, SLOT(NetNickTaken(const QString&)), Qt::QueuedConnection);
  1070     connect(hwnet, SIGNAL(NickTaken(const QString&)), this, SLOT(NetNickTaken(const QString&)), Qt::QueuedConnection);
  1083     connect(hwnet, SIGNAL(AuthFailed()), this, SLOT(NetAuthFailed()), Qt::QueuedConnection);
  1071     connect(hwnet, SIGNAL(AuthFailed()), this, SLOT(NetAuthFailed()), Qt::QueuedConnection);
  1084     //connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom()));
  1072     //connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom()));
  1085 
  1073 
  1086     ui.pageRoomsList->chatWidget->setUsersModel(hwnet->lobbyPlayersModel());
  1074     ui.pageRoomsList->chatWidget->setUsersModel(hwnet->lobbyPlayersModel());
  1087     ui.pageNetGame->pChatWidget->setUsersModel(hwnet->roomPlayersModel());
  1075     ui.pageNetGame->chatWidget->setUsersModel(hwnet->roomPlayersModel());
  1088 
  1076 
  1089 // rooms list page stuff
  1077 // rooms list page stuff
  1090     ui.pageRoomsList->setModel(hwnet->roomsListModel());
  1078     ui.pageRoomsList->setModel(hwnet->roomsListModel());
  1091     connect(hwnet, SIGNAL(adminAccess(bool)),
  1079     connect(hwnet, SIGNAL(adminAccess(bool)),
  1092             ui.pageRoomsList, SLOT(setAdmin(bool)), Qt::QueuedConnection);
  1080             ui.pageRoomsList, SLOT(setAdmin(bool)), Qt::QueuedConnection);
  1111     connect(hwnet, SIGNAL(roomMaster(bool)),
  1099     connect(hwnet, SIGNAL(roomMaster(bool)),
  1112             this, SLOT(NetGameChangeStatus(bool)), Qt::QueuedConnection);
  1100             this, SLOT(NetGameChangeStatus(bool)), Qt::QueuedConnection);
  1113 
  1101 
  1114 // net page stuff
  1102 // net page stuff
  1115     connect(hwnet, SIGNAL(chatStringFromNet(const QString&)),
  1103     connect(hwnet, SIGNAL(chatStringFromNet(const QString&)),
  1116             ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
  1104             ui.pageNetGame->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
  1117 
  1105 
  1118     connect(hwnet, SIGNAL(chatStringFromMe(const QString&)),
  1106     connect(hwnet, SIGNAL(chatStringFromMe(const QString&)),
  1119             ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
  1107             ui.pageNetGame->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
  1120     connect(hwnet, SIGNAL(roomMaster(bool)),
  1108     connect(hwnet, SIGNAL(roomMaster(bool)),
  1121             ui.pageNetGame->pChatWidget, SLOT(adminAccess(bool)), Qt::QueuedConnection);
  1109             ui.pageNetGame->chatWidget, SLOT(adminAccess(bool)), Qt::QueuedConnection);
  1122     connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)),
  1110     connect(ui.pageNetGame->chatWidget, SIGNAL(chatLine(const QString&)),
  1123             hwnet, SLOT(chatLineToNet(const QString&)));
  1111             hwnet, SLOT(chatLineToNet(const QString&)));
  1124     connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady()));
  1112     connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady()));
  1125     connect(hwnet, SIGNAL(setMyReadyStatus(bool)),
  1113     connect(hwnet, SIGNAL(setMyReadyStatus(bool)),
  1126             ui.pageNetGame, SLOT(setReadyStatus(bool)), Qt::QueuedConnection);
  1114             ui.pageNetGame, SLOT(setReadyStatus(bool)), Qt::QueuedConnection);
  1127 
  1115 
  1128 // chat widget actions
  1116 // chat widget actions
  1129     connect(ui.pageNetGame->pChatWidget, SIGNAL(kick(const QString&)),
  1117     connect(ui.pageNetGame->chatWidget, SIGNAL(kick(const QString&)),
  1130             hwnet, SLOT(kickPlayer(const QString&)));
  1118             hwnet, SLOT(kickPlayer(const QString&)));
  1131     connect(ui.pageNetGame->pChatWidget, SIGNAL(ban(const QString&)),
  1119     connect(ui.pageNetGame->chatWidget, SIGNAL(ban(const QString&)),
  1132             hwnet, SLOT(banPlayer(const QString&)));
  1120             hwnet, SLOT(banPlayer(const QString&)));
  1133     connect(ui.pageNetGame->pChatWidget, SIGNAL(info(const QString&)),
  1121     connect(ui.pageNetGame->chatWidget, SIGNAL(info(const QString&)),
  1134             hwnet, SLOT(infoPlayer(const QString&)));
  1122             hwnet, SLOT(infoPlayer(const QString&)));
  1135     connect(ui.pageNetGame->pChatWidget, SIGNAL(follow(const QString&)),
  1123     connect(ui.pageNetGame->chatWidget, SIGNAL(follow(const QString&)),
  1136             hwnet, SLOT(followPlayer(const QString&)));
  1124             hwnet, SLOT(followPlayer(const QString&)));
  1137     connect(ui.pageRoomsList->chatWidget, SIGNAL(kick(const QString&)),
  1125     connect(ui.pageRoomsList->chatWidget, SIGNAL(kick(const QString&)),
  1138             hwnet, SLOT(kickPlayer(const QString&)));
  1126             hwnet, SLOT(kickPlayer(const QString&)));
  1139     connect(ui.pageRoomsList->chatWidget, SIGNAL(ban(const QString&)),
  1127     connect(ui.pageRoomsList->chatWidget, SIGNAL(ban(const QString&)),
  1140             hwnet, SLOT(banPlayer(const QString&)));
  1128             hwnet, SLOT(banPlayer(const QString&)));
  1153     connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)),
  1141     connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)),
  1154             ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
  1142             ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
  1155 
  1143 
  1156 // nick list stuff
  1144 // nick list stuff
  1157     connect(hwnet, SIGNAL(nickAdded(const QString&, bool)),
  1145     connect(hwnet, SIGNAL(nickAdded(const QString&, bool)),
  1158             ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection);
  1146             ui.pageNetGame->chatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection);
  1159     connect(hwnet, SIGNAL(nickRemoved(const QString&)),
  1147     connect(hwnet, SIGNAL(nickRemoved(const QString&)),
  1160             ui.pageNetGame->pChatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection);
  1148             ui.pageNetGame->chatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection);
  1161     connect(hwnet, SIGNAL(nickAddedLobby(const QString&, bool)),
  1149     connect(hwnet, SIGNAL(nickAddedLobby(const QString&, bool)),
  1162             ui.pageRoomsList->chatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection);
  1150             ui.pageRoomsList->chatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection);
  1163     connect(hwnet, SIGNAL(nickRemovedLobby(const QString&)),
  1151     connect(hwnet, SIGNAL(nickRemovedLobby(const QString&)),
  1164             ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection);
  1152             ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection);
  1165 
  1153 
  1301     GoToPage(ID_PAGE_ROOMSLIST);
  1289     GoToPage(ID_PAGE_ROOMSLIST);
  1302 }
  1290 }
  1303 
  1291 
  1304 void HWForm::NetGameEnter()
  1292 void HWForm::NetGameEnter()
  1305 {
  1293 {
  1306     ui.pageNetGame->pChatWidget->clear();
  1294     ui.pageNetGame->chatWidget->clear();
  1307     GoToPage(ID_PAGE_NETGAME);
  1295     GoToPage(ID_PAGE_NETGAME);
  1308 }
  1296 }
  1309 
  1297 
  1310 void HWForm::AddNetTeam(const HWTeam& team)
  1298 void HWForm::AddNetTeam(const HWTeam& team)
  1311 {
  1299 {