Refactored data getter a bit.
This commit is contained in:
parent
ce7e0f6579
commit
0900d68dca
@ -31,3 +31,22 @@ Feed::Feed(RootItem *parent) : RootItem(parent) {
|
|||||||
|
|
||||||
Feed::~Feed() {
|
Feed::~Feed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant Feed::data(int column, int role) const {
|
||||||
|
switch (role) {
|
||||||
|
case Qt::ForegroundRole:
|
||||||
|
switch (status()) {
|
||||||
|
case NewMessages:
|
||||||
|
return QColor(Qt::blue);
|
||||||
|
|
||||||
|
case NetworkError:
|
||||||
|
return QColor(Qt::red);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return RootItem::data(column, role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include "core/message.h"
|
#include "core/message.h"
|
||||||
|
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
|
||||||
// Base class for "feed" nodes.
|
// Base class for "feed" nodes.
|
||||||
class Feed : public RootItem {
|
class Feed : public RootItem {
|
||||||
@ -61,6 +63,8 @@ class Feed : public RootItem {
|
|||||||
// messages.
|
// messages.
|
||||||
virtual int update() = 0;
|
virtual int update() = 0;
|
||||||
|
|
||||||
|
QVariant data(int column, int role) const;
|
||||||
|
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// Members to override. */
|
// Members to override. */
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
|
@ -160,6 +160,54 @@ QList<Message> StandardFeed::undeletedMessages() const {
|
|||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant StandardFeed::data(int column, int role) const {
|
||||||
|
switch (role) {
|
||||||
|
case Qt::ToolTipRole:
|
||||||
|
if (column == FDS_MODEL_TITLE_INDEX) {
|
||||||
|
QString auto_update_string;
|
||||||
|
|
||||||
|
switch (autoUpdateType()) {
|
||||||
|
case DontAutoUpdate:
|
||||||
|
//: Describes feed auto-update status.
|
||||||
|
auto_update_string = tr("does not use auto-update");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DefaultAutoUpdate:
|
||||||
|
//: Describes feed auto-update status.
|
||||||
|
auto_update_string = tr("uses global settings");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SpecificAutoUpdate:
|
||||||
|
default:
|
||||||
|
//: Describes feed auto-update status.
|
||||||
|
auto_update_string = tr("uses specific settings "
|
||||||
|
"(%n minute(s) to next auto-update)",
|
||||||
|
0,
|
||||||
|
autoUpdateRemainingInterval());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//: Tooltip for feed.
|
||||||
|
return tr("%1 (%2)"
|
||||||
|
"%3\n\n"
|
||||||
|
"Network status: %6\n"
|
||||||
|
"Encoding: %4\n"
|
||||||
|
"Auto-update status: %5").arg(title(),
|
||||||
|
StandardFeed::typeToString(type()),
|
||||||
|
description().isEmpty() ? QString() : QString('\n') + description(),
|
||||||
|
encoding(),
|
||||||
|
auto_update_string,
|
||||||
|
NetworkFactory::networkErrorText(m_networkError));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return Feed::data(column, role);
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return Feed::data(column, role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString StandardFeed::typeToString(StandardFeed::Type type) {
|
QString StandardFeed::typeToString(StandardFeed::Type type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Atom10:
|
case Atom10:
|
||||||
@ -372,66 +420,6 @@ QPair<StandardFeed*,QNetworkReply::NetworkError> StandardFeed::guessFeed(const Q
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant StandardFeed::data(int column, int role) const {
|
|
||||||
switch (role) {
|
|
||||||
case Qt::ToolTipRole:
|
|
||||||
if (column == FDS_MODEL_TITLE_INDEX) {
|
|
||||||
QString auto_update_string;
|
|
||||||
|
|
||||||
switch (autoUpdateType()) {
|
|
||||||
case DontAutoUpdate:
|
|
||||||
//: Describes feed auto-update status.
|
|
||||||
auto_update_string = tr("does not use auto-update");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DefaultAutoUpdate:
|
|
||||||
//: Describes feed auto-update status.
|
|
||||||
auto_update_string = tr("uses global settings");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SpecificAutoUpdate:
|
|
||||||
default:
|
|
||||||
//: Describes feed auto-update status.
|
|
||||||
auto_update_string = tr("uses specific settings "
|
|
||||||
"(%n minute(s) to next auto-update)",
|
|
||||||
0,
|
|
||||||
autoUpdateRemainingInterval());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//: Tooltip for feed.
|
|
||||||
return tr("%1 (%2)"
|
|
||||||
"%3\n\n"
|
|
||||||
"Network status: %6\n"
|
|
||||||
"Encoding: %4\n"
|
|
||||||
"Auto-update status: %5").arg(title(),
|
|
||||||
StandardFeed::typeToString(type()),
|
|
||||||
description().isEmpty() ? QString() : QString('\n') + description(),
|
|
||||||
encoding(),
|
|
||||||
auto_update_string,
|
|
||||||
NetworkFactory::networkErrorText(m_networkError));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return Feed::data(column, role);
|
|
||||||
}
|
|
||||||
|
|
||||||
case Qt::ForegroundRole:
|
|
||||||
switch (status()) {
|
|
||||||
case NewMessages:
|
|
||||||
return QColor(Qt::blue);
|
|
||||||
|
|
||||||
case NetworkError:
|
|
||||||
return QColor(Qt::red);
|
|
||||||
|
|
||||||
default:
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
return Feed::data(column, role);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Qt::ItemFlags StandardFeed::additionalFlags() const {
|
Qt::ItemFlags StandardFeed::additionalFlags() const {
|
||||||
return Qt::ItemIsDragEnabled;
|
return Qt::ItemIsDragEnabled;
|
||||||
}
|
}
|
||||||
|
@ -79,8 +79,9 @@ class StandardFeed : public Feed {
|
|||||||
|
|
||||||
QList<Message> undeletedMessages() const;
|
QList<Message> undeletedMessages() const;
|
||||||
|
|
||||||
// Obtains data related to this feed.
|
|
||||||
QVariant data(int column, int role) const;
|
QVariant data(int column, int role) const;
|
||||||
|
|
||||||
|
// Obtains data related to this feed.
|
||||||
Qt::ItemFlags additionalFlags() const;
|
Qt::ItemFlags additionalFlags() const;
|
||||||
bool performDragDropChange(RootItem *target_item);
|
bool performDragDropChange(RootItem *target_item);
|
||||||
|
|
||||||
|
@ -289,7 +289,13 @@ int TtRssFeed::updateMessages(const QList<Message> &messages) {
|
|||||||
qDebug("Transaction commit for message downloader failed.");
|
qDebug("Transaction commit for message downloader failed.");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setStatus(NewMessages);
|
if (updated_messages > 0) {
|
||||||
|
setStatus(NewMessages);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setStatus(Normal);
|
||||||
|
}
|
||||||
|
|
||||||
updateCounts(true);
|
updateCounts(true);
|
||||||
serviceRoot()->itemChanged(QList<RootItem*>() << this);
|
serviceRoot()->itemChanged(QList<RootItem*>() << this);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user