21 #include "ui_filetransferwidget.h"
29 #include "util/display.h"
33 #include <QDesktopServices>
34 #include <QDesktopWidget>
36 #include <QFileDialog>
37 #include <QMessageBox>
38 #include <QMouseEvent>
40 #include <QVariantAnimation>
54 , ui(
new Ui::FileTransferWidget)
64 setAttribute(Qt::WA_TranslucentBackground,
true);
66 ui->previewButton->hide();
67 ui->filenameLabel->setText(
file.fileName);
68 ui->progressBar->setValue(0);
69 ui->fileSizeLabel->setText(getHumanReadableSize(
file.progress.getFileSize()));
70 ui->etaLabel->setText(
"");
72 backgroundColorAnimation =
new QVariantAnimation(
this);
73 backgroundColorAnimation->setDuration(500);
74 backgroundColorAnimation->setEasingCurve(QEasingCurve::OutCubic);
75 connect(backgroundColorAnimation, &QVariantAnimation::valueChanged,
this,
76 [
this](
const QVariant& val) {
77 backgroundColor = val.value<QColor>();
81 buttonColorAnimation =
new QVariantAnimation(
this);
82 buttonColorAnimation->setDuration(500);
83 buttonColorAnimation->setEasingCurve(QEasingCurve::OutCubic);
84 connect(buttonColorAnimation, &QVariantAnimation::valueChanged,
this, [
this](
const QVariant& val) {
85 buttonColor = val.value<QColor>();
91 connect(ui->previewButton, &QPushButton::clicked,
this,
117 bool writable = tmp.open(QIODevice::WriteOnly);
134 if (filepath.isEmpty()) {
141 tr(
"You do not have permission to write that location. Choose another, or "
142 "cancel the save dialog.",
143 "text of permissions popup"));
159 setProperty(
"fontColor", whiteFont ?
"white" :
"black");
178 return (
ui->rightButton->isVisible() ||
ui->leftButton->isVisible())
179 && !(
ui->leftButton->isVisible() &&
ui->leftButton->objectName() ==
"ok");
185 QPainter painter(
this);
186 painter.setRenderHint(QPainter::Antialiasing);
187 painter.setPen(Qt::NoPen);
189 qreal ratio =
static_cast<qreal
>(geometry().height()) /
static_cast<qreal
>(geometry().width());
191 const int buttonFieldWidth = 32;
192 const int lineWidth = 1;
195 painter.setClipRect(QRect(0, 0, width(), height()));
197 painter.drawRoundedRect(geometry(), r * ratio, r, Qt::RelativeSize);
201 QPainterPath buttonBackground;
202 buttonBackground.addRoundedRect(width() - 2 * buttonFieldWidth - lineWidth * 2, 0,
203 buttonFieldWidth, buttonFieldWidth + lineWidth, 50, 50,
205 buttonBackground.addRect(width() - 2 * buttonFieldWidth - lineWidth * 2, 0,
206 buttonFieldWidth * 2, buttonFieldWidth / 2);
207 buttonBackground.addRect(width() - 1.5 * buttonFieldWidth - lineWidth * 2, 0,
208 buttonFieldWidth * 2, buttonFieldWidth + 1);
209 buttonBackground.setFillRule(Qt::WindingFill);
211 painter.drawPath(buttonBackground);
214 QPainterPath leftButton;
215 leftButton.addRoundedRect(QRect(width() - 2 * buttonFieldWidth - lineWidth, 0,
216 buttonFieldWidth, buttonFieldWidth),
217 50, 50, Qt::RelativeSize);
218 leftButton.addRect(QRect(width() - 2 * buttonFieldWidth - lineWidth, 0,
219 buttonFieldWidth / 2, buttonFieldWidth / 2));
220 leftButton.addRect(QRect(width() - 1.5 * buttonFieldWidth - lineWidth, 0,
221 buttonFieldWidth / 2, buttonFieldWidth));
222 leftButton.setFillRule(Qt::WindingFill);
224 painter.drawPath(leftButton);
228 painter.setClipRect(QRect(width() - buttonFieldWidth, 0, buttonFieldWidth, buttonFieldWidth));
229 painter.drawRoundedRect(geometry(), r * ratio, r, Qt::RelativeSize);
253 switch (
file.status) {
256 ui->progressLabel->setText(tr(
"Waiting to send...",
"file transfer widget"));
258 ui->progressLabel->setText(tr(
"Accept to receive this file",
"file transfer widget"));
262 ui->etaLabel->setText(
"");
263 if (
file.pauseStatus.localPaused()) {
264 ui->progressLabel->setText(tr(
"Paused",
"file transfer widget"));
266 ui->progressLabel->setText(tr(
"Remote paused",
"file transfer widget"));
270 ui->etaLabel->setText(
"");
271 ui->progressLabel->setText(tr(
"Resuming...",
"file transfer widget"));
279 qCritical() <<
"Invalid file status";
290 switch (
file.status) {
304 qCritical() <<
"Invalid file status";
311 switch (
file.status) {
316 auto speed =
file.progress.getSpeed();
317 auto progress =
file.progress.getProgress();
318 auto remainingTime =
file.progress.getTimeLeftSeconds();
320 ui->progressBar->setValue(
static_cast<int>(progress * 100.0));
325 QTime toGo = QTime(0, 0).addSecs(remainingTime);
326 QString format = toGo.hour() > 0 ?
"hh:mm:ss" :
"mm:ss";
327 ui->etaLabel->setText(toGo.toString(format));
329 ui->etaLabel->setText(
"");
332 ui->progressLabel->setText(getHumanReadableSize(speed) +
"/s");
338 ui->progressBar->hide();
339 ui->progressLabel->hide();
340 ui->etaLabel->hide();
344 qCritical() <<
"Invalid file status";
355 switch (
file.status) {
360 disconnect(&
coreFile,
nullptr,
this,
nullptr);
367 qCritical() <<
"Invalid file status";
378 switch (
file.status) {
381 ui->leftButton->setObjectName(
"pause");
382 ui->leftButton->setToolTip(tr(
"Pause transfer"));
385 ui->rightButton->setObjectName(
"cancel");
386 ui->rightButton->setToolTip(tr(
"Cancel transfer"));
392 if (
file.pauseStatus.localPaused()) {
394 ui->leftButton->setObjectName(
"resume");
395 ui->leftButton->setToolTip(tr(
"Resume transfer"));
398 ui->leftButton->setObjectName(
"pause");
399 ui->leftButton->setToolTip(tr(
"Pause transfer"));
403 ui->rightButton->setObjectName(
"cancel");
404 ui->rightButton->setToolTip(tr(
"Cancel transfer"));
411 ui->rightButton->setObjectName(
"cancel");
412 ui->rightButton->setToolTip(tr(
"Cancel transfer"));
416 ui->leftButton->setObjectName(
"pause");
417 ui->leftButton->setToolTip(tr(
"Pause transfer"));
420 ui->leftButton->setObjectName(
"accept");
421 ui->leftButton->setToolTip(tr(
"Accept transfer"));
426 ui->leftButton->hide();
427 ui->rightButton->hide();
431 ui->leftButton->setObjectName(
"ok");
432 ui->leftButton->setToolTip(tr(
"Open file"));
433 ui->leftButton->show();
436 ui->rightButton->setObjectName(
"dir");
437 ui->rightButton->setToolTip(tr(
"Open file directory"));
438 ui->rightButton->show();
442 qCritical() <<
"Invalid file status";
450 if (btn->objectName() ==
"cancel") {
452 }
else if (btn->objectName() ==
"pause") {
454 }
else if (btn->objectName() ==
"resume") {
459 if (btn->objectName() ==
"cancel") {
461 }
else if (btn->objectName() ==
"pause") {
463 }
else if (btn->objectName() ==
"resume") {
465 }
else if (btn->objectName() ==
"accept") {
467 QFileDialog::getSaveFileName(Q_NULLPTR,
468 tr(
"Save a file",
"Title of the file saving dialog"),
475 if (btn->objectName() ==
"ok" || btn->objectName() ==
"previewButton") {
477 }
else if (btn->objectName() ==
"dir") {
479 QDesktopServices::openUrl(QUrl::fromLocalFile(dirPath));
485 ui->previewButton->setIconFromFile(filename);
486 ui->previewButton->show();
514 if (shouldUpdateFileProgress)
523 if (shouldUpdateFileProgress) {
545 qCritical() <<
"Invalid file status";