1 /*
2  * QtDownload.h
3  *
4  *
5  * Copyright 2013 Scott Wilson.
6  *
7  * This file is part of SuperCollider.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23 
24 #include <QObject>
25 #include <QString>
26 #include <QNetworkAccessManager>
27 #include <QNetworkReply>
28 
29 
30 class QtDownload : public QObject {
31     Q_OBJECT
32     Q_PROPERTY(QString source READ source WRITE setSource);
33     Q_PROPERTY(QString destination READ destination WRITE setDestination);
34 
35 public:
36     explicit QtDownload();
37     ~QtDownload();
38 
39     void setSource(const QString& t);
40     void setDestination(const QString& l);
41     QString source() { return m_target; }
42     QString destination() { return m_local; }
43     Q_INVOKABLE void cancel();
44     Q_INVOKABLE void download();
45 
46 Q_SIGNALS:
47     void doFinished();
48     void doError();
49     void doProgress(int, int);
50 
51 private:
52     QNetworkAccessManager* m_manager;
53     QString m_target;
54     QString m_local;
55     QNetworkReply* m_reply;
56     bool started;
57 
58 public Q_SLOTS:
59     void downloadFinished();
60     void downloadProgress(qint64 recieved, qint64 total);
61     void replyError(QNetworkReply::NetworkError errorCode);
62 };