125 SDLInteraction::instance().setMusicTrack("/Music/main_theme.ogg"); |
138 SDLInteraction::instance().setMusicTrack("/Music/main_theme.ogg"); |
126 |
139 |
127 #ifdef USE_XFIRE |
140 #ifdef USE_XFIRE |
128 xfire_init(); |
141 xfire_init(); |
129 #endif |
142 #endif |
130 gameSettings = new QSettings(cfgdir->absolutePath() + "/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); |
143 this->setStyleSheet(styleSheet); |
135 ui.setupUi(this); |
144 ui.setupUi(this); |
136 setMinimumSize(760, 580); |
145 setMinimumSize(760, 580); |
137 //setFocusPolicy(Qt::StrongFocus); |
146 //setFocusPolicy(Qt::StrongFocus); |
138 CustomizePalettes(); |
147 CustomizePalettes(); |
139 |
148 |
140 ui.pageOptions->CBResolution->addItems(SDLInteraction::instance().getResolutions()); |
149 ui.pageOptions->CBResolution->addItems(SDLInteraction::instance().getResolutions()); |
141 |
150 |
142 config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini"); |
151 config = new GameUIConfig(this, "physfs://hedgewars.ini"); |
143 |
152 frontendEffects = config->value("frontend/effects", true).toBool(); |
|
153 playerHash = QString(QCryptographicHash::hash(config->value("net/nick","").toString().toUtf8(), QCryptographicHash::Md5).toHex()); |
|
154 |
|
155 ui.pageRoomsList->setSettings(config); |
|
156 ui.pageNetGame->chatWidget->setSettings(config); |
|
157 ui.pageRoomsList->chatWidget->setSettings(config); |
|
158 #ifdef VIDEOREC |
144 ui.pageVideos->init(config); |
159 ui.pageVideos->init(config); |
|
160 ui.pageOptions->setConfig(config); |
|
161 #endif |
|
162 |
|
163 #ifdef __APPLE__ |
|
164 AutoUpdater* updater = NULL; |
|
165 if (config->isAutoUpdateEnabled()) |
|
166 { |
|
167 #ifdef __APPLE__ |
|
168 #ifdef SPARKLE_ENABLED |
|
169 updater = new SparkleAutoUpdater(); |
|
170 #endif |
|
171 #endif |
|
172 if (updater) |
|
173 { |
|
174 updater->checkForUpdates(); |
|
175 delete updater; |
|
176 } |
|
177 } |
|
178 #endif |
145 |
179 |
146 #ifdef __APPLE__ |
180 #ifdef __APPLE__ |
147 panel = new M3Panel; |
181 panel = new M3Panel; |
148 |
|
149 #ifdef SPARKLE_ENABLED |
|
150 AutoUpdater* updater; |
|
151 |
|
152 updater = new SparkleAutoUpdater(); |
|
153 if (updater && config->isAutoUpdateEnabled()) |
|
154 updater->checkForUpdates(); |
|
155 #endif |
|
156 |
182 |
157 QShortcut *hideFrontend = new QShortcut(QKeySequence("Ctrl+M"), this); |
183 QShortcut *hideFrontend = new QShortcut(QKeySequence("Ctrl+M"), this); |
158 connect (hideFrontend, SIGNAL(activated()), this, SLOT(showMinimized())); |
184 connect (hideFrontend, SIGNAL(activated()), this, SLOT(showMinimized())); |
159 #else |
185 #else |
160 // ctrl+q closes frontend for consistency |
186 // ctrl+q closes frontend for consistency |
188 pageSwitchMapper->setMapping(ui.pageMain->BtnSetup, ID_PAGE_SETUP); |
214 pageSwitchMapper->setMapping(ui.pageMain->BtnSetup, ID_PAGE_SETUP); |
189 |
215 |
190 connect(ui.pageMain->BtnFeedback, SIGNAL(clicked()), pageSwitchMapper, SLOT(map())); |
216 connect(ui.pageMain->BtnFeedback, SIGNAL(clicked()), pageSwitchMapper, SLOT(map())); |
191 pageSwitchMapper->setMapping(ui.pageMain->BtnFeedback, ID_PAGE_FEEDBACK); |
217 pageSwitchMapper->setMapping(ui.pageMain->BtnFeedback, ID_PAGE_FEEDBACK); |
192 |
218 |
193 connect(ui.pageMain->BtnNet, SIGNAL(clicked()), pageSwitchMapper, SLOT(map())); |
|
194 pageSwitchMapper->setMapping(ui.pageMain->BtnNet, ID_PAGE_NETTYPE); |
|
195 |
|
196 connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), pageSwitchMapper, SLOT(map())); |
219 connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), pageSwitchMapper, SLOT(map())); |
197 pageSwitchMapper->setMapping(ui.pageMain->BtnInfo, ID_PAGE_INFO); |
220 pageSwitchMapper->setMapping(ui.pageMain->BtnInfo, ID_PAGE_INFO); |
198 |
221 |
199 connect(ui.pageMain->BtnDataDownload, SIGNAL(clicked()), pageSwitchMapper, SLOT(map())); |
222 connect(ui.pageMain->BtnDataDownload, SIGNAL(clicked()), pageSwitchMapper, SLOT(map())); |
200 pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD); |
223 pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD); |
529 void HWForm::OnPageShown(quint8 id, quint8 lastid) |
556 void HWForm::OnPageShown(quint8 id, quint8 lastid) |
530 { |
557 { |
531 #ifdef USE_XFIRE |
558 #ifdef USE_XFIRE |
532 updateXfire(); |
559 updateXfire(); |
533 #endif |
560 #endif |
|
561 |
|
562 QString openPrefix = "Debug: (PAGE_OPENED: "; |
|
563 QString openSuffix = ")"; |
|
564 QString closePrefix = "Debug: (PAGE_LEFT: "; |
|
565 QString closeSuffix = ")"; |
|
566 |
|
567 switch (lastid) { //Print the id of the page we're leaving |
|
568 case ID_PAGE_SETUP_TEAM : qDebug("%sPAGE_SETUP_TEAM%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
569 case ID_PAGE_SETUP : qDebug("%sPAGE_SETUP%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
570 case ID_PAGE_MULTIPLAYER : qDebug("%sPAGE_MULTIPLAYER%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
571 case ID_PAGE_DEMOS : qDebug("%sPAGE_DEMOS%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
572 case ID_PAGE_NET : qDebug("%sPAGE_NET%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
573 case ID_PAGE_NETGAME : qDebug("%sPAGE_NETGAME%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
574 case ID_PAGE_INFO : qDebug("%sPAGE_INFO%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
575 case ID_PAGE_MAIN : qDebug("%sPAGE_MAIN%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
576 case ID_PAGE_GAMESTATS : qDebug("%sPAGE_GAMESTATS%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
577 case ID_PAGE_SINGLEPLAYER : qDebug("%sPAGE_SINGLEPLAYER%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
578 case ID_PAGE_TRAINING : qDebug("%sPAGE_TRAINING%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
579 case ID_PAGE_SELECTWEAPON : qDebug("%sPAGE_SELECTWEAPON%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
580 case ID_PAGE_NETSERVER : qDebug("%sPAGE_NETSERVER%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
581 case ID_PAGE_INGAME : qDebug("%sPAGE_INGAME%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
582 case ID_PAGE_ROOMSLIST : qDebug("%sPAGE_ROOMSLIST%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
583 case ID_PAGE_CONNECTING : qDebug("%sPAGE_CONNECTING%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
584 case ID_PAGE_SCHEME : qDebug("%sPAGE_SCHEME%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
585 case ID_PAGE_ADMIN : qDebug("%sPAGE_ADMIN%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
586 case ID_PAGE_CAMPAIGN : qDebug("%sPAGE_CAMPAIGN%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
587 case ID_PAGE_DRAWMAP : qDebug("%sPAGE_DRAWMAP%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
588 case ID_PAGE_DATADOWNLOAD : qDebug("%sPAGE_DATADOWNLOAD%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
589 case ID_PAGE_FEEDBACK : qDebug("%sPAGE_FEEDBACK%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
590 case ID_PAGE_VIDEOS : qDebug("%sPAGE_VIDEOS%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
591 case MAX_PAGE : qDebug("%sMAX_PAGE%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
592 default : qDebug("%sUNKNOWN PAGE%s", qPrintable(closePrefix), qPrintable(closeSuffix)); break; |
|
593 } //end switch(lastid) |
|
594 switch (id) { //Print the id of the opened page |
|
595 case ID_PAGE_SETUP_TEAM : qDebug("%sPAGE_SETUP_TEAM%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
596 case ID_PAGE_SETUP : qDebug("%sPAGE_SETUP%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
597 case ID_PAGE_MULTIPLAYER : qDebug("%sPAGE_MULTIPLAYER%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
598 case ID_PAGE_DEMOS : qDebug("%sPAGE_DEMOS%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
599 case ID_PAGE_NET : qDebug("%sPAGE_NET%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
600 case ID_PAGE_NETGAME : qDebug("%sPAGE_NETGAME%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
601 case ID_PAGE_INFO : qDebug("%sPAGE_INFO%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
602 case ID_PAGE_MAIN : qDebug("%sPAGE_MAIN%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
603 case ID_PAGE_GAMESTATS : qDebug("%sPAGE_GAMESTATS%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
604 case ID_PAGE_SINGLEPLAYER : qDebug("%sPAGE_SINGLEPLAYER%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
605 case ID_PAGE_TRAINING : qDebug("%sPAGE_TRAINING%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
606 case ID_PAGE_SELECTWEAPON : qDebug("%sPAGE_SELECTWEAPON%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
607 case ID_PAGE_NETSERVER : qDebug("%sPAGE_NETSERVER%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
608 case ID_PAGE_INGAME : qDebug("%sPAGE_INGAME%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
609 case ID_PAGE_ROOMSLIST : qDebug("%sPAGE_ROOMSLIST%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
610 case ID_PAGE_CONNECTING : qDebug("%sPAGE_CONNECTING%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
611 case ID_PAGE_SCHEME : qDebug("%sPAGE_SCHEME%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
612 case ID_PAGE_ADMIN : qDebug("%sPAGE_ADMIN%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
613 case ID_PAGE_CAMPAIGN : qDebug("%sPAGE_CAMPAIGN%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
614 case ID_PAGE_DRAWMAP : qDebug("%sPAGE_DRAWMAP%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
615 case ID_PAGE_DATADOWNLOAD : qDebug("%sPAGE_DATADOWNLOAD%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
616 case ID_PAGE_FEEDBACK : qDebug("%sPAGE_FEEDBACK%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
617 case ID_PAGE_VIDEOS : qDebug("%sPAGE_VIDEOS%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
618 case MAX_PAGE : qDebug("%sMAX_PAGE%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
619 default : qDebug("%sUNKNOWN PAGE%s", qPrintable(openPrefix), qPrintable(openSuffix)); break; |
|
620 } //end switch(id) |
|
621 |
534 if (id == ID_PAGE_DATADOWNLOAD) |
622 if (id == ID_PAGE_DATADOWNLOAD) |
535 { |
623 { |
536 ui.pageDataDownload->fetchList(); |
624 ui.pageDataDownload->fetchList(); |
537 } |
625 } |
538 if (id == ID_PAGE_DRAWMAP) |
626 if (id == ID_PAGE_DRAWMAP) |
963 NetConnectServer("netserver.hedgewars.org", 46631); |
1046 NetConnectServer("netserver.hedgewars.org", 46631); |
964 } |
1047 } |
965 |
1048 |
966 void HWForm::NetPassword(const QString & nick) |
1049 void HWForm::NetPassword(const QString & nick) |
967 { |
1050 { |
968 int passLength = config->value("net/passwordlength", 0).toInt(); |
1051 //Get hashes |
969 QString hash = config->value("net/passwordhash", "").toString(); |
1052 QString hash = config->passwordHash(); |
970 |
1053 QString temphash = config->tempHash(); |
971 // If the password is blank, ask the user to enter one in |
1054 |
972 if (passLength == 0) |
1055 //Check them |
973 { |
1056 |
974 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)); |
1057 if (temphash.isEmpty() && hash.isEmpty()) { //If the user enters a registered nick with no password, sends a bogus hash |
975 hpd->cbSave->setChecked(config->value("net/savepassword", true).toBool()); |
1058 hwnet->SendPasswordHash("THISISNOHASH"); |
976 if (hpd->exec() != QDialog::Accepted) |
1059 } |
977 { |
1060 else if (temphash.isEmpty()) { //Send saved hash as default |
978 ForcedDisconnect(tr("No password supplied.")); |
1061 hwnet->SendPasswordHash(hash); |
979 delete hpd; |
1062 } |
980 return; |
1063 else { //Send the hash |
981 } |
1064 hwnet->SendPasswordHash(temphash); |
982 |
1065 } |
983 QString password = hpd->lePassword->text(); |
1066 |
984 hash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex(); |
1067 //Remove temporary hash from config |
985 |
1068 config->clearTempHash(); |
986 bool save = hpd->cbSave->isChecked(); |
1069 } |
987 config->setValue("net/savepassword", save); |
1070 |
988 if (save) // user wants to save password |
1071 void HWForm::NetNickRegistered(const QString & nick) |
989 { |
1072 { |
990 config->setValue("net/passwordhash", hash); |
1073 //Get hashes |
991 config->setValue("net/passwordlength", password.size()); |
1074 QString hash = config->passwordHash(); |
992 config->setNetPasswordLength(password.size()); |
1075 QString temphash = config->tempHash(); |
993 } |
1076 |
994 |
1077 if (hash.isEmpty()) { |
995 delete hpd; |
1078 if (temphash.isEmpty()) { //If the user enters a registered nick with no password |
996 } |
1079 QString suppliedpass; |
997 |
1080 while (suppliedpass.isEmpty()) { |
998 hwnet->SendPasswordHash(hash); |
1081 QInputDialog nickRegedDialog(this); |
|
1082 nickRegedDialog.setWindowModality(Qt::WindowModal); |
|
1083 nickRegedDialog.setInputMode(QInputDialog::TextInput); |
|
1084 nickRegedDialog.setWindowTitle(tr("Hedgewars - Nick registered")); |
|
1085 nickRegedDialog.setLabelText(tr("This nick is registered, and you haven't specified a password.\n\nIf this nick isn't yours, please register your own nick at www.hedgewars.org\n\nPassword:")); |
|
1086 nickRegedDialog.setTextEchoMode(QLineEdit::Password); |
|
1087 nickRegedDialog.exec(); |
|
1088 |
|
1089 suppliedpass = nickRegedDialog.textValue(); |
|
1090 |
|
1091 if (nickRegedDialog.result() == QDialog::Rejected) { |
|
1092 config->clearPasswordHash(); |
|
1093 config->clearTempHash(); |
|
1094 GoBack(); |
|
1095 return; |
|
1096 } |
|
1097 temphash = QCryptographicHash::hash(suppliedpass.toUtf8(), QCryptographicHash::Md5).toHex(); |
|
1098 config->setTempHash(temphash); |
|
1099 } |
|
1100 } |
|
1101 } |
|
1102 NetPassword(nick); |
|
1103 } |
|
1104 |
|
1105 void HWForm::NetNickNotRegistered(const QString & nick) |
|
1106 { |
|
1107 QMessageBox noRegMsg(this); |
|
1108 noRegMsg.setIcon(QMessageBox::Information); |
|
1109 noRegMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Nick not registered")); |
|
1110 noRegMsg.setWindowModality(Qt::WindowModal); |
|
1111 noRegMsg.setText(tr("Your nickname is not registered.\nTo prevent someone else from using it,\nplease register it at www.hedgewars.org")); |
|
1112 |
|
1113 if (!config->passwordHash().isEmpty()) |
|
1114 { |
|
1115 config->clearPasswordHash(); |
|
1116 noRegMsg.setText(noRegMsg.text()+tr("\n\nYour password wasn't saved either.")); |
|
1117 } |
|
1118 if (!config->tempHash().isEmpty()) |
|
1119 { |
|
1120 config->clearTempHash(); |
|
1121 } |
|
1122 noRegMsg.exec(); |
999 } |
1123 } |
1000 |
1124 |
1001 void HWForm::NetNickTaken(const QString & nick) |
1125 void HWForm::NetNickTaken(const QString & nick) |
1002 { |
1126 { |
1003 bool ok = false; |
1127 bool ok = false; |
1004 QString newNick = QInputDialog::getText(this, tr("Nickname"), tr("Someone already uses your nickname %1 on the server.\nPlease pick another nickname:").arg(nick), QLineEdit::Normal, nick, &ok); |
1128 QString newNick = QInputDialog::getText(this, tr("Nickname"), tr("Someone already uses your nickname %1 on the server.\nPlease pick another nickname:").arg(nick), QLineEdit::Normal, nick, &ok); |
1005 |
1129 |
1006 if (!ok || newNick.isEmpty()) |
1130 if (!ok || newNick.isEmpty()) |
1007 { |
1131 { |
1008 ForcedDisconnect(tr("No nickname supplied.")); |
1132 //ForcedDisconnect(tr("No nickname supplied.")); |
|
1133 bool retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied.")); |
|
1134 GoBack(); |
|
1135 if (retry) { |
|
1136 NetConnectOfficialServer(); |
|
1137 } |
1009 return; |
1138 return; |
1010 } |
1139 } |
1011 |
1140 |
1012 hwnet->NewNick(newNick); |
1141 hwnet->NewNick(newNick); |
1013 config->setValue("net/nick", newNick); |
1142 config->setValue("net/nick", newNick); |
1072 connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()), Qt::QueuedConnection); |
1232 connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()), Qt::QueuedConnection); |
1073 connect(hwnet, SIGNAL(LeftRoom(const QString&)), this, SLOT(NetLeftRoom(const QString&)), Qt::QueuedConnection); |
1233 connect(hwnet, SIGNAL(LeftRoom(const QString&)), this, SLOT(NetLeftRoom(const QString&)), Qt::QueuedConnection); |
1074 connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(const HWTeam&)), Qt::QueuedConnection); |
1234 connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(const HWTeam&)), Qt::QueuedConnection); |
1075 connect(hwnet, SIGNAL(RemoveNetTeam(const HWTeam&)), this, SLOT(RemoveNetTeam(const HWTeam&)), Qt::QueuedConnection); |
1235 connect(hwnet, SIGNAL(RemoveNetTeam(const HWTeam&)), this, SLOT(RemoveNetTeam(const HWTeam&)), Qt::QueuedConnection); |
1076 connect(hwnet, SIGNAL(TeamAccepted(const QString&)), this, SLOT(NetTeamAccepted(const QString&)), Qt::QueuedConnection); |
1236 connect(hwnet, SIGNAL(TeamAccepted(const QString&)), this, SLOT(NetTeamAccepted(const QString&)), Qt::QueuedConnection); |
1077 connect(hwnet, SIGNAL(AskForPassword(const QString&)), this, SLOT(NetPassword(const QString&)), Qt::QueuedConnection); |
1237 connect(hwnet, SIGNAL(NickRegistered(const QString&)), this, SLOT(NetNickRegistered(const QString&)), Qt::QueuedConnection); |
|
1238 connect(hwnet, SIGNAL(NickNotRegistered(const QString&)), this, SLOT(NetNickNotRegistered(const QString&)), Qt::QueuedConnection); |
1078 connect(hwnet, SIGNAL(NickTaken(const QString&)), this, SLOT(NetNickTaken(const QString&)), Qt::QueuedConnection); |
1239 connect(hwnet, SIGNAL(NickTaken(const QString&)), this, SLOT(NetNickTaken(const QString&)), Qt::QueuedConnection); |
1079 connect(hwnet, SIGNAL(AuthFailed()), this, SLOT(NetAuthFailed()), Qt::QueuedConnection); |
1240 connect(hwnet, SIGNAL(AuthFailed()), this, SLOT(NetAuthFailed()), Qt::QueuedConnection); |
1080 //connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom())); |
1241 //connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom())); |
1081 |
1242 |
1082 ui.pageRoomsList->chatWidget->setUsersModel(hwnet->lobbyPlayersModel()); |
1243 ui.pageRoomsList->chatWidget->setUsersModel(hwnet->lobbyPlayersModel()); |
1083 ui.pageNetGame->pChatWidget->setUsersModel(hwnet->roomPlayersModel()); |
1244 ui.pageNetGame->chatWidget->setUsersModel(hwnet->roomPlayersModel()); |
1084 |
1245 |
1085 // rooms list page stuff |
1246 // rooms list page stuff |
1086 ui.pageRoomsList->setModel(hwnet->roomsListModel()); |
1247 ui.pageRoomsList->setModel(hwnet->roomsListModel()); |
1087 connect(hwnet, SIGNAL(adminAccess(bool)), |
1248 connect(hwnet, SIGNAL(adminAccess(bool)), |
1088 ui.pageRoomsList, SLOT(setAdmin(bool)), Qt::QueuedConnection); |
1249 ui.pageRoomsList, SLOT(setAdmin(bool)), Qt::QueuedConnection); |
1107 connect(hwnet, SIGNAL(roomMaster(bool)), |
1268 connect(hwnet, SIGNAL(roomMaster(bool)), |
1108 this, SLOT(NetGameChangeStatus(bool)), Qt::QueuedConnection); |
1269 this, SLOT(NetGameChangeStatus(bool)), Qt::QueuedConnection); |
1109 |
1270 |
1110 // net page stuff |
1271 // net page stuff |
1111 connect(hwnet, SIGNAL(chatStringFromNet(const QString&)), |
1272 connect(hwnet, SIGNAL(chatStringFromNet(const QString&)), |
1112 ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1273 ui.pageNetGame->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1113 |
1274 |
1114 connect(hwnet, SIGNAL(chatStringFromMe(const QString&)), |
1275 connect(hwnet, SIGNAL(chatStringFromMe(const QString&)), |
1115 ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1276 ui.pageNetGame->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1116 connect(hwnet, SIGNAL(roomMaster(bool)), |
1277 connect(hwnet, SIGNAL(roomMaster(bool)), |
1117 ui.pageNetGame->pChatWidget, SLOT(adminAccess(bool)), Qt::QueuedConnection); |
1278 ui.pageNetGame->chatWidget, SLOT(adminAccess(bool)), Qt::QueuedConnection); |
1118 connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)), |
1279 connect(ui.pageNetGame->chatWidget, SIGNAL(chatLine(const QString&)), |
1119 hwnet, SLOT(chatLineToNet(const QString&))); |
1280 hwnet, SLOT(chatLineToNet(const QString&))); |
1120 connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady())); |
1281 connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady())); |
1121 connect(hwnet, SIGNAL(setMyReadyStatus(bool)), |
1282 connect(hwnet, SIGNAL(setMyReadyStatus(bool)), |
1122 ui.pageNetGame, SLOT(setReadyStatus(bool)), Qt::QueuedConnection); |
1283 ui.pageNetGame, SLOT(setReadyStatus(bool)), Qt::QueuedConnection); |
1123 |
1284 |
1124 // chat widget actions |
1285 // chat widget actions |
1125 connect(ui.pageNetGame->pChatWidget, SIGNAL(kick(const QString&)), |
1286 connect(ui.pageNetGame->chatWidget, SIGNAL(kick(const QString&)), |
1126 hwnet, SLOT(kickPlayer(const QString&))); |
1287 hwnet, SLOT(kickPlayer(const QString&))); |
1127 connect(ui.pageNetGame->pChatWidget, SIGNAL(ban(const QString&)), |
1288 connect(ui.pageNetGame->chatWidget, SIGNAL(ban(const QString&)), |
1128 hwnet, SLOT(banPlayer(const QString&))); |
1289 hwnet, SLOT(banPlayer(const QString&))); |
1129 connect(ui.pageNetGame->pChatWidget, SIGNAL(info(const QString&)), |
1290 connect(ui.pageNetGame->chatWidget, SIGNAL(info(const QString&)), |
1130 hwnet, SLOT(infoPlayer(const QString&))); |
1291 hwnet, SLOT(infoPlayer(const QString&))); |
1131 connect(ui.pageNetGame->pChatWidget, SIGNAL(follow(const QString&)), |
1292 connect(ui.pageNetGame->chatWidget, SIGNAL(follow(const QString&)), |
1132 hwnet, SLOT(followPlayer(const QString&))); |
1293 hwnet, SLOT(followPlayer(const QString&))); |
1133 connect(ui.pageRoomsList->chatWidget, SIGNAL(kick(const QString&)), |
1294 connect(ui.pageRoomsList->chatWidget, SIGNAL(kick(const QString&)), |
1134 hwnet, SLOT(kickPlayer(const QString&))); |
1295 hwnet, SLOT(kickPlayer(const QString&))); |
1135 connect(ui.pageRoomsList->chatWidget, SIGNAL(ban(const QString&)), |
1296 connect(ui.pageRoomsList->chatWidget, SIGNAL(ban(const QString&)), |
1136 hwnet, SLOT(banPlayer(const QString&))); |
1297 hwnet, SLOT(banPlayer(const QString&))); |
1149 connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)), |
1310 connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)), |
1150 ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1311 ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1151 |
1312 |
1152 // nick list stuff |
1313 // nick list stuff |
1153 connect(hwnet, SIGNAL(nickAdded(const QString&, bool)), |
1314 connect(hwnet, SIGNAL(nickAdded(const QString&, bool)), |
1154 ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection); |
1315 ui.pageNetGame->chatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection); |
1155 connect(hwnet, SIGNAL(nickRemoved(const QString&)), |
1316 connect(hwnet, SIGNAL(nickRemoved(const QString&)), |
1156 ui.pageNetGame->pChatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection); |
1317 ui.pageNetGame->chatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection); |
1157 connect(hwnet, SIGNAL(nickAddedLobby(const QString&, bool)), |
1318 connect(hwnet, SIGNAL(nickAddedLobby(const QString&, bool)), |
1158 ui.pageRoomsList->chatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection); |
1319 ui.pageRoomsList->chatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection); |
1159 connect(hwnet, SIGNAL(nickRemovedLobby(const QString&)), |
1320 connect(hwnet, SIGNAL(nickRemovedLobby(const QString&)), |
1160 ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection); |
1321 ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection); |
1161 |
1322 |
1174 |
1335 |
1175 // admin stuff |
1336 // admin stuff |
1176 connect(hwnet, SIGNAL(serverMessageNew(const QString&)), ui.pageAdmin, SLOT(serverMessageNew(const QString &))); |
1337 connect(hwnet, SIGNAL(serverMessageNew(const QString&)), ui.pageAdmin, SLOT(serverMessageNew(const QString &))); |
1177 connect(hwnet, SIGNAL(serverMessageOld(const QString&)), ui.pageAdmin, SLOT(serverMessageOld(const QString &))); |
1338 connect(hwnet, SIGNAL(serverMessageOld(const QString&)), ui.pageAdmin, SLOT(serverMessageOld(const QString &))); |
1178 connect(hwnet, SIGNAL(latestProtocolVar(int)), ui.pageAdmin, SLOT(protocol(int))); |
1339 connect(hwnet, SIGNAL(latestProtocolVar(int)), ui.pageAdmin, SLOT(protocol(int))); |
|
1340 connect(hwnet, SIGNAL(bansList(const QStringList &)), ui.pageAdmin, SLOT(setBansList(const QStringList &))); |
1179 connect(ui.pageAdmin, SIGNAL(setServerMessageNew(const QString&)), hwnet, SLOT(setServerMessageNew(const QString &))); |
1341 connect(ui.pageAdmin, SIGNAL(setServerMessageNew(const QString&)), hwnet, SLOT(setServerMessageNew(const QString &))); |
1180 connect(ui.pageAdmin, SIGNAL(setServerMessageOld(const QString&)), hwnet, SLOT(setServerMessageOld(const QString &))); |
1342 connect(ui.pageAdmin, SIGNAL(setServerMessageOld(const QString&)), hwnet, SLOT(setServerMessageOld(const QString &))); |
1181 connect(ui.pageAdmin, SIGNAL(setProtocol(int)), hwnet, SLOT(setLatestProtocolVar(int))); |
1343 connect(ui.pageAdmin, SIGNAL(setProtocol(int)), hwnet, SLOT(setLatestProtocolVar(int))); |
1182 connect(ui.pageAdmin, SIGNAL(askServerVars()), hwnet, SLOT(askServerVars())); |
1344 connect(ui.pageAdmin, SIGNAL(askServerVars()), hwnet, SLOT(askServerVars())); |
1183 connect(ui.pageAdmin, SIGNAL(clearAccountsCache()), hwnet, SLOT(clearAccountsCache())); |
1345 connect(ui.pageAdmin, SIGNAL(clearAccountsCache()), hwnet, SLOT(clearAccountsCache())); |
|
1346 connect(ui.pageAdmin, SIGNAL(bansListRequest()), hwnet, SLOT(getBanList())); |
|
1347 connect(ui.pageAdmin, SIGNAL(removeBan(QString)), hwnet, SLOT(removeBan(QString))); |
|
1348 connect(ui.pageAdmin, SIGNAL(banIP(QString,QString,int)), hwnet, SLOT(banIP(QString,QString,int))); |
|
1349 connect(ui.pageAdmin, SIGNAL(banNick(QString,QString,int)), hwnet, SLOT(banNick(QString,QString,int))); |
1184 |
1350 |
1185 // disconnect |
1351 // disconnect |
1186 connect(hwnet, SIGNAL(disconnected(const QString&)), this, SLOT(ForcedDisconnect(const QString&)), Qt::QueuedConnection); |
1352 connect(hwnet, SIGNAL(disconnected(const QString&)), this, SLOT(ForcedDisconnect(const QString&)), Qt::QueuedConnection); |
1187 |
1353 |
1188 // config stuff |
1354 // config stuff |
1189 connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &))); |
1355 connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &))); |
1190 connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &))); |
1356 connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &))); |
1191 connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig())); |
1357 connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig())); |
1192 |
1358 |
1193 while (nick.isEmpty()) |
1359 //nick and pass stuff |
1194 { |
1360 |
1195 nick = QInputDialog::getText(this, |
1361 //remove temppasswordhash just in case |
1196 QObject::tr("Nickname"), |
1362 config->clearTempHash(); |
1197 QObject::tr("Please enter your nickname"), |
1363 |
1198 QLineEdit::Normal, |
1364 //initialize |
1199 QDir::home().dirName()); |
1365 QString hash = config->passwordHash(); |
1200 config->setValue("net/nick",nick); |
1366 QString temphash = config->tempHash(); |
|
1367 QString nickname = config->value("net/nick", "").toString(); |
|
1368 QString password; |
|
1369 |
|
1370 if (nickname.isEmpty() || hash.isEmpty()) { //if something from login is missing, start dialog loop |
|
1371 |
|
1372 while (nickname.isEmpty() || (hash.isEmpty() && temphash.isEmpty())) //while a nickname, or both hashes are missing |
|
1373 { |
|
1374 //open dialog |
|
1375 HWPasswordDialog * pwDialog = new HWPasswordDialog(this); |
|
1376 pwDialog->cbSave->setChecked(config->value("net/savepassword", true).toBool()); |
|
1377 |
|
1378 //if nickname is present, put it into the field |
|
1379 if (!nickname.isEmpty()) { |
|
1380 pwDialog->leNickname->setText(nickname); |
|
1381 pwDialog->lePassword->setFocus(); |
|
1382 } |
|
1383 |
|
1384 //if dialog close, create an error message |
|
1385 if (pwDialog->exec() != QDialog::Accepted) { |
|
1386 delete pwDialog; |
|
1387 GoBack(); |
|
1388 return; |
|
1389 } |
|
1390 |
|
1391 //set nick and pass from the dialog |
|
1392 nickname = pwDialog->leNickname->text(); |
|
1393 password = pwDialog->lePassword->text(); |
|
1394 |
|
1395 //check the nickname variable |
|
1396 if (nickname.isEmpty()) { |
|
1397 int retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied.")); |
|
1398 GoBack(); |
|
1399 delete pwDialog; |
|
1400 if (retry) { |
|
1401 NetConnectOfficialServer(); |
|
1402 } |
|
1403 return; |
|
1404 } |
|
1405 |
|
1406 if (!password.isEmpty()) { |
|
1407 //calculate temphash and set it into config |
|
1408 temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex(); |
|
1409 config->setTempHash(temphash); |
|
1410 |
|
1411 //if user wants to save password |
|
1412 bool save = pwDialog->cbSave->isChecked(); |
|
1413 config->setValue("net/savepassword", save); |
|
1414 if (save) // user wants to save password |
|
1415 { |
|
1416 config->setPasswordHash(temphash); |
|
1417 } |
|
1418 } |
|
1419 else { |
|
1420 delete pwDialog; |
|
1421 config->setValue("net/nick", nickname); |
|
1422 config->updNetNick(); |
|
1423 config->clearPasswordHash(); |
|
1424 break; |
|
1425 } |
|
1426 |
|
1427 delete pwDialog; |
|
1428 |
|
1429 //update nickname |
|
1430 config->setValue("net/nick", nickname); |
1201 config->updNetNick(); |
1431 config->updNetNick(); |
1202 } |
1432 |
1203 |
1433 //and all the variables |
1204 ui.pageRoomsList->setUser(nick); |
1434 hash = config->passwordHash(); |
1205 ui.pageNetGame->setUser(nick); |
1435 temphash = config->tempHash(); |
1206 |
1436 nickname = config->value("net/nick", "").toString(); |
1207 hwnet->Connect(hostName, port, nick); |
1437 } |
1208 } |
1438 } |
|
1439 |
|
1440 ui.pageRoomsList->setUser(nickname); |
|
1441 ui.pageNetGame->setUser(nickname); |
|
1442 |
|
1443 hwnet->Connect(hostName, port, nickname); |
|
1444 } |
|
1445 |
|
1446 |
1209 |
1447 |
1210 void HWForm::NetConnect() |
1448 void HWForm::NetConnect() |
1211 { |
1449 { |
1212 HWHostPortDialog * hpd = new HWHostPortDialog(this); |
1450 HWHostPortDialog * hpd = new HWHostPortDialog(this); |
1213 hpd->leHost->setText(*netHost); |
1451 hpd->leHost->setText(*netHost); |
1630 } |
1883 } |
1631 |
1884 |
1632 // 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] |
1885 // 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] |
1633 QString HWForm::getDemoArguments() |
1886 QString HWForm::getDemoArguments() |
1634 { |
1887 { |
|
1888 |
|
1889 QString prefix = datadir->absolutePath(); |
|
1890 QString userPrefix = cfgdir->absolutePath(); |
|
1891 #ifdef Q_WS_WIN |
|
1892 prefix = prefix.replace("/","\\"); |
|
1893 userPrefix = userPrefix.replace("/","\\"); |
|
1894 #endif |
|
1895 |
1635 QRect resolution = config->vid_Resolution(); |
1896 QRect resolution = config->vid_Resolution(); |
1636 return QString(QString::number(resolution.width()) + " " |
1897 return QString("--prefix " + prefix |
1637 + QString::number(resolution.height()) + " " |
1898 + " --user-prefix " + userPrefix |
1638 + QString::number(config->bitDepth()) + " " // bpp |
1899 + " --width " + QString::number(resolution.width()) |
1639 + QString::number(config->volume()) + " " // sound volume |
1900 + " --height " + QString::number(resolution.height()) |
1640 + (config->isMusicEnabled() ? "1" : "0") + " " |
1901 + " --volume " + QString::number(config->volume()) |
1641 + (config->isSoundEnabled() ? "1" : "0") + " " |
1902 + (config->isMusicEnabled() ? "" : " --nomusic") |
1642 + config->language() + ".txt " |
1903 + (config->isSoundEnabled() ? "" : " --nosound") |
1643 + (config->vid_Fullscreen() ? "1" : "0") + " " |
1904 + " --locale " + config->language() + ".txt" |
1644 + (config->isShowFPSEnabled() ? "1" : "0") + " " |
1905 + (config->vid_Fullscreen() ? " --fullscreen" : "") |
1645 + (config->isAltDamageEnabled() ? "1" : "0") + " " |
1906 + (config->isShowFPSEnabled() ? " --showfps" : "") |
1646 + QString::number(config->timerInterval()) + " " |
1907 + (config->isAltDamageEnabled() ? " --altdmg" : "") |
1647 + QString::number(config->translateQuality())); |
1908 + " --frame-interval " + QString::number(config->timerInterval()) |
|
1909 + " --raw-quality " + QString::number(config->translateQuality())); |
1648 } |
1910 } |
1649 |
1911 |
1650 void HWForm::AssociateFiles() |
1912 void HWForm::AssociateFiles() |
1651 { |
1913 { |
1652 bool success = true; |
1914 bool success = true; |
1657 registry_hkcr.setValue(".hws/Default", "Hedgewars.Save"); |
1919 registry_hkcr.setValue(".hws/Default", "Hedgewars.Save"); |
1658 registry_hkcr.setValue("Hedgewars.Demo/Default", tr("Hedgewars Demo File", "File Types")); |
1920 registry_hkcr.setValue("Hedgewars.Demo/Default", tr("Hedgewars Demo File", "File Types")); |
1659 registry_hkcr.setValue("Hedgewars.Save/Default", tr("Hedgewars Save File", "File Types")); |
1921 registry_hkcr.setValue("Hedgewars.Save/Default", tr("Hedgewars Save File", "File Types")); |
1660 registry_hkcr.setValue("Hedgewars.Demo/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwdfile.ico\",0"); |
1922 registry_hkcr.setValue("Hedgewars.Demo/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwdfile.ico\",0"); |
1661 registry_hkcr.setValue("Hedgewars.Save/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwsfile.ico\",0"); |
1923 registry_hkcr.setValue("Hedgewars.Save/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwsfile.ico\",0"); |
1662 registry_hkcr.setValue("Hedgewars.Demo/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + cfgdir->absolutePath().replace("/","\\") + "\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\" --set-everything "+arguments); |
1924 registry_hkcr.setValue("Hedgewars.Demo/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"%1\" "+arguments); |
1663 registry_hkcr.setValue("Hedgewars.Save/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + cfgdir->absolutePath().replace("/","\\") + "\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\" --set-everything "+arguments); |
1925 registry_hkcr.setValue("Hedgewars.Save/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"%1\" "+arguments); |
1664 #elif defined __APPLE__ |
1926 #elif defined __APPLE__ |
1665 // only useful when other apps have taken precedence over our file extensions and you want to reset it |
1927 // only useful when other apps have taken precedence over our file extensions and you want to reset it |
1666 system("defaults write com.apple.LaunchServices LSHandlers -array-add '<dict><key>LSHandlerContentTag</key><string>hwd</string><key>LSHandlerContentTagClass</key><string>public.filename-extension</string><key>LSHandlerRoleAll</key><string>org.hedgewars.desktop</string></dict>'"); |
1928 system("defaults write com.apple.LaunchServices LSHandlers -array-add '<dict><key>LSHandlerContentTag</key><string>hwd</string><key>LSHandlerContentTagClass</key><string>public.filename-extension</string><key>LSHandlerRoleAll</key><string>org.hedgewars.desktop</string></dict>'"); |
1667 system("defaults write com.apple.LaunchServices LSHandlers -array-add '<dict><key>LSHandlerContentTag</key><string>hws</string><key>LSHandlerContentTagClass</key><string>public.filename-extension</string><key>LSHandlerRoleAll</key><string>org.hedgewars.desktop</string></dict>'"); |
1929 system("defaults write com.apple.LaunchServices LSHandlers -array-add '<dict><key>LSHandlerContentTag</key><string>hws</string><key>LSHandlerContentTagClass</key><string>public.filename-extension</string><key>LSHandlerRoleAll</key><string>org.hedgewars.desktop</string></dict>'"); |
1668 system("/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -domain local -domain system -domain user"); |
1930 system("/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -domain local -domain system -domain user"); |
1724 } |
1986 } |
1725 } |
1987 } |
1726 |
1988 |
1727 void HWForm::SendFeedback() |
1989 void HWForm::SendFeedback() |
1728 { |
1990 { |
1729 //Create Xml representation of google code issue first |
1991 // Get form data |
1730 if (!CreateIssueXml()) |
1992 |
1731 { |
1993 QString summary = ui.pageFeedback->summary->text(); |
1732 ShowErrorMessage(QMessageBox::tr("Please fill out all fields")); |
1994 QString description = ui.pageFeedback->description->toPlainText(); |
|
1995 QString email = ui.pageFeedback->email->text(); |
|
1996 QString captchaCode = ui.pageFeedback->captcha_code->text(); |
|
1997 QString captchaID = QString::number(ui.pageFeedback->captchaID); |
|
1998 QString version = "HedgewarsFoundation-Hedgewars-" + (cVersionString?(*cVersionString):QString("")); |
|
1999 |
|
2000 if (summary.isEmpty() || description.isEmpty()) |
|
2001 { |
|
2002 ShowErrorMessage(QMessageBox::tr("Please fill out all fields. Email is optional.")); |
1733 return; |
2003 return; |
1734 } |
2004 } |
1735 |
2005 |
1736 //Google login using fake account (feedback.hedgewars@gmail.com) |
2006 // Submit issue to PHP script |
|
2007 |
|
2008 QByteArray body; |
|
2009 body.append("captcha="); |
|
2010 body.append(captchaID); |
|
2011 body.append("&code="); |
|
2012 body.append(captchaCode); |
|
2013 body.append("&version="); |
|
2014 body.append(QUrl::toPercentEncoding(version)); |
|
2015 body.append("&title="); |
|
2016 body.append(QUrl::toPercentEncoding(summary)); |
|
2017 body.append("&body="); |
|
2018 body.append(QUrl::toPercentEncoding(description)); |
|
2019 body.append("&email="); |
|
2020 body.append(QUrl::toPercentEncoding(email)); |
|
2021 if (ui.pageFeedback->CheckSendSpecs->isChecked()) |
|
2022 { |
|
2023 body.append("&specs="); |
|
2024 body.append(QUrl::toPercentEncoding(ui.pageFeedback->specs)); |
|
2025 } |
|
2026 |
1737 nam = new QNetworkAccessManager(this); |
2027 nam = new QNetworkAccessManager(this); |
1738 connect(nam, SIGNAL(finished(QNetworkReply*)), |
2028 connect(nam, SIGNAL(finished(QNetworkReply*)), |
1739 this, SLOT(finishedSlot(QNetworkReply*))); |
2029 this, SLOT(finishedSlot(QNetworkReply*))); |
1740 |
2030 |
1741 QUrl url(QString("https://www.google.com/accounts/ClientLogin?" |
2031 QNetworkRequest header(QUrl("http://hedgewars.org/feedback/?submit")); |
1742 "accountType=GOOGLE&Email=feedback.hedgewars@gmail.com&Passwd=hwfeedback&service=code&source=HedgewarsFoundation-Hedgewars-") |
2032 header.setRawHeader("Content-Length", QString::number(body.size()).toAscii()); |
1743 + (cVersionString?(*cVersionString):QString(""))); |
2033 |
1744 nam->get(QNetworkRequest(url)); |
2034 nam->post(header, body); |
1745 |
|
1746 } |
|
1747 |
|
1748 bool HWForm::CreateIssueXml() |
|
1749 { |
|
1750 QString summary = ui.pageFeedback->summary->text(); |
|
1751 QString description = ui.pageFeedback->description->toPlainText(); |
|
1752 |
|
1753 //Check if all necessary information is entered |
|
1754 if (summary.isEmpty() || description.isEmpty()) |
|
1755 return false; |
|
1756 |
|
1757 issueXml = |
|
1758 "<?xml version='1.0' encoding='UTF-8'?>" |
|
1759 "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:issues='http://code.google.com/p/hedgewars/issues/list'>" |
|
1760 "<title>"; |
|
1761 issueXml.append(summary); |
|
1762 issueXml.append("</title><content type='html'>"); |
|
1763 issueXml.append(description); |
|
1764 issueXml.append("</content><author><name>feedback.hedgewars</name></author></entry>"); |
|
1765 |
|
1766 return true; |
|
1767 } |
2035 } |
1768 |
2036 |
1769 void HWForm::finishedSlot(QNetworkReply* reply) |
2037 void HWForm::finishedSlot(QNetworkReply* reply) |
1770 { |
2038 { |
1771 if (reply && reply->error() == QNetworkReply::NoError) |
2039 if (reply && reply->error() == QNetworkReply::NoError) |
1772 { |
2040 { |
1773 QByteArray array = reply->readAll(); |
|
1774 QString str(array); |
|
1775 |
|
1776 if (authToken.length() != 0) |
|
1777 { |
|
1778 |
|
1779 QMessageBox infoMsg(this); |
2041 QMessageBox infoMsg(this); |
1780 infoMsg.setIcon(QMessageBox::Information); |
2042 infoMsg.setIcon(QMessageBox::Information); |
1781 infoMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Success")); |
2043 infoMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Success")); |
1782 infoMsg.setText(QMessageBox::tr("Successfully posted the issue on hedgewars.googlecode.com")); |
2044 infoMsg.setText(reply->readAll()); |
1783 infoMsg.setWindowModality(Qt::WindowModal); |
2045 infoMsg.setWindowModality(Qt::WindowModal); |
1784 infoMsg.exec(); |
2046 infoMsg.exec(); |
1785 |
2047 |
1786 ui.pageFeedback->summary->clear(); |
2048 ui.pageFeedback->summary->clear(); |
|
2049 ui.pageFeedback->email->clear(); |
1787 ui.pageFeedback->description->clear(); |
2050 ui.pageFeedback->description->clear(); |
1788 authToken = ""; |
2051 ui.pageFeedback->LoadCaptchaImage(); |
|
2052 |
1789 return; |
2053 return; |
1790 } |
2054 } |
1791 |
|
1792 if (!getAuthToken(str)) |
|
1793 { |
|
1794 ShowErrorMessage(QMessageBox::tr("Error during authentication at google.com")); |
|
1795 return; |
|
1796 } |
|
1797 |
|
1798 QByteArray body(issueXml.toUtf8()); |
|
1799 QNetworkRequest header(QUrl("https://code.google.com/feeds/issues/p/hedgewars/issues/full")); |
|
1800 header.setRawHeader("Content-Length", QString::number(issueXml.length()).toAscii()); |
|
1801 header.setRawHeader("Content-Type", "application/atom+xml"); |
|
1802 header.setRawHeader("Authorization", QString("GoogleLogin auth=%1").arg(authToken).toUtf8()); |
|
1803 nam->post(header, body); |
|
1804 |
|
1805 } |
|
1806 else if (authToken.length() == 0) |
|
1807 ShowErrorMessage(QMessageBox::tr("Error during authentication at google.com")); |
|
1808 else |
2055 else |
1809 { |
2056 { |
1810 ShowErrorMessage(QMessageBox::tr("Error reporting the issue, please try again later (or visit hedgewars.googlecode.com directly)")); |
2057 ShowErrorMessage(QString("Error: ") + reply->readAll()); |
1811 authToken = ""; |
2058 ui.pageFeedback->LoadCaptchaImage(); |
1812 } |
2059 } |
1813 |
2060 } |
1814 } |
2061 |
1815 |
|
1816 bool HWForm::getAuthToken(QString str) |
|
1817 { |
|
1818 QRegExp ex("Auth=(.+)"); |
|
1819 |
|
1820 if (-1 == ex.indexIn(str)) |
|
1821 return false; |
|
1822 |
|
1823 authToken = ex.cap(1); |
|
1824 authToken.remove(QChar('\n')); |
|
1825 |
|
1826 return true; |
|
1827 } |
|
1828 |
|
1829 |
|
1830 |
|