Mercurial > trustbridge
annotate ui/downloader.h @ 10:fe39d93f1261
Start on Downloader component
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Thu, 13 Feb 2014 14:43:15 +0000 |
parents | |
children | 95e1b6edf2fc |
rev | line source |
---|---|
10
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
1 #ifndef DOWNLOADER_H |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
2 #define DOWNLOADER_H |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
3 /** |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
4 * @file downloader.h |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
5 * @brief High level API to download necessary data. |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
6 * |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
7 */ |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
8 |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
9 #include <QThread> |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
10 #include <QString> |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
11 #include <QByteArray> |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
12 |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
13 class Downloader: public QThread |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
14 { |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
15 Q_OBJECT |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
16 |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
17 public: |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
18 /** |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
19 * @brief Construct a downloader to download data from url |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
20 * |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
21 * Takes the builtin certificate for https verification. |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
22 * |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
23 * @param[in] parent the parent object. |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
24 * @param[in] url the Url to download data from. |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
25 */ |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
26 Downloader(QObject* parent, const QString& url); |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
27 |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
28 /** |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
29 * @brief Construct a downloader with a specific certificate |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
30 * |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
31 * @param[in] parent the parent object. |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
32 * @param[in] url the Url to download data from |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
33 * @param[in] certificate to accept https connection from |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
34 */ |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
35 Downloader(QObject* parent, const QString& url, |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
36 const QByteArray& certificate); |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
37 |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
38 enum Status { |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
39 NewSoftwareAvailable, // A Software Update has been downloaded |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
40 NewListAvailable, // A certificate list has been downloaded |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
41 UpToDate, // Nothing changed |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
42 Error // An error happened |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
43 }; |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
44 |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
45 enum ErrorCode { |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
46 NoConnection, |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
47 InvalidCertificate, |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
48 ConnectionLost, |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
49 Timeout, |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
50 Unknown |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
51 }; |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
52 |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
53 /** |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
54 * @brief Construct a downloader with a specific certificate |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
55 * |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
56 * @param[in] url the Url to download data from |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
57 * @param[in] certificate to accept https connection from |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
58 */ |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
59 QString getDownloadedFileName(); |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
60 |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
61 protected: |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
62 void run(); |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
63 |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
64 private: |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
65 QString mUrl; |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
66 QByteArray mCert; |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
67 |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
68 Q_SIGNALS: |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
69 /** |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
70 * @brief Some progress has been made. |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
71 * |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
72 * @param[out] message: A message to show. Can be empty. |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
73 * @param[out] current: Value of current progress. |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
74 * @param[out] total: Total value of possible progress |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
75 */ |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
76 void progress(const QString &message, int current, int total); |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
77 |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
78 /** |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
79 * @brief An error happened |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
80 * |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
81 * @param[out] message: A message to show. Can be empty. |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
82 * @param[out] errorCode: ErrorCode of this error. |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
83 * @param[out] total: Total value of possible progress. |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
84 */ |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
85 void error(const QString &message, ErrorCode error); |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
86 }; |
fe39d93f1261
Start on Downloader component
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
87 #endif |