whyclwt
2022-05-18 ab72c6e114d7c4e83564194367ba623ca23bf09d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//----------------------------------------------------------------------------------------------
#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();
}
//----------------------------------------------------------------------------------------------