diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/downloader.h	Thu Feb 13 14:43:15 2014 +0000
@@ -0,0 +1,87 @@
+#ifndef DOWNLOADER_H
+#define DOWNLOADER_H
+/**
+ * @file downloader.h
+ * @brief High level API to download necessary data.
+ *
+ */
+
+#include <QThread>
+#include <QString>
+#include <QByteArray>
+
+class Downloader: public QThread
+{
+    Q_OBJECT
+
+public:
+    /**
+     * @brief Construct a downloader to download data from url
+     *
+     * Takes the builtin certificate for https verification.
+     *
+     * @param[in] parent the parent object.
+     * @param[in] url the Url to download data from.
+     */
+    Downloader(QObject* parent, const QString& url);
+
+    /**
+     * @brief Construct a downloader with a specific certificate
+     *
+     * @param[in] parent the parent object.
+     * @param[in] url the Url to download data from
+     * @param[in] certificate to accept https connection from
+     */
+    Downloader(QObject* parent, const QString& url,
+               const QByteArray& certificate);
+
+    enum Status {
+        NewSoftwareAvailable, // A Software Update has been downloaded
+        NewListAvailable, // A certificate list has been downloaded
+        UpToDate, // Nothing changed
+        Error // An error happened
+    };
+
+    enum ErrorCode {
+        NoConnection,
+        InvalidCertificate,
+        ConnectionLost,
+        Timeout,
+        Unknown
+    };
+
+    /**
+     * @brief Construct a downloader with a specific certificate
+     *
+     * @param[in] url the Url to download data from
+     * @param[in] certificate to accept https connection from
+     */
+    QString getDownloadedFileName();
+
+protected:
+    void run();
+
+private:
+    QString mUrl;
+    QByteArray mCert;
+
+Q_SIGNALS:
+    /**
+     * @brief Some progress has been made.
+     *
+     * @param[out] message: A message to show. Can be empty.
+     * @param[out] current: Value of current progress.
+     * @param[out] total: Total value of possible progress
+     */
+    void progress(const QString &message, int current, int total);
+
+    /**
+     * @brief An error happened
+     *
+     * @param[out] message: A message to show. Can be empty.
+     * @param[out] errorCode: ErrorCode of this error.
+     * @param[out] total: Total value of possible progress.
+     */
+    void error(const QString &message, ErrorCode error);
+};
+#endif

http://wald.intevation.org/projects/trustbridge/