From 03573e69c239740e0d6d0260f891e6a170f79062 Mon Sep 17 00:00:00 2001 From: Bart De Vries Date: Fri, 2 Apr 2021 15:53:51 +0200 Subject: [PATCH] Minor improvements --- src/qml/EntryPage.qml | 6 ++++++ src/qml/FeedListPage.qml | 2 +- src/qml/QueuePage.qml | 6 ++---- src/qml/main.qml | 5 +++++ src/queuemodel.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/queuemodel.h | 3 ++- 6 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/qml/EntryPage.qml b/src/qml/EntryPage.qml index b2adcffb..f0bbaaa2 100644 --- a/src/qml/EntryPage.qml +++ b/src/qml/EntryPage.qml @@ -56,4 +56,10 @@ Kirigami.ScrollablePage { else entry.enclosure.deleteFile() } } + actions.right: Kirigami.Action { + text: "Add to queue" + icon.name: "media-playlist-append" + visible: entry.enclosure + onTriggered: { queueModel.addEntry(entry.feed.url, entry.id) } + } } diff --git a/src/qml/FeedListPage.qml b/src/qml/FeedListPage.qml index b8a7ffb4..94c72aa2 100644 --- a/src/qml/FeedListPage.qml +++ b/src/qml/FeedListPage.qml @@ -14,7 +14,7 @@ import org.kde.kirigami 2.12 as Kirigami import org.kde.alligator 1.0 Kirigami.ScrollablePage { - title: "Subscriptions" + title: i18n("Subscriptions") property var lastFeed: "" diff --git a/src/qml/QueuePage.qml b/src/qml/QueuePage.qml index d82553e4..c2bcc7da 100644 --- a/src/qml/QueuePage.qml +++ b/src/qml/QueuePage.qml @@ -14,7 +14,7 @@ import org.kde.alligator 1.0 Kirigami.ScrollablePage { id: queuepage - title: "Queue" + title: i18n("Queue") Component { id: delegateComponent Kirigami.SwipeListItem { @@ -55,12 +55,10 @@ Kirigami.ScrollablePage { } } - QueueModel { id: queueModel } - ListView { id: mainList - model: queueModel + model: root.queueModel moveDisplaced: Transition { YAnimator { diff --git a/src/qml/main.qml b/src/qml/main.qml index 768a8f67..054dec0e 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -40,6 +40,7 @@ Kirigami.ApplicationWindow { pageStack.push(feedList) } }, + Kirigami.Action{ separator: true }, Kirigami.Action { text: i18n("Settings") iconName: "settings-configure" @@ -70,6 +71,10 @@ Kirigami.ApplicationWindow { id: feedList } + QueueModel { + id: queueModel + } + QueuePage { id: queuelist } diff --git a/src/queuemodel.cpp b/src/queuemodel.cpp index 8394de16..c323fbb0 100644 --- a/src/queuemodel.cpp +++ b/src/queuemodel.cpp @@ -32,6 +32,8 @@ QueueModel::QueueModel(QObject *parent) void QueueModel::updateQueue() { + +/* QSqlQuery query; query.prepare(QStringLiteral("SELECT * FROM Enclosures")); Database::instance().execute(query); @@ -89,6 +91,7 @@ void QueueModel::updateQueue() m_entries.append(entry); } } + */ } QueueModel::~QueueModel() @@ -140,3 +143,39 @@ bool QueueModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int co return true; } + +void QueueModel::addEntry(QString feedurl, QString id) { + qDebug() << feedurl << id; + + QSqlQuery feedQuery; + feedQuery.prepare(QStringLiteral("SELECT * FROM Feeds WHERE url=:feedurl")); + feedQuery.bindValue(QStringLiteral(":feedurl"), feedurl); + Database::instance().execute(feedQuery); + if (!feedQuery.next()) { + qWarning() << "Feed not found:" << feedurl; + // TODO: remove enclosures belonging to non-existent feed + return; + } + int feed_index = feedQuery.value(QStringLiteral("rowid")).toInt() - 1; + qDebug() << feed_index << feedurl; + Feed* feed = new Feed(feed_index); + + // Find query index + QSqlQuery entryQuery; + entryQuery.prepare(QStringLiteral("SELECT rowid FROM Entries WHERE feed=:feedurl ORDER BY updated;")); + entryQuery.bindValue(QStringLiteral(":feedurl"), feedurl); + Database::instance().execute(entryQuery); + int counter = -1; + int entry_index = -1; + while (entryQuery.next()) { + counter++; + QString idquery = entryQuery.value(QStringLiteral("id")).toString(); + if (idquery == id) entry_index = counter; + } + if (entry_index == -1) return; + + beginInsertRows(QModelIndex(), rowCount(QModelIndex()) - 1, rowCount(QModelIndex()) - 1); + m_entries.append(new Entry(feed, entry_index)); + endInsertRows(); + return; +} diff --git a/src/queuemodel.h b/src/queuemodel.h index 0bccbcdc..caf58064 100644 --- a/src/queuemodel.h +++ b/src/queuemodel.h @@ -26,9 +26,10 @@ public: Q_INVOKABLE bool move(int from, int to); Q_INVOKABLE bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override; + Q_INVOKABLE void addEntry(QString feedurl, QString id); private: void updateQueue(); - mutable QList m_entries; + mutable QVector m_entries; };