aheinecke@10: #ifndef DOWNLOADER_H aheinecke@10: #define DOWNLOADER_H aheinecke@10: /** aheinecke@10: * @file downloader.h aheinecke@10: * @brief High level API to download necessary data. aheinecke@10: * aheinecke@10: */ aheinecke@10: aheinecke@10: #include aheinecke@10: #include aheinecke@10: #include aheinecke@10: aheinecke@10: class Downloader: public QThread aheinecke@10: { aheinecke@10: Q_OBJECT aheinecke@10: aheinecke@10: public: aheinecke@10: /** aheinecke@10: * @brief Construct a downloader to download data from url aheinecke@10: * aheinecke@10: * Takes the builtin certificate for https verification. aheinecke@10: * aheinecke@10: * @param[in] parent the parent object. aheinecke@10: * @param[in] url the Url to download data from. aheinecke@10: */ aheinecke@10: Downloader(QObject* parent, const QString& url); aheinecke@10: aheinecke@10: /** aheinecke@10: * @brief Construct a downloader with a specific certificate aheinecke@10: * aheinecke@10: * @param[in] parent the parent object. aheinecke@10: * @param[in] url the Url to download data from aheinecke@10: * @param[in] certificate to accept https connection from aheinecke@10: */ aheinecke@10: Downloader(QObject* parent, const QString& url, aheinecke@10: const QByteArray& certificate); aheinecke@10: aheinecke@10: enum Status { aheinecke@10: NewSoftwareAvailable, // A Software Update has been downloaded aheinecke@10: NewListAvailable, // A certificate list has been downloaded aheinecke@10: UpToDate, // Nothing changed aheinecke@10: Error // An error happened aheinecke@10: }; aheinecke@10: aheinecke@10: enum ErrorCode { aheinecke@10: NoConnection, aheinecke@10: InvalidCertificate, aheinecke@10: ConnectionLost, aheinecke@10: Timeout, aheinecke@10: Unknown aheinecke@10: }; aheinecke@10: aheinecke@10: /** aheinecke@10: * @brief Construct a downloader with a specific certificate aheinecke@10: * aheinecke@10: * @param[in] url the Url to download data from aheinecke@10: * @param[in] certificate to accept https connection from aheinecke@10: */ aheinecke@10: QString getDownloadedFileName(); aheinecke@10: aheinecke@10: protected: aheinecke@10: void run(); aheinecke@10: aheinecke@10: private: aheinecke@10: QString mUrl; aheinecke@10: QByteArray mCert; aheinecke@10: aheinecke@10: Q_SIGNALS: aheinecke@10: /** aheinecke@10: * @brief Some progress has been made. aheinecke@10: * aheinecke@10: * @param[out] message: A message to show. Can be empty. aheinecke@10: * @param[out] current: Value of current progress. aheinecke@10: * @param[out] total: Total value of possible progress aheinecke@10: */ aheinecke@10: void progress(const QString &message, int current, int total); aheinecke@10: aheinecke@10: /** aheinecke@10: * @brief An error happened aheinecke@10: * aheinecke@10: * @param[out] message: A message to show. Can be empty. aheinecke@10: * @param[out] errorCode: ErrorCode of this error. aheinecke@10: * @param[out] total: Total value of possible progress. aheinecke@10: */ aheinecke@10: void error(const QString &message, ErrorCode error); aheinecke@10: }; aheinecke@10: #endif