From f0cf15a5727a1e33703046a5f87d057a95075478 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 11 Dec 2017 04:16:00 +0100 Subject: [PATCH] Ref T203, CInstallXSwiftBusComponent now using TUpdateInfo (and no longer the XSwiftBus service) * default name can be set * XSwiftBusFileInfo no longer needed * data read from cache (i.e. TUpdateInfo) --- .../components/installxswiftbuscomponent.cpp | 38 ++++++++- .../components/installxswiftbuscomponent.h | 23 +++--- .../components/installxswiftbuscomponent.ui | 82 +++++++++++-------- .../components/installxswiftbusdialog.cpp | 5 ++ .../components/installxswiftbusdialog.h | 4 + 5 files changed, 105 insertions(+), 47 deletions(-) diff --git a/src/blackgui/components/installxswiftbuscomponent.cpp b/src/blackgui/components/installxswiftbuscomponent.cpp index cc7e5ae87..3dfd861f7 100644 --- a/src/blackgui/components/installxswiftbuscomponent.cpp +++ b/src/blackgui/components/installxswiftbuscomponent.cpp @@ -23,6 +23,7 @@ #include using namespace BlackMisc; +using namespace BlackMisc::Db; using namespace BlackMisc::Network; using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation::Settings; @@ -43,8 +44,8 @@ namespace BlackGui ui->le_DownloadDir->setText(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)); ui->cb_DownloadFile->setEnabled(false); - connect(ui->pb_DialogInstallDir, &QPushButton::pressed, this, &CInstallXSwiftBusComponent::selectPluginDirectory); - connect(ui->pb_DialogDownloadDir, &QPushButton::pressed, this, &CInstallXSwiftBusComponent::selectDownloadDirectory); + connect(ui->tb_DialogInstallDir, &QPushButton::pressed, this, &CInstallXSwiftBusComponent::selectPluginDirectory); + connect(ui->tb_DialogDownloadDir, &QPushButton::pressed, this, &CInstallXSwiftBusComponent::selectDownloadDirectory); connect(ui->pb_Download, &QPushButton::pressed, this, &CInstallXSwiftBusComponent::triggerDownloadingOfXSwiftBusFile); connect(ui->pb_OpenDownloadDir, &QPushButton::pressed, this, &CInstallXSwiftBusComponent::openDownloadDir); connect(ui->pb_OpenInstallDir, &QPushButton::pressed, this, &CInstallXSwiftBusComponent::openInstallDir); @@ -130,7 +131,7 @@ namespace BlackGui } const CRemoteFile rf = this->getRemoteFileSelected(); - const CUrl download = rf.getUrl(); + const CUrl download = rf.getSmartUrl(); if (download.isEmpty()) { const CStatusMessage msg = CStatusMessage(this, CLogCategory::validation()).error("No download URL for file name '%1'") << rf.getNameAndSize(); @@ -168,7 +169,9 @@ namespace BlackGui CRemoteFile CInstallXSwiftBusComponent::getRemoteFileSelected() const { const QString fileNameAndSize = ui->cb_DownloadFile->currentText(); - return m_remoteFiles.findFirstMatchingNameOrDefault(fileNameAndSize); + const CUpdateInfo update = m_updates.get(); + const CRemoteFileList remoteFiles = update.getArtifactsXsb().asRemoteFiles(); + return remoteFiles.findFirstByMatchingNameOrDefault(fileNameAndSize); } bool CInstallXSwiftBusComponent::existsDownloadDir() const @@ -193,6 +196,33 @@ namespace BlackGui return dir; } + void CInstallXSwiftBusComponent::updatesChanged() + { + const CUpdateInfo updateInfo = m_updates.get(); + if (updateInfo.getArtifactsXsb().isEmpty()) { return; } + const CArtifactList artifacts = updateInfo.getArtifactsXsbLatestVersionFirst(); + const CRemoteFileList remoteFiles = artifacts.asRemoteFiles(); + if (!remoteFiles.isEmpty()) + { + const QStringList xSwiftBusFiles(remoteFiles.getNamesPlusSize(true)); + ui->cb_DownloadFile->addItems(xSwiftBusFiles); + + // current text + QString current; + if (!m_defaultDownloadName.isEmpty()) + { + const CRemoteFile rf = remoteFiles.findFirstByMatchingNameOrDefault(m_defaultDownloadName); + current = rf.getNameAndSize(); + } + ui->cb_DownloadFile->setCurrentText( + current.isEmpty() ? + remoteFiles.backOrDefault().getNameAndSize() : + current + ); // latest version + } + ui->cb_DownloadFile->setEnabled(!remoteFiles.isEmpty()); + } + void CInstallXSwiftBusComponent::openInstallDir() { if (!this->existsXSwiftBusPluginDir()) { return; } diff --git a/src/blackgui/components/installxswiftbuscomponent.h b/src/blackgui/components/installxswiftbuscomponent.h index 96388fa83..7b743d123 100644 --- a/src/blackgui/components/installxswiftbuscomponent.h +++ b/src/blackgui/components/installxswiftbuscomponent.h @@ -15,6 +15,8 @@ #include "blackgui/overlaymessagesframe.h" #include "blackgui/loadindicator.h" #include "blackcore/application/applicationsettings.h" +#include "blackcore/application/updatesettings.h" +#include "blackmisc/db/updateinfo.h" #include "blackmisc/simulation/settings/simulatorsettings.h" #include "blackmisc/network/remotefilelist.h" #include @@ -43,12 +45,16 @@ namespace BlackGui //! Dtor virtual ~CInstallXSwiftBusComponent(); + //! Set a default name for download + void setDefaultDownloadName(const QString &defaultDownload); + private: QScopedPointer ui; - BlackMisc::CSettingReadOnly m_enabledSimulators { this }; - BlackMisc::Simulation::Settings::CMultiSimulatorSettings m_simulatorSettings { this }; - BlackMisc::Network::CRemoteFileList m_remoteFiles; + BlackMisc::Simulation::Settings::CMultiSimulatorSettings m_simulatorSettings { this }; //!< for directories of XPlane + BlackMisc::CDataReadOnly m_updates { this, &CInstallXSwiftBusComponent::updatesChanged }; + BlackMisc::CSettingReadOnly m_updateSettings { this }; //!< channel/platform selected const QFileDialog::Options m_fileDialogOptions { QFileDialog::ShowDirsOnly | QFileDialog::ReadOnly | QFileDialog::DontResolveSymlinks }; + QString m_defaultDownloadName; //!< default name for download static constexpr int OverlayMsgTimeoutMs = 5000; //!< how long overlay is displayed @@ -61,13 +67,7 @@ namespace BlackGui //! Install from download directory to X-Plane directory void installXSwiftBus(); - //! Trigger loading of XSwiftBus file info - void triggerLoadingXSwiftBusFileInfo(); - - //! Received info about XSwiftBus download files - void loadedAlphaXSwiftBusFileInfo(QNetworkReply *reply); - - //! Trigger downloading of XSwiftBusFile + //! Trigger downloading of the XSwiftBus file void triggerDownloadingOfXSwiftBusFile(); //! Downloaded XSwiftBus file @@ -85,6 +85,9 @@ namespace BlackGui //! X-Plane directory from settings of default directory QString getXPlanePluginDirectory() const; + //! Updates have been changed + void updatesChanged(); + //! Show install dir void openInstallDir(); diff --git a/src/blackgui/components/installxswiftbuscomponent.ui b/src/blackgui/components/installxswiftbuscomponent.ui index ca1deab2d..0178acd12 100644 --- a/src/blackgui/components/installxswiftbuscomponent.ui +++ b/src/blackgui/components/installxswiftbuscomponent.ui @@ -67,6 +67,13 @@ Download and install XSwiftBus + + + + Install directory: + + + @@ -84,13 +91,6 @@ - - - - Install directory: - - - @@ -101,44 +101,58 @@ - - - - download and install - - - download - - - - - - - ... - - - - - - ... - - - - open - + open + + + + download and install + + + download + + + + + + + change directory + + + change directory + + + + :/diagona/icons/diagona/icons/folder--pencil.png:/diagona/icons/diagona/icons/folder--pencil.png + + + + + + + change directory + + + change directory + + + + :/diagona/icons/diagona/icons/folder--pencil.png:/diagona/icons/diagona/icons/folder--pencil.png + + + @@ -190,6 +204,8 @@ 1 - + + + diff --git a/src/blackgui/components/installxswiftbusdialog.cpp b/src/blackgui/components/installxswiftbusdialog.cpp index 858bbad88..604cb1093 100644 --- a/src/blackgui/components/installxswiftbusdialog.cpp +++ b/src/blackgui/components/installxswiftbusdialog.cpp @@ -23,5 +23,10 @@ namespace BlackGui CInstallXSwiftBusDialog::~CInstallXSwiftBusDialog() { } + + void CInstallXSwiftBusDialog::setDefaultDownloadName(const QString &defaultName) + { + ui->comp_InstallXSwiftBus->setDefaultDownloadName(defaultName); + } } // ns } // ns diff --git a/src/blackgui/components/installxswiftbusdialog.h b/src/blackgui/components/installxswiftbusdialog.h index 3cb75c539..6f4e973e9 100644 --- a/src/blackgui/components/installxswiftbusdialog.h +++ b/src/blackgui/components/installxswiftbusdialog.h @@ -12,6 +12,7 @@ #ifndef BLACKGUI_COMPONENTS_INSTALLXSWIFTBUSDIALOG_H #define BLACKGUI_COMPONENTS_INSTALLXSWIFTBUSDIALOG_H +#include #include namespace Ui { class CInstallXSwiftBusDialog; } @@ -33,6 +34,9 @@ namespace BlackGui //! Dtor virtual ~CInstallXSwiftBusDialog(); + //! \copydoc CInstallXSwiftBusComponent::setDefaultDownloadName + void setDefaultDownloadName(const QString &defaultName); + private: QScopedPointer ui; };