//----------------------------------------------------------------------------------------------
|
#include "filecopydialog.h"
|
#include "ui_filecopydialog.h"
|
#include <QTimer>
|
#include <QTextCodec>
|
#include <QDebug>
|
//----------------------------------------------------------------------------------------------
|
|
FileCopyDialog::FileCopyDialog(QWidget *parent) :
|
QDialog(parent),
|
ui(new Ui::FileCopyDialog)
|
{
|
value = 0;
|
timer = new QTimer(this);
|
ui->setupUi(this);
|
}
|
//----------------------------------------------------------------------------------------------
|
|
FileCopyDialog::~FileCopyDialog()
|
{
|
delete timer;
|
delete ui;
|
}
|
//----------------------------------------------------------------------------------------------
|
void FileCopyDialog::valueAdd()
|
{
|
if(value < max_value*6)
|
{
|
value++;
|
ui->progressBar->setValue(value);
|
}
|
}
|
|
void FileCopyDialog::updateProgress(int val)
|
{
|
if(val == 65535)
|
{
|
save_ok = false;
|
value = max_value*10;
|
}
|
else
|
{
|
if(val*10 > value)
|
value = val*10;
|
}
|
|
ui->progressBar->setValue(value);
|
|
if(value >= ui->progressBar->maximum())
|
{
|
if(is_delete)
|
ui->label->setText(tr("等待数据删除完成..."));
|
else
|
ui->label->setText(tr("等待U盘转存完成..."));
|
ui->pushButton->setEnabled(false);
|
|
QTimer::singleShot(1000, this, SLOT(accept()));
|
}
|
}
|
//----------------------------------------------------------------------------------------------
|
|
bool FileCopyDialog::CopyFiles(const QStringList &fromDir, const QString &toDir,
|
bool coverFileIfExist)
|
{
|
save_ok = true;
|
|
max_value = fromDir.count();
|
|
ui->progressBar->setMinimum(0);
|
ui->progressBar->setMaximum(max_value*10);//100);
|
ui->progressBar->setValue(0);
|
|
connect(timer,SIGNAL(timeout()),this, SLOT(valueAdd()));
|
//connect(timer,SIGNAL(timeout()),this, SLOT(updateProgress()));
|
timer->start(500);
|
|
FileManage FM;
|
connect(&FM, SIGNAL(progressValue(int)), this, SLOT(updateProgress(int)));
|
|
// qDebug()<<toDir;
|
// for(int n=0;n<fromDir.count();n++){
|
// qDebug()<<fromDir.at(n);
|
// }
|
|
FM.copyDirectoryFiles(fromDir, toDir, coverFileIfExist);
|
|
is_delete = false;
|
|
this->exec();
|
|
return save_ok;
|
}
|
|
bool FileCopyDialog::DeleteFiles(const QStringList &fromDir)
|
{
|
save_ok = true;
|
|
max_value = fromDir.count();
|
|
ui->progressBar->setMinimum(0);
|
ui->progressBar->setMaximum(max_value*10);//100);
|
ui->progressBar->setValue(0);
|
|
connect(timer,SIGNAL(timeout()),this, SLOT(valueAdd()));
|
//connect(timer,SIGNAL(timeout()),this, SLOT(updateProgress()));
|
timer->start(500);
|
|
FileManage FM;
|
connect(&FM, SIGNAL(progressValue(int)), this, SLOT(updateProgress(int)));
|
FM.deleteDirectoryFiles(fromDir);
|
|
is_delete = true;
|
|
ui->label->setText(tr("正在删除数据..."));
|
|
this->exec();
|
|
return save_ok;
|
}
|
|
void FileCopyDialog::updateTimeSetProgress()
|
{
|
ui->progressBar->setValue(value);
|
if(value >= ui->progressBar->maximum())
|
{
|
QTimer::singleShot(1000, this, SLOT(accept()));
|
}
|
}
|
//----------------------------------------------------------------------------------------------
|
|
void FileCopyDialog::on_pushButton_released()
|
{
|
this->reject();
|
}
|
//----------------------------------------------------------------------------------------------
|