From 9cc38c7f39aa65b059e4d22d98c4c7646321fca9 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 12 Dec 2017 20:40:20 +0100 Subject: [PATCH] Ref T203, download component (generic file download) --- src/blackgui/components/downloadcomponent.cpp | 343 ++++++++++++++++++ src/blackgui/components/downloadcomponent.h | 146 ++++++++ src/blackgui/components/downloadcomponent.ui | 294 +++++++++++++++ src/blackgui/components/downloaddialog.cpp | 68 ++++ src/blackgui/components/downloaddialog.h | 69 ++++ src/blackgui/components/downloaddialog.ui | 100 +++++ .../components/updateinfocomponent.cpp | 26 ++ src/blackgui/components/updateinfocomponent.h | 5 + 8 files changed, 1051 insertions(+) create mode 100644 src/blackgui/components/downloadcomponent.cpp create mode 100644 src/blackgui/components/downloadcomponent.h create mode 100644 src/blackgui/components/downloadcomponent.ui create mode 100644 src/blackgui/components/downloaddialog.cpp create mode 100644 src/blackgui/components/downloaddialog.h create mode 100644 src/blackgui/components/downloaddialog.ui diff --git a/src/blackgui/components/downloadcomponent.cpp b/src/blackgui/components/downloadcomponent.cpp new file mode 100644 index 000000000..f3ec3a4d8 --- /dev/null +++ b/src/blackgui/components/downloadcomponent.cpp @@ -0,0 +1,343 @@ +/* Copyright (C) 2017 + * swift project Community/Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "downloadcomponent.h" +#include "ui_downloadcomponent.h" +#include "blackgui/guiapplication.h" +#include "blackgui/overlaymessagesframe.h" +#include "blackmisc/simulation/xplane/xplaneutil.h" +#include "blackmisc/logmessage.h" +#include "blackmisc/directoryutils.h" +#include "blackmisc/fileutils.h" + +#include +#include +#include +#include +#include +#include + +using namespace BlackMisc; +using namespace BlackMisc::Db; +using namespace BlackMisc::Network; +using namespace BlackMisc::Simulation; + +namespace BlackGui +{ + namespace Components + { + CDownloadComponent::CDownloadComponent(QWidget *parent) : + COverlayMessagesFrame(parent), + CLoadIndicatorEnabled(this), + ui(new Ui::CDownloadComponent) + { + ui->setupUi(this); + this->setOverlaySizeFactors(0.8, 0.9, 2); + this->setForceSmall(true); + + ui->le_DownloadDir->setText(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)); + ui->prb_Current->setMinimum(0); + ui->prb_Current->setMaximum(1); // min/max 0,0 means busy indicator + ui->prb_Current->setValue(0); + ui->prb_Total->setMinimum(0); + ui->prb_Total->setMaximum(1); + ui->prb_Total->setValue(0); + + connect(ui->tb_DialogDownloadDir, &QToolButton::pressed, this, &CDownloadComponent::selectDownloadDirectory); + connect(ui->tb_ResetDownloadDir, &QToolButton::pressed, this, &CDownloadComponent::resetDownloadDir); + connect(ui->tb_CancelDownload, &QToolButton::pressed, this, &CDownloadComponent::cancelOngoingDownloads); + connect(ui->pb_Download, &QPushButton::pressed, [ = ] { this->triggerDownloadingOfFiles(); }); + connect(ui->pb_OpenDownloadDir, &QPushButton::pressed, this, &CDownloadComponent::openDownloadDir); + connect(ui->pb_DoIt, &QPushButton::pressed, this, &CDownloadComponent::startDownloadedExecutable); + } + + CDownloadComponent::~CDownloadComponent() + { } + + bool CDownloadComponent::setDownloadFile(const CRemoteFile &remoteFile) + { + return this->setDownloadFiles(CRemoteFileList(remoteFile)); + } + + bool CDownloadComponent::setDownloadFiles(const CRemoteFileList &remoteFiles) + { + if (!m_waitingForDownload.isEmpty()) { return false; } + m_remoteFiles = remoteFiles; + this->clear(); + return true; + } + + bool CDownloadComponent::setDownloadDirectory(const QString &path) + { + const QDir d(path); + if (!d.exists()) return false; + ui->le_DownloadDir->setText(d.absolutePath()); + return true; + } + + void CDownloadComponent::selectDownloadDirectory() + { + QString downloadDir = ui->le_DownloadDir->text().trimmed(); + downloadDir = QFileDialog::getExistingDirectory(parentWidget(), + tr("Choose your download directory"), downloadDir, m_fileDialogOptions); + + if (downloadDir.isEmpty()) { return; } // canceled + if (!QDir(downloadDir).exists()) + { + const CStatusMessage msg = CStatusMessage(this, CLogCategory::validation()).warning("'%1' is not a valid download directory") << downloadDir; + this->showOverlayMessage(msg, CDownloadComponent::OverlayMsgTimeoutMs); + return; + } + ui->le_DownloadDir->setText(downloadDir); + } + + bool CDownloadComponent::triggerDownloadingOfFiles(int delayMs) + { + if (m_remoteFiles.isEmpty()) { return false; } + if (!m_waitingForDownload.isEmpty()) { return false; } + if (delayMs > 0) + { + QTimer::singleShot(delayMs, this, [ = ] { this->triggerDownloadingOfFiles(); }); + return true; + } + m_waitingForDownload = m_remoteFiles; + this->showFileInfo(); + return this->triggerDownloadingOfNextFile(); + } + + bool CDownloadComponent::isDownloading() const + { + return m_reply || m_fileInProgress.hasName(); + } + + bool CDownloadComponent::haveAllDownloadsCompleted() const + { + if (this->isDownloading()) { return false; } + if (!m_waitingForDownload.isEmpty()) { return false; } + return true; + } + + CDownloadComponent::Mode CDownloadComponent::getMode() const + { + Mode mode = ui->cb_Shutdown->isChecked() ? ShutdownSwift : JustDownload; + if (ui->cb_StartAfterDownload) mode |= StartAfterDownload; + return mode; + } + + void CDownloadComponent::setMode(Mode mode) + { + ui->cb_Shutdown->setChecked(mode.testFlag(ShutdownSwift)); + ui->cb_StartAfterDownload->setChecked(mode.testFlag(StartAfterDownload)); + } + + void CDownloadComponent::clear() + { + if (m_reply) + { + m_reply->abort(); + m_reply = nullptr; + } + + m_waitingForDownload.clear(); + m_fileInProgress = CRemoteFile(); + + ui->prb_Current->setValue(0); + ui->prb_Total->setValue(0); + + ui->le_Completed->clear(); + ui->le_CompletedNumber->clear(); + ui->le_CompletedUrl->clear(); + ui->le_Started->clear(); + ui->le_StartedNumber->clear(); + ui->le_StartedUrl->clear(); + this->showFileInfo(); + } + + bool CDownloadComponent::triggerDownloadingOfNextFile() + { + if (m_waitingForDownload.isEmpty()) { return false; } + const CRemoteFile rf = m_waitingForDownload.front(); + m_waitingForDownload.pop_front(); + return this->triggerDownloadingOfFile(rf); + } + + bool CDownloadComponent::triggerDownloadingOfFile(const CRemoteFile &remoteFile) + { + if (!sGui || !sGui->hasWebDataServices() || sGui->isShuttingDown()) { return false; } + if (!this->existsDownloadDir()) + { + const CStatusMessage msg = CStatusMessage(this, CLogCategory::validation()).error("Invalid download directory"); + this->showOverlayMessage(msg, CDownloadComponent::OverlayMsgTimeoutMs); + return false; + } + + const CUrl download = remoteFile.getSmartUrl(); + if (download.isEmpty()) + { + const CStatusMessage msg = CStatusMessage(this, CLogCategory::validation()).error("No download URL for file name '%1'") << remoteFile.getNameAndSize(); + this->showOverlayMessage(msg, CDownloadComponent::OverlayMsgTimeoutMs); + return false; + } + + this->showStartedFileMessage(remoteFile); + m_fileInProgress = remoteFile; + const QString saveAsFile = CFileUtils::appendFilePaths(ui->le_DownloadDir->text(), remoteFile.getName()); + QNetworkReply *r = sGui->downloadFromNetwork(download, saveAsFile, { this, &CDownloadComponent::downloadedFile}); + bool success = false; + if (r) + { + // this->showLoading(10 * 1000); + CLogMessage(this).info("Triggered downloading of file from '%1'") << download.getHost(); + connect(r, &QNetworkReply::downloadProgress, this, &CDownloadComponent::downloadProgress); + m_reply = r; + success = true; + } + else + { + const CStatusMessage msg = CStatusMessage(this, CLogCategory::validation()).error("Starting download for '%1' failed") << download.getFullUrl(); + this->showOverlayMessage(msg, CDownloadComponent::OverlayMsgTimeoutMs); + } + return success; + } + + void CDownloadComponent::downloadedFile(const CStatusMessage &status) + { + // reset in progress + const CRemoteFile justDownloaded(m_fileInProgress); + m_fileInProgress = CRemoteFile(); + m_reply = nullptr; + this->showCompletedFileMessage(justDownloaded); + this->hideLoading(); + + if (sGui && sGui->isShuttingDown()) { return; } + if (status.isWarningOrAbove()) + { + this->showOverlayMessage(status, CDownloadComponent::OverlayMsgTimeoutMs); + this->clear(); + return; + } + + const bool t = this->triggerDownloadingOfNextFile(); + if (!t) { this->lastFileDownloaded(); } + } + + void CDownloadComponent::lastFileDownloaded() + { + QTimer::singleShot(0, this, &CDownloadComponent::allDownloadsCompleted); + this->startDownloadedExecutable(); + } + + void CDownloadComponent::startDownloadedExecutable() + { + if (!ui->cb_StartAfterDownload->isChecked()) { return; } + if (!this->haveAllDownloadsCompleted()) { return; } + const CRemoteFileList executables = m_remoteFiles.findExecutableFiles(); + if (executables.isEmpty()) { return; } + + // try to start + const QDir dir(ui->le_DownloadDir->text()); + if (!dir.exists()) { return; } + + const QString msg = ui->cb_Shutdown->isChecked() ? + QString("Start '%1' and close swift?") : + QString("Start '%1'?"); + + for (const CRemoteFile &rf : executables) + { + const QString executable = CFileUtils::appendFilePaths(dir.absolutePath(), rf.getName()); + const QFile executableFile(executable); + if (!executableFile.exists()) { continue; } + + QMessageBox::StandardButton reply = QMessageBox::question(this, "Start?", msg.arg(rf.getName()), QMessageBox::Yes | QMessageBox::No); + if (reply != QMessageBox::Yes) { return; } + + QStringList arguments; + if (rf.isSwiftInstaller()) + { + QDir dir(QCoreApplication::applicationDirPath()); + dir.cdUp(); + if (dir.exists()) + { + const QString d(dir.absolutePath()); + arguments << "--installdir"; + arguments << d; + } + } + + const bool started = QProcess::startDetached(executable, arguments, dir.absolutePath()); + if (started) + { + const bool shutdown = ui->cb_Shutdown->isChecked(); + if (sGui && shutdown) + { + QTimer::singleShot(1000, sGui, [] { CGuiApplication::exit(); }); + } + break; + } + } // files + } + + bool CDownloadComponent::existsDownloadDir() const + { + if (ui->le_DownloadDir->text().isEmpty()) { return false; } + const QDir dir(ui->le_DownloadDir->text()); + return dir.exists() && dir.isReadable(); + } + + void CDownloadComponent::openDownloadDir() + { + if (!this->existsDownloadDir()) { return; } + QDesktopServices::openUrl(QUrl::fromLocalFile(ui->le_DownloadDir->text())); + } + + void CDownloadComponent::resetDownloadDir() + { + ui->le_DownloadDir->setText(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)); + } + + void CDownloadComponent::showStartedFileMessage(const CRemoteFile &rf) + { + static const QString of("%1/%2"); + const int current = m_remoteFiles.size() - m_waitingForDownload.size(); + ui->le_Started->setText(rf.getName()); + ui->le_StartedNumber->setText(of.arg(current).arg(m_remoteFiles.size())); + ui->le_StartedUrl->setText(rf.getUrl().getFullUrl()); + ui->prb_Total->setMaximum(m_remoteFiles.size()); + ui->prb_Total->setValue(current - 1); + } + + void CDownloadComponent::showCompletedFileMessage(const CRemoteFile &rf) + { + static const QString of("%1/%2"); + const int current = m_remoteFiles.size() - m_waitingForDownload.size(); + ui->le_Completed->setText(rf.getName()); + ui->le_CompletedNumber->setText(of.arg(current).arg(m_remoteFiles.size())); + ui->le_CompletedUrl->setText(rf.getUrl().getFullUrl()); + ui->prb_Total->setMaximum(m_remoteFiles.size()); + ui->prb_Total->setValue(current); + } + + void CDownloadComponent::cancelOngoingDownloads() + { + this->clear(); + } + + void CDownloadComponent::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) + { + ui->prb_Current->setMaximum(bytesTotal); + ui->prb_Current->setValue(bytesReceived); + } + + void CDownloadComponent::showFileInfo() + { + static const QString info("Files: %1 size: %2"); + ui->le_Info->setText(info.arg(m_remoteFiles.size()).arg(m_remoteFiles.getTotalFileSizeHumanReadable())); + } + } // ns +} // ns diff --git a/src/blackgui/components/downloadcomponent.h b/src/blackgui/components/downloadcomponent.h new file mode 100644 index 000000000..bd7ac4e97 --- /dev/null +++ b/src/blackgui/components/downloadcomponent.h @@ -0,0 +1,146 @@ +/* Copyright (C) 2017 + * swift project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_COMPONENTS_DOWNLOADCOMPONENT_H +#define BLACKGUI_COMPONENTS_DOWNLOADCOMPONENT_H + +#include "blackgui/blackguiexport.h" +#include "blackgui/overlaymessagesframe.h" +#include "blackgui/loadindicator.h" +#include "blackmisc/network/remotefilelist.h" + +#include +#include +#include +#include +#include + +namespace Ui { class CDownloadComponent; } +namespace BlackGui +{ + namespace Components + { + /** + * Download a file + */ + class BLACKGUI_EXPORT CDownloadComponent : + public COverlayMessagesFrame, + public CLoadIndicatorEnabled + { + Q_OBJECT + + public: + //! How to run + enum ModeFlag + { + JustDownload, //!< download, that's it + StartAfterDownload, //!< download, then install + ShutdownSwift, //!< for installers, stop swift before running + SwiftInstaller = StartAfterDownload | ShutdownSwift + }; + Q_DECLARE_FLAGS(Mode, ModeFlag) + + //! Default constructor + explicit CDownloadComponent(QWidget *parent = nullptr); + + //! Dtor + virtual ~CDownloadComponent(); + + //! Set file to be downloaded + bool setDownloadFile(const BlackMisc::Network::CRemoteFile &remoteFile); + + //! Set files to be downloaded + bool setDownloadFiles(const BlackMisc::Network::CRemoteFileList &remoteFiles); + + //! Set donwload directory + bool setDownloadDirectory(const QString &path); + + //! Trigger downloading of the file + bool triggerDownloadingOfFiles(int delayMs = -1); + + //! Downloads in progress + bool isDownloading() const; + + //! Have all downloads completed? + bool haveAllDownloadsCompleted() const; + + //! Get the mode + Mode getMode() const; + + //! Set the mode + void setMode(Mode mode); + + //! Clear all values + void clear(); + + //! Cancel ongoing downloads + void cancelOngoingDownloads(); + + signals: + //! All downloads have been completed + void allDownloadsCompleted(); + + private: + static constexpr int OverlayMsgTimeoutMs = 5000; //!< how long overlay is displayed + QScopedPointer ui; + const QFileDialog::Options m_fileDialogOptions { QFileDialog::ShowDirsOnly | QFileDialog::ReadOnly | QFileDialog::DontResolveSymlinks }; + BlackMisc::Network::CRemoteFile m_fileInProgress; //!< file currently downloading + BlackMisc::Network::CRemoteFileList m_remoteFiles; //!< files for download + BlackMisc::Network::CRemoteFileList m_waitingForDownload; //!< files currently waiting for download + QNetworkReply *m_reply = nullptr; + + //! Select download directory + void selectDownloadDirectory(); + + //! Trigger the download of the next file + bool triggerDownloadingOfNextFile(); + + //! Trigger downloading of the file + bool triggerDownloadingOfFile(const BlackMisc::Network::CRemoteFile &remoteFile); + + //! Downloaded file + void downloadedFile(const BlackMisc::CStatusMessage &status); + + //! Last file was downloaded + void lastFileDownloaded(); + + //! Start download + void startDownloadedExecutable(); + + //! Is the download dir existing? + bool existsDownloadDir() const; + + //! Show download dir + void openDownloadDir(); + + //! Reset the download directory + void resetDownloadDir(); + + //! Show started file download + void showStartedFileMessage(const BlackMisc::Network::CRemoteFile &rf); + + //! Show completed file download + void showCompletedFileMessage(const BlackMisc::Network::CRemoteFile &rf); + + //! Download progress + void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); + + //! File info + void showFileInfo(); + }; + } // ns +} // ns + +Q_DECLARE_METATYPE(BlackGui::Components::CDownloadComponent::Mode) +Q_DECLARE_METATYPE(BlackGui::Components::CDownloadComponent::ModeFlag) +Q_DECLARE_OPERATORS_FOR_FLAGS(BlackGui::Components::CDownloadComponent::Mode) + +#endif // guard diff --git a/src/blackgui/components/downloadcomponent.ui b/src/blackgui/components/downloadcomponent.ui new file mode 100644 index 000000000..b60f1a6fb --- /dev/null +++ b/src/blackgui/components/downloadcomponent.ui @@ -0,0 +1,294 @@ + + + CDownloadComponent + + + + 0 + 0 + 450 + 310 + + + + + 450 + 250 + + + + Download files + + + + + + cancel downloading + + + ... + + + + :/diagona/icons/diagona/icons/cross-circle.png:/diagona/icons/diagona/icons/cross-circle.png + + + + + + + true + + + + + + + Started: + + + + + + + Completed: + + + + + + + Directory: + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 1 + + + + + + + open + + + + + + + true + + + + + + + Current: + + + + + + + Reset download directory + + + ... + + + + :/diagona/icons/diagona/icons/arrow-circle-225-left.png:/diagona/icons/diagona/icons/arrow-circle-225-left.png + + + + + + + change directory + + + change directory + + + select folder + + + + :/diagona/icons/diagona/icons/folder--pencil.png:/diagona/icons/diagona/icons/folder--pencil.png + + + + + + + true + + + + + + + 1 + + + 0 + + + + + + + true + + + + + + + Total: + + + + + + + Info: + + + + + + + 4 + + + true + + + + + + + true + + + + + + + download and install + + + download + + + + + + + true + + + + + + + 4 + + + true + + + + + + + Actions: + + + + + + + + 0 + 20 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + start after download + + + + + + + shutdown + + + + + + + + + + do it + + + + + + + le_Info + tb_CancelDownload + pb_Download + le_DownloadDir + tb_DialogDownloadDir + tb_ResetDownloadDir + pb_OpenDownloadDir + le_Started + le_StartedNumber + le_StartedUrl + le_Completed + le_CompletedNumber + le_CompletedUrl + cb_StartAfterDownload + cb_Shutdown + + + + + + diff --git a/src/blackgui/components/downloaddialog.cpp b/src/blackgui/components/downloaddialog.cpp new file mode 100644 index 000000000..dca08e1b5 --- /dev/null +++ b/src/blackgui/components/downloaddialog.cpp @@ -0,0 +1,68 @@ +/* Copyright (C) 2017 + * swift project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "downloaddialog.h" +#include "ui_downloaddialog.h" +#include + +using namespace BlackMisc::Network; + +namespace BlackGui +{ + namespace Components + { + CDownloadDialog::CDownloadDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::CDownloadDialog) + { + ui->setupUi(this); + this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint); + } + + CDownloadDialog::~CDownloadDialog() + { } + + void CDownloadDialog::setDownloadFile(const CRemoteFile &remoteFile) + { + ui->comp_Download->setDownloadFile(remoteFile); + } + + void CDownloadDialog::setDownloadFiles(const CRemoteFileList &remoteFiles) + { + ui->comp_Download->setDownloadFiles(remoteFiles); + } + + void CDownloadDialog::triggerDownloadingOfFiles(int delayMs) + { + ui->comp_Download->triggerDownloadingOfFiles(delayMs); + } + + void CDownloadDialog::setMode(CDownloadComponent::Mode mode) + { + ui->comp_Download->setMode(mode); + } + + void CDownloadDialog::showAndStartDownloading() + { + QTimer::singleShot(0, this, [ = ] { ui->comp_Download->triggerDownloadingOfFiles(2500); }); + this->show(); + } + + void CDownloadDialog::accept() + { + ui->comp_Download->triggerDownloadingOfFiles(); + } + + void CDownloadDialog::reject() + { + ui->comp_Download->cancelOngoingDownloads(); + this->done(CDownloadDialog::Rejected); + } + } // ns +} // ns diff --git a/src/blackgui/components/downloaddialog.h b/src/blackgui/components/downloaddialog.h new file mode 100644 index 000000000..e6b456b06 --- /dev/null +++ b/src/blackgui/components/downloaddialog.h @@ -0,0 +1,69 @@ +/* Copyright (C) 2017 + * swift project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_COMPONENTS_DOWNLOADDIALOG_H +#define BLACKGUI_COMPONENTS_DOWNLOADDIALOG_H + +#include "blackgui/blackguiexport.h" +#include "downloadcomponent.h" + +#include +#include + +namespace BlackMisc { namespace Network { class CRemoteFile; class CRemoteFileList; }} +namespace Ui { class CDownloadDialog; } +namespace BlackGui +{ + namespace Components + { + /** + * CDownloadComponent as dialog + */ + class BLACKGUI_EXPORT CDownloadDialog : public QDialog + { + Q_OBJECT + + public: + //! Constructor + explicit CDownloadDialog(QWidget *parent = nullptr); + + //! Destructor + virtual ~CDownloadDialog(); + + //! \copydoc CDownloadComponent::setDownloadFile + void setDownloadFile(const BlackMisc::Network::CRemoteFile &remoteFile); + + //! \copydoc CDownloadComponent::setDownloadFiles + void setDownloadFiles(const BlackMisc::Network::CRemoteFileList &remoteFiles); + + //! \copydoc CDownloadComponent::triggerDownloadingOfFiles + void triggerDownloadingOfFiles(int delayMs); + + //! \copydoc CDownloadComponent::setMode + void setMode(CDownloadComponent::Mode mode); + + //! Show and start the downloading + void showAndStartDownloading(); + + protected: + //! \copydoc QDialog::accept + virtual void accept() override; + + //! \copydoc QDialog::reject + virtual void reject() override; + + private: + QScopedPointer ui; + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/downloaddialog.ui b/src/blackgui/components/downloaddialog.ui new file mode 100644 index 000000000..f7db7971a --- /dev/null +++ b/src/blackgui/components/downloaddialog.ui @@ -0,0 +1,100 @@ + + + CDownloadDialog + + + + 0 + 0 + 425 + 265 + + + + + 425 + 0 + + + + Download files + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + + 0 + 225 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + BlackGui::Components::CDownloadComponent + QFrame +
blackgui/components/downloadcomponent.h
+ 1 +
+
+ + + + bb_DownloadDialog + accepted() + CDownloadDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + bb_DownloadDialog + rejected() + CDownloadDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
diff --git a/src/blackgui/components/updateinfocomponent.cpp b/src/blackgui/components/updateinfocomponent.cpp index 44a2faa09..8117596c5 100644 --- a/src/blackgui/components/updateinfocomponent.cpp +++ b/src/blackgui/components/updateinfocomponent.cpp @@ -10,6 +10,7 @@ #include "updateinfocomponent.h" #include "ui_updateinfocomponent.h" #include "installxswiftbusdialog.h" +#include "downloaddialog.h" #include "blackgui/guiapplication.h" #include "blackmisc/network/networkutils.h" #include "blackmisc/db/distributionlist.h" @@ -130,6 +131,31 @@ namespace BlackGui m_installXSwiftBusDialog->show(); } + void CUpdateInfoComponent::downloadInstallerDialog() + { + const CUpdateInfo update(m_updateInfo.get()); + const QString currentVersion = ui->cb_ArtifactsPilotClient->currentText(); + const CArtifact artifact = update.getArtifactsPilotClient().findFirstByVersionOrDefault(currentVersion); + + if (!m_downloadDialog) + { + m_downloadDialog.reset(new CDownloadDialog(this)); + m_downloadDialog->setModal(true); + } + + const CRemoteFile rf = artifact.asRemoteFile(); + if (rf.getUrl().isHavingHtmlSuffix()) + { + QDesktopServices::openUrl(rf.getUrl()); + } + else + { + m_downloadDialog->setMode(CDownloadComponent::SwiftInstaller); + m_downloadDialog->setDownloadFile(artifact.asRemoteFile()); + m_downloadDialog->showAndStartDownloading(); + } + } + void CUpdateInfoComponent::saveSettings() { const QString channel = this->getSelectedOrDefaultDistribution().getChannel(); diff --git a/src/blackgui/components/updateinfocomponent.h b/src/blackgui/components/updateinfocomponent.h index 4f1366d92..2e9f94b99 100644 --- a/src/blackgui/components/updateinfocomponent.h +++ b/src/blackgui/components/updateinfocomponent.h @@ -25,6 +25,7 @@ namespace BlackGui namespace Components { class CInstallXSwiftBusDialog; + class CDownloadDialog; /** * Update info (distributions, artifacts etc.) @@ -59,6 +60,7 @@ namespace BlackGui private: QScopedPointer ui; QScopedPointer m_installXSwiftBusDialog; //!< dialog, install XSwiftXBus + QScopedPointer m_downloadDialog; //!< dialog, download installer BlackMisc::CDataReadOnly m_updateInfo { this, &CUpdateInfoComponent::changedUpdateInfo }; //!< version cache BlackMisc::CSetting m_updateSettings { this }; //!< channel/platform selected BlackMisc::CDigestSignal m_dsDistributionAvailable { this, &CUpdateInfoComponent::updateInfoAvailable, 15000, 2 }; @@ -81,6 +83,9 @@ namespace BlackGui //! Install XSwiftBus dialog void downloadXSwiftBusDialog(); + //! Download installer dialog + void downloadInstallerDialog(); + //! Save the current settings void saveSettings();