swift
updateinfodialog.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 
4 #include "updateinfodialog.h"
5 
6 #include <QDesktopServices>
7 #include <QPushButton>
8 
9 #include "ui_updateinfodialog.h"
10 
11 #include "gui/guiapplication.h"
12 
13 using namespace swift::misc::db;
14 
15 namespace swift::gui::components
16 {
17  CUpdateInfoDialog::CUpdateInfoDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CUpdateInfoDialog)
18  {
19  ui->setupUi(this);
20  ui->bb_UpdateInfolDialog->button(QDialogButtonBox::Ok)->setText(" Download and install ");
21  ui->cb_DontShowAgain->setChecked(!m_setting.get());
22  this->selectionChanged();
23  connect(ui->comp_UpdateInfo, &CUpdateInfoComponent::selectionChanged, this,
24  &CUpdateInfoDialog::selectionChanged);
25  connect(ui->cb_DontShowAgain, &QCheckBox::toggled, this, &CUpdateInfoDialog::onDontShowAgain);
26  }
27 
29 
31  {
32  const bool newVersion = ui->comp_UpdateInfo->isNewPilotClientVersionAvailable();
33  return newVersion;
34  }
35 
37  {
38  const int r = QDialog::exec();
39  if (r != QDialog::Accepted) { return r; }
40  if (!ui->comp_UpdateInfo->isNewPilotClientVersionAvailable()) { return QDialog::Rejected; }
41  const CDistribution distribution = ui->comp_UpdateInfo->getCurrentDistribution();
42  if (!distribution.hasDownloadUrl()) { return QDialog::Rejected; }
43 
44  ui->comp_UpdateInfo->triggerDownload();
45  return r;
46  }
47 
48  bool CUpdateInfoDialog::event(QEvent *event)
49  {
50  if (CGuiApplication::triggerShowHelp(this, event)) { return true; }
51  return QDialog::event(event);
52  }
53 
54  void CUpdateInfoDialog::onDontShowAgain(bool dontShowAgain) { m_setting.setAndSave(!dontShowAgain); }
55 
56  void CUpdateInfoDialog::selectionChanged()
57  {
58  const bool nv = ui->comp_UpdateInfo->isNewPilotClientVersionAvailable();
59  ui->bb_UpdateInfolDialog->button(QDialogButtonBox::Ok)->setVisible(nv);
60  }
61 } // namespace swift::gui::components
static bool triggerShowHelp(const QWidget *widget, QEvent *event)
Static version used with dialogs.
void selectionChanged()
New platfrom or channel.
bool isNewVersionAvailable() const
A new version existing?
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.
Definition: valuecache.h:417
T get() const
Get a copy of the current value.
Definition: valuecache.h:408
Distributions for channel.
Definition: distribution.h:27
bool hasDownloadUrl() const
Has a download URL?
High level reusable GUI components.
Definition: aboutdialog.cpp:13