# HG changeset patch # User unc0rr # Date 1314950784 -14400 # Node ID d710db47a1efa859b05985fcce1ee3af1b2edeb4 # Parent f3f381011728abebd850cc4547bb2272eea3b26e Implement save button on game statistics page. I'm surprised I did it. Closes issue #264 diff -r f3f381011728 -r d710db47a1ef QTfrontend/hwform.cpp --- 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 #include #include +#include #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 diff -r f3f381011728 -r d710db47a1ef QTfrontend/hwform.h --- a/QTfrontend/hwform.h Fri Sep 02 01:19:37 2011 -0400 +++ b/QTfrontend/hwform.h Fri Sep 02 12:06:24 2011 +0400 @@ -117,6 +117,8 @@ void AsyncNetServerStart(); void NetLeftRoom(); void selectFirstNetScheme(); + + void saveDemoWithCustomName(); private: void _NetConnect(const QString & hostName, quint16 port, const QString & nick); @@ -162,6 +164,7 @@ QTime eggTimer; BGWidget * wBackground; QSignalMapper * pageSwitchMapper; + QByteArray m_lastDemo; #ifdef __APPLE__ InstallController * panel; diff -r f3f381011728 -r d710db47a1ef QTfrontend/pagegamestats.cpp --- a/QTfrontend/pagegamestats.cpp Fri Sep 02 01:19:37 2011 -0400 +++ b/QTfrontend/pagegamestats.cpp Fri Sep 02 12:06:24 2011 +0400 @@ -47,6 +47,11 @@ BtnBack = addButton(":/res/Exit.png", pageLayout, 3, 0, true); BtnBack->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + BtnSave = addButton(":/res/Save.png", pageLayout, 3, 2, true); + BtnSave->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + BtnSave->setStyleSheet("QPushButton{margin: 12px 0px 12px 0px;}"); + connect(BtnSave, SIGNAL(clicked()), this, SIGNAL(saveDemoRequested())); + QGroupBox * gb = new QGroupBox(this); QVBoxLayout * gbl = new QVBoxLayout; @@ -62,7 +67,7 @@ gbl->addWidget(l); gbl->addWidget(labelGameStats); gb->setLayout(gbl); - pageLayout->addWidget(gb, 1, 1); + pageLayout->addWidget(gb, 1, 1, 1, 2); // graph graphic = new FitGraphicsView(gb); diff -r f3f381011728 -r d710db47a1ef QTfrontend/pagegamestats.h --- a/QTfrontend/pagegamestats.h Fri Sep 02 01:19:37 2011 -0400 +++ b/QTfrontend/pagegamestats.h Fri Sep 02 12:06:24 2011 +0400 @@ -44,6 +44,7 @@ PageGameStats(QWidget* parent = 0); QPushButton *BtnBack; + QPushButton *BtnSave; QLabel *labelGameStats; QLabel *labelGameWin; QLabel *labelGameRank; @@ -53,6 +54,9 @@ void GameStats(char type, const QString & info); void clear(); void renderStats(); + +signals: + void saveDemoRequested(); private: void AddStatText(const QString & msg);