Button for renaming demo and save files
authorunc0rr
Sun, 02 Dec 2007 18:53:04 +0000
changeset 627 92e136c3eb46
parent 626 a30171dbcd19
child 628 1d592e3ae7ae
Button for renaming demo and save files
QTfrontend/playrecordpage.cpp
QTfrontend/playrecordpage.h
--- a/QTfrontend/playrecordpage.cpp	Sun Dec 02 17:29:20 2007 +0000
+++ b/QTfrontend/playrecordpage.cpp	Sun Dec 02 18:53:04 2007 +0000
@@ -20,6 +20,10 @@
 #include <QGridLayout>
 #include <QPushButton>
 #include <QListWidget>
+#include <QListWidgetItem>
+#include <QFileInfo>
+#include <QMessageBox>
+#include <QInputDialog>
 
 #include "hwconsts.h"
 #include "playrecordpage.h"
@@ -35,17 +39,23 @@
 	BtnBack = new QPushButton(this);
 	BtnBack->setFont(*font14);
 	BtnBack->setText(QPushButton::tr("Back"));
-	pageLayout->addWidget(BtnBack, 1, 0);
+	pageLayout->addWidget(BtnBack, 2, 0);
 
-	BtnPlayDemo	= new QPushButton(this);
-	BtnPlayDemo->setGeometry(QRect(240,	330, 161, 41));
+	BtnPlayDemo = new QPushButton(this);
 	BtnPlayDemo->setFont(*font14);
 	BtnPlayDemo->setText(QPushButton::tr("Play demo"));
-	pageLayout->addWidget(BtnPlayDemo, 1, 2);
+	pageLayout->addWidget(BtnPlayDemo, 2, 2);
 
-	DemosList =	new QListWidget(this);
+	BtnRenameRecord = new QPushButton(this);
+//	BtnRenameRecord->setFont(*font14);
+	BtnRenameRecord->setText(QPushButton::tr("Rename"));
+	pageLayout->addWidget(BtnRenameRecord, 0, 2);
+
+	DemosList = new QListWidget(this);
 	DemosList->setGeometry(QRect(170, 10, 311, 311));
-	pageLayout->addWidget(DemosList, 0, 1);
+	pageLayout->addWidget(DemosList, 0, 1, 2, 1);
+
+	connect(BtnRenameRecord, SIGNAL(clicked()), this, SLOT(renameRecord()));
 }
 
 void PagePlayDemo::FillFromDir(RecordType rectype)
@@ -53,6 +63,8 @@
 	QDir dir;
 	QString extension;
 
+	recType = rectype;
+
 	dir.cd(cfgdir->absolutePath());
 	if (rectype == RT_Demo)
 	{
@@ -79,3 +91,36 @@
 	}
 }
 
+void PagePlayDemo::renameRecord()
+{
+	QListWidgetItem * curritem = DemosList->currentItem();
+	if (!curritem)
+	{
+		QMessageBox::critical(this,
+				tr("Error"),
+				tr("Please, select record from the list"),
+				tr("OK"));
+		return ;
+	}
+	QFile rfile(curritem->data(Qt::UserRole).toString());
+
+	QFileInfo finfo(rfile);
+
+	bool ok;
+
+	QString newname = QInputDialog::getText(this, tr("Rename dialog"), tr("Enter new file name:"), QLineEdit::Normal, finfo.completeBaseName(), &ok);
+
+	if(ok && newname.size())
+	{
+		QString newfullname = QString("%1/%2.%3")
+		                              .arg(finfo.absolutePath())
+		                              .arg(newname)
+		                              .arg(finfo.suffix());
+
+		ok = rfile.rename(newfullname);
+		if(!ok)
+			QMessageBox::critical(this, tr("Error"), /*tr("Cannot rename to") +*/ newname);
+		else
+			FillFromDir(recType);
+	}
+}
--- a/QTfrontend/playrecordpage.h	Sun Dec 02 17:29:20 2007 +0000
+++ b/QTfrontend/playrecordpage.h	Sun Dec 02 18:53:04 2007 +0000
@@ -41,7 +41,14 @@
 
 	QPushButton *BtnBack;
 	QPushButton *BtnPlayDemo;
+	QPushButton *BtnRenameRecord;
 	QListWidget *DemosList;
+
+private:
+	RecordType recType;
+
+private slots:
+	void renameRecord();
 };