add EntryPage

This commit is contained in:
Tobias Fella 2020-03-04 14:00:27 +01:00
parent 1b743f7983
commit 73b986933f
No known key found for this signature in database
GPG Key ID: E55EDAB3CA5D9925
9 changed files with 53 additions and 13 deletions

View File

@ -55,9 +55,9 @@ Kirigami.ScrollablePage {
delegate: Kirigami.SwipeListItem {
Controls.Label {
id: postTitle
width: parent.width
text: model.display
text: model.title
textFormat: Text.RichText
color: model.read ? Kirigami.Theme.disabledTextColor : Kirigami.Theme.textColor
}
@ -73,7 +73,7 @@ Kirigami.ScrollablePage {
onClicked: {
model.read = true;
//pageStack.push("qrc:/qml/EntryDetailsPage.qml", {"modelData": model})
pageStack.push("qrc:/EntryPage.qml", {"data": model})
}
}
}

View File

@ -0,0 +1,22 @@
import QtQuick 2.7
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.10 as Controls
import org.kde.kirigami 2.8 as Kirigami
import org.kde.alligator 1.0
Kirigami.ScrollablePage {
id: page
property QtObject data
title: data.title
ColumnLayout {
Controls.Label {
text: page.data.content
wrapMode: Text.WordWrap
Layout.fillWidth: true
}
}
}

View File

@ -22,7 +22,7 @@ import QtQuick 2.13
import QtQuick.Controls 2.10 as Controls
import QtQuick.Layouts 1.12
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kirigami 2.8 as Kirigami
import org.kde.alligator 1.0
@ -45,7 +45,7 @@ Kirigami.ScrollablePage {
id: urlField
Layout.fillWidth: true
//placeholderText: "https://example.org/feed.xml"
text: "https://rss.golem.de/rss.php?feed=RSS2.0"
text: "https://planet.kde.org/rss20.xml"
Kirigami.FormData.label: "Url"
}
Controls.Button {

View File

@ -20,8 +20,9 @@
#include "entry.h"
Entry::Entry(const QString title, const bool bookmark, const bool read)
Entry::Entry(const QString title, const QString content, const bool bookmark, const bool read)
: m_title(title)
, m_content(content)
, m_bookmark(bookmark)
, m_read(read)
{
@ -29,6 +30,7 @@ Entry::Entry(const QString title, const bool bookmark, const bool read)
Entry::Entry(const Entry &other)
: m_title(other.title())
, m_content(other.content())
, m_bookmark(other.isBookmark())
, m_read(other.isRead())
{
@ -49,6 +51,11 @@ QString Entry::title() const
return m_title;
}
QString Entry::content() const
{
return m_content;
}
void Entry::setRead(bool read)
{
m_read = read;

View File

@ -26,9 +26,10 @@ class Entry
{
public:
Entry(const Entry &);
Entry(const QString title, const bool bookmark, const bool read);
Entry(const QString title, const QString content, const bool bookmark, const bool read);
QString title() const;
QString content() const;
bool isBookmark() const;
bool isRead() const;
@ -37,6 +38,7 @@ public:
private:
QString m_title;
QString m_content;
bool m_bookmark;
bool m_read;
};

View File

@ -36,7 +36,9 @@ QVariant EntryListModel::data(const QModelIndex &index, int role) const
return m_entries[index.row()].isBookmark();
if (role == Read)
return m_entries[index.row()].isRead();
if (role == Qt::DisplayRole)
if (role == Content)
return m_entries[index.row()].content();
if (role == Title)
return m_entries[index.row()].title();
return QStringLiteral("DEADBEEF");
}
@ -47,9 +49,10 @@ int EntryListModel::rowCount(const QModelIndex &index) const
QHash<int, QByteArray> EntryListModel::roleNames() const
{
QHash<int, QByteArray> roleNames;
roleNames[Qt::DisplayRole] = "display";
roleNames[Title] = "title";
roleNames[Bookmark] = "bookmark";
roleNames[Read] = "read";
roleNames[Content] = "content";
return roleNames;
}
bool EntryListModel::setData(const QModelIndex &index, const QVariant &value, int role)
@ -72,7 +75,7 @@ void EntryListModel::fetch()
query.bindValue(QStringLiteral(":feed"), m_feed);
query.exec();
while (query.next()) {
m_entries.append(Entry(query.value(1).toString(), false, false));
m_entries.append(Entry(query.value(1).toString(), query.value(2).toString(), false, false));
}
endResetModel();
});

View File

@ -33,8 +33,10 @@ class EntryListModel : public QAbstractListModel
Q_PROPERTY(QString feed READ feed WRITE setFeed NOTIFY feedChanged)
public:
enum DataRole {
Bookmark = Qt::UserRole + 1,
Title = Qt::UserRole + 1,
Bookmark,
Read,
Content,
};
explicit EntryListModel(QObject *parent = nullptr);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

View File

@ -48,11 +48,14 @@ void Fetcher::fetch(QUrl url)
for (const auto &entry : feed->items()) {
query = QSqlQuery(db);
query.prepare(QStringLiteral("INSERT INTO Entries VALUES (:feed, :id, :title, :contents);"));
query.prepare(QStringLiteral("INSERT INTO Entries VALUES (:feed, :id, :title, :content);"));
query.bindValue(QStringLiteral(":feed"), url.toString());
query.bindValue(QStringLiteral(":id"), entry->id());
query.bindValue(QStringLiteral(":title"), entry->title());
query.bindValue(QStringLiteral(":contents"), entry->content());
if(!entry->content().isEmpty())
query.bindValue(QStringLiteral(":content"), entry->content());
else
query.bindValue(QStringLiteral(":content"), entry->description());
query.exec();
for (const auto &author : entry->authors()) {
query = QSqlQuery(db);

View File

@ -3,5 +3,6 @@
<file alias="main.qml">contents/ui/main.qml</file>
<file alias="EntryListPage.qml">contents/ui/EntryListPage.qml</file>
<file alias="FeedListPage.qml">contents/ui/FeedListPage.qml</file>
<file alias="EntryPage.qml">contents/ui/EntryPage.qml</file>
</qresource>
</RCC>