QTfrontend/hwform.cpp
branchphysfslayer
changeset 7928 88fde28bbda6
parent 7917 00415e77fa2a
child 7927 a96614777ce6
equal deleted inserted replaced
7778:3331b30e4ef1 7928:88fde28bbda6
   161     connect (hideFrontend, SIGNAL(activated()), this, SLOT(showMinimized()));
   161     connect (hideFrontend, SIGNAL(activated()), this, SLOT(showMinimized()));
   162 #else
   162 #else
   163     // ctrl+q closes frontend for consistency
   163     // ctrl+q closes frontend for consistency
   164     QShortcut * closeFrontend = new QShortcut(QKeySequence("Ctrl+Q"), this);
   164     QShortcut * closeFrontend = new QShortcut(QKeySequence("Ctrl+Q"), this);
   165     connect (closeFrontend, SIGNAL(activated()), this, SLOT(close()));
   165     connect (closeFrontend, SIGNAL(activated()), this, SLOT(close()));
   166     QShortcut * updateData = new QShortcut(QKeySequence("F5"), this);
   166     //QShortcut * updateData = new QShortcut(QKeySequence("F5"), this);
   167     connect (updateData, SIGNAL(activated()), &DataManager::instance(), SLOT(reload()));
   167     //connect (updateData, SIGNAL(activated()), &DataManager::instance(), SLOT(reload()));
   168 #endif
   168 #endif
   169 
   169 
   170     UpdateTeamsLists();
   170     UpdateTeamsLists();
   171     InitCampaignPage();
   171     InitCampaignPage();
   172     UpdateCampaignPage(0);
   172     UpdateCampaignPage(0);
   200     pageSwitchMapper->setMapping(ui.pageMain->BtnInfo, ID_PAGE_INFO);
   200     pageSwitchMapper->setMapping(ui.pageMain->BtnInfo, ID_PAGE_INFO);
   201 
   201 
   202     connect(ui.pageMain->BtnDataDownload, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   202     connect(ui.pageMain->BtnDataDownload, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   203     pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD);
   203     pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD);
   204 
   204 
   205     connect(ui.pageNetGame, SIGNAL(DLCClicked()), pageSwitchMapper, SLOT(map()));
       
   206     pageSwitchMapper->setMapping(ui.pageNetGame, ID_PAGE_DATADOWNLOAD);
       
   207 
   205 
   208 #ifdef VIDEOREC
   206 #ifdef VIDEOREC
   209     connect(ui.pageMain->BtnVideos, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   207     connect(ui.pageMain->BtnVideos, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   210     pageSwitchMapper->setMapping(ui.pageMain->BtnVideos, ID_PAGE_VIDEOS);
   208     pageSwitchMapper->setMapping(ui.pageMain->BtnVideos, ID_PAGE_VIDEOS);
   211 #endif
   209 #endif
   691         animationOldOpacity->setStartValue(1);
   689         animationOldOpacity->setStartValue(1);
   692         animationOldOpacity->setEndValue(0.01);
   690         animationOldOpacity->setEndValue(0.01);
   693         animationOldOpacity->setEasingCurve(QEasingCurve::OutExpo);
   691         animationOldOpacity->setEasingCurve(QEasingCurve::OutExpo);
   694 #endif
   692 #endif
   695 
   693 
   696         QParallelAnimationGroup *group = new QParallelAnimationGroup;
   694         // let's hide the old slide after its animation has finished
   697         group->addAnimation(animationOldSlide);
       
   698         group->addAnimation(animationNewSlide);
       
   699 #ifdef false
       
   700         group->addAnimation(animationOldOpacity);
       
   701         group->addAnimation(animationNewOpacity);
       
   702 #endif
       
   703         group->start();
       
   704 
       
   705         connect(animationOldSlide, SIGNAL(finished()), ui.Pages->widget(lastid), SLOT(hide()));
   695         connect(animationOldSlide, SIGNAL(finished()), ui.Pages->widget(lastid), SLOT(hide()));
       
   696 
       
   697         // start animations
       
   698         animationOldSlide->start(QAbstractAnimation::DeleteWhenStopped);
       
   699         animationNewSlide->start(QAbstractAnimation::DeleteWhenStopped);
       
   700 
   706     	/* this is for the situation when the animation below is interrupted by a new animation.  For some reason, finished is not being fired */ 	
   701     	/* this is for the situation when the animation below is interrupted by a new animation.  For some reason, finished is not being fired */ 	
   707     	for(int i=0;i<MAX_PAGE;i++) if (i!=id && i!=lastid) ui.Pages->widget(i)->hide();
   702     	for(int i=0;i<MAX_PAGE;i++) if (i!=id && i!=lastid) ui.Pages->widget(i)->hide();
   708     }
   703     }
   709 #endif
   704 #endif
   710 }
   705 }
   804         animationNewOpacity->setStartValue(0.01);
   799         animationNewOpacity->setStartValue(0.01);
   805         animationNewOpacity->setEndValue(1);
   800         animationNewOpacity->setEndValue(1);
   806         animationNewOpacity->setEasingCurve(QEasingCurve::OutExpo);
   801         animationNewOpacity->setEasingCurve(QEasingCurve::OutExpo);
   807 #endif
   802 #endif
   808 
   803 
   809         QParallelAnimationGroup *group = new QParallelAnimationGroup;
   804         // let's hide the old slide after its animation has finished
   810         group->addAnimation(animationOldSlide);
       
   811         group->addAnimation(animationNewSlide);
       
   812 #ifdef false
       
   813         group->addAnimation(animationOldOpacity);
       
   814         group->addAnimation(animationNewOpacity);
       
   815 #endif
       
   816         group->start();
       
   817 
       
   818         connect(animationNewSlide, SIGNAL(finished()), ui.Pages->widget(curid), SLOT(hide()));
   805         connect(animationNewSlide, SIGNAL(finished()), ui.Pages->widget(curid), SLOT(hide()));
   819     }
   806 
   820 #endif
   807         // start animations
       
   808         animationOldSlide->start(QAbstractAnimation::DeleteWhenStopped);
       
   809         animationNewSlide->start(QAbstractAnimation::DeleteWhenStopped);
       
   810     }
       
   811 #endif
       
   812 
       
   813     if (stopAnim)
       
   814         ui.Pages->widget(curid)->hide();
       
   815 
       
   816 // TODO the whole pages shown and effects stuff should be moved
       
   817 // out of hwform.cpp and into a subclass of QStackedLayout
       
   818 
   821 }
   819 }
   822 
   820 
   823 void HWForm::OpenSnapshotFolder()
   821 void HWForm::OpenSnapshotFolder()
   824 {
   822 {
   825     QString path = QDir::toNativeSeparators(cfgdir->absolutePath() + "/Screenshots");
   823     QString path = QDir::toNativeSeparators(cfgdir->absolutePath() + "/Screenshots");
   895 }
   893 }
   896 
   894 
   897 
   895 
   898 void HWForm::DeleteTeam(const QString & teamName)
   896 void HWForm::DeleteTeam(const QString & teamName)
   899 {
   897 {
   900     ui.pageEditTeam->deleteTeam(teamName);
   898     QMessageBox reallyDeleteMsg(this);
   901     QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Teams"), QMessageBox::tr("Really delete this team?"), QMessageBox::Ok | QMessageBox::Cancel);
   899     reallyDeleteMsg.setIcon(QMessageBox::Question);
   902 
   900     reallyDeleteMsg.setWindowTitle(QMessageBox::tr("Teams - Are you sure?"));
   903     UpdateTeamsLists();
   901     reallyDeleteMsg.setText(QMessageBox::tr("Do you really want to delete the team '%1'?").arg(teamName));
       
   902     reallyDeleteMsg.setWindowModality(Qt::WindowModal);
       
   903     reallyDeleteMsg.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
       
   904 
       
   905     if (reallyDeleteMsg.exec() == QMessageBox::Ok)
       
   906     {
       
   907         ui.pageEditTeam->deleteTeam(teamName);
       
   908         UpdateTeamsLists();
       
   909     }
   904 }
   910 }
   905 
   911 
   906 void HWForm::DeleteScheme()
   912 void HWForm::DeleteScheme()
   907 {
   913 {
   908     ui.pageScheme->selectScheme->setCurrentIndex(ui.pageOptions->SchemesName->currentIndex());
   914     ui.pageScheme->selectScheme->setCurrentIndex(ui.pageOptions->SchemesName->currentIndex());
   909     if (ui.pageOptions->SchemesName->currentIndex() < ammoSchemeModel->numberOfDefaultSchemes)
   915     if (ui.pageOptions->SchemesName->currentIndex() < ammoSchemeModel->numberOfDefaultSchemes)
   910     {
   916     {
   911         QMessageBox::warning(0, QMessageBox::tr("Schemes"), QMessageBox::tr("Can not delete default scheme '%1'!").arg(ui.pageOptions->SchemesName->currentText()));
   917         ShowErrorMessage(QMessageBox::tr("Cannot delete default scheme '%1'!").arg(ui.pageOptions->SchemesName->currentText()));
   912     }
   918     }
   913     else
   919     else
   914     {
   920     {
   915         ui.pageScheme->deleteRow();
   921         ui.pageScheme->deleteRow();
   916         ammoSchemeModel->Save();
   922         ammoSchemeModel->Save();
   932 void HWForm::PlayDemo()
   938 void HWForm::PlayDemo()
   933 {
   939 {
   934     QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem();
   940     QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem();
   935     if (!curritem)
   941     if (!curritem)
   936     {
   942     {
   937         QMessageBox::critical(this,
   943         ShowErrorMessage(QMessageBox::tr("Please select a record from the list"));
   938                               tr("Error"),
       
   939                               tr("Please select record from the list above"),
       
   940                               tr("OK"));
       
   941         return;
   944         return;
   942     }
   945     }
   943     CreateGame(0, 0, 0);
   946     CreateGame(0, 0, 0);
   944     game->PlayDemo(curritem->data(Qt::UserRole).toString(), ui.pagePlayDemo->isSave());
   947     game->PlayDemo(curritem->data(Qt::UserRole).toString(), ui.pagePlayDemo->isSave());
   945 }
   948 }
   999 }
  1002 }
  1000 
  1003 
  1001 void HWForm::NetNickTaken(const QString & nick)
  1004 void HWForm::NetNickTaken(const QString & nick)
  1002 {
  1005 {
  1003     bool ok = false;
  1006     bool ok = false;
  1004     QString newNick = QInputDialog::getText(this, tr("Nickname"), tr("Some one already uses\n your nickname %1\non the server.\nPlease pick another nickname:").arg(nick), QLineEdit::Normal, nick, &ok);
  1007     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 
  1008 
  1006     if (!ok || newNick.isEmpty())
  1009     if (!ok || newNick.isEmpty())
  1007     {
  1010     {
  1008         ForcedDisconnect(tr("No nickname supplied."));
  1011         ForcedDisconnect(tr("No nickname supplied."));
  1009         return;
  1012         return;
  1227 void HWForm::NetStartServer()
  1230 void HWForm::NetStartServer()
  1228 {
  1231 {
  1229     config->SaveOptions();
  1232     config->SaveOptions();
  1230 
  1233 
  1231     pnetserver = new HWNetServer;
  1234     pnetserver = new HWNetServer;
  1232     if(!pnetserver->StartServer(ui.pageNetServer->sbPort->value()))
  1235     if (!pnetserver->StartServer(ui.pageNetServer->sbPort->value()))
  1233     {
  1236     {
  1234         QMessageBox::critical(0, tr("Error"),
  1237         ShowErrorMessage(QMessageBox::tr("Unable to start server"));
  1235                               tr("Unable to start the server"));
  1238 
  1236         delete pnetserver;
  1239         delete pnetserver;
  1237         pnetserver = 0;
  1240         pnetserver = 0;
  1238         return;
  1241         return;
  1239     }
  1242     }
  1240 
  1243 
  1269         hwnet->Disconnect();
  1272         hwnet->Disconnect();
  1270 }
  1273 }
  1271 
  1274 
  1272 void HWForm::ForcedDisconnect(const QString & reason)
  1275 void HWForm::ForcedDisconnect(const QString & reason)
  1273 {
  1276 {
  1274     if(pnetserver) return; // we have server - let it care of all things
  1277     if (pnetserver)
       
  1278         return; // we have server - let it care of all things
  1275     if (hwnet)
  1279     if (hwnet)
  1276     {
  1280     {
  1277         QMessageBox::warning(this, QMessageBox::tr("Network"),
  1281         QString errorStr = QMessageBox::tr("Connection to server is lost") + (reason.isEmpty()?"":("\n\n" + HWNewNet::tr("Quit reason: ") + '"' + reason +'"'));
  1278                              QMessageBox::tr("Connection to server is lost") + (reason.isEmpty()?"":("\n\n" + HWNewNet::tr("Quit reason: ") + '"' + reason +'"')));
  1282         ShowErrorMessage(errorStr);
  1279 
  1283     }
  1280     }
  1284 
  1281     if (ui.Pages->currentIndex() != ID_PAGE_NET) GoBack();
  1285     while (ui.Pages->currentIndex() != ID_PAGE_NET
       
  1286         && ui.Pages->currentIndex() != ID_PAGE_NETTYPE
       
  1287         && ui.Pages->currentIndex() != ID_PAGE_MAIN)
       
  1288     {
       
  1289         GoBack();
       
  1290     }
  1282 }
  1291 }
  1283 
  1292 
  1284 void HWForm::NetConnected()
  1293 void HWForm::NetConnected()
  1285 {
  1294 {
  1286     GoToPage(ID_PAGE_ROOMSLIST);
  1295     GoToPage(ID_PAGE_ROOMSLIST);
  1377     m_lastDemo = QByteArray();
  1386     m_lastDemo = QByteArray();
  1378 }
  1387 }
  1379 
  1388 
  1380 void HWForm::ShowErrorMessage(const QString & msg)
  1389 void HWForm::ShowErrorMessage(const QString & msg)
  1381 {
  1390 {
  1382     QMessageBox::warning(this,
  1391     QMessageBox msgMsg(this);
  1383                          "Hedgewars",
  1392     msgMsg.setIcon(QMessageBox::Warning);
  1384                          msg);
  1393     msgMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Error"));
       
  1394     msgMsg.setText(msg);
       
  1395     msgMsg.setWindowModality(Qt::WindowModal);
       
  1396     msgMsg.exec();
  1385 }
  1397 }
  1386 
  1398 
  1387 void HWForm::GetRecord(RecordType type, const QByteArray & record)
  1399 void HWForm::GetRecord(RecordType type, const QByteArray & record)
  1388 {
  1400 {
  1389     if (type != rtNeither)
  1401     if (type != rtNeither)
  1672     if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-demo")==0;
  1684     if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-demo")==0;
  1673     if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-save")==0;
  1685     if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-save")==0;
  1674     // 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
  1686     // 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
  1675     if (success) success = system(("sed -i 's/^\\(Exec=.*\\) \\([^ ]* %f\\)/\\1 "+cfgdir->absolutePath().replace(" ","\\\\ ").replace("/","\\/")+" \\2 --set-everything "+arguments+"/' "+QDir::home().absolutePath()+"/.local/share/applications/hwengine.desktop").toLocal8Bit().constData())==0;
  1687     if (success) success = system(("sed -i 's/^\\(Exec=.*\\) \\([^ ]* %f\\)/\\1 "+cfgdir->absolutePath().replace(" ","\\\\ ").replace("/","\\/")+" \\2 --set-everything "+arguments+"/' "+QDir::home().absolutePath()+"/.local/share/applications/hwengine.desktop").toLocal8Bit().constData())==0;
  1676 #endif
  1688 #endif
  1677     if (success) QMessageBox::information(0, "", QMessageBox::tr("All file associations have been set."));
  1689     if (success)
  1678     else QMessageBox::information(0, "", QMessageBox::tr("File association failed."));
  1690     {
       
  1691         QMessageBox infoMsg(this);
       
  1692         infoMsg.setIcon(QMessageBox::Information);
       
  1693         infoMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Success"));
       
  1694         infoMsg.setText(QMessageBox::tr("All file associations have been set"));
       
  1695         infoMsg.setWindowModality(Qt::WindowModal);
       
  1696         infoMsg.exec();
       
  1697     }
       
  1698     else
       
  1699         ShowErrorMessage(QMessageBox::tr("File association failed."));
  1679 }
  1700 }
  1680 
  1701 
  1681 void HWForm::saveDemoWithCustomName()
  1702 void HWForm::saveDemoWithCustomName()
  1682 {
  1703 {
  1683     if(!m_lastDemo.isEmpty())
  1704     if(!m_lastDemo.isEmpty())
  1709 void HWForm::SendFeedback()
  1730 void HWForm::SendFeedback()
  1710 {
  1731 {
  1711     //Create Xml representation of google code issue first
  1732     //Create Xml representation of google code issue first
  1712     if (!CreateIssueXml())
  1733     if (!CreateIssueXml())
  1713     {
  1734     {
  1714         QMessageBox::warning(this, QMessageBox::tr("Fields required"),
  1735         ShowErrorMessage(QMessageBox::tr("Please fill out all fields"));
  1715                              QMessageBox::tr("Please fill out all fields"));
       
  1716         return;
  1736         return;
  1717     }
  1737     }
  1718 
  1738 
  1719     //Google login using fake account (feedback.hedgewars@gmail.com)
  1739     //Google login using fake account (feedback.hedgewars@gmail.com)
  1720     nam = new QNetworkAccessManager(this);
  1740     nam = new QNetworkAccessManager(this);
  1756         QByteArray array = reply->readAll();
  1776         QByteArray array = reply->readAll();
  1757         QString str(array);
  1777         QString str(array);
  1758 
  1778 
  1759         if (authToken.length() != 0)
  1779         if (authToken.length() != 0)
  1760         {
  1780         {
  1761             QMessageBox::information(this, QMessageBox::tr("Success"),
  1781 
  1762                                      QMessageBox::tr("Successfully posted the issue on code.google.com!"));
  1782             QMessageBox infoMsg(this);
       
  1783             infoMsg.setIcon(QMessageBox::Information);
       
  1784             infoMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Success"));
       
  1785             infoMsg.setText(QMessageBox::tr("Successfully posted the issue on hedgewars.googlecode.com"));
       
  1786             infoMsg.setWindowModality(Qt::WindowModal);
       
  1787             infoMsg.exec();
       
  1788 
  1763             ui.pageFeedback->summary->clear();
  1789             ui.pageFeedback->summary->clear();
  1764             ui.pageFeedback->description->clear();
  1790             ui.pageFeedback->description->clear();
  1765             authToken = "";
  1791             authToken = "";
  1766             return;
  1792             return;
  1767         }
  1793         }
  1768 
  1794 
  1769         if(!getAuthToken(str))
  1795         if (!getAuthToken(str))
  1770         {
  1796         {
  1771             QMessageBox::warning(this, QMessageBox::tr("Network"),
  1797             ShowErrorMessage(QMessageBox::tr("Error during authentication at google.com"));
  1772                                  QMessageBox::tr("Error during authentication with www.google.com"));
       
  1773             return;
  1798             return;
  1774         }
  1799         }
  1775 
  1800 
  1776         QByteArray body(issueXml.toUtf8());
  1801         QByteArray body(issueXml.toUtf8());
  1777         QNetworkRequest header(QUrl("https://code.google.com/feeds/issues/p/hedgewars/issues/full"));
  1802         QNetworkRequest header(QUrl("https://code.google.com/feeds/issues/p/hedgewars/issues/full"));
  1780         header.setRawHeader("Authorization", QString("GoogleLogin auth=%1").arg(authToken).toUtf8());
  1805         header.setRawHeader("Authorization", QString("GoogleLogin auth=%1").arg(authToken).toUtf8());
  1781         nam->post(header, body);
  1806         nam->post(header, body);
  1782 
  1807 
  1783     }
  1808     }
  1784     else if (authToken.length() == 0)
  1809     else if (authToken.length() == 0)
  1785         QMessageBox::warning(this, QMessageBox::tr("Network"),
  1810         ShowErrorMessage(QMessageBox::tr("Error during authentication at google.com"));
  1786                              QMessageBox::tr("Error during authentication with www.google.com"));
       
  1787     else
  1811     else
  1788     {
  1812     {
  1789         QMessageBox::warning(this, QMessageBox::tr("Network"),
  1813         ShowErrorMessage(QMessageBox::tr("Error reporting the issue, please try again later (or visit hedgewars.googlecode.com directly)"));
  1790                              QMessageBox::tr("Error creating the issue"));
       
  1791         authToken = "";
  1814         authToken = "";
  1792     }
  1815     }
  1793 
  1816 
  1794 }
  1817 }
  1795 
  1818