From f069871eb145be61b6ba8b76512ccbe34e5cc8ae Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Thu, 30 Apr 2020 16:17:41 +0200 Subject: [PATCH] Fix showing images in EntryPage by setting baseUrl --- src/database.cpp | 2 +- src/entryListModel.cpp | 6 ++++++ src/entryListModel.h | 2 ++ src/fetcher.cpp | 3 ++- src/qml/EntryListPage.qml | 2 +- src/qml/EntryPage.qml | 2 ++ 6 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/database.cpp b/src/database.cpp index bfab4fa6..ad09a475 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -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; diff --git a/src/entryListModel.cpp b/src/entryListModel.cpp index 615a2ec1..4a04dbb6 100644 --- a/src/entryListModel.cpp +++ b/src/entryListModel.cpp @@ -53,6 +53,7 @@ QHash 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(); +} diff --git a/src/entryListModel.h b/src/entryListModel.h index 5867b7da..47d21d77 100644 --- a/src/entryListModel.h +++ b/src/entryListModel.h @@ -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); diff --git a/src/fetcher.cpp b/src/fetcher.cpp index 587e8bf5..a92beb62 100644 --- a/src/fetcher.cpp +++ b/src/fetcher.cpp @@ -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(entry->datePublished())); query.bindValue(QStringLiteral(":updated"), static_cast(entry->dateUpdated())); + query.bindValue(QStringLiteral(":link"), entry->link()); if (!entry->content().isEmpty()) query.bindValue(QStringLiteral(":content"), entry->content()); else diff --git a/src/qml/EntryListPage.qml b/src/qml/EntryListPage.qml index 8ea403c4..25834230 100644 --- a/src/qml/EntryListPage.qml +++ b/src/qml/EntryListPage.qml @@ -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)}) } } } diff --git a/src/qml/EntryPage.qml b/src/qml/EntryPage.qml index 84c7b817..dfc8952c 100644 --- a/src/qml/EntryPage.qml +++ b/src/qml/EntryPage.qml @@ -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