QTfrontend/hwform.cpp
changeset 5906 ed9676dc8cb4
parent 5865 35387d27f73a
child 5907 64ccc6be0ec5
--- a/QTfrontend/hwform.cpp	Wed Sep 14 22:27:22 2011 +0200
+++ b/QTfrontend/hwform.cpp	Wed Sep 14 22:39:39 2011 +0200
@@ -38,6 +38,7 @@
 #include <QSignalMapper>
 #include <QShortcut>
 #include <QDesktopServices>
+#include <QInputDialog>
 
 #include "hwform.h"
 #include "game.h"
@@ -92,7 +93,7 @@
 bool frontendEffects = true;
 QString playerHash;
 
-HWForm::HWForm(QWidget *parent)
+HWForm::HWForm(QWidget *parent, QString styleSheet)
   : QMainWindow(parent), pnetserver(0), pRegisterServer(0), editedTeam(0), hwnet(0)
 {
 #ifdef USE_XFIRE
@@ -103,6 +104,7 @@
     frontendEffects = gameSettings->value("frontend/effects", true).toBool();
     playerHash = QString(QCryptographicHash::hash(gameSettings->value("net/nick","").toString().toLatin1(), QCryptographicHash::Md5).toHex());
 
+    this->setStyleSheet(styleSheet);
     ui.setupUi(this);
     setMinimumSize(760, 580);
     //setFocusPolicy(Qt::StrongFocus);
@@ -151,12 +153,17 @@
     
     connect(ui.pageMain->BtnNet, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
     pageSwitchMapper->setMapping(ui.pageMain->BtnNet, ID_PAGE_NETTYPE);
+
     connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
-    pageSwitchMapper->setMapping(ui.pageMain->BtnInfo, ID_PAGE_DATADOWNLOAD);
+    pageSwitchMapper->setMapping(ui.pageMain->BtnInfo, ID_PAGE_INFO);
+
+    connect(ui.pageMain->BtnDataDownload, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
+    pageSwitchMapper->setMapping(ui.pageMain->BtnDataDownload, ID_PAGE_DATADOWNLOAD);
 
     connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed()));
     connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked()));
 
+    connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
     connect(ui.pageDataDownload->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
 
     connect(ui.pageEditTeam->BtnTeamSave, SIGNAL(clicked()), this, SLOT(TeamSave()));
@@ -223,6 +230,7 @@
     connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
 
     connect(ui.pageGameStats->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
+    connect(ui.pageGameStats, SIGNAL(saveDemoRequested()), this, SLOT(saveDemoWithCustomName()));
 
     connect(ui.pageSinglePlayer->BtnSimpleGamePage, SIGNAL(clicked()), this, SLOT(SimpleGame()));
     connect(ui.pageSinglePlayer->BtnTrainPage, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
@@ -619,8 +627,9 @@
     }
 
     QStringList tmnames;
-    QListIterator<HWTeam> it(curTeamSelWidget->getDontPlayingTeams());
-    while(it.hasNext()) tmnames += it.next().TeamName;
+
+    foreach(HWTeam team, curTeamSelWidget->getNotPlayingTeams())
+        tmnames += team.TeamName;
 
     //UpdateTeamsLists(&tmnames); // FIXME: still need more work if teamname is updated while configuring
     UpdateTeamsLists();
@@ -722,7 +731,7 @@
         return;
     }
     CreateGame(0, 0, 0);
-    game->PlayDemo(curritem->data(Qt::UserRole).toString());
+    game->PlayDemo(curritem->data(Qt::UserRole).toString(), ui.pagePlayDemo->isSave());
 }
 
 void HWForm::PlayDemoQuick(const QString & demofilename)
@@ -731,7 +740,7 @@
     GoBack(); //needed to cleanly disconnect from netgame
     GoToPage(ID_PAGE_MAIN);
     CreateGame(0, 0, 0);
-    game->PlayDemo(demofilename);
+    game->PlayDemo(demofilename, false);
 }
 
 void HWForm::NetConnectServer(const QString & host, quint16 port)
@@ -1033,6 +1042,7 @@
     connect(game, SIGNAL(GameStats(char, const QString &)), ui.pageGameStats, SLOT(GameStats(char, const QString &)));
     connect(game, SIGNAL(ErrorMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection);
     connect(game, SIGNAL(HaveRecord(bool, const QByteArray &)), this, SLOT(GetRecord(bool, const QByteArray &)));
+    m_lastDemo = QByteArray();
 }
 
 void HWForm::ShowErrorMessage(const QString & msg)
@@ -1061,6 +1071,7 @@
         demo.replace(QByteArray("\x02TN"), QByteArray("\x02TD"));
         demo.replace(QByteArray("\x02TS"), QByteArray("\x02TD"));
         filename = cfgdir->absolutePath() + "/Demos/" + recordFileName + "." + *cProtoVer + ".hwd";
+        m_lastDemo = demo;
     } else
     {
         demo.replace(QByteArray("\x02TL"), QByteArray("\x02TS"));
@@ -1075,7 +1086,7 @@
         ShowErrorMessage(tr("Cannot save record to file %1").arg(filename));
         return ;
     }
-    demofile.write(demo.constData(), demo.size());
+    demofile.write(demo);
     demofile.close();
 }
 
@@ -1293,3 +1304,30 @@
     else QMessageBox::information(0, "", QMessageBox::tr("File association failed."));
 }
 
+void HWForm::saveDemoWithCustomName()
+{
+    if(!m_lastDemo.isEmpty())
+    {
+        QString fileName;
+        bool ok = false;
+        do
+        {
+            fileName = QInputDialog::getText(this, tr("Demo name"), tr("Demo name:"));
+            
+            if(!fileName.isEmpty())
+            {
+                QString filePath = cfgdir->absolutePath() + "/Demos/" + fileName + "." + *cProtoVer + ".hwd";
+                QFile demofile(filePath);
+                ok = demofile.open(QIODevice::WriteOnly);
+                if (!ok)
+                    ShowErrorMessage(tr("Cannot save record to file %1").arg(filePath));
+                else
+                {
+                    ok = -1 != demofile.write(m_lastDemo);
+                    demofile.close();
+                }
+            }
+        } while(!fileName.isEmpty() && !ok);
+    }
+}
+