summaryrefslogtreecommitdiff
path: root/file_download.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'file_download.cpp')
-rw-r--r--file_download.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/file_download.cpp b/file_download.cpp
new file mode 100644
index 0000000..c155f8b
--- /dev/null
+++ b/file_download.cpp
@@ -0,0 +1,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 */
+}