added threadview

This commit is contained in:
Morgan McMillian 2016-09-24 08:13:45 -07:00
parent f67e4c2104
commit a9a5968d32
9 changed files with 132 additions and 17 deletions

View file

@ -1,5 +1,5 @@
1
16
17
icons/globe.png
icons/ic_add.png
icons/ic_add_bookmarks.png
@ -16,3 +16,4 @@ moment.js
NewPostSheet.qml
PostItem.qml
StreamTab.qml
ThreadPage.qml

View file

@ -27,7 +27,7 @@ Container {
leftPadding: ui.sdu(3.0)
rightPadding: ui.sdu(3.0)
topPadding: ui.sdu(2.0)
bottomPadding: ui.sdu(2.0)
//bottomPadding: ui.sdu(2.0)
property string lorem: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse non enim tellus. Donec vestibulum enim urna, eget faucibus diam commodo a. Donec eget hendrerit metus. Pellentesque vehicula nisi nec vehicula ullamcorper. Aliquam a elit eget mi fringilla porta fermentum eget eros. Phasellus vestibulum nulla sed elit congue adipiscing. Cras imperdiet urna ac ipsum volutpat lobortis. Maecenas vehicula tortor at viverra convallis. Curabitur nibh massa, tristique id felis ut, venenatis faucibus dui. Donec fringilla, mi nec tincidunt dignissim, neque nunc semper mi, quis rutrum diam turpis sit amet erat. Cras a sodales nisi. Nunc sit amet diam sed lectus molestie cursus convallis et erat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Duis vitae varius leo. Mauris eu leo a nunc bibendum rutrum euismod et ipsum. "
property variant theme : Application.themeSupport.theme.colorTheme.style
@ -108,8 +108,9 @@ Container {
topMargin: ui.sdu(2.0)
bottomMargin: ui.sdu(2.0)
Label {
text: ListItemData.content.text
text: ListItemData.content.html
multiline: true
textFormat: TextFormat.Html
}
}
Container {
@ -155,6 +156,14 @@ Container {
}
imageSource: "asset:///icons/ic_reply_all.png"
}
ActionItem {
title: qsTr("Add Bookmark")
imageSource: "asset:///icons/ic_add_bookmarks.png"
onTriggered: {
postitem.ListItem.view.addBookmark(ListItemData.id);
}
enabled: false
}
}
]
attachedObjects: [

View file

@ -40,11 +40,21 @@ NavigationPane {
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")
return _app.setting("username");
}
function addBookmark(pid) {
// pnut.setBookmark(pid);
console.log("- needs fixing -");
}
}
}
@ -99,6 +109,10 @@ NavigationPane {
actionBarAutoHideBehavior: ActionBarAutoHideBehavior.HideOnScroll
}
attachedObjects: [
ComponentDefinition {
id: threadPage
source: "ThreadPage.qml"
},
NewPostSheet {
id: newPostSheet
onSendPost: {
@ -117,9 +131,6 @@ NavigationPane {
id: pnut
onStreamReceived: {
// console.log("- got a result -");
// console.log("- type: " + rtype);
// console.log(stream);
switch (rtype) {
case Pnut.STREAM_OLDER:
postModel.append(stream);
@ -131,7 +142,7 @@ NavigationPane {
pnut.beforeId = postModel.value(postModel.size() - 1).id;
pnut.sinceId = postModel.value(0).id;
}
onAuthorizationReceived: {
pnut.getStream(endpoint, Pnut.STREAM_OLDER);
timer.start();

28
assets/ThreadPage.qml Normal file
View file

@ -0,0 +1,28 @@
import bb.cascades 1.4
Page {
Container {
ListView {
id: threadView
dataModel: ArrayDataModel {
id: threadModel
}
listItemComponents: [
ListItemComponent {
id: root
PostItem {}
}
]
function sendReply(text, pid) {
pnut.sendReply(text, pid);
}
function getUserName() {
return _app.setting("username")
}
}
}
function loadThread(data) {
threadModel.append(data);
}
}

View file

@ -1 +1 @@
26
37

View file

@ -69,6 +69,7 @@ config_pri_assets {
$$quote($$BASEDIR/assets/NewPostSheet.qml) \
$$quote($$BASEDIR/assets/PostItem.qml) \
$$quote($$BASEDIR/assets/StreamTab.qml) \
$$quote($$BASEDIR/assets/ThreadPage.qml) \
$$quote($$BASEDIR/assets/icons/globe.png) \
$$quote($$BASEDIR/assets/icons/ic_add.png) \
$$quote($$BASEDIR/assets/icons/ic_add_bookmarks.png) \

View file

@ -119,6 +119,30 @@ void Pnut::postRequest(QUrl url, KQOAuthParameters parameters, int id, QByteArra
oauthManager->executeAuthorizedRequest(oauthRequest, id);
}
void Pnut::putRequest(QUrl url, KQOAuthParameters parameters, int id)
{
oauthRequest->clearRequest();
oauthRequest->initRequest(KQOAuthRequest::AuthorizedRequest, url);
oauthRequest->setToken(m_appSettings->value("access_token").toString());
oauthRequest->setHttpMethod(KQOAuthRequest::PUT);
oauthRequest->setRequestOAuthMethod(KQOAuthRequest::OAUTH2);
oauthRequest->setAdditionalParameters(parameters);
oauthManager->executeAuthorizedRequest(oauthRequest, id);
}
void Pnut::deleteRequest(QUrl url, KQOAuthParameters parameters, int id)
{
oauthRequest->clearRequest();
oauthRequest->initRequest(KQOAuthRequest::AuthorizedRequest, url);
oauthRequest->setToken(m_appSettings->value("access_token").toString());
oauthRequest->setHttpMethod(KQOAuthRequest::DELETE);
oauthRequest->setRequestOAuthMethod(KQOAuthRequest::OAUTH2);
oauthRequest->setAdditionalParameters(parameters);
oauthManager->executeAuthorizedRequest(oauthRequest, id);
}
void Pnut::onAuthorizationReceived(QString token, QString verifier)
{
switch (oauthManager->lastError())
@ -174,11 +198,17 @@ void Pnut::onAuthorizedRequestReady(QByteArray data, int id)
emit streamReceived(variant.toMap()["data"].toList(), rtype);
req_map.remove(id);
rtype_map.remove(id);
} else if (endpoint == ":me")
}
else if (endpoint == ":me")
{
QVariantMap userinfo(variant.toMap()["data"].toMap());
m_appSettings->setValue("username", userinfo.value("username").toString());
}
else if (endpoint == ":thread")
{
emit threadReceived(variant.toMap()["data"].toList());
req_map.remove(id);
}
break;
}
case Pnut::CREATED:
@ -262,3 +292,27 @@ void Pnut::getUserInfo()
req_map[++req_id] = ":me";
getRequest(url, parameters, req_id);
}
void Pnut::getThread(QString pid)
{
QUrl url(PNUT_API_ROOT + "/posts/" + pid + "/thread");
KQOAuthParameters parameters;
req_map[++req_id] = ":thread";
getRequest(url, parameters, req_id);
}
void Pnut::setBookmark(QString pid)
{
QUrl url(PNUT_API_ROOT + "/posts/" + pid + "/bookmark");
KQOAuthParameters parameters;
req_map[++req_id] = ":bookmark";
putRequest(url, parameters, req_id);
}
void Pnut::deleteBookmark(QString pid)
{
QUrl url(PNUT_API_ROOT + "/posts/" + pid + "/bookmark");
KQOAuthParameters parameters;
req_map[++req_id] = ":bookmark";
deleteRequest(url, parameters, req_id);
}

View file

@ -71,6 +71,9 @@ public:
Q_INVOKABLE void sendReply(QString text, int pid);
Q_INVOKABLE void getUser(QString uid);
Q_INVOKABLE void getUserInfo();
Q_INVOKABLE void getThread(QString pid);
Q_INVOKABLE void setBookmark(QString pid);
Q_INVOKABLE void deleteBookmark(QString pid);
public slots:
void onRequestReady(QByteArray data);
@ -80,6 +83,7 @@ public slots:
Q_SIGNALS:
void authorizationReceived();
void streamReceived(QVariantList stream, Pnut::RequestType rtype);
void threadReceived(QVariantList thread);
private:
static const QString PNUT_API_ROOT;
@ -99,6 +103,8 @@ private:
void getRequest(QUrl url, KQOAuthParameters parameters, int id);
void postRequest(QUrl url, KQOAuthParameters parameters, int id, QByteArray data);
void putRequest(QUrl url, KQOAuthParameters parameters, int id);
void deleteRequest(QUrl url, KQOAuthParameters parameters, int id);
};
#endif /* PNUT_H_ */

View file

@ -22,40 +22,45 @@
<context>
<name>PostItem</name>
<message>
<location filename="../assets/PostItem.qml" line="140"/>
<location filename="../assets/PostItem.qml" line="141"/>
<source>Reply</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../assets/PostItem.qml" line="149"/>
<location filename="../assets/PostItem.qml" line="150"/>
<source>Reply All</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../assets/PostItem.qml" line="160"/>
<source>Add Bookmark</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StreamTab</name>
<message>
<location filename="../assets/StreamTab.qml" line="53"/>
<location filename="../assets/StreamTab.qml" line="63"/>
<source>New Post</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../assets/StreamTab.qml" line="62"/>
<location filename="../assets/StreamTab.qml" line="72"/>
<source>Load Newer</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../assets/StreamTab.qml" line="70"/>
<location filename="../assets/StreamTab.qml" line="80"/>
<source>Reload</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../assets/StreamTab.qml" line="81"/>
<location filename="../assets/StreamTab.qml" line="91"/>
<source>Load Older</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../assets/StreamTab.qml" line="89"/>
<location filename="../assets/StreamTab.qml" line="99"/>
<source>Logout</source>
<translation type="unfinished"></translation>
</message>