QTfrontend/hwform.cpp
branchwebgl
changeset 8330 aaefa587e277
parent 8328 03684c667664
child 8444 75db7bb8dce8
equal deleted inserted replaced
8116:d24257910f8d 8330:aaefa587e277
    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"
    94 #include "roomslistmodel.h"
    95 #include "roomslistmodel.h"
    95 #include "recorder.h"
    96 #include "recorder.h"
    96 #include "playerslistmodel.h"
    97 #include "playerslistmodel.h"
    97 
    98 
    98 #include "DataManager.h"
    99 #include "DataManager.h"
       
   100 #include "AutoUpdater.h"
       
   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
    99 
   113 
   100 #ifdef __APPLE__
   114 #ifdef __APPLE__
   101 #include "M3Panel.h"
   115 #include "M3Panel.h"
   102 #ifdef SPARKLE_ENABLED
   116 #ifdef SPARKLE_ENABLED
   103 #include "SparkleAutoUpdater.h"
   117 #include "SparkleAutoUpdater.h"
   109 // and this one flag does not warrant a static class
   123 // and this one flag does not warrant a static class
   110 bool frontendEffects = true;
   124 bool frontendEffects = true;
   111 QString playerHash;
   125 QString playerHash;
   112 
   126 
   113 GameUIConfig* HWForm::config = NULL;
   127 GameUIConfig* HWForm::config = NULL;
   114 QSettings* HWForm::gameSettings = NULL;
       
   115 
   128 
   116 HWForm::HWForm(QWidget *parent, QString styleSheet)
   129 HWForm::HWForm(QWidget *parent, QString styleSheet)
   117     : QMainWindow(parent)
   130     : QMainWindow(parent)
   118     , game(0)
   131     , game(0)
   119     , pnetserver(0)
   132     , pnetserver(0)
   125     SDLInteraction::instance().setMusicTrack("/Music/main_theme.ogg");
   138     SDLInteraction::instance().setMusicTrack("/Music/main_theme.ogg");
   126 
   139 
   127 #ifdef USE_XFIRE
   140 #ifdef USE_XFIRE
   128     xfire_init();
   141     xfire_init();
   129 #endif
   142 #endif
   130     gameSettings = new QSettings(cfgdir->absolutePath() + "/hedgewars.ini", QSettings::IniFormat);
       
   131     frontendEffects = gameSettings->value("frontend/effects", true).toBool();
       
   132     playerHash = QString(QCryptographicHash::hash(gameSettings->value("net/nick","").toString().toUtf8(), QCryptographicHash::Md5).toHex());
       
   133 
       
   134     this->setStyleSheet(styleSheet);
   143     this->setStyleSheet(styleSheet);
   135     ui.setupUi(this);
   144     ui.setupUi(this);
   136     setMinimumSize(760, 580);
   145     setMinimumSize(760, 580);
   137     //setFocusPolicy(Qt::StrongFocus);
   146     //setFocusPolicy(Qt::StrongFocus);
   138     CustomizePalettes();
   147     CustomizePalettes();
   139 
   148 
   140     ui.pageOptions->CBResolution->addItems(SDLInteraction::instance().getResolutions());
   149     ui.pageOptions->CBResolution->addItems(SDLInteraction::instance().getResolutions());
   141 
   150 
   142     config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini");
   151     config = new GameUIConfig(this, "physfs://hedgewars.ini");
   143 
   152     frontendEffects = config->value("frontend/effects", true).toBool();
       
   153     playerHash = QString(QCryptographicHash::hash(config->value("net/nick","").toString().toUtf8(), QCryptographicHash::Md5).toHex());
       
   154 
       
   155     ui.pageRoomsList->setSettings(config);
       
   156     ui.pageNetGame->chatWidget->setSettings(config);
       
   157     ui.pageRoomsList->chatWidget->setSettings(config);
       
   158 #ifdef VIDEOREC
   144     ui.pageVideos->init(config);
   159     ui.pageVideos->init(config);
       
   160     ui.pageOptions->setConfig(config);
       
   161 #endif
       
   162 
       
   163 #ifdef __APPLE__
       
   164     AutoUpdater* updater = NULL;
       
   165     if (config->isAutoUpdateEnabled())
       
   166     {
       
   167 #ifdef __APPLE__
       
   168 #ifdef SPARKLE_ENABLED
       
   169         updater = new SparkleAutoUpdater();
       
   170 #endif
       
   171 #endif
       
   172         if (updater)
       
   173         {
       
   174             updater->checkForUpdates();
       
   175             delete updater;
       
   176         }
       
   177     }
       
   178 #endif
   145 
   179 
   146 #ifdef __APPLE__
   180 #ifdef __APPLE__
   147     panel = new M3Panel;
   181     panel = new M3Panel;
   148 
       
   149 #ifdef SPARKLE_ENABLED
       
   150     AutoUpdater* updater;
       
   151 
       
   152     updater = new SparkleAutoUpdater();
       
   153     if (updater && config->isAutoUpdateEnabled())
       
   154         updater->checkForUpdates();
       
   155 #endif
       
   156 
   182 
   157     QShortcut *hideFrontend = new QShortcut(QKeySequence("Ctrl+M"), this);
   183     QShortcut *hideFrontend = new QShortcut(QKeySequence("Ctrl+M"), this);
   158     connect (hideFrontend, SIGNAL(activated()), this, SLOT(showMinimized()));
   184     connect (hideFrontend, SIGNAL(activated()), this, SLOT(showMinimized()));
   159 #else
   185 #else
   160     // ctrl+q closes frontend for consistency
   186     // ctrl+q closes frontend for consistency
   188     pageSwitchMapper->setMapping(ui.pageMain->BtnSetup, ID_PAGE_SETUP);
   214     pageSwitchMapper->setMapping(ui.pageMain->BtnSetup, ID_PAGE_SETUP);
   189 
   215 
   190     connect(ui.pageMain->BtnFeedback, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   216     connect(ui.pageMain->BtnFeedback, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   191     pageSwitchMapper->setMapping(ui.pageMain->BtnFeedback, ID_PAGE_FEEDBACK);
   217     pageSwitchMapper->setMapping(ui.pageMain->BtnFeedback, ID_PAGE_FEEDBACK);
   192 
   218 
   193     connect(ui.pageMain->BtnNet, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
       
   194     pageSwitchMapper->setMapping(ui.pageMain->BtnNet, ID_PAGE_NETTYPE);
       
   195 
       
   196     connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   219     connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   197     pageSwitchMapper->setMapping(ui.pageMain->BtnInfo, ID_PAGE_INFO);
   220     pageSwitchMapper->setMapping(ui.pageMain->BtnInfo, ID_PAGE_INFO);
   198 
   221 
   199     connect(ui.pageMain->BtnDataDownload, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   222     connect(ui.pageMain->BtnDataDownload, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
   200     pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD);
   223     pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD);
   289             this, SLOT(UpdateWeapons())); // executed second
   312             this, SLOT(UpdateWeapons())); // executed second
   290     //connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()),
   313     //connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsDeleted()),
   291     //    this, SLOT(GoBack())); // executed third
   314     //    this, SLOT(GoBack())); // executed third
   292 
   315 
   293 
   316 
   294     connect(ui.pageNetType->BtnLAN, SIGNAL(clicked()), this, SLOT(GoToNet()));
   317     connect(ui.pageMain->BtnNetLocal, SIGNAL(clicked()), this, SLOT(GoToNet()));
   295     connect(ui.pageNetType->BtnOfficialServer, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer()));
   318     connect(ui.pageMain->BtnNetOfficial, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer()));
   296 
   319 
   297     connect(ui.pageConnecting, SIGNAL(cancelConnection()), this, SLOT(GoBack()));
   320     connect(ui.pageConnecting, SIGNAL(cancelConnection()), this, SLOT(GoBack()));
   298 
   321 
   299     connect(ui.pageVideos, SIGNAL(goBack()), config, SLOT(SaveVideosOptions()));
   322     connect(ui.pageVideos, SIGNAL(goBack()), config, SLOT(SaveVideosOptions()));
   300 
   323 
   437             (*it)->setCurrentIndex(pos);
   460             (*it)->setCurrentIndex(pos);
   438         }
   461         }
   439     }
   462     }
   440 }
   463 }
   441 
   464 
   442 void HWForm::UpdateTeamsLists(const QStringList* editable_teams)
   465 void HWForm::UpdateTeamsLists()
   443 {
   466 {
   444     QStringList teamslist;
   467     QStringList teamslist = config->GetTeamsList();
   445     if(editable_teams)
       
   446     {
       
   447         teamslist =* editable_teams;
       
   448     }
       
   449     else
       
   450     {
       
   451         teamslist = config->GetTeamsList();
       
   452     }
       
   453 
   468 
   454     if(teamslist.empty())
   469     if(teamslist.empty())
   455     {
   470     {
   456         HWTeam defaultTeam(tr("DefaultTeam"));
   471         QString currentNickName = config->value("net/nick","").toString().toUtf8();
       
   472         QString teamName;
       
   473 
       
   474         if (currentNickName.isEmpty())
       
   475         {
       
   476             teamName = tr("DefaultTeam");
       
   477         }
       
   478         else
       
   479         {
       
   480             teamName = tr("%1's Team").arg(currentNickName);
       
   481         }
       
   482 
       
   483         HWTeam defaultTeam(teamName);
   457         defaultTeam.saveToFile();
   484         defaultTeam.saveToFile();
   458         teamslist.push_back(tr("DefaultTeam"));
   485         teamslist.push_back(teamName);
   459     }
   486     }
   460 
   487 
   461     ui.pageOptions->CBTeamName->clear();
   488     ui.pageOptions->CBTeamName->clear();
   462     ui.pageOptions->CBTeamName->addItems(teamslist);
   489     ui.pageOptions->CBTeamName->addItems(teamslist);
   463     ui.pageCampaign->CBTeam->clear();
   490     ui.pageCampaign->CBTeam->clear();
   529 void HWForm::OnPageShown(quint8 id, quint8 lastid)
   556 void HWForm::OnPageShown(quint8 id, quint8 lastid)
   530 {
   557 {
   531 #ifdef USE_XFIRE
   558 #ifdef USE_XFIRE
   532     updateXfire();
   559     updateXfire();
   533 #endif
   560 #endif
       
   561 
       
   562     QString openPrefix = "Debug:   (PAGE_OPENED: ";
       
   563     QString openSuffix = ")";
       
   564     QString closePrefix = "Debug:   (PAGE_LEFT: ";
       
   565     QString closeSuffix = ")";
       
   566 
       
   567     switch (lastid) { //Print the id of the page we're leaving
       
   568       case ID_PAGE_SETUP_TEAM : qDebug("%sPAGE_SETUP_TEAM%s", qPrintable(closePrefix), qPrintable(closeSuffix));    break;
       
   569       case ID_PAGE_SETUP :      qDebug("%sPAGE_SETUP%s", qPrintable(closePrefix), qPrintable(closeSuffix));     break;
       
   570       case ID_PAGE_MULTIPLAYER :    qDebug("%sPAGE_MULTIPLAYER%s", qPrintable(closePrefix), qPrintable(closeSuffix));   break;
       
   571       case ID_PAGE_DEMOS :      qDebug("%sPAGE_DEMOS%s", qPrintable(closePrefix), qPrintable(closeSuffix));     break;
       
   572       case ID_PAGE_NET :        qDebug("%sPAGE_NET%s", qPrintable(closePrefix), qPrintable(closeSuffix));       break;
       
   573       case ID_PAGE_NETGAME :        qDebug("%sPAGE_NETGAME%s", qPrintable(closePrefix), qPrintable(closeSuffix));       break;
       
   574       case ID_PAGE_INFO :       qDebug("%sPAGE_INFO%s", qPrintable(closePrefix), qPrintable(closeSuffix));      break;
       
   575       case ID_PAGE_MAIN :       qDebug("%sPAGE_MAIN%s", qPrintable(closePrefix), qPrintable(closeSuffix));      break;
       
   576       case ID_PAGE_GAMESTATS :      qDebug("%sPAGE_GAMESTATS%s", qPrintable(closePrefix), qPrintable(closeSuffix));     break;
       
   577       case ID_PAGE_SINGLEPLAYER :   qDebug("%sPAGE_SINGLEPLAYER%s", qPrintable(closePrefix), qPrintable(closeSuffix));  break;
       
   578       case ID_PAGE_TRAINING :       qDebug("%sPAGE_TRAINING%s", qPrintable(closePrefix), qPrintable(closeSuffix));      break;
       
   579       case ID_PAGE_SELECTWEAPON :   qDebug("%sPAGE_SELECTWEAPON%s", qPrintable(closePrefix), qPrintable(closeSuffix));  break;
       
   580       case ID_PAGE_NETSERVER :      qDebug("%sPAGE_NETSERVER%s", qPrintable(closePrefix), qPrintable(closeSuffix));     break;
       
   581       case ID_PAGE_INGAME :     qDebug("%sPAGE_INGAME%s", qPrintable(closePrefix), qPrintable(closeSuffix));        break;
       
   582       case ID_PAGE_ROOMSLIST :      qDebug("%sPAGE_ROOMSLIST%s", qPrintable(closePrefix), qPrintable(closeSuffix));     break;
       
   583       case ID_PAGE_CONNECTING : qDebug("%sPAGE_CONNECTING%s", qPrintable(closePrefix), qPrintable(closeSuffix));    break;
       
   584       case ID_PAGE_SCHEME :     qDebug("%sPAGE_SCHEME%s", qPrintable(closePrefix), qPrintable(closeSuffix));        break;
       
   585       case ID_PAGE_ADMIN :      qDebug("%sPAGE_ADMIN%s", qPrintable(closePrefix), qPrintable(closeSuffix));     break;
       
   586       case ID_PAGE_CAMPAIGN :       qDebug("%sPAGE_CAMPAIGN%s", qPrintable(closePrefix), qPrintable(closeSuffix));      break;
       
   587       case ID_PAGE_DRAWMAP :        qDebug("%sPAGE_DRAWMAP%s", qPrintable(closePrefix), qPrintable(closeSuffix));       break;
       
   588       case ID_PAGE_DATADOWNLOAD :   qDebug("%sPAGE_DATADOWNLOAD%s", qPrintable(closePrefix), qPrintable(closeSuffix));  break;
       
   589       case ID_PAGE_FEEDBACK :       qDebug("%sPAGE_FEEDBACK%s", qPrintable(closePrefix), qPrintable(closeSuffix));      break;
       
   590       case ID_PAGE_VIDEOS :     qDebug("%sPAGE_VIDEOS%s", qPrintable(closePrefix), qPrintable(closeSuffix));        break;
       
   591       case MAX_PAGE :           qDebug("%sMAX_PAGE%s", qPrintable(closePrefix), qPrintable(closeSuffix));       break;
       
   592       default :         qDebug("%sUNKNOWN PAGE%s", qPrintable(closePrefix), qPrintable(closeSuffix));       break;
       
   593     } //end switch(lastid)
       
   594     switch (id) { //Print the id of the opened page
       
   595       case ID_PAGE_SETUP_TEAM : qDebug("%sPAGE_SETUP_TEAM%s", qPrintable(openPrefix), qPrintable(openSuffix));      break;
       
   596       case ID_PAGE_SETUP :      qDebug("%sPAGE_SETUP%s", qPrintable(openPrefix), qPrintable(openSuffix));       break;
       
   597       case ID_PAGE_MULTIPLAYER :    qDebug("%sPAGE_MULTIPLAYER%s", qPrintable(openPrefix), qPrintable(openSuffix));     break;
       
   598       case ID_PAGE_DEMOS :      qDebug("%sPAGE_DEMOS%s", qPrintable(openPrefix), qPrintable(openSuffix));       break;
       
   599       case ID_PAGE_NET :        qDebug("%sPAGE_NET%s", qPrintable(openPrefix), qPrintable(openSuffix));         break;
       
   600       case ID_PAGE_NETGAME :        qDebug("%sPAGE_NETGAME%s", qPrintable(openPrefix), qPrintable(openSuffix));     break;
       
   601       case ID_PAGE_INFO :       qDebug("%sPAGE_INFO%s", qPrintable(openPrefix), qPrintable(openSuffix));        break;
       
   602       case ID_PAGE_MAIN :       qDebug("%sPAGE_MAIN%s", qPrintable(openPrefix), qPrintable(openSuffix));        break;
       
   603       case ID_PAGE_GAMESTATS :      qDebug("%sPAGE_GAMESTATS%s", qPrintable(openPrefix), qPrintable(openSuffix));       break;
       
   604       case ID_PAGE_SINGLEPLAYER :   qDebug("%sPAGE_SINGLEPLAYER%s", qPrintable(openPrefix), qPrintable(openSuffix));    break;
       
   605       case ID_PAGE_TRAINING :       qDebug("%sPAGE_TRAINING%s", qPrintable(openPrefix), qPrintable(openSuffix));        break;
       
   606       case ID_PAGE_SELECTWEAPON :   qDebug("%sPAGE_SELECTWEAPON%s", qPrintable(openPrefix), qPrintable(openSuffix));    break;
       
   607       case ID_PAGE_NETSERVER :      qDebug("%sPAGE_NETSERVER%s", qPrintable(openPrefix), qPrintable(openSuffix));       break;
       
   608       case ID_PAGE_INGAME :     qDebug("%sPAGE_INGAME%s", qPrintable(openPrefix), qPrintable(openSuffix));      break;
       
   609       case ID_PAGE_ROOMSLIST :      qDebug("%sPAGE_ROOMSLIST%s", qPrintable(openPrefix), qPrintable(openSuffix));       break;
       
   610       case ID_PAGE_CONNECTING : qDebug("%sPAGE_CONNECTING%s", qPrintable(openPrefix), qPrintable(openSuffix));      break;
       
   611       case ID_PAGE_SCHEME :     qDebug("%sPAGE_SCHEME%s", qPrintable(openPrefix), qPrintable(openSuffix));      break;
       
   612       case ID_PAGE_ADMIN :      qDebug("%sPAGE_ADMIN%s", qPrintable(openPrefix), qPrintable(openSuffix));       break;
       
   613       case ID_PAGE_CAMPAIGN :       qDebug("%sPAGE_CAMPAIGN%s", qPrintable(openPrefix), qPrintable(openSuffix));        break;
       
   614       case ID_PAGE_DRAWMAP :        qDebug("%sPAGE_DRAWMAP%s", qPrintable(openPrefix), qPrintable(openSuffix));     break;
       
   615       case ID_PAGE_DATADOWNLOAD :   qDebug("%sPAGE_DATADOWNLOAD%s", qPrintable(openPrefix), qPrintable(openSuffix));    break;
       
   616       case ID_PAGE_FEEDBACK :       qDebug("%sPAGE_FEEDBACK%s", qPrintable(openPrefix), qPrintable(openSuffix));        break;
       
   617       case ID_PAGE_VIDEOS :     qDebug("%sPAGE_VIDEOS%s", qPrintable(openPrefix), qPrintable(openSuffix));      break;
       
   618       case MAX_PAGE :           qDebug("%sMAX_PAGE%s", qPrintable(openPrefix), qPrintable(openSuffix));         break;
       
   619       default :         qDebug("%sUNKNOWN PAGE%s", qPrintable(openPrefix), qPrintable(openSuffix));     break;
       
   620     } //end switch(id)
       
   621 
   534     if (id == ID_PAGE_DATADOWNLOAD)
   622     if (id == ID_PAGE_DATADOWNLOAD)
   535     {
   623     {
   536         ui.pageDataDownload->fetchList();
   624         ui.pageDataDownload->fetchList();
   537     }
   625     }
   538     if (id == ID_PAGE_DRAWMAP)
   626     if (id == ID_PAGE_DRAWMAP)
   610     if (id == ID_PAGE_MAIN)
   698     if (id == ID_PAGE_MAIN)
   611     {
   699     {
   612         ui.pageOptions->setTeamOptionsEnabled(true);
   700         ui.pageOptions->setTeamOptionsEnabled(true);
   613     }
   701     }
   614 
   702 
   615     if (id == ID_PAGE_SETUP)
   703     if (id == ID_PAGE_FEEDBACK)
   616     {
   704     {
   617         config->reloadValues();
   705         ui.pageFeedback->LoadCaptchaImage();
   618     }
       
   619 
       
   620     if (id == ID_PAGE_VIDEOS )
       
   621     {
       
   622         config->reloadVideosValues();
       
   623     }
   706     }
   624 }
   707 }
   625 
   708 
   626 void HWForm::GoToPage(int id)
   709 void HWForm::GoToPage(int id)
   627 {
   710 {
   634     ui.Pages->setCurrentIndex(id);
   717     ui.Pages->setCurrentIndex(id);
   635 
   718 
   636 
   719 
   637    /* if (id == ID_PAGE_DRAWMAP || id == ID_PAGE_GAMESTATS)
   720    /* if (id == ID_PAGE_DRAWMAP || id == ID_PAGE_GAMESTATS)
   638         stopAnim = true;
   721         stopAnim = true;
   639 	This were disabled due to broken flake animations.  I believe the more general problems w/ opacity that forced its disable makes blocking these
   722     This were disabled due to broken flake animations.  I believe the more general problems w/ opacity that forced its disable makes blocking these
   640 	unnecessary.
   723     unnecessary.
   641    */
   724    */
   642 
   725 
   643 #if (QT_VERSION >= 0x040600)
   726 #if (QT_VERSION >= 0x040600)
   644     if (!stopAnim)
   727     if (!stopAnim)
   645     {
   728     {
   693 
   776 
   694         // start animations
   777         // start animations
   695         animationOldSlide->start(QAbstractAnimation::DeleteWhenStopped);
   778         animationOldSlide->start(QAbstractAnimation::DeleteWhenStopped);
   696         animationNewSlide->start(QAbstractAnimation::DeleteWhenStopped);
   779         animationNewSlide->start(QAbstractAnimation::DeleteWhenStopped);
   697 
   780 
   698     	/* this is for the situation when the animation below is interrupted by a new animation.  For some reason, finished is not being fired */ 	
   781         /* this is for the situation when the animation below is interrupted by a new animation.  For some reason, finished is not being fired */
   699     	for(int i=0;i<MAX_PAGE;i++) if (i!=id && i!=lastid) ui.Pages->widget(i)->hide();
   782         for(int i=0;i<MAX_PAGE;i++) if (i!=id && i!=lastid) ui.Pages->widget(i)->hide();
   700     }
   783     }
   701 #endif
   784 #endif
   702 }
   785 }
   703 
   786 
   704 void HWForm::GoBack()
   787 void HWForm::GoBack()
   963     NetConnectServer("netserver.hedgewars.org", 46631);
  1046     NetConnectServer("netserver.hedgewars.org", 46631);
   964 }
  1047 }
   965 
  1048 
   966 void HWForm::NetPassword(const QString & nick)
  1049 void HWForm::NetPassword(const QString & nick)
   967 {
  1050 {
   968     int passLength = config->value("net/passwordlength", 0).toInt();
  1051     //Get hashes
   969     QString hash = config->value("net/passwordhash", "").toString();
  1052     QString hash =  config->passwordHash();
   970 
  1053     QString temphash =  config->tempHash();
   971     // If the password is blank, ask the user to enter one in
  1054 
   972     if (passLength == 0)
  1055     //Check them
   973     {
  1056 
   974         HWPasswordDialog * hpd = new HWPasswordDialog(this, tr("Your nickname %1 is\nregistered on Hedgewars.org\nPlease provide your password below\nor pick another nickname in game config:").arg(nick));
  1057     if (temphash.isEmpty() && hash.isEmpty()) { //If the user enters a registered nick with no password, sends a bogus hash
   975         hpd->cbSave->setChecked(config->value("net/savepassword", true).toBool());
  1058         hwnet->SendPasswordHash("THISISNOHASH");
   976         if (hpd->exec() != QDialog::Accepted)
  1059     }
   977         {
  1060     else if (temphash.isEmpty()) { //Send saved hash as default
   978             ForcedDisconnect(tr("No password supplied."));
  1061         hwnet->SendPasswordHash(hash);
   979             delete hpd;
  1062     }
   980             return;
  1063     else { //Send the hash
   981         }
  1064         hwnet->SendPasswordHash(temphash);
   982 
  1065     }
   983         QString password = hpd->lePassword->text();
  1066 
   984         hash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex();
  1067     //Remove temporary hash from config
   985 
  1068     config->clearTempHash();
   986         bool save = hpd->cbSave->isChecked();
  1069 }
   987         config->setValue("net/savepassword", save);
  1070 
   988         if (save) // user wants to save password
  1071 void HWForm::NetNickRegistered(const QString & nick)
   989         {
  1072 {
   990             config->setValue("net/passwordhash", hash);
  1073     //Get hashes
   991             config->setValue("net/passwordlength", password.size());
  1074     QString hash =  config->passwordHash();
   992             config->setNetPasswordLength(password.size());
  1075     QString temphash =  config->tempHash();
   993         }
  1076 
   994 
  1077     if (hash.isEmpty()) {
   995         delete hpd;
  1078         if (temphash.isEmpty()) { //If the user enters a registered nick with no password
   996     }
  1079             QString suppliedpass;
   997 
  1080             while (suppliedpass.isEmpty()) {
   998     hwnet->SendPasswordHash(hash);
  1081                 QInputDialog nickRegedDialog(this);
       
  1082                 nickRegedDialog.setWindowModality(Qt::WindowModal);
       
  1083                 nickRegedDialog.setInputMode(QInputDialog::TextInput);
       
  1084                 nickRegedDialog.setWindowTitle(tr("Hedgewars - Nick registered"));
       
  1085                 nickRegedDialog.setLabelText(tr("This nick is registered, and you haven't specified a password.\n\nIf this nick isn't yours, please register your own nick at www.hedgewars.org\n\nPassword:"));
       
  1086                 nickRegedDialog.setTextEchoMode(QLineEdit::Password);
       
  1087                 nickRegedDialog.exec();
       
  1088 
       
  1089                 suppliedpass = nickRegedDialog.textValue();
       
  1090 
       
  1091                 if (nickRegedDialog.result() == QDialog::Rejected) {
       
  1092                     config->clearPasswordHash();
       
  1093                     config->clearTempHash();
       
  1094                     GoBack();
       
  1095                     return;
       
  1096                 }
       
  1097                 temphash = QCryptographicHash::hash(suppliedpass.toUtf8(), QCryptographicHash::Md5).toHex();
       
  1098                 config->setTempHash(temphash);
       
  1099             }
       
  1100         }
       
  1101     }
       
  1102     NetPassword(nick);
       
  1103 }
       
  1104 
       
  1105 void HWForm::NetNickNotRegistered(const QString & nick)
       
  1106 {
       
  1107     QMessageBox noRegMsg(this);
       
  1108     noRegMsg.setIcon(QMessageBox::Information);
       
  1109     noRegMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Nick not registered"));
       
  1110     noRegMsg.setWindowModality(Qt::WindowModal);
       
  1111     noRegMsg.setText(tr("Your nickname is not registered.\nTo prevent someone else from using it,\nplease register it at www.hedgewars.org"));
       
  1112 
       
  1113     if (!config->passwordHash().isEmpty())
       
  1114     {
       
  1115         config->clearPasswordHash();
       
  1116         noRegMsg.setText(noRegMsg.text()+tr("\n\nYour password wasn't saved either."));
       
  1117     }
       
  1118     if (!config->tempHash().isEmpty())
       
  1119     {
       
  1120         config->clearTempHash();
       
  1121     }
       
  1122     noRegMsg.exec();
   999 }
  1123 }
  1000 
  1124 
  1001 void HWForm::NetNickTaken(const QString & nick)
  1125 void HWForm::NetNickTaken(const QString & nick)
  1002 {
  1126 {
  1003     bool ok = false;
  1127     bool ok = false;
  1004     QString newNick = QInputDialog::getText(this, tr("Nickname"), tr("Someone already uses your nickname %1 on the server.\nPlease pick another nickname:").arg(nick), QLineEdit::Normal, nick, &ok);
  1128     QString newNick = QInputDialog::getText(this, tr("Nickname"), tr("Someone already uses your nickname %1 on the server.\nPlease pick another nickname:").arg(nick), QLineEdit::Normal, nick, &ok);
  1005 
  1129 
  1006     if (!ok || newNick.isEmpty())
  1130     if (!ok || newNick.isEmpty())
  1007     {
  1131     {
  1008         ForcedDisconnect(tr("No nickname supplied."));
  1132         //ForcedDisconnect(tr("No nickname supplied."));
       
  1133     bool retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied."));
       
  1134     GoBack();
       
  1135         if (retry) {
       
  1136            NetConnectOfficialServer();
       
  1137         }
  1009         return;
  1138         return;
  1010     }
  1139     }
  1011 
  1140 
  1012     hwnet->NewNick(newNick);
  1141     hwnet->NewNick(newNick);
  1013     config->setValue("net/nick", newNick);
  1142     config->setValue("net/nick", newNick);
  1018 }
  1147 }
  1019 
  1148 
  1020 void HWForm::NetAuthFailed()
  1149 void HWForm::NetAuthFailed()
  1021 {
  1150 {
  1022     // Set the password blank if case the user tries to join and enter his password again
  1151     // Set the password blank if case the user tries to join and enter his password again
  1023     config->setValue("net/passwordlength", 0);
  1152     config->clearTempHash();
  1024     config->setNetPasswordLength(0);
  1153 
       
  1154     //Try to login again
       
  1155     bool retry = RetryDialog(tr("Hedgewars - Wrong password"), tr("You entered a wrong password."));
       
  1156     GoBack();
       
  1157 
       
  1158     config->clearPasswordHash();
       
  1159     config->clearTempHash();
       
  1160     if (retry) {
       
  1161        NetConnectOfficialServer();
       
  1162     }
       
  1163 }
       
  1164 
       
  1165 bool HWForm::RetryDialog(const QString & title, const QString & label)
       
  1166 {
       
  1167     QMessageBox retryMsg(this);
       
  1168     retryMsg.setIcon(QMessageBox::Warning);
       
  1169     retryMsg.setWindowTitle(title);
       
  1170     retryMsg.setText(label);
       
  1171     retryMsg.setWindowModality(Qt::WindowModal);
       
  1172 
       
  1173     retryMsg.addButton(QMessageBox::Cancel);
       
  1174 
       
  1175     QPushButton *retryButton = retryMsg.addButton(QMessageBox::Ok);
       
  1176     retryButton->setText(tr("Try Again"));
       
  1177     retryButton->setFocus();
       
  1178 
       
  1179     retryMsg.exec();
       
  1180 
       
  1181     if (retryMsg.clickedButton() == retryButton) {
       
  1182        return true;
       
  1183     }
       
  1184     return false;
  1025 }
  1185 }
  1026 
  1186 
  1027 void HWForm::NetTeamAccepted(const QString & team)
  1187 void HWForm::NetTeamAccepted(const QString & team)
  1028 {
  1188 {
  1029     ui.pageNetGame->pNetTeamsWidget->changeTeamStatus(team);
  1189     ui.pageNetGame->pNetTeamsWidget->changeTeamStatus(team);
  1072     connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()), Qt::QueuedConnection);
  1232     connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()), Qt::QueuedConnection);
  1073     connect(hwnet, SIGNAL(LeftRoom(const QString&)), this, SLOT(NetLeftRoom(const QString&)), Qt::QueuedConnection);
  1233     connect(hwnet, SIGNAL(LeftRoom(const QString&)), this, SLOT(NetLeftRoom(const QString&)), Qt::QueuedConnection);
  1074     connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(const HWTeam&)), Qt::QueuedConnection);
  1234     connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(const HWTeam&)), Qt::QueuedConnection);
  1075     connect(hwnet, SIGNAL(RemoveNetTeam(const HWTeam&)), this, SLOT(RemoveNetTeam(const HWTeam&)), Qt::QueuedConnection);
  1235     connect(hwnet, SIGNAL(RemoveNetTeam(const HWTeam&)), this, SLOT(RemoveNetTeam(const HWTeam&)), Qt::QueuedConnection);
  1076     connect(hwnet, SIGNAL(TeamAccepted(const QString&)), this, SLOT(NetTeamAccepted(const QString&)), Qt::QueuedConnection);
  1236     connect(hwnet, SIGNAL(TeamAccepted(const QString&)), this, SLOT(NetTeamAccepted(const QString&)), Qt::QueuedConnection);
  1077     connect(hwnet, SIGNAL(AskForPassword(const QString&)), this, SLOT(NetPassword(const QString&)), Qt::QueuedConnection);
  1237     connect(hwnet, SIGNAL(NickRegistered(const QString&)), this, SLOT(NetNickRegistered(const QString&)), Qt::QueuedConnection);
       
  1238     connect(hwnet, SIGNAL(NickNotRegistered(const QString&)), this, SLOT(NetNickNotRegistered(const QString&)), Qt::QueuedConnection);
  1078     connect(hwnet, SIGNAL(NickTaken(const QString&)), this, SLOT(NetNickTaken(const QString&)), Qt::QueuedConnection);
  1239     connect(hwnet, SIGNAL(NickTaken(const QString&)), this, SLOT(NetNickTaken(const QString&)), Qt::QueuedConnection);
  1079     connect(hwnet, SIGNAL(AuthFailed()), this, SLOT(NetAuthFailed()), Qt::QueuedConnection);
  1240     connect(hwnet, SIGNAL(AuthFailed()), this, SLOT(NetAuthFailed()), Qt::QueuedConnection);
  1080     //connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom()));
  1241     //connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom()));
  1081 
  1242 
  1082     ui.pageRoomsList->chatWidget->setUsersModel(hwnet->lobbyPlayersModel());
  1243     ui.pageRoomsList->chatWidget->setUsersModel(hwnet->lobbyPlayersModel());
  1083     ui.pageNetGame->pChatWidget->setUsersModel(hwnet->roomPlayersModel());
  1244     ui.pageNetGame->chatWidget->setUsersModel(hwnet->roomPlayersModel());
  1084 
  1245 
  1085 // rooms list page stuff
  1246 // rooms list page stuff
  1086     ui.pageRoomsList->setModel(hwnet->roomsListModel());
  1247     ui.pageRoomsList->setModel(hwnet->roomsListModel());
  1087     connect(hwnet, SIGNAL(adminAccess(bool)),
  1248     connect(hwnet, SIGNAL(adminAccess(bool)),
  1088             ui.pageRoomsList, SLOT(setAdmin(bool)), Qt::QueuedConnection);
  1249             ui.pageRoomsList, SLOT(setAdmin(bool)), Qt::QueuedConnection);
  1107     connect(hwnet, SIGNAL(roomMaster(bool)),
  1268     connect(hwnet, SIGNAL(roomMaster(bool)),
  1108             this, SLOT(NetGameChangeStatus(bool)), Qt::QueuedConnection);
  1269             this, SLOT(NetGameChangeStatus(bool)), Qt::QueuedConnection);
  1109 
  1270 
  1110 // net page stuff
  1271 // net page stuff
  1111     connect(hwnet, SIGNAL(chatStringFromNet(const QString&)),
  1272     connect(hwnet, SIGNAL(chatStringFromNet(const QString&)),
  1112             ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
  1273             ui.pageNetGame->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
  1113 
  1274 
  1114     connect(hwnet, SIGNAL(chatStringFromMe(const QString&)),
  1275     connect(hwnet, SIGNAL(chatStringFromMe(const QString&)),
  1115             ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
  1276             ui.pageNetGame->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
  1116     connect(hwnet, SIGNAL(roomMaster(bool)),
  1277     connect(hwnet, SIGNAL(roomMaster(bool)),
  1117             ui.pageNetGame->pChatWidget, SLOT(adminAccess(bool)), Qt::QueuedConnection);
  1278             ui.pageNetGame->chatWidget, SLOT(adminAccess(bool)), Qt::QueuedConnection);
  1118     connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)),
  1279     connect(ui.pageNetGame->chatWidget, SIGNAL(chatLine(const QString&)),
  1119             hwnet, SLOT(chatLineToNet(const QString&)));
  1280             hwnet, SLOT(chatLineToNet(const QString&)));
  1120     connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady()));
  1281     connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady()));
  1121     connect(hwnet, SIGNAL(setMyReadyStatus(bool)),
  1282     connect(hwnet, SIGNAL(setMyReadyStatus(bool)),
  1122             ui.pageNetGame, SLOT(setReadyStatus(bool)), Qt::QueuedConnection);
  1283             ui.pageNetGame, SLOT(setReadyStatus(bool)), Qt::QueuedConnection);
  1123 
  1284 
  1124 // chat widget actions
  1285 // chat widget actions
  1125     connect(ui.pageNetGame->pChatWidget, SIGNAL(kick(const QString&)),
  1286     connect(ui.pageNetGame->chatWidget, SIGNAL(kick(const QString&)),
  1126             hwnet, SLOT(kickPlayer(const QString&)));
  1287             hwnet, SLOT(kickPlayer(const QString&)));
  1127     connect(ui.pageNetGame->pChatWidget, SIGNAL(ban(const QString&)),
  1288     connect(ui.pageNetGame->chatWidget, SIGNAL(ban(const QString&)),
  1128             hwnet, SLOT(banPlayer(const QString&)));
  1289             hwnet, SLOT(banPlayer(const QString&)));
  1129     connect(ui.pageNetGame->pChatWidget, SIGNAL(info(const QString&)),
  1290     connect(ui.pageNetGame->chatWidget, SIGNAL(info(const QString&)),
  1130             hwnet, SLOT(infoPlayer(const QString&)));
  1291             hwnet, SLOT(infoPlayer(const QString&)));
  1131     connect(ui.pageNetGame->pChatWidget, SIGNAL(follow(const QString&)),
  1292     connect(ui.pageNetGame->chatWidget, SIGNAL(follow(const QString&)),
  1132             hwnet, SLOT(followPlayer(const QString&)));
  1293             hwnet, SLOT(followPlayer(const QString&)));
  1133     connect(ui.pageRoomsList->chatWidget, SIGNAL(kick(const QString&)),
  1294     connect(ui.pageRoomsList->chatWidget, SIGNAL(kick(const QString&)),
  1134             hwnet, SLOT(kickPlayer(const QString&)));
  1295             hwnet, SLOT(kickPlayer(const QString&)));
  1135     connect(ui.pageRoomsList->chatWidget, SIGNAL(ban(const QString&)),
  1296     connect(ui.pageRoomsList->chatWidget, SIGNAL(ban(const QString&)),
  1136             hwnet, SLOT(banPlayer(const QString&)));
  1297             hwnet, SLOT(banPlayer(const QString&)));
  1149     connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)),
  1310     connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)),
  1150             ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
  1311             ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
  1151 
  1312 
  1152 // nick list stuff
  1313 // nick list stuff
  1153     connect(hwnet, SIGNAL(nickAdded(const QString&, bool)),
  1314     connect(hwnet, SIGNAL(nickAdded(const QString&, bool)),
  1154             ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection);
  1315             ui.pageNetGame->chatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection);
  1155     connect(hwnet, SIGNAL(nickRemoved(const QString&)),
  1316     connect(hwnet, SIGNAL(nickRemoved(const QString&)),
  1156             ui.pageNetGame->pChatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection);
  1317             ui.pageNetGame->chatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection);
  1157     connect(hwnet, SIGNAL(nickAddedLobby(const QString&, bool)),
  1318     connect(hwnet, SIGNAL(nickAddedLobby(const QString&, bool)),
  1158             ui.pageRoomsList->chatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection);
  1319             ui.pageRoomsList->chatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection);
  1159     connect(hwnet, SIGNAL(nickRemovedLobby(const QString&)),
  1320     connect(hwnet, SIGNAL(nickRemovedLobby(const QString&)),
  1160             ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection);
  1321             ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection);
  1161 
  1322 
  1174 
  1335 
  1175 // admin stuff
  1336 // admin stuff
  1176     connect(hwnet, SIGNAL(serverMessageNew(const QString&)), ui.pageAdmin, SLOT(serverMessageNew(const QString &)));
  1337     connect(hwnet, SIGNAL(serverMessageNew(const QString&)), ui.pageAdmin, SLOT(serverMessageNew(const QString &)));
  1177     connect(hwnet, SIGNAL(serverMessageOld(const QString&)), ui.pageAdmin, SLOT(serverMessageOld(const QString &)));
  1338     connect(hwnet, SIGNAL(serverMessageOld(const QString&)), ui.pageAdmin, SLOT(serverMessageOld(const QString &)));
  1178     connect(hwnet, SIGNAL(latestProtocolVar(int)), ui.pageAdmin, SLOT(protocol(int)));
  1339     connect(hwnet, SIGNAL(latestProtocolVar(int)), ui.pageAdmin, SLOT(protocol(int)));
       
  1340     connect(hwnet, SIGNAL(bansList(const QStringList &)), ui.pageAdmin, SLOT(setBansList(const QStringList &)));
  1179     connect(ui.pageAdmin, SIGNAL(setServerMessageNew(const QString&)), hwnet, SLOT(setServerMessageNew(const QString &)));
  1341     connect(ui.pageAdmin, SIGNAL(setServerMessageNew(const QString&)), hwnet, SLOT(setServerMessageNew(const QString &)));
  1180     connect(ui.pageAdmin, SIGNAL(setServerMessageOld(const QString&)), hwnet, SLOT(setServerMessageOld(const QString &)));
  1342     connect(ui.pageAdmin, SIGNAL(setServerMessageOld(const QString&)), hwnet, SLOT(setServerMessageOld(const QString &)));
  1181     connect(ui.pageAdmin, SIGNAL(setProtocol(int)), hwnet, SLOT(setLatestProtocolVar(int)));
  1343     connect(ui.pageAdmin, SIGNAL(setProtocol(int)), hwnet, SLOT(setLatestProtocolVar(int)));
  1182     connect(ui.pageAdmin, SIGNAL(askServerVars()), hwnet, SLOT(askServerVars()));
  1344     connect(ui.pageAdmin, SIGNAL(askServerVars()), hwnet, SLOT(askServerVars()));
  1183     connect(ui.pageAdmin, SIGNAL(clearAccountsCache()), hwnet, SLOT(clearAccountsCache()));
  1345     connect(ui.pageAdmin, SIGNAL(clearAccountsCache()), hwnet, SLOT(clearAccountsCache()));
       
  1346     connect(ui.pageAdmin, SIGNAL(bansListRequest()), hwnet, SLOT(getBanList()));
       
  1347     connect(ui.pageAdmin, SIGNAL(removeBan(QString)), hwnet, SLOT(removeBan(QString)));
       
  1348     connect(ui.pageAdmin, SIGNAL(banIP(QString,QString,int)), hwnet, SLOT(banIP(QString,QString,int)));
       
  1349     connect(ui.pageAdmin, SIGNAL(banNick(QString,QString,int)), hwnet, SLOT(banNick(QString,QString,int)));
  1184 
  1350 
  1185 // disconnect
  1351 // disconnect
  1186     connect(hwnet, SIGNAL(disconnected(const QString&)), this, SLOT(ForcedDisconnect(const QString&)), Qt::QueuedConnection);
  1352     connect(hwnet, SIGNAL(disconnected(const QString&)), this, SLOT(ForcedDisconnect(const QString&)), Qt::QueuedConnection);
  1187 
  1353 
  1188 // config stuff
  1354 // config stuff
  1189     connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &)));
  1355     connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &)));
  1190     connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &)));
  1356     connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &)));
  1191     connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig()));
  1357     connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig()));
  1192 
  1358 
  1193     while (nick.isEmpty())
  1359 //nick and pass stuff
  1194     {
  1360 
  1195         nick = QInputDialog::getText(this,
  1361     //remove temppasswordhash just in case
  1196                                      QObject::tr("Nickname"),
  1362     config->clearTempHash();
  1197                                      QObject::tr("Please enter your nickname"),
  1363 
  1198                                      QLineEdit::Normal,
  1364     //initialize
  1199                                      QDir::home().dirName());
  1365     QString hash = config->passwordHash();
  1200         config->setValue("net/nick",nick);
  1366     QString temphash = config->tempHash();
       
  1367     QString nickname = config->value("net/nick", "").toString();
       
  1368     QString password;
       
  1369 
       
  1370     if (nickname.isEmpty() || hash.isEmpty()) { //if something from login is missing, start dialog loop
       
  1371 
       
  1372         while (nickname.isEmpty() || (hash.isEmpty() && temphash.isEmpty())) //while a nickname, or both hashes are missing
       
  1373         {
       
  1374         //open dialog
       
  1375             HWPasswordDialog * pwDialog = new HWPasswordDialog(this);
       
  1376             pwDialog->cbSave->setChecked(config->value("net/savepassword", true).toBool());
       
  1377 
       
  1378         //if nickname is present, put it into the field
       
  1379         if (!nickname.isEmpty()) {
       
  1380             pwDialog->leNickname->setText(nickname);
       
  1381             pwDialog->lePassword->setFocus();
       
  1382         }
       
  1383 
       
  1384         //if dialog close, create an error message
       
  1385         if (pwDialog->exec() != QDialog::Accepted) {
       
  1386             delete pwDialog;
       
  1387             GoBack();
       
  1388             return;
       
  1389         }
       
  1390 
       
  1391         //set nick and pass from the dialog
       
  1392         nickname = pwDialog->leNickname->text();
       
  1393         password = pwDialog->lePassword->text();
       
  1394 
       
  1395         //check the nickname variable
       
  1396         if (nickname.isEmpty()) {
       
  1397             int retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied."));
       
  1398             GoBack();
       
  1399             delete pwDialog;
       
  1400             if (retry) {
       
  1401                 NetConnectOfficialServer();
       
  1402             }
       
  1403             return;
       
  1404         }
       
  1405 
       
  1406         if (!password.isEmpty()) {
       
  1407             //calculate temphash and set it into config
       
  1408             temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex();
       
  1409             config->setTempHash(temphash);
       
  1410 
       
  1411             //if user wants to save password
       
  1412             bool save = pwDialog->cbSave->isChecked();
       
  1413             config->setValue("net/savepassword", save);
       
  1414             if (save) // user wants to save password
       
  1415             {
       
  1416                 config->setPasswordHash(temphash);
       
  1417             }
       
  1418         }
       
  1419         else {
       
  1420             delete pwDialog;
       
  1421             config->setValue("net/nick", nickname);
       
  1422             config->updNetNick();
       
  1423             config->clearPasswordHash();
       
  1424             break;
       
  1425         }
       
  1426 
       
  1427         delete pwDialog;
       
  1428 
       
  1429         //update nickname
       
  1430         config->setValue("net/nick", nickname);
  1201         config->updNetNick();
  1431         config->updNetNick();
  1202     }
  1432 
  1203 
  1433         //and all the variables
  1204     ui.pageRoomsList->setUser(nick);
  1434         hash = config->passwordHash();
  1205     ui.pageNetGame->setUser(nick);
  1435         temphash = config->tempHash();
  1206 
  1436         nickname = config->value("net/nick", "").toString();
  1207     hwnet->Connect(hostName, port, nick);
  1437         }
  1208 }
  1438     }
       
  1439 
       
  1440     ui.pageRoomsList->setUser(nickname);
       
  1441     ui.pageNetGame->setUser(nickname);
       
  1442 
       
  1443     hwnet->Connect(hostName, port, nickname);
       
  1444 }
       
  1445 
       
  1446 
  1209 
  1447 
  1210 void HWForm::NetConnect()
  1448 void HWForm::NetConnect()
  1211 {
  1449 {
  1212     HWHostPortDialog * hpd = new HWHostPortDialog(this);
  1450     HWHostPortDialog * hpd = new HWHostPortDialog(this);
  1213     hpd->leHost->setText(*netHost);
  1451     hpd->leHost->setText(*netHost);
  1269         hwnet->Disconnect();
  1507         hwnet->Disconnect();
  1270 }
  1508 }
  1271 
  1509 
  1272 void HWForm::ForcedDisconnect(const QString & reason)
  1510 void HWForm::ForcedDisconnect(const QString & reason)
  1273 {
  1511 {
       
  1512     if (reason == "Reconnected too fast") { //TODO: this is a hack, which should be remade
       
  1513         bool retry = RetryDialog(tr("Hedgewars - Connection error"), tr("You reconnected too fast.\nPlease wait a few seconds and try again."));
       
  1514         if (retry) {
       
  1515             NetConnectOfficialServer();
       
  1516         }
       
  1517         else {
       
  1518             while (ui.Pages->currentIndex() != ID_PAGE_NET
       
  1519                 && ui.Pages->currentIndex() != ID_PAGE_MAIN)
       
  1520             {
       
  1521                 GoBack();
       
  1522             }
       
  1523         }
       
  1524         return;
       
  1525     }
  1274     if (pnetserver)
  1526     if (pnetserver)
  1275         return; // we have server - let it care of all things
  1527         return; // we have server - let it care of all things
  1276     if (hwnet)
  1528     if (hwnet)
  1277     {
  1529     {
  1278         QString errorStr = QMessageBox::tr("Connection to server is lost") + (reason.isEmpty()?"":("\n\n" + HWNewNet::tr("Quit reason: ") + '"' + reason +'"'));
  1530         QString errorStr = QMessageBox::tr("Connection to server is lost") + (reason.isEmpty()?"":("\n\n" + HWNewNet::tr("Quit reason: ") + '"' + reason +'"'));
  1279         ShowErrorMessage(errorStr);
  1531         ShowErrorMessage(errorStr);
  1280     }
  1532     }
  1281 
  1533 
  1282     while (ui.Pages->currentIndex() != ID_PAGE_NET
  1534     while (ui.Pages->currentIndex() != ID_PAGE_NET
  1283         && ui.Pages->currentIndex() != ID_PAGE_NETTYPE
       
  1284         && ui.Pages->currentIndex() != ID_PAGE_MAIN)
  1535         && ui.Pages->currentIndex() != ID_PAGE_MAIN)
  1285     {
  1536     {
  1286         GoBack();
  1537         GoBack();
  1287     }
  1538     }
  1288 }
  1539 }
  1292     GoToPage(ID_PAGE_ROOMSLIST);
  1543     GoToPage(ID_PAGE_ROOMSLIST);
  1293 }
  1544 }
  1294 
  1545 
  1295 void HWForm::NetGameEnter()
  1546 void HWForm::NetGameEnter()
  1296 {
  1547 {
  1297     ui.pageNetGame->pChatWidget->clear();
  1548     ui.pageNetGame->chatWidget->clear();
  1298     GoToPage(ID_PAGE_NETGAME);
  1549     GoToPage(ID_PAGE_NETGAME);
  1299 }
  1550 }
  1300 
  1551 
  1301 void HWForm::AddNetTeam(const HWTeam& team)
  1552 void HWForm::AddNetTeam(const HWTeam& team)
  1302 {
  1553 {
  1343         case gsFinished:
  1594         case gsFinished:
  1344         {
  1595         {
  1345             //setVisible(true);
  1596             //setVisible(true);
  1346             setFocusPolicy(Qt::StrongFocus);
  1597             setFocusPolicy(Qt::StrongFocus);
  1347             if (id == ID_PAGE_INGAME) GoBack();
  1598             if (id == ID_PAGE_INGAME) GoBack();
  1348             Music(ui.pageOptions->CBEnableFrontendMusic->isChecked());
  1599             Music(ui.pageOptions->CBFrontendMusic->isChecked());
  1349             if (wBackground) wBackground->startAnimation();
  1600             if (wBackground) wBackground->startAnimation();
  1350             GoToPage(ID_PAGE_GAMESTATS);
  1601             GoToPage(ID_PAGE_GAMESTATS);
  1351             if (hwnet && (!game || !game->netSuspend)) hwnet->gameFinished(true);
  1602             if (hwnet && (!game || !game->netSuspend)) hwnet->gameFinished(true);
  1352             if (game) game->netSuspend = false;
  1603             if (game) game->netSuspend = false;
  1353             break;
  1604             break;
  1361 // was room chief and the game was aborted
  1612 // was room chief and the game was aborted
  1362                     (hwnet && hwnet->isRoomChief() && hwnet->isInRoom() &&
  1613                     (hwnet && hwnet->isRoomChief() && hwnet->isInRoom() &&
  1363                      (gameState == gsInterrupted || gameState == gsStopped || gameState == gsDestroyed || gameState == gsHalted)))
  1614                      (gameState == gsInterrupted || gameState == gsStopped || gameState == gsDestroyed || gameState == gsHalted)))
  1364             {
  1615             {
  1365                 if (id == ID_PAGE_INGAME) GoBack();
  1616                 if (id == ID_PAGE_INGAME) GoBack();
  1366                 Music(ui.pageOptions->CBEnableFrontendMusic->isChecked());
  1617                 Music(ui.pageOptions->CBFrontendMusic->isChecked());
  1367                 if (wBackground) wBackground->startAnimation();
  1618                 if (wBackground) wBackground->startAnimation();
  1368                 if (hwnet) hwnet->gameFinished(false);
  1619                 if (hwnet) hwnet->gameFinished(false);
  1369             }
  1620             }
  1370             if (gameState == gsHalted) close();
  1621             if (gameState == gsHalted) close();
  1371         };
  1622         };
  1478 {
  1729 {
  1479 #ifdef USE_XFIRE
  1730 #ifdef USE_XFIRE
  1480     xfire_free();
  1731     xfire_free();
  1481 #endif
  1732 #endif
  1482     config->SaveOptions();
  1733     config->SaveOptions();
       
  1734 #if VIDEOREC
  1483     config->SaveVideosOptions();
  1735     config->SaveVideosOptions();
       
  1736 #endif
  1484     event->accept();
  1737     event->accept();
  1485 }
  1738 }
  1486 
  1739 
  1487 void HWForm::Music(bool checked)
  1740 void HWForm::Music(bool checked)
  1488 {
  1741 {
  1630 }
  1883 }
  1631 
  1884 
  1632 // used for --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]
  1885 // used for --set-everything [screen width] [screen height] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]
  1633 QString HWForm::getDemoArguments()
  1886 QString HWForm::getDemoArguments()
  1634 {
  1887 {
       
  1888 
       
  1889     QString prefix = datadir->absolutePath();
       
  1890     QString userPrefix = cfgdir->absolutePath();
       
  1891 #ifdef Q_WS_WIN
       
  1892     prefix = prefix.replace("/","\\");
       
  1893     userPrefix = userPrefix.replace("/","\\");
       
  1894 #endif
       
  1895 
  1635     QRect resolution = config->vid_Resolution();
  1896     QRect resolution = config->vid_Resolution();
  1636     return QString(QString::number(resolution.width()) + " "
  1897     return QString("--prefix " + prefix
  1637                    + QString::number(resolution.height()) + " "
  1898                    + " --user-prefix " + userPrefix
  1638                    + QString::number(config->bitDepth()) + " " // bpp
  1899                    + " --width " + QString::number(resolution.width())
  1639                    + QString::number(config->volume()) + " " // sound volume
  1900                    + " --height " + QString::number(resolution.height())
  1640                    + (config->isMusicEnabled() ? "1" : "0") + " "
  1901                    + " --volume " + QString::number(config->volume())
  1641                    + (config->isSoundEnabled() ? "1" : "0") + " "
  1902                    + (config->isMusicEnabled() ? "" : " --nomusic")
  1642                    + config->language() + ".txt "
  1903                    + (config->isSoundEnabled() ? "" : " --nosound")
  1643                    + (config->vid_Fullscreen() ? "1" : "0") + " "
  1904                    + " --locale " + config->language() + ".txt"
  1644                    + (config->isShowFPSEnabled() ? "1" : "0") + " "
  1905                    + (config->vid_Fullscreen() ? " --fullscreen" : "")
  1645                    + (config->isAltDamageEnabled() ? "1" : "0") + " "
  1906                    + (config->isShowFPSEnabled() ? " --showfps" : "")
  1646                    + QString::number(config->timerInterval()) + " "
  1907                    + (config->isAltDamageEnabled() ? " --altdmg" : "")
  1647                    + QString::number(config->translateQuality()));
  1908                    + " --frame-interval " + QString::number(config->timerInterval())
       
  1909                    + " --raw-quality " + QString::number(config->translateQuality()));
  1648 }
  1910 }
  1649 
  1911 
  1650 void HWForm::AssociateFiles()
  1912 void HWForm::AssociateFiles()
  1651 {
  1913 {
  1652     bool success = true;
  1914     bool success = true;
  1657     registry_hkcr.setValue(".hws/Default", "Hedgewars.Save");
  1919     registry_hkcr.setValue(".hws/Default", "Hedgewars.Save");
  1658     registry_hkcr.setValue("Hedgewars.Demo/Default", tr("Hedgewars Demo File", "File Types"));
  1920     registry_hkcr.setValue("Hedgewars.Demo/Default", tr("Hedgewars Demo File", "File Types"));
  1659     registry_hkcr.setValue("Hedgewars.Save/Default", tr("Hedgewars Save File", "File Types"));
  1921     registry_hkcr.setValue("Hedgewars.Save/Default", tr("Hedgewars Save File", "File Types"));
  1660     registry_hkcr.setValue("Hedgewars.Demo/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwdfile.ico\",0");
  1922     registry_hkcr.setValue("Hedgewars.Demo/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwdfile.ico\",0");
  1661     registry_hkcr.setValue("Hedgewars.Save/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwsfile.ico\",0");
  1923     registry_hkcr.setValue("Hedgewars.Save/DefaultIcon/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwsfile.ico\",0");
  1662     registry_hkcr.setValue("Hedgewars.Demo/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + cfgdir->absolutePath().replace("/","\\") + "\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\" --set-everything "+arguments);
  1924     registry_hkcr.setValue("Hedgewars.Demo/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"%1\" "+arguments);
  1663     registry_hkcr.setValue("Hedgewars.Save/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"" + cfgdir->absolutePath().replace("/","\\") + "\" \"" + datadir->absolutePath().replace("/", "\\") + "\" \"%1\" --set-everything "+arguments);
  1925     registry_hkcr.setValue("Hedgewars.Save/Shell/Open/Command/Default", "\"" + bindir->absolutePath().replace("/", "\\") + "\\hwengine.exe\" \"%1\" "+arguments);
  1664 #elif defined __APPLE__
  1926 #elif defined __APPLE__
  1665     // only useful when other apps have taken precedence over our file extensions and you want to reset it
  1927     // only useful when other apps have taken precedence over our file extensions and you want to reset it
  1666     system("defaults write com.apple.LaunchServices LSHandlers -array-add '<dict><key>LSHandlerContentTag</key><string>hwd</string><key>LSHandlerContentTagClass</key><string>public.filename-extension</string><key>LSHandlerRoleAll</key><string>org.hedgewars.desktop</string></dict>'");
  1928     system("defaults write com.apple.LaunchServices LSHandlers -array-add '<dict><key>LSHandlerContentTag</key><string>hwd</string><key>LSHandlerContentTagClass</key><string>public.filename-extension</string><key>LSHandlerRoleAll</key><string>org.hedgewars.desktop</string></dict>'");
  1667     system("defaults write com.apple.LaunchServices LSHandlers -array-add '<dict><key>LSHandlerContentTag</key><string>hws</string><key>LSHandlerContentTagClass</key><string>public.filename-extension</string><key>LSHandlerRoleAll</key><string>org.hedgewars.desktop</string></dict>'");
  1929     system("defaults write com.apple.LaunchServices LSHandlers -array-add '<dict><key>LSHandlerContentTag</key><string>hws</string><key>LSHandlerContentTagClass</key><string>public.filename-extension</string><key>LSHandlerRoleAll</key><string>org.hedgewars.desktop</string></dict>'");
  1668     system("/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -domain local -domain system -domain user");
  1930     system("/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -domain local -domain system -domain user");
  1679     if (success) success = system(("cp "+datadir->absolutePath()+"/misc/hwengine.desktop "+QDir::home().absolutePath()+"/.local/share/applications").toLocal8Bit().constData())==0;
  1941     if (success) success = system(("cp "+datadir->absolutePath()+"/misc/hwengine.desktop "+QDir::home().absolutePath()+"/.local/share/applications").toLocal8Bit().constData())==0;
  1680     if (success) success = system(("update-mime-database "+QDir::home().absolutePath()+"/.local/share/mime").toLocal8Bit().constData())==0;
  1942     if (success) success = system(("update-mime-database "+QDir::home().absolutePath()+"/.local/share/mime").toLocal8Bit().constData())==0;
  1681     if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-demo")==0;
  1943     if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-demo")==0;
  1682     if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-save")==0;
  1944     if (success) success = system("xdg-mime default hwengine.desktop application/x-hedgewars-save")==0;
  1683     // 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
  1945     // 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
  1684     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;
  1946     if (success) success = system(("sed -i 's/^\\(Exec=.*\\) \\([^ ]* %f\\)/\\1 \\2 "+arguments+"/' "+QDir::home().absolutePath()+"/.local/share/applications/hwengine.desktop").toLocal8Bit().constData())==0;
  1685 #endif
  1947 #endif
  1686     if (success)
  1948     if (success)
  1687     {
  1949     {
  1688         QMessageBox infoMsg(this);
  1950         QMessageBox infoMsg(this);
  1689         infoMsg.setIcon(QMessageBox::Information);
  1951         infoMsg.setIcon(QMessageBox::Information);
  1724     }
  1986     }
  1725 }
  1987 }
  1726 
  1988 
  1727 void HWForm::SendFeedback()
  1989 void HWForm::SendFeedback()
  1728 {
  1990 {
  1729     //Create Xml representation of google code issue first
  1991     // Get form data
  1730     if (!CreateIssueXml())
  1992 
  1731     {
  1993     QString summary = ui.pageFeedback->summary->text();
  1732         ShowErrorMessage(QMessageBox::tr("Please fill out all fields"));
  1994     QString description = ui.pageFeedback->description->toPlainText();
       
  1995     QString email = ui.pageFeedback->email->text();
       
  1996     QString captchaCode = ui.pageFeedback->captcha_code->text();
       
  1997     QString captchaID = QString::number(ui.pageFeedback->captchaID);
       
  1998     QString version = "HedgewarsFoundation-Hedgewars-" + (cVersionString?(*cVersionString):QString(""));
       
  1999 
       
  2000     if (summary.isEmpty() || description.isEmpty())
       
  2001     {
       
  2002         ShowErrorMessage(QMessageBox::tr("Please fill out all fields. Email is optional."));
  1733         return;
  2003         return;
  1734     }
  2004     }
  1735 
  2005 
  1736     //Google login using fake account (feedback.hedgewars@gmail.com)
  2006     // Submit issue to PHP script
       
  2007 
       
  2008     QByteArray body;
       
  2009     body.append("captcha=");
       
  2010     body.append(captchaID);
       
  2011     body.append("&code=");
       
  2012     body.append(captchaCode);
       
  2013     body.append("&version=");
       
  2014     body.append(QUrl::toPercentEncoding(version));
       
  2015     body.append("&title=");
       
  2016     body.append(QUrl::toPercentEncoding(summary));
       
  2017     body.append("&body=");
       
  2018     body.append(QUrl::toPercentEncoding(description));
       
  2019     body.append("&email=");
       
  2020     body.append(QUrl::toPercentEncoding(email));
       
  2021     if (ui.pageFeedback->CheckSendSpecs->isChecked())
       
  2022     {
       
  2023         body.append("&specs=");
       
  2024         body.append(QUrl::toPercentEncoding(ui.pageFeedback->specs));
       
  2025     }
       
  2026 
  1737     nam = new QNetworkAccessManager(this);
  2027     nam = new QNetworkAccessManager(this);
  1738     connect(nam, SIGNAL(finished(QNetworkReply*)),
  2028     connect(nam, SIGNAL(finished(QNetworkReply*)),
  1739             this, SLOT(finishedSlot(QNetworkReply*)));
  2029             this, SLOT(finishedSlot(QNetworkReply*)));
  1740 
  2030 
  1741     QUrl url(QString("https://www.google.com/accounts/ClientLogin?"
  2031     QNetworkRequest header(QUrl("http://hedgewars.org/feedback/?submit"));
  1742                      "accountType=GOOGLE&Email=feedback.hedgewars@gmail.com&Passwd=hwfeedback&service=code&source=HedgewarsFoundation-Hedgewars-")
  2032     header.setRawHeader("Content-Length", QString::number(body.size()).toAscii());
  1743                     + (cVersionString?(*cVersionString):QString("")));
  2033 
  1744     nam->get(QNetworkRequest(url));
  2034     nam->post(header, body);
  1745 
       
  1746 }
       
  1747 
       
  1748 bool HWForm::CreateIssueXml()
       
  1749 {
       
  1750     QString summary = ui.pageFeedback->summary->text();
       
  1751     QString description = ui.pageFeedback->description->toPlainText();
       
  1752 
       
  1753     //Check if all necessary information is entered
       
  1754     if (summary.isEmpty() || description.isEmpty())
       
  1755         return false;
       
  1756 
       
  1757     issueXml =
       
  1758         "<?xml version='1.0' encoding='UTF-8'?>"
       
  1759         "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:issues='http://code.google.com/p/hedgewars/issues/list'>"
       
  1760         "<title>";
       
  1761     issueXml.append(summary);
       
  1762     issueXml.append("</title><content type='html'>");
       
  1763     issueXml.append(description);
       
  1764     issueXml.append("</content><author><name>feedback.hedgewars</name></author></entry>");
       
  1765 
       
  1766     return true;
       
  1767 }
  2035 }
  1768 
  2036 
  1769 void HWForm::finishedSlot(QNetworkReply* reply)
  2037 void HWForm::finishedSlot(QNetworkReply* reply)
  1770 {
  2038 {
  1771     if (reply && reply->error() == QNetworkReply::NoError)
  2039     if (reply && reply->error() == QNetworkReply::NoError)
  1772     {
  2040     {
  1773         QByteArray array = reply->readAll();
       
  1774         QString str(array);
       
  1775 
       
  1776         if (authToken.length() != 0)
       
  1777         {
       
  1778 
       
  1779             QMessageBox infoMsg(this);
  2041             QMessageBox infoMsg(this);
  1780             infoMsg.setIcon(QMessageBox::Information);
  2042             infoMsg.setIcon(QMessageBox::Information);
  1781             infoMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Success"));
  2043             infoMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Success"));
  1782             infoMsg.setText(QMessageBox::tr("Successfully posted the issue on hedgewars.googlecode.com"));
  2044             infoMsg.setText(reply->readAll());
  1783             infoMsg.setWindowModality(Qt::WindowModal);
  2045             infoMsg.setWindowModality(Qt::WindowModal);
  1784             infoMsg.exec();
  2046             infoMsg.exec();
  1785 
  2047 
  1786             ui.pageFeedback->summary->clear();
  2048             ui.pageFeedback->summary->clear();
       
  2049             ui.pageFeedback->email->clear();
  1787             ui.pageFeedback->description->clear();
  2050             ui.pageFeedback->description->clear();
  1788             authToken = "";
  2051             ui.pageFeedback->LoadCaptchaImage();
       
  2052 
  1789             return;
  2053             return;
  1790         }
  2054     }
  1791 
       
  1792         if (!getAuthToken(str))
       
  1793         {
       
  1794             ShowErrorMessage(QMessageBox::tr("Error during authentication at google.com"));
       
  1795             return;
       
  1796         }
       
  1797 
       
  1798         QByteArray body(issueXml.toUtf8());
       
  1799         QNetworkRequest header(QUrl("https://code.google.com/feeds/issues/p/hedgewars/issues/full"));
       
  1800         header.setRawHeader("Content-Length", QString::number(issueXml.length()).toAscii());
       
  1801         header.setRawHeader("Content-Type", "application/atom+xml");
       
  1802         header.setRawHeader("Authorization", QString("GoogleLogin auth=%1").arg(authToken).toUtf8());
       
  1803         nam->post(header, body);
       
  1804 
       
  1805     }
       
  1806     else if (authToken.length() == 0)
       
  1807         ShowErrorMessage(QMessageBox::tr("Error during authentication at google.com"));
       
  1808     else
  2055     else
  1809     {
  2056     {
  1810         ShowErrorMessage(QMessageBox::tr("Error reporting the issue, please try again later (or visit hedgewars.googlecode.com directly)"));
  2057         ShowErrorMessage(QString("Error: ") + reply->readAll());
  1811         authToken = "";
  2058         ui.pageFeedback->LoadCaptchaImage();
  1812     }
  2059     }
  1813 
  2060 }
  1814 }
  2061 
  1815 
       
  1816 bool HWForm::getAuthToken(QString str)
       
  1817 {
       
  1818     QRegExp ex("Auth=(.+)");
       
  1819 
       
  1820     if (-1 == ex.indexIn(str))
       
  1821         return false;
       
  1822 
       
  1823     authToken = ex.cap(1);
       
  1824     authToken.remove(QChar('\n'));
       
  1825 
       
  1826     return true;
       
  1827 }
       
  1828 
       
  1829 
       
  1830