forked from KikoPlayProject/KikoPlay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselecttorrentfile.cpp
More file actions
81 lines (74 loc) · 3.21 KB
/
selecttorrentfile.cpp
File metadata and controls
81 lines (74 loc) · 3.21 KB
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
#include "selecttorrentfile.h"
#include <QTreeView>
#include <QPushButton>
#include <QLabel>
#include <QCheckBox>
#include <QHBoxLayout>
#include <QHeaderView>
#include "Common/notifier.h"
#include "widgets/dirselectwidget.h"
#include "Download/torrent.h"
SelectTorrentFile::SelectTorrentFile(TorrentFile *torrentFileTree, QWidget *parent, const QString &path) : CFramelessDialog(tr("Add Torrent"),parent,true),model(nullptr)
{
model=new TorrentFileModel(torrentFileTree,this);
TorrentTreeView *torrentFileView=new TorrentTreeView(this);
torrentFileView->setObjectName(QStringLiteral("TaskFileInfoView"));
torrentFileView->setAlternatingRowColors(true);
torrentFileView->setModel(model);
torrentFileView->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding);
torrentFileView->header()->resizeSection(0,240*logicalDpiX()/96);
torrentFileView->header()->resizeSection(1,50*logicalDpiX()/96);
torrentFileView->header()->resizeSection(2,50*logicalDpiX()/96);
QObject::connect(torrentFileView, &TorrentTreeView::ignoreColorChanged, model, &TorrentFileModel::setIgnoreColor);
QObject::connect(torrentFileView, &TorrentTreeView::normColorChanged, model, &TorrentFileModel::setNormColor);
QCheckBox *selectAll=new QCheckBox(tr("Select All"),this);
selectAll->setChecked(true);
QObject::connect(selectAll,&QCheckBox::stateChanged,[this](int state){
model->checkAll(state==Qt::Checked);
});
QCheckBox *selectVideo=new QCheckBox(tr("Select Video"),this);
QObject::connect(selectVideo,&QCheckBox::stateChanged,[this](int state){
model->checkVideoFiles(state==Qt::Checked);
});
QLabel *checkedFileSizeLabel=new QLabel(this);
QObject::connect(model,&TorrentFileModel::checkedIndexChanged,[this,checkedFileSizeLabel](){
checkedFileSize=model->getCheckedFileSize();
checkedFileSizeLabel->setText(tr("Select: %1").arg(formatSize(false,checkedFileSize)));
});
checkedFileSize = model->getCheckedFileSize();
checkedFileSizeLabel->setText(tr("Select: %1").arg(formatSize(false,checkedFileSize)));
dirSelect = new DirSelectWidget(this);
if (!path.isEmpty()) dirSelect->setDir(path);
QVBoxLayout *dialogVLayout=new QVBoxLayout(this);
QHBoxLayout *checkHLayout=new QHBoxLayout();
checkHLayout->addWidget(selectAll);
checkHLayout->addWidget(selectVideo);
checkHLayout->addStretch(1);
checkHLayout->addWidget(checkedFileSizeLabel);
dialogVLayout->addLayout(checkHLayout);
dialogVLayout->addWidget(torrentFileView);
dialogVLayout->addWidget(dirSelect);
resize(400*logicalDpiX()/96,420*logicalDpiY()/96);
}
void SelectTorrentFile::onAccept()
{
QString selectIndexes=model->getCheckedIndex();
if(selectIndexes.isEmpty())
{
showMessage(tr("No File is Selected"), NM_ERROR | NM_HIDE);
return;
}
this->selectIndexes=selectIndexes;
if(!dirSelect->isValid())
{
showMessage(tr("Dir is invaild"), NM_ERROR | NM_HIDE);
return;
}
if(checkedFileSize>dirSelect->getFreeSpace())
{
showMessage(tr("Insufficient Disk Space"), NM_ERROR | NM_HIDE);
return;
}
this->dir=dirSelect->getDir();
CFramelessDialog::onAccept();
}