]> git.sven.stormbind.net Git - sven/vym.git/blob - downloadagent.h
929daffde3a968ba27765979c0653e2ff859d70b
[sven/vym.git] / downloadagent.h
1 #include <QCoreApplication>
2 #include <QFile>
3 #include <QFileInfo>
4 #include <QList>
5 #include <QNetworkAccessManager>
6 #include <QNetworkRequest>
7 #include <QNetworkReply>
8 #include <QSslError>
9 #include <QStringList>
10 #include <QTemporaryFile>
11 #include <QTimer>
12 #include <QUrl>
13
14 #include <stdio.h>
15
16 QT_BEGIN_NAMESPACE
17 class QSslError;
18 QT_END_NAMESPACE
19
20 QT_USE_NAMESPACE
21
22 class VymModel;
23
24 class DownloadAgent: public QObject
25 {
26     Q_OBJECT
27     QNetworkAccessManager agent;
28     QList<QNetworkReply *> currentDownloads;
29
30 public:
31     DownloadAgent(const QUrl &u);
32     QString getDestination ();
33     void setFinishedAction (VymModel *m, const QString &script);
34     QString getFinishedScript();
35     uint getFinishedScriptModelID();
36     void setUserAgent(const QString &s);
37     bool  isSuccess();
38     QString getResultMessage();
39     void doDownload(const QUrl &url);
40     bool saveToDisk(const QString &filename, const QString &data);
41
42 public slots:
43     void execute();
44     void requestFinished(QNetworkReply *reply);
45     void sslErrors(const QList<QSslError> &errors);
46
47 signals:
48     void downloadFinished();
49
50 private:
51     QTemporaryFile tmpFile;
52     QByteArray userAgent;
53     QUrl url;
54
55     bool success;
56     QString resultMessage;
57
58     QString finishedScript;
59     uint finishedScriptModelID;
60 };
61