QTfrontend/playrecordpage.cpp
changeset 627 92e136c3eb46
parent 603 d7877468653b
child 628 1d592e3ae7ae
equal deleted inserted replaced
626:a30171dbcd19 627:92e136c3eb46
    18 
    18 
    19 #include <QFont>
    19 #include <QFont>
    20 #include <QGridLayout>
    20 #include <QGridLayout>
    21 #include <QPushButton>
    21 #include <QPushButton>
    22 #include <QListWidget>
    22 #include <QListWidget>
       
    23 #include <QListWidgetItem>
       
    24 #include <QFileInfo>
       
    25 #include <QMessageBox>
       
    26 #include <QInputDialog>
    23 
    27 
    24 #include "hwconsts.h"
    28 #include "hwconsts.h"
    25 #include "playrecordpage.h"
    29 #include "playrecordpage.h"
    26 
    30 
    27 PagePlayDemo::PagePlayDemo(QWidget* parent) : QWidget(parent)
    31 PagePlayDemo::PagePlayDemo(QWidget* parent) : QWidget(parent)
    33 	pageLayout->setColumnStretch(2, 1);
    37 	pageLayout->setColumnStretch(2, 1);
    34 
    38 
    35 	BtnBack = new QPushButton(this);
    39 	BtnBack = new QPushButton(this);
    36 	BtnBack->setFont(*font14);
    40 	BtnBack->setFont(*font14);
    37 	BtnBack->setText(QPushButton::tr("Back"));
    41 	BtnBack->setText(QPushButton::tr("Back"));
    38 	pageLayout->addWidget(BtnBack, 1, 0);
    42 	pageLayout->addWidget(BtnBack, 2, 0);
    39 
    43 
    40 	BtnPlayDemo	= new QPushButton(this);
    44 	BtnPlayDemo = new QPushButton(this);
    41 	BtnPlayDemo->setGeometry(QRect(240,	330, 161, 41));
       
    42 	BtnPlayDemo->setFont(*font14);
    45 	BtnPlayDemo->setFont(*font14);
    43 	BtnPlayDemo->setText(QPushButton::tr("Play demo"));
    46 	BtnPlayDemo->setText(QPushButton::tr("Play demo"));
    44 	pageLayout->addWidget(BtnPlayDemo, 1, 2);
    47 	pageLayout->addWidget(BtnPlayDemo, 2, 2);
    45 
    48 
    46 	DemosList =	new QListWidget(this);
    49 	BtnRenameRecord = new QPushButton(this);
       
    50 //	BtnRenameRecord->setFont(*font14);
       
    51 	BtnRenameRecord->setText(QPushButton::tr("Rename"));
       
    52 	pageLayout->addWidget(BtnRenameRecord, 0, 2);
       
    53 
       
    54 	DemosList = new QListWidget(this);
    47 	DemosList->setGeometry(QRect(170, 10, 311, 311));
    55 	DemosList->setGeometry(QRect(170, 10, 311, 311));
    48 	pageLayout->addWidget(DemosList, 0, 1);
    56 	pageLayout->addWidget(DemosList, 0, 1, 2, 1);
       
    57 
       
    58 	connect(BtnRenameRecord, SIGNAL(clicked()), this, SLOT(renameRecord()));
    49 }
    59 }
    50 
    60 
    51 void PagePlayDemo::FillFromDir(RecordType rectype)
    61 void PagePlayDemo::FillFromDir(RecordType rectype)
    52 {
    62 {
    53 	QDir dir;
    63 	QDir dir;
    54 	QString extension;
    64 	QString extension;
       
    65 
       
    66 	recType = rectype;
    55 
    67 
    56 	dir.cd(cfgdir->absolutePath());
    68 	dir.cd(cfgdir->absolutePath());
    57 	if (rectype == RT_Demo)
    69 	if (rectype == RT_Demo)
    58 	{
    70 	{
    59 		dir.cd("Demos");
    71 		dir.cd("Demos");
    77 	{
    89 	{
    78 		DemosList->item(i)->setData(Qt::UserRole, dir.absoluteFilePath(QString("%1.%2").arg(sl[i], extension)));
    90 		DemosList->item(i)->setData(Qt::UserRole, dir.absoluteFilePath(QString("%1.%2").arg(sl[i], extension)));
    79 	}
    91 	}
    80 }
    92 }
    81 
    93 
       
    94 void PagePlayDemo::renameRecord()
       
    95 {
       
    96 	QListWidgetItem * curritem = DemosList->currentItem();
       
    97 	if (!curritem)
       
    98 	{
       
    99 		QMessageBox::critical(this,
       
   100 				tr("Error"),
       
   101 				tr("Please, select record from the list"),
       
   102 				tr("OK"));
       
   103 		return ;
       
   104 	}
       
   105 	QFile rfile(curritem->data(Qt::UserRole).toString());
       
   106 
       
   107 	QFileInfo finfo(rfile);
       
   108 
       
   109 	bool ok;
       
   110 
       
   111 	QString newname = QInputDialog::getText(this, tr("Rename dialog"), tr("Enter new file name:"), QLineEdit::Normal, finfo.completeBaseName(), &ok);
       
   112 
       
   113 	if(ok && newname.size())
       
   114 	{
       
   115 		QString newfullname = QString("%1/%2.%3")
       
   116 		                              .arg(finfo.absolutePath())
       
   117 		                              .arg(newname)
       
   118 		                              .arg(finfo.suffix());
       
   119 
       
   120 		ok = rfile.rename(newfullname);
       
   121 		if(!ok)
       
   122 			QMessageBox::critical(this, tr("Error"), /*tr("Cannot rename to") +*/ newname);
       
   123 		else
       
   124 			FillFromDir(recType);
       
   125 	}
       
   126 }