From d02b713341fe342b366dbdadaed4ed65749ab2d3 Mon Sep 17 00:00:00 2001 From: Jeena Date: Tue, 17 Feb 2015 23:31:23 +0100 Subject: [PATCH] fixed logout --- Content.qml | 6 ++++++ Login.qml | 6 ++++-- TheMenuBar.qml | 16 +++++++++------- content.css | 5 +++-- main.cpp | 4 ++-- main.qml | 43 +++++++++++++++++++++++++++++++++---------- tinytinyrss.cpp | 8 ++++++++ tinytinyrss.h | 1 + tinytinyrsslogin.cpp | 25 +++++++++++++++++++++++-- tinytinyrsslogin.h | 1 + 10 files changed, 90 insertions(+), 25 deletions(-) diff --git a/Content.qml b/Content.qml index f51da2c..278f2d7 100644 --- a/Content.qml +++ b/Content.qml @@ -38,6 +38,10 @@ ScrollView { } } + function loggedOut() { + post = null + } + Label { id: fontLabel } WebView { @@ -52,6 +56,8 @@ ScrollView { function setPost() { if(post) { experimental.evaluateJavaScript("setArticle(" + post.jsonString + ")") + } else { + experimental.evaluateJavaScript("setArticle('logout')") } } diff --git a/Login.qml b/Login.qml index d56635d..ac87e53 100644 --- a/Login.qml +++ b/Login.qml @@ -2,7 +2,7 @@ import QtQuick 2.0 import QtQuick.Controls 1.2 Rectangle { - color: "white" + color: "transparent" anchors.fill: parent property string serverUrl: serverUrl.text @@ -10,7 +10,8 @@ Rectangle { property string password: password.text Column { - width: parent.width + anchors.centerIn: parent + width: parent.width / 2 anchors.margins: parent.width / 4 spacing: 10 @@ -20,6 +21,7 @@ Rectangle { anchors.left: parent.left anchors.right: parent.right anchors.margins: 20 + font.pointSize: 20 } TextField { diff --git a/TheMenuBar.qml b/TheMenuBar.qml index 97aaf8e..3dbe0bf 100644 --- a/TheMenuBar.qml +++ b/TheMenuBar.qml @@ -5,6 +5,7 @@ import TTRSS 1.0 MenuBar { id: menuBar property bool loggedIn: false + property ServerLogin serverLogin property Server server property Sidebar sidebar property Content content @@ -20,7 +21,8 @@ MenuBar { } MenuItem { text: qsTr("Log Out") - enabled: false + enabled: loggedIn + onTriggered: serverLogin.logout() } MenuSeparator { } MenuItem { @@ -36,7 +38,7 @@ MenuBar { MenuItem { text: qsTr("Reload") shortcut: "R" - enabled: true + enabled: loggedIn onTriggered: server.reload() } MenuItem { @@ -52,7 +54,7 @@ MenuBar { MenuItem { text: qsTr("Set &Unread") shortcut: "U" - enabled: true + enabled: loggedIn onTriggered: { content.post.dontChangeRead = true content.post.read = false @@ -73,7 +75,7 @@ MenuBar { MenuItem { text: qsTr("Open in Browser") shortcut: "N" - enabled: true + enabled: loggedIn onTriggered: Qt.openUrlExternally(content.post.link) } } @@ -84,19 +86,19 @@ MenuBar { MenuItem { text: qsTr("Zoom In") shortcut: "Ctrl++" - enabled: true + enabled: loggedIn onTriggered: app.zoomIn() } MenuItem { text: qsTr("Zoom Out") shortcut: "Ctrl+-" - enabled: true + enabled: loggedIn onTriggered: app.zoomOut() } MenuItem { text: qsTr("Reset") shortcut: "Ctrl+0" - enabled: true + enabled: loggedIn onTriggered: app.zoomReset() } } diff --git a/content.css b/content.css index a578306..ff59c26 100644 --- a/content.css +++ b/content.css @@ -3,7 +3,6 @@ body { font-family: sans-serif; padding: 1em 1.5em; font-weight: lighter; - font-size: 1em; } h1 { @@ -27,7 +26,8 @@ h1 { header p { color: #aaa; margin: 0; - padding: 0 + padding: 0; + font-size: 0.8em; } a { @@ -42,4 +42,5 @@ img { article { line-height: 1.6; + font-size: 0.8em; } diff --git a/main.cpp b/main.cpp index 959b088..3f76e93 100644 --- a/main.cpp +++ b/main.cpp @@ -12,8 +12,8 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - app.setOrganizationName("Jabs Nu"); - app.setOrganizationDomain("jabs.nu"); + app.setOrganizationName("Jeena"); + app.setOrganizationDomain("jeena.net"); app.setApplicationName("FeedMonkey"); qmlRegisterType("TTRSS", 1, 0, "ServerLogin"); diff --git a/main.qml b/main.qml index a7a0785..611d35b 100644 --- a/main.qml +++ b/main.qml @@ -10,6 +10,9 @@ ApplicationWindow { title: "FeedMonkey" visible: true + minimumWidth: 480 + minimumHeight: 320 + width: 800 height: 640 x: 200 @@ -19,42 +22,60 @@ ApplicationWindow { property Sidebar sidebar: sidebar property Content content: content - property int defaultTextFontSize: 13 - property int textFontSize: defaultTextFontSize + property variant fontSizes: [7,9,11,13,15,17,19,21,23,25,27,29,31] + property int defaultTextFontSizeIndex: 4 + property int textFontSizeIndex: defaultTextFontSizeIndex + property int textFontSize: fontSizes[textFontSizeIndex] Settings { + id: settings category: "window" property alias x: app.x property alias y: app.y property alias width: app.width property alias height: app.height property alias sidebarWidth: sidebar.width - //property alias textFontSize: app.textFontSize + property alias textFontSizeIndex: app.textFontSizeIndex } property TheMenuBar menu: TheMenuBar { id: menu + serverLogin: serverLogin server: server sidebar: sidebar content: content } function loggedIn() { - menu.loggedIn = true; - login.visible = false; - server.initialize(serverLogin.serverUrl, serverLogin.sessionId); + if(serverLogin.loggedIn()) { + menu.loggedIn = true; + 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() { - textFontSize *= 1.2 + if(textFontSizeIndex + 1 < fontSizes.length) { + textFontSize = fontSizes[++textFontSizeIndex] + } } function zoomOut() { - textFontSize *= 0.8 + if(textFontSizeIndex - 1 > 0) { + textFontSize = fontSizes[--textFontSizeIndex] + } } function zoomReset() { - textFontSize = defaultTextFontSize + textFontSizeIndex = defaultTextFontSizeIndex + textFontSize = fontSizes[textFontSizeIndex] } function keyPressed(event) { @@ -98,6 +119,7 @@ ApplicationWindow { } SplitView { + id: contentView anchors.fill: parent orientation: Qt.Horizontal visible: serverLogin.loggedIn() @@ -140,13 +162,14 @@ ApplicationWindow { visible: !serverLogin.loggedIn() function login() { + console.log("FOO") serverLogin.login(serverUrl, userName, password) } } ServerLogin { id: serverLogin - onSessionIdChanged: loggedIn() + onSessionIdChanged: app.loggedIn() } Server { diff --git a/tinytinyrss.cpp b/tinytinyrss.cpp index b48ee8d..db4cca7 100644 --- a/tinytinyrss.cpp +++ b/tinytinyrss.cpp @@ -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 callback) { QVariantMap options; diff --git a/tinytinyrss.h b/tinytinyrss.h index 1888d1a..8082760 100644 --- a/tinytinyrss.h +++ b/tinytinyrss.h @@ -23,6 +23,7 @@ public: Q_INVOKABLE void initialize(const QString serverUrl, const QString sessionId); Q_INVOKABLE void reload(); + Q_INVOKABLE void loggedOut(); QQmlListProperty posts(); diff --git a/tinytinyrsslogin.cpp b/tinytinyrsslogin.cpp index 7af2ef1..683653b 100644 --- a/tinytinyrsslogin.cpp +++ b/tinytinyrsslogin.cpp @@ -4,12 +4,15 @@ #include #include +#define APP_URL "net.jeena" +#define APP_NAME "FeedMonkey" + TinyTinyRSSLogin::TinyTinyRSSLogin(QObject *parent) : QObject(parent) { mNetworkManager = new QNetworkAccessManager(this); - QSettings settings("net.jeena", "feedmonkey"); + QSettings settings; mSessionId = settings.value("sessionId").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())); } +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() { QNetworkReply *reply = qobject_cast(sender()); @@ -56,7 +77,7 @@ void TinyTinyRSSLogin::reply() emit sessionIdChanged(mSessionId); - QSettings settings("net.jeena", "feedmonkey"); + QSettings settings; settings.setValue("sessionId", mSessionId); settings.setValue("serverUrl", mServerUrl); settings.sync(); diff --git a/tinytinyrsslogin.h b/tinytinyrsslogin.h index 178093f..5fd012c 100644 --- a/tinytinyrsslogin.h +++ b/tinytinyrsslogin.h @@ -20,6 +20,7 @@ public: Q_INVOKABLE bool loggedIn(); Q_INVOKABLE void login(const QString serverUrl, const QString user, const QString password); + Q_INVOKABLE void logout(); signals: void sessionIdChanged(QString);