mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
Ref T203, download component (generic file download)
This commit is contained in:
343
src/blackgui/components/downloadcomponent.cpp
Normal file
343
src/blackgui/components/downloadcomponent.cpp
Normal file
@@ -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 <QProcess>
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
#include <QStandardPaths>
|
||||
#include <QTimer>
|
||||
#include <QDesktopServices>
|
||||
|
||||
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
|
||||
146
src/blackgui/components/downloadcomponent.h
Normal file
146
src/blackgui/components/downloadcomponent.h
Normal file
@@ -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 <QNetworkReply>
|
||||
#include <QFileDialog>
|
||||
#include <QWizard>
|
||||
#include <QScopedPointer>
|
||||
#include <QFlags>
|
||||
|
||||
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::CDownloadComponent> 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
|
||||
294
src/blackgui/components/downloadcomponent.ui
Normal file
294
src/blackgui/components/downloadcomponent.ui
Normal file
@@ -0,0 +1,294 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CDownloadComponent</class>
|
||||
<widget class="QFrame" name="CDownloadComponent">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>450</width>
|
||||
<height>310</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>450</width>
|
||||
<height>250</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Download files</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gl_DownloadComponent" columnstretch="1,3,1,1,1">
|
||||
<item row="0" column="3">
|
||||
<widget class="QToolButton" name="tb_CancelDownload">
|
||||
<property name="toolTip">
|
||||
<string>cancel downloading</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../blackmisc/blackmisc.qrc">
|
||||
<normaloff>:/diagona/icons/diagona/icons/cross-circle.png</normaloff>:/diagona/icons/diagona/icons/cross-circle.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="le_DownloadDir">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="lbl_Started">
|
||||
<property name="text">
|
||||
<string>Started:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="lbl_Completed">
|
||||
<property name="text">
|
||||
<string>Completed:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lbl_DownloadDirectory">
|
||||
<property name="text">
|
||||
<string>Directory:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="0">
|
||||
<spacer name="vs_DownloadComponent">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="7" column="1" colspan="4">
|
||||
<widget class="QProgressBar" name="prb_Current">
|
||||
<property name="maximum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<widget class="QPushButton" name="pb_OpenDownloadDir">
|
||||
<property name="text">
|
||||
<string>open</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="3">
|
||||
<widget class="QLineEdit" name="le_Started">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="lbl_Current">
|
||||
<property name="text">
|
||||
<string>Current:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QToolButton" name="tb_ResetDownloadDir">
|
||||
<property name="toolTip">
|
||||
<string>Reset download directory</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../blackmisc/blackmisc.qrc">
|
||||
<normaloff>:/diagona/icons/diagona/icons/arrow-circle-225-left.png</normaloff>:/diagona/icons/diagona/icons/arrow-circle-225-left.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QToolButton" name="tb_DialogDownloadDir">
|
||||
<property name="toolTip">
|
||||
<string>change directory</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string>change directory</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>select folder</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../blackmisc/blackmisc.qrc">
|
||||
<normaloff>:/diagona/icons/diagona/icons/folder--pencil.png</normaloff>:/diagona/icons/diagona/icons/folder--pencil.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1" colspan="3">
|
||||
<widget class="QLineEdit" name="le_Completed">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1" colspan="4">
|
||||
<widget class="QProgressBar" name="prb_Total">
|
||||
<property name="maximum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1" colspan="4">
|
||||
<widget class="QLineEdit" name="le_CompletedUrl">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="lbl_Total">
|
||||
<property name="text">
|
||||
<string>Total:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lbl_Info">
|
||||
<property name="text">
|
||||
<string>Info:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="4">
|
||||
<widget class="QLineEdit" name="le_StartedNumber">
|
||||
<property name="maxLength">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="4">
|
||||
<widget class="QLineEdit" name="le_StartedUrl">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<widget class="QPushButton" name="pb_Download">
|
||||
<property name="toolTip">
|
||||
<string>download and install</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>download</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="2">
|
||||
<widget class="QLineEdit" name="le_Info">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="4">
|
||||
<widget class="QLineEdit" name="le_CompletedNumber">
|
||||
<property name="maxLength">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="lbl_Actions">
|
||||
<property name="text">
|
||||
<string>Actions:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1" colspan="3">
|
||||
<widget class="QFrame" name="fr_Checkboxes">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="hl_Checkboxes">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="cb_StartAfterDownload">
|
||||
<property name="text">
|
||||
<string>start after download</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="cb_Shutdown">
|
||||
<property name="text">
|
||||
<string>shutdown</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="4">
|
||||
<widget class="QPushButton" name="pb_DoIt">
|
||||
<property name="text">
|
||||
<string>do it</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>le_Info</tabstop>
|
||||
<tabstop>tb_CancelDownload</tabstop>
|
||||
<tabstop>pb_Download</tabstop>
|
||||
<tabstop>le_DownloadDir</tabstop>
|
||||
<tabstop>tb_DialogDownloadDir</tabstop>
|
||||
<tabstop>tb_ResetDownloadDir</tabstop>
|
||||
<tabstop>pb_OpenDownloadDir</tabstop>
|
||||
<tabstop>le_Started</tabstop>
|
||||
<tabstop>le_StartedNumber</tabstop>
|
||||
<tabstop>le_StartedUrl</tabstop>
|
||||
<tabstop>le_Completed</tabstop>
|
||||
<tabstop>le_CompletedNumber</tabstop>
|
||||
<tabstop>le_CompletedUrl</tabstop>
|
||||
<tabstop>cb_StartAfterDownload</tabstop>
|
||||
<tabstop>cb_Shutdown</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../../blackmisc/blackmisc.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
68
src/blackgui/components/downloaddialog.cpp
Normal file
68
src/blackgui/components/downloaddialog.cpp
Normal file
@@ -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 <QTimer>
|
||||
|
||||
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
|
||||
69
src/blackgui/components/downloaddialog.h
Normal file
69
src/blackgui/components/downloaddialog.h
Normal file
@@ -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 <QDialog>
|
||||
#include <QScopedPointer>
|
||||
|
||||
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::CDownloadDialog> ui;
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
100
src/blackgui/components/downloaddialog.ui
Normal file
100
src/blackgui/components/downloaddialog.ui
Normal file
@@ -0,0 +1,100 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CDownloadDialog</class>
|
||||
<widget class="QDialog" name="CDownloadDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>425</width>
|
||||
<height>265</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>425</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Download files</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="vl_DownloadDialog">
|
||||
<property name="leftMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="BlackGui::Components::CDownloadComponent" name="comp_Download">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>225</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="bb_DownloadDialog">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>BlackGui::Components::CDownloadComponent</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>blackgui/components/downloadcomponent.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>bb_DownloadDialog</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>CDownloadDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>bb_DownloadDialog</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>CDownloadDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -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();
|
||||
|
||||
@@ -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::CUpdateInfoComponent> ui;
|
||||
QScopedPointer<CInstallXSwiftBusDialog> m_installXSwiftBusDialog; //!< dialog, install XSwiftXBus
|
||||
QScopedPointer<CDownloadDialog> m_downloadDialog; //!< dialog, download installer
|
||||
BlackMisc::CDataReadOnly<BlackMisc::Db::TUpdateInfo> m_updateInfo { this, &CUpdateInfoComponent::changedUpdateInfo }; //!< version cache
|
||||
BlackMisc::CSetting<BlackCore::Application::TUpdatePreferences> 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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user