Commit 51b05427 authored by hjk's avatar hjk

TextEditor: Simplify definitiondowloader.h

Change-Id: I01621753851a99275ef8bee2c55c69840dc29580
Reviewed-by: default avatarNikita Baryshnikov <nib952051@gmail.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 5615c406
......@@ -41,8 +41,22 @@
#include <utils/networkaccessmanager.h>
using namespace TextEditor;
using namespace Internal;
namespace TextEditor {
namespace Internal {
static QNetworkReply *getData(const QUrl &url)
{
Utils::NetworkAccessManager *manager = Utils::NetworkAccessManager::instance();
QNetworkRequest request(url);
QNetworkReply *reply = manager->get(request);
QEventLoop eventLoop;
QObject::connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
eventLoop.exec();
return reply;
}
DefinitionDownloader::DefinitionDownloader(const QUrl &url, const QString &localPath) :
m_url(url), m_localPath(localPath), m_status(Unknown)
......@@ -50,12 +64,10 @@ DefinitionDownloader::DefinitionDownloader(const QUrl &url, const QString &local
void DefinitionDownloader::run()
{
Utils::NetworkAccessManager *manager = Utils::NetworkAccessManager::instance();
int currentAttempt = 0;
const int maxAttempts = 5;
while (currentAttempt < maxAttempts) {
QScopedPointer<QNetworkReply> reply(getData(manager));
QScopedPointer<QNetworkReply> reply(getData(m_url));
if (reply->error() != QNetworkReply::NoError) {
m_status = NetworkError;
return;
......@@ -72,18 +84,6 @@ void DefinitionDownloader::run()
}
}
QNetworkReply *DefinitionDownloader::getData(QNetworkAccessManager *manager) const
{
QNetworkRequest request(m_url);
QNetworkReply *reply = manager->get(request);
QEventLoop eventLoop;
connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
eventLoop.exec();
return reply;
}
void DefinitionDownloader::saveData(QNetworkReply *reply)
{
const QString &urlPath = m_url.path();
......@@ -106,3 +106,6 @@ void DefinitionDownloader::saveData(QNetworkReply *reply)
DefinitionDownloader::Status DefinitionDownloader::status() const
{ return m_status; }
} // namespace Internal
} // namespace TextEditor
......@@ -37,7 +37,6 @@
QT_BEGIN_NAMESPACE
class QNetworkReply;
class QNetworkAccessManager;
QT_END_NAMESPACE
namespace TextEditor {
......@@ -63,7 +62,6 @@ signals:
void foundReferencedDefinition(const QString &name);
private:
QNetworkReply *getData(QNetworkAccessManager *manager) const;
void saveData(QNetworkReply *reply);
QUrl m_url;
......
......@@ -55,7 +55,6 @@ namespace TextEditor {
namespace Internal {
class HighlightDefinition;
class DefinitionDownloader;
class ManagerProcessor;
class MultiDefinitionDownloader;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment