Improve error messages when feedback or DLC fail to reach Internet
authoralfadur
Sun, 08 Oct 2017 19:04:20 +0200
changeset 12674 8d266b2d0f9c
parent 12673 28e859ea393b
child 12675 cc13c9bc6839
Improve error messages when feedback or DLC fail to reach Internet Problems with a missing SSL library are hinted at.
QTfrontend/hwform.cpp
QTfrontend/ui/page/pagedata.cpp
--- a/QTfrontend/hwform.cpp	Sun Oct 08 16:50:47 2017 +0200
+++ b/QTfrontend/hwform.cpp	Sun Oct 08 19:04:20 2017 +0200
@@ -2250,11 +2250,27 @@
 {
     QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
 
-    if (reply && (reply->error() == QNetworkReply::NoError)) {
-        FeedbackDialog dialog(this);
-        dialog.exec();
-    } else
-        MessageDialog::ShowErrorMessage(tr("This page requires an internet connection."), this);
+    if (reply) {
+        switch (reply->error()) {
+            case QNetworkReply::NoError:
+                {
+                    FeedbackDialog dialog(this);
+                    dialog.exec();
+                }
+                break;
+            case QNetworkReply::UnknownNetworkError:
+                MessageDialog::ShowFatalMessage(
+                    tr("Unknown network error (possibly missing SSL library)."), this);
+                break;
+            default:
+                MessageDialog::ShowFatalMessage(
+                    QString(tr("This feature requires an Internet connection, but you don't appear to be online (error code: %1).")).arg(reply->error()), this);
+                break;
+        }
+    }
+    else {
+        MessageDialog::ShowFatalMessage(tr("Internal error: Reply object is invalid."), this);
+    }
 }
 
 void HWForm::startGame()
--- a/QTfrontend/ui/page/pagedata.cpp	Sun Oct 08 16:50:47 2017 +0200
+++ b/QTfrontend/ui/page/pagedata.cpp	Sun Oct 08 19:04:20 2017 +0200
@@ -136,22 +136,34 @@
 void PageDataDownload::pageDownloaded()
 {
     QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
+    const char *html =
+        "<center><h2>Hedgewars Downloadable Content</h2><br><br>"
+        "<h4><i>%1</i></h4></center>";
 
-    if (reply && (reply->error() == QNetworkReply::NoError)) {
-        QString html = QString::fromUtf8(reply->readAll());
-        int begin = html.indexOf("<!-- BEGIN -->");
-        int end = html.indexOf("<!-- END -->");
-        if(begin != -1 && begin < end)
+    if (reply) {
+        if (reply->error() == QNetworkReply::NoError)
         {
-            html.truncate(end);
-            html.remove(0, begin);
+            QString html = QString::fromUtf8(reply->readAll());
+                    int begin = html.indexOf("<!-- BEGIN -->");
+                    int end = html.indexOf("<!-- END -->");
+                    if(begin != -1 && begin < end)
+                    {
+                        html.truncate(end);
+                        html.remove(0, begin);
+                    }
+                    web->setHtml(html);
         }
-        web->setHtml(html);
-    } else
-        web->setHtml(QString(
-            "<center><h2>Hedgewars Downloadable Content</h2><br><br>"
-            "<p><i><h4>%1</i></h4></p></center>")
-            .arg(tr("This page requires an internet connection.")));
+        else
+        {
+            QString message = reply->error() == QNetworkReply::UnknownNetworkError ?
+                tr("Unknown network error (possibly missing SSL library).") :
+                QString(tr("This feature requires an Internet connection, but you don't appear to be online (error code: %1).")).arg(reply->error());
+            web->setHtml(QString(html).arg(message));
+        }
+    }
+    else {
+        web->setHtml(QString(html).arg(tr("Internal error: Reply object is invalid.")));
+    }
 }
 
 void PageDataDownload::fileDownloaded()