Better error texts.

This commit is contained in:
Martin Rotter 2014-02-22 21:03:59 +01:00
parent d86ed7f019
commit 0a6671e86e
6 changed files with 81 additions and 15 deletions

View File

@ -9,7 +9,10 @@
FeedsModelFeed::FeedsModelFeed(FeedsModelRootItem *parent_item) FeedsModelFeed::FeedsModelFeed(FeedsModelRootItem *parent_item)
: FeedsModelRootItem(parent_item), m_totalCount(0), m_unreadCount(0) { : FeedsModelRootItem(parent_item),
m_type(StandardRss0X),
m_totalCount(0),
m_unreadCount(0) {
m_kind = FeedsModelRootItem::Feed; m_kind = FeedsModelRootItem::Feed;
} }

View File

@ -57,9 +57,10 @@ QPair<FeedsModelStandardFeed*, QNetworkReply::NetworkError> FeedsModelStandardFe
// Try to obtain icon. // Try to obtain icon.
QIcon icon_data; QIcon icon_data;
if (NetworkFactory::downloadIcon(url, if ((result.second = NetworkFactory::downloadIcon(url,
5000, 5000,
icon_data) == QNetworkReply::NoError) { icon_data)) ==
QNetworkReply::NoError) {
// Icon for feed was downloaded and is stored now in _icon_data. // Icon for feed was downloaded and is stored now in _icon_data.
result.first = new FeedsModelStandardFeed(); result.first = new FeedsModelStandardFeed();
result.first->setIcon(icon_data); result.first->setIcon(icon_data);
@ -90,6 +91,10 @@ QPair<FeedsModelStandardFeed*, QNetworkReply::NetworkError> FeedsModelStandardFe
} }
} }
if (result.first == NULL) {
result.first = new FeedsModelStandardFeed();
}
QTextCodec *custom_codec = QTextCodec::codecForName(xml_schema_encoding.toLocal8Bit()); QTextCodec *custom_codec = QTextCodec::codecForName(xml_schema_encoding.toLocal8Bit());
if (custom_codec != NULL) { if (custom_codec != NULL) {
@ -108,6 +113,11 @@ QPair<FeedsModelStandardFeed*, QNetworkReply::NetworkError> FeedsModelStandardFe
QDomDocument xml_document; QDomDocument xml_document;
if (!xml_document.setContent(xml_contents_encoded)) { if (!xml_document.setContent(xml_contents_encoded)) {
qDebug("XML of feed '%s' is not valid and cannot be loaded.",
qPrintable(url));
result.second = QNetworkReply::UnknownContentError;
// XML is invalid, exit. // XML is invalid, exit.
return result; return result;
} }

View File

@ -11,6 +11,49 @@
NetworkFactory::NetworkFactory() { NetworkFactory::NetworkFactory() {
} }
QString NetworkFactory::networkErrorText(QNetworkReply::NetworkError error_code) {
switch (error_code) {
case QNetworkReply::ProtocolFailure:
return QObject::tr("protocol error");
case QNetworkReply::HostNotFoundError:
return QObject::tr("host not found");
case QNetworkReply::RemoteHostClosedError:
case QNetworkReply::ConnectionRefusedError:
return QObject::tr("connection refused");
case QNetworkReply::TimeoutError:
case QNetworkReply::ProxyTimeoutError:
return QObject::tr("connection timed out");
case QNetworkReply::SslHandshakeFailedError:
return QObject::tr("SSL handshake failed");
case QNetworkReply::ProxyConnectionClosedError:
case QNetworkReply::ProxyConnectionRefusedError:
return QObject::tr("proxy server connection refused");
case QNetworkReply::TemporaryNetworkFailureError:
return QObject::tr("temporary failure");
case QNetworkReply::ProxyAuthenticationRequiredError:
return QObject::tr("proxy authentication required");
case QNetworkReply::ProxyNotFoundError:
return QObject::tr("proxy server not found");
case QNetworkReply::NoError:
return QObject::tr("success");
case QNetworkReply::UnknownContentError:
return QObject::tr("uknown content");
default:
return QObject::tr("unknown error");
}
}
QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QString &url, QNetworkReply::NetworkError NetworkFactory::downloadIcon(const QString &url,
int timeout, int timeout,
QIcon &output) { QIcon &output) {
@ -115,7 +158,7 @@ QNetworkReply::NetworkError NetworkFactory::downloadFeedFile(const QString &url,
qDebug("File '%s' fetched with status '%s' (code %d).", qDebug("File '%s' fetched with status '%s' (code %d).",
qPrintable(url), qPrintable(url),
qPrintable(reply->errorString()), qPrintable(networkErrorText(reply_error)),
reply_error); reply_error);
// Delete needed stuff and exit. // Delete needed stuff and exit.

View File

@ -12,6 +12,8 @@ class NetworkFactory {
explicit NetworkFactory(); explicit NetworkFactory();
public: public:
static QString networkErrorText(QNetworkReply::NetworkError error_code);
// Performs SYNCHRONOUS download if favicon for the site, // Performs SYNCHRONOUS download if favicon for the site,
// given URL belongs to. // given URL belongs to.
static QNetworkReply::NetworkError downloadIcon(const QString &url, static QNetworkReply::NetworkError downloadIcon(const QString &url,

View File

@ -7,6 +7,7 @@
#include "core/feedsmodelcategory.h" #include "core/feedsmodelcategory.h"
#include "core/feedsmodelfeed.h" #include "core/feedsmodelfeed.h"
#include "core/feedsmodelstandardfeed.h" #include "core/feedsmodelstandardfeed.h"
#include "core/networkfactory.h"
#include "gui/iconthemefactory.h" #include "gui/iconthemefactory.h"
#include "gui/baselineedit.h" #include "gui/baselineedit.h"
#include "gui/messagebox.h" #include "gui/messagebox.h"
@ -248,7 +249,7 @@ void FormStandardFeedDetails::guessFeed() {
m_ui->m_txtPassword->lineEdit()->text()); m_ui->m_txtPassword->lineEdit()->text());
if (result.first != NULL) { if (result.first != NULL) {
// Icon was perhaps guessed. // Icon or whole feed was guessed.
m_ui->m_btnIcon->setIcon(result.first->icon()); m_ui->m_btnIcon->setIcon(result.first->icon());
m_ui->m_txtTitle->lineEdit()->setText(result.first->title()); m_ui->m_txtTitle->lineEdit()->setText(result.first->title());
m_ui->m_txtDescription->lineEdit()->setText(result.first->description()); m_ui->m_txtDescription->lineEdit()->setText(result.first->description());
@ -256,15 +257,22 @@ void FormStandardFeedDetails::guessFeed() {
m_ui->m_cmbEncoding->setCurrentIndex(m_ui->m_cmbEncoding->findText(result.first->encoding(), m_ui->m_cmbEncoding->setCurrentIndex(m_ui->m_cmbEncoding->findText(result.first->encoding(),
Qt::MatchFixedString)); Qt::MatchFixedString));
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Ok, if (result.second == QNetworkReply::NoError) {
tr("Feed metada fetched."), m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Ok,
tr("Feed metadata fetched successfully.")); tr("All metadata fetched successfully."),
tr("Feed and icon metadata fetched."));
}
else {
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Warning,
tr("Result: %1.").arg(NetworkFactory::networkErrorText(result.second)),
tr("Feed or icon metatada not fetched."));
}
} }
else { else {
// No feed guessed, even no icon available. // No feed guessed, even no icon available.
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Error, m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Error,
tr("Error occurred."), tr("Error: %1.").arg(NetworkFactory::networkErrorText(result.second)),
tr("Error occurred.")); tr("No metadata fetched."));
} }
} }

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>405</width> <width>432</width>
<height>259</height> <height>322</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -65,8 +65,8 @@
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt; <string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt; &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; } p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt; &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> &lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="textInteractionFlags"> <property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set> <set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>