view ui/downloader.h @ 964:706405a2f3e8

(issue89) Add help icon to help button
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 28 Aug 2014 12:55:19 +0200
parents eaed02defe6a
children 2949f1842955
line wrap: on
line source
/* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU GPL (v>=2)
 * and comes with ABSOLUTELY NO WARRANTY!
 * See LICENSE.txt for details.
 */
#ifndef DOWNLOADER_H
#define DOWNLOADER_H
/**
 * @file downloader.h
 * @brief High level API to download necessary data.
 *
 */

#include <QThread>
#include <QDateTime>
#include <QString>
#include <QByteArray>

#include "sslconnection.h"

class Downloader: public QThread
{
    Q_OBJECT

public:
    /**
     * @brief Construct a downloader with a specific certificate
     *
     * The downloader will check the last-modified date of the
     * certificate list / sw on the server at the specified url
     * and download those accordingly. If newestSW or newestList is
     * are valid datetimes only files modified after the respective date
     * are downloaded.
     *
     * Downloaded files are placed in QStandardPaths::DataLocation
     *
     * @param[in] parent the parent object.
     * @param[in] url the Url to download data from
     * @param[in] certificate optional certificate to validate https connection
     * @param[in] newestSW datetime after which software should be downloaded
     * @param[in] newestList datetime after which the list should be downloaded
     * @param[in] resourceSW the path where the software is to be found
     * @param[in] resourceList the path where the list is to be found
     */
    Downloader(QObject* parent, const QString& url,
               const QByteArray& certificate = QByteArray(),
               const QDateTime& newestSW = QDateTime(),
               const QDateTime& newestList = QDateTime(),
               const QString& resourceSW = QString(),
               const QString& resourceList = QString(),
               bool downloadSW = true);

    ~Downloader();

    /**
     * @brief get the directory where the downloader saves data
     *
     * If the directory does not exist this function ensures that it
     * is created.
     *
     * @returns The directory in which downloaded files are placed.
     **/
    QString getDataDirectory();

    /**
     * @brief get the current error state
     *
     * @returns The current error state.
     **/
    SSLConnection::ErrorCode getErrorState();

protected:
    void run();

private:
    QDateTime mLastModSW;
    QDateTime mLastModList;

    QString mResourceSW;
    QString mResourceList;

    bool mDownloadSW;

    SSLConnection *mSSLConnection;

Q_SIGNALS:
    /**
     * @brief software update is available
     */
    void newSoftwareAvailable(const QString &fileName,
            const QDateTime &lastMod);

    /**
     * @brief new certificate list available
     */
    void newListAvailable(const QString &fileName, const QDateTime &lastMod);

    /**
     * @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.
     */
    void error(const QString &message, SSLConnection::ErrorCode error);

    /**
     * @brief Found the last modified date for software.
     *
     * @param[out] date The last modified date.
     */
    void lastModifiedDate(const QDateTime &date);
};
#endif

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