From c400630bc440e13171ea06397b0bc9660bf9761a Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Sat, 3 May 2014 21:12:20 +0200 Subject: [PATCH] make post --- interface/src/ui/SnapshotShareDialog.cpp | 60 +++++++++++++++++-- interface/src/ui/SnapshotShareDialog.h | 6 ++ .../networking/src/DataServerAccountInfo.cpp | 2 + 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/interface/src/ui/SnapshotShareDialog.cpp b/interface/src/ui/SnapshotShareDialog.cpp index 081d3518b2..921400ba1e 100644 --- a/interface/src/ui/SnapshotShareDialog.cpp +++ b/interface/src/ui/SnapshotShareDialog.cpp @@ -6,10 +6,17 @@ // // +#include "SnapshotShareDialog.h" +#include "AccountManager.h" + +#include +#include +#include +#include + const int NARROW_SNAPSHOT_DIALOG_SIZE = 500; const int WIDE_SNAPSHOT_DIALOG_WIDTH = 650; - -#include "SnapshotShareDialog.h" +const QString FORUM_POST_URL = "http://localhost:4000"; SnapshotShareDialog::SnapshotShareDialog(QString fileName, QWidget* parent) : QDialog(parent), _fileName(fileName) { @@ -46,7 +53,52 @@ SnapshotShareDialog::SnapshotShareDialog(QString fileName, QWidget* parent) : QD } void SnapshotShareDialog::accept() { - // post to Discourse forum - + close(); + + // post to Discourse forum +// AccountManager& accountManager = AccountManager::getInstance(); + QNetworkAccessManager* _networkAccessManager = NULL; + + if (!_networkAccessManager) { + _networkAccessManager = new QNetworkAccessManager(this); + } + + QNetworkRequest request; + + QUrl grantURL(FORUM_POST_URL); + grantURL.setPath("/posts"); + + + QByteArray postData; + // postData.append("api_key=" + accountManager.getAccountInfo().getDiscourseApiKey() + "&"); + postData.append("api_key=9168f53930b2fc69ec278414d6ff04fed723ef717867a25954143150d3e2dfe8&"); + postData.append("topic_id=64&"); + postData.append("raw=" + QUrl::toPercentEncoding(ui.textEdit->toPlainText())); + + request.setUrl(grantURL); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + + QNetworkReply* requestReply = _networkAccessManager->post(request, postData); + connect(_networkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(serviceRequestFinished(QNetworkReply*))); + + connect(requestReply, &QNetworkReply::finished, this, &SnapshotShareDialog::requestFinished); + connect(requestReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(requestError(QNetworkReply::NetworkError))); } + +void SnapshotShareDialog::serviceRequestFinished(QNetworkReply* reply) { + qDebug() << reply->errorString(); +} + +void SnapshotShareDialog::requestFinished() { + + QNetworkReply* requestReply = reinterpret_cast(sender()); + + qDebug() << requestReply->errorString(); + delete requestReply; +} + +void SnapshotShareDialog::requestError(QNetworkReply::NetworkError error) { + // TODO: error handling + qDebug() << "AccountManager requestError - " << error; +} \ No newline at end of file diff --git a/interface/src/ui/SnapshotShareDialog.h b/interface/src/ui/SnapshotShareDialog.h index 2823c8b78d..18a66616db 100644 --- a/interface/src/ui/SnapshotShareDialog.h +++ b/interface/src/ui/SnapshotShareDialog.h @@ -10,6 +10,7 @@ #define __hifi__snapshotShareDialog__ #include "ui_shareSnapshot.h" +#include class SnapshotShareDialog : public QDialog { Q_OBJECT @@ -21,6 +22,11 @@ private: QString _fileName; Ui_SnapshotShareDialog ui; +public slots: + void requestFinished(); + void requestError(QNetworkReply::NetworkError error); + void serviceRequestFinished(QNetworkReply* reply); + private slots: void accept(); }; diff --git a/libraries/networking/src/DataServerAccountInfo.cpp b/libraries/networking/src/DataServerAccountInfo.cpp index d7cbd91e78..a9522148a8 100644 --- a/libraries/networking/src/DataServerAccountInfo.cpp +++ b/libraries/networking/src/DataServerAccountInfo.cpp @@ -37,6 +37,7 @@ DataServerAccountInfo::DataServerAccountInfo(const DataServerAccountInfo& otherI _accessToken = otherInfo._accessToken; _username = otherInfo._username; _xmppPassword = otherInfo._xmppPassword; + _discourseApiKey = otherInfo._discourseApiKey; } DataServerAccountInfo& DataServerAccountInfo::operator=(const DataServerAccountInfo& otherInfo) { @@ -51,6 +52,7 @@ void DataServerAccountInfo::swap(DataServerAccountInfo& otherInfo) { swap(_accessToken, otherInfo._accessToken); swap(_username, otherInfo._username); swap(_xmppPassword, otherInfo._xmppPassword); + swap(_discourseApiKey, otherInfo._discourseApiKey); } void DataServerAccountInfo::setUsername(const QString& username) {