mirror of https://github.com/KDE/kasts.git
Enable entry images in listviews/listmodels
This commit is contained in:
parent
8bb027dc82
commit
bb7f3393a7
|
@ -11,11 +11,16 @@
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
#include "fetcher.h"
|
||||||
|
|
||||||
Entry::Entry(Feed *feed, QString id)
|
Entry::Entry(Feed *feed, QString id)
|
||||||
: QObject(nullptr)
|
: QObject(nullptr)
|
||||||
, m_feed(feed)
|
, m_feed(feed)
|
||||||
{
|
{
|
||||||
|
connect(&Fetcher::instance(), &Fetcher::downloadFinished, this, [this](QString url) {
|
||||||
|
if(url == m_image)
|
||||||
|
Q_EMIT imageChanged(url);
|
||||||
|
});
|
||||||
QSqlQuery entryQuery;
|
QSqlQuery entryQuery;
|
||||||
entryQuery.prepare(QStringLiteral("SELECT * FROM Entries WHERE feed=:feed AND id=:id;"));
|
entryQuery.prepare(QStringLiteral("SELECT * FROM Entries WHERE feed=:feed AND id=:id;"));
|
||||||
entryQuery.bindValue(QStringLiteral(":feed"), m_feed->url());
|
entryQuery.bindValue(QStringLiteral(":feed"), m_feed->url());
|
||||||
|
@ -46,6 +51,7 @@ Entry::Entry(Feed *feed, QString id)
|
||||||
m_hasenclosure = true;
|
m_hasenclosure = true;
|
||||||
m_enclosure = new Enclosure(this);
|
m_enclosure = new Enclosure(this);
|
||||||
}
|
}
|
||||||
|
m_image = entryQuery.value(QStringLiteral("image")).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
Entry::~Entry()
|
Entry::~Entry()
|
||||||
|
@ -155,6 +161,21 @@ bool Entry::hasEnclosure() const
|
||||||
return m_hasenclosure;
|
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
|
Feed *Entry::feed() const
|
||||||
{
|
{
|
||||||
return m_feed;
|
return m_feed;
|
||||||
|
|
|
@ -33,6 +33,7 @@ class Entry : public QObject
|
||||||
Q_PROPERTY(bool read READ read WRITE setRead NOTIFY readChanged);
|
Q_PROPERTY(bool read READ read WRITE setRead NOTIFY readChanged);
|
||||||
Q_PROPERTY(Enclosure *enclosure READ enclosure CONSTANT);
|
Q_PROPERTY(Enclosure *enclosure READ enclosure CONSTANT);
|
||||||
Q_PROPERTY(bool hasEnclosure READ hasEnclosure CONSTANT);
|
Q_PROPERTY(bool hasEnclosure READ hasEnclosure CONSTANT);
|
||||||
|
Q_PROPERTY(QString image READ image WRITE setImage NOTIFY imageChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Entry(Feed *feed, QString id);
|
Entry(Feed *feed, QString id);
|
||||||
|
@ -48,16 +49,19 @@ public:
|
||||||
bool read() const;
|
bool read() const;
|
||||||
Enclosure *enclosure() const;
|
Enclosure *enclosure() const;
|
||||||
bool hasEnclosure() const;
|
bool hasEnclosure() const;
|
||||||
|
QString image() const;
|
||||||
Feed *feed() const;
|
Feed *feed() const;
|
||||||
|
|
||||||
QString baseUrl() const;
|
QString baseUrl() const;
|
||||||
|
|
||||||
void setRead(bool read);
|
void setRead(bool read);
|
||||||
|
void setImage(const QString &url);
|
||||||
|
|
||||||
Q_INVOKABLE QString adjustedContent(int width, int fontSize);
|
Q_INVOKABLE QString adjustedContent(int width, int fontSize);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void readChanged(bool read);
|
void readChanged(bool read);
|
||||||
|
void imageChanged(const QString &url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Feed *m_feed;
|
Feed *m_feed;
|
||||||
|
@ -70,6 +74,7 @@ private:
|
||||||
QString m_link;
|
QString m_link;
|
||||||
bool m_read;
|
bool m_read;
|
||||||
Enclosure *m_enclosure = nullptr;
|
Enclosure *m_enclosure = nullptr;
|
||||||
|
QString m_image;
|
||||||
bool m_hasenclosure = false;
|
bool m_hasenclosure = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -217,7 +217,8 @@ QString Fetcher::image(const QString &url)
|
||||||
{
|
{
|
||||||
QString path = filePath(url);
|
QString path = filePath(url);
|
||||||
if (QFileInfo::exists(path)) {
|
if (QFileInfo::exists(path)) {
|
||||||
return path;
|
if (QFileInfo(path).size() != 0 )
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
download(url);
|
download(url);
|
||||||
|
|
|
@ -14,7 +14,13 @@ import org.kde.alligator 1.0
|
||||||
|
|
||||||
Kirigami.SwipeListItem {
|
Kirigami.SwipeListItem {
|
||||||
|
|
||||||
contentItem: ColumnLayout {
|
contentItem: RowLayout {
|
||||||
|
Kirigami.Icon {
|
||||||
|
source: Fetcher.image(entry.image)
|
||||||
|
height: parent.height
|
||||||
|
width: height
|
||||||
|
}
|
||||||
|
ColumnLayout {
|
||||||
spacing: 0
|
spacing: 0
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
|
@ -51,6 +57,7 @@ Kirigami.SwipeListItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
model.entry.read = true
|
model.entry.read = true
|
||||||
|
|
|
@ -86,8 +86,11 @@ Kirigami.ScrollablePage {
|
||||||
|
|
||||||
Kirigami.Icon {
|
Kirigami.Icon {
|
||||||
source: Fetcher.image(page.feed.image)
|
source: Fetcher.image(page.feed.image)
|
||||||
width: height
|
property int size: Kirigami.Units.iconSizes.large
|
||||||
height: parent.height
|
Layout.minimumWidth: size
|
||||||
|
Layout.minimumHeight: size
|
||||||
|
Layout.maximumWidth: size
|
||||||
|
Layout.maximumHeight: size
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
|
|
|
@ -22,8 +22,9 @@ Kirigami.ScrollablePage {
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
Kirigami.Icon {
|
Kirigami.Icon {
|
||||||
source: Fetcher.image(feed.image)
|
source: Fetcher.image(feed.image)
|
||||||
height: 200
|
property int size: Kirigami.Units.iconSizes.huge
|
||||||
width: height
|
Layout.minimumHeight: size
|
||||||
|
Layout.minimumWidth: size
|
||||||
}
|
}
|
||||||
Kirigami.Heading {
|
Kirigami.Heading {
|
||||||
text: feed.name
|
text: feed.name
|
||||||
|
|
|
@ -22,6 +22,7 @@ Kirigami.SwipeListItem {
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
text: model.feed.name
|
text: model.feed.name
|
||||||
icon: model.feed.refreshing ? "view-refresh" : model.feed.image === "" ? "rss" : Fetcher.image(model.feed.image)
|
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)
|
subtitle: i18np("%1 unread entry", "%1 unread entries", model.feed.unreadEntryCount)
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
|
|
@ -55,7 +55,7 @@ Item {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|
||||||
Kirigami.Icon {
|
Kirigami.Icon {
|
||||||
source: Fetcher.image(audio.entry.feed.image)
|
source: Fetcher.image(audio.entry.image)
|
||||||
Layout.preferredHeight: parent.height
|
Layout.preferredHeight: parent.height
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
Layout.leftMargin: Kirigami.Units.smallSpacing
|
Layout.leftMargin: Kirigami.Units.smallSpacing
|
||||||
|
|
|
@ -26,7 +26,7 @@ Kirigami.Page {
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
Kirigami.Icon {
|
Kirigami.Icon {
|
||||||
source: Fetcher.image(audio.entry.feed.image)
|
source: Fetcher.image(audio.entry.image)
|
||||||
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
|
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
|
||||||
Layout.preferredWidth: Math.min(parent.width, Kirigami.Units.iconSizes.enormous * 3)
|
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)
|
Layout.preferredHeight: Math.min(parent.height - 2*controls.height, Kirigami.Units.iconSizes.enormous * 3)
|
||||||
|
|
|
@ -22,6 +22,11 @@ Kirigami.SwipeListItem {
|
||||||
listView: queueList
|
listView: queueList
|
||||||
onMoveRequested: DataManager.moveQueueItem(oldIndex, newIndex)
|
onMoveRequested: DataManager.moveQueueItem(oldIndex, newIndex)
|
||||||
}
|
}
|
||||||
|
Kirigami.Icon {
|
||||||
|
source: Fetcher.image(model.entry.image)
|
||||||
|
height: parent.height
|
||||||
|
width: height
|
||||||
|
}
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
spacing: 0
|
spacing: 0
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|
Loading…
Reference in New Issue