[trojita] /: GUI: Show accurate error message when a part fails to load in the GUI

Jan Kundrát null at kde.org
Thu Jan 12 08:43:03 UTC 2017


Git commit 1faa911b5331ad6196165c739fa5f5f6134593a9 by Jan Kundrát.
Committed on 02/01/2017 at 22:07.
Pushed by gerrit into branch 'master'.

GUI: Show accurate error message when a part fails to load in the GUI

The code should distinguish between being offline and parts failing for
some other reason.

CCBUG: 341982
Change-Id: I858d79d88c4c51a25ca8cb3a493dd144f1cc366f

M  +17   -4    src/Gui/EmbeddedWebView.cpp
M  +10   -2    src/Imap/Network/MsgPartNetworkReply.cpp
M  +1    -1    tests/Imap/test_Imap_MsgPartNetAccessManager.cpp

https://commits.kde.org/trojita/1faa911b5331ad6196165c739fa5f5f6134593a9

diff --git a/src/Gui/EmbeddedWebView.cpp b/src/Gui/EmbeddedWebView.cpp
index 66350a9c..95826d85 100644
--- a/src/Gui/EmbeddedWebView.cpp
+++ b/src/Gui/EmbeddedWebView.cpp
@@ -324,10 +324,23 @@ bool ErrorCheckingPage::extension(Extension extension, const ExtensionOption *op
     ErrorPageExtensionReturn *res = static_cast<ErrorPageExtensionReturn *>(output);
     if (input && res) {
         if (input->url.scheme() == QLatin1String("trojita-imap")) {
-            if (input->domain == QtNetwork && input->error == QNetworkReply::TimeoutError) {
-                res->content = tr("<img src=\"%2\"/><span style=\"font-family: sans-serif; color: gray\">"
-                                  "Uncached data not available when offline</span>")
-                        .arg(Util::resizedImageAsDataUrl(QStringLiteral(":/icons/network-offline.svg"), 32)).toUtf8();
+            QString emblem;
+            if (input->domain == QtNetwork) {
+                switch (input->error) {
+                case QNetworkReply::TimeoutError:
+                    emblem = QStringLiteral("network-offline");
+                    break;
+                case QNetworkReply::ContentNotFoundError:
+                    emblem = QStringLiteral("emblem-error");
+                    break;
+                case QNetworkReply::UnknownProxyError:
+                    emblem = QStringLiteral("emblem-error");
+                    break;
+                }
+            }
+            if (!emblem.isNull()) {
+                res->content = tr("<img src=\"%2\"/><span style=\"font-family: sans-serif; color: gray\">%1</span>")
+                        .arg(input->errorString, Util::resizedImageAsDataUrl(QStringLiteral(":/icons/%1.svg").arg(emblem), 32)).toUtf8();
                 return true;
             }
         }
diff --git a/src/Imap/Network/MsgPartNetworkReply.cpp b/src/Imap/Network/MsgPartNetworkReply.cpp
index c1a9b497..1135650e 100644
--- a/src/Imap/Network/MsgPartNetworkReply.cpp
+++ b/src/Imap/Network/MsgPartNetworkReply.cpp
@@ -78,9 +78,17 @@ void MsgPartNetworkReply::slotModelDataChanged(const QModelIndex &topLeft, const
 void MsgPartNetworkReply::slotMyDataChanged()
 {
     if (part.data(Mailbox::RoleIsUnavailable).toBool()) {
-        setError(TimeoutError, tr("Offline"));
+        if (!part.data(Mailbox::RoleIsNetworkOffline).isValid()) {
+            setError(UnknownProxyError, tr("Cannot access data"));
+        } else {
+            if (part.data(Mailbox::RoleIsNetworkOffline).toBool()) {
+                setError(TimeoutError, tr("Uncached data not available when offline"));
+            } else {
+                setError(ContentNotFoundError, tr("Error downloading data"));
+            }
+        }
         setFinished(true);
-        emit error(TimeoutError);
+        emit error(error());
         emit finished();
         return;
     }
diff --git a/tests/Imap/test_Imap_MsgPartNetAccessManager.cpp b/tests/Imap/test_Imap_MsgPartNetAccessManager.cpp
index 32a54233..ded026af 100644
--- a/tests/Imap/test_Imap_MsgPartNetAccessManager.cpp
+++ b/tests/Imap/test_Imap_MsgPartNetAccessManager.cpp
@@ -226,7 +226,7 @@ void ImapMsgPartNetAccessManagerTest::testFetchResultOfflineSingle()
     QCOMPARE(msg1p1.data(Imap::Mailbox::RoleIsUnavailable), QVariant(true));
 
     QCOMPARE(res->isFinished(), true);
-    QCOMPARE(res->error(), QNetworkReply::TimeoutError);
+    QCOMPARE(res->error(), QNetworkReply::ContentNotFoundError);
 }
 
 



More information about the kde-doc-english mailing list