RabbitCommon v2.2.6
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#include <QStateMachine>
15#include <QUrl>
16#include <QButtonGroup>
17#include <QCommandLineParser>
18#include "rabbitcommon_export.h"
19
20#include "Download.h"
21
22namespace Ui {
23class CFrmUpdater;
24}
25
69class RABBITCOMMON_EXPORT CFrmUpdater : public QWidget
70{
71 Q_OBJECT
72
73public:
79 explicit CFrmUpdater(QVector<QUrl> urls = QVector<QUrl>(), QWidget *parent = nullptr);
80 virtual ~CFrmUpdater() override;
81
82 int SetVersion(const QString &szVersion);
89 int SetTitle(QImage icon = QImage(), const QString &szTitle = QString());
90
95 Q_DECL_DEPRECATED
96 int GenerateUpdateXml();
97 Q_DECL_DEPRECATED
98 int GenerateUpdateXml(QCommandLineParser &parser);
104 int GenerateUpdateJson();
112 int GenerateUpdateJson(QCommandLineParser &parser);
113
119 int SetInstallAutoStartup(bool bAutoStart = true);
120
121protected Q_SLOTS:
122 // [Add the slot functions of RabbitCommon::CDownload]
123 void slotDownloadError(int nErr, const QString szError);
124 void slotDownloadFileFinished(const QString szFile);
125 void slotDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
126 // [Add the slot functions of RabbitCommon::CDownload]
127
128 void slotButtonClickd(int id);
129 void slotCheck();
130 void slotDownloadFile();
131 virtual void slotCheckConfigFile();
132 void slotDownloadSetupFile();
133 void slotUpdate();
134 void slotStateFinished();
135
136 void on_pbOK_clicked();
137 void on_pbClose_clicked();
138 void slotShowWindow(QSystemTrayIcon::ActivationReason reason);
139
140Q_SIGNALS:
141 void sigError();
142 void sigFinished();
143 void sigDownLoadRedire();
144
145private:
146 CFrmUpdater(QWidget *parent);
147 int CompareVersion(const QString &newVersion, const QString &currentVersion);
148 int InitStateMachine();
149 bool IsDownLoad();
150 int CheckRedirectConfigFile();
151 int CheckUpdateConfigFile();
152 bool CheckPrompt(const QString &szVersion);
153 QString InstallScript(const QString szDownLoadFile,
154 const QString szApplicationName);
155
156private:
157 Ui::CFrmUpdater *ui;
158 bool m_InstallAutoStartupType;
159
160 QSystemTrayIcon m_TrayIcon;
161
162 QButtonGroup m_ButtonGroup;
163
164 QString m_szCurrentVersion;
165
166 QFile m_DownloadFile;
167 bool m_bDownload;
168 QVector<QUrl> m_Urls;
169 // [Instantiate the object of RabbitCommon::CDownload]
170 QSharedPointer<RabbitCommon::CDownload> m_Download;
171 // [Instantiate the object of RabbitCommon::CDownload]
172
173 QStateMachine m_StateMachine;
174 QState *m_pStateDownloadSetupFile;
175
176 enum class CONFIG_TYPE{
177 VERSION,
178 FILE,
179 VERSION_FILE
180 };
181
183 QString szVerion;
184 QString szMinUpdateVersion;
185 QString szInfomation;
186 QString szTime;
187 bool bForce;
188 QString szHome;
189 };
190
191 struct CONFIG_FILE {
192 QString szSystem;
193 QString szSystemMinVersion;
194 QString szArchitecture;
195 QString szArchitectureMinVersion;
196 QString szFileName;
197 QVector<QUrl> urls;
198 QString szMd5sum;
199 };
200
202 QString szVersion;
203 QString szMinUpdateVersion;
204 QVector<CONFIG_FILE> files;
205 };
206
207 struct CONFIG_INFO {
208 CONFIG_VERSION version;
209 QVector<CONFIG_FILE> files;
210 } m_Info;
211
212 CONFIG_FILE m_ConfigFile;
213
214 int GetRedirectFromFile(const QString& szFile, QVector<CONFIG_REDIRECT> &conf);
215 int GetConfigFromFile(const QString& szFile, CONFIG_INFO &conf);
216 int GetConfigFromCommandLine(/*[in]*/QCommandLineParser &parser,
217 /*[out]*/QString &szFile,
218 /*[out]*/CONFIG_INFO &info,
219 /*[out]*/CONFIG_TYPE &type);
220 int GenerateUpdateXmlFile(const QString &szFile,
221 const CONFIG_INFO &info,
222 CONFIG_TYPE &type);
223 int GenerateJsonFile(const QString &szFile,
224 const CONFIG_INFO &info,
225 CONFIG_TYPE type);
226
227 // QWidget interface
228protected:
229 virtual void showEvent(QShowEvent *event) override;
230private Q_SLOTS:
231 void on_cbPrompt_clicked(bool checked);
232 void on_cbHomePage_clicked(bool checked);
233
234#if defined(HAVE_TEST)
235 friend class CUnitTests;
236 friend class CTestGenerateJsonFile;
237 friend class CTestGenerateDefaultJsonFile;
238 friend class CTestUpdater;
239#endif
240};
241
242#endif // RABBITCOMMON_FRMUPDATER_H
Updater.
Definition FrmUpdater.h:70