6 #include <QDesktopServices>
9 #include "ui_updateinfocomponent.h"
20 using namespace swift::config;
21 using namespace swift::core::application;
23 using namespace swift::misc::db;
24 using namespace swift::misc::network;
28 CUpdateInfoComponent::CUpdateInfoComponent(QWidget *parent) : QFrame(parent), ui(new Ui::
CUpdateInfoComponent)
31 Q_ASSERT_X(
sGui, Q_FUNC_INFO,
"Need sGui");
34 Qt::QueuedConnection);
35 connect(ui->pb_CheckForUpdates, &QPushButton::pressed,
this, &CUpdateInfoComponent::requestLoadOfSetup,
36 Qt::QueuedConnection);
37 connect(ui->pb_DownloadXSwiftBus, &QPushButton::pressed,
this, &CUpdateInfoComponent::downloadXSwiftBusDialog,
38 Qt::QueuedConnection);
39 connect(ui->pb_DownloadInstaller, &QPushButton::pressed,
this, &CUpdateInfoComponent::downloadInstallerDialog,
40 Qt::QueuedConnection);
43 if (!m_updateInfo.
get().isEmpty()) { this->changedUpdateInfo(); }
51 const CPlatform p = this->getSelectedOrDefaultPlatform();
52 const CDistribution d = this->getSelectedOrDefaultDistribution();
60 const QStringList settings = m_updateSettings.
get();
61 Q_ASSERT_X(settings.size() == 2, Q_FUNC_INFO,
"wrong setting");
62 const QString channel = settings.front();
63 if (channel.isEmpty()) {
return false; }
67 const QVersionNumber vCurrentChannelPlatform =
69 const QVersionNumber vCurrent = CBuildConfig::getVersion();
70 if (vCurrentChannelPlatform.isNull()) {
return false; }
71 return (vCurrentChannelPlatform > vCurrent);
76 QPointer<CUpdateInfoComponent> myself(
this);
78 if (!myself) {
return; }
79 ui->pb_DownloadInstaller->click();
83 void CUpdateInfoComponent::requestLoadOfSetup()
89 void CUpdateInfoComponent::changedUpdateInfo()
91 ui->lbl_CurrentVersionDisplay->setText(CBuildConfig::getVersionString());
94 const QStringList settings = m_updateSettings.
get();
95 Q_ASSERT_X(settings.size() == 2, Q_FUNC_INFO,
"Settings");
97 const CPlatformSet platforms = updateInfo.getArtifactsPilotClient().getPlatforms();
98 CDistributionList distributions = updateInfo.getArtifactsPilotClient().getDistributions();
102 ui->cb_Platforms->disconnect();
103 ui->cb_Platforms->clear();
104 for (
const CPlatform &platform : platforms)
106 ui->cb_Platforms->insertItem(i++,
CIcon(platform.toIcon()).
toPixmap(), platform.getPlatformName());
108 if (platforms.contains(settings.last())) { ui->cb_Platforms->setCurrentText(settings.last()); }
109 else if (platforms.contains(CPlatform::currentPlatform().getPlatformName()))
111 ui->cb_Platforms->setCurrentText(CPlatform::currentPlatform().getPlatformName());
115 ui->cb_Channels->disconnect();
116 ui->cb_Channels->clear();
119 ui->cb_Channels->insertItem(i++,
CIcon(distribution.getRestrictionIcon()).
toPixmap(),
120 distribution.getChannel());
122 if (distributions.containsChannel(settings.front())) { ui->cb_Channels->setCurrentText(settings.front()); }
124 this->uiSelectionChanged();
125 connect(ui->cb_Platforms, &QComboBox::currentTextChanged,
this, &CUpdateInfoComponent::platformChanged,
126 Qt::QueuedConnection);
127 connect(ui->cb_Channels, &QComboBox::currentTextChanged,
this, &CUpdateInfoComponent::channelChanged,
128 Qt::QueuedConnection);
134 void CUpdateInfoComponent::downloadXSwiftBusDialog()
136 const QString currentXsb = ui->cb_ArtifactsXsb->currentText();
137 const QString currentSwift = ui->cb_ArtifactsPilotClient->currentText();
139 if (!
stringCompare(currentXsb, currentSwift, Qt::CaseInsensitive))
141 const QString msg = QStringLiteral(
"xswiftbus '%1' does NOT match swift version, download anyway?")
142 .arg(currentXsb, currentSwift);
143 const QMessageBox::StandardButton reply = QMessageBox::question(
this, QStringLiteral(
"Download xswiftbus"),
144 msg, QMessageBox::Yes | QMessageBox::No);
145 if (reply != QMessageBox::Yes) {
return; }
148 if (!m_installXSwiftBusDialog)
150 m_installXSwiftBusDialog.reset(
new CInstallXSwiftBusDialog(
this));
151 m_installXSwiftBusDialog->setModal(
true);
154 m_installXSwiftBusDialog->setDefaultDownloadName(currentXsb);
155 m_installXSwiftBusDialog->show();
158 void CUpdateInfoComponent::downloadInstallerDialog()
161 const QString currentVersion = ui->cb_ArtifactsPilotClient->currentText();
162 const QString platform = ui->cb_Platforms->currentText();
163 if (!CPlatform::isCurrentPlatform(platform))
165 const QMessageBox::StandardButton ret =
166 QMessageBox::warning(
this,
"Download installer",
167 QStringLiteral(
"The platform '%1' does not match your current platform '%2'.\n"
168 "Do you want to continue?")
169 .arg(platform, CPlatform::currentPlatform().getPlatformName()),
170 QMessageBox::Yes | QMessageBox::No);
171 if (ret != QMessageBox::Yes) {
return; }
176 update.getArtifactsPilotClient().findByMatchingPlatform(platform).findFirstByVersionOrDefault(
179 if (!m_downloadDialog)
181 m_downloadDialog.reset(
new CDownloadDialog(
this));
182 m_downloadDialog->setModal(
true);
189 m_downloadDialog->setMode(CDownloadComponent::SwiftInstaller);
190 m_downloadDialog->setDownloadFile(artifact.
asRemoteFile());
191 m_downloadDialog->showAndStartDownloading();
195 void CUpdateInfoComponent::saveSettings()
197 const QString channel = this->getSelectedOrDefaultDistribution().
getChannel();
198 const QString platform = this->getSelectedOrDefaultPlatform().
getPlatformName();
199 const QStringList settings({ channel, platform });
204 void CUpdateInfoComponent::channelChanged() { this->uiSelectionChanged(); }
206 void CUpdateInfoComponent::platformChanged() { this->uiSelectionChanged(); }
208 void CUpdateInfoComponent::uiSelectionChanged()
210 const CDistribution selectedDistribution(this->getSelectedOrDefaultDistribution());
211 const CPlatform selectedPlatform(this->getSelectedOrDefaultPlatform());
216 selectedDistribution, selectedPlatform,
true);
219 selectedDistribution, selectedPlatform,
true);
222 const QStringList sortedPilotClientVersions = artifactsPilotClient.
getSortedVersions();
223 ui->cb_ArtifactsPilotClient->clear();
224 ui->cb_ArtifactsPilotClient->insertItems(0, sortedPilotClientVersions);
225 ui->pb_DownloadInstaller->setEnabled(!artifactsPilotClient.
isEmpty());
228 ui->cb_ArtifactsXsb->clear();
229 ui->cb_ArtifactsXsb->insertItems(0, sortedXsbVersions);
230 ui->pb_DownloadXSwiftBus->setEnabled(!artifactsXsb.
isEmpty());
233 this->saveSettings();
237 ui->lbl_StatusInfo->setText(newer ?
"New version available" :
"Nothing new");
238 ui->lbl_StatusInfo->setStyleSheet(newer ?
"background-color: green; color: white;" :
239 "background-color: red; color: white;");
246 const CPlatform &CUpdateInfoComponent::getSelectedOrDefaultPlatform()
const
248 const QStringList settings = m_updateSettings.
get();
249 QString p = ui->cb_Platforms->currentText();
250 if (p.isEmpty()) { p = settings.last(); }
251 if (p.isEmpty()) { p = CPlatform::currentPlatform().getPlatformName(); }
252 return CPlatform::stringToPlatformObject(p);
255 CDistribution CUpdateInfoComponent::getSelectedOrDefaultDistribution()
const
257 const QStringList settings = m_updateSettings.
get();
258 QString c = ui->cb_Channels->currentText();
259 if (c.isEmpty()) { c = settings.first(); }
261 return c.isEmpty() ? updateInfo.getDistributions().getMostStableOrDefault() :
262 updateInfo.getDistributions().findFirstByChannelOrDefault(c);
void updateInfoAvailable(bool success)
Update info available (cache, web load)
bool isShuttingDown() const
Is application shutting down?
void reloadUpdateInfo()
Reload update info.
Update info (distributions, artifacts etc.)
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 triggerDownload()
Trigger download.
void newerPilotClientAvailable(const swift::misc::db::CArtifact &latestPilotClient)
A newer pilot client is available.
virtual ~CUpdateInfoComponent()
Dtor.
CStatusMessage setAndSave(const T &value, qint64 timestamp=0)
Write and save in the same step. Must be called from the thread in which the owner lives.
T get() const
Get a copy of the current value.
void inputSignal()
Received input signal, or manually trigger.
Value object for icons. An icon is stored in the global icon repository and identified by its index....
QPixmap toPixmap() const
Corresponding pixmap.
Class for emitting a log message.
static void preformatted(const CStatusMessage &statusMessage)
Sends a verbatim, preformatted message to the log.
bool isEmpty() const
Synonym for empty.
Streamable status message, e.g.
Artifacts ("our software" products)
network::CRemoteFile asRemoteFile() const
Turn into remote file.
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.
CArtifactList findWithUnrestrictedDistributions() const
Find artifacts with public (unrestricted) distributions.
QStringList getSortedVersions() const
All unique versions.
Distributions for channel.
const QString & getChannel() const
Version channel (Alpha, Beta, Stable ..)
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.
const CDistributionList & getDistributions() const
Distributions (all)
const CArtifactList & getArtifactsPilotClient() const
Artifacts (pilot client)
bool isLoadedFromDb() const
Loaded from DB.
const CUrl & getUrl() const
Get URL.
bool isHavingHtmlSuffix() const
Likely a HTM file?
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
High level reusable GUI components.
Free functions in swift::misc.
SWIFT_MISC_EXPORT bool stringCompare(const QString &c1, const QString &c2, Qt::CaseSensitivity cs)
String compare.
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...