diff --git a/src/entry.cpp b/src/entry.cpp index 81bf5b3c..bf56bb46 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -11,11 +11,16 @@ #include #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; diff --git a/src/entry.h b/src/entry.h index 932d9689..e604676b 100644 --- a/src/entry.h +++ b/src/entry.h @@ -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; }; diff --git a/src/fetcher.cpp b/src/fetcher.cpp index 002b4609..e7bb82e4 100644 --- a/src/fetcher.cpp +++ b/src/fetcher.cpp @@ -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); diff --git a/src/qml/EntryListDelegate.qml b/src/qml/EntryListDelegate.qml index 2f8c5a0c..d16ed200 100644 --- a/src/qml/EntryListDelegate.qml +++ b/src/qml/EntryListDelegate.qml @@ -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 diff --git a/src/qml/EntryListPage.qml b/src/qml/EntryListPage.qml index a4319f46..7bf8cf38 100644 --- a/src/qml/EntryListPage.qml +++ b/src/qml/EntryListPage.qml @@ -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 { diff --git a/src/qml/FeedDetailsPage.qml b/src/qml/FeedDetailsPage.qml index 88d2d30b..c99aa235 100644 --- a/src/qml/FeedDetailsPage.qml +++ b/src/qml/FeedDetailsPage.qml @@ -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 diff --git a/src/qml/FeedListDelegate.qml b/src/qml/FeedListDelegate.qml index fbb18f45..5cf3d535 100644 --- a/src/qml/FeedListDelegate.qml +++ b/src/qml/FeedListDelegate.qml @@ -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: { diff --git a/src/qml/MinimizedPlayerControls.qml b/src/qml/MinimizedPlayerControls.qml index afdc3f07..7241d447 100644 --- a/src/qml/MinimizedPlayerControls.qml +++ b/src/qml/MinimizedPlayerControls.qml @@ -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 diff --git a/src/qml/PlayerControls.qml b/src/qml/PlayerControls.qml index 21b96332..82ef8e31 100644 --- a/src/qml/PlayerControls.qml +++ b/src/qml/PlayerControls.qml @@ -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) diff --git a/src/qml/QueueDelegate.qml b/src/qml/QueueDelegate.qml index 21fc272a..9372e75c 100644 --- a/src/qml/QueueDelegate.qml +++ b/src/qml/QueueDelegate.qml @@ -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