Fix showing images in EntryPage by setting baseUrl

This commit is contained in:
Tobias Fella 2020-04-30 16:17:41 +02:00
parent db8c6053b3
commit f069871eb1
6 changed files with 14 additions and 3 deletions

View File

@ -58,7 +58,7 @@ bool Database::migrateTo1()
qDebug() << "Migrating database to version 1";
QSqlQuery query(QSqlDatabase::database());
TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Feeds (name TEXT, url TEXT, image TEXT);")));
TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Entries (feed TEXT, id TEXT UNIQUE, title TEXT, content TEXT, created INTEGER, updated INTEGER);")));
TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Entries (feed TEXT, id TEXT UNIQUE, title TEXT, content TEXT, created INTEGER, updated INTEGER, link TEXT);")));
TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Authors (feed TEXT, id TEXT, name TEXT, uri TEXT, email TEXT);")));
TRUE_OR_RETURN(execute(QStringLiteral("PRAGMA user_version = 1;")));
return true;

View File

@ -53,6 +53,7 @@ QHash<int, QByteArray> EntryListModel::roleNames() const
roleNames[Content] = "content";
roleNames[Created] = "created";
roleNames[Updated] = "updated";
roleNames[Link] = "link";
return roleNames;
}
@ -77,3 +78,8 @@ QString EntryListModel::image(QString url)
{
return Fetcher::instance().image(url);
}
QString EntryListModel::baseUrl(QString url)
{
return QUrl(url).adjusted(QUrl::RemovePath).toString();
}

View File

@ -36,6 +36,7 @@ public:
Content,
Created,
Updated,
Link,
};
explicit EntryListModel(QObject *parent = nullptr);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
@ -43,6 +44,7 @@ public:
Q_INVOKABLE void fetch();
Q_INVOKABLE QString image(QString url);
Q_INVOKABLE QString baseUrl(QString url);
QString feed() const;
void setFeed(QString feed);

View File

@ -72,12 +72,13 @@ void Fetcher::fetch(QUrl url)
query.next();
if (query.value(0).toInt() != 0)
continue;
query.prepare(QStringLiteral("INSERT INTO Entries VALUES (:feed, :id, :title, :content, :created, :updated);"));
query.prepare(QStringLiteral("INSERT INTO Entries VALUES (:feed, :id, :title, :content, :created, :updated, :link);"));
query.bindValue(QStringLiteral(":feed"), url.toString());
query.bindValue(QStringLiteral(":id"), entry->id());
query.bindValue(QStringLiteral(":title"), entry->title());
query.bindValue(QStringLiteral(":created"), static_cast<int>(entry->datePublished()));
query.bindValue(QStringLiteral(":updated"), static_cast<int>(entry->dateUpdated()));
query.bindValue(QStringLiteral(":link"), entry->link());
if (!entry->content().isEmpty())
query.bindValue(QStringLiteral(":content"), entry->content());
else

View File

@ -105,7 +105,7 @@ Kirigami.ScrollablePage {
onClicked: {
model.read = true;
pageStack.push("qrc:/EntryPage.qml", {"data": model})
pageStack.push("qrc:/EntryPage.qml", {"data": model, "baseUrl": entryListModel.baseUrl(model.link)})
}
}
}

View File

@ -29,11 +29,13 @@ import org.kde.alligator 1.0
Kirigami.ScrollablePage {
id: page
property QtObject data
property alias baseUrl: label.baseUrl
title: data.title
ColumnLayout {
Controls.Label {
id: label
text: page.data.content
textFormat: Text.RichText
wrapMode: Text.WordWrap