QTfrontend/hwform.cpp
branchflibqtfrontend
changeset 8363 0b4ac686fc44
parent 8304 620560c89284
parent 8357 d7bef04c99d4
equal deleted inserted replaced
8306:50fe80adbfcb 8363:0b4ac686fc44
    37 #include <QTableView>
    37 #include <QTableView>
    38 #include <QCryptographicHash>
    38 #include <QCryptographicHash>
    39 #include <QSignalMapper>
    39 #include <QSignalMapper>
    40 #include <QShortcut>
    40 #include <QShortcut>
    41 #include <QDesktopServices>
    41 #include <QDesktopServices>
       
    42 #include <QDesktopWidget>
       
    43 #include <QApplication>
    42 #include <QInputDialog>
    44 #include <QInputDialog>
    43 #include <QPropertyAnimation>
    45 #include <QPropertyAnimation>
    44 #include <QSettings>
    46 #include <QSettings>
    45 
    47 
    46 #if (QT_VERSION >= 0x040600)
    48 #if (QT_VERSION >= 0x040600)
    71 #include "pagenet.h"
    73 #include "pagenet.h"
    72 #include "pagemain.h"
    74 #include "pagemain.h"
    73 #include "pagefeedback.h"
    75 #include "pagefeedback.h"
    74 #include "pagenetserver.h"
    76 #include "pagenetserver.h"
    75 #include "pagedrawmap.h"
    77 #include "pagedrawmap.h"
    76 #include "pagenettype.h"
       
    77 #include "pagegamestats.h"
    78 #include "pagegamestats.h"
    78 #include "pageplayrecord.h"
    79 #include "pageplayrecord.h"
    79 #include "pagedata.h"
    80 #include "pagedata.h"
    80 #include "pagevideos.h"
    81 #include "pagevideos.h"
    81 #include "hwconsts.h"
    82 #include "hwconsts.h"
    96 #include "playerslistmodel.h"
    97 #include "playerslistmodel.h"
    97 
    98 
    98 #include "DataManager.h"
    99 #include "DataManager.h"
    99 #include "AutoUpdater.h"
   100 #include "AutoUpdater.h"
   100 
   101 
       
   102 #ifdef Q_WS_WIN
       
   103 #define WINVER 0x0500
       
   104 #include <windows.h>
       
   105 #else
       
   106 #include <unistd.h>
       
   107 #include <sys/types.h>
       
   108 #endif
       
   109 
       
   110 #ifdef Q_WS_MAC
       
   111 #include <sys/sysctl.h>
       
   112 #endif
       
   113 
   101 #ifdef __APPLE__
   114 #ifdef __APPLE__
   102 #include "M3Panel.h"
   115 #include "M3Panel.h"
   103 #ifdef SPARKLE_ENABLED
   116 #ifdef SPARKLE_ENABLED
   104 #include "SparkleAutoUpdater.h"
   117 #include "SparkleAutoUpdater.h"
   105 #endif
   118 #endif
   142     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());
   143 
   156 
   144     ui.pageRoomsList->setSettings(config);
   157     ui.pageRoomsList->setSettings(config);
   145     ui.pageNetGame->chatWidget->setSettings(config);
   158     ui.pageNetGame->chatWidget->setSettings(config);
   146     ui.pageRoomsList->chatWidget->setSettings(config);
   159     ui.pageRoomsList->chatWidget->setSettings(config);
       
   160     ui.pageOptions->setConfig(config);
   147 #ifdef VIDEOREC
   161 #ifdef VIDEOREC
   148     ui.pageVideos->init(config);
   162     ui.pageVideos->init(config);
   149     ui.pageOptions->setConfig(config);
       
   150 #endif
   163 #endif
   151 
   164 
   152 #ifdef __APPLE__
   165 #ifdef __APPLE__
   153     AutoUpdater* updater = NULL;
   166     AutoUpdater* updater = NULL;
   154     if (config->isAutoUpdateEnabled())
   167     if (config->isAutoUpdateEnabled())
   203     pageSwitchMapper->setMapping(ui.pageMain->BtnSetup, ID_PAGE_SETUP);
   216     pageSwitchMapper->setMapping(ui.pageMain->BtnSetup, ID_PAGE_SETUP);
   204 
   217 
   205     connect(ui.pageMain->BtnFeedback, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   218     connect(ui.pageMain->BtnFeedback, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   206     pageSwitchMapper->setMapping(ui.pageMain->BtnFeedback, ID_PAGE_FEEDBACK);
   219     pageSwitchMapper->setMapping(ui.pageMain->BtnFeedback, ID_PAGE_FEEDBACK);
   207 
   220 
   208     connect(ui.pageMain->BtnNet, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
       
   209     pageSwitchMapper->setMapping(ui.pageMain->BtnNet, ID_PAGE_NETTYPE);
       
   210 
       
   211     connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   221     connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   212     pageSwitchMapper->setMapping(ui.pageMain->BtnInfo, ID_PAGE_INFO);
   222     pageSwitchMapper->setMapping(ui.pageMain->BtnInfo, ID_PAGE_INFO);
   213 
   223 
   214     connect(ui.pageMain->BtnDataDownload, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   224     connect(ui.pageMain->BtnDataDownload, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   215     pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD);
   225     pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD);
   304             this, SLOT(UpdateWeapons())); // executed second
   314             this, SLOT(UpdateWeapons())); // executed second
   305     //connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()),
   315     //connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()),
   306     //    this, SLOT(GoBack())); // executed third
   316     //    this, SLOT(GoBack())); // executed third
   307 
   317 
   308 
   318 
   309     connect(ui.pageNetType->BtnLAN, SIGNAL(clicked()), this, SLOT(GoToNet()));
   319     connect(ui.pageMain->BtnNetLocal, SIGNAL(clicked()), this, SLOT(GoToNet()));
   310     connect(ui.pageNetType->BtnOfficialServer, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer()));
   320     connect(ui.pageMain->BtnNetOfficial, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer()));
   311 
   321 
   312     connect(ui.pageConnecting, SIGNAL(cancelConnection()), this, SLOT(GoBack()));
   322     connect(ui.pageConnecting, SIGNAL(cancelConnection()), this, SLOT(GoBack()));
   313 
   323 
   314     connect(ui.pageVideos, SIGNAL(goBack()), config, SLOT(SaveVideosOptions()));
   324     connect(ui.pageVideos, SIGNAL(goBack()), config, SLOT(SaveVideosOptions()));
   315 
   325 
   543 void HWForm::GoToVideos()
   553 void HWForm::GoToVideos()
   544 {
   554 {
   545     GoToPage(ID_PAGE_VIDEOS);
   555     GoToPage(ID_PAGE_VIDEOS);
   546 }
   556 }
   547 
   557 
       
   558 //TODO: maybe find a better place for this?
       
   559 QString HWForm::stringifyPageId(quint32 id)
       
   560 {
       
   561     QString pageName;
       
   562     switch (id)
       
   563     {
       
   564       case ID_PAGE_SETUP_TEAM :   pageName = "PAGE_SETUP_TEAM"; break;
       
   565       case ID_PAGE_SETUP :        pageName = "PAGE_SETUP"; break;
       
   566       case ID_PAGE_MULTIPLAYER :  pageName = "PAGE_MULTIPLAYER"; break;
       
   567       case ID_PAGE_DEMOS :        pageName = "PAGE_DEMOS"; break;
       
   568       case ID_PAGE_NET :          pageName = "PAGE_NET"; break;
       
   569       case ID_PAGE_NETGAME :      pageName = "PAGE_NETGAME"; break;
       
   570       case ID_PAGE_INFO :         pageName = "PAGE_INFO"; break;
       
   571       case ID_PAGE_MAIN :         pageName = "PAGE_MAIN"; break;
       
   572       case ID_PAGE_GAMESTATS :    pageName = "PAGE_GAMESTATS"; break;
       
   573       case ID_PAGE_SINGLEPLAYER : pageName = "PAGE_SINGLEPLAYER"; break;
       
   574       case ID_PAGE_TRAINING :     pageName = "PAGE_TRAINING"; break;
       
   575       case ID_PAGE_SELECTWEAPON : pageName = "PAGE_SELECTWEAPON"; break;
       
   576       case ID_PAGE_NETSERVER :    pageName = "PAGE_NETSERVER"; break;
       
   577       case ID_PAGE_INGAME :       pageName = "PAGE_INGAME"; break;
       
   578       case ID_PAGE_ROOMSLIST :    pageName = "PAGE_ROOMSLIST"; break;
       
   579       case ID_PAGE_CONNECTING :   pageName = "PAGE_CONNECTING"; break;
       
   580       case ID_PAGE_SCHEME :       pageName = "PAGE_SCHEME"; break;
       
   581       case ID_PAGE_ADMIN :        pageName = "PAGE_ADMIN"; break;
       
   582       case ID_PAGE_CAMPAIGN :     pageName = "PAGE_CAMPAIGN"; break;
       
   583       case ID_PAGE_DRAWMAP :      pageName = "PAGE_DRAWMAP"; break;
       
   584       case ID_PAGE_DATADOWNLOAD : pageName = "PAGE_DATADOWNLOAD"; break;
       
   585       case ID_PAGE_FEEDBACK :     pageName = "PAGE_FEEDBACK"; break;
       
   586       case ID_PAGE_VIDEOS :       pageName = "PAGE_VIDEOS"; break;
       
   587       case MAX_PAGE :             pageName = "MAX_PAGE"; break;
       
   588       default :                   pageName = "UNKNOWN_PAGE"; break;
       
   589     }
       
   590     return pageName;
       
   591 }
       
   592 
   548 void HWForm::OnPageShown(quint8 id, quint8 lastid)
   593 void HWForm::OnPageShown(quint8 id, quint8 lastid)
   549 {
   594 {
   550 #ifdef USE_XFIRE
   595 #ifdef USE_XFIRE
   551     updateXfire();
   596     updateXfire();
   552 #endif
   597 #endif
   553     
   598     
   554     QString openPrefix = "Debug:   (PAGE_OPENED: ";
   599     qDebug("Leaving %s, entering %s", qPrintable(stringifyPageId(lastid)), qPrintable(stringifyPageId(id)));
   555     QString openSuffix = ")";
   600 
   556     QString closePrefix = "Debug:   (PAGE_LEFT: ";
       
   557     QString closeSuffix = ")";
       
   558     
       
   559     switch (lastid) { //Print the id of the page we're leaving      
       
   560       case ID_PAGE_SETUP_TEAM :	qDebug("%sPAGE_SETUP_TEAM%s", qPrintable(closePrefix), qPrintable(closeSuffix)); 	break;      
       
   561       case ID_PAGE_SETUP :		qDebug("%sPAGE_SETUP%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;      
       
   562       case ID_PAGE_MULTIPLAYER :	qDebug("%sPAGE_MULTIPLAYER%s", qPrintable(closePrefix), qPrintable(closeSuffix));	break;      
       
   563       case ID_PAGE_DEMOS :		qDebug("%sPAGE_DEMOS%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;      
       
   564       case ID_PAGE_NET :		qDebug("%sPAGE_NET%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;      
       
   565       case ID_PAGE_NETGAME :		qDebug("%sPAGE_NETGAME%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;      
       
   566       case ID_PAGE_INFO :		qDebug("%sPAGE_INFO%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;      
       
   567       case ID_PAGE_MAIN :		qDebug("%sPAGE_MAIN%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;      
       
   568       case ID_PAGE_GAMESTATS :		qDebug("%sPAGE_GAMESTATS%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;      
       
   569       case ID_PAGE_SINGLEPLAYER :	qDebug("%sPAGE_SINGLEPLAYER%s", qPrintable(closePrefix), qPrintable(closeSuffix));	break;      
       
   570       case ID_PAGE_TRAINING :		qDebug("%sPAGE_TRAINING%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;      
       
   571       case ID_PAGE_SELECTWEAPON :	qDebug("%sPAGE_SELECTWEAPON%s", qPrintable(closePrefix), qPrintable(closeSuffix));	break;      
       
   572       case ID_PAGE_NETSERVER :		qDebug("%sPAGE_NETSERVER%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;      
       
   573       case ID_PAGE_INGAME :		qDebug("%sPAGE_INGAME%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;      
       
   574       case ID_PAGE_ROOMSLIST :		qDebug("%sPAGE_ROOMSLIST%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;      
       
   575       case ID_PAGE_CONNECTING :	qDebug("%sPAGE_CONNECTING%s", qPrintable(closePrefix), qPrintable(closeSuffix));	break;      
       
   576       case ID_PAGE_SCHEME :		qDebug("%sPAGE_SCHEME%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;      
       
   577       case ID_PAGE_ADMIN :		qDebug("%sPAGE_ADMIN%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;      
       
   578       case ID_PAGE_NETTYPE :		qDebug("%sPAGE_NETTYPE%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;      
       
   579       case ID_PAGE_CAMPAIGN :		qDebug("%sPAGE_CAMPAIGN%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;      
       
   580       case ID_PAGE_DRAWMAP :		qDebug("%sPAGE_DRAWMAP%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;      
       
   581       case ID_PAGE_DATADOWNLOAD :	qDebug("%sPAGE_DATADOWNLOAD%s", qPrintable(closePrefix), qPrintable(closeSuffix));	break;      
       
   582       case ID_PAGE_FEEDBACK :		qDebug("%sPAGE_FEEDBACK%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;      
       
   583       case ID_PAGE_VIDEOS :		qDebug("%sPAGE_VIDEOS%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;
       
   584       case MAX_PAGE :			qDebug("%sMAX_PAGE%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break; 
       
   585       default :			qDebug("%sUNKNOWN PAGE%s", qPrintable(closePrefix), qPrintable(closeSuffix));		break;
       
   586     } //end switch(lastid)
       
   587     switch (id) { //Print the id of the opened page
       
   588       case ID_PAGE_SETUP_TEAM :	qDebug("%sPAGE_SETUP_TEAM%s", qPrintable(openPrefix), qPrintable(openSuffix)); 		break;      
       
   589       case ID_PAGE_SETUP :		qDebug("%sPAGE_SETUP%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   590       case ID_PAGE_MULTIPLAYER :	qDebug("%sPAGE_MULTIPLAYER%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   591       case ID_PAGE_DEMOS :		qDebug("%sPAGE_DEMOS%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   592       case ID_PAGE_NET :		qDebug("%sPAGE_NET%s", qPrintable(openPrefix), qPrintable(openSuffix));			break;      
       
   593       case ID_PAGE_NETGAME :		qDebug("%sPAGE_NETGAME%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   594       case ID_PAGE_INFO :		qDebug("%sPAGE_INFO%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   595       case ID_PAGE_MAIN :		qDebug("%sPAGE_MAIN%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   596       case ID_PAGE_GAMESTATS :		qDebug("%sPAGE_GAMESTATS%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   597       case ID_PAGE_SINGLEPLAYER :	qDebug("%sPAGE_SINGLEPLAYER%s", qPrintable(openPrefix), qPrintable(openSuffix));	break;      
       
   598       case ID_PAGE_TRAINING :		qDebug("%sPAGE_TRAINING%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   599       case ID_PAGE_SELECTWEAPON :	qDebug("%sPAGE_SELECTWEAPON%s", qPrintable(openPrefix), qPrintable(openSuffix));	break;      
       
   600       case ID_PAGE_NETSERVER :		qDebug("%sPAGE_NETSERVER%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   601       case ID_PAGE_INGAME :		qDebug("%sPAGE_INGAME%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   602       case ID_PAGE_ROOMSLIST :		qDebug("%sPAGE_ROOMSLIST%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   603       case ID_PAGE_CONNECTING :	qDebug("%sPAGE_CONNECTING%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   604       case ID_PAGE_SCHEME :		qDebug("%sPAGE_SCHEME%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   605       case ID_PAGE_ADMIN :		qDebug("%sPAGE_ADMIN%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   606       case ID_PAGE_NETTYPE :		qDebug("%sPAGE_NETTYPE%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   607       case ID_PAGE_CAMPAIGN :		qDebug("%sPAGE_CAMPAIGN%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   608       case ID_PAGE_DRAWMAP :		qDebug("%sPAGE_DRAWMAP%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   609       case ID_PAGE_DATADOWNLOAD :	qDebug("%sPAGE_DATADOWNLOAD%s", qPrintable(openPrefix), qPrintable(openSuffix));	break;      
       
   610       case ID_PAGE_FEEDBACK :		qDebug("%sPAGE_FEEDBACK%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;      
       
   611       case ID_PAGE_VIDEOS :		qDebug("%sPAGE_VIDEOS%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;
       
   612       case MAX_PAGE :			qDebug("%sMAX_PAGE%s", qPrintable(openPrefix), qPrintable(openSuffix));			break; 
       
   613       default :			qDebug("%sUNKNOWN PAGE%s", qPrintable(openPrefix), qPrintable(openSuffix));		break;
       
   614     } //end switch(id)
       
   615     
       
   616     if (id == ID_PAGE_DATADOWNLOAD)
   601     if (id == ID_PAGE_DATADOWNLOAD)
   617     {
   602     {
   618         ui.pageDataDownload->fetchList();
   603         ui.pageDataDownload->fetchList();
   619     }
   604     }
   620     if (id == ID_PAGE_DRAWMAP)
   605     if (id == ID_PAGE_DRAWMAP)
   967 }
   952 }
   968 
   953 
   969 
   954 
   970 void HWForm::DeleteTeam(const QString & teamName)
   955 void HWForm::DeleteTeam(const QString & teamName)
   971 {
   956 {
   972     QMessageBox reallyDeleteMsg(this);
   957     ui.pageEditTeam->deleteTeam(teamName);
   973     reallyDeleteMsg.setIcon(QMessageBox::Question);
   958     UpdateTeamsLists();
   974     reallyDeleteMsg.setWindowTitle(QMessageBox::tr("Teams - Are you sure?"));
       
   975     reallyDeleteMsg.setText(QMessageBox::tr("Do you really want to delete the team '%1'?").arg(teamName));
       
   976     reallyDeleteMsg.setWindowModality(Qt::WindowModal);
       
   977     reallyDeleteMsg.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
       
   978 
       
   979     if (reallyDeleteMsg.exec() == QMessageBox::Ok)
       
   980     {
       
   981         ui.pageEditTeam->deleteTeam(teamName);
       
   982         UpdateTeamsLists();
       
   983     }
       
   984 }
   959 }
   985 
   960 
   986 void HWForm::DeleteScheme()
   961 void HWForm::DeleteScheme()
   987 {
   962 {
   988     ui.pageScheme->selectScheme->setCurrentIndex(ui.pageOptions->SchemesName->currentIndex());
   963     ui.pageScheme->selectScheme->setCurrentIndex(ui.pageOptions->SchemesName->currentIndex());
  1508         if (retry) {
  1483         if (retry) {
  1509             NetConnectOfficialServer();
  1484             NetConnectOfficialServer();
  1510         }
  1485         }
  1511         else {
  1486         else {
  1512             while (ui.Pages->currentIndex() != ID_PAGE_NET
  1487             while (ui.Pages->currentIndex() != ID_PAGE_NET
  1513                 && ui.Pages->currentIndex() != ID_PAGE_NETTYPE
       
  1514                 && ui.Pages->currentIndex() != ID_PAGE_MAIN) 
  1488                 && ui.Pages->currentIndex() != ID_PAGE_MAIN) 
  1515             {
  1489             {
  1516                 GoBack();
  1490                 GoBack();
  1517             }
  1491             }
  1518         }
  1492         }
  1525         QString errorStr = QMessageBox::tr("Connection to server is lost") + (reason.isEmpty()?"":("\n\n" + HWNewNet::tr("Quit reason: ") + '"' + reason +'"'));
  1499         QString errorStr = QMessageBox::tr("Connection to server is lost") + (reason.isEmpty()?"":("\n\n" + HWNewNet::tr("Quit reason: ") + '"' + reason +'"'));
  1526         ShowErrorMessage(errorStr);
  1500         ShowErrorMessage(errorStr);
  1527     }
  1501     }
  1528 
  1502 
  1529     while (ui.Pages->currentIndex() != ID_PAGE_NET
  1503     while (ui.Pages->currentIndex() != ID_PAGE_NET
  1530         && ui.Pages->currentIndex() != ID_PAGE_NETTYPE
       
  1531         && ui.Pages->currentIndex() != ID_PAGE_MAIN)
  1504         && ui.Pages->currentIndex() != ID_PAGE_MAIN)
  1532     {
  1505     {
  1533         GoBack();
  1506         GoBack();
  1534     }
  1507     }
  1535 }
  1508 }
  1879 }
  1852 }
  1880 
  1853 
  1881 // 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]
  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]
  1882 QString HWForm::getDemoArguments()
  1855 QString HWForm::getDemoArguments()
  1883 {
  1856 {
       
  1857 
       
  1858     QString prefix = datadir->absolutePath();
       
  1859     QString userPrefix = cfgdir->absolutePath();
  1884 #ifdef Q_WS_WIN
  1860 #ifdef Q_WS_WIN
  1885     QString userdir = cfgdir->absolutePath().replace("/","\\");
  1861     prefix = prefix.replace("/","\\");
  1886 #else
  1862     userPrefix = userPrefix.replace("/","\\");
  1887     QString userdir = cfgdir->absolutePath();
  1863 #endif
  1888 #endif
  1864 
  1889 
  1865     std::pair<QRect, QRect> resolutions = config->vid_ResolutionPair();
  1890     QRect resolution = config->vid_Resolution();
  1866     return QString("--prefix " + prefix
  1891     return QString("--user-dir " + userdir
  1867                    + " --user-prefix " + userPrefix
  1892                    + " --width " + QString::number(resolution.width())
  1868                    + " --fullscreen-width " + QString::number(resolutions.first.width())
  1893                    + " --height " + QString::number(resolution.height())
  1869                    + " --fullscreen-height " + QString::number(resolutions.first.height())
       
  1870                    + " --width " + QString::number(resolutions.second.width())
       
  1871                    + " --height " + QString::number(resolutions.second.height())
  1894                    + " --volume " + QString::number(config->volume())
  1872                    + " --volume " + QString::number(config->volume())
  1895                    + (config->isMusicEnabled() ? "" : " --nomusic")
  1873                    + (config->isMusicEnabled() ? "" : " --nomusic")
  1896                    + (config->isSoundEnabled() ? "" : " --nosound")
  1874                    + (config->isSoundEnabled() ? "" : " --nosound")
  1897                    + " --locale " + config->language() + ".txt"
  1875                    + " --locale " + config->language() + ".txt"
  1898                    + (config->vid_Fullscreen() ? " --fullscreen" : "")
  1876                    + (config->vid_Fullscreen() ? " --fullscreen" : "")
  1912     registry_hkcr.setValue(".hws/Default", "Hedgewars.Save");
  1890     registry_hkcr.setValue(".hws/Default", "Hedgewars.Save");
  1913     registry_hkcr.setValue("Hedgewars.Demo/Default", tr("Hedgewars Demo File", "File Types"));
  1891     registry_hkcr.setValue("Hedgewars.Demo/Default", tr("Hedgewars Demo File", "File Types"));
  1914     registry_hkcr.setValue("Hedgewars.Save/Default", tr("Hedgewars Save File", "File Types"));
  1892     registry_hkcr.setValue("Hedgewars.Save/Default", tr("Hedgewars Save File", "File Types"));
  1915     registry_hkcr.setValue("Hedgewars.Demo/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwdfile.ico\",0");
  1893     registry_hkcr.setValue("Hedgewars.Demo/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwdfile.ico\",0");
  1916     registry_hkcr.setValue("Hedgewars.Save/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwsfile.ico\",0");
  1894     registry_hkcr.setValue("Hedgewars.Save/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwsfile.ico\",0");
  1917     registry_hkcr.setValue("Hedgewars.Demo/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\" "+arguments);
  1895     registry_hkcr.setValue("Hedgewars.Demo/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"%1\" "+arguments);
  1918     registry_hkcr.setValue("Hedgewars.Save/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\" "+arguments);
  1896     registry_hkcr.setValue("Hedgewars.Save/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"%1\" "+arguments);
  1919 #elif defined __APPLE__
  1897 #elif defined __APPLE__
  1920     // only useful when other apps have taken precedence over our file extensions and you want to reset it
  1898     // only useful when other apps have taken precedence over our file extensions and you want to reset it
  1921     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>'");
  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>'");
  1922     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>'");
  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>'");
  1923     system("/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -domain local -domain system -domain user");
  1901     system("/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -domain local -domain system -domain user");
  1979     }
  1957     }
  1980 }
  1958 }
  1981 
  1959 
  1982 void HWForm::SendFeedback()
  1960 void HWForm::SendFeedback()
  1983 {
  1961 {
  1984     //Create Xml representation of google code issue first
  1962     // Get form data
  1985     if (!CreateIssueXml())
  1963     
  1986     {
  1964     QString summary = ui.pageFeedback->summary->text();
  1987         ShowErrorMessage(QMessageBox::tr("Please fill out all fields"));
  1965     QString description = ui.pageFeedback->description->toPlainText();
  1988         return;
  1966     QString email = ui.pageFeedback->email->text();
  1989     }
       
  1990 
       
  1991     //Submit issue to PHP script
       
  1992     QString source = "HedgewarsFoundation-Hedgewars-";
       
  1993     source += (cVersionString?(*cVersionString):QString(""));
       
  1994     QString captchaCode = ui.pageFeedback->captcha_code->text();
  1967     QString captchaCode = ui.pageFeedback->captcha_code->text();
  1995     QString captchaID = QString::number(ui.pageFeedback->captchaID);
  1968     QString captchaID = QString::number(ui.pageFeedback->captchaID);
       
  1969     QString version = "HedgewarsFoundation-Hedgewars-" + (cVersionString?(*cVersionString):QString(""));
       
  1970 
       
  1971     if (summary.isEmpty() || description.isEmpty())
       
  1972     {
       
  1973         ShowErrorMessage(QMessageBox::tr("Please fill out all fields. Email is optional."));
       
  1974         return;
       
  1975     }
       
  1976 
       
  1977     // Submit issue to PHP script
  1996     
  1978     
  1997     QByteArray body;
  1979     QByteArray body;
  1998     body.append("captcha=");
  1980     body.append("captcha=");
  1999     body.append(captchaID);
  1981     body.append(captchaID);
  2000     body.append("&code=");
  1982     body.append("&code=");
  2001     body.append(captchaCode);
  1983     body.append(captchaCode);
  2002     body.append("&source=");
  1984     body.append("&version=");
  2003     body.append(source);
  1985     body.append(QUrl::toPercentEncoding(version));
  2004     body.append("&issue=");
  1986     body.append("&title=");
  2005     body.append(QUrl::toPercentEncoding(issueXml));
  1987     body.append(QUrl::toPercentEncoding(summary));
       
  1988     body.append("&body=");
       
  1989     body.append(QUrl::toPercentEncoding(description));
       
  1990     body.append("&email=");
       
  1991     body.append(QUrl::toPercentEncoding(email));
       
  1992     if (ui.pageFeedback->CheckSendSpecs->isChecked())
       
  1993     {
       
  1994         body.append("&specs=");
       
  1995         body.append(QUrl::toPercentEncoding(ui.pageFeedback->specs));
       
  1996     }
  2006     
  1997     
  2007     nam = new QNetworkAccessManager(this);
  1998     nam = new QNetworkAccessManager(this);
  2008     connect(nam, SIGNAL(finished(QNetworkReply*)),
  1999     connect(nam, SIGNAL(finished(QNetworkReply*)),
  2009             this, SLOT(finishedSlot(QNetworkReply*)));
  2000             this, SLOT(finishedSlot(QNetworkReply*)));
  2010             
  2001             
  2012     header.setRawHeader("Content-Length", QString::number(body.size()).toAscii());
  2003     header.setRawHeader("Content-Length", QString::number(body.size()).toAscii());
  2013     
  2004     
  2014     nam->post(header, body);
  2005     nam->post(header, body);
  2015 }
  2006 }
  2016 
  2007 
  2017 bool HWForm::CreateIssueXml()
       
  2018 {
       
  2019     QString summary = ui.pageFeedback->summary->text();
       
  2020     QString description = ui.pageFeedback->description->toPlainText();
       
  2021     QString email = ui.pageFeedback->email->text();
       
  2022 
       
  2023     //Check if all necessary information is entered
       
  2024     if (summary.isEmpty() || description.isEmpty())
       
  2025         return false;
       
  2026 
       
  2027     issueXml =
       
  2028         "<?xml version='1.0' encoding='UTF-8'?>"
       
  2029         "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:issues='http://code.google.com/p/hedgewars/issues/list'>"
       
  2030         "<title>";
       
  2031     issueXml.append(summary);
       
  2032     issueXml.append("</title><content type='html'>");
       
  2033     issueXml.append(description);
       
  2034     issueXml.append("</content><author><name>feedback.hedgewars</name></author>");
       
  2035 
       
  2036     if (!email.isEmpty())
       
  2037     {
       
  2038         issueXml.append("<issues:owner><issues:username>");
       
  2039         issueXml.append(email);
       
  2040         issueXml.append("</issues:username></issues:owner>");
       
  2041         issueXml.append("<issues:cc><issues:username>");
       
  2042         issueXml.append(email);
       
  2043         issueXml.append("</issues:username></issues:cc>");
       
  2044     }
       
  2045 
       
  2046     issueXml.append("</entry>");
       
  2047 
       
  2048     return true;
       
  2049 }
       
  2050 
       
  2051 void HWForm::finishedSlot(QNetworkReply* reply)
  2008 void HWForm::finishedSlot(QNetworkReply* reply)
  2052 {
  2009 {
  2053     if (reply && reply->error() == QNetworkReply::NoError)
  2010     if (reply && reply->error() == QNetworkReply::NoError)
  2054     {
  2011     {
  2055             QMessageBox infoMsg(this);
  2012             QMessageBox infoMsg(this);
  2056             infoMsg.setIcon(QMessageBox::Information);
  2013             infoMsg.setIcon(QMessageBox::Information);
  2057             infoMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Success"));
  2014             infoMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Success"));
  2058             infoMsg.setText(QMessageBox::tr("Successfully posted the issue on hedgewars.googlecode.com"));
  2015             infoMsg.setText(reply->readAll());
  2059             infoMsg.setWindowModality(Qt::WindowModal);
  2016             infoMsg.setWindowModality(Qt::WindowModal);
  2060             infoMsg.exec();
  2017             infoMsg.exec();
  2061 
  2018 
  2062             ui.pageFeedback->summary->clear();
  2019             ui.pageFeedback->summary->clear();
       
  2020             ui.pageFeedback->email->clear();
  2063             ui.pageFeedback->description->clear();
  2021             ui.pageFeedback->description->clear();
  2064             ui.pageFeedback->EmbedSystemInfo();
       
  2065             ui.pageFeedback->LoadCaptchaImage();
  2022             ui.pageFeedback->LoadCaptchaImage();
  2066             
  2023             
  2067             return;
  2024             return;
  2068     }
  2025     }
  2069     else
  2026     else