mirror of https://github.com/KDE/kasts.git
Make entry models only update if something really changed
This commit is contained in:
parent
0f957841b3
commit
a45351e1de
|
@ -49,7 +49,7 @@ Feed::Feed(QString const feedurl)
|
||||||
setRefreshing(true);
|
setRefreshing(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connect(&Fetcher::instance(), &Fetcher::feedUpdated, this, [this](const QString &url) {
|
connect(&DataManager::instance(), &DataManager::feedEntriesUpdated, this, [this](const QString &url) {
|
||||||
if (url == m_url) {
|
if (url == m_url) {
|
||||||
setRefreshing(false);
|
setRefreshing(false);
|
||||||
Q_EMIT entryCountChanged();
|
Q_EMIT entryCountChanged();
|
||||||
|
@ -65,7 +65,11 @@ Feed::Feed(QString const feedurl)
|
||||||
setRefreshing(false);
|
setRefreshing(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
connect(&Fetcher::instance(), &Fetcher::feedUpdateFinished, this, [this](const QString &url) {
|
||||||
|
if(url == m_url) {
|
||||||
|
setRefreshing(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
connect(&Fetcher::instance(), &Fetcher::downloadFinished, this, [this](QString url) {
|
connect(&Fetcher::instance(), &Fetcher::downloadFinished, this, [this](QString url) {
|
||||||
if(url == m_image)
|
if(url == m_image)
|
||||||
Q_EMIT imageChanged(url);
|
Q_EMIT imageChanged(url);
|
||||||
|
|
|
@ -140,9 +140,10 @@ void Fetcher::processFeed(Syndication::FeedPtr feed, const QString &url)
|
||||||
|
|
||||||
Q_EMIT feedDetailsUpdated(url, feed->title(), image, feed->link(), feed->description(), current);
|
Q_EMIT feedDetailsUpdated(url, feed->title(), image, feed->link(), feed->description(), current);
|
||||||
|
|
||||||
|
bool updatedEntries = false;
|
||||||
for (const auto &entry : feed->items()) {
|
for (const auto &entry : feed->items()) {
|
||||||
QCoreApplication::processEvents(); // keep the main thread semi-responsive
|
QCoreApplication::processEvents(); // keep the main thread semi-responsive
|
||||||
processEntry(entry, url, isNewFeed);
|
updatedEntries = updatedEntries || processEntry(entry, url, isNewFeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now mark the appropriate number of recent entries "new" and "read" only for new feeds
|
// Now mark the appropriate number of recent entries "new" and "read" only for new feeds
|
||||||
|
@ -163,10 +164,11 @@ void Fetcher::processFeed(Syndication::FeedPtr feed, const QString &url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT feedUpdated(url);
|
if (updatedEntries || isNewFeed) Q_EMIT feedUpdated(url);
|
||||||
|
Q_EMIT feedUpdateFinished(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fetcher::processEntry(Syndication::ItemPtr entry, const QString &url, const bool &isNewFeed)
|
bool Fetcher::processEntry(Syndication::ItemPtr entry, const QString &url, const bool &isNewFeed)
|
||||||
{
|
{
|
||||||
qDebug() << "Processing" << entry->title();
|
qDebug() << "Processing" << entry->title();
|
||||||
|
|
||||||
|
@ -180,7 +182,7 @@ void Fetcher::processEntry(Syndication::ItemPtr entry, const QString &url, const
|
||||||
query.next();
|
query.next();
|
||||||
|
|
||||||
if (query.value(0).toInt() != 0)
|
if (query.value(0).toInt() != 0)
|
||||||
return;
|
return false; // entry already exists
|
||||||
|
|
||||||
query.prepare(QStringLiteral("INSERT INTO Entries VALUES (:feed, :id, :title, :content, :created, :updated, :link, :read, :new, :hasEnclosure, :image);"));
|
query.prepare(QStringLiteral("INSERT INTO Entries VALUES (:feed, :id, :title, :content, :created, :updated, :link, :read, :new, :hasEnclosure, :image);"));
|
||||||
query.bindValue(QStringLiteral(":feed"), url);
|
query.bindValue(QStringLiteral(":feed"), url);
|
||||||
|
@ -225,6 +227,7 @@ void Fetcher::processEntry(Syndication::ItemPtr entry, const QString &url, const
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT entryAdded(url, entry->id());
|
Q_EMIT entryAdded(url, entry->id());
|
||||||
|
return true; // this is a new entry
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fetcher::processAuthor(const QString &url, const QString &entryId, const QString &authorName, const QString &authorUri, const QString &authorEmail)
|
void Fetcher::processAuthor(const QString &url, const QString &entryId, const QString &authorName, const QString &authorUri, const QString &authorEmail)
|
||||||
|
|
|
@ -34,7 +34,7 @@ private:
|
||||||
Fetcher();
|
Fetcher();
|
||||||
|
|
||||||
void processFeed(Syndication::FeedPtr feed, const QString &url);
|
void processFeed(Syndication::FeedPtr feed, const QString &url);
|
||||||
void processEntry(Syndication::ItemPtr entry, const QString &url, const bool &isNewFeed);
|
bool processEntry(Syndication::ItemPtr entry, const QString &url, const bool &isNewFeed); // returns true if this is a new entry; false if it already existed
|
||||||
void processAuthor(const QString &url, const QString &entryId, const QString &authorName, const QString &authorUri, const QString &authorEmail);
|
void processAuthor(const QString &url, const QString &entryId, const QString &authorName, const QString &authorUri, const QString &authorEmail);
|
||||||
void processEnclosure(Syndication::EnclosurePtr enclosure, Syndication::ItemPtr entry, const QString &feedUrl);
|
void processEnclosure(Syndication::EnclosurePtr enclosure, Syndication::ItemPtr entry, const QString &feedUrl);
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ Q_SIGNALS:
|
||||||
void startedFetchingFeed(const QString &url);
|
void startedFetchingFeed(const QString &url);
|
||||||
void feedUpdated(const QString &url);
|
void feedUpdated(const QString &url);
|
||||||
void feedDetailsUpdated(const QString &url, const QString &name, const QString &image, const QString &link, const QString &description, const QDateTime &lastUpdated);
|
void feedDetailsUpdated(const QString &url, const QString &name, const QString &image, const QString &link, const QString &description, const QDateTime &lastUpdated);
|
||||||
|
void feedUpdateFinished(const QString &url);
|
||||||
void error(const QString &url, int errorId, const QString &errorString);
|
void error(const QString &url, int errorId, const QString &errorString);
|
||||||
void entryAdded(const QString &feedurl, const QString &id);
|
void entryAdded(const QString &feedurl, const QString &id);
|
||||||
void downloadFinished(QString url) const;
|
void downloadFinished(QString url) const;
|
||||||
|
|
Loading…
Reference in New Issue