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.Controls 1.3
|
||||
import QtQuick.Layouts 1.1
|
||||
import TTRSS 1.0
|
||||
|
||||
ApplicationWindow {
|
||||
|
@ -10,29 +11,39 @@ ApplicationWindow {
|
|||
|
||||
menuBar: TheMenuBar {}
|
||||
|
||||
Component {
|
||||
id: delegate
|
||||
Text { text: title }
|
||||
function loggedIn() {
|
||||
login.visible = false;
|
||||
server.initialize(serverLogin.serverUrl, serverLogin.sessionId);
|
||||
}
|
||||
|
||||
ScrollView {
|
||||
width: parent.width / 3
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.top: parent.top
|
||||
ListView {
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
spacing: 5
|
||||
model: server.posts
|
||||
delegate: delegate
|
||||
SplitView {
|
||||
anchors.fill: parent
|
||||
orientation: Qt.Horizontal
|
||||
|
||||
ScrollView {
|
||||
Layout.minimumWidth: 400
|
||||
|
||||
ListView {
|
||||
id: listView
|
||||
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 {
|
||||
width: parent.width / 3 * 2
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
Content {
|
||||
Layout.minimumWidth: 50
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
|
||||
Login {
|
||||
|
@ -47,13 +58,16 @@ ApplicationWindow {
|
|||
|
||||
ServerLogin {
|
||||
id: serverLogin
|
||||
onSessionIdChanged: {
|
||||
login.visible = false;
|
||||
server.initialize(serverUrl, sessionId);
|
||||
}
|
||||
onSessionIdChanged: loggedIn()
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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());
|
||||
mTitle = post.value("title").toString().trimmed();
|
||||
mFeedTitle = post.value("feed_title").toString().trimmed();
|
||||
mId = post.value("id").toString().trimmed();
|
||||
mFeedId = post.value("feed_id").toString().trimmed();
|
||||
mAuthor = post.value("author").toString().trimmed();
|
||||
QUrl url(post.value("link").toString().trimmed());
|
||||
mLink = url;
|
||||
QDateTime timestamp;
|
||||
timestamp.setTime_t(post.value("updated").toInt());
|
||||
mDate = timestamp;
|
||||
mContent = post.value("content").toString();
|
||||
mContent = post.value("content").toString().trimmed();
|
||||
mExcerpt = post.value("excerpt").toString().trimmed();
|
||||
mStarred = post.value("marked").toBool();
|
||||
mRead = !post.value("unread").toBool();
|
||||
}
|
||||
|
|
15
post.h
15
post.h
|
@ -10,13 +10,14 @@ class Post : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString title READ title CONSTANT)
|
||||
Q_PROPERTY(QString feedTitle READ feedTitle)
|
||||
Q_PROPERTY(QString id READ id)
|
||||
Q_PROPERTY(QString feedId READ feedId)
|
||||
Q_PROPERTY(QString feedTitle READ feedTitle CONSTANT)
|
||||
Q_PROPERTY(QString id READ id CONSTANT)
|
||||
Q_PROPERTY(QString feedId READ feedId CONSTANT)
|
||||
Q_PROPERTY(QString author READ author CONSTANT)
|
||||
Q_PROPERTY(QUrl link READ link)
|
||||
Q_PROPERTY(QDateTime date READ date)
|
||||
Q_PROPERTY(QString content READ content)
|
||||
Q_PROPERTY(QUrl link READ link CONSTANT)
|
||||
Q_PROPERTY(QDateTime date READ date CONSTANT)
|
||||
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 read READ read NOTIFY readChanged)
|
||||
|
||||
|
@ -32,6 +33,7 @@ public:
|
|||
QUrl link() const { return mLink; }
|
||||
QDateTime date() const { return mDate; }
|
||||
QString content() const { return mContent; }
|
||||
QString excerpt() const { return mExcerpt; }
|
||||
bool starred() const { return mStarred; }
|
||||
bool read() const { return mRead; }
|
||||
|
||||
|
@ -50,6 +52,7 @@ private:
|
|||
QUrl mLink;
|
||||
QDateTime mDate;
|
||||
QString mContent;
|
||||
QString mExcerpt;
|
||||
bool mStarred;
|
||||
bool mRead;
|
||||
};
|
||||
|
|
1
qml.qrc
1
qml.qrc
|
@ -4,5 +4,6 @@
|
|||
<file>TheMenuBar.qml</file>
|
||||
<file>Content.qml</file>
|
||||
<file>Login.qml</file>
|
||||
<file>PostListItem.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -2,11 +2,16 @@
|
|||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QNetworkReply>
|
||||
#include <QSettings>
|
||||
|
||||
TinyTinyRSSLogin::TinyTinyRSSLogin(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
mNetworkManager = new QNetworkAccessManager(this);
|
||||
|
||||
QSettings settings("net.jeena", "feedmonkey");
|
||||
mSessionId = settings.value("sessionId").toString();
|
||||
mServerUrl = settings.value("serverUrl").toString();
|
||||
}
|
||||
|
||||
TinyTinyRSSLogin::~TinyTinyRSSLogin()
|
||||
|
@ -14,6 +19,11 @@ TinyTinyRSSLogin::~TinyTinyRSSLogin()
|
|||
delete mNetworkManager;
|
||||
}
|
||||
|
||||
bool TinyTinyRSSLogin::loggedIn()
|
||||
{
|
||||
return !mSessionId.isEmpty();
|
||||
}
|
||||
|
||||
void TinyTinyRSSLogin::login(const QString serverUrl, const QString user, const QString password)
|
||||
{
|
||||
mServerUrl = QUrl(serverUrl + "/api/");
|
||||
|
@ -39,10 +49,18 @@ void TinyTinyRSSLogin::reply()
|
|||
|
||||
if (reply) {
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
|
||||
QString jsonString = QString(reply->readAll());
|
||||
QJsonDocument json = QJsonDocument::fromJson(jsonString.toUtf8());
|
||||
mSessionId = json.object().value("content").toObject().value("session_id").toString();
|
||||
|
||||
emit sessionIdChanged(mSessionId);
|
||||
|
||||
QSettings settings("net.jeena", "feedmonkey");
|
||||
settings.setValue("sessionId", mSessionId);
|
||||
settings.setValue("serverUrl", mServerUrl);
|
||||
settings.sync();
|
||||
|
||||
} else {
|
||||
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
//do some error management
|
||||
|
|
|
@ -18,6 +18,7 @@ public:
|
|||
QString sessionId() const { return mSessionId; }
|
||||
QUrl serverUrl() const { return mServerUrl; }
|
||||
|
||||
Q_INVOKABLE bool loggedIn();
|
||||
Q_INVOKABLE void login(const QString serverUrl, const QString user, const QString password);
|
||||
|
||||
signals:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue