forked from jeena/FeedTheMonkey
made possible to use doOperation with callback, added setRead, added settings for window position and size
This commit is contained in:
parent
ddb54f398c
commit
41e762445f
8 changed files with 94 additions and 47 deletions
|
@ -2,6 +2,8 @@ TEMPLATE = app
|
||||||
|
|
||||||
QT += qml quick
|
QT += qml quick
|
||||||
|
|
||||||
|
CONFIG += c++11
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
tinytinyrss.cpp \
|
tinytinyrss.cpp \
|
||||||
tinytinyrsslogin.cpp \
|
tinytinyrsslogin.cpp \
|
||||||
|
|
|
@ -50,8 +50,13 @@ ScrollView {
|
||||||
|
|
||||||
onCurrentItemChanged: {
|
onCurrentItemChanged: {
|
||||||
if(previousPost) {
|
if(previousPost) {
|
||||||
previousPost.read = true;
|
if(!previousPost.dontChangeRead) {
|
||||||
|
previousPost.read = true;
|
||||||
|
} else {
|
||||||
|
previousPost.dontChangeRead = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
item.content.post = server.posts[currentIndex]
|
item.content.post = server.posts[currentIndex]
|
||||||
content.flickableItem.contentY = 0
|
content.flickableItem.contentY = 0
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,8 @@ MenuBar {
|
||||||
MenuItem {
|
MenuItem {
|
||||||
text: qsTr("Reload")
|
text: qsTr("Reload")
|
||||||
shortcut: "R"
|
shortcut: "R"
|
||||||
enabled: false
|
enabled: true
|
||||||
|
onTriggered: server.reload()
|
||||||
}
|
}
|
||||||
MenuItem {
|
MenuItem {
|
||||||
text: qsTr("Show &Starred")
|
text: qsTr("Show &Starred")
|
||||||
|
@ -47,7 +48,10 @@ MenuBar {
|
||||||
text: qsTr("Set &Unread")
|
text: qsTr("Set &Unread")
|
||||||
shortcut: "U"
|
shortcut: "U"
|
||||||
enabled: true
|
enabled: true
|
||||||
onTriggered: content.post.read = false
|
onTriggered: {
|
||||||
|
content.post.dontChangeRead = true
|
||||||
|
content.post.read = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
MenuItem {
|
MenuItem {
|
||||||
text: qsTr("Next")
|
text: qsTr("Next")
|
||||||
|
|
14
main.qml
14
main.qml
|
@ -1,6 +1,8 @@
|
||||||
import QtQuick 2.3
|
import QtQuick 2.3
|
||||||
import QtQuick.Controls 1.3
|
import QtQuick.Controls 1.3
|
||||||
|
import QtQuick.Window 2.0
|
||||||
import QtQuick.Layouts 1.1
|
import QtQuick.Layouts 1.1
|
||||||
|
import Qt.labs.settings 1.0
|
||||||
import TTRSS 1.0
|
import TTRSS 1.0
|
||||||
|
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
|
@ -8,15 +10,17 @@ ApplicationWindow {
|
||||||
title: "FeedMonkey"
|
title: "FeedMonkey"
|
||||||
visible: true
|
visible: true
|
||||||
|
|
||||||
contentItem.minimumWidth: 640
|
|
||||||
contentItem.minimumHeight: 480
|
|
||||||
contentItem.implicitWidth: 1024
|
|
||||||
contentItem.implicitHeight: 800
|
|
||||||
|
|
||||||
property Server server: server
|
property Server server: server
|
||||||
property Sidebar sidebar: sidebar
|
property Sidebar sidebar: sidebar
|
||||||
property Content content: content
|
property Content content: content
|
||||||
|
|
||||||
|
Settings {
|
||||||
|
property alias x: app.x
|
||||||
|
property alias y: app.y
|
||||||
|
property alias width: app.width
|
||||||
|
property alias height: app.height
|
||||||
|
}
|
||||||
|
|
||||||
menuBar: TheMenuBar {
|
menuBar: TheMenuBar {
|
||||||
id: menu
|
id: menu
|
||||||
server: server
|
server: server
|
||||||
|
|
14
post.cpp
14
post.cpp
|
@ -11,7 +11,7 @@ Post::Post(QJsonObject post, QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
mTitle = post.value("title").toString().trimmed();
|
mTitle = post.value("title").toString().trimmed();
|
||||||
mFeedTitle = post.value("feed_title").toString().trimmed();
|
mFeedTitle = post.value("feed_title").toString().trimmed();
|
||||||
mId = post.value("id").toString().trimmed();
|
mId = post.value("id").toInt();
|
||||||
mFeedId = post.value("feed_id").toString().trimmed();
|
mFeedId = post.value("feed_id").toString().trimmed();
|
||||||
mAuthor = post.value("author").toString().trimmed();
|
mAuthor = post.value("author").toString().trimmed();
|
||||||
QUrl url(post.value("link").toString().trimmed());
|
QUrl url(post.value("link").toString().trimmed());
|
||||||
|
@ -23,6 +23,7 @@ Post::Post(QJsonObject post, QObject *parent) : QObject(parent)
|
||||||
mExcerpt = post.value("excerpt").toString().remove(QRegExp("<[^>]*>")).replace("…", " ...").trimmed().replace("(\\s+)", " ").replace("\n", "");
|
mExcerpt = post.value("excerpt").toString().remove(QRegExp("<[^>]*>")).replace("…", " ...").trimmed().replace("(\\s+)", " ").replace("\n", "");
|
||||||
mStarred = post.value("marked").toBool();
|
mStarred = post.value("marked").toBool();
|
||||||
mRead = !post.value("unread").toBool();
|
mRead = !post.value("unread").toBool();
|
||||||
|
mDontChangeRead = false;
|
||||||
|
|
||||||
QJsonDocument doc(post);
|
QJsonDocument doc(post);
|
||||||
QString result(doc.toJson(QJsonDocument::Indented));
|
QString result(doc.toJson(QJsonDocument::Indented));
|
||||||
|
@ -36,6 +37,17 @@ Post::~Post()
|
||||||
|
|
||||||
void Post::setRead(bool r)
|
void Post::setRead(bool r)
|
||||||
{
|
{
|
||||||
|
if(mRead == r) return;
|
||||||
|
|
||||||
mRead = r;
|
mRead = r;
|
||||||
emit readChanged(mRead);
|
emit readChanged(mRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Post::setDontChangeRead(bool r)
|
||||||
|
{
|
||||||
|
qDebug() << "setDontChangeRead " << r << " " << mDontChangeRead;
|
||||||
|
if(mDontChangeRead == r) return;
|
||||||
|
|
||||||
|
mDontChangeRead = r;
|
||||||
|
emit dontChangeReadChanged(mDontChangeRead);
|
||||||
|
}
|
||||||
|
|
11
post.h
11
post.h
|
@ -11,7 +11,7 @@ class Post : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString title READ title CONSTANT)
|
Q_PROPERTY(QString title READ title CONSTANT)
|
||||||
Q_PROPERTY(QString feedTitle READ feedTitle CONSTANT)
|
Q_PROPERTY(QString feedTitle READ feedTitle CONSTANT)
|
||||||
Q_PROPERTY(QString id READ id CONSTANT)
|
Q_PROPERTY(int id READ id CONSTANT)
|
||||||
Q_PROPERTY(QString feedId READ feedId CONSTANT)
|
Q_PROPERTY(QString feedId READ feedId CONSTANT)
|
||||||
Q_PROPERTY(QString author READ author CONSTANT)
|
Q_PROPERTY(QString author READ author CONSTANT)
|
||||||
Q_PROPERTY(QUrl link READ link CONSTANT)
|
Q_PROPERTY(QUrl link READ link CONSTANT)
|
||||||
|
@ -20,6 +20,7 @@ class Post : public QObject
|
||||||
Q_PROPERTY(QString excerpt READ excerpt CONSTANT)
|
Q_PROPERTY(QString excerpt READ excerpt CONSTANT)
|
||||||
Q_PROPERTY(bool starred READ starred NOTIFY starredChanged)
|
Q_PROPERTY(bool starred READ starred NOTIFY starredChanged)
|
||||||
Q_PROPERTY(bool read READ read WRITE setRead NOTIFY readChanged)
|
Q_PROPERTY(bool read READ read WRITE setRead NOTIFY readChanged)
|
||||||
|
Q_PROPERTY(bool dontChangeRead READ dontChangeRead WRITE setDontChangeRead NOTIFY dontChangeReadChanged)
|
||||||
Q_PROPERTY(QString jsonString READ jsonString CONSTANT)
|
Q_PROPERTY(QString jsonString READ jsonString CONSTANT)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -28,7 +29,7 @@ public:
|
||||||
~Post();
|
~Post();
|
||||||
QString title() const { return mTitle; }
|
QString title() const { return mTitle; }
|
||||||
QString feedTitle() const { return mFeedTitle; }
|
QString feedTitle() const { return mFeedTitle; }
|
||||||
QString id() const { return mId; }
|
int id() const { return mId; }
|
||||||
QString feedId() const { return mFeedId; }
|
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; }
|
||||||
|
@ -38,18 +39,21 @@ public:
|
||||||
bool starred() const { return mStarred; }
|
bool starred() const { return mStarred; }
|
||||||
bool read() { return mRead; }
|
bool read() { return mRead; }
|
||||||
void setRead(bool r);
|
void setRead(bool r);
|
||||||
|
bool dontChangeRead() const { return mDontChangeRead; }
|
||||||
|
void setDontChangeRead(bool r);
|
||||||
QString jsonString() const { return mJsonString; }
|
QString jsonString() const { return mJsonString; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void starredChanged(bool);
|
void starredChanged(bool);
|
||||||
void readChanged(bool);
|
void readChanged(bool);
|
||||||
|
void dontChangeReadChanged(bool);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString mTitle;
|
QString mTitle;
|
||||||
QString mFeedTitle;
|
QString mFeedTitle;
|
||||||
QString mId;
|
int mId;
|
||||||
QString mFeedId;
|
QString mFeedId;
|
||||||
QString mAuthor;
|
QString mAuthor;
|
||||||
QUrl mLink;
|
QUrl mLink;
|
||||||
|
@ -58,6 +62,7 @@ private:
|
||||||
QString mExcerpt;
|
QString mExcerpt;
|
||||||
bool mStarred;
|
bool mStarred;
|
||||||
bool mRead;
|
bool mRead;
|
||||||
|
bool mDontChangeRead;
|
||||||
QString mJsonString;
|
QString mJsonString;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "tinytinyrss.h"
|
#include "tinytinyrss.h"
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
@ -16,7 +15,7 @@ TinyTinyRSS::TinyTinyRSS(QObject *parent) :
|
||||||
|
|
||||||
TinyTinyRSS::~TinyTinyRSS()
|
TinyTinyRSS::~TinyTinyRSS()
|
||||||
{
|
{
|
||||||
mPosts.empty();
|
mPosts.clear();
|
||||||
delete mNetworkManager;
|
delete mNetworkManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,10 +35,24 @@ void TinyTinyRSS::reload()
|
||||||
opts.insert("feed_id", -4);
|
opts.insert("feed_id", -4);
|
||||||
opts.insert("skip", 0);
|
opts.insert("skip", 0);
|
||||||
|
|
||||||
doOperation("getHeadlines", opts);
|
doOperation("getHeadlines", opts, [this] (const QJsonObject &json) {
|
||||||
|
|
||||||
|
mPosts.clear();
|
||||||
|
|
||||||
|
QJsonArray posts = json.value("content").toArray();
|
||||||
|
for(int i = 0; i <= posts.count(); i++)
|
||||||
|
{
|
||||||
|
QJsonObject postJson = posts.at(i).toObject();
|
||||||
|
Post *post = new Post(postJson, this);
|
||||||
|
connect(post, SIGNAL(readChanged(bool)), this, SLOT(onPostReadChanged(bool)));
|
||||||
|
mPosts.append(post);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit postsChanged(mPosts);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void TinyTinyRSS::doOperation(QString operation, QVariantMap opts)
|
void TinyTinyRSS::doOperation(QString operation, QVariantMap opts, std::function<void (const QJsonObject &json)> callback)
|
||||||
{
|
{
|
||||||
QVariantMap options;
|
QVariantMap options;
|
||||||
options.insert("sid", mSessionId);
|
options.insert("sid", mSessionId);
|
||||||
|
@ -58,42 +71,41 @@ void TinyTinyRSS::doOperation(QString operation, QVariantMap opts)
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||||
|
|
||||||
QNetworkReply *reply = mNetworkManager->post(request, json.toJson());
|
QNetworkReply *reply = mNetworkManager->post(request, json.toJson());
|
||||||
connect(reply, SIGNAL(finished()), this, SLOT(reply()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void TinyTinyRSS::reply()
|
connect(reply, &QNetworkReply::finished, [callback, reply] () {
|
||||||
{
|
if (reply) {
|
||||||
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
|
if (reply->error() == QNetworkReply::NoError) {
|
||||||
|
QString jsonString = QString(reply->readAll());
|
||||||
if (reply) {
|
QJsonDocument json = QJsonDocument::fromJson(jsonString.toUtf8());
|
||||||
if (reply->error() == QNetworkReply::NoError) {
|
callback(json.object());
|
||||||
QString jsonString = QString(reply->readAll());
|
} else {
|
||||||
QJsonDocument json = QJsonDocument::fromJson(jsonString.toUtf8());
|
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
|
//do some error management
|
||||||
QJsonArray posts = json.object().value("content").toArray();
|
qWarning() << "HTTP error: " << httpStatus;
|
||||||
|
|
||||||
for(int i = 0; i <= posts.count(); i++)
|
|
||||||
{
|
|
||||||
QJsonObject postJson = posts.at(i).toObject();
|
|
||||||
Post *post = new Post(postJson, this);
|
|
||||||
connect(post, SIGNAL(readChanged(bool)), this, SLOT(onPostReadChanged(bool)));
|
|
||||||
mPosts.append(post);
|
|
||||||
}
|
}
|
||||||
|
reply->deleteLater();
|
||||||
emit postsChanged(mPosts);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
|
||||||
//do some error management
|
|
||||||
qWarning() << "HTTP error: " << httpStatus;
|
|
||||||
}
|
}
|
||||||
reply->deleteLater();
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TinyTinyRSS::onPostReadChanged(bool r)
|
void TinyTinyRSS::onPostReadChanged(bool r)
|
||||||
{
|
{
|
||||||
qDebug() << r;
|
Post *post = (Post *)sender();
|
||||||
|
|
||||||
|
updateArticle(post->id(), 2, !r, [post] (const QJsonObject &json) {
|
||||||
|
qDebug() << json;
|
||||||
|
// not doing anything with this yet.
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void TinyTinyRSS::updateArticle(int articleId, int field, bool trueFalse, std::function<void (const QJsonObject &json)> callback)
|
||||||
|
{
|
||||||
|
QVariantMap opts;
|
||||||
|
opts.insert("article_ids", articleId);
|
||||||
|
opts.insert("field", field);
|
||||||
|
opts.insert("mode", trueFalse ? 1 : 0);
|
||||||
|
|
||||||
|
doOperation("updateArticle", opts, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
QQmlListProperty<Post> TinyTinyRSS::posts()
|
QQmlListProperty<Post> TinyTinyRSS::posts()
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QQmlListProperty>
|
#include <QQmlListProperty>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include "post.h"
|
#include "post.h"
|
||||||
|
|
||||||
|
@ -30,11 +33,11 @@ signals:
|
||||||
void postsChanged(QList<Post *>);
|
void postsChanged(QList<Post *>);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void reply();
|
|
||||||
void onPostReadChanged(bool);
|
void onPostReadChanged(bool);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void doOperation(QString operation, QVariantMap opts);
|
void doOperation(QString operation, QVariantMap opts, std::function<void (const QJsonObject &json)> callback);
|
||||||
|
void updateArticle(int articleId, int field, bool trueFalse, std::function<void (const QJsonObject &json)> callback);
|
||||||
|
|
||||||
QString mServerUrl;
|
QString mServerUrl;
|
||||||
QString mSessionId;
|
QString mSessionId;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue