From 5efd4f85f8777cf824505cac205dcbbb25b4483f Mon Sep 17 00:00:00 2001 From: Bart De Vries Date: Tue, 6 Apr 2021 23:01:26 +0200 Subject: [PATCH] Optimize image loading (partially) and improve QueueDelegate --- src/entriesmodel.cpp | 2 +- src/qml/EntryListDelegate.qml | 77 +++++++++++++++++++---------------- src/qml/FeedListDelegate.qml | 14 +++---- src/qml/QueueDelegate.qml | 35 +++++++++++----- 4 files changed, 73 insertions(+), 55 deletions(-) diff --git a/src/entriesmodel.cpp b/src/entriesmodel.cpp index 18818c3b..c0386d52 100644 --- a/src/entriesmodel.cpp +++ b/src/entriesmodel.cpp @@ -32,7 +32,7 @@ QVariant EntriesModel::data(const QModelIndex &index, int role) const { if (role != 0) return QVariant(); - qDebug() << "fetching item" << index.row(); + //qDebug() << "fetching item" << index.row(); return QVariant::fromValue(DataManager::instance().getEntry(m_feed, index.row())); } diff --git a/src/qml/EntryListDelegate.qml b/src/qml/EntryListDelegate.qml index 7cbed50a..c32a20de 100644 --- a/src/qml/EntryListDelegate.qml +++ b/src/qml/EntryListDelegate.qml @@ -15,49 +15,54 @@ import org.kde.alligator 1.0 Kirigami.SwipeListItem { contentItem: RowLayout { - Kirigami.Icon { - source: entry.image === "" ? "rss" : Fetcher.image(entry.image) - height: parent.height - width: height + Image { + asynchronous: true + source: entry.image === "" ? "rss" : "file://"+Fetcher.image(entry.image) + fillMode: Image.PreserveAspectFit + property int size: Kirigami.Units.iconSizes.medium + Layout.maximumHeight: size + Layout.maximumWidth: size + sourceSize.width: size + sourceSize.height: size } - ColumnLayout { - spacing: 0 - Layout.fillWidth: true - Layout.alignment: Qt.AlignVCenter - Controls.Label { - text: entry.title + ColumnLayout { + spacing: 0 Layout.fillWidth: true - elide: Text.ElideRight - font.weight: entry.read ? Font.Normal : Font.Bold - opacity: 1 - } - Loader { - sourceComponent: entry.enclosure && entry.enclosure.status === Enclosure.Downloading ? downloadProgress : subtitle - Layout.fillWidth: true - Component { - id: subtitle - Controls.Label { - text: entry.updated.toLocaleString(Qt.locale(), Locale.ShortFormat) + (entry.authors.length === 0 ? "" : " " + i18nc("by ", "by") + " " + entry.authors[0].name) - Layout.fillWidth: true - elide: Text.ElideRight - font: Kirigami.Theme.smallFont - opacity: entry.read ? 0.7 : 0.9 - visible: !downloadProgress.visible - } + Layout.alignment: Qt.AlignVCenter + Controls.Label { + text: entry.title + Layout.fillWidth: true + elide: Text.ElideRight + font.weight: entry.read ? Font.Normal : Font.Bold + opacity: 1 } - Component { - id: downloadProgress - Controls.ProgressBar { - from: 0 - to: 100 - value: entry.enclosure.downloadProgress - visible: entry.enclosure && entry.enclosure.status === Enclosure.Downloading - Layout.fillWidth: true + Loader { + sourceComponent: entry.enclosure && entry.enclosure.status === Enclosure.Downloading ? downloadProgress : subtitle + Layout.fillWidth: true + Component { + id: subtitle + Controls.Label { + text: entry.updated.toLocaleString(Qt.locale(), Locale.ShortFormat) + (entry.authors.length === 0 ? "" : " " + i18nc("by ", "by") + " " + entry.authors[0].name) + Layout.fillWidth: true + elide: Text.ElideRight + font: Kirigami.Theme.smallFont + opacity: entry.read ? 0.7 : 0.9 + visible: !downloadProgress.visible + } + } + Component { + id: downloadProgress + Controls.ProgressBar { + from: 0 + to: 100 + value: entry.enclosure.downloadProgress + visible: entry.enclosure && entry.enclosure.status === Enclosure.Downloading + Layout.fillWidth: true + } } } } } -} onClicked: { entry.read = true diff --git a/src/qml/FeedListDelegate.qml b/src/qml/FeedListDelegate.qml index 5cf3d535..1e543a09 100644 --- a/src/qml/FeedListDelegate.qml +++ b/src/qml/FeedListDelegate.qml @@ -20,15 +20,15 @@ Kirigami.SwipeListItem { contentItem: Kirigami.BasicListItem { anchors.top: parent.top 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) + text: feed.name + icon: feed.refreshing ? "view-refresh" : feed.image === "" ? "rss" : Fetcher.image(feed.image) + iconSize: Kirigami.Units.iconSizes.medium + subtitle: i18np("%1 unread entry", "%1 unread entries", feed.unreadEntryCount) onClicked: { - lastFeed = model.feed.url + lastFeed = feed.url - pageStack.push("qrc:/EntryListPage.qml", {"feed": model.feed}) + pageStack.push("qrc:/EntryListPage.qml", {"feed": feed}) } } @@ -36,7 +36,7 @@ Kirigami.SwipeListItem { Kirigami.Action { icon.name: "delete" onTriggered: { - if(pageStack.depth > 1 && model.feed.url === lastFeed) + if(pageStack.depth > 1 && feed.url === lastFeed) while(pageStack.depth > 1) pageStack.pop() feedsModel.removeFeed(index) diff --git a/src/qml/QueueDelegate.qml b/src/qml/QueueDelegate.qml index aab59ec7..14191472 100644 --- a/src/qml/QueueDelegate.qml +++ b/src/qml/QueueDelegate.qml @@ -22,21 +22,33 @@ Kirigami.SwipeListItem { listView: queueList onMoveRequested: DataManager.moveQueueItem(oldIndex, newIndex) } - Kirigami.Icon { - source: entry.image === "" ? "rss" : Fetcher.image(entry.image) - property int size: Kirigami.Units.iconSizes.medium - Layout.minimumHeight: size - Layout.minimumWidth: size + Image { + asynchronous: true + source: entry.image === "" ? "rss" : "file://"+Fetcher.image(entry.image) + fillMode: Image.PreserveAspectFit + property int size: Kirigami.Units.gridUnit * 3 + sourceSize.width: size + sourceSize.height: size + Layout.maximumHeight: size + Layout.maximumWidth: size + Layout.rightMargin:Kirigami.Units.smallSpacing } ColumnLayout { - spacing: 0 + spacing: Kirigami.Units.smallSpacing Layout.fillWidth: true Layout.alignment: Qt.AlignVCenter + Controls.Label { + text: entry.updated.toLocaleDateString(Qt.locale(), Locale.NarrowFormat) + (entry.enclosure ? " ยท " + Math.floor(entry.enclosure.size/(1024*1024)) + "MB" : "") + Layout.fillWidth: true + elide: Text.ElideRight + font: Kirigami.Theme.smallFont + opacity: 0.7 + } Controls.Label { text: entry.title Layout.fillWidth: true elide: Text.ElideRight - font.weight: entry.read ? Font.Normal : Font.Bold + font.weight: Font.Normal opacity: 1 } Loader { @@ -45,11 +57,11 @@ Kirigami.SwipeListItem { Component { id: subtitle Controls.Label { - text: entry.updated.toLocaleString(Qt.locale(), Locale.ShortFormat) + (entry.authors.length === 0 ? "" : " " + i18nc("by ", "by") + " " + entry.authors[0].name) + text: (Math.floor(entry.enclosure.duration/3600) < 10 ? "0" : "") + Math.floor(entry.enclosure.duration/3600) + ":" + (Math.floor(entry.enclosure.duration/60) % 60 < 10 ? "0" : "") + Math.floor(entry.enclosure.duration/60) % 60 + ":" + (Math.floor(entry.enclosure.duration) % 60 < 10 ? "0" : "") + Math.floor(entry.enclosure.duration) % 60 Layout.fillWidth: true elide: Text.ElideRight font: Kirigami.Theme.smallFont - opacity: entry.read ? 0.7 : 0.9 + opacity: 0.7 visible: !downloadProgress.visible } } @@ -77,9 +89,10 @@ Kirigami.SwipeListItem { iconName: "media-playback-start" text: "Play" onTriggered: { - audio.entry = entry - audio.play() + audio.entry = entry + audio.play() } + visible: entry.enclosure && entry.enclosure.status === Enclosure.Downloaded }, Kirigami.Action { text: i18n("Download")