Enable entry images in listviews/listmodels

This commit is contained in:
Bart De Vries 2021-04-05 14:15:44 +02:00
parent 8bb027dc82
commit bb7f3393a7
10 changed files with 52 additions and 8 deletions

View File

@ -11,11 +11,16 @@
#include <QUrl>
#include "database.h"
#include "fetcher.h"
Entry::Entry(Feed *feed, QString id)
: QObject(nullptr)
, m_feed(feed)
{
connect(&Fetcher::instance(), &Fetcher::downloadFinished, this, [this](QString url) {
if(url == m_image)
Q_EMIT imageChanged(url);
});
QSqlQuery entryQuery;
entryQuery.prepare(QStringLiteral("SELECT * FROM Entries WHERE feed=:feed AND id=:id;"));
entryQuery.bindValue(QStringLiteral(":feed"), m_feed->url());
@ -46,6 +51,7 @@ Entry::Entry(Feed *feed, QString id)
m_hasenclosure = true;
m_enclosure = new Enclosure(this);
}
m_image = entryQuery.value(QStringLiteral("image")).toString();
}
Entry::~Entry()
@ -155,6 +161,21 @@ bool Entry::hasEnclosure() const
return m_hasenclosure;
}
QString Entry::image() const
{
if (!m_image.isEmpty()) {
return m_image;
} else {
return m_feed->image();
}
}
void Entry::setImage(const QString &image)
{
m_image = image;
Q_EMIT imageChanged(m_image);
}
Feed *Entry::feed() const
{
return m_feed;

View File

@ -33,6 +33,7 @@ class Entry : public QObject
Q_PROPERTY(bool read READ read WRITE setRead NOTIFY readChanged);
Q_PROPERTY(Enclosure *enclosure READ enclosure CONSTANT);
Q_PROPERTY(bool hasEnclosure READ hasEnclosure CONSTANT);
Q_PROPERTY(QString image READ image WRITE setImage NOTIFY imageChanged)
public:
Entry(Feed *feed, QString id);
@ -48,16 +49,19 @@ public:
bool read() const;
Enclosure *enclosure() const;
bool hasEnclosure() const;
QString image() const;
Feed *feed() const;
QString baseUrl() const;
void setRead(bool read);
void setImage(const QString &url);
Q_INVOKABLE QString adjustedContent(int width, int fontSize);
Q_SIGNALS:
void readChanged(bool read);
void imageChanged(const QString &url);
private:
Feed *m_feed;
@ -70,6 +74,7 @@ private:
QString m_link;
bool m_read;
Enclosure *m_enclosure = nullptr;
QString m_image;
bool m_hasenclosure = false;
};

View File

@ -217,7 +217,8 @@ QString Fetcher::image(const QString &url)
{
QString path = filePath(url);
if (QFileInfo::exists(path)) {
return path;
if (QFileInfo(path).size() != 0 )
return path;
}
download(url);

View File

@ -14,7 +14,13 @@ import org.kde.alligator 1.0
Kirigami.SwipeListItem {
contentItem: ColumnLayout {
contentItem: RowLayout {
Kirigami.Icon {
source: Fetcher.image(entry.image)
height: parent.height
width: height
}
ColumnLayout {
spacing: 0
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
@ -51,6 +57,7 @@ Kirigami.SwipeListItem {
}
}
}
}
onClicked: {
model.entry.read = true

View File

@ -86,8 +86,11 @@ Kirigami.ScrollablePage {
Kirigami.Icon {
source: Fetcher.image(page.feed.image)
width: height
height: parent.height
property int size: Kirigami.Units.iconSizes.large
Layout.minimumWidth: size
Layout.minimumHeight: size
Layout.maximumWidth: size
Layout.maximumHeight: size
}
ColumnLayout {

View File

@ -22,8 +22,9 @@ Kirigami.ScrollablePage {
ColumnLayout {
Kirigami.Icon {
source: Fetcher.image(feed.image)
height: 200
width: height
property int size: Kirigami.Units.iconSizes.huge
Layout.minimumHeight: size
Layout.minimumWidth: size
}
Kirigami.Heading {
text: feed.name

View File

@ -22,6 +22,7 @@ Kirigami.SwipeListItem {
anchors.bottom: parent.bottom
text: model.feed.name
icon: model.feed.refreshing ? "view-refresh" : model.feed.image === "" ? "rss" : Fetcher.image(model.feed.image)
iconSize: Kirigami.Units.iconSizes.large
subtitle: i18np("%1 unread entry", "%1 unread entries", model.feed.unreadEntryCount)
onClicked: {

View File

@ -55,7 +55,7 @@ Item {
Layout.fillWidth: true
Kirigami.Icon {
source: Fetcher.image(audio.entry.feed.image)
source: Fetcher.image(audio.entry.image)
Layout.preferredHeight: parent.height
Layout.alignment: Qt.AlignVCenter
Layout.leftMargin: Kirigami.Units.smallSpacing

View File

@ -26,7 +26,7 @@ Kirigami.Page {
ColumnLayout {
anchors.fill: parent
Kirigami.Icon {
source: Fetcher.image(audio.entry.feed.image)
source: Fetcher.image(audio.entry.image)
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
Layout.preferredWidth: Math.min(parent.width, Kirigami.Units.iconSizes.enormous * 3)
Layout.preferredHeight: Math.min(parent.height - 2*controls.height, Kirigami.Units.iconSizes.enormous * 3)

View File

@ -22,6 +22,11 @@ Kirigami.SwipeListItem {
listView: queueList
onMoveRequested: DataManager.moveQueueItem(oldIndex, newIndex)
}
Kirigami.Icon {
source: Fetcher.image(model.entry.image)
height: parent.height
width: height
}
ColumnLayout {
spacing: 0
Layout.fillWidth: true