swift
downloaddialog.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #include "downloaddialog.h"
5 
6 #include <QTimer>
7 
8 #include "ui_downloaddialog.h"
9 
10 using namespace swift::misc::network;
11 
12 namespace swift::gui::components
13 {
14  CDownloadDialog::CDownloadDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CDownloadDialog)
15  {
16  ui->setupUi(this);
17  this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
18  }
19 
21 
23  {
24  setWindowTitle("Downloading " + remoteFile.getName());
25  ui->comp_Download->setDownloadFile(remoteFile);
26  }
27 
29  {
30  ui->comp_Download->setDownloadFiles(remoteFiles);
31  }
32 
34  {
35  ui->comp_Download->triggerDownloadingOfFiles(delayMs);
36  }
37 
38  void CDownloadDialog::setMode(CDownloadComponent::Mode mode) { ui->comp_Download->setMode(mode); }
39 
41  {
42  const QPointer<CDownloadDialog> guard(this);
43  QTimer::singleShot(0, this, [=] {
44  if (guard.isNull()) { return; }
45  ui->comp_Download->triggerDownloadingOfFiles(2500);
46  });
47  this->show();
48  }
49 
51  {
52  if (!ui->comp_Download->haveAllDownloadsCompleted())
53  {
54  const QString msg = QStringLiteral("Download ongoing. Do you want to abort it?");
55  QMessageBox::StandardButton reply =
56  QMessageBox::question(this, "Abort?", msg, QMessageBox::Yes | QMessageBox::No);
57  if (reply == QMessageBox::Yes)
58  {
59  ui->comp_Download->cancelOngoingDownloads();
60  this->done(CDownloadDialog::Rejected);
61  }
62  }
63  else { this->done(CDownloadDialog::Accepted); }
64  }
65 
66 } // namespace swift::gui::components
CDownloadComponent as dialog.
void setDownloadFile(const swift::misc::network::CRemoteFile &remoteFile)
Set file to be downloaded.
void showAndStartDownloading()
Show and start the downloading.
void setMode(CDownloadComponent::Mode mode)
Set the mode.
void triggerDownloadingOfFiles(int delayMs)
Trigger downloading of the file.
void setDownloadFiles(const swift::misc::network::CRemoteFileList &remoteFiles)
Set files to be downloaded.
const QString & getName() const
Name.
Definition: remotefile.h:52
Value object encapsulating a list of remote files.
High level reusable GUI components.
Definition: aboutdialog.cpp:13
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...
Definition: threadutils.h:30