--- a/QTfrontend/hwform.cpp Fri Sep 02 01:19:37 2011 -0400
+++ b/QTfrontend/hwform.cpp Fri Sep 02 12:06:24 2011 +0400
@@ -38,6 +38,7 @@
#include <QSignalMapper>
#include <QShortcut>
#include <QDesktopServices>
+#include <QInputDialog>
#include "hwform.h"
#include "game.h"
@@ -223,6 +224,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()));
@@ -1033,6 +1035,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 +1064,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 +1079,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 +1297,29 @@
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);
+ }
+}
\ No newline at end of file