RabbitCommon v2.3.3
Loading...
Searching...
No Matches
FrmUpdater.h
1
6#ifndef RABBITCOMMON_FRMUPDATER_H
7#define RABBITCOMMON_FRMUPDATER_H
8
9#include <QSystemTrayIcon>
10#include <QWidget>
11#include <QFile>
12#include <QPixmap>
13#include <QApplication>
14
15#include <QUrl>
16#include <QButtonGroup>
17#include <QCommandLineParser>
18#include "rabbitcommon_export.h"
19
20namespace RabbitCommon {
21class CDownload;
22}
23
24namespace Ui {
25class CFrmUpdater;
26}
27
28class QStateMachine;
29class QState;
30
74class RABBITCOMMON_EXPORT CFrmUpdater : public QWidget
75{
76 Q_OBJECT
77
78public:
84 explicit CFrmUpdater(QVector<QUrl> urls = QVector<QUrl>(), QWidget *parent = nullptr);
85 virtual ~CFrmUpdater() override;
86
87 int SetVersion(const QString &szVersion);
94 int SetTitle(QImage icon = QImage(), const QString &szTitle = QString());
95
100 Q_DECL_DEPRECATED
101 int GenerateUpdateXml();
102 Q_DECL_DEPRECATED
103 int GenerateUpdateXml(QCommandLineParser &parser);
109 int GenerateUpdateJson();
117 int GenerateUpdateJson(QCommandLineParser &parser);
118
124 int SetInstallAutoStartup(bool bAutoStart = true);
125
126protected Q_SLOTS:
127 // [Add the slot functions of RabbitCommon::CDownload]
128 void slotDownloadError(int nErr, const QString szError);
129 void slotDownloadFileFinished(const QString szFile);
130 void slotDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
131 // [Add the slot functions of RabbitCommon::CDownload]
132
133 void slotButtonClickd(int id);
134 void slotCheck();
135 void slotDownloadFile();
136 virtual void slotCheckConfigFile();
137 void slotDownloadSetupFile();
138 void slotUpdate();
139 void slotStateFinished();
140
141 void on_pbOK_clicked();
142 void on_pbClose_clicked();
143 void slotShowWindow(QSystemTrayIcon::ActivationReason reason);
144
145Q_SIGNALS:
146 void sigError();
147 void sigFinished();
148 void sigDownLoadRedire();
149
150private:
151 CFrmUpdater(QWidget *parent);
152 int CompareVersion(const QString &newVersion, const QString &currentVersion);
153 int InitStateMachine();
154 bool IsDownLoad();
155 int CheckRedirectConfigFile();
156 int CheckUpdateConfigFile();
157 bool CheckPrompt(const QString &szVersion);
158 QString InstallScript(const QString szDownLoadFile,
159 const QString szApplicationName);
160
161private:
162 Ui::CFrmUpdater *ui;
163 bool m_InstallAutoStartupType;
164
165 QSystemTrayIcon m_TrayIcon;
166
167 QButtonGroup m_ButtonGroup;
168
169 QString m_szCurrentVersion;
170
171 QFile m_DownloadFile;
172 bool m_bDownload;
173 QVector<QUrl> m_Urls;
174 // [Instantiate the object of RabbitCommon::CDownload]
175 QSharedPointer<RabbitCommon::CDownload> m_Download;
176 // [Instantiate the object of RabbitCommon::CDownload]
177
178 QStateMachine* m_StateMachine;
179 QState *m_pStateDownloadSetupFile;
180
181 enum class CONFIG_TYPE{
182 VERSION,
183 FILE,
184 VERSION_FILE
185 };
186
188 QString szVerion;
189 QString szMinUpdateVersion;
190 QString szInfomation;
191 QString szTime;
192 bool bForce;
193 QString szHome;
194 };
195
196 struct CONFIG_FILE {
197 QString szSystem;
198 QString szSystemMinVersion;
199 QString szArchitecture;
200 QString szArchitectureMinVersion;
201 QString szFileName;
202 QVector<QUrl> urls;
203 QString szMd5sum;
204 };
205
207 QString szVersion;
208 QString szMinUpdateVersion;
209 QVector<CONFIG_FILE> files;
210 };
211
212 struct CONFIG_INFO {
213 CONFIG_VERSION version;
214 QVector<CONFIG_FILE> files;
215 } m_Info;
216
217 CONFIG_FILE m_ConfigFile;
218
219 int GetRedirectFromFile(const QString& szFile, QVector<CONFIG_REDIRECT> &conf);
220 int GetConfigFromFile(const QString& szFile, CONFIG_INFO &conf);
221 int GetConfigFromCommandLine(/*[in]*/QCommandLineParser &parser,
222 /*[out]*/QString &szFile,
223 /*[out]*/CONFIG_INFO &info,
224 /*[out]*/CONFIG_TYPE &type);
225 int GenerateUpdateXmlFile(const QString &szFile,
226 const CONFIG_INFO &info,
227 CONFIG_TYPE &type);
228 int GenerateJsonFile(const QString &szFile,
229 const CONFIG_INFO &info,
230 CONFIG_TYPE type);
231
232 // QWidget interface
233protected:
234 virtual void showEvent(QShowEvent *event) override;
235private Q_SLOTS:
236 void on_cbPrompt_clicked(bool checked);
237 void on_cbHomePage_clicked(bool checked);
238
239#if defined(HAVE_TEST)
240 friend class CUnitTests;
241 friend class CTestGenerateJsonFile;
242 friend class CTestGenerateDefaultJsonFile;
243 friend class CTestUpdater;
244#endif
245};
246
247#endif // RABBITCOMMON_FRMUPDATER_H
Updater.
Definition FrmUpdater.h:75