QTfrontend/playrecordpage.cpp
changeset 2742 21c0d2e69753
parent 2631 163b0128bd21
child 2948 3f21a9dc93d0
equal deleted inserted replaced
2741:7a84ce33f52f 2742:21c0d2e69753
    69 
    69 
    70 	dir.cd(cfgdir->absolutePath());
    70 	dir.cd(cfgdir->absolutePath());
    71 	if (rectype == RT_Demo)
    71 	if (rectype == RT_Demo)
    72 	{
    72 	{
    73 		dir.cd("Demos");
    73 		dir.cd("Demos");
    74 		extension = "hwd_" + *cProtoVer;
    74 		extension = "hwd";
    75 		BtnPlayDemo->setText(QPushButton::tr("Play demo"));
    75 		BtnPlayDemo->setText(QPushButton::tr("Play demo"));
    76 	} else
    76 	} else
    77 	{
    77 	{
    78 		dir.cd("Saves");
    78 		dir.cd("Saves");
    79 		extension = "hws_" + *cProtoVer;
    79 		extension = "hws";
    80 		BtnPlayDemo->setText(QPushButton::tr("Load"));
    80 		BtnPlayDemo->setText(QPushButton::tr("Load"));
    81 	}
    81 	}
    82 	dir.setFilter(QDir::Files);
    82 	dir.setFilter(QDir::Files);
    83 
    83 
    84 	QStringList sl = dir.entryList(QStringList(QString("*.%1").arg(extension)));
    84 	QStringList sl = dir.entryList(QStringList(QString("*.%2.%1").arg(extension, *cProtoVer)));
    85 	sl.replaceInStrings(QRegExp(QString("^(.*)\\.%1$").arg(extension)), "\\1");
    85 	sl.replaceInStrings(QRegExp(QString("^(.*)\\.%2\\.%1$").arg(extension, *cProtoVer)), "\\1");
    86 
    86 
    87 	DemosList->clear();
    87 	DemosList->clear();
    88 	DemosList->addItems(sl);
    88 	DemosList->addItems(sl);
    89 
    89 
    90 	for (int i = 0; i < DemosList->count(); ++i)
    90 	for (int i = 0; i < DemosList->count(); ++i)
    91 	{
    91 	{
    92 		DemosList->item(i)->setData(Qt::UserRole, dir.absoluteFilePath(QString("%1.%2").arg(sl[i], extension)));
    92 		DemosList->item(i)->setData(Qt::UserRole, dir.absoluteFilePath(QString("%1.%3.%2").arg(sl[i], extension, *cProtoVer)));
       
    93 		DemosList->item(i)->setIcon(recType == RT_Demo ? QIcon(":/res/file_demo.png") : QIcon(":/res/file_save.png"));
    93 	}
    94 	}
    94 }
    95 }
    95 
    96 
    96 void PagePlayDemo::renameRecord()
    97 void PagePlayDemo::renameRecord()
    97 {
    98 {
   108 
   109 
   109 	QFileInfo finfo(rfile);
   110 	QFileInfo finfo(rfile);
   110 
   111 
   111 	bool ok;
   112 	bool ok;
   112 
   113 
   113 	QString newname = QInputDialog::getText(this, tr("Rename dialog"), tr("Enter new file name:"), QLineEdit::Normal, finfo.completeBaseName(), &ok);
   114 	QString newname = QInputDialog::getText(this, tr("Rename dialog"), tr("Enter new file name:"), QLineEdit::Normal, finfo.completeBaseName().replace("." + *cProtoVer, ""), &ok);
   114 
   115 
   115 	if(ok && newname.size())
   116 	if(ok && newname.size())
   116 	{
   117 	{
   117 		QString newfullname = QString("%1/%2.%3")
   118 		QString newfullname = QString("%1/%2.%3.%4")
   118 		                              .arg(finfo.absolutePath())
   119 		                              .arg(finfo.absolutePath())
   119 		                              .arg(newname)
   120 		                              .arg(newname)
       
   121 									  .arg(*cProtoVer)
   120 		                              .arg(finfo.suffix());
   122 		                              .arg(finfo.suffix());
   121 
   123 
   122 		ok = rfile.rename(newfullname);
   124 		ok = rfile.rename(newfullname);
   123 		if(!ok)
   125 		if(!ok)
   124 			QMessageBox::critical(this, tr("Error"), tr("Cannot rename to") + newfullname);
   126 			QMessageBox::critical(this, tr("Error"), tr("Cannot rename to") + newfullname);
   138 				tr("OK"));
   140 				tr("OK"));
   139 		return ;
   141 		return ;
   140 	}
   142 	}
   141 	QFile rfile(curritem->data(Qt::UserRole).toString());
   143 	QFile rfile(curritem->data(Qt::UserRole).toString());
   142 
   144 
   143 	QFileInfo finfo(rfile);
       
   144 
       
   145 	bool ok;
   145 	bool ok;
   146 
   146 
   147 	ok = rfile.remove();
   147 	ok = rfile.remove();
   148 	if(!ok)
   148 	if(!ok)
   149 		QMessageBox::critical(this, tr("Error"), tr("Cannot delete file"));
   149 		QMessageBox::critical(this, tr("Error"), tr("Cannot delete file"));