From a9a5968d32b756cdf5d3c2368b56c59e5706dc9a Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Sat, 24 Sep 2016 08:13:45 -0700 Subject: [PATCH] added threadview --- assets/.assets.index | 3 ++- assets/PostItem.qml | 13 ++++++++-- assets/StreamTab.qml | 21 ++++++++++++---- assets/ThreadPage.qml | 28 +++++++++++++++++++++ buildnum | 2 +- config.pri | 1 + src/Pnut.cpp | 56 +++++++++++++++++++++++++++++++++++++++++- src/Pnut.h | 6 +++++ translations/Goober.ts | 19 ++++++++------ 9 files changed, 132 insertions(+), 17 deletions(-) create mode 100644 assets/ThreadPage.qml diff --git a/assets/.assets.index b/assets/.assets.index index 5953d57..785da60 100644 --- a/assets/.assets.index +++ b/assets/.assets.index @@ -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 diff --git a/assets/PostItem.qml b/assets/PostItem.qml index 389e9dd..0d89fdb 100644 --- a/assets/PostItem.qml +++ b/assets/PostItem.qml @@ -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: [ diff --git a/assets/StreamTab.qml b/assets/StreamTab.qml index 8581c7c..1aeed18 100644 --- a/assets/StreamTab.qml +++ b/assets/StreamTab.qml @@ -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(); diff --git a/assets/ThreadPage.qml b/assets/ThreadPage.qml new file mode 100644 index 0000000..aeeb25a --- /dev/null +++ b/assets/ThreadPage.qml @@ -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); + } +} diff --git a/buildnum b/buildnum index 978b4e8..7c09198 100644 --- a/buildnum +++ b/buildnum @@ -1 +1 @@ -26 \ No newline at end of file +37 \ No newline at end of file diff --git a/config.pri b/config.pri index b6d8440..7f16a96 100644 --- a/config.pri +++ b/config.pri @@ -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) \ diff --git a/src/Pnut.cpp b/src/Pnut.cpp index b72cd5f..39b7616 100644 --- a/src/Pnut.cpp +++ b/src/Pnut.cpp @@ -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); +} diff --git a/src/Pnut.h b/src/Pnut.h index 3f315f9..5f50f87 100644 --- a/src/Pnut.h +++ b/src/Pnut.h @@ -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_ */ diff --git a/translations/Goober.ts b/translations/Goober.ts index b552002..ca1a765 100644 --- a/translations/Goober.ts +++ b/translations/Goober.ts @@ -22,40 +22,45 @@ PostItem - + Reply - + Reply All + + + Add Bookmark + + StreamTab - + New Post - + Load Newer - + Reload - + Load Older - + Logout