add all feeds view

This commit is contained in:
Tobias Fella 2020-03-17 21:15:10 +01:00
parent a6f6969912
commit 7013a7278e
No known key found for this signature in database
GPG Key ID: E55EDAB3CA5D9925
4 changed files with 40 additions and 10 deletions

View File

@ -34,6 +34,7 @@ Kirigami.ScrollablePage {
contextualActions: [ contextualActions: [
Kirigami.Action { Kirigami.Action {
text: "Details" text: "Details"
visible: url != "all"
onTriggered: ;//pageStack.push("qrc:/qml/FeedDetailsPage.qml", {"modelData": atomModel}) onTriggered: ;//pageStack.push("qrc:/qml/FeedDetailsPage.qml", {"modelData": atomModel})
} }
] ]

View File

@ -61,11 +61,26 @@ Kirigami.ScrollablePage {
} }
ListView { ListView {
id: feedList
anchors.fill: parent anchors.fill: parent
model: FeedListModel { model: FeedListModel {
id: 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 { delegate: Kirigami.SwipeListItem {
Controls.Label { Controls.Label {
text: model.display text: model.display

View File

@ -24,6 +24,8 @@
#include "fetcher.h" #include "fetcher.h"
#include "database.h" #include "database.h"
#include "alligator-debug.h"
EntryListModel::EntryListModel(QObject *parent) EntryListModel::EntryListModel(QObject *parent)
: QAbstractListModel(parent) : QAbstractListModel(parent)
{ {
@ -67,18 +69,28 @@ bool EntryListModel::setData(const QModelIndex &index, const QVariant &value, in
void EntryListModel::fetch() void EntryListModel::fetch()
{ {
connect(&Fetcher::instance(), &Fetcher::finished, this, [this]() { connect(&Fetcher::instance(), &Fetcher::finished, this, &EntryListModel::update);
beginResetModel(); if(m_feed.compare("all") != 0)
QSqlQuery query; 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.prepare(QStringLiteral("SELECT id, title, content FROM Entries WHERE feed=:feed;"));
query.bindValue(QStringLiteral(":feed"), m_feed); query.bindValue(QStringLiteral(":feed"), m_feed);
Database::instance().execute(query); }
while (query.next()) { Database::instance().execute(query);
m_entries.append(Entry(query.value(1).toString(), query.value(2).toString(), false, false)); while (query.next()) {
} m_entries.append(Entry(query.value(1).toString(), query.value(2).toString(), false, false));
endResetModel(); }
}); endResetModel();
Fetcher::instance().fetch(m_feed);
} }
QString EntryListModel::feed() const QString EntryListModel::feed() const

View File

@ -55,4 +55,6 @@ Q_SIGNALS:
private: private:
QVector<Entry> m_entries; QVector<Entry> m_entries;
QString m_feed; QString m_feed;
void update();
}; };