Added network statuses indication to feeds list.

This commit is contained in:
Martin Rotter 2014-08-29 08:28:26 +02:00
parent 7227d39c9b
commit 91ba9676ce
3 changed files with 29 additions and 13 deletions

View File

@ -39,6 +39,7 @@
FeedsModelFeed::FeedsModelFeed(FeedsModelRootItem *parent_item)
: FeedsModelRootItem(parent_item),
m_status(Normal),
m_networkError(QNetworkReply::NoError),
m_type(Rss0X),
m_totalCount(0),
m_unreadCount(0),
@ -312,12 +313,14 @@ QVariant FeedsModelFeed::data(int column, int role) const {
//: Tooltip for feed.
return tr("%1 (%2)\n"
"%3\n\n"
"Network status: %6\n"
"Encoding: %4\n"
"Auto-update status: %5").arg(m_title,
FeedsModelFeed::typeToString(m_type),
m_description,
m_encoding,
auto_update_string);
auto_update_string,
NetworkFactory::networkErrorText(m_networkError));
}
else if (column == FDS_MODEL_COUNTS_INDEX) {
//: Tooltip for "unread" column of feed list.
@ -339,7 +342,16 @@ QVariant FeedsModelFeed::data(int column, int role) const {
return countOfUnreadMessages() > 0 ? m_boldFont : m_normalFont;
case Qt::ForegroundRole:
return m_status == NewMessages ? QColor(Qt::blue) : QVariant();
switch (m_status) {
case NewMessages:
return QColor(Qt::blue);
case NetworkError:
return QColor(Qt::red);
default:
return QVariant();
}
default:
return QVariant();
@ -349,16 +361,19 @@ QVariant FeedsModelFeed::data(int column, int role) const {
void FeedsModelFeed::update() {
QByteArray feed_contents;
int download_timeout = qApp->settings()->value(APP_CFG_FEEDS, "feed_update_timeout", DOWNLOAD_TIMEOUT).toInt();
QNetworkReply::NetworkError download_result = NetworkFactory::downloadFile(url(), download_timeout,
m_networkError = NetworkFactory::downloadFile(url(), download_timeout,
feed_contents, passwordProtected(),
username(), password());
if (download_result != QNetworkReply::NoError) {
qWarning("Error during fetching of new messages for feed '%s' (id %d).",
qPrintable(url()),
id());
if (m_networkError != QNetworkReply::NoError) {
qWarning("Error during fetching of new messages for feed '%s' (id %d).", qPrintable(url()), id());
m_status = NetworkError;
return;
}
else {
m_status = Normal;
}
// Encode downloaded data for further parsing.
QTextCodec *codec = QTextCodec::codecForName(encoding().toLocal8Bit());

View File

@ -199,6 +199,7 @@ class FeedsModelFeed : public FeedsModelRootItem {
QString m_password;
Status m_status;
QNetworkReply::NetworkError m_networkError;
Type m_type;
int m_totalCount;
int m_unreadCount;

View File

@ -80,7 +80,7 @@ QString NetworkFactory::networkErrorText(QNetworkReply::NetworkError error_code)
case QNetworkReply::NoError:
//: Network status.
return tr("success");
return tr("no errors");
case QNetworkReply::UnknownContentError:
//: Network status.