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: [
Kirigami.Action {
text: "Details"
visible: url != "all"
onTriggered: ;//pageStack.push("qrc:/qml/FeedDetailsPage.qml", {"modelData": atomModel})
}
]

View File

@ -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

View File

@ -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]() {
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);
}
QString EntryListModel::feed() const

View File

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