173 lines
5.6 KiB
QML
173 lines
5.6 KiB
QML
/*
|
|
* Copyright (C) 2016 Morgan McMillian <gilag@monkeystew.com>
|
|
*
|
|
* This file is apart of the Goober application, a client for pnut.io
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
import bb.cascades 1.4
|
|
import com.monkeystew.pnut 1.0
|
|
import com.monkeystew.qtimer 1.0
|
|
|
|
NavigationPane {
|
|
id: nav
|
|
|
|
property string stream_type
|
|
property string endpoint
|
|
|
|
Page {
|
|
Container {
|
|
ListView {
|
|
id: streamView
|
|
dataModel: ArrayDataModel {
|
|
id: postModel
|
|
}
|
|
listItemComponents: [
|
|
ListItemComponent {
|
|
id: root
|
|
PostItem {}
|
|
}
|
|
]
|
|
onTriggered: {
|
|
var page = threadPage.createObject();
|
|
pnut.threadReceived.connect(page.loadThread);
|
|
pnut.getThread(postModel.data(indexPath).thread_id);
|
|
nav.push(page);
|
|
}
|
|
function sendReply(text, pid) {
|
|
pnut.sendReply(text, pid);
|
|
}
|
|
function getUserName() {
|
|
return _app.setting("username");
|
|
}
|
|
function addBookmark(pid) {
|
|
// pnut.setBookmark(pid);
|
|
console.log("- needs fixing -");
|
|
}
|
|
}
|
|
}
|
|
actions: [
|
|
ActionItem {
|
|
title: qsTr("New Post")
|
|
ActionBar.placement: ActionBarPlacement.Signature
|
|
onTriggered: {
|
|
newPostSheet.open();
|
|
newPostSheet.input.requestFocus();
|
|
}
|
|
imageSource: "asset:///icons/ic_add.png"
|
|
},
|
|
ActionItem {
|
|
title: qsTr("Load Newer")
|
|
ActionBar.placement: ActionBarPlacement.InOverflow
|
|
onTriggered: {
|
|
pnut.getStream(endpoint, Pnut.STREAM_NEWER);
|
|
}
|
|
imageSource: "asset:///icons/ic_to_top.png"
|
|
},
|
|
ActionItem {
|
|
title: qsTr("Reload")
|
|
ActionBar.placement: ActionBarPlacement.InOverflow
|
|
onTriggered: {
|
|
postModel.clear()
|
|
pnut.beforeId = 0
|
|
pnut.sinceId = 0
|
|
pnut.getStream(endpoint, Pnut.STREAM_OLDER);
|
|
}
|
|
imageSource: "asset:///icons/ic_reload.png"
|
|
},
|
|
ActionItem {
|
|
title: qsTr("Load Older")
|
|
ActionBar.placement: ActionBarPlacement.InOverflow
|
|
onTriggered: {
|
|
pnut.getStream(endpoint, Pnut.STREAM_OLDER);
|
|
}
|
|
imageSource: "asset:///icons/ic_to_bottom.png"
|
|
},
|
|
ActionItem {
|
|
title: qsTr("Logout")
|
|
ActionBar.placement: ActionBarPlacement.InOverflow
|
|
onTriggered: {
|
|
postModel.clear()
|
|
pnut.beforeId = 0
|
|
pnut.sinceId = 0
|
|
_app.setSetting("access_token", "");
|
|
}
|
|
}
|
|
]
|
|
actionBarAutoHideBehavior: ActionBarAutoHideBehavior.HideOnScroll
|
|
}
|
|
attachedObjects: [
|
|
ComponentDefinition {
|
|
id: threadPage
|
|
source: "ThreadPage.qml"
|
|
},
|
|
NewPostSheet {
|
|
id: newPostSheet
|
|
onSendPost: {
|
|
console.log("send: " + text);
|
|
pnut.sendPost(text);
|
|
}
|
|
},
|
|
QTimer {
|
|
id: timer
|
|
interval: 30000
|
|
onTimeout: {
|
|
pnut.getStream(endpoint, Pnut.STREAM_NEWER);
|
|
}
|
|
},
|
|
Pnut {
|
|
id: pnut
|
|
|
|
onStreamReceived: {
|
|
switch (rtype) {
|
|
case Pnut.STREAM_OLDER:
|
|
postModel.append(stream);
|
|
break;
|
|
case Pnut.STREAM_NEWER:
|
|
postModel.insert(0, stream);
|
|
break;
|
|
}
|
|
pnut.beforeId = postModel.value(postModel.size() - 1).id;
|
|
pnut.sinceId = postModel.value(0).id;
|
|
}
|
|
|
|
onAuthorizationReceived: {
|
|
pnut.getStream(endpoint, Pnut.STREAM_OLDER);
|
|
timer.start();
|
|
}
|
|
}
|
|
]
|
|
onPopTransitionEnded: {
|
|
page.destroy();
|
|
}
|
|
onCreationCompleted: {
|
|
switch (stream_type) {
|
|
case "Home":
|
|
endpoint = "/posts/streams/me";
|
|
break;
|
|
case "Global":
|
|
default:
|
|
endpoint = "/posts/streams/global"
|
|
break;
|
|
}
|
|
if (_app.setting("access_token") && _app.setting("access_token").length > 0) {
|
|
pnut.getUserInfo();
|
|
pnut.getStream(endpoint, Pnut.STREAM_OLDER);
|
|
timer.start();
|
|
} else {
|
|
pnut.authorize();
|
|
}
|
|
}
|
|
}
|