better sidebar
This commit is contained in:
parent
48d2646545
commit
b24d2bef07
7 changed files with 113 additions and 36 deletions
39
PostListItem.qml
Normal file
39
PostListItem.qml
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
import QtQuick 2.0
|
||||||
|
|
||||||
|
Item {
|
||||||
|
property ListView listView
|
||||||
|
height: column.height
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
color: "white"
|
||||||
|
anchors.margins: 10
|
||||||
|
anchors.fill: parent
|
||||||
|
Column {
|
||||||
|
id: column
|
||||||
|
Text {
|
||||||
|
text: "[" + date.toLocaleString(null, "hh:mm:ss") + "] " + feedTitle
|
||||||
|
font.pointSize: 9
|
||||||
|
color: "gray"
|
||||||
|
wrapMode: Text.Wrap
|
||||||
|
}
|
||||||
|
Text {
|
||||||
|
text: title
|
||||||
|
font.pointSize: 12
|
||||||
|
wrapMode: Text.Wrap
|
||||||
|
}
|
||||||
|
Text {
|
||||||
|
text: excerpt
|
||||||
|
font.pointSize: 9
|
||||||
|
color: "gray"
|
||||||
|
wrapMode: Text.Wrap
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
anchors.fill: parent
|
||||||
|
onClicked: {
|
||||||
|
listView.currentIndex = index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
main.qml
60
main.qml
|
@ -1,5 +1,6 @@
|
||||||
import QtQuick 2.3
|
import QtQuick 2.3
|
||||||
import QtQuick.Controls 1.3
|
import QtQuick.Controls 1.3
|
||||||
|
import QtQuick.Layouts 1.1
|
||||||
import TTRSS 1.0
|
import TTRSS 1.0
|
||||||
|
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
|
@ -10,29 +11,39 @@ ApplicationWindow {
|
||||||
|
|
||||||
menuBar: TheMenuBar {}
|
menuBar: TheMenuBar {}
|
||||||
|
|
||||||
Component {
|
function loggedIn() {
|
||||||
id: delegate
|
login.visible = false;
|
||||||
Text { text: title }
|
server.initialize(serverLogin.serverUrl, serverLogin.sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScrollView {
|
SplitView {
|
||||||
width: parent.width / 3
|
anchors.fill: parent
|
||||||
anchors.bottom: parent.bottom
|
orientation: Qt.Horizontal
|
||||||
anchors.top: parent.top
|
|
||||||
ListView {
|
ScrollView {
|
||||||
anchors.top: parent.top
|
Layout.minimumWidth: 400
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
spacing: 5
|
ListView {
|
||||||
model: server.posts
|
id: listView
|
||||||
delegate: delegate
|
anchors.top: parent.top
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
spacing: 5
|
||||||
|
model: server.posts
|
||||||
|
delegate: PostListItem {
|
||||||
|
listView: listView
|
||||||
|
}
|
||||||
|
highlight: Rectangle {
|
||||||
|
color: "lightblue"
|
||||||
|
opacity: 0.5
|
||||||
|
focus: true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Content {
|
Content {
|
||||||
width: parent.width / 3 * 2
|
Layout.minimumWidth: 50
|
||||||
anchors.right: parent.right
|
Layout.fillWidth: true
|
||||||
anchors.top: parent.top
|
}
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Login {
|
Login {
|
||||||
|
@ -47,13 +58,16 @@ ApplicationWindow {
|
||||||
|
|
||||||
ServerLogin {
|
ServerLogin {
|
||||||
id: serverLogin
|
id: serverLogin
|
||||||
onSessionIdChanged: {
|
onSessionIdChanged: loggedIn()
|
||||||
login.visible = false;
|
|
||||||
server.initialize(serverUrl, sessionId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Server {
|
Server {
|
||||||
id: server
|
id: server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
if(serverLogin.loggedIn()) {
|
||||||
|
loggedIn();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
15
post.cpp
15
post.cpp
|
@ -8,17 +8,18 @@ Post::Post(QObject *parent) : QObject(parent)
|
||||||
|
|
||||||
Post::Post(QJsonObject post, QObject *parent) : QObject(parent)
|
Post::Post(QJsonObject post, QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
mTitle = post.value("title").toString();
|
mTitle = post.value("title").toString().trimmed();
|
||||||
mFeedTitle = post.value("feed_title").toString();
|
mFeedTitle = post.value("feed_title").toString().trimmed();
|
||||||
mId = post.value("id").toString();
|
mId = post.value("id").toString().trimmed();
|
||||||
mFeedId = post.value("feed_id").toString();
|
mFeedId = post.value("feed_id").toString().trimmed();
|
||||||
mAuthor = post.value("author").toString();
|
mAuthor = post.value("author").toString().trimmed();
|
||||||
QUrl url(post.value("link").toString());
|
QUrl url(post.value("link").toString().trimmed());
|
||||||
mLink = url;
|
mLink = url;
|
||||||
QDateTime timestamp;
|
QDateTime timestamp;
|
||||||
timestamp.setTime_t(post.value("updated").toInt());
|
timestamp.setTime_t(post.value("updated").toInt());
|
||||||
mDate = timestamp;
|
mDate = timestamp;
|
||||||
mContent = post.value("content").toString();
|
mContent = post.value("content").toString().trimmed();
|
||||||
|
mExcerpt = post.value("excerpt").toString().trimmed();
|
||||||
mStarred = post.value("marked").toBool();
|
mStarred = post.value("marked").toBool();
|
||||||
mRead = !post.value("unread").toBool();
|
mRead = !post.value("unread").toBool();
|
||||||
}
|
}
|
||||||
|
|
15
post.h
15
post.h
|
@ -10,13 +10,14 @@ 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)
|
Q_PROPERTY(QString feedTitle READ feedTitle CONSTANT)
|
||||||
Q_PROPERTY(QString id READ id)
|
Q_PROPERTY(QString id READ id CONSTANT)
|
||||||
Q_PROPERTY(QString feedId READ feedId)
|
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)
|
Q_PROPERTY(QUrl link READ link CONSTANT)
|
||||||
Q_PROPERTY(QDateTime date READ date)
|
Q_PROPERTY(QDateTime date READ date CONSTANT)
|
||||||
Q_PROPERTY(QString content READ content)
|
Q_PROPERTY(QString content READ content 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 NOTIFY readChanged)
|
Q_PROPERTY(bool read READ read NOTIFY readChanged)
|
||||||
|
|
||||||
|
@ -32,6 +33,7 @@ public:
|
||||||
QUrl link() const { return mLink; }
|
QUrl link() const { return mLink; }
|
||||||
QDateTime date() const { return mDate; }
|
QDateTime date() const { return mDate; }
|
||||||
QString content() const { return mContent; }
|
QString content() const { return mContent; }
|
||||||
|
QString excerpt() const { return mExcerpt; }
|
||||||
bool starred() const { return mStarred; }
|
bool starred() const { return mStarred; }
|
||||||
bool read() const { return mRead; }
|
bool read() const { return mRead; }
|
||||||
|
|
||||||
|
@ -50,6 +52,7 @@ private:
|
||||||
QUrl mLink;
|
QUrl mLink;
|
||||||
QDateTime mDate;
|
QDateTime mDate;
|
||||||
QString mContent;
|
QString mContent;
|
||||||
|
QString mExcerpt;
|
||||||
bool mStarred;
|
bool mStarred;
|
||||||
bool mRead;
|
bool mRead;
|
||||||
};
|
};
|
||||||
|
|
1
qml.qrc
1
qml.qrc
|
@ -4,5 +4,6 @@
|
||||||
<file>TheMenuBar.qml</file>
|
<file>TheMenuBar.qml</file>
|
||||||
<file>Content.qml</file>
|
<file>Content.qml</file>
|
||||||
<file>Login.qml</file>
|
<file>Login.qml</file>
|
||||||
|
<file>PostListItem.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -2,11 +2,16 @@
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
TinyTinyRSSLogin::TinyTinyRSSLogin(QObject *parent) :
|
TinyTinyRSSLogin::TinyTinyRSSLogin(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
mNetworkManager = new QNetworkAccessManager(this);
|
mNetworkManager = new QNetworkAccessManager(this);
|
||||||
|
|
||||||
|
QSettings settings("net.jeena", "feedmonkey");
|
||||||
|
mSessionId = settings.value("sessionId").toString();
|
||||||
|
mServerUrl = settings.value("serverUrl").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
TinyTinyRSSLogin::~TinyTinyRSSLogin()
|
TinyTinyRSSLogin::~TinyTinyRSSLogin()
|
||||||
|
@ -14,6 +19,11 @@ TinyTinyRSSLogin::~TinyTinyRSSLogin()
|
||||||
delete mNetworkManager;
|
delete mNetworkManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TinyTinyRSSLogin::loggedIn()
|
||||||
|
{
|
||||||
|
return !mSessionId.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
void TinyTinyRSSLogin::login(const QString serverUrl, const QString user, const QString password)
|
void TinyTinyRSSLogin::login(const QString serverUrl, const QString user, const QString password)
|
||||||
{
|
{
|
||||||
mServerUrl = QUrl(serverUrl + "/api/");
|
mServerUrl = QUrl(serverUrl + "/api/");
|
||||||
|
@ -39,10 +49,18 @@ void TinyTinyRSSLogin::reply()
|
||||||
|
|
||||||
if (reply) {
|
if (reply) {
|
||||||
if (reply->error() == QNetworkReply::NoError) {
|
if (reply->error() == QNetworkReply::NoError) {
|
||||||
|
|
||||||
QString jsonString = QString(reply->readAll());
|
QString jsonString = QString(reply->readAll());
|
||||||
QJsonDocument json = QJsonDocument::fromJson(jsonString.toUtf8());
|
QJsonDocument json = QJsonDocument::fromJson(jsonString.toUtf8());
|
||||||
mSessionId = json.object().value("content").toObject().value("session_id").toString();
|
mSessionId = json.object().value("content").toObject().value("session_id").toString();
|
||||||
|
|
||||||
emit sessionIdChanged(mSessionId);
|
emit sessionIdChanged(mSessionId);
|
||||||
|
|
||||||
|
QSettings settings("net.jeena", "feedmonkey");
|
||||||
|
settings.setValue("sessionId", mSessionId);
|
||||||
|
settings.setValue("serverUrl", mServerUrl);
|
||||||
|
settings.sync();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
//do some error management
|
//do some error management
|
||||||
|
|
|
@ -18,6 +18,7 @@ public:
|
||||||
QString sessionId() const { return mSessionId; }
|
QString sessionId() const { return mSessionId; }
|
||||||
QUrl serverUrl() const { return mServerUrl; }
|
QUrl serverUrl() const { return mServerUrl; }
|
||||||
|
|
||||||
|
Q_INVOKABLE bool loggedIn();
|
||||||
Q_INVOKABLE void login(const QString serverUrl, const QString user, const QString password);
|
Q_INVOKABLE void login(const QString serverUrl, const QString user, const QString password);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue