fixed login with multiple tabs

This commit is contained in:
Morgan McMillian 2016-10-21 16:53:19 -07:00
parent 81b1874e6e
commit 80ad29bef0
7 changed files with 81 additions and 25 deletions

View file

@ -1,7 +1,7 @@
import bb.cascades 1.4 import bb.cascades 1.4
Sheet { Sheet {
peekEnabled: false // peekEnabled: false
signal login signal login
Page { Page {

View file

@ -28,6 +28,10 @@ NavigationPane {
property string endpoint property string endpoint
property int unread: -1 property int unread: -1
property bool refreshpull: false property bool refreshpull: false
property bool active
signal openLogin()
signal closeLogin()
Page { Page {
Container { Container {
@ -52,10 +56,15 @@ NavigationPane {
var page = threadPage.createObject(); var page = threadPage.createObject();
pnut.threadReceived.connect(page.loadThread); pnut.threadReceived.connect(page.loadThread);
pnut.getThread(postModel.data(indexPath).thread_id); pnut.getThread(postModel.data(indexPath).thread_id);
page.follow.connect(pnut.followUser)
page.unfollow.connect(pnut.unfollowUser)
page.block.connect(pnut.blockUser)
page.unblock.connect(pnut.unblockUser)
page.mute.connect(pnut.muteUser)
page.unmute.connect(pnut.unmuteUser)
nav.push(page); nav.push(page);
} }
function viewProfile(userobj) { function viewProfile(userobj) {
console.log("narf: " + JSON.stringify(userobj))
var page = profilePage.createObject(); var page = profilePage.createObject();
page.user = userobj page.user = userobj
page.follow.connect(pnut.followUser) page.follow.connect(pnut.followUser)
@ -174,14 +183,8 @@ NavigationPane {
NewPostSheet { NewPostSheet {
id: newPostSheet id: newPostSheet
onSendPost: { onSendPost: {
console.log("send: " + text); console.log("send: " + text)
pnut.sendPost(text); pnut.sendPost(text)
}
},
LoginSheet {
id: loginSheet
onLogin: {
pnut.authorize();
} }
}, },
QTimer { QTimer {
@ -217,14 +220,17 @@ NavigationPane {
} }
onAuthorizationRequired: { onAuthorizationRequired: {
loginSheet.open(); console.log("__Got a auth required thingy")
openLogin()
timer.stop(); timer.stop();
} }
onAuthorizationReceived: { onAuthorizationReceived: {
loginSheet.close(); console.log("-- THIS --")
closeLogin()
pnut.getStream(endpoint, Pnut.STREAM_OLDER); pnut.getStream(endpoint, Pnut.STREAM_OLDER);
timer.start(); timer.start();
console.log("__Should be closed now")
} }
onFollowSuccess: update_user_page(user) onFollowSuccess: update_user_page(user)
@ -263,7 +269,7 @@ NavigationPane {
onCreationCompleted: { onCreationCompleted: {
switch (stream_type) { switch (stream_type) {
case "Home": case "Home":
endpoint = "/posts/streams/unified"; endpoint = "/posts/streams/unified"
break; break;
case "Global": case "Global":
default: default:
@ -271,15 +277,20 @@ NavigationPane {
break; break;
} }
if (_app.setting("access_token") && _app.setting("access_token").length > 0) { if (_app.setting("access_token") && _app.setting("access_token").length > 0) {
pnut.getUserInfo(); console.log("__I think I'm authenticated")
pnut.getStream(endpoint, Pnut.STREAM_OLDER); pnut.getUserInfo()
pnut.getStream(endpoint, Pnut.STREAM_OLDER)
timer.start(); timer.start();
} else { } else {
loginSheet.open(); console.log("__I am not authenticated yet")
timer.stop(); openLogin()
timer.stop()
} }
} }
function login() {
pnut.authorize()
}
function logout() { function logout() {
pnut.logout(); pnut.logout()
} }
} }

View file

@ -1,6 +1,14 @@
import bb.cascades 1.4 import bb.cascades 1.4
Page { Page {
signal follow(string uid)
signal unfollow(string uid)
signal block(string uid)
signal unblock(string uid)
signal mute(string uid)
signal unmute(string uid)
Container { Container {
ListView { ListView {
id: threadView id: threadView
@ -19,6 +27,17 @@ Page {
function getUserName() { function getUserName() {
return _app.setting("username") return _app.setting("username")
} }
function viewProfile(userobj) {
var page = profilePage.createObject();
page.user = userobj
page.follow.connect(follow)
page.unfollow.connect(unfollow)
page.block.connect(block)
page.unblock.connect(unblock)
page.mute.connect(mute)
page.unmute.connect(unmute)
nav.push(page);
}
} }
} }

View file

@ -47,6 +47,12 @@ TabbedPane {
delegate: Delegate { delegate: Delegate {
StreamTab { StreamTab {
stream_type: "Home" stream_type: "Home"
onOpenLogin: {
loginSheet.open()
}
onCloseLogin: {
loginSheet.close()
}
} }
} }
imageSource: "asset:///icons/home.png" imageSource: "asset:///icons/home.png"
@ -62,6 +68,12 @@ TabbedPane {
StreamTab { StreamTab {
id: globalTab id: globalTab
stream_type: "Global" stream_type: "Global"
onOpenLogin: {
loginSheet.open()
}
onCloseLogin: {
loginSheet.close()
}
} }
} }
imageSource: "asset:///icons/globe.png" imageSource: "asset:///icons/globe.png"
@ -70,4 +82,13 @@ TabbedPane {
} }
} }
attachedObjects: [
LoginSheet {
id: loginSheet
onLogin: {
activePane.login()
}
}
]
} }

View file

@ -1 +1 @@
138 168

View file

@ -145,8 +145,13 @@ void Pnut::deleteRequest(QUrl url, KQOAuthParameters parameters, int id)
void Pnut::onAuthorizationReceived(QString token, QString verifier) void Pnut::onAuthorizationReceived(QString token, QString verifier)
{ {
qDebug() << "--check check--";
qDebug() << oauthManager->lastError();
qDebug() << "token: " << token;
qDebug() << "verif: " << verifier;
switch (oauthManager->lastError()) switch (oauthManager->lastError())
{ {
case KQOAuthManager::RequestValidationError:
case KQOAuthManager::NoError: case KQOAuthManager::NoError:
qDebug() << "- authorization received -"; qDebug() << "- authorization received -";
m_appSettings->setValue("access_token", token); m_appSettings->setValue("access_token", token);

View file

@ -129,22 +129,22 @@
<context> <context>
<name>StreamTab</name> <name>StreamTab</name>
<message> <message>
<location filename="../assets/StreamTab.qml" line="108"/> <location filename="../assets/StreamTab.qml" line="117"/>
<source>New Post</source> <source>New Post</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../assets/StreamTab.qml" line="117"/> <location filename="../assets/StreamTab.qml" line="131"/>
<source>To Top</source> <source>To Top</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../assets/StreamTab.qml" line="143"/> <location filename="../assets/StreamTab.qml" line="157"/>
<source>To Bottom</source> <source>To Bottom</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../assets/StreamTab.qml" line="132"/> <location filename="../assets/StreamTab.qml" line="146"/>
<source>Reload</source> <source>Reload</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -162,7 +162,7 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../assets/main.qml" line="60"/> <location filename="../assets/main.qml" line="66"/>
<source>Global</source> <source>Global</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>