mirror of https://github.com/KDE/kasts.git
save and show image
This commit is contained in:
parent
fed096f96c
commit
fb7d52aa48
|
@ -19,7 +19,8 @@
|
|||
*/
|
||||
|
||||
import QtQuick 2.7
|
||||
import QtQuick.Controls 2.10 as Controls
|
||||
import QtQuick.Layouts 1.14
|
||||
import QtQuick.Controls 2.14 as Controls
|
||||
|
||||
import org.kde.kirigami 2.8 as Kirigami
|
||||
|
||||
|
@ -27,31 +28,39 @@ import org.kde.alligator 1.0
|
|||
|
||||
Kirigami.ScrollablePage {
|
||||
id: page
|
||||
property string name
|
||||
property string url
|
||||
title: name
|
||||
property var feed
|
||||
|
||||
contextualActions: [
|
||||
Kirigami.Action {
|
||||
text: "Details"
|
||||
visible: url != "all"
|
||||
visible: feed.url != "all"
|
||||
onTriggered: ;//pageStack.push("qrc:/qml/FeedDetailsPage.qml", {"modelData": atomModel})
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
Component.onCompleted: {
|
||||
entryListModel.fetch(url);
|
||||
entryListModel.fetch();
|
||||
}
|
||||
|
||||
ListView {
|
||||
model: EntryListModel {
|
||||
id: entryListModel
|
||||
feed: url
|
||||
feed: page.feed
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: entryListModel
|
||||
header: RowLayout {
|
||||
width: parent.width
|
||||
height: page.height * 0.2
|
||||
Image {
|
||||
source: feed.image
|
||||
fillMode: Image.PreserveAspectFit
|
||||
sourceSize.width: 0
|
||||
sourceSize.height: parent.height
|
||||
}
|
||||
Kirigami.Heading {
|
||||
text: feed.name
|
||||
}
|
||||
}
|
||||
|
||||
delegate: Kirigami.SwipeListItem {
|
||||
|
|
|
@ -83,11 +83,9 @@ Kirigami.ScrollablePage {
|
|||
|
||||
delegate: Kirigami.SwipeListItem {
|
||||
Controls.Label {
|
||||
text: model.display
|
||||
text: model.feed.name
|
||||
}
|
||||
|
||||
onTextChanged: console.log(model.display)
|
||||
|
||||
width: parent.width
|
||||
height: Kirigami.Units.gridUnit * 2
|
||||
actions: [
|
||||
|
@ -103,7 +101,7 @@ Kirigami.ScrollablePage {
|
|||
}
|
||||
]
|
||||
onClicked: {
|
||||
pageStack.push("qrc:/EntryListPage.qml", {"name": model.display, "url": model.url})
|
||||
pageStack.push("qrc:/EntryListPage.qml", {feed: model.feed})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ bool Database::migrate() {
|
|||
|
||||
bool Database::migrateTo1() {
|
||||
QSqlQuery query(QSqlDatabase::database());
|
||||
TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Feeds (name TEXT, url TEXT);")));
|
||||
TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Feeds (name TEXT, url TEXT, image TEXT);")));
|
||||
TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Entries (feed TEXT, id TEXT UNIQUE, title TEXT, content TEXT, created INTEGER, updated INTEGER);")));
|
||||
TRUE_OR_RETURN(execute(QStringLiteral("CREATE TABLE IF NOT EXISTS Authors (id TEXT, name TEXT, uri TEXT, email TEXT);")));
|
||||
TRUE_OR_RETURN(execute(QStringLiteral("PRAGMA user_version = 1;")));
|
||||
|
|
|
@ -79,8 +79,8 @@ bool EntryListModel::setData(const QModelIndex &index, const QVariant &value, in
|
|||
void EntryListModel::fetch()
|
||||
{
|
||||
connect(&Fetcher::instance(), &Fetcher::finished, this, &EntryListModel::update);
|
||||
if(m_feed.compare("all") != 0)
|
||||
Fetcher::instance().fetch(m_feed);
|
||||
if(m_feed.url().compare("all") != 0)
|
||||
Fetcher::instance().fetch(m_feed.url());
|
||||
else
|
||||
update();
|
||||
}
|
||||
|
@ -88,12 +88,12 @@ void EntryListModel::fetch()
|
|||
void EntryListModel::update() {
|
||||
beginResetModel();
|
||||
QSqlQuery query;
|
||||
if(m_feed.compare("all") == 0) {
|
||||
if(m_feed.url().compare("all") == 0) {
|
||||
query.prepare(QStringLiteral("SELECT id, title, content, updated FROM Entries ORDER BY updated DESC;"));
|
||||
}
|
||||
else {
|
||||
query.prepare(QStringLiteral("SELECT id, title, content, updated FROM Entries WHERE feed=:feed ORDER BY updated DESC;"));
|
||||
query.bindValue(QStringLiteral(":feed"), m_feed);
|
||||
query.bindValue(QStringLiteral(":feed"), m_feed.url());
|
||||
}
|
||||
Database::instance().execute(query);
|
||||
while (query.next()) {
|
||||
|
@ -102,12 +102,13 @@ void EntryListModel::update() {
|
|||
endResetModel();
|
||||
}
|
||||
|
||||
QString EntryListModel::feed() const
|
||||
Feed EntryListModel::feed()
|
||||
{
|
||||
return m_feed;
|
||||
}
|
||||
|
||||
void EntryListModel::setFeed(QString feed)
|
||||
void EntryListModel::setFeed(Feed feed)
|
||||
{
|
||||
m_feed = feed;
|
||||
emit feedChanged(feed);
|
||||
}
|
||||
|
|
|
@ -23,14 +23,13 @@
|
|||
#include <QAbstractListModel>
|
||||
#include <QObject>
|
||||
|
||||
#include <Syndication/Syndication>
|
||||
|
||||
#include "entry.h"
|
||||
#include "feed.h"
|
||||
|
||||
class EntryListModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString feed READ feed WRITE setFeed NOTIFY feedChanged)
|
||||
Q_PROPERTY(Feed feed READ feed WRITE setFeed NOTIFY feedChanged)
|
||||
public:
|
||||
enum DataRole {
|
||||
Title = Qt::UserRole + 1,
|
||||
|
@ -45,17 +44,17 @@ public:
|
|||
QHash<int, QByteArray> roleNames() const override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
|
||||
QString feed() const;
|
||||
void setFeed(QString feed);
|
||||
Feed feed();
|
||||
void setFeed(Feed feed);
|
||||
|
||||
Q_INVOKABLE void fetch();
|
||||
|
||||
Q_SIGNALS:
|
||||
void feedChanged(QString);
|
||||
void feedChanged(Feed);
|
||||
|
||||
private:
|
||||
QVector<Entry> m_entries;
|
||||
QString m_feed;
|
||||
Feed m_feed;
|
||||
|
||||
void update();
|
||||
};
|
||||
|
|
32
src/feed.cpp
32
src/feed.cpp
|
@ -18,23 +18,38 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
#include "feed.h"
|
||||
|
||||
Feed::Feed()
|
||||
: m_url(QStringLiteral(""))
|
||||
, m_name(QStringLiteral(""))
|
||||
, m_image(QStringLiteral(""))
|
||||
{
|
||||
}
|
||||
Feed::Feed(const QString url)
|
||||
: m_url(url)
|
||||
, m_name(url)
|
||||
, m_image(QStringLiteral(""))
|
||||
{
|
||||
}
|
||||
|
||||
Feed::Feed(const QString url, const QString name)
|
||||
Feed::Feed(const QString url, const QString name, const QString image)
|
||||
: m_url(url)
|
||||
, m_name(name)
|
||||
, m_image(image)
|
||||
{
|
||||
}
|
||||
|
||||
Feed::Feed(const Feed &other)
|
||||
: m_url(other.url())
|
||||
, m_name(other.name())
|
||||
, m_image(other.image())
|
||||
{
|
||||
}
|
||||
|
||||
Feed::~Feed()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -47,3 +62,18 @@ QString Feed::name() const
|
|||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
QString Feed::image() const
|
||||
{
|
||||
return m_image;
|
||||
}
|
||||
|
||||
void Feed::setName(QString name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
void Feed::setImage(QString image)
|
||||
{
|
||||
m_image = image;
|
||||
}
|
||||
|
|
16
src/feed.h
16
src/feed.h
|
@ -25,15 +25,29 @@
|
|||
|
||||
class Feed
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QString url READ url)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
Q_PROPERTY(QString image READ image WRITE setImage)
|
||||
public:
|
||||
Feed();
|
||||
Feed(const QString url);
|
||||
Feed(const QString url, const QString name, const QString image);
|
||||
Feed(const Feed &other);
|
||||
Feed(const QString url, const QString name);
|
||||
~Feed();
|
||||
|
||||
QString name() const;
|
||||
QString url() const;
|
||||
QString image() const;
|
||||
|
||||
private:
|
||||
QString m_url;
|
||||
QString m_name;
|
||||
QString m_image;
|
||||
|
||||
void setName(QString);
|
||||
void setImage(QString);
|
||||
};
|
||||
|
||||
|
||||
Q_DECLARE_METATYPE(Feed);
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
|
||||
#include <QUrl>
|
||||
|
||||
#include <Syndication/Syndication>
|
||||
|
||||
#include "feedListModel.h"
|
||||
#include "fetcher.h"
|
||||
#include "database.h"
|
||||
|
@ -32,11 +30,11 @@ FeedListModel::FeedListModel(QObject *parent)
|
|||
: QAbstractListModel(parent)
|
||||
{
|
||||
QSqlQuery query;
|
||||
query.prepare(QStringLiteral("SELECT name, url FROM Feeds"));
|
||||
query.prepare(QStringLiteral("SELECT name, url, image FROM Feeds"));
|
||||
Database::instance().execute(query);
|
||||
beginInsertRows(QModelIndex(), 0, query.size());
|
||||
while (query.next()) {
|
||||
feeds += Feed(query.value(1).toString(), query.value(0).toString());
|
||||
feeds += Feed(query.value(1).toString(), query.value(0).toString(), query.value(2).toString());
|
||||
}
|
||||
endInsertRows();
|
||||
}
|
||||
|
@ -44,17 +42,15 @@ FeedListModel::FeedListModel(QObject *parent)
|
|||
QHash<int, QByteArray> FeedListModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roleNames;
|
||||
roleNames[Qt::DisplayRole] = "display";
|
||||
roleNames[Url] = "url";
|
||||
roleNames[FeedRole] = "feed";
|
||||
return roleNames;
|
||||
}
|
||||
|
||||
QVariant FeedListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Url)
|
||||
return feeds[index.row()].url();
|
||||
if (role == Qt::DisplayRole)
|
||||
return feeds[index.row()].name();
|
||||
if (role == FeedRole) {
|
||||
return QVariant::fromValue(feeds[index.row()]);
|
||||
}
|
||||
return QStringLiteral("DEADBEEF");
|
||||
}
|
||||
int FeedListModel::rowCount(const QModelIndex &index) const
|
||||
|
@ -72,14 +68,14 @@ void FeedListModel::addFeed(QString url)
|
|||
if(query.value(0).toInt() != 0) return;
|
||||
connect(&Fetcher::instance(), &Fetcher::finished, this, [this, url]() {
|
||||
QSqlQuery query;
|
||||
query.prepare(QStringLiteral("SELECT name FROM Feeds WHERE url=:url;"));
|
||||
query.prepare(QStringLiteral("SELECT name, image FROM Feeds WHERE url=:url;"));
|
||||
query.bindValue(QStringLiteral(":url"), url);
|
||||
Database::instance().execute(query);
|
||||
query.next();
|
||||
for(int i = 0; i < feeds.length(); i++) {
|
||||
if(feeds[i].url() == url) {
|
||||
feeds.removeAt(i);
|
||||
feeds.insert(i, Feed(url, query.value(0).toString()));
|
||||
feeds.insert(i, Feed(url, query.value(0).toString(), query.value(0).toString()));
|
||||
emit dataChanged(index(i), index(i));
|
||||
break;
|
||||
}
|
||||
|
@ -90,7 +86,7 @@ void FeedListModel::addFeed(QString url)
|
|||
feeds.append(Feed(url));
|
||||
endInsertRows();
|
||||
|
||||
query.prepare(QStringLiteral("INSERT INTO Feeds VALUES (:url, :name);"));
|
||||
query.prepare(QStringLiteral("INSERT INTO Feeds VALUES (:url, :name, '');"));
|
||||
query.bindValue(QStringLiteral(":url"), url);
|
||||
query.bindValue(QStringLiteral(":name"), url);
|
||||
Database::instance().execute(query);
|
||||
|
|
|
@ -33,7 +33,7 @@ class FeedListModel : public QAbstractListModel
|
|||
|
||||
public:
|
||||
enum DataRole {
|
||||
Url = Qt::UserRole + 1,
|
||||
FeedRole = Qt::UserRole + 1,
|
||||
};
|
||||
explicit FeedListModel(QObject *parent = nullptr);
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
|
|
@ -70,9 +70,10 @@ void Fetcher::fetch(QUrl url)
|
|||
query.bindValue(QStringLiteral(":email"), author->email());
|
||||
Database::instance().execute(query);
|
||||
}
|
||||
query.prepare(QStringLiteral("UPDATE Feeds SET name=:name WHERE url=:url;"));
|
||||
query.prepare(QStringLiteral("UPDATE Feeds SET name=:name, image=:image WHERE url=:url;"));
|
||||
query.bindValue(QStringLiteral(":name"), feed->title());
|
||||
query.bindValue(QStringLiteral(":url"), url.toString());
|
||||
query.bindValue(QStringLiteral(":image"), feed->image()->url());
|
||||
Database::instance().execute(query);
|
||||
}
|
||||
delete reply;
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "feedListModel.h"
|
||||
#include "database.h"
|
||||
#include "alligatorsettings.h"
|
||||
#include "feed.h"
|
||||
|
||||
#include "alligator-debug.h"
|
||||
|
||||
|
@ -45,6 +46,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
|
|||
|
||||
qmlRegisterType<FeedListModel>("org.kde.alligator", 1, 0, "FeedListModel");
|
||||
qmlRegisterType<EntryListModel>("org.kde.alligator", 1, 0, "EntryListModel");
|
||||
qRegisterMetaType<Feed>();
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
|
||||
|
|
Loading…
Reference in New Issue