-
Notifications
You must be signed in to change notification settings - Fork 57
/
addcloudtask.cpp
226 lines (190 loc) · 6.55 KB
/
addcloudtask.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*
* CloudClient - A Qt cloud client for lixian.vip.xunlei.com
* Copyright (C) 2012 by Aaron Lewis <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "addcloudtask.h"
#include "ui_addcloudtask.h"
#define OFFSET_SUBID 1
#define OFFSET_SIZE 2
#define OFFSET_URL 3
AddCloudTask::AddCloudTask(ThunderCore *tc, QWidget *parent) :
QDialog(parent),
ui(new Ui::AddCloudTask),
tcore (tc),
bt_model(new QStandardItemModel),
batch_model(new QStandardItemModel)
{
ui->setupUi(this);
ui->tabWidget->setCurrentIndex(0);
ui->tableViewBT->setModel(bt_model);
ui->tableViewBatch->setModel(batch_model);
bt_model->setHorizontalHeaderLabels(QStringList()
<< tr("Size")
<< tr("Name"));
batch_model->setHorizontalHeaderLabels(QStringList()
<< tr("Size")
<< tr("Name"));
connect (tcore, SIGNAL(RemoteTaskChanged(ThunderCore::RemoteTaskType)),
SLOT(slotRemoteTaskChanged(ThunderCore::RemoteTaskType)));
}
AddCloudTask::~AddCloudTask()
{
delete ui;
}
void AddCloudTask::showEvent(QShowEvent *e)
{
switch (ui->tabWidget->currentIndex())
{
case 0:
{
QClipboard *clip = QApplication::clipboard();
ui->url->setText(clip->text());
ui->url->setFocus();
}
break;
case 1:
break;
}
QDialog::showEvent(e);
}
void AddCloudTask::slotRemoteTaskChanged(ThunderCore::RemoteTaskType type)
{
switch (type)
{
case ThunderCore::SingleTaskReady:
{
tmp_singleRemoteTask = tcore->getSingleRemoteTask();
tmp_singleRemoteTask.url = ui->url->text();
ui->sizeLabel->setText(tr("File size: %1").arg(tmp_singleRemoteTask.size));
ui->name->setText(tmp_singleRemoteTask.name);
}
break;
case ThunderCore::BitorrentTaskReady:
{
bt_model->setRowCount(0);
const Thunder::BitorrentTask & bttask = tcore->getUploadedBTTasks();
ui->sizeLabelBT->setText(tr("%1 (Total: %2)")
.arg(bttask.ftitle)
.arg(Util::toReadableSize(bttask.btsize)));
foreach (const Thunder::BTSubTask & task, bttask.subtasks)
{
QList<QStandardItem*> items;
items << new QStandardItem (task.format_size)
<< new QStandardItem (task.name);
for (int i = 0; i < items.size(); ++i)
items.at(i)->setTextAlignment(Qt::AlignCenter);
items.first()->setData(task.id, Qt::UserRole + OFFSET_SUBID);
items.first()->setData(task.size, Qt::UserRole + OFFSET_SIZE);
bt_model->appendRow(items);
}
ui->tableViewBT->selectAll();
}
break;
case ThunderCore::BatchTaskReady:
{
batch_model->setRowCount(0);
unsigned long long task_tot_size = 0;
foreach (const Thunder::BatchTask & batch_task, tcore->getUploadedBatchTasks())
{
QList<QStandardItem*> items;
items << new QStandardItem (batch_task.formatsize)
<< new QStandardItem (batch_task.name);
items.first()->setData(batch_task.url, Qt::UserRole + OFFSET_URL);
for (int i = 0; i < items.size(); ++i)
items.at(i)->setTextAlignment(Qt::AlignCenter);
task_tot_size += batch_task.size;
batch_model->appendRow(items);
}
ui->tableViewBatch->selectAll();
ui->sizeLabelBatchJob->setText(tr("Total size of tasks: %1")
.arg(Util::toReadableSize(task_tot_size)));
}
break;
default:
Q_ASSERT(false);
break;
}
}
void AddCloudTask::on_url_textChanged(const QString &arg1)
{
tcore->addCloudTaskPre(arg1);
}
void AddCloudTask::setSingleTaskInfo(Thunder::RemoteTask remote_task)
{
ui->url->setText(remote_task.name);
ui->sizeLabel->setText(tr("Task would consume %1 disk size.").arg(remote_task.size));
}
void AddCloudTask::on_buttonBox_accepted()
{
switch (ui->tabWidget->currentIndex())
{
case 0:
{
tcore->addCloudTaskPost(tmp_singleRemoteTask);
}
break;
case 1:
{
QList<Thunder::BTSubTask> tasks;
foreach (const QModelIndex & index,
ui->tableViewBT->selectionModel()->selectedIndexes())
if (index.column() == 0)
{
Thunder::BTSubTask task;
task.id = QString::number(index.row());
task.size = bt_model->data(index, Qt::UserRole + OFFSET_SIZE).toString();
tasks.append(task);
}
tcore->commitBitorrentTask (tasks);
}
break;
case 2:
{
QStringList urls;
foreach (const QModelIndex & index,
ui->tableViewBatch->selectionModel()->selectedIndexes())
if (index.column() == 0)
{
urls.append(batch_model->data(index,
Qt::UserRole + OFFSET_URL).toString());
}
tcore->addBatchTaskPost(urls);
}
break;
default:
break;
}
}
void AddCloudTask::on_uploadBTFile_clicked()
{
const QString & file = QFileDialog::getOpenFileName(this,
tr("Upload a torrent file"),
QApplication::applicationDirPath(),
tr("BT File (*.torrent);;All Files (*)"));
if (file.isEmpty())
return;
tcore->uploadBitorrent(file);
}
void AddCloudTask::on_openEditorBtn_clicked()
{
SimpleEditor *editor = new SimpleEditor (this);
editor->exec();
tcore->addBatchTaskPre(editor->getText());
}
void AddCloudTask::on_getClipboardBtn_clicked()
{
tcore->addBatchTaskPre(QApplication::clipboard()->text());
}