Update name when fetched

This commit is contained in:
Tobias Fella 2020-03-06 22:45:17 +01:00
parent 764fc4b982
commit 8639518e6d
No known key found for this signature in database
GPG Key ID: E55EDAB3CA5D9925
1 changed files with 19 additions and 0 deletions

View File

@ -21,12 +21,15 @@
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QUrl>
#include <QSqlError>
#include <Syndication/Syndication>
#include "feedListModel.h"
#include "fetcher.h"
#include <iostream>
FeedListModel::FeedListModel(QObject *parent)
: QAbstractListModel(parent)
{
@ -62,6 +65,22 @@ int FeedListModel::rowCount(const QModelIndex &index) const
void FeedListModel::addFeed(QString url)
{
connect(&Fetcher::instance(), &Fetcher::finished, this, [this, url]() {
QSqlQuery query(QSqlDatabase::database());
query.prepare(QStringLiteral("SELECT name FROM Feeds WHERE url=:url;"));
query.bindValue(QStringLiteral(":url"), url);
query.exec();
if(!query.next())
std::cout << "Query empty" << std::endl;
for(int i = 0; i < feeds.length(); i++) {
if(feeds[i].url() == url) {
feeds.removeAt(i);
feeds.insert(i, Feed(url, query.value(0).toString()));
emit dataChanged(index(i), index(i));
break;
}
}
});
Fetcher::instance().fetch(QUrl(url));
beginInsertRows(QModelIndex(), feeds.size(), feeds.size());
feeds.append(Feed(url));