/*------------------------------------------------------------------------------ -- This file is a part of the QLop Software -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -------------------------------------------------------------------------------*/ /*-- Author : Alexis Jeandet -- Mail : alexis.jeandet@member.fsf.org ----------------------------------------------------------------------------*/ #include "filedownloader_old.h" #include FileDownloader_old::FileDownloader_old(QUrl fileUrl, const QString &name, QObject *parent) : QObject(parent) { connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)), SLOT(fileDownloaded(QNetworkReply*))); QNetworkProxyQuery q(QUrl("http://www.google.com")); q.setQueryType(QNetworkProxyQuery::UrlRequest); q.setProtocolTag("http"); QList proxies = QNetworkProxyFactory::systemProxyForQuery(q); if( proxies.size() > 0 && proxies[0].type() != QNetworkProxy::NoProxy ) QNetworkProxy::setApplicationProxy(proxies[0]); else qDebug("No proxy server selected"); this->m_downloadComplete = false; this->m_fileName = name; QNetworkRequest request(fileUrl); m_Reply = m_WebCtrl.get(request); connect(this->m_Reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(downloadProgress(qint64,qint64))); connect(&m_WebCtrl,SIGNAL(finished(QNetworkReply*)),this,SLOT(fileDownloaded(QNetworkReply*))); this->m_progressBar.setMinimum(0); this->m_progressBar.show(); this->m_widget.setLayout(&this->m_layout); this->m_layout.addWidget(&this->m_label); this->m_layout.addWidget(&this->m_progressBar); this->m_label.setText(name); } FileDownloader_old::~FileDownloader_old() { } void FileDownloader_old::fileDownloaded(QNetworkReply* pReply) { m_DownloadedData = pReply->readAll(); this->m_downloadComplete = true; pReply->deleteLater(); emit downloaded(); this->m_progressBar.hide(); } void FileDownloader_old::downloadProgress(qint64 bytesSent, qint64 bytesTotal) { if(Q_UNLIKELY(this->m_progressBar.maximum()!=bytesTotal)) { this->m_progressBar.setMaximum(bytesTotal); } this->m_progressBar.setValue(bytesSent); } bool FileDownloader_old::downloadComplete(){return m_downloadComplete;} QByteArray FileDownloader_old::downloadedData() const { return m_DownloadedData; } void FileDownloader_old::clearData() { this->m_DownloadedData.clear(); } int FileDownloader_old::donloadedDataSize() { return m_DownloadedData.size(); } QWidget *FileDownloader_old::getProgressBar() { return &this->m_widget; } QString FileDownloader_old::fileName(){return m_fileName;}