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 {}
|
||||
|
||||
Content {
|
||||
id: content
|
||||
anchors.fill: parent
|
||||
visible: false
|
||||
Row {
|
||||
ListView {
|
||||
width: 300
|
||||
model: server.posts
|
||||
delegate: Text {
|
||||
text: title
|
||||
}
|
||||
}
|
||||
Content {
|
||||
id: content
|
||||
anchors.fill: parent
|
||||
visible: false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Login {
|
||||
id: login
|
||||
anchors.fill: parent
|
||||
|
|
20
post.cpp
20
post.cpp
|
@ -1,16 +1,26 @@
|
|||
#include "post.h"
|
||||
#include <QDebug>
|
||||
|
||||
Post::Post(QObject *parent) : QObject(parent),
|
||||
mStarred(false)
|
||||
Post::Post(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Post::Post(QJsonObject post, QObject *parent) : QObject(parent),
|
||||
mStarred(false)
|
||||
Post::Post(QJsonObject post, QObject *parent) : QObject(parent)
|
||||
{
|
||||
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()
|
||||
|
|
19
post.h
19
post.h
|
@ -10,35 +10,48 @@ class Post : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
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(QUrl link READ link)
|
||||
Q_PROPERTY(QDate date READ date)
|
||||
Q_PROPERTY(QDateTime date READ date)
|
||||
Q_PROPERTY(QString content READ content)
|
||||
Q_PROPERTY(bool starred READ starred NOTIFY starredChanged)
|
||||
Q_PROPERTY(bool read READ read NOTIFY readChanged)
|
||||
|
||||
public:
|
||||
Post(QObject *parent = 0);
|
||||
Post(QJsonObject post, QObject *parent = 0);
|
||||
~Post();
|
||||
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; }
|
||||
QUrl link() const { return mLink; }
|
||||
QDate date() const { return mDate; }
|
||||
QDateTime date() const { return mDate; }
|
||||
QString content() const { return mContent; }
|
||||
bool starred() const { return mStarred; }
|
||||
bool read() const { return mRead; }
|
||||
|
||||
signals:
|
||||
void starredChanged(bool);
|
||||
void readChanged(bool);
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
QString mTitle;
|
||||
QString mFeedTitle;
|
||||
QString mId;
|
||||
QString mFeedId;
|
||||
QString mAuthor;
|
||||
QUrl mLink;
|
||||
QDate mDate;
|
||||
QDateTime mDate;
|
||||
QString mContent;
|
||||
bool mStarred;
|
||||
bool mRead;
|
||||
};
|
||||
|
||||
#endif // POST_H
|
||||
|
|
|
@ -9,7 +9,7 @@ TinyTinyRSS::TinyTinyRSS(QObject *parent) :
|
|||
QObject(parent)
|
||||
{
|
||||
mNetworkManager = new QNetworkAccessManager(this);
|
||||
mPosts = QList<Post*>();
|
||||
mPosts = QList<Post *>();
|
||||
}
|
||||
|
||||
TinyTinyRSS::~TinyTinyRSS()
|
||||
|
@ -69,7 +69,8 @@ void TinyTinyRSS::reply()
|
|||
QJsonDocument json = QJsonDocument::fromJson(jsonString.toUtf8());
|
||||
|
||||
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();
|
||||
Post *post = new Post(postJson, this);
|
||||
|
@ -77,6 +78,7 @@ void TinyTinyRSS::reply()
|
|||
}
|
||||
|
||||
emit postsChanged(mPosts);
|
||||
|
||||
} else {
|
||||
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
//do some error management
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
class TinyTinyRSS : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QList<Post*> posts READ posts NOTIFY postsChanged)
|
||||
Q_PROPERTY(QList<Post *> posts READ posts NOTIFY postsChanged)
|
||||
|
||||
public:
|
||||
TinyTinyRSS(QObject *parent = 0);
|
||||
|
@ -22,7 +22,7 @@ public:
|
|||
Q_INVOKABLE void reload();
|
||||
|
||||
signals:
|
||||
void postsChanged(QList<Post*>);
|
||||
void postsChanged(QList<Post *>);
|
||||
|
||||
private slots:
|
||||
void reply();
|
||||
|
@ -32,7 +32,7 @@ private:
|
|||
|
||||
QString mServerUrl;
|
||||
QString mSessionId;
|
||||
QList<Post*> mPosts;
|
||||
QList<Post *> mPosts;
|
||||
QNetworkAccessManager *mNetworkManager;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue