summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-10-30 06:32:38 (GMT)
committerMontel Laurent <montel@kde.org>2016-10-30 06:32:38 (GMT)
commitc0f73a906f38d05440883f51f2a25bd391d7f73f (patch)
treef3e0cfb60bbd8a2d0e08e84037b4491e3841d911
parentd7fba5bbdcf80a7bb1ba083cc2b5af26df62e69d (diff)
Test if network is online.
-rw-r--r--messageviewer/src/checkphishingurl/checkphishingurljob.cpp23
-rw-r--r--messageviewer/src/checkphishingurl/checkphishingurljob.h4
2 files changed, 27 insertions, 0 deletions
diff --git a/messageviewer/src/checkphishingurl/checkphishingurljob.cpp b/messageviewer/src/checkphishingurl/checkphishingurljob.cpp
index 72865dd..e6a6bbc 100644
--- a/messageviewer/src/checkphishingurl/checkphishingurljob.cpp
+++ b/messageviewer/src/checkphishingurl/checkphishingurljob.cpp
@@ -19,6 +19,8 @@
#include "checkphishingurljob.h"
#include <QNetworkAccessManager>
+#include <QNetworkConfigurationManager>
+#include <QNetworkReply>
using namespace MessageViewer;
@@ -26,13 +28,23 @@ CheckPhishingUrlJob::CheckPhishingUrlJob(QObject *parent)
: QObject(parent)
{
mNetworkAccessManager = new QNetworkAccessManager(this);
+ connect(mNetworkAccessManager, &QNetworkAccessManager::finished, this, &CheckPhishingUrlJob::slotCheckUrlFinished);
+ mNetworkConfigurationManager = new QNetworkConfigurationManager();
}
CheckPhishingUrlJob::~CheckPhishingUrlJob()
{
+ delete mNetworkConfigurationManager;
+}
+void CheckPhishingUrlJob::slotCheckUrlFinished(QNetworkReply *reply)
+{
+ Q_UNUSED(reply);
+ //TODO Q_EMIT result(MessageViewer::CheckPhishingUrlJob:: ?);
+ deleteLater();
}
+
void CheckPhishingUrlJob::setUrl(const QUrl &url)
{
mUrl = url;
@@ -42,6 +54,12 @@ void CheckPhishingUrlJob::start()
{
if (canStart()) {
const QString postRequest = createPostRequest();
+ if (postRequest.isEmpty()) {
+ Q_EMIT result(MessageViewer::CheckPhishingUrlJob::Unknown);
+ deleteLater();
+ } else {
+ //TODO
+ }
} else {
Q_EMIT result(MessageViewer::CheckPhishingUrlJob::Unknown);
deleteLater();
@@ -50,6 +68,11 @@ void CheckPhishingUrlJob::start()
bool CheckPhishingUrlJob::canStart() const
{
+ if (!mNetworkConfigurationManager->isOnline()) {
+ //TODO it's not online !
+ return false;
+ }
+
return mUrl.isValid();
}
diff --git a/messageviewer/src/checkphishingurl/checkphishingurljob.h b/messageviewer/src/checkphishingurl/checkphishingurljob.h
index 27be62d..4689fcc 100644
--- a/messageviewer/src/checkphishingurl/checkphishingurljob.h
+++ b/messageviewer/src/checkphishingurl/checkphishingurljob.h
@@ -24,6 +24,8 @@
#include <QUrl>
#include "messageviewer_export.h"
class QNetworkAccessManager;
+class QNetworkReply;
+class QNetworkConfigurationManager;
namespace MessageViewer {
class MESSAGEVIEWER_EXPORT CheckPhishingUrlJob : public QObject
{
@@ -48,8 +50,10 @@ Q_SIGNALS:
void result(MessageViewer::CheckPhishingUrlJob::UrlStatus status);
private:
+ void slotCheckUrlFinished(QNetworkReply *reply);
QUrl mUrl;
QNetworkAccessManager *mNetworkAccessManager;
+ QNetworkConfigurationManager *mNetworkConfigurationManager;
};
}