QTfrontend/hwform.cpp
changeset 8383 b557c73a7593
parent 8380 0b375a3ceaa0
child 8384 a6e7a95f3b2e
equal deleted inserted replaced
8382:67e257b98422 8383:b557c73a7593
    94 #include "mouseoverfilter.h"
    94 #include "mouseoverfilter.h"
    95 #include "roomslistmodel.h"
    95 #include "roomslistmodel.h"
    96 #include "recorder.h"
    96 #include "recorder.h"
    97 #include "playerslistmodel.h"
    97 #include "playerslistmodel.h"
    98 
    98 
       
    99 #include "MessageDialog.h"
    99 #include "DataManager.h"
   100 #include "DataManager.h"
   100 #include "AutoUpdater.h"
   101 #include "AutoUpdater.h"
   101 
   102 
   102 #ifdef Q_WS_WIN
   103 #ifdef Q_WS_WIN
   103 #define WINVER 0x0500
   104 #define WINVER 0x0500
   959 void HWForm::DeleteScheme()
   960 void HWForm::DeleteScheme()
   960 {
   961 {
   961     ui.pageScheme->selectScheme->setCurrentIndex(ui.pageOptions->SchemesName->currentIndex());
   962     ui.pageScheme->selectScheme->setCurrentIndex(ui.pageOptions->SchemesName->currentIndex());
   962     if (ui.pageOptions->SchemesName->currentIndex() < ammoSchemeModel->numberOfDefaultSchemes)
   963     if (ui.pageOptions->SchemesName->currentIndex() < ammoSchemeModel->numberOfDefaultSchemes)
   963     {
   964     {
   964         ShowErrorMessage(QMessageBox::tr("Cannot delete default scheme '%1'!").arg(ui.pageOptions->SchemesName->currentText()));
   965         MessageDialog::ShowErrorMessage(QMessageBox::tr("Cannot delete default scheme '%1'!").arg(ui.pageOptions->SchemesName->currentText()), this);
   965     }
   966     }
   966     else
   967     else
   967     {
   968     {
   968         ui.pageScheme->deleteRow();
   969         ui.pageScheme->deleteRow();
   969         ammoSchemeModel->Save();
   970         ammoSchemeModel->Save();
   985 void HWForm::PlayDemo()
   986 void HWForm::PlayDemo()
   986 {
   987 {
   987     QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem();
   988     QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem();
   988     if (!curritem)
   989     if (!curritem)
   989     {
   990     {
   990         ShowErrorMessage(QMessageBox::tr("Please select a record from the list"));
   991         MessageDialog::ShowErrorMessage(QMessageBox::tr("Please select a record from the list"), this);
   991         return;
   992         return;
   992     }
   993     }
   993     CreateGame(0, 0, 0);
   994     CreateGame(0, 0, 0);
   994     game->PlayDemo(curritem->data(Qt::UserRole).toString(), ui.pagePlayDemo->isSave());
   995     game->PlayDemo(curritem->data(Qt::UserRole).toString(), ui.pagePlayDemo->isSave());
   995 }
   996 }
  1159 void HWForm::NetError(const QString & errmsg)
  1160 void HWForm::NetError(const QString & errmsg)
  1160 {
  1161 {
  1161     switch (ui.Pages->currentIndex())
  1162     switch (ui.Pages->currentIndex())
  1162     {
  1163     {
  1163         case ID_PAGE_INGAME:
  1164         case ID_PAGE_INGAME:
  1164             ShowErrorMessage(errmsg);
  1165             MessageDialog::ShowErrorMessage(errmsg, this);
  1165             // no break
  1166             // no break
  1166         case ID_PAGE_NETGAME:
  1167         case ID_PAGE_NETGAME:
  1167             ui.pageNetGame->displayError(errmsg);
  1168             ui.pageNetGame->displayError(errmsg);
  1168             break;
  1169             break;
  1169         default:
  1170         default:
  1436     config->SaveOptions();
  1437     config->SaveOptions();
  1437 
  1438 
  1438     pnetserver = new HWNetServer;
  1439     pnetserver = new HWNetServer;
  1439     if (!pnetserver->StartServer(ui.pageNetServer->sbPort->value()))
  1440     if (!pnetserver->StartServer(ui.pageNetServer->sbPort->value()))
  1440     {
  1441     {
  1441         ShowErrorMessage(QMessageBox::tr("Unable to start server"));
  1442         MessageDialog::ShowErrorMessage(QMessageBox::tr("Unable to start server"), this);
  1442 
  1443 
  1443         delete pnetserver;
  1444         delete pnetserver;
  1444         pnetserver = 0;
  1445         pnetserver = 0;
  1445         return;
  1446         return;
  1446     }
  1447     }
  1495     if (pnetserver)
  1496     if (pnetserver)
  1496         return; // we have server - let it care of all things
  1497         return; // we have server - let it care of all things
  1497     if (hwnet)
  1498     if (hwnet)
  1498     {
  1499     {
  1499         QString errorStr = QMessageBox::tr("Connection to server is lost") + (reason.isEmpty()?"":("\n\n" + HWNewNet::tr("Quit reason: ") + '"' + reason +'"'));
  1500         QString errorStr = QMessageBox::tr("Connection to server is lost") + (reason.isEmpty()?"":("\n\n" + HWNewNet::tr("Quit reason: ") + '"' + reason +'"'));
  1500         ShowErrorMessage(errorStr);
  1501         MessageDialog::ShowErrorMessage(errorStr, this);
  1501     }
  1502     }
  1502 
  1503 
  1503     while (ui.Pages->currentIndex() != ID_PAGE_NET
  1504     while (ui.Pages->currentIndex() != ID_PAGE_NET
  1504         && ui.Pages->currentIndex() != ID_PAGE_MAIN)
  1505         && ui.Pages->currentIndex() != ID_PAGE_MAIN)
  1505     {
  1506     {
  1601     connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
  1602     connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
  1602     connect(game, SIGNAL(HaveRecord(RecordType, const QByteArray &)), this, SLOT(GetRecord(RecordType, const QByteArray &)));
  1603     connect(game, SIGNAL(HaveRecord(RecordType, const QByteArray &)), this, SLOT(GetRecord(RecordType, const QByteArray &)));
  1603     m_lastDemo = QByteArray();
  1604     m_lastDemo = QByteArray();
  1604 }
  1605 }
  1605 
  1606 
  1606 void HWForm::ShowErrorMessage(const QString & msg)
       
  1607 {
       
  1608     QMessageBox msgMsg(this);
       
  1609     msgMsg.setIcon(QMessageBox::Warning);
       
  1610     msgMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Error"));
       
  1611     msgMsg.setText(msg);
       
  1612     msgMsg.setWindowModality(Qt::WindowModal);
       
  1613     msgMsg.exec();
       
  1614 }
       
  1615 
       
  1616 void HWForm::GetRecord(RecordType type, const QByteArray & record)
  1607 void HWForm::GetRecord(RecordType type, const QByteArray & record)
  1617 {
  1608 {
  1618     if (type != rtNeither)
  1609     if (type != rtNeither)
  1619     {
  1610     {
  1620         QString filename;
  1611         QString filename;
  1643             filename = cfgdir->absolutePath() + "/Saves/" + recordFileName + "." + *cProtoVer + ".hws";
  1634             filename = cfgdir->absolutePath() + "/Saves/" + recordFileName + "." + *cProtoVer + ".hws";
  1644         }
  1635         }
  1645 
  1636 
  1646         QFile demofile(filename);
  1637         QFile demofile(filename);
  1647         if (!demofile.open(QIODevice::WriteOnly))
  1638         if (!demofile.open(QIODevice::WriteOnly))
  1648             ShowErrorMessage(tr("Cannot save record to file %1").arg(filename));
  1639             MessageDialog::ShowErrorMessage(tr("Cannot save record to file %1").arg(filename), this);
  1649         else
  1640         else
  1650         {
  1641         {
  1651             demofile.write(demo);
  1642             demofile.write(demo);
  1652             demofile.close();
  1643             demofile.close();
  1653         }
  1644         }
  1924         infoMsg.setText(QMessageBox::tr("All file associations have been set"));
  1915         infoMsg.setText(QMessageBox::tr("All file associations have been set"));
  1925         infoMsg.setWindowModality(Qt::WindowModal);
  1916         infoMsg.setWindowModality(Qt::WindowModal);
  1926         infoMsg.exec();
  1917         infoMsg.exec();
  1927     }
  1918     }
  1928     else
  1919     else
  1929         ShowErrorMessage(QMessageBox::tr("File association failed."));
  1920         MessageDialog::ShowErrorMessage(QMessageBox::tr("File association failed."), this);
  1930 }
  1921 }
  1931 
  1922 
  1932 void HWForm::openRegistrationPage() 
  1923 void HWForm::openRegistrationPage() 
  1933 {
  1924 {
  1934     QDesktopServices::openUrl(QUrl("http://www.hedgewars.org/user/register"));
  1925     QDesktopServices::openUrl(QUrl("http://www.hedgewars.org/user/register"));
  1948             {
  1939             {
  1949                 QString filePath = cfgdir->absolutePath() + "/Demos/" + fileName + "." + *cProtoVer + ".hwd";
  1940                 QString filePath = cfgdir->absolutePath() + "/Demos/" + fileName + "." + *cProtoVer + ".hwd";
  1950                 QFile demofile(filePath);
  1941                 QFile demofile(filePath);
  1951                 ok = demofile.open(QIODevice::WriteOnly);
  1942                 ok = demofile.open(QIODevice::WriteOnly);
  1952                 if (!ok)
  1943                 if (!ok)
  1953                     ShowErrorMessage(tr("Cannot save record to file %1").arg(filePath));
  1944                     MessageDialog::ShowErrorMessage(tr("Cannot save record to file %1").arg(filePath), this);
  1954                 else
  1945                 else
  1955                 {
  1946                 {
  1956                     ok = -1 != demofile.write(m_lastDemo);
  1947                     ok = -1 != demofile.write(m_lastDemo);
  1957                     demofile.close();
  1948                     demofile.close();
  1958                 }
  1949                 }
  1973     QString captchaID = QString::number(ui.pageFeedback->captchaID);
  1964     QString captchaID = QString::number(ui.pageFeedback->captchaID);
  1974     QString version = "HedgewarsFoundation-Hedgewars-" + (cVersionString?(*cVersionString):QString(""));
  1965     QString version = "HedgewarsFoundation-Hedgewars-" + (cVersionString?(*cVersionString):QString(""));
  1975 
  1966 
  1976     if (summary.isEmpty() || description.isEmpty())
  1967     if (summary.isEmpty() || description.isEmpty())
  1977     {
  1968     {
  1978         ShowErrorMessage(QMessageBox::tr("Please fill out all fields. Email is optional."));
  1969         MessageDialog::ShowErrorMessage(QMessageBox::tr("Please fill out all fields. Email is optional."), this);
  1979         return;
  1970         return;
  1980     }
  1971     }
  1981 
  1972 
  1982     // Submit issue to PHP script
  1973     // Submit issue to PHP script
  1983     
  1974     
  2028             
  2019             
  2029             return;
  2020             return;
  2030     }
  2021     }
  2031     else
  2022     else
  2032     {
  2023     {
  2033         ShowErrorMessage(QString("Error: ") + reply->readAll());
  2024         MessageDialog::ShowErrorMessage(QString("Error: ") + reply->readAll(), this);
  2034         ui.pageFeedback->LoadCaptchaImage();
  2025         ui.pageFeedback->LoadCaptchaImage();
  2035     }
  2026     }
  2036 }
  2027 }
  2037 
  2028 
       
  2029 void HWForm::ShowErrorMessage(const QString & msg)
       
  2030 {
       
  2031     MessageDialog::ShowErrorMessage(msg, this);
       
  2032 }