RabbitCommon v2.3.4
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
31typedef int (*pUpdateCallback)(const QString szFile);
32
76class RABBITCOMMON_EXPORT CFrmUpdater : public QWidget
77{
78 Q_OBJECT
79
80public:
86 explicit CFrmUpdater(QVector<QUrl> urls = QVector<QUrl>(), QWidget *parent = nullptr);
87 virtual ~CFrmUpdater() override;
88
89 int SetVersion(const QString &szVersion);
96 int SetTitle(QImage icon = QImage(), const QString &szTitle = QString());
97
102 Q_DECL_DEPRECATED
103 int GenerateUpdateXml();
104 Q_DECL_DEPRECATED
105 int GenerateUpdateXml(QCommandLineParser &parser);
111 int GenerateUpdateJson();
119 int GenerateUpdateJson(QCommandLineParser &parser);
120
126 int SetInstallAutoStartup(bool bAutoStart = true);
127
132 int SetUpdateCallback(pUpdateCallback pCb);
133
134protected Q_SLOTS:
135 // [Add the slot functions of RabbitCommon::CDownload]
136 void slotDownloadError(int nErr, const QString szError);
137 void slotDownloadFileFinished(const QString szFile);
138 void slotDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
139 // [Add the slot functions of RabbitCommon::CDownload]
140
141 void slotButtonClickd(int id);
142 void slotCheck();
143 void slotDownloadFile();
144 virtual void slotCheckConfigFile();
145 void slotDownloadSetupFile();
146 void slotUpdate();
147 void slotStateFinished();
148
149 void on_pbOK_clicked();
150 void on_pbClose_clicked();
151 void slotShowWindow(QSystemTrayIcon::ActivationReason reason);
152
153Q_SIGNALS:
154 void sigError();
155 void sigFinished();
156 void sigDownLoadRedire();
157
158private:
159 CFrmUpdater(QWidget *parent);
160 int CompareVersion(const QString &newVersion, const QString &currentVersion);
161 int InitStateMachine();
162 bool IsDownLoad();
163 int CheckRedirectConfigFile();
164 int CheckUpdateConfigFile();
165 bool CheckPrompt(const QString &szVersion);
166 QString InstallScript(const QString szDownLoadFile,
167 const QString szApplicationName);
168 Q_INVOKABLE int Execute(const QString szFile);
169
170private:
171 Ui::CFrmUpdater *ui;
172 bool m_InstallAutoStartupType;
173
174 QSystemTrayIcon m_TrayIcon;
175
176 QButtonGroup m_ButtonGroup;
177
178 QString m_szCurrentVersion;
179
180 QFile m_DownloadFile;
181 bool m_bDownload;
182 QVector<QUrl> m_Urls;
183 // [Instantiate the object of RabbitCommon::CDownload]
184 QSharedPointer<RabbitCommon::CDownload> m_Download;
185 // [Instantiate the object of RabbitCommon::CDownload]
186
187 QStateMachine* m_StateMachine;
188 QState *m_pStateDownloadSetupFile;
189
190 enum class CONFIG_TYPE{
191 VERSION,
192 FILE,
193 VERSION_FILE
194 };
195
197 QString szVerion;
198 QString szMinUpdateVersion;
199 QString szInfomation;
200 QString szTime;
201 bool bForce;
202 QString szHome;
203 };
204
205 struct CONFIG_FILE {
206 QString szSystem;
207 QString szSystemMinVersion;
208 QString szArchitecture;
209 QString szArchitectureMinVersion;
210 QString szFileName;
211 QVector<QUrl> urls;
212 QString szMd5sum;
213 };
214
216 QString szVersion;
217 QString szMinUpdateVersion;
218 QVector<CONFIG_FILE> files;
219 };
220
221 struct CONFIG_INFO {
222 CONFIG_VERSION version;
223 QVector<CONFIG_FILE> files;
224 } m_Info;
225
226 CONFIG_FILE m_ConfigFile;
227
228 int GetRedirectFromFile(const QString& szFile, QVector<CONFIG_REDIRECT> &conf);
229 int GetConfigFromFile(const QString& szFile, CONFIG_INFO &conf);
230 int GetConfigFromCommandLine(/*[in]*/QCommandLineParser &parser,
231 /*[out]*/QString &szFile,
232 /*[out]*/CONFIG_INFO &info,
233 /*[out]*/CONFIG_TYPE &type);
234 int GenerateUpdateXmlFile(const QString &szFile,
235 const CONFIG_INFO &info,
236 CONFIG_TYPE &type);
237 int GenerateJsonFile(const QString &szFile,
238 const CONFIG_INFO &info,
239 CONFIG_TYPE type);
240
241 pUpdateCallback m_pcbUpdate;
242
243 // QWidget interface
244protected:
245 virtual void showEvent(QShowEvent *event) override;
246private Q_SLOTS:
247 void on_cbPrompt_clicked(bool checked);
248 void on_cbHomePage_clicked(bool checked);
249
250#if defined(HAVE_TEST)
251 friend class CUnitTests;
252 friend class CTestGenerateJsonFile;
253 friend class CTestGenerateDefaultJsonFile;
254 friend class CTestUpdater;
255#endif
256};
257
258#endif // RABBITCOMMON_FRMUPDATER_H
Updater.
Definition FrmUpdater.h:77