Krita Source Code Documentation
Loading...
Searching...
No Matches
MultiFeedRssModel Class Reference

#include <KisMultiFeedRSSModel.h>

+ Inheritance diagram for MultiFeedRssModel:

Public Slots

void setArticleCount (int arg)
 

Signals

void articleCountChanged (int arg)
 
void feedDataChanged ()
 

Public Member Functions

virtual void addFeed (const QString &feed)
 
int articleCount () const
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
 MultiFeedRssModel (KisNetworkAccessManager *nam, QObject *parent=0)
 
 MultiFeedRssModel (QObject *parent=0)
 
void removeFeed (const QString &feed)
 
QHash< int, QByteArray > roleNames () const override
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
 ~MultiFeedRssModel () override
 

Properties

int articleCount
 

Private Slots

void appendFeedData (QNetworkReply *reply)
 

Private Member Functions

void initialize ()
 
void sortAggregatedFeed ()
 

Private Attributes

RssItemList m_aggregatedFeed
 
int m_articleCount
 
KisNetworkAccessManagerm_networkAccessManager
 
QStringList m_sites
 

Friends

class MockMultiFeedRssModel
 

Detailed Description

Definition at line 41 of file KisMultiFeedRSSModel.h.

Constructor & Destructor Documentation

◆ MultiFeedRssModel() [1/2]

MultiFeedRssModel::MultiFeedRssModel ( QObject * parent = 0)
explicit

Definition at line 43 of file KisMultiFeedRSSModel.cpp.

43 :
44 QAbstractListModel(parent),
47{
48 initialize();
49}
Network Access Manager for use with Krita.
KisNetworkAccessManager * m_networkAccessManager

References initialize().

◆ MultiFeedRssModel() [2/2]

MultiFeedRssModel::MultiFeedRssModel ( KisNetworkAccessManager * nam,
QObject * parent = 0 )
explicit

Definition at line 51 of file KisMultiFeedRSSModel.cpp.

52 : QAbstractListModel(parent),
55{
56 initialize();
57}

References initialize().

◆ ~MultiFeedRssModel()

MultiFeedRssModel::~MultiFeedRssModel ( )
override

Definition at line 60 of file KisMultiFeedRSSModel.cpp.

61{
63}

References m_networkAccessManager.

Member Function Documentation

◆ addFeed()

void MultiFeedRssModel::addFeed ( const QString & feed)
virtual

Definition at line 78 of file KisMultiFeedRSSModel.cpp.

79{
80 if (m_sites.contains(feed)) {
81 // do not add the feed twice
82 return;
83 }
84
85 m_sites << feed;
86 const QUrl feedUrl(feed);
88}

References KisNetworkAccessManager::getUrl(), m_networkAccessManager, and m_sites.

◆ appendFeedData

void MultiFeedRssModel::appendFeedData ( QNetworkReply * reply)
privateslot

Definition at line 95 of file KisMultiFeedRSSModel.cpp.

96{
97 beginResetModel();
98 KisRssReader reader;
99 m_aggregatedFeed.append(reader.parse(reply));
102 endResetModel();
103
104 Q_EMIT feedDataChanged();
105}
RssItemList parse(QNetworkReply *reply)
void setArticleCount(int arg)

References feedDataChanged(), m_aggregatedFeed, KisRssReader::parse(), setArticleCount(), and sortAggregatedFeed().

◆ articleCount()

int MultiFeedRssModel::articleCount ( ) const
inline

Definition at line 57 of file KisMultiFeedRSSModel.h.

57 {
58 return m_articleCount;
59 }

◆ articleCountChanged

void MultiFeedRssModel::articleCountChanged ( int arg)
signal

◆ data()

QVariant MultiFeedRssModel::data ( const QModelIndex & index,
int role = Qt::DisplayRole ) const
override

Definition at line 141 of file KisMultiFeedRSSModel.cpp.

