ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Window.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 "Window.h"
9 #include "ui_Window.h"
10 
11 #include <QDebug>
12 #include <QSimpleUpdater.h>
13 
14 //==============================================================================
15 // Define the URL of the Update Definitions file
16 //==============================================================================
17 
18 static const QString DEFS_URL = "https://raw.githubusercontent.com/"
19  "alex-spataru/QSimpleUpdater/master/tutorial/"
20  "definitions/updates.json";
21 
22 //==============================================================================
23 // Window::Window
24 //==============================================================================
25 
26 Window::Window(QWidget *parent)
27  : QMainWindow(parent)
28 {
29  m_ui = new Ui::Window;
30  m_ui->setupUi(this);
31 
32  setWindowTitle(qApp->applicationName());
33 
34  /* QSimpleUpdater is single-instance */
35  m_updater = QSimpleUpdater::getInstance();
36 
37  /* Check for updates when the "Check For Updates" button is clicked */
38  connect(m_updater, SIGNAL(checkingFinished(QString)), this, SLOT(updateChangelog(QString)));
39  connect(m_updater, SIGNAL(appcastDownloaded(QString, QByteArray)), this, SLOT(displayAppcast(QString, QByteArray)));
40 
41  /* React to button clicks */
42  connect(m_ui->resetButton, SIGNAL(clicked()), this, SLOT(resetFields()));
43  connect(m_ui->closeButton, SIGNAL(clicked()), this, SLOT(close()));
44  connect(m_ui->checkButton, SIGNAL(clicked()), this, SLOT(checkForUpdates()));
45 
46  /* Resize the dialog to fit */
47  setMinimumSize(minimumSizeHint());
48  resize(minimumSizeHint());
49 
50  /* Reset the UI state */
51  resetFields();
52 }
53 
54 //==============================================================================
55 // Window::~Window
56 //==============================================================================
57 
59 {
60  delete m_ui;
61 }
62 
63 //==============================================================================
64 // Window::checkForUpdates
65 //==============================================================================
66 
68 {
69  m_ui->installedVersion->setText("0.1");
70  m_ui->customAppcast->setChecked(false);
71  m_ui->enableDownloader->setChecked(true);
72  m_ui->showAllNotifcations->setChecked(false);
73  m_ui->showUpdateNotifications->setChecked(true);
74  m_ui->mandatoryUpdate->setChecked(false);
75 }
76 
77 //==============================================================================
78 // Window::checkForUpdates
79 //==============================================================================
80 
82 {
83  /* Get settings from the UI */
84  QString version = m_ui->installedVersion->text();
85  bool customAppcast = m_ui->customAppcast->isChecked();
86  bool downloaderEnabled = m_ui->enableDownloader->isChecked();
87  bool notifyOnFinish = m_ui->showAllNotifcations->isChecked();
88  bool notifyOnUpdate = m_ui->showUpdateNotifications->isChecked();
89  bool mandatoryUpdate = m_ui->mandatoryUpdate->isChecked();
90 
91  /* Apply the settings */
92  m_updater->setModuleVersion(DEFS_URL, version);
93  m_updater->setNotifyOnFinish(DEFS_URL, notifyOnFinish);
94  m_updater->setNotifyOnUpdate(DEFS_URL, notifyOnUpdate);
95  m_updater->setUseCustomAppcast(DEFS_URL, customAppcast);
96  m_updater->setDownloaderEnabled(DEFS_URL, downloaderEnabled);
97  m_updater->setMandatoryUpdate(DEFS_URL, mandatoryUpdate);
98 
99  /* Check for updates */
100  m_updater->checkForUpdates(DEFS_URL);
101 }
102 
103 //==============================================================================
104 // Window::updateChangelog
105 //==============================================================================
106 
107 void Window::updateChangelog(const QString &url)
108 {
109  if (url == DEFS_URL)
110  m_ui->changelogText->setText(m_updater->getChangelog(url));
111 }
112 
113 //==============================================================================
114 // Window::displayAppcast
115 //==============================================================================
116 
117 void Window::displayAppcast(const QString &url, const QByteArray &reply)
118 {
119  if (url == DEFS_URL)
120  {
121  QString text = "This is the downloaded appcast: <p><pre>" + QString::fromUtf8(reply)
122  + "</pre></p><p> If you need to store more information on the "
123  "appcast (or use another format), just use the "
124  "<b>QSimpleUpdater::setCustomAppcast()</b> function. "
125  "It allows your application to interpret the appcast "
126  "using your code and not QSU's code.</p>";
127 
128  m_ui->changelogText->setText(text);
129  }
130 }
std::string version
static const QString DEFS_URL
Definition: Window.cpp:18
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()
struct Window Window
Definition: sqlite3.c:14678
void checkForUpdates()
Definition: Window.cpp:81
~Window()
Definition: Window.cpp:58
void displayAppcast(const QString &url, const QByteArray &reply)
Definition: Window.cpp:117
void resetFields()
Definition: Window.cpp:67
void updateChangelog(const QString &url)
Definition: Window.cpp:107
Window(QWidget *parent=0)
Definition: Window.cpp:26