mirror of https://github.com/KDE/kasts.git
Fix showing images in EntryPage by setting baseUrl
This commit is contained in:
parent
db8c6053b3
commit
f069871eb1
|
@ -58,7 +58,7 @@ bool Database::migrateTo1()
|
||||||
qDebug() << "Migrating database to version 1";
|
qDebug() << "Migrating database to version 1";
|
||||||
QSqlQuery query(QSqlDatabase::database());
|
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 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("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;")));
|
TRUE_OR_RETURN(execute(QStringLiteral("PRAGMA user_version = 1;")));
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -53,6 +53,7 @@ QHash<int, QByteArray> EntryListModel::roleNames() const
|
||||||
roleNames[Content] = "content";
|
roleNames[Content] = "content";
|
||||||
roleNames[Created] = "created";
|
roleNames[Created] = "created";
|
||||||
roleNames[Updated] = "updated";
|
roleNames[Updated] = "updated";
|
||||||
|
roleNames[Link] = "link";
|
||||||
return roleNames;
|
return roleNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,3 +78,8 @@ QString EntryListModel::image(QString url)
|
||||||
{
|
{
|
||||||
return Fetcher::instance().image(url);
|
return Fetcher::instance().image(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString EntryListModel::baseUrl(QString url)
|
||||||
|
{
|
||||||
|
return QUrl(url).adjusted(QUrl::RemovePath).toString();
|
||||||
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
Content,
|
Content,
|
||||||
Created,
|
Created,
|
||||||
Updated,
|
Updated,
|
||||||
|
Link,
|
||||||
};
|
};
|
||||||
explicit EntryListModel(QObject *parent = nullptr);
|
explicit EntryListModel(QObject *parent = nullptr);
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
@ -43,6 +44,7 @@ public:
|
||||||
|
|
||||||
Q_INVOKABLE void fetch();
|
Q_INVOKABLE void fetch();
|
||||||
Q_INVOKABLE QString image(QString url);
|
Q_INVOKABLE QString image(QString url);
|
||||||
|
Q_INVOKABLE QString baseUrl(QString url);
|
||||||
|
|
||||||
QString feed() const;
|
QString feed() const;
|
||||||
void setFeed(QString feed);
|
void setFeed(QString feed);
|
||||||
|
|
|
@ -72,12 +72,13 @@ void Fetcher::fetch(QUrl url)
|
||||||
query.next();
|
query.next();
|
||||||
if (query.value(0).toInt() != 0)
|
if (query.value(0).toInt() != 0)
|
||||||
continue;
|
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(":feed"), url.toString());
|
||||||
query.bindValue(QStringLiteral(":id"), entry->id());
|
query.bindValue(QStringLiteral(":id"), entry->id());
|
||||||
query.bindValue(QStringLiteral(":title"), entry->title());
|
query.bindValue(QStringLiteral(":title"), entry->title());
|
||||||
query.bindValue(QStringLiteral(":created"), static_cast<int>(entry->datePublished()));
|
query.bindValue(QStringLiteral(":created"), static_cast<int>(entry->datePublished()));
|
||||||
query.bindValue(QStringLiteral(":updated"), static_cast<int>(entry->dateUpdated()));
|
query.bindValue(QStringLiteral(":updated"), static_cast<int>(entry->dateUpdated()));
|
||||||
|
query.bindValue(QStringLiteral(":link"), entry->link());
|
||||||
if (!entry->content().isEmpty())
|
if (!entry->content().isEmpty())
|
||||||
query.bindValue(QStringLiteral(":content"), entry->content());
|
query.bindValue(QStringLiteral(":content"), entry->content());
|
||||||
else
|
else
|
||||||
|
|
|
@ -105,7 +105,7 @@ Kirigami.ScrollablePage {
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
model.read = true;
|
model.read = true;
|
||||||
pageStack.push("qrc:/EntryPage.qml", {"data": model})
|
pageStack.push("qrc:/EntryPage.qml", {"data": model, "baseUrl": entryListModel.baseUrl(model.link)})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,11 +29,13 @@ import org.kde.alligator 1.0
|
||||||
Kirigami.ScrollablePage {
|
Kirigami.ScrollablePage {
|
||||||
id: page
|
id: page
|
||||||
property QtObject data
|
property QtObject data
|
||||||
|
property alias baseUrl: label.baseUrl
|
||||||
|
|
||||||
title: data.title
|
title: data.title
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
Controls.Label {
|
Controls.Label {
|
||||||
|
id: label
|
||||||
text: page.data.content
|
text: page.data.content
|
||||||
textFormat: Text.RichText
|
textFormat: Text.RichText
|
||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
|
|
Loading…
Reference in New Issue