142{
143 if (index.row() < m_aggregatedFeed.size()) {
144 RssItem item = m_aggregatedFeed.at(index.row());
145
146 switch (role) {
147 case Qt::DisplayRole:
148 {
149 QTextDocument doc;
150 doc.setHtml(item.description);
151 // Extract the first text block, which is the `<p>` element containing
152 // the shortened post text, excluding the "This post [...] appeared
153 // first on [...]" text.
154 QString text = doc.firstBlock().text();
155 if (text.length() > 292) {
156 text.truncate(290);
157 text.append("...");
158 }
159 return QString("<b><a href=\"" + item.link + "\">" + item.title + "</a></b>"
160 "<br><small>(" + QLocale().toString(item.pubDate.toLocalTime(), QLocale::ShortFormat) + ") "
161 "<p style=\"margin-top: 4px\">" + text + "</p></small>");
162 }
164 return item.title;
166 return item.description;
168 return item.pubDate.toString("dd-MM-yyyy hh:mm");
170 return item.link;
172 return item.category;
174 return item.blogName;
176 return item.blogIcon;
177 }
178 }
179
180 return QVariant();
181}
QString toString(const QString &value)
QString title
QString category
QString blogName
QString blogIcon
QDateTime pubDate
QString description
QString link

References RssItem::blogIcon, KisRssReader::BlogIconRole, RssItem::blogName, KisRssReader::BlogNameRole, RssItem::category, KisRssReader::CategoryRole, RssItem::description, KisRssReader::DescriptionRole, RssItem::link, KisRssReader::LinkRole, m_aggregatedFeed, RssItem::pubDate, KisRssReader::PubDateRole, RssItem::title, and KisRssReader::TitleRole.

◆ feedDataChanged

void MultiFeedRssModel::feedDataChanged ( )
signal

◆ initialize()

void MultiFeedRssModel::initialize ( )
private

Definition at line 112 of file KisMultiFeedRSSModel.cpp.

113{
114 connect(m_networkAccessManager, SIGNAL(finished(QNetworkReply*)),
115 SLOT(appendFeedData(QNetworkReply*)), Qt::QueuedConnection);
116}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void appendFeedData(QNetworkReply *reply)

References appendFeedData(), connect(), and m_networkAccessManager.

◆ removeFeed()

void MultiFeedRssModel::removeFeed ( const QString & feed)

Definition at line 118 of file KisMultiFeedRSSModel.cpp.

119{
120 bool isRemoved = m_sites.removeOne(feed);
121 if (isRemoved) {
122 beginResetModel();
123 QMutableListIterator<RssItem> it(m_aggregatedFeed);
124 while (it.hasNext()) {
125 RssItem item = it.next();
126 if (item.source == feed)
127 it.remove();
128 }
130 endResetModel();
131
132 Q_EMIT feedDataChanged();
133 }
134}
QString source

References feedDataChanged(), m_aggregatedFeed, m_sites, setArticleCount(), and RssItem::source.

◆ roleNames()

◆ rowCount()

int MultiFeedRssModel::rowCount ( const QModelIndex & parent = QModelIndex()) const
override

Definition at line 136 of file KisMultiFeedRSSModel.cpp.

137{
138 return m_aggregatedFeed.size();
139}

References m_aggregatedFeed.

◆ setArticleCount

void MultiFeedRssModel::setArticleCount ( int arg)
inlineslot

Definition at line 62 of file KisMultiFeedRSSModel.h.

62 {
63 if (m_articleCount != arg) {
64 m_articleCount = arg;
65 Q_EMIT articleCountChanged(arg);
66 }
67 }
void articleCountChanged(int arg)

◆ sortAggregatedFeed()

void MultiFeedRssModel::sortAggregatedFeed ( )
private

Definition at line 107 of file KisMultiFeedRSSModel.cpp.

108{
109 std::sort(m_aggregatedFeed.begin(), m_aggregatedFeed.end(), sortForPubDate);
110}
bool sortForPubDate(const RssItem &item1, const RssItem &item2)

References m_aggregatedFeed, and sortForPubDate().

Friends And Related Symbol Documentation

◆ MockMultiFeedRssModel

friend class MockMultiFeedRssModel
friend

Definition at line 85 of file KisMultiFeedRSSModel.h.

Member Data Documentation

◆ m_aggregatedFeed

RssItemList MultiFeedRssModel::m_aggregatedFeed
private

Definition at line 78 of file KisMultiFeedRSSModel.h.

◆ m_articleCount

int MultiFeedRssModel::m_articleCount
private

Definition at line 80 of file KisMultiFeedRSSModel.h.

◆ m_networkAccessManager

KisNetworkAccessManager* MultiFeedRssModel::m_networkAccessManager
private

Definition at line 79 of file KisMultiFeedRSSModel.h.

◆ m_sites

QStringList MultiFeedRssModel::m_sites
private

Definition at line 77 of file KisMultiFeedRSSModel.h.

Property Documentation

◆ articleCount

int MultiFeedRssModel::articleCount
readwrite

Definition at line 44 of file KisMultiFeedRSSModel.h.


The documentation for this class was generated from the following files: