summaryrefslogtreecommitdiff
path: root/file_download.cpp
blob: c155f8b9c545fe9c3c9e71588d2d1c91af51f4e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "file_download.h"

file_download::file_download()
{

}

int file_download::file_download::download_file(QString url, QString save_location)
{
    /*
     * this function will download a given url/file to a location
     * no file location will be interpreted as . (current directory)
     */
    qDebug() << "downloading to " + save_location + " from " + url;
    if (QFile::exists(save_location))
        QFile::remove(save_location);
    QNetworkReply *reply = http.get(QNetworkRequest(url));
    QObject::connect(reply, SIGNAL(finished()),&loop, SLOT(quit()));
    loop.exec();
    QFile file(save_location);
    file.open(QIODevice::WriteOnly);
    file.write(reply->readAll());
    delete reply;
    if (QFile::exists(save_location) && file.size() > 0)
        return 1; /* file downloaded - could just be a blank file at this point */
    else
        return 0; /* file did not download */
}