ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvUpdateDlg.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "ecvUpdateDlg.h"
9 
10 #include <QDebug>
11 
12 #include "CommonSettings.h"
13 #include "MainWindow.h"
14 #include "ui_UpdateDialog.h"
15 
16 // for application update
18 
19 //==============================================================================
20 // ecvUpdateDlg::ecvUpdateDlg
21 //==============================================================================
22 
24  : QDialog(parent, Qt::Tool), m_ui(new Ui::UpdateDialog) {
25  m_ui->setupUi(this);
26 
27  /* QSimpleUpdater is single-instance */
28  m_updater = QSimpleUpdater::getInstance();
29 
30  /* Check for updates when the "Check For Updates" button is clicked */
31  connect(m_updater, SIGNAL(checkingFinished(QString)), this,
32  SLOT(updateChangelog(QString)));
33  connect(m_updater, SIGNAL(appcastDownloaded(QString, QByteArray)), this,
34  SLOT(displayAppcast(QString, QByteArray)));
35 
36  /* React to button clicks */
37  connect(m_ui->resetButton, SIGNAL(clicked()), this, SLOT(resetFields()));
38  connect(m_ui->closeButton, SIGNAL(clicked()), this, SLOT(close()));
39  connect(m_ui->checkButton, SIGNAL(clicked()), this,
40  SLOT(checkForUpdates()));
41 
42  /* reset the UI state */
43  resetFields();
44 }
45 
46 //==============================================================================
47 // ecvUpdateDlg::~ecvUpdateDlg
48 //==============================================================================
49 
50 ecvUpdateDlg::~ecvUpdateDlg() { delete m_ui; }
51 
52 //==============================================================================
53 // ecvUpdateDlg::checkForUpdates
54 //==============================================================================
55 
57  m_ui->installedVersion->setText(
58  QString(Settings::APP_VERSION).replace("v", ""));
59  m_ui->customAppcast->setChecked(false);
60  m_ui->enableDownloader->setChecked(true);
61  m_ui->showAllNotifcations->setChecked(false);
62  m_ui->showUpdateNotifications->setChecked(true);
63  m_ui->mandatoryUpdate->setChecked(false);
64 }
65 
66 //==============================================================================
67 // ecvUpdateDlg::checkForUpdates
68 //==============================================================================
69 
71  /* Get settings from the UI */
72  QString version = m_ui->installedVersion->text();
73  bool customAppcast = m_ui->customAppcast->isChecked();
74  bool downloaderEnabled = m_ui->enableDownloader->isChecked();
75  bool notifyOnFinish = m_ui->showAllNotifcations->isChecked();
76  bool notifyOnUpdate = m_ui->showUpdateNotifications->isChecked();
77  bool mandatoryUpdate = m_ui->mandatoryUpdate->isChecked();
78 
79  /* Apply the settings */
81  m_updater->setNotifyOnFinish(Settings::UPDATE_RUL, notifyOnFinish);
82  m_updater->setNotifyOnUpdate(Settings::UPDATE_RUL, notifyOnUpdate);
83  m_updater->setUseCustomAppcast(Settings::UPDATE_RUL, customAppcast);
84  m_updater->setDownloaderEnabled(Settings::UPDATE_RUL, downloaderEnabled);
85  m_updater->setMandatoryUpdate(Settings::UPDATE_RUL, mandatoryUpdate);
86 
87  /* Check for updates */
89 }
90 
91 //==============================================================================
92 // ecvUpdateDlg::updateChangelog
93 //==============================================================================
94 
95 void ecvUpdateDlg::updateChangelog(const QString& url) {
96  if (url == Settings::UPDATE_RUL)
97  m_ui->changelogText->setText(m_updater->getChangelog(url));
98 }
99 
100 //==============================================================================
101 // ecvUpdateDlg::displayAppcast
102 //==============================================================================
103 
104 void ecvUpdateDlg::displayAppcast(const QString& url, const QByteArray& reply) {
105  if (url == Settings::UPDATE_RUL) {
106  QString text =
107  "This is the downloaded appcast: <p><pre>" +
108  QString::fromUtf8(reply) +
109  "</pre></p><p> If you need to store more information on the "
110  "appcast (or use another format), just use the "
111  "<b>QSimpleUpdater::setCustomAppcast()</b> function. "
112  "It allows your application to interpret the appcast "
113  "using your code and not QSU's code.</p>";
114 
115  m_ui->changelogText->setText(text);
116  }
117 }
std::string version
void setModuleVersion(const QString &url, const QString &version)
void setNotifyOnUpdate(const QString &url, const bool notify)
void setNotifyOnFinish(const QString &url, const bool notify)
QString getChangelog(const QString &url) const
void checkForUpdates(const QString &url)
void setMandatoryUpdate(const QString &url, const bool mandatory_update)
void setDownloaderEnabled(const QString &url, const bool enabled)
void setUseCustomAppcast(const QString &url, const bool customAppcast)
static QSimpleUpdater * getInstance()
void displayAppcast(const QString &url, const QByteArray &reply)
ecvUpdateDlg(QWidget *parent=nullptr)
void updateChangelog(const QString &url)
void checkForUpdates()
void resetFields()
static const QString UPDATE_RUL
static const QString APP_VERSION