mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 01:56:54 +02:00
make post
This commit is contained in:
parent
b2c1afe1bd
commit
c400630bc4
3 changed files with 64 additions and 4 deletions
|
@ -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 NARROW_SNAPSHOT_DIALOG_SIZE = 500;
|
||||||
const int WIDE_SNAPSHOT_DIALOG_WIDTH = 650;
|
const int WIDE_SNAPSHOT_DIALOG_WIDTH = 650;
|
||||||
|
const QString FORUM_POST_URL = "http://localhost:4000";
|
||||||
#include "SnapshotShareDialog.h"
|
|
||||||
|
|
||||||
SnapshotShareDialog::SnapshotShareDialog(QString fileName, QWidget* parent) : QDialog(parent), _fileName(fileName) {
|
SnapshotShareDialog::SnapshotShareDialog(QString fileName, QWidget* parent) : QDialog(parent), _fileName(fileName) {
|
||||||
|
|
||||||
|
@ -46,7 +53,52 @@ SnapshotShareDialog::SnapshotShareDialog(QString fileName, QWidget* parent) : QD
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnapshotShareDialog::accept() {
|
void SnapshotShareDialog::accept() {
|
||||||
// post to Discourse forum
|
|
||||||
|
|
||||||
close();
|
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;
|
||||||
|
}
|
|
@ -10,6 +10,7 @@
|
||||||
#define __hifi__snapshotShareDialog__
|
#define __hifi__snapshotShareDialog__
|
||||||
|
|
||||||
#include "ui_shareSnapshot.h"
|
#include "ui_shareSnapshot.h"
|
||||||
|
#include <QNetworkReply>
|
||||||
|
|
||||||
class SnapshotShareDialog : public QDialog {
|
class SnapshotShareDialog : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -21,6 +22,11 @@ private:
|
||||||
QString _fileName;
|
QString _fileName;
|
||||||
Ui_SnapshotShareDialog ui;
|
Ui_SnapshotShareDialog ui;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void requestFinished();
|
||||||
|
void requestError(QNetworkReply::NetworkError error);
|
||||||
|
void serviceRequestFinished(QNetworkReply* reply);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void accept();
|
void accept();
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,6 +37,7 @@ DataServerAccountInfo::DataServerAccountInfo(const DataServerAccountInfo& otherI
|
||||||
_accessToken = otherInfo._accessToken;
|
_accessToken = otherInfo._accessToken;
|
||||||
_username = otherInfo._username;
|
_username = otherInfo._username;
|
||||||
_xmppPassword = otherInfo._xmppPassword;
|
_xmppPassword = otherInfo._xmppPassword;
|
||||||
|
_discourseApiKey = otherInfo._discourseApiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
DataServerAccountInfo& DataServerAccountInfo::operator=(const DataServerAccountInfo& otherInfo) {
|
DataServerAccountInfo& DataServerAccountInfo::operator=(const DataServerAccountInfo& otherInfo) {
|
||||||
|
@ -51,6 +52,7 @@ void DataServerAccountInfo::swap(DataServerAccountInfo& otherInfo) {
|
||||||
swap(_accessToken, otherInfo._accessToken);
|
swap(_accessToken, otherInfo._accessToken);
|
||||||
swap(_username, otherInfo._username);
|
swap(_username, otherInfo._username);
|
||||||
swap(_xmppPassword, otherInfo._xmppPassword);
|
swap(_xmppPassword, otherInfo._xmppPassword);
|
||||||
|
swap(_discourseApiKey, otherInfo._discourseApiKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataServerAccountInfo::setUsername(const QString& username) {
|
void DataServerAccountInfo::setUsername(const QString& username) {
|
||||||
|
|
Loading…
Reference in a new issue