From d1bf788f0755e937846cd3354ac1f674de08b970 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 25 Apr 2017 14:36:13 +0200 Subject: [PATCH] Ref T41, independent dialog for downloading swift --- .../components/downloadandinstalldialog.cpp | 62 +++++++++++++ .../components/downloadandinstalldialog.h | 52 +++++++++++ .../components/downloadandinstalldialog.ui | 88 +++++++++++++++++++ 3 files changed, 202 insertions(+) create mode 100644 src/blackgui/components/downloadandinstalldialog.cpp create mode 100644 src/blackgui/components/downloadandinstalldialog.h create mode 100644 src/blackgui/components/downloadandinstalldialog.ui diff --git a/src/blackgui/components/downloadandinstalldialog.cpp b/src/blackgui/components/downloadandinstalldialog.cpp new file mode 100644 index 000000000..5c776c0e5 --- /dev/null +++ b/src/blackgui/components/downloadandinstalldialog.cpp @@ -0,0 +1,62 @@ +/* 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 "downloadandinstalldialog.h" +#include "ui_downloadandinstalldialog.h" +#include +#include + +using namespace BlackMisc::Db; + +namespace BlackGui +{ + class COverlayMessagesFrame; + + namespace Components + { + CDownloadAndInstallDialog::CDownloadAndInstallDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::CDownloadAndInstallDialog) + { + ui->setupUi(this); + ui->bb_DownloadInstallDialog->button(QDialogButtonBox::Ok)->setText("Download and install"); + this->selectionChanged(); + connect(ui->comp_DistributionInfo, &CDistributionInfoComponent::selectionChanged, this, &CDownloadAndInstallDialog::selectionChanged); + } + + CDownloadAndInstallDialog::~CDownloadAndInstallDialog() + { } + + bool CDownloadAndInstallDialog::isNewVersionAvailable() const + { + const bool newVersion = ui->comp_DistributionInfo->isNewVersionAvailable(); + return newVersion; + } + + int CDownloadAndInstallDialog::exec() + { + const int r = QDialog::exec(); + if (r != QDialog::Accepted) return r; + if (!ui->comp_DistributionInfo->isNewVersionAvailable()) { return QDialog::Rejected; } + const CDistribution distribution = ui->comp_DistributionInfo->getCurrentDistribution(); + if (!distribution.hasDownloadUrls()) { return QDialog::Rejected; } + + // in future, start download and close application + // for now, just open URL + QDesktopServices::openUrl(distribution.getDownloadUrls().getRandomUrl()); + return QDialog::Rejected; + } + + void CDownloadAndInstallDialog::selectionChanged() + { + const bool nv = ui->comp_DistributionInfo->isNewVersionAvailable(); + ui->bb_DownloadInstallDialog->button(QDialogButtonBox::Ok)->setEnabled(nv); + } + } // ns +} // ns diff --git a/src/blackgui/components/downloadandinstalldialog.h b/src/blackgui/components/downloadandinstalldialog.h new file mode 100644 index 000000000..9c6116760 --- /dev/null +++ b/src/blackgui/components/downloadandinstalldialog.h @@ -0,0 +1,52 @@ +/* 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_DOWNLOADANDINSTALLDIALOG_H +#define BLACKGUI_COMPONENTS_DOWNLOADANDINSTALLDIALOG_H + +#include "blackgui/blackguiexport.h" +#include + +namespace Ui { class CDownloadAndInstallDialog; } +namespace BlackGui +{ + namespace Components + { + /** + * Download and install swift + */ + class BLACKGUI_EXPORT CDownloadAndInstallDialog : public QDialog + { + Q_OBJECT + + public: + //! Constructor + explicit CDownloadAndInstallDialog(QWidget *parent = nullptr); + + //! Destructor + virtual ~CDownloadAndInstallDialog(); + + //! A new version existing? + bool isNewVersionAvailable() const; + + //! \copydoc QDialog::exec + virtual int exec() override; + + private: + QScopedPointer ui; + + //! Selection in distribution component changed + void selectionChanged(); + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/downloadandinstalldialog.ui b/src/blackgui/components/downloadandinstalldialog.ui new file mode 100644 index 000000000..cae577f91 --- /dev/null +++ b/src/blackgui/components/downloadandinstalldialog.ui @@ -0,0 +1,88 @@ + + + CDownloadAndInstallDialog + + + + 0 + 0 + 400 + 125 + + + + Update checker + + + + + + true + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + BlackGui::Components::CDistributionInfoComponent + QFrame +
blackgui/components/distributioninfocomponent.h
+ 1 +
+
+ + + + bb_DownloadInstallDialog + accepted() + CDownloadAndInstallDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + bb_DownloadInstallDialog + rejected() + CDownloadAndInstallDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +