Better error texts.
This commit is contained in:
parent
d86ed7f019
commit
0a6671e86e
@ -9,7 +9,10 @@
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -57,9 +57,10 @@ QPair<FeedsModelStandardFeed*, QNetworkReply::NetworkError> FeedsModelStandardFe
|
||||
// Try to obtain icon.
|
||||
QIcon icon_data;
|
||||
|
||||
if (NetworkFactory::downloadIcon(url,
|
||||
5000,
|
||||
icon_data) == QNetworkReply::NoError) {
|
||||
if ((result.second = NetworkFactory::downloadIcon(url,
|
||||
5000,
|
||||
icon_data)) ==
|
||||
QNetworkReply::NoError) {
|
||||
// Icon for feed was downloaded and is stored now in _icon_data.
|
||||
result.first = new FeedsModelStandardFeed();
|
||||
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());
|
||||
|
||||
if (custom_codec != NULL) {
|
||||
@ -108,6 +113,11 @@ QPair<FeedsModelStandardFeed*, QNetworkReply::NetworkError> FeedsModelStandardFe
|
||||
QDomDocument xml_document;
|
||||
|
||||
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.
|
||||
return result;
|
||||
}
|
||||
|
@ -11,6 +11,49 @@
|
||||
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,
|
||||
int timeout,
|
||||
QIcon &output) {
|
||||
@ -115,7 +158,7 @@ QNetworkReply::NetworkError NetworkFactory::downloadFeedFile(const QString &url,
|
||||
|
||||
qDebug("File '%s' fetched with status '%s' (code %d).",
|
||||
qPrintable(url),
|
||||
qPrintable(reply->errorString()),
|
||||
qPrintable(networkErrorText(reply_error)),
|
||||
reply_error);
|
||||
|
||||
// Delete needed stuff and exit.
|
||||
|
@ -12,6 +12,8 @@ class NetworkFactory {
|
||||
explicit NetworkFactory();
|
||||
|
||||
public:
|
||||
static QString networkErrorText(QNetworkReply::NetworkError error_code);
|
||||
|
||||
// Performs SYNCHRONOUS download if favicon for the site,
|
||||
// given URL belongs to.
|
||||
static QNetworkReply::NetworkError downloadIcon(const QString &url,
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "core/feedsmodelcategory.h"
|
||||
#include "core/feedsmodelfeed.h"
|
||||
#include "core/feedsmodelstandardfeed.h"
|
||||
#include "core/networkfactory.h"
|
||||
#include "gui/iconthemefactory.h"
|
||||
#include "gui/baselineedit.h"
|
||||
#include "gui/messagebox.h"
|
||||
@ -248,7 +249,7 @@ void FormStandardFeedDetails::guessFeed() {
|
||||
m_ui->m_txtPassword->lineEdit()->text());
|
||||
|
||||
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_txtTitle->lineEdit()->setText(result.first->title());
|
||||
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(),
|
||||
Qt::MatchFixedString));
|
||||
|
||||
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Ok,
|
||||
tr("Feed metada fetched."),
|
||||
tr("Feed metadata fetched successfully."));
|
||||
if (result.second == QNetworkReply::NoError) {
|
||||
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Ok,
|
||||
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 {
|
||||
// No feed guessed, even no icon available.
|
||||
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Error,
|
||||
tr("Error occurred."),
|
||||
tr("Error occurred."));
|
||||
tr("Error: %1.").arg(NetworkFactory::networkErrorText(result.second)),
|
||||
tr("No metadata fetched."));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>405</width>
|
||||
<height>259</height>
|
||||
<width>432</width>
|
||||
<height>322</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -65,8 +65,8 @@
|
||||
<string notr="true"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
|
||||
<p style="-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;"><br /></p></body></html></string>
|
||||
</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
|
||||
<p style="-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;"><br /></p></body></html></string>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
|
||||
|
Loading…
x
Reference in New Issue
Block a user