added listview
This commit is contained in:
parent
6146758f59
commit
923d514dff
5 changed files with 52 additions and 17 deletions
18
main.qml
18
main.qml
|
@ -10,12 +10,22 @@ ApplicationWindow {
|
||||||
|
|
||||||
menuBar: TheMenuBar {}
|
menuBar: TheMenuBar {}
|
||||||
|
|
||||||
Content {
|
Row {
|
||||||
id: content
|
ListView {
|
||||||
anchors.fill: parent
|
width: 300
|
||||||
visible: false
|
model: server.posts
|
||||||
|
delegate: Text {
|
||||||
|
text: title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Content {
|
||||||
|
id: content
|
||||||
|
anchors.fill: parent
|
||||||
|
visible: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Login {
|
Login {
|
||||||
id: login
|
id: login
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
20
post.cpp
20
post.cpp
|
@ -1,16 +1,26 @@
|
||||||
#include "post.h"
|
#include "post.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
Post::Post(QObject *parent) : QObject(parent),
|
Post::Post(QObject *parent) : QObject(parent)
|
||||||
mStarred(false)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Post::Post(QJsonObject post, QObject *parent) : QObject(parent),
|
Post::Post(QJsonObject post, QObject *parent) : QObject(parent)
|
||||||
mStarred(false)
|
|
||||||
{
|
{
|
||||||
qDebug() << post;
|
mTitle = post.value("title").toString();
|
||||||
|
mFeedTitle = post.value("feed_title").toString();
|
||||||
|
mId = post.value("id").toString();
|
||||||
|
mFeedId = post.value("feed_id").toString();
|
||||||
|
mAuthor = post.value("author").toString();
|
||||||
|
QUrl url(post.value("link").toString());
|
||||||
|
mLink = url;
|
||||||
|
QDateTime timestamp;
|
||||||
|
timestamp.setTime_t(post.value("updated").toInt());
|
||||||
|
mDate = timestamp;
|
||||||
|
mContent = post.value("content").toString();
|
||||||
|
mStarred = post.value("marked").toBool();
|
||||||
|
mRead = !post.value("unread").toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
Post::~Post()
|
Post::~Post()
|
||||||
|
|
19
post.h
19
post.h
|
@ -10,35 +10,48 @@ class Post : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString title READ title)
|
Q_PROPERTY(QString title READ title)
|
||||||
|
Q_PROPERTY(QString feedTitle READ feedTitle)
|
||||||
|
Q_PROPERTY(QString id READ id)
|
||||||
|
Q_PROPERTY(QString feedId READ feedId)
|
||||||
Q_PROPERTY(QString author READ author)
|
Q_PROPERTY(QString author READ author)
|
||||||
Q_PROPERTY(QUrl link READ link)
|
Q_PROPERTY(QUrl link READ link)
|
||||||
Q_PROPERTY(QDate date READ date)
|
Q_PROPERTY(QDateTime date READ date)
|
||||||
Q_PROPERTY(QString content READ content)
|
Q_PROPERTY(QString content READ content)
|
||||||
Q_PROPERTY(bool starred READ starred NOTIFY starredChanged)
|
Q_PROPERTY(bool starred READ starred NOTIFY starredChanged)
|
||||||
|
Q_PROPERTY(bool read READ read NOTIFY readChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Post(QObject *parent = 0);
|
Post(QObject *parent = 0);
|
||||||
Post(QJsonObject post, QObject *parent = 0);
|
Post(QJsonObject post, QObject *parent = 0);
|
||||||
~Post();
|
~Post();
|
||||||
QString title() const { return mTitle; }
|
QString title() const { return mTitle; }
|
||||||
|
QString feedTitle() const { return mFeedTitle; }
|
||||||
|
QString id() const { return mId; }
|
||||||
|
QString feedId() const { return mFeedId; }
|
||||||
QString author() const { return mAuthor; }
|
QString author() const { return mAuthor; }
|
||||||
QUrl link() const { return mLink; }
|
QUrl link() const { return mLink; }
|
||||||
QDate date() const { return mDate; }
|
QDateTime date() const { return mDate; }
|
||||||
QString content() const { return mContent; }
|
QString content() const { return mContent; }
|
||||||
bool starred() const { return mStarred; }
|
bool starred() const { return mStarred; }
|
||||||
|
bool read() const { return mRead; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void starredChanged(bool);
|
void starredChanged(bool);
|
||||||
|
void readChanged(bool);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString mTitle;
|
QString mTitle;
|
||||||
|
QString mFeedTitle;
|
||||||
|
QString mId;
|
||||||
|
QString mFeedId;
|
||||||
QString mAuthor;
|
QString mAuthor;
|
||||||
QUrl mLink;
|
QUrl mLink;
|
||||||
QDate mDate;
|
QDateTime mDate;
|
||||||
QString mContent;
|
QString mContent;
|
||||||
bool mStarred;
|
bool mStarred;
|
||||||
|
bool mRead;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // POST_H
|
#endif // POST_H
|
||||||
|
|
|
@ -9,7 +9,7 @@ TinyTinyRSS::TinyTinyRSS(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
mNetworkManager = new QNetworkAccessManager(this);
|
mNetworkManager = new QNetworkAccessManager(this);
|
||||||
mPosts = QList<Post*>();
|
mPosts = QList<Post *>();
|
||||||
}
|
}
|
||||||
|
|
||||||
TinyTinyRSS::~TinyTinyRSS()
|
TinyTinyRSS::~TinyTinyRSS()
|
||||||
|
@ -69,7 +69,8 @@ void TinyTinyRSS::reply()
|
||||||
QJsonDocument json = QJsonDocument::fromJson(jsonString.toUtf8());
|
QJsonDocument json = QJsonDocument::fromJson(jsonString.toUtf8());
|
||||||
|
|
||||||
QJsonArray posts = json.object().value("content").toArray();
|
QJsonArray posts = json.object().value("content").toArray();
|
||||||
for(int i = 0; posts.count(); i++)
|
|
||||||
|
for(int i = 0; i <= posts.count(); i++)
|
||||||
{
|
{
|
||||||
QJsonObject postJson = posts.at(i).toObject();
|
QJsonObject postJson = posts.at(i).toObject();
|
||||||
Post *post = new Post(postJson, this);
|
Post *post = new Post(postJson, this);
|
||||||
|
@ -77,6 +78,7 @@ void TinyTinyRSS::reply()
|
||||||
}
|
}
|
||||||
|
|
||||||
emit postsChanged(mPosts);
|
emit postsChanged(mPosts);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
//do some error management
|
//do some error management
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
class TinyTinyRSS : public QObject
|
class TinyTinyRSS : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QList<Post*> posts READ posts NOTIFY postsChanged)
|
Q_PROPERTY(QList<Post *> posts READ posts NOTIFY postsChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TinyTinyRSS(QObject *parent = 0);
|
TinyTinyRSS(QObject *parent = 0);
|
||||||
|
@ -22,7 +22,7 @@ public:
|
||||||
Q_INVOKABLE void reload();
|
Q_INVOKABLE void reload();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void postsChanged(QList<Post*>);
|
void postsChanged(QList<Post *>);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void reply();
|
void reply();
|
||||||
|
@ -32,7 +32,7 @@ private:
|
||||||
|
|
||||||
QString mServerUrl;
|
QString mServerUrl;
|
||||||
QString mSessionId;
|
QString mSessionId;
|
||||||
QList<Post*> mPosts;
|
QList<Post *> mPosts;
|
||||||
QNetworkAccessManager *mNetworkManager;
|
QNetworkAccessManager *mNetworkManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue