From 73b986933f154d5fc99153662a5507783de46b08 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Wed, 4 Mar 2020 14:00:27 +0100 Subject: [PATCH] add EntryPage --- src/contents/ui/EntryListPage.qml | 6 +++--- src/contents/ui/EntryPage.qml | 22 ++++++++++++++++++++++ src/contents/ui/FeedListPage.qml | 4 ++-- src/entry.cpp | 9 ++++++++- src/entry.h | 4 +++- src/entryListModel.cpp | 9 ++++++--- src/entryListModel.h | 4 +++- src/fetcher.cpp | 7 +++++-- src/resources.qrc | 1 + 9 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 src/contents/ui/EntryPage.qml diff --git a/src/contents/ui/EntryListPage.qml b/src/contents/ui/EntryListPage.qml index 662480d5..6cd6402c 100755 --- a/src/contents/ui/EntryListPage.qml +++ b/src/contents/ui/EntryListPage.qml @@ -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}) } } } diff --git a/src/contents/ui/EntryPage.qml b/src/contents/ui/EntryPage.qml new file mode 100644 index 00000000..7c86ec8e --- /dev/null +++ b/src/contents/ui/EntryPage.qml @@ -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 + } + } +} diff --git a/src/contents/ui/FeedListPage.qml b/src/contents/ui/FeedListPage.qml index 24b621bc..35e2e481 100644 --- a/src/contents/ui/FeedListPage.qml +++ b/src/contents/ui/FeedListPage.qml @@ -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 { diff --git a/src/entry.cpp b/src/entry.cpp index eea5d313..3600062a 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -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; diff --git a/src/entry.h b/src/entry.h index 93eeeefa..e0a9ccc2 100644 --- a/src/entry.h +++ b/src/entry.h @@ -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; }; diff --git a/src/entryListModel.cpp b/src/entryListModel.cpp index 8aab1848..28c708fd 100644 --- a/src/entryListModel.cpp +++ b/src/entryListModel.cpp @@ -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 EntryListModel::roleNames() const { QHash 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(); }); diff --git a/src/entryListModel.h b/src/entryListModel.h index 8c85befe..e93169b1 100644 --- a/src/entryListModel.h +++ b/src/entryListModel.h @@ -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; diff --git a/src/fetcher.cpp b/src/fetcher.cpp index d0879f4d..57be9efa 100644 --- a/src/fetcher.cpp +++ b/src/fetcher.cpp @@ -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); diff --git a/src/resources.qrc b/src/resources.qrc index ca064049..f64457ac 100755 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -3,5 +3,6 @@ contents/ui/main.qml contents/ui/EntryListPage.qml contents/ui/FeedListPage.qml + contents/ui/EntryPage.qml