make post

This commit is contained in:
Stojce Slavkovski 2014-05-03 21:12:20 +02:00
parent b2c1afe1bd
commit c400630bc4
3 changed files with 64 additions and 4 deletions

View file

@ -6,10 +6,17 @@
//
//
#include "SnapshotShareDialog.h"
#include "AccountManager.h"
#include <QString>
#include <QUrlQuery>
#include <QtNetwork/QNetworkRequest>
#include <QHttpMultiPart>
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<QNetworkReply*>(sender());
qDebug() << requestReply->errorString();
delete requestReply;
}
void SnapshotShareDialog::requestError(QNetworkReply::NetworkError error) {
// TODO: error handling
qDebug() << "AccountManager requestError - " << error;
}

View file

@ -10,6 +10,7 @@
#define __hifi__snapshotShareDialog__
#include "ui_shareSnapshot.h"
#include <QNetworkReply>
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();
};

View file

@ -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) {