From 7013a7278eabf7a01b27194dd4e8bb20aca50a9d Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Tue, 17 Mar 2020 21:15:10 +0100 Subject: [PATCH] add all feeds view --- src/contents/ui/EntryListPage.qml | 1 + src/contents/ui/FeedListPage.qml | 15 +++++++++++++++ src/entryListModel.cpp | 32 +++++++++++++++++++++---------- src/entryListModel.h | 2 ++ 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/contents/ui/EntryListPage.qml b/src/contents/ui/EntryListPage.qml index 6cd6402c..ba5b724e 100755 --- a/src/contents/ui/EntryListPage.qml +++ b/src/contents/ui/EntryListPage.qml @@ -34,6 +34,7 @@ Kirigami.ScrollablePage { contextualActions: [ Kirigami.Action { text: "Details" + visible: url != "all" onTriggered: ;//pageStack.push("qrc:/qml/FeedDetailsPage.qml", {"modelData": atomModel}) } ] diff --git a/src/contents/ui/FeedListPage.qml b/src/contents/ui/FeedListPage.qml index 35e2e481..b04d7059 100644 --- a/src/contents/ui/FeedListPage.qml +++ b/src/contents/ui/FeedListPage.qml @@ -61,11 +61,26 @@ Kirigami.ScrollablePage { } ListView { + id: feedList anchors.fill: parent model: FeedListModel { id: feedListModel } + header: + Kirigami.SwipeListItem { + Controls.Label { + text: "All feeds" + } + + width: parent.width; + height: Kirigami.Units.gridUnit * 2 + onClicked: { + feedList.focus = false + pageStack.push("qrc:/EntryListPage.qml", {"name": "All feeds", "url": "all"}) + } + } + delegate: Kirigami.SwipeListItem { Controls.Label { text: model.display diff --git a/src/entryListModel.cpp b/src/entryListModel.cpp index 89f1dde7..8f0b4f54 100644 --- a/src/entryListModel.cpp +++ b/src/entryListModel.cpp @@ -24,6 +24,8 @@ #include "fetcher.h" #include "database.h" +#include "alligator-debug.h" + EntryListModel::EntryListModel(QObject *parent) : QAbstractListModel(parent) { @@ -67,18 +69,28 @@ bool EntryListModel::setData(const QModelIndex &index, const QVariant &value, in void EntryListModel::fetch() { - connect(&Fetcher::instance(), &Fetcher::finished, this, [this]() { - beginResetModel(); - QSqlQuery query; + connect(&Fetcher::instance(), &Fetcher::finished, this, &EntryListModel::update); + if(m_feed.compare("all") != 0) + Fetcher::instance().fetch(m_feed); + else + update(); +} + +void EntryListModel::update() { + beginResetModel(); + QSqlQuery query; + if(m_feed.compare("all") == 0) { + query.prepare(QStringLiteral("SELECT id, title, content FROM Entries;")); + } + else { query.prepare(QStringLiteral("SELECT id, title, content FROM Entries WHERE feed=:feed;")); query.bindValue(QStringLiteral(":feed"), m_feed); - Database::instance().execute(query); - while (query.next()) { - m_entries.append(Entry(query.value(1).toString(), query.value(2).toString(), false, false)); - } - endResetModel(); - }); - Fetcher::instance().fetch(m_feed); + } + Database::instance().execute(query); + while (query.next()) { + m_entries.append(Entry(query.value(1).toString(), query.value(2).toString(), false, false)); + } + endResetModel(); } QString EntryListModel::feed() const diff --git a/src/entryListModel.h b/src/entryListModel.h index e93169b1..9036681d 100644 --- a/src/entryListModel.h +++ b/src/entryListModel.h @@ -55,4 +55,6 @@ Q_SIGNALS: private: QVector m_entries; QString m_feed; + + void update(); };