forked from Januarylovelulu/Popkart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownload.cpp
133 lines (120 loc) · 4.23 KB
/
download.cpp
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
#include "download.h"
#include "ui_download.h"
Download::Download(QString fileName, QString path, QString url, QWidget *parent) :
QDialog(parent),
ui(new Ui::Download)
{
ui->setupUi(this);
settings = new QSettings(QSettings::NativeFormat, QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());
QString pathPic=settings->value("picPath").toString();
QImage imgBackgroud(pathPic);
QPalette palette;
palette.setBrush(this->backgroundRole(),
QBrush(imgBackgroud.scaled(this->width(),this->height())));
this->setPalette(palette);
this->setStyleSheet("font-family:\"楷体\";"
"font-size:17px;"
"font-weight:100;");
QString str = settings->value("settings").toString();
if(!str.isEmpty())
{
QStringList strList=str.split(";");
ui->lineEdit->setStyleSheet(QString("background:rgb(255,255,255,%1);").arg(strList.at(4)));
ui->pushButton_1->setStyleSheet(QString("background:rgb(25,255,255,%1);").arg(strList.at(5)));
ui->pushButton_2->setStyleSheet(QString("background:rgb(25,255,255,%1);").arg(strList.at(5)));
ui->pushButton_3->setStyleSheet(QString("background:rgb(25,255,255,%1);").arg(strList.at(5)));
this->setWindowOpacity(QString(strList.at(6)).toDouble()/100.0);
ui->progressBar->setStyleSheet("border:2px solid grey;border-radius:5px;text-align:center;");
}
if(path.isEmpty())
{
ui->lineEdit->setText(MyFile::pathDesktop());
this->path=MyFile::pathDesktop();
}
else
{
ui->lineEdit->setText(path);
this->path=path;
}
this->url=url;
this->fileName=fileName;
setWindowTitle("下载文件: "+fileName);
}
Download::~Download()
{
delete ui;
delete settings;
}
void Download::closeEvent(QCloseEvent *event)
{
if(isDownloading==true)
{
QMessageBox box(this);
box.addButton("确定",QMessageBox::YesRole);
box.addButton("取消",QMessageBox::NoRole);
box.setWindowTitle("确定退出?");
box.setText("一旦退出,下载立即取消\n"
"退出后,下载数据会保留\n"
"下次下载时,会接着下载");
int res=box.exec();
if(res==0)
{
event->accept();
myNetwork.stopDownload();
return;
}
else
{
event->ignore();
return;
}
}
myNetwork.stopDownload();
event->accept();
}
void Download::on_pushButton_1_clicked()
{
QStringList path=myFile.selectDirectory();
if(!path.isEmpty())
{
ui->lineEdit->setText(path.at(0));
this->path=path.at(0);
}
}
void Download::on_pushButton_2_clicked()
{
if(ui->pushButton_2->text()=="下载")
{
connect(&myNetwork,&MyNetwork::returnDownloadProgressBarValue,ui->progressBar,&QProgressBar::setValue);
connect(&myNetwork,&MyNetwork::returnDownloadStatute,ui->label_1,&QLabel::setText);
connect(&myNetwork,&MyNetwork::returnDownloadSpeedAndTime,ui->label_2,&QLabel::setText);
connect(&myNetwork,&MyNetwork::returnDownloadFinish,this,&Download::on_DownloadFinish);
myNetwork.download(fileName,path,url);
ui->lineEdit->setEnabled(false);
ui->pushButton_1->setEnabled(false);
ui->pushButton_2->setText("暂停");
isDownloading=true;
}
else
{
ui->pushButton_2->setText("下载");
myNetwork.stopDownload();
disconnect(&myNetwork,&MyNetwork::returnDownloadProgressBarValue,ui->progressBar,&QProgressBar::setValue);
disconnect(&myNetwork,&MyNetwork::returnDownloadStatute,ui->label_1,&QLabel::setText);
disconnect(&myNetwork,&MyNetwork::returnDownloadSpeedAndTime,ui->label_2,&QLabel::setText);
disconnect(&myNetwork,&MyNetwork::returnDownloadFinish,this,&Download::on_DownloadFinish);
isDownloading=false;
}
}
void Download::on_pushButton_3_clicked()
{
this->close();
}
void Download::on_DownloadFinish()
{
ui->lineEdit->setEnabled(true);
ui->pushButton_1->setEnabled(true);
ui->pushButton_2->setEnabled(true);
isDownloading=false;
emit returnDownloadFinish();
}