153 config = new GameUIConfig(this, "physfs://hedgewars.ini"); |
153 config = new GameUIConfig(this, "physfs://hedgewars.ini"); |
154 frontendEffects = config->value("frontend/effects", true).toBool(); |
154 frontendEffects = config->value("frontend/effects", true).toBool(); |
155 playerHash = QString(QCryptographicHash::hash(config->value("net/nick","").toString().toUtf8(), QCryptographicHash::Md5).toHex()); |
155 playerHash = QString(QCryptographicHash::hash(config->value("net/nick","").toString().toUtf8(), QCryptographicHash::Md5).toHex()); |
156 |
156 |
157 ui.pageRoomsList->setSettings(config); |
157 ui.pageRoomsList->setSettings(config); |
|
158 ui.pageNetGame->setSettings(config); |
158 ui.pageNetGame->chatWidget->setSettings(config); |
159 ui.pageNetGame->chatWidget->setSettings(config); |
159 ui.pageRoomsList->chatWidget->setSettings(config); |
160 ui.pageRoomsList->chatWidget->setSettings(config); |
160 ui.pageOptions->setConfig(config); |
161 ui.pageOptions->setConfig(config); |
161 #ifdef VIDEOREC |
162 #ifdef VIDEOREC |
162 ui.pageVideos->init(config); |
163 ui.pageVideos->init(config); |
347 { |
348 { |
348 widgets.at(i)->installEventFilter(filter); |
349 widgets.at(i)->installEventFilter(filter); |
349 } |
350 } |
350 } |
351 } |
351 |
352 |
|
353 ui.Pages->setCurrentIndex(ID_PAGE_INFO); |
352 PagesStack.push(ID_PAGE_MAIN); |
354 PagesStack.push(ID_PAGE_MAIN); |
353 ((AbstractPage*)ui.Pages->widget(ID_PAGE_MAIN))->triggerPageEnter(); |
355 ((AbstractPage*)ui.Pages->widget(ID_PAGE_MAIN))->triggerPageEnter(); |
354 GoBack(); |
356 GoBack(); |
355 } |
357 } |
356 |
358 |
357 #ifdef USE_XFIRE |
359 #ifdef USE_XFIRE |
358 void HWForm::updateXfire(void) |
360 void HWForm::updateXfire(void) |
359 { |
361 { |
360 if(hwnet && (hwnet->clientState() != HWNewNet::Disconnected)) |
362 if(hwnet && (hwnet->clientState() != HWNewNet::Disconnected)) |
361 { |
363 { |
362 xfire_setvalue(XFIRE_SERVER, !hwnet->getHost().compare("netserver.hedgewars.org:46631") ? "Official server" : hwnet->getHost().toAscii()); |
364 xfire_setvalue(XFIRE_SERVER, !hwnet->getHost().compare(QString("%1:%2").arg(NETGAME_DEFAULT_SERVER).arg(NETGAME_DEFAULT_PORT)) ? "Official server" : hwnet->getHost().toAscii()); |
363 switch(hwnet->clientState()) |
365 switch(hwnet->clientState()) |
364 { |
366 { |
365 case HWNewNet::Connecting: // Connecting |
367 case HWNewNet::Connecting: // Connecting |
366 case HWNewNet::Connected: |
368 case HWNewNet::Connected: |
367 xfire_setvalue(XFIRE_STATUS, "Connecting"); |
369 xfire_setvalue(XFIRE_STATUS, "Connecting"); |
990 game->PlayDemo(curritem->data(Qt::UserRole).toString(), ui.pagePlayDemo->isSave()); |
992 game->PlayDemo(curritem->data(Qt::UserRole).toString(), ui.pagePlayDemo->isSave()); |
991 } |
993 } |
992 |
994 |
993 void HWForm::PlayDemoQuick(const QString & demofilename) |
995 void HWForm::PlayDemoQuick(const QString & demofilename) |
994 { |
996 { |
995 if (game && game->gameState == gsStarted) return; |
|
996 GoBack(); //needed to cleanly disconnect from netgame |
|
997 GoToPage(ID_PAGE_MAIN); |
997 GoToPage(ID_PAGE_MAIN); |
|
998 //GoBack() <- don't or you'll close the socket |
998 CreateGame(0, 0, 0); |
999 CreateGame(0, 0, 0); |
999 game->PlayDemo(demofilename, false); |
1000 game->PlayDemo(demofilename, false); |
1000 } |
1001 } |
1001 |
1002 |
|
1003 void HWForm::NetConnectQuick(const QString & host, quint16 port) |
|
1004 { |
|
1005 GoToPage(ID_PAGE_MAIN); |
|
1006 NetConnectServer(host, port); |
|
1007 } |
|
1008 |
1002 void HWForm::NetConnectServer(const QString & host, quint16 port) |
1009 void HWForm::NetConnectServer(const QString & host, quint16 port) |
1003 { |
1010 { |
|
1011 qDebug("connecting to %s:%d", qPrintable(host), port); |
1004 _NetConnect(host, port, ui.pageOptions->editNetNick->text().trimmed()); |
1012 _NetConnect(host, port, ui.pageOptions->editNetNick->text().trimmed()); |
1005 } |
1013 } |
1006 |
1014 |
1007 void HWForm::NetConnectOfficialServer() |
1015 void HWForm::NetConnectOfficialServer() |
1008 { |
1016 { |
1009 NetConnectServer("netserver.hedgewars.org", 46631); |
1017 NetConnectServer(NETGAME_DEFAULT_SERVER, NETGAME_DEFAULT_PORT); |
1010 } |
1018 } |
1011 |
1019 |
1012 void HWForm::NetPassword(const QString & nick) |
1020 void HWForm::NetPassword(const QString & nick) |
1013 { |
1021 { |
1014 Q_UNUSED(nick); |
1022 Q_UNUSED(nick); |
1094 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); |
1102 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); |
1095 |
1103 |
1096 if (!ok || newNick.isEmpty()) |
1104 if (!ok || newNick.isEmpty()) |
1097 { |
1105 { |
1098 //ForcedDisconnect(tr("No nickname supplied.")); |
1106 //ForcedDisconnect(tr("No nickname supplied.")); |
1099 bool retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied.")); |
1107 bool retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied.")); |
1100 GoBack(); |
1108 GoBack(); |
1101 if (retry) { |
1109 if (retry) { |
1102 NetConnectOfficialServer(); |
1110 if (hwnet->m_private_game) { |
|
1111 QStringList list = hwnet->getHost().split(":"); |
|
1112 NetConnectServer(list.at(0), list.at(1).toShort()); |
|
1113 } else |
|
1114 NetConnectOfficialServer(); |
1103 } |
1115 } |
1104 return; |
1116 return; |
1105 } |
1117 } |
1106 |
1118 |
1107 hwnet->NewNick(newNick); |
1119 hwnet->NewNick(newNick); |
1180 |
1192 |
1181 void HWForm::_NetConnect(const QString & hostName, quint16 port, QString nick) |
1193 void HWForm::_NetConnect(const QString & hostName, quint16 port, QString nick) |
1182 { |
1194 { |
1183 Q_UNUSED(nick); |
1195 Q_UNUSED(nick); |
1184 |
1196 |
1185 if(hwnet) |
1197 if (hwnet) { |
1186 { |
1198 // destroy old connection |
1187 hwnet->Disconnect(); |
1199 hwnet->Disconnect(); |
1188 delete hwnet; |
1200 delete hwnet; |
1189 hwnet=0; |
1201 hwnet = NULL; |
1190 } |
1202 } |
1191 |
1203 |
1192 hwnet = new HWNewNet(); |
1204 hwnet = new HWNewNet(); |
1193 |
1205 |
1194 GoToPage(ID_PAGE_CONNECTING); |
1206 GoToPage(ID_PAGE_CONNECTING); |
1195 |
1207 |
1196 connect(hwnet, SIGNAL(AskForRunGame()), this, SLOT(CreateNetGame())); |
1208 connect(hwnet, SIGNAL(AskForRunGame()), this, SLOT(CreateNetGame()), Qt::QueuedConnection); |
1197 connect(hwnet, SIGNAL(connected()), this, SLOT(NetConnected()), Qt::QueuedConnection); |
1209 connect(hwnet, SIGNAL(connected()), this, SLOT(NetConnected()), Qt::QueuedConnection); |
1198 connect(hwnet, SIGNAL(Error(const QString&)), this, SLOT(NetError(const QString&)), Qt::QueuedConnection); |
1210 connect(hwnet, SIGNAL(Error(const QString&)), this, SLOT(NetError(const QString&)), Qt::QueuedConnection); |
1199 connect(hwnet, SIGNAL(Warning(const QString&)), this, SLOT(NetWarning(const QString&)), Qt::QueuedConnection); |
1211 connect(hwnet, SIGNAL(Warning(const QString&)), this, SLOT(NetWarning(const QString&)), Qt::QueuedConnection); |
1200 connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()), Qt::QueuedConnection); |
1212 connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()), Qt::QueuedConnection); |
1201 connect(hwnet, SIGNAL(LeftRoom(const QString&)), this, SLOT(NetLeftRoom(const QString&)), Qt::QueuedConnection); |
1213 connect(hwnet, SIGNAL(LeftRoom(const QString&)), this, SLOT(NetLeftRoom(const QString&)), Qt::QueuedConnection); |
1235 // room status stuff |
1247 // room status stuff |
1236 connect(hwnet, SIGNAL(roomMaster(bool)), |
1248 connect(hwnet, SIGNAL(roomMaster(bool)), |
1237 this, SLOT(NetGameChangeStatus(bool)), Qt::QueuedConnection); |
1249 this, SLOT(NetGameChangeStatus(bool)), Qt::QueuedConnection); |
1238 |
1250 |
1239 // net page stuff |
1251 // net page stuff |
|
1252 connect(hwnet, SIGNAL(roomNameUpdated(const QString &)), |
|
1253 ui.pageNetGame, SLOT(setRoomName(const QString &)), Qt::QueuedConnection); |
1240 connect(hwnet, SIGNAL(chatStringFromNet(const QString&)), |
1254 connect(hwnet, SIGNAL(chatStringFromNet(const QString&)), |
1241 ui.pageNetGame->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1255 ui.pageNetGame->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1242 |
1256 |
1243 connect(hwnet, SIGNAL(chatStringFromMe(const QString&)), |
1257 connect(hwnet, SIGNAL(chatStringFromMe(const QString&)), |
1244 ui.pageNetGame->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1258 ui.pageNetGame->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1276 connect(ui.pageRoomsList->chatWidget, SIGNAL(chatLine(const QString&)), |
1290 connect(ui.pageRoomsList->chatWidget, SIGNAL(chatLine(const QString&)), |
1277 hwnet, SLOT(chatLineToLobby(const QString&))); |
1291 hwnet, SLOT(chatLineToLobby(const QString&))); |
1278 connect(hwnet, SIGNAL(chatStringLobby(const QString&)), |
1292 connect(hwnet, SIGNAL(chatStringLobby(const QString&)), |
1279 ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1293 ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1280 connect(hwnet, SIGNAL(chatStringLobby(const QString&, const QString&)), |
1294 connect(hwnet, SIGNAL(chatStringLobby(const QString&, const QString&)), |
1281 ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&, const QString&))); |
1295 ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&, const QString&)), Qt::QueuedConnection); |
1282 connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)), |
1296 connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)), |
1283 ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1297 ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1284 |
1298 |
1285 // nick list stuff |
1299 // nick list stuff |
1286 connect(hwnet, SIGNAL(nickAdded(const QString&, bool)), |
1300 connect(hwnet, SIGNAL(nickAdded(const QString&, bool)), |
1326 // config stuff |
1340 // config stuff |
1327 connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &))); |
1341 connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &))); |
1328 connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &))); |
1342 connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &))); |
1329 connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig())); |
1343 connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig())); |
1330 |
1344 |
1331 //nick and pass stuff |
1345 //nick and pass stuff |
1332 |
1346 QString nickname = config->value("net/nick", "").toString(); |
|
1347 |
|
1348 hwnet->m_private_game = !(hostName == NETGAME_DEFAULT_SERVER && port == NETGAME_DEFAULT_PORT); |
|
1349 if (hwnet->m_private_game == false) |
|
1350 if (AskForNickAndPwd() != 0) |
|
1351 return; |
|
1352 |
|
1353 ui.pageRoomsList->setUser(nickname); |
|
1354 ui.pageNetGame->setUser(nickname); |
|
1355 |
|
1356 hwnet->Connect(hostName, port, nickname); |
|
1357 } |
|
1358 |
|
1359 int HWForm::AskForNickAndPwd(void) |
|
1360 { |
1333 //remove temppasswordhash just in case |
1361 //remove temppasswordhash just in case |
1334 config->clearTempHash(); |
1362 config->clearTempHash(); |
1335 |
1363 |
1336 //initialize |
1364 //initialize |
1337 QString hash = config->passwordHash(); |
1365 QString hash = config->passwordHash(); |
1371 if (nickname.isEmpty()) { |
1399 if (nickname.isEmpty()) { |
1372 int retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied.")); |
1400 int retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied.")); |
1373 GoBack(); |
1401 GoBack(); |
1374 delete pwDialog; |
1402 delete pwDialog; |
1375 if (retry) { |
1403 if (retry) { |
1376 NetConnectOfficialServer(); |
1404 if (hwnet->m_private_game) { |
1377 } |
1405 QStringList list = hwnet->getHost().split(":"); |
1378 return; |
1406 NetConnectServer(list.at(0), list.at(1).toShort()); |
|
1407 } else |
|
1408 NetConnectOfficialServer(); |
|
1409 } |
|
1410 return -1; |
1379 } |
1411 } |
1380 |
1412 |
1381 if (!password.isEmpty()) { |
1413 if (!password.isEmpty()) { |
1382 //calculate temphash and set it into config |
1414 //calculate temphash and set it into config |
1383 temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex(); |
1415 temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex(); |
1410 hash = config->passwordHash(); |
1442 hash = config->passwordHash(); |
1411 temphash = config->tempHash(); |
1443 temphash = config->tempHash(); |
1412 nickname = config->value("net/nick", "").toString(); |
1444 nickname = config->value("net/nick", "").toString(); |
1413 } |
1445 } |
1414 } |
1446 } |
1415 |
1447 return 0; |
1416 ui.pageRoomsList->setUser(nickname); |
1448 } |
1417 ui.pageNetGame->setUser(nickname); |
|
1418 |
|
1419 hwnet->Connect(hostName, port, nickname); |
|
1420 } |
|
1421 |
|
1422 |
|
1423 |
1449 |
1424 void HWForm::NetConnect() |
1450 void HWForm::NetConnect() |
1425 { |
1451 { |
1426 HWHostPortDialog * hpd = new HWHostPortDialog(this); |
1452 HWHostPortDialog * hpd = new HWHostPortDialog(this); |
1427 hpd->leHost->setText(*netHost); |
1453 hpd->leHost->setText(*netHost); |
1486 void HWForm::ForcedDisconnect(const QString & reason) |
1512 void HWForm::ForcedDisconnect(const QString & reason) |
1487 { |
1513 { |
1488 if (reason == "Reconnected too fast") { //TODO: this is a hack, which should be remade |
1514 if (reason == "Reconnected too fast") { //TODO: this is a hack, which should be remade |
1489 bool retry = RetryDialog(tr("Hedgewars - Connection error"), tr("You reconnected too fast.\nPlease wait a few seconds and try again.")); |
1515 bool retry = RetryDialog(tr("Hedgewars - Connection error"), tr("You reconnected too fast.\nPlease wait a few seconds and try again.")); |
1490 if (retry) { |
1516 if (retry) { |
1491 NetConnectOfficialServer(); |
1517 if (hwnet->m_private_game) { |
|
1518 QStringList list = hwnet->getHost().split(":"); |
|
1519 NetConnectServer(list.at(0), list.at(1).toShort()); |
|
1520 } else |
|
1521 NetConnectOfficialServer(); |
1492 } |
1522 } |
1493 else { |
1523 else { |
1494 while (ui.Pages->currentIndex() != ID_PAGE_NET |
1524 while (ui.Pages->currentIndex() != ID_PAGE_NET |
1495 && ui.Pages->currentIndex() != ID_PAGE_MAIN) |
1525 && ui.Pages->currentIndex() != ID_PAGE_MAIN) |
1496 { |
1526 { |
1619 QString recordFileName = |
1648 QString recordFileName = |
1620 config->appendDateTimeToRecordName() ? |
1649 config->appendDateTimeToRecordName() ? |
1621 QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm") : |
1650 QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm") : |
1622 "LastRound"; |
1651 "LastRound"; |
1623 |
1652 |
1624 QStringList versionParts = cVersionString->split('-'); |
1653 recordFileName += "_" + *cRevisionString + "-" + *cHashString; |
1625 if ( (versionParts.size() == 2) && (!versionParts[1].isEmpty()) && (versionParts[1].contains(':')) ) |
|
1626 recordFileName = recordFileName + "_" + versionParts[1].replace(':','-'); |
|
1627 |
1654 |
1628 if (type == rtDemo) |
1655 if (type == rtDemo) |
1629 { |
1656 { |
1630 demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD")); |
1657 demo.replace(QByteArray("\x02TL"), QByteArray("\x02TD")); |
1631 demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD")); |
1658 demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD")); |
1725 void HWForm::NetGameMaster() |
1752 void HWForm::NetGameMaster() |
1726 { |
1753 { |
1727 ui.pageNetGame->setMasterMode(true); |
1754 ui.pageNetGame->setMasterMode(true); |
1728 ui.pageNetGame->restrictJoins->setChecked(false); |
1755 ui.pageNetGame->restrictJoins->setChecked(false); |
1729 ui.pageNetGame->restrictTeamAdds->setChecked(false); |
1756 ui.pageNetGame->restrictTeamAdds->setChecked(false); |
|
1757 ui.pageNetGame->restrictUnregistered->setChecked(false); |
1730 ui.pageNetGame->pGameCFG->GameSchemes->setModel(ammoSchemeModel); |
1758 ui.pageNetGame->pGameCFG->GameSchemes->setModel(ammoSchemeModel); |
1731 ui.pageNetGame->pGameCFG->setMaster(true); |
1759 ui.pageNetGame->pGameCFG->setMaster(true); |
1732 ui.pageNetGame->pNetTeamsWidget->setInteractivity(true); |
1760 ui.pageNetGame->pNetTeamsWidget->setInteractivity(true); |
1733 |
1761 |
1734 if (hwnet) |
1762 if (hwnet) |
1737 ui.pageNetGame->BtnStart->disconnect(this); |
1765 ui.pageNetGame->BtnStart->disconnect(this); |
1738 ui.pageNetGame->BtnUpdate->disconnect(hwnet); |
1766 ui.pageNetGame->BtnUpdate->disconnect(hwnet); |
1739 ui.pageNetGame->leRoomName->disconnect(hwnet); |
1767 ui.pageNetGame->leRoomName->disconnect(hwnet); |
1740 ui.pageNetGame->restrictJoins->disconnect(hwnet); |
1768 ui.pageNetGame->restrictJoins->disconnect(hwnet); |
1741 ui.pageNetGame->restrictTeamAdds->disconnect(hwnet); |
1769 ui.pageNetGame->restrictTeamAdds->disconnect(hwnet); |
|
1770 ui.pageNetGame->restrictUnregistered->disconnect(hwnet); |
1742 ui.pageNetGame->disconnect(hwnet, SLOT(updateRoomName(const QString&))); |
1771 ui.pageNetGame->disconnect(hwnet, SLOT(updateRoomName(const QString&))); |
1743 |
1772 |
1744 ui.pageNetGame->setRoomName(hwnet->getRoom()); |
1773 ui.pageNetGame->setRoomName(hwnet->getRoom()); |
1745 |
1774 |
1746 connect(ui.pageNetGame->BtnStart, SIGNAL(clicked()), this, SLOT(startGame())); |
1775 connect(ui.pageNetGame->BtnStart, SIGNAL(clicked()), this, SLOT(startGame())); |
1747 connect(ui.pageNetGame, SIGNAL(askForUpdateRoomName(const QString &)), hwnet, SLOT(updateRoomName(const QString &))); |
1776 connect(ui.pageNetGame, SIGNAL(askForUpdateRoomName(const QString &)), hwnet, SLOT(updateRoomName(const QString &))); |
1748 connect(ui.pageNetGame->restrictJoins, SIGNAL(triggered()), hwnet, SLOT(toggleRestrictJoins())); |
1777 connect(ui.pageNetGame->restrictJoins, SIGNAL(triggered()), hwnet, SLOT(toggleRestrictJoins())); |
1749 connect(ui.pageNetGame->restrictTeamAdds, SIGNAL(triggered()), hwnet, SLOT(toggleRestrictTeamAdds())); |
1778 connect(ui.pageNetGame->restrictTeamAdds, SIGNAL(triggered()), hwnet, SLOT(toggleRestrictTeamAdds())); |
|
1779 connect(ui.pageNetGame->restrictUnregistered, SIGNAL(triggered()), hwnet, SLOT(toggleRegisteredOnly())); |
1750 connect(ui.pageNetGame->pGameCFG->GameSchemes->model(), |
1780 connect(ui.pageNetGame->pGameCFG->GameSchemes->model(), |
1751 SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), |
1781 SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), |
1752 ui.pageNetGame->pGameCFG, |
1782 ui.pageNetGame->pGameCFG, |
1753 SLOT(resendSchemeData()) |
1783 SLOT(resendSchemeData()) |
1754 ); |
1784 ); |
1853 |
1883 |
1854 // 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] |
1884 // 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] |
1855 QString HWForm::getDemoArguments() |
1885 QString HWForm::getDemoArguments() |
1856 { |
1886 { |
1857 |
1887 |
1858 QString prefix = datadir->absolutePath(); |
1888 QString prefix = "\"" + datadir->absolutePath() + "\""; |
1859 QString userPrefix = cfgdir->absolutePath(); |
1889 QString userPrefix = "\"" + cfgdir->absolutePath() + "\""; |
1860 #ifdef Q_WS_WIN |
1890 #ifdef Q_WS_WIN |
1861 prefix = prefix.replace("/","\\"); |
1891 prefix = prefix.replace("/","\\"); |
1862 userPrefix = userPrefix.replace("/","\\"); |
1892 userPrefix = userPrefix.replace("/","\\"); |
1863 #endif |
1893 #endif |
1864 |
1894 |
1884 { |
1914 { |
1885 bool success = true; |
1915 bool success = true; |
1886 QString arguments = getDemoArguments(); |
1916 QString arguments = getDemoArguments(); |
1887 #ifdef _WIN32 |
1917 #ifdef _WIN32 |
1888 QSettings registry_hkcr("HKEY_CLASSES_ROOT", QSettings::NativeFormat); |
1918 QSettings registry_hkcr("HKEY_CLASSES_ROOT", QSettings::NativeFormat); |
|
1919 |
|
1920 // file extension(s) |
1889 registry_hkcr.setValue(".hwd/Default", "Hedgewars.Demo"); |
1921 registry_hkcr.setValue(".hwd/Default", "Hedgewars.Demo"); |
1890 registry_hkcr.setValue(".hws/Default", "Hedgewars.Save"); |
1922 registry_hkcr.setValue(".hws/Default", "Hedgewars.Save"); |
1891 registry_hkcr.setValue("Hedgewars.Demo/Default", tr("Hedgewars Demo File", "File Types")); |
1923 registry_hkcr.setValue("Hedgewars.Demo/Default", tr("Hedgewars Demo File", "File Types")); |
1892 registry_hkcr.setValue("Hedgewars.Save/Default", tr("Hedgewars Save File", "File Types")); |
1924 registry_hkcr.setValue("Hedgewars.Save/Default", tr("Hedgewars Save File", "File Types")); |
1893 registry_hkcr.setValue("Hedgewars.Demo/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwdfile.ico\",0"); |
1925 registry_hkcr.setValue("Hedgewars.Demo/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwdfile.ico\",0"); |
1894 registry_hkcr.setValue("Hedgewars.Save/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwsfile.ico\",0"); |
1926 registry_hkcr.setValue("Hedgewars.Save/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwsfile.ico\",0"); |
1895 registry_hkcr.setValue("Hedgewars.Demo/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"%1\" "+arguments); |
1927 registry_hkcr.setValue("Hedgewars.Demo/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" " + arguments + " %1"); |
1896 registry_hkcr.setValue("Hedgewars.Save/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"%1\" "+arguments); |
1928 registry_hkcr.setValue("Hedgewars.Save/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" " + arguments + " %1"); |
|
1929 |
|
1930 // custom url scheme(s) |
|
1931 registry_hkcr.setValue("hwplay/Default", "\"URL:Hedgewars ServerAccess Scheme\""); |
|
1932 registry_hkcr.setValue("hwplay/URL Protocol", ""); |
|
1933 registry_hkcr.setValue("hwplay/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hedgewars.exe\",0"); |
|
1934 registry_hkcr.setValue("hwplay/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hedgewars.exe\" %1"); |
1897 #elif defined __APPLE__ |
1935 #elif defined __APPLE__ |
1898 // only useful when other apps have taken precedence over our file extensions and you want to reset it |
1936 // only useful when other apps have taken precedence over our file extensions and you want to reset it |
1899 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>'"); |
1937 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>'"); |
1900 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>'"); |
1938 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>'"); |
1901 system("/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -domain local -domain system -domain user"); |
1939 system("/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -domain local -domain system -domain user"); |
1907 if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share/mime/packages"); |
1945 if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share/mime/packages"); |
1908 if (success) success = checkForDir(QDir::home().absolutePath() + "/.local"); |
1946 if (success) success = checkForDir(QDir::home().absolutePath() + "/.local"); |
1909 if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share"); |
1947 if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share"); |
1910 if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share/applications"); |
1948 if (success) success = checkForDir(QDir::home().absolutePath() + "/.local/share/applications"); |
1911 if (success) success = system(("cp "+datadir->absolutePath()+"/misc/hedgewars-mimeinfo.xml "+QDir::home().absolutePath()+"/.local/share/mime/packages").toLocal8Bit().constData())==0; |
1949 if (success) success = system(("cp "+datadir->absolutePath()+"/misc/hedgewars-mimeinfo.xml "+QDir::home().absolutePath()+"/.local/share/mime/packages").toLocal8Bit().constData())==0; |
|
1950 if (success) success = system(("cp "+datadir->absolutePath()+"/misc/hedgewars.desktop "+QDir::home().absolutePath()+"/.local/share/applications").toLocal8Bit().constData())==0; |
1912 if (success) success = system(("cp "+datadir->absolutePath()+"/misc/hwengine.desktop "+QDir::home().absolutePath()+"/.local/share/applications").toLocal8Bit().constData())==0; |
1951 if (success) success = system(("cp "+datadir->absolutePath()+"/misc/hwengine.desktop "+QDir::home().absolutePath()+"/.local/share/applications").toLocal8Bit().constData())==0; |
1913 if (success) success = system(("update-mime-database "+QDir::home().absolutePath()+"/.local/share/mime").toLocal8Bit().constData())==0; |
1952 if (success) success = system(("update-mime-database "+QDir::home().absolutePath()+"/.local/share/mime").toLocal8Bit().constData())==0; |
|
1953 if (success) success = system("xdg-mime default hedgewars.desktop x-scheme-handler/hwplay")==0; |
1914 if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-demo")==0; |
1954 if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-demo")==0; |
1915 if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-save")==0; |
1955 if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-save")==0; |
1916 // hack to add user's settings to hwengine. might be better at this point to read in the file, append it, and write it out to its new home. This assumes no spaces in the data dir path |
1956 // hack to add user's settings to hwengine. might be better at this point to read in the file, append it, and write it out to its new home. This assumes no spaces in the data dir path |
1917 if (success) success = system(("sed -i 's/^\\(Exec=.*\\) \\([^ ]* %f\\)/\\1 \\2 "+arguments+"/' "+QDir::home().absolutePath()+"/.local/share/applications/hwengine.desktop").toLocal8Bit().constData())==0; |
1957 if (success) success = system(("sed -i 's|^\\(Exec=.*\\) \\(%f\\)|\\1 \\2 "+arguments+"|' "+QDir::home().absolutePath()+"/.local/share/applications/hwengine.desktop").toLocal8Bit().constData())==0; |
1918 #endif |
1958 #endif |
1919 if (success) |
1959 if (success) |
1920 { |
1960 { |
1921 QMessageBox infoMsg(this); |
1961 QMessageBox infoMsg(this); |
1922 infoMsg.setIcon(QMessageBox::Information); |
1962 infoMsg.setIcon(QMessageBox::Information); |