swift
Loading...
Searching...
No Matches
updateinfocomponent.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
5
6#include <QDesktopServices>
7#include <QMessageBox>
8
9#include "ui_updateinfocomponent.h"
10
11#include "config/buildconfig.h"
14#include "gui/guiapplication.h"
16#include "misc/logmessage.h"
18#include "misc/stringutils.h"
19
20using namespace swift::config;
21using namespace swift::core::application;
22using namespace swift::misc;
23using namespace swift::misc::db;
24using namespace swift::misc::network;
25
27{
29 {
30 ui->setupUi(this);
31 Q_ASSERT_X(sGui, Q_FUNC_INFO, "Need sGui");
32
33 connect(sGui, &CGuiApplication::updateInfoAvailable, this, &CUpdateInfoComponent::changedUpdateInfo,
35 connect(ui->pb_CheckForUpdates, &QPushButton::pressed, this, &CUpdateInfoComponent::requestLoadOfSetup,
37 connect(ui->pb_DownloadXSwiftBus, &QPushButton::pressed, this, &CUpdateInfoComponent::downloadXSwiftBusDialog,
39 connect(ui->pb_DownloadInstaller, &QPushButton::pressed, this, &CUpdateInfoComponent::downloadInstallerDialog,
41
42 // use version signal as trigger for completion
43 if (!m_updateInfo.get().isEmpty())
44 {
45 this->changedUpdateInfo();
46 }
47 }
48
50
52 {
53 const CUpdateInfo info = m_updateInfo.get();
54 const CPlatform p = this->getSelectedOrDefaultPlatform();
55 const CDistribution d = this->getSelectedOrDefaultDistribution();
56 const CArtifact a =
58 return a;
59 }
60
62 {
63 const QStringList settings = m_updateSettings.get();
64 Q_ASSERT_X(settings.size() == 2, Q_FUNC_INFO, "wrong setting");
65 const QString channel = settings.front();
66 if (channel.isEmpty())
67 {
68 return false;
69 }
70
71 const CUpdateInfo info = m_updateInfo.get();
73 const QVersionNumber vCurrentChannelPlatform =
76 if (vCurrentChannelPlatform.isNull())
77 {
78 return false;
79 }
80 return (vCurrentChannelPlatform > vCurrent);
81 }
82
84 {
86 QTimer::singleShot(10, this, [=, this] {
87 if (!myself)
88 {
89 return;
90 }
91 ui->pb_DownloadInstaller->click();
92 });
93 }
94
95 void CUpdateInfoComponent::requestLoadOfSetup()
96 {
97 if (!sGui || sGui->isShuttingDown())
98 {
99 return;
100 }
101 sGui->reloadUpdateInfo();
102 }
103
104 void CUpdateInfoComponent::changedUpdateInfo()
105 {
106 ui->lbl_CurrentVersionDisplay->setText(CBuildConfig::getVersionString());
107
108 const CUpdateInfo updateInfo(m_updateInfo.get());
109 const QStringList settings = m_updateSettings.get();
110 Q_ASSERT_X(settings.size() == 2, Q_FUNC_INFO, "Settings");
111
112 const CPlatformSet platforms = updateInfo.getArtifactsPilotClient().getPlatforms();
113 CDistributionList distributions = updateInfo.getArtifactsPilotClient().getDistributions();
115
116 int i = 0;
117 disconnect(ui->cb_Platforms, &QComboBox::currentTextChanged, this, &CUpdateInfoComponent::platformChanged);
118 ui->cb_Platforms->clear();
119 for (const CPlatform &platform : platforms)
120 {
121 ui->cb_Platforms->insertItem(i++, CIcon(platform.toIcon()).toPixmap(), platform.getPlatformName());
122 }
123 if (platforms.contains(settings.last()))
124 {
125 ui->cb_Platforms->setCurrentText(settings.last());
126 }
127 else if (platforms.contains(CPlatform::currentPlatform().getPlatformName()))
128 {
129 ui->cb_Platforms->setCurrentText(CPlatform::currentPlatform().getPlatformName());
130 }
131
132 i = 0;
133 disconnect(ui->cb_Channels, &QComboBox::currentTextChanged, this, &CUpdateInfoComponent::channelChanged);
134 ui->cb_Channels->clear();
135 for (const CDistribution &distribution : distributions)
136 {
137 ui->cb_Channels->insertItem(i++, CIcon(distribution.getRestrictionIcon()).toPixmap(),
138 distribution.getChannel());
139 }
140 if (distributions.containsChannel(settings.front()))
141 {
142 ui->cb_Channels->setCurrentText(settings.front());
143 }
144
145 this->uiSelectionChanged();
146 connect(ui->cb_Platforms, &QComboBox::currentTextChanged, this, &CUpdateInfoComponent::platformChanged,
148 connect(ui->cb_Channels, &QComboBox::currentTextChanged, this, &CUpdateInfoComponent::channelChanged,
150
151 // emit via digest signal
152 m_dsDistributionAvailable.inputSignal();
153 }
154
155 void CUpdateInfoComponent::downloadXSwiftBusDialog()
156 {
157 const QString currentXsb = ui->cb_ArtifactsXsb->currentText();
158 const QString currentSwift = ui->cb_ArtifactsPilotClient->currentText();
159
160 if (!stringCompare(currentXsb, currentSwift, Qt::CaseInsensitive))
161 {
162 const QString msg = QStringLiteral("xswiftbus '%1' does NOT match swift version, download anyway?")
163 .arg(currentXsb, currentSwift);
164 const QMessageBox::StandardButton reply = QMessageBox::question(this, QStringLiteral("Download xswiftbus"),
166 if (reply != QMessageBox::Yes)
167 {
168 return;
169 }
170 }
171
172 if (!m_installXSwiftBusDialog)
173 {
174 m_installXSwiftBusDialog.reset(new CInstallXSwiftBusDialog(this));
175 m_installXSwiftBusDialog->setModal(true);
176 }
177
178 m_installXSwiftBusDialog->setDefaultDownloadName(currentXsb);
179 m_installXSwiftBusDialog->show();
180 }
181
182 void CUpdateInfoComponent::downloadInstallerDialog()
183 {
184 const CUpdateInfo update(m_updateInfo.get());
185 const QString currentVersion = ui->cb_ArtifactsPilotClient->currentText();
186 const QString platform = ui->cb_Platforms->currentText();
187 if (!CPlatform::isCurrentPlatform(platform))
188 {
190 QMessageBox::warning(this, "Download installer",
191 QStringLiteral("The platform '%1' does not match your current platform '%2'.\n"
192 "Do you want to continue?")
193 .arg(platform, CPlatform::currentPlatform().getPlatformName()),
195 if (ret != QMessageBox::Yes)
196 {
197 return;
198 }
199 }
200
201 // find artifcat
202 const CArtifact artifact =
203 update.getArtifactsPilotClient().findByMatchingPlatform(platform).findFirstByVersionOrDefault(
204 currentVersion);
205
206 if (!m_downloadDialog)
207 {
208 m_downloadDialog.reset(new CDownloadDialog(this));
209 m_downloadDialog->setModal(true);
210 }
211
212 const CRemoteFile rf = artifact.asRemoteFile();
213 if (rf.getUrl().isHavingHtmlSuffix())
214 {
216 }
217 else
218 {
219 m_downloadDialog->setMode(CDownloadComponent::SwiftInstaller);
220 m_downloadDialog->setDownloadFile(artifact.asRemoteFile());
221 m_downloadDialog->showAndStartDownloading();
222 }
223 }
224
225 void CUpdateInfoComponent::saveSettings()
226 {
227 const QString channel = this->getSelectedOrDefaultDistribution().getChannel();
228 const QString platform = this->getSelectedOrDefaultPlatform().getPlatformName();
229 const QStringList settings({ channel, platform });
230 const CStatusMessage m = m_updateSettings.setAndSave(settings);
231 if (m.isFailure())
232 {
234 }
235 }
236
237 void CUpdateInfoComponent::channelChanged() { this->uiSelectionChanged(); }
238
239 void CUpdateInfoComponent::platformChanged() { this->uiSelectionChanged(); }
240
241 void CUpdateInfoComponent::uiSelectionChanged()
242 {
243 const CDistribution selectedDistribution(this->getSelectedOrDefaultDistribution());
244 const CPlatform selectedPlatform(this->getSelectedOrDefaultPlatform());
245
246 // for xswiftbus we only show public (unrestricted) ones, as the follow up dialog will only show unrestricted
247 const CUpdateInfo updateInfo(m_updateInfo.get());
248 const CArtifactList artifactsPilotClient = updateInfo.getArtifactsPilotClient().findByDistributionAndPlatform(
249 selectedDistribution, selectedPlatform, true);
250 const CArtifactList artifactsXsb =
251 updateInfo.getArtifactsXSwiftBus().findWithUnrestrictedDistributions().findByDistributionAndPlatform(
252 selectedDistribution, selectedPlatform, true);
253 const CArtifact latestPilotClient = artifactsPilotClient.getLatestArtifactOrDefault();
254
255 const QStringList sortedPilotClientVersions = artifactsPilotClient.getSortedVersions();
256 ui->cb_ArtifactsPilotClient->clear();
257 ui->cb_ArtifactsPilotClient->insertItems(0, sortedPilotClientVersions);
258 ui->pb_DownloadInstaller->setEnabled(!artifactsPilotClient.isEmpty());
259
260 const QStringList sortedXsbVersions = artifactsXsb.getSortedVersions();
261 ui->cb_ArtifactsXsb->clear();
262 ui->cb_ArtifactsXsb->insertItems(0, sortedXsbVersions);
263 ui->pb_DownloadXSwiftBus->setEnabled(!artifactsXsb.isEmpty());
264
265 // save the settings as this is needed afterwards
266 this->saveSettings();
267
269 const bool newer = this->isNewPilotClientVersionAvailable();
270 ui->lbl_StatusInfo->setText(newer ? "New version available" : "Nothing new");
271 ui->lbl_StatusInfo->setStyleSheet(newer ? "background-color: green; color: white;" :
272 "background-color: red; color: white;");
273
274 emit this->selectionChanged();
275
276 if (newer && latestPilotClient.isLoadedFromDb())
277 {
278 emit this->newerPilotClientAvailable(latestPilotClient);
279 }
280 }
281
282 const CPlatform &CUpdateInfoComponent::getSelectedOrDefaultPlatform() const
283 {
284 const QStringList settings = m_updateSettings.get(); // channel / platform
285 QString p = ui->cb_Platforms->currentText();
286 if (p.isEmpty())
287 {
288 p = settings.last();
289 }
290 if (p.isEmpty())
291 {
293 }
295 }
296
297 CDistribution CUpdateInfoComponent::getSelectedOrDefaultDistribution() const
298 {
299 const QStringList settings = m_updateSettings.get(); // channel / platform
300 QString c = ui->cb_Channels->currentText();
301 if (c.isEmpty())
302 {
303 c = settings.first();
304 }
305 const CUpdateInfo updateInfo(m_updateInfo.get());
306 return c.isEmpty() ? updateInfo.getDistributions().getMostStableOrDefault() :
307 updateInfo.getDistributions().findFirstByChannelOrDefault(c);
308 }
309} // namespace swift::gui::components
static const QString & getVersionString()
Version as QVersionNumber.
static const QVersionNumber & getVersion()
Version as QVersionNumber.
void updateInfoAvailable(bool success)
Update info available (cache, web load).
void selectionChanged()
New platfrom or channel.
bool isNewPilotClientVersionAvailable() const
Is there a new version available?
swift::misc::db::CArtifact getLatestAvailablePilotClientArtifactForSelection() const
Is there a new version available return version, else empty string.
void newerPilotClientAvailable(const swift::misc::db::CArtifact &latestPilotClient)
A newer pilot client is available.
T get() const
Get a copy of the current value.
Definition valuecache.h:411
Value object for icons. An icon is stored in the global icon repository and identified by its index....
Definition icon.h:39
QPixmap toPixmap() const
Corresponding pixmap.
Definition icon.cpp:34
static void preformatted(const CStatusMessage &statusMessage)
Sends a verbatim, preformatted message to the log.
Platform (i.e.
Definition platform.h:24
static bool isCurrentPlatform(const QString &platform)
Is this the current platform.
Definition platform.cpp:179
QString getPlatformName() const
Name of platform.
Definition platform.cpp:56
static const CPlatform & stringToPlatformObject(const QString &str)
Convert to enum.
Definition platform.cpp:138
static const CPlatform & currentPlatform()
Current platform.
Definition platform.cpp:173
Value object for a set of platforms.
Definition platformset.h:22
bool isEmpty() const
Synonym for empty.
Definition sequence.h:285
Artifacts ("our software" products).
Definition artifact.h:23
network::CRemoteFile asRemoteFile() const
Turn into remote file.
Definition artifact.cpp:67
CArtifactList findByDistribution(const CDistribution &distribution, bool findMoreStableDistribution=false) const
Find by distribution.
CArtifactList findByDistributionAndPlatform(const CDistribution &distribution, const CPlatform &platform, bool findMoreStableDistributions=false) const
Find by distribution and platform.
QVersionNumber getLatestQVersion() const
Latest version.
CArtifact getLatestArtifactOrDefault() const
Latest (newest) artifact.
QStringList getSortedVersions() const
All unique versions.
Distributions for channel.
Multiple distributions for different channels:
CDistribution findFirstByChannelOrDefault(const QString &channel) const
Find by channel.
void sortByStability(Qt::SortOrder order=Qt::AscendingOrder)
Stability.
Update info, i.e. artifacts and distributions.
Definition updateinfo.h:24
const CDistributionList & getDistributions() const
Distributions (all).
Definition updateinfo.h:64
const CArtifactList & getArtifactsPilotClient() const
Artifacts (pilot client).
Definition updateinfo.h:44
bool isLoadedFromDb() const
Loaded from DB.
Definition datastore.cpp:58
const CUrl & getUrl() const
Get URL.
Definition remotefile.h:76
bool isHavingHtmlSuffix() const
Likely a HTM file?
Definition url.cpp:215
High level reusable GUI components.
Classes related to configuration settings.
Free functions in swift::misc.
SWIFT_MISC_EXPORT bool stringCompare(const QString &c1, const QString &c2, Qt::CaseSensitivity cs)
String compare.
void currentTextChanged(const QString &text)
bool openUrl(const QUrl &url)
QFrame(QWidget *parent, Qt::WindowFlags f)
void clear()
T & first()
QList< T >::reference front()
T & last()
QMessageBox::StandardButton question(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
QObject * parent() const const
QChar & front()
bool isEmpty() const const
CaseInsensitive
QueuedConnection
DescendingOrder
bool isNull() const const
QWidget(QWidget *parent, Qt::WindowFlags f)
void update()