fixed logout

This commit is contained in:
Jeena 2015-02-17 23:31:23 +01:00
parent ba5f901a78
commit d02b713341
10 changed files with 90 additions and 25 deletions

View file

@ -38,6 +38,10 @@ ScrollView {
} }
} }
function loggedOut() {
post = null
}
Label { id: fontLabel } Label { id: fontLabel }
WebView { WebView {
@ -52,6 +56,8 @@ ScrollView {
function setPost() { function setPost() {
if(post) { if(post) {
experimental.evaluateJavaScript("setArticle(" + post.jsonString + ")") experimental.evaluateJavaScript("setArticle(" + post.jsonString + ")")
} else {
experimental.evaluateJavaScript("setArticle('logout')")
} }
} }

View file

@ -2,7 +2,7 @@ import QtQuick 2.0
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
Rectangle { Rectangle {
color: "white" color: "transparent"
anchors.fill: parent anchors.fill: parent
property string serverUrl: serverUrl.text property string serverUrl: serverUrl.text
@ -10,7 +10,8 @@ Rectangle {
property string password: password.text property string password: password.text
Column { Column {
width: parent.width anchors.centerIn: parent
width: parent.width / 2
anchors.margins: parent.width / 4 anchors.margins: parent.width / 4
spacing: 10 spacing: 10
@ -20,6 +21,7 @@ Rectangle {
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.margins: 20 anchors.margins: 20
font.pointSize: 20
} }
TextField { TextField {

View file

@ -5,6 +5,7 @@ import TTRSS 1.0
MenuBar { MenuBar {
id: menuBar id: menuBar
property bool loggedIn: false property bool loggedIn: false
property ServerLogin serverLogin
property Server server property Server server
property Sidebar sidebar property Sidebar sidebar
property Content content property Content content
@ -20,7 +21,8 @@ MenuBar {
} }
MenuItem { MenuItem {
text: qsTr("Log Out") text: qsTr("Log Out")
enabled: false enabled: loggedIn
onTriggered: serverLogin.logout()
} }
MenuSeparator { } MenuSeparator { }
MenuItem { MenuItem {
@ -36,7 +38,7 @@ MenuBar {
MenuItem { MenuItem {
text: qsTr("Reload") text: qsTr("Reload")
shortcut: "R" shortcut: "R"
enabled: true enabled: loggedIn
onTriggered: server.reload() onTriggered: server.reload()
} }
MenuItem { MenuItem {
@ -52,7 +54,7 @@ MenuBar {
MenuItem { MenuItem {
text: qsTr("Set &Unread") text: qsTr("Set &Unread")
shortcut: "U" shortcut: "U"
enabled: true enabled: loggedIn
onTriggered: { onTriggered: {
content.post.dontChangeRead = true content.post.dontChangeRead = true
content.post.read = false content.post.read = false
@ -73,7 +75,7 @@ MenuBar {
MenuItem { MenuItem {
text: qsTr("Open in Browser") text: qsTr("Open in Browser")
shortcut: "N" shortcut: "N"
enabled: true enabled: loggedIn
onTriggered: Qt.openUrlExternally(content.post.link) onTriggered: Qt.openUrlExternally(content.post.link)
} }
} }
@ -84,19 +86,19 @@ MenuBar {
MenuItem { MenuItem {
text: qsTr("Zoom In") text: qsTr("Zoom In")
shortcut: "Ctrl++" shortcut: "Ctrl++"
enabled: true enabled: loggedIn
onTriggered: app.zoomIn() onTriggered: app.zoomIn()
} }
MenuItem { MenuItem {
text: qsTr("Zoom Out") text: qsTr("Zoom Out")
shortcut: "Ctrl+-" shortcut: "Ctrl+-"
enabled: true enabled: loggedIn
onTriggered: app.zoomOut() onTriggered: app.zoomOut()
} }
MenuItem { MenuItem {
text: qsTr("Reset") text: qsTr("Reset")
shortcut: "Ctrl+0" shortcut: "Ctrl+0"
enabled: true enabled: loggedIn
onTriggered: app.zoomReset() onTriggered: app.zoomReset()
} }
} }

View file

@ -3,7 +3,6 @@ body {
font-family: sans-serif; font-family: sans-serif;
padding: 1em 1.5em; padding: 1em 1.5em;
font-weight: lighter; font-weight: lighter;
font-size: 1em;
} }
h1 { h1 {
@ -27,7 +26,8 @@ h1 {
header p { header p {
color: #aaa; color: #aaa;
margin: 0; margin: 0;
padding: 0 padding: 0;
font-size: 0.8em;
} }
a { a {
@ -42,4 +42,5 @@ img {
article { article {
line-height: 1.6; line-height: 1.6;
font-size: 0.8em;
} }

View file

@ -12,8 +12,8 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
app.setOrganizationName("Jabs Nu"); app.setOrganizationName("Jeena");
app.setOrganizationDomain("jabs.nu"); app.setOrganizationDomain("jeena.net");
app.setApplicationName("FeedMonkey"); app.setApplicationName("FeedMonkey");
qmlRegisterType<TinyTinyRSSLogin>("TTRSS", 1, 0, "ServerLogin"); qmlRegisterType<TinyTinyRSSLogin>("TTRSS", 1, 0, "ServerLogin");

View file

@ -10,6 +10,9 @@ ApplicationWindow {
title: "FeedMonkey" title: "FeedMonkey"
visible: true visible: true
minimumWidth: 480
minimumHeight: 320
width: 800 width: 800
height: 640 height: 640
x: 200 x: 200
@ -19,42 +22,60 @@ ApplicationWindow {
property Sidebar sidebar: sidebar property Sidebar sidebar: sidebar
property Content content: content property Content content: content
property int defaultTextFontSize: 13 property variant fontSizes: [7,9,11,13,15,17,19,21,23,25,27,29,31]
property int textFontSize: defaultTextFontSize property int defaultTextFontSizeIndex: 4
property int textFontSizeIndex: defaultTextFontSizeIndex
property int textFontSize: fontSizes[textFontSizeIndex]
Settings { Settings {
id: settings
category: "window" category: "window"
property alias x: app.x property alias x: app.x
property alias y: app.y property alias y: app.y
property alias width: app.width property alias width: app.width
property alias height: app.height property alias height: app.height
property alias sidebarWidth: sidebar.width property alias sidebarWidth: sidebar.width
//property alias textFontSize: app.textFontSize property alias textFontSizeIndex: app.textFontSizeIndex
} }
property TheMenuBar menu: TheMenuBar { property TheMenuBar menu: TheMenuBar {
id: menu id: menu
serverLogin: serverLogin
server: server server: server
sidebar: sidebar sidebar: sidebar
content: content content: content
} }
function loggedIn() { function loggedIn() {
menu.loggedIn = true; if(serverLogin.loggedIn()) {
login.visible = false; menu.loggedIn = true;
server.initialize(serverLogin.serverUrl, serverLogin.sessionId); contentView.visible = true
login.visible = false;
server.initialize(serverLogin.serverUrl, serverLogin.sessionId);
} else {
menu.loggedIn = false
contentView.visible = false
login.visible = true
server.loggedOut()
content.loggedOut()
}
} }
function zoomIn() { function zoomIn() {
textFontSize *= 1.2 if(textFontSizeIndex + 1 < fontSizes.length) {
textFontSize = fontSizes[++textFontSizeIndex]
}
} }
function zoomOut() { function zoomOut() {
textFontSize *= 0.8 if(textFontSizeIndex - 1 > 0) {
textFontSize = fontSizes[--textFontSizeIndex]
}
} }
function zoomReset() { function zoomReset() {
textFontSize = defaultTextFontSize textFontSizeIndex = defaultTextFontSizeIndex
textFontSize = fontSizes[textFontSizeIndex]
} }
function keyPressed(event) { function keyPressed(event) {
@ -98,6 +119,7 @@ ApplicationWindow {
} }
SplitView { SplitView {
id: contentView
anchors.fill: parent anchors.fill: parent
orientation: Qt.Horizontal orientation: Qt.Horizontal
visible: serverLogin.loggedIn() visible: serverLogin.loggedIn()
@ -140,13 +162,14 @@ ApplicationWindow {
visible: !serverLogin.loggedIn() visible: !serverLogin.loggedIn()
function login() { function login() {
console.log("FOO")
serverLogin.login(serverUrl, userName, password) serverLogin.login(serverUrl, userName, password)
} }
} }
ServerLogin { ServerLogin {
id: serverLogin id: serverLogin
onSessionIdChanged: loggedIn() onSessionIdChanged: app.loggedIn()
} }
Server { Server {

View file

@ -52,6 +52,14 @@ void TinyTinyRSS::reload()
}); });
} }
void TinyTinyRSS::loggedOut()
{
mServerUrl = nullptr;
mSessionId = nullptr;
mPosts.clear();
emit postsChanged(mPosts);
}
void TinyTinyRSS::doOperation(QString operation, QVariantMap opts, std::function<void (const QJsonObject &json)> callback) void TinyTinyRSS::doOperation(QString operation, QVariantMap opts, std::function<void (const QJsonObject &json)> callback)
{ {
QVariantMap options; QVariantMap options;

View file

@ -23,6 +23,7 @@ public:
Q_INVOKABLE void initialize(const QString serverUrl, const QString sessionId); Q_INVOKABLE void initialize(const QString serverUrl, const QString sessionId);
Q_INVOKABLE void reload(); Q_INVOKABLE void reload();
Q_INVOKABLE void loggedOut();
QQmlListProperty<Post> posts(); QQmlListProperty<Post> posts();

View file

@ -4,12 +4,15 @@
#include <QNetworkReply> #include <QNetworkReply>
#include <QSettings> #include <QSettings>
#define APP_URL "net.jeena"
#define APP_NAME "FeedMonkey"
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"); QSettings settings;
mSessionId = settings.value("sessionId").toString(); mSessionId = settings.value("sessionId").toString();
mServerUrl = settings.value("serverUrl").toString(); mServerUrl = settings.value("serverUrl").toString();
} }
@ -43,6 +46,24 @@ void TinyTinyRSSLogin::login(const QString serverUrl, const QString user, const
connect(reply, SIGNAL(finished()), this, SLOT(reply())); connect(reply, SIGNAL(finished()), this, SLOT(reply()));
} }
void TinyTinyRSSLogin::logout()
{
if(mSessionId.length() > 0 && mServerUrl.toString().length() > 0) {
QVariantMap options;
options.insert("op", "logout");
options.insert("sid", mSessionId);
QJsonObject jsonobj = QJsonObject::fromVariantMap(options);
QJsonDocument json = QJsonDocument(jsonobj);
QNetworkRequest request(mServerUrl);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QNetworkReply *reply = mNetworkManager->post(request, json.toJson());
connect(reply, SIGNAL(finished()), this, SLOT(reply()));
}
}
void TinyTinyRSSLogin::reply() void TinyTinyRSSLogin::reply()
{ {
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
@ -56,7 +77,7 @@ void TinyTinyRSSLogin::reply()
emit sessionIdChanged(mSessionId); emit sessionIdChanged(mSessionId);
QSettings settings("net.jeena", "feedmonkey"); QSettings settings;
settings.setValue("sessionId", mSessionId); settings.setValue("sessionId", mSessionId);
settings.setValue("serverUrl", mServerUrl); settings.setValue("serverUrl", mServerUrl);
settings.sync(); settings.sync();

View file

@ -20,6 +20,7 @@ public:
Q_INVOKABLE bool loggedIn(); 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);
Q_INVOKABLE void logout();
signals: signals:
void sessionIdChanged(QString); void sessionIdChanged(QString);