Almost done with complete refactoring (no queue yet)

This commit is contained in:
Bart De Vries 2021-04-03 11:44:08 +02:00
parent 2a9fc8e0a9
commit 0808d3b5fe
6 changed files with 33 additions and 9 deletions

View File

@ -27,9 +27,27 @@ DataManager::DataManager()
m_feeds[url]->setLastUpdated(lastUpdated);
// TODO: signal feedmodel: Q_EMIT dataChanged(createIndex(i, 0), createIndex(i, 0));
});
connect(&Fetcher::instance(), &Fetcher::feedUpdated, this, [this](const QString &url) {
// TODO: make DataManager rescan entries
Q_EMIT feedEntriesUpdated(url);
connect(&Fetcher::instance(), &Fetcher::entryAdded, this, [this](const QString &feedurl, const QString &id) {
// Only add the new entry to m_entries
// we will repopulate m_entrymap once all new entries have been added,
// such that m_entrymap will show all new entries in the correct order
m_entries[id] = nullptr;
Q_EMIT entryAdded(feedurl, id);
});
connect(&Fetcher::instance(), &Fetcher::feedUpdated, this, [this](const QString &feedurl) {
// Update m_entrymap for feedurl, such that the new and old entries show
// up in the correct order
// TODO: put this code into a separate method and re-use this in the constructor
QSqlQuery query;
m_entrymap[feedurl].clear();
query.prepare(QStringLiteral("SELECT id FROM Entries WHERE feed=:feed ORDER BY updated DESC;"));
query.bindValue(QStringLiteral(":feed"), feedurl);
Database::instance().execute(query);
while (query.next()) {
m_entrymap[feedurl] += query.value(QStringLiteral("id")).toString();
qDebug() << m_entrymap[feedurl];
}
Q_EMIT feedEntriesUpdated(feedurl);
});
// Only read unique feedurls and entry ids from the database.
@ -43,11 +61,12 @@ DataManager::DataManager()
qDebug() << m_feedmap;
for (auto &feedurl : m_feedmap) {
query.prepare(QStringLiteral("SELECT id FROM Entries WHERE feed=:feed ORDER BY updated;"));
query.prepare(QStringLiteral("SELECT id FROM Entries WHERE feed=:feed ORDER BY updated DESC;"));
query.bindValue(QStringLiteral(":feed"), feedurl);
Database::instance().execute(query);
while (query.next()) {
m_entrymap[feedurl] += query.value(QStringLiteral("id")).toString();
m_entries[query.value(QStringLiteral("id")).toString()] = nullptr;
qDebug() << m_entrymap[feedurl];
}
}
@ -143,7 +162,9 @@ void DataManager::removeFeed(const int &index)
query.bindValue(QStringLiteral(":url"), feed->url());
Database::instance().execute(query);
// Then delete the instances and mappings
// TODO: delete files: enclosure files and images
// Then delete the object instances and mappings
for (auto& id : m_entrymap[feed->url()]) {
delete m_entries[id]; // delete pointer
m_entries.remove(id); // delete the hash key

View File

@ -43,8 +43,8 @@ public:
Q_SIGNALS:
void feedAdded(const QString &url);
void feedRemoved(const int &index);
void entryAdded(const QString &id);
void entryRemoved(const Feed*, const int &index);
void entryAdded(const QString &feedurl, const QString &id);
void entryRemoved(const Feed*, const int &index); // TODO: implement this method
void feedEntriesUpdated(const QString &url);
private:

View File

@ -17,10 +17,12 @@ EntriesModel::EntriesModel(Feed *feed)
: QAbstractListModel(feed)
, m_feed(feed)
{
// When feed is updated, the entire model needs to be reset because we
// cannot know where the new entries will be inserted into the list (or that
// maybe even items have been removed.
connect(&DataManager::instance(), &DataManager::feedEntriesUpdated, this, [this](const QString &url) {
if (m_feed->url() == url) {
beginResetModel();
// TODO: make sure to pop the entrylistpage if it's the active one
endResetModel();
}
});

View File

@ -133,6 +133,7 @@ void Fetcher::processEntry(Syndication::ItemPtr entry, const QString &url)
for (const auto &enclosure : entry->enclosures()) {
processEnclosure(enclosure, entry, url);
}
Q_EMIT entryAdded(url, entry->id());
}
void Fetcher::processAuthor(Syndication::PersonPtr author, const QString &entryId, const QString &url)

View File

@ -44,5 +44,6 @@ Q_SIGNALS:
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 error(const QString &url, int errorId, const QString &errorString);
void entryAdded(const QString &feedurl, const QString &id);
void downloadFinished(QString url);
};

View File

@ -40,7 +40,6 @@ Kirigami.ApplicationWindow {
pageStack.push(feedList)
}
},
Kirigami.Action{ separator: true },
Kirigami.Action {
text: i18n("Settings")
iconName: "settings-configure"