diff --git a/interface/resources/qml/hifi/dialogs/SnapshotShareDialog.qml b/interface/resources/qml/hifi/dialogs/SnapshotShareDialog.qml new file mode 100644 index 0000000000..f99b770a78 --- /dev/null +++ b/interface/resources/qml/hifi/dialogs/SnapshotShareDialog.qml @@ -0,0 +1,117 @@ +import QtQuick 2.5 +import QtQuick.Controls 1.4 +import QtQuick.Controls.Styles 1.4 +import QtQuick.XmlListModel 2.0 + +import "../../windows" +import "../../js/Utils.js" as Utils +import "../models" + +Window { + id: root + resizable: true + width: 516 + height: 616 + minSize: Qt.vector2d(500, 600); + maxSize: Qt.vector2d(1000, 800); + + property alias source: image.source + + Rectangle { + anchors.fill: parent + color: "white" + + Item { + anchors { fill: parent; margins: 8 } + + Image { + id: image + anchors { top: parent.top; left: parent.left; right: parent.right; bottom: notesLabel.top; bottomMargin: 8 } + fillMode: Image.PreserveAspectFit + } + + Text { + id: notesLabel + anchors { left: parent.left; bottom: notes.top; bottomMargin: 8; } + text: "Notes about this image" + font.pointSize: 14 + font.bold: true + color: "#666" + } + + TextArea { + id: notes + anchors { left: parent.left; bottom: parent.bottom; right: shareButton.left; rightMargin: 8 } + height: 60 + } + + Button { + id: shareButton + anchors { verticalCenter: notes.verticalCenter; right: parent.right; } + width: 120; height: 50 + text: "Share" + + style: ButtonStyle { + background: Rectangle { + implicitWidth: 120 + implicitHeight: 50 + border.width: control.activeFocus ? 2 : 1 + color: "#333" + radius: 9 + } + label: Text { + color: shareButton.enabled ? "white" : "gray" + font.pixelSize: 18 + font.bold: true + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + anchors.fill: parent + text: shareButton.text + } + } + + onClicked: { + enabled = false; + uploadTimer.start(); + } + + Timer { + id: uploadTimer + running: false + interval: 5 + repeat: false + onTriggered: { + var uploaded = SnapshotUploader.uploadSnapshot(root.source.toString()) + console.log("Uploaded result " + uploaded) + if (!uploaded) { + console.log("Upload failed "); + } + } + } + } + } + + Action { + id: shareAction + text: qsTr("OK") + enabled: root.result ? true : false + shortcut: Qt.Key_Return + onTriggered: { + root.destroy(); + } + } + + Action { + id: cancelAction + text: qsTr("Cancel") + shortcut: Qt.Key_Escape + onTriggered: { + root.destroy(); + } + } + } +} + + + + diff --git a/interface/resources/qml/hifi/overlays/RectangleOverlay.qml b/interface/resources/qml/hifi/overlays/RectangleOverlay.qml index fc4169103a..cba3b560d2 100644 --- a/interface/resources/qml/hifi/overlays/RectangleOverlay.qml +++ b/interface/resources/qml/hifi/overlays/RectangleOverlay.qml @@ -17,7 +17,6 @@ Overlay { for (var i = 0; i < keys.length; ++i) { var key = keys[i]; var value = properties[key]; - console.log("OVERLAY rectangle property " + key + " set to value " + value); switch (key) { case "height": root.height = value; break; case "width": root.width = value; break; @@ -30,7 +29,7 @@ Overlay { case "borderColor": rectangle.border.color = Qt.rgba(value.red / 255, value.green / 255, value.blue / 255, rectangle.border.color.a); break; case "borderWidth": rectangle.border.width = value; break; case "radius": rectangle.radius = value; break; - default: console.log("OVERLAY Unhandled rectangle property " + key); + default: console.warn("OVERLAY Unhandled rectangle property " + key); } } } diff --git a/interface/resources/qml/hifi/overlays/TextOverlay.qml b/interface/resources/qml/hifi/overlays/TextOverlay.qml index ba5cafdf64..20336fdde6 100644 --- a/interface/resources/qml/hifi/overlays/TextOverlay.qml +++ b/interface/resources/qml/hifi/overlays/TextOverlay.qml @@ -46,8 +46,7 @@ Overlay { case "backgroundColor": background.color = Qt.rgba(value.red / 255, value.green / 255, value.blue / 255, background.color.a); break; case "font": textField.font.pixelSize = value.size; break; case "lineHeight": textField.lineHeight = value; break; - default: - console.log("OVERLAY text unhandled property " + key); + default: console.warn("OVERLAY text unhandled property " + key); } } } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d7b487899e..28bc934772 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -155,7 +155,6 @@ #include "ui/AddressBarDialog.h" #include "ui/AvatarInputs.h" #include "ui/AssetUploadDialogFactory.h" -#include "ui/DataWebDialog.h" #include "ui/DialogsManager.h" #include "ui/LoginDialog.h" #include "ui/overlays/Cube3DOverlay.h" @@ -1208,6 +1207,7 @@ void Application::initializeUi() { // For some reason there is already an "Application" object in the QML context, // though I can't find it. Hence, "ApplicationInterface" + rootContext->setContextProperty("SnapshotUploader", new SnapshotUploader()); rootContext->setContextProperty("ApplicationInterface", this); rootContext->setContextProperty("AnimationCache", DependencyManager::get().data()); rootContext->setContextProperty("Audio", &AudioScriptingInterface::getInstance()); @@ -1843,7 +1843,7 @@ void Application::keyPressEvent(QKeyEvent* event) { if (isShifted && isMeta) { auto offscreenUi = DependencyManager::get(); offscreenUi->getRootContext()->engine()->clearComponentCache(); - OffscreenUi::information("Debugging", "Component cache cleared"); + //OffscreenUi::information("Debugging", "Component cache cleared"); // placeholder for dialogs being converted to QML. } break; @@ -4510,10 +4510,10 @@ void Application::takeSnapshot() { return; } - if (!_snapshotShareDialog) { - _snapshotShareDialog = new SnapshotShareDialog(fileName, _glWidget); - } - _snapshotShareDialog->show(); + DependencyManager::get()->load("hifi/dialogs/SnapshotShareDialog.qml", [=](QQmlContext*, QObject* dialog) { + dialog->setProperty("source", QUrl::fromLocalFile(fileName)); + connect(dialog, SIGNAL(uploadSnapshot(const QString& snapshot)), this, SLOT(uploadSnapshot(const QString& snapshot))); + }); } float Application::getRenderResolutionScale() const { diff --git a/interface/src/Application.h b/interface/src/Application.h index 5e9c443bba..4b32d8879b 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -60,7 +60,6 @@ #include "ui/OctreeStatsDialog.h" #include "ui/OverlayConductor.h" #include "ui/overlays/Overlays.h" -#include "ui/SnapshotShareDialog.h" #include "UndoStackScriptingInterface.h" class OffscreenGLCanvas; @@ -453,7 +452,6 @@ private: NodeToOctreeSceneStats _octreeServerSceneStats; ControllerScriptingInterface* _controllerScriptingInterface{ nullptr }; QPointer _logDialog; - QPointer _snapshotShareDialog; FileLogger* _logger; diff --git a/interface/src/ui/ChatInputArea.cpp b/interface/src/ui/ChatInputArea.cpp deleted file mode 100644 index 3e8fc84fe2..0000000000 --- a/interface/src/ui/ChatInputArea.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// -// ChatInputArea.cpp -// interface/src/ui -// -// Created by Ryan Huffman on 4/24/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include "ChatInputArea.h" - -ChatInputArea::ChatInputArea(QWidget* parent) : QTextEdit(parent) { -}; - -void ChatInputArea::insertFromMimeData(const QMimeData* source) { - insertPlainText(source->text()); -}; diff --git a/interface/src/ui/ChatInputArea.h b/interface/src/ui/ChatInputArea.h deleted file mode 100644 index 31d1584df7..0000000000 --- a/interface/src/ui/ChatInputArea.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// ChatInputArea.h -// interface/src/ui -// -// Created by Ryan Huffman on 4/11/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_ChatInputArea_h -#define hifi_ChatInputArea_h - -#include -#include - -class ChatInputArea : public QTextEdit { - Q_OBJECT -public: - ChatInputArea(QWidget* parent); - -protected: - void insertFromMimeData(const QMimeData* source); -}; - -#endif // hifi_ChatInputArea_h diff --git a/interface/src/ui/ChatMessageArea.cpp b/interface/src/ui/ChatMessageArea.cpp deleted file mode 100644 index bef22b9fed..0000000000 --- a/interface/src/ui/ChatMessageArea.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// -// ChatMessageArea.cpp -// interface/src/ui -// -// Created by Ryan Huffman on 4/11/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include "Application.h" -#include "ChatMessageArea.h" -#include -#include - -ChatMessageArea::ChatMessageArea(bool useFixedHeight) : QTextBrowser(), _useFixedHeight(useFixedHeight) { - setOpenLinks(false); - - connect(document()->documentLayout(), &QAbstractTextDocumentLayout::documentSizeChanged, - this, &ChatMessageArea::updateLayout); - - connect(this, &QTextBrowser::anchorClicked, qApp, &Application::openUrl); -} - -void ChatMessageArea::setHtml(const QString& html) { - // Create format with updated line height - QTextBlockFormat format; - format.setLineHeight(CHAT_MESSAGE_LINE_HEIGHT, QTextBlockFormat::ProportionalHeight); - - // Possibly a bug in QT, the format won't take effect if `insertHtml` is used first. Inserting a space and deleting - // it after ensures the format is applied. - QTextCursor cursor = textCursor(); - cursor.setBlockFormat(format); - cursor.insertText(" "); - cursor.insertHtml(html); - cursor.setPosition(0); - cursor.deleteChar(); -} - -void ChatMessageArea::updateLayout() { - if (_useFixedHeight) { - setFixedHeight(document()->size().height()); - updateGeometry(); - emit sizeChanged(size()); - } -} - -void ChatMessageArea::setSize(const QSize& size) { - setFixedHeight(size.height()); - updateGeometry(); -} - -void ChatMessageArea::wheelEvent(QWheelEvent* event) { - // Capture wheel events to stop Ctrl-WheelUp/Down zooming - event->ignore(); -} diff --git a/interface/src/ui/ChatMessageArea.h b/interface/src/ui/ChatMessageArea.h deleted file mode 100644 index 57199538fd..0000000000 --- a/interface/src/ui/ChatMessageArea.h +++ /dev/null @@ -1,37 +0,0 @@ -// -// ChatMessageArea.h -// interface/src/ui -// -// Created by Ryan Huffman on 4/11/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_ChatMessageArea_h -#define hifi_ChatMessageArea_h - -#include - -const int CHAT_MESSAGE_LINE_HEIGHT = 130; - -class ChatMessageArea : public QTextBrowser { - Q_OBJECT -public: - ChatMessageArea(bool useFixedHeight = true); - virtual void setHtml(const QString& html); - -public slots: - void updateLayout(); - void setSize(const QSize& size); - -signals: - void sizeChanged(QSize newSize); - -protected: - virtual void wheelEvent(QWheelEvent* event); - bool _useFixedHeight; -}; - -#endif // hifi_ChatMessageArea_h diff --git a/interface/src/ui/DataWebDialog.cpp b/interface/src/ui/DataWebDialog.cpp deleted file mode 100644 index a92e0ac214..0000000000 --- a/interface/src/ui/DataWebDialog.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// -// DataWebDialog.cpp -// interface/src/ui -// -// Created by Stephen Birarda on 2014-09-17. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include -#include - -#include -#include - -#include "Application.h" -#include "DataWebPage.h" - -#include "DataWebDialog.h" - -DataWebDialog::DataWebDialog() { - // make sure the dialog deletes itself when it closes - setAttribute(Qt::WA_DeleteOnClose); - - // set our page to a DataWebPage - setPage(new DataWebPage(this)); - - // have the Application handle external links - connect(this, &QWebView::linkClicked, qApp, &Application::openUrl); -} - -DataWebDialog* DataWebDialog::dialogForPath(const QString& path, - const JavascriptObjectMap& javascriptObjects) { - DataWebDialog* dialogWebView = new DataWebDialog(); - - dialogWebView->_javascriptObjects = javascriptObjects; - connect(dialogWebView->page()->mainFrame(), &QWebFrame::javaScriptWindowObjectCleared, - dialogWebView, &DataWebDialog::addJavascriptObjectsToWindow); - - QUrl dataWebUrl(NetworkingConstants::METAVERSE_SERVER_URL); - dataWebUrl.setPath(path); - - qDebug() << "Opening a data web dialog for" << dataWebUrl.toString(); - - dialogWebView->load(dataWebUrl); - - return dialogWebView; -} - -void DataWebDialog::addJavascriptObjectsToWindow() { - foreach(const QString& name, _javascriptObjects.keys()) { - page()->mainFrame()->addToJavaScriptWindowObject(name, _javascriptObjects[name]); - } -} \ No newline at end of file diff --git a/interface/src/ui/DataWebDialog.h b/interface/src/ui/DataWebDialog.h deleted file mode 100644 index 219e674620..0000000000 --- a/interface/src/ui/DataWebDialog.h +++ /dev/null @@ -1,32 +0,0 @@ -// -// DataWebDialog.h -// interface/src/ui -// -// Created by Stephen Birarda on 2014-09-17. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_DataWebDialog_h -#define hifi_DataWebDialog_h - -#include -#include - -typedef QMap JavascriptObjectMap; - -class DataWebDialog : public QWebView { - Q_OBJECT -public: - DataWebDialog(); - static DataWebDialog* dialogForPath(const QString& path, - const JavascriptObjectMap& javascriptObjects = JavascriptObjectMap()); -private slots: - void addJavascriptObjectsToWindow(); -private: - JavascriptObjectMap _javascriptObjects; -}; - -#endif // hifi_WebkitDialog_h \ No newline at end of file diff --git a/interface/src/ui/Snapshot.cpp b/interface/src/ui/Snapshot.cpp index 41bd379c32..e35039df3d 100644 --- a/interface/src/ui/Snapshot.cpp +++ b/interface/src/ui/Snapshot.cpp @@ -9,13 +9,17 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -23,6 +27,8 @@ #include #include #include +#include +#include #include "Application.h" #include "Snapshot.h" @@ -128,4 +134,116 @@ QFile* Snapshot::savedFileForSnapshot(QImage & shot, bool isTemporary) { } } +const QString FORUM_URL = "https://alphas.highfidelity.io"; +const QString FORUM_UPLOADS_URL = FORUM_URL + "/uploads"; +const QString FORUM_POST_URL = FORUM_URL + "/posts"; +const QString FORUM_REPLY_TO_TOPIC = "244"; +const QString FORUM_POST_TEMPLATE = "

%2

"; +const QString SHARE_DEFAULT_ERROR = "The server isn't responding. Please try again in a few minutes."; +const QString SUCCESS_LABEL_TEMPLATE = "Success!!! Go check out your image ...
%1"; + + +QString SnapshotUploader::uploadSnapshot(const QUrl& fileUrl) { + if (AccountManager::getInstance().getAccountInfo().getDiscourseApiKey().isEmpty()) { + OffscreenUi::warning(nullptr, "", "Your Discourse API key is missing, you cannot share snapshots. Please try to relog."); + return QString(); + } + + QHttpPart apiKeyPart; + apiKeyPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"api_key\"")); + apiKeyPart.setBody(AccountManager::getInstance().getAccountInfo().getDiscourseApiKey().toLatin1()); + + QString filename = fileUrl.toLocalFile(); + qDebug() << filename; + QFile* file = new QFile(filename); + Q_ASSERT(file->exists()); + file->open(QIODevice::ReadOnly); + + QHttpPart imagePart; + imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg")); + imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, + QVariant("form-data; name=\"file\"; filename=\"" + file->fileName() + "\"")); + imagePart.setBodyDevice(file); + + QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); + file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart + multiPart->append(apiKeyPart); + multiPart->append(imagePart); + + QUrl url(FORUM_UPLOADS_URL); + QNetworkRequest request(url); + request.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); + + QString result; + QEventLoop loop; + + QSharedPointer reply(NetworkAccessManager::getInstance().post(request, multiPart)); + QObject::connect(reply.data(), &QNetworkReply::finished, [&] { + loop.quit(); + + qDebug() << reply->errorString(); + for (const auto& header : reply->rawHeaderList()) { + qDebug() << "Header " << QString(header); + } + auto replyResult = reply->readAll(); + qDebug() << QString(replyResult); + QJsonDocument jsonResponse = QJsonDocument::fromJson(replyResult); + const QJsonObject& responseObject = jsonResponse.object(); + if (!responseObject.contains("url")) { + OffscreenUi::warning(this, "", SHARE_DEFAULT_ERROR); + return; + } + result = responseObject["url"].toString(); + }); + loop.exec(); + return result; +} + +QString SnapshotUploader::sendForumPost(const QString& snapshotPath, const QString& notes) { + // post to Discourse forum + QNetworkRequest request; + request.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); + QUrl forumUrl(FORUM_POST_URL); + + QUrlQuery query; + query.addQueryItem("api_key", AccountManager::getInstance().getAccountInfo().getDiscourseApiKey()); + query.addQueryItem("topic_id", FORUM_REPLY_TO_TOPIC); + query.addQueryItem("raw", FORUM_POST_TEMPLATE.arg(snapshotPath, notes)); + forumUrl.setQuery(query); + + QByteArray postData = forumUrl.toEncoded(QUrl::RemoveFragment); + request.setUrl(forumUrl); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + + QNetworkReply* requestReply = NetworkAccessManager::getInstance().post(request, postData); + + QEventLoop loop; + QString result; + connect(requestReply, &QNetworkReply::finished, [&] { + loop.quit(); + QJsonDocument jsonResponse = QJsonDocument::fromJson(requestReply->readAll()); + requestReply->deleteLater(); + const QJsonObject& responseObject = jsonResponse.object(); + + if (!responseObject.contains("id")) { + QString errorMessage(SHARE_DEFAULT_ERROR); + if (responseObject.contains("errors")) { + QJsonArray errorArray = responseObject["errors"].toArray(); + if (!errorArray.first().toString().isEmpty()) { + errorMessage = errorArray.first().toString(); + } + } + OffscreenUi::warning(this, "", errorMessage); + return; + } + + const QString urlTemplate = "%1/t/%2/%3/%4"; + result = urlTemplate.arg(FORUM_URL, + responseObject["topic_slug"].toString(), + QString::number(responseObject["topic_id"].toDouble()), + QString::number(responseObject["post_number"].toDouble())); + }); + loop.exec(); + return result; +} diff --git a/interface/src/ui/Snapshot.h b/interface/src/ui/Snapshot.h index 5856743141..d87a70255f 100644 --- a/interface/src/ui/Snapshot.h +++ b/interface/src/ui/Snapshot.h @@ -43,4 +43,12 @@ private: static QFile* savedFileForSnapshot(QImage & image, bool isTemporary); }; +class SnapshotUploader : public QObject{ + Q_OBJECT +public: + SnapshotUploader(QObject* parent = nullptr) : QObject(parent) {} + Q_INVOKABLE QString uploadSnapshot(const QUrl& fileUrl); + Q_INVOKABLE QString sendForumPost(const QString& snapshotPath, const QString& notes); +}; + #endif // hifi_Snapshot_h diff --git a/interface/src/ui/SnapshotShareDialog.cpp b/interface/src/ui/SnapshotShareDialog.cpp index ddebfe25fd..94f89641e2 100644 --- a/interface/src/ui/SnapshotShareDialog.cpp +++ b/interface/src/ui/SnapshotShareDialog.cpp @@ -9,16 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "SnapshotShareDialog.h" -#include "AccountManager.h" -#include "SharedUtil.h" +#if 0 -#include -#include -#include -#include -#include -#include #include @@ -26,13 +18,6 @@ const int NARROW_SNAPSHOT_DIALOG_SIZE = 500; const int WIDE_SNAPSHOT_DIALOG_WIDTH = 650; const int SUCCESS_LABEL_HEIGHT = 140; -const QString FORUM_URL = "https://alphas.highfidelity.io"; -const QString FORUM_UPLOADS_URL = FORUM_URL + "/uploads"; -const QString FORUM_POST_URL = FORUM_URL + "/posts"; -const QString FORUM_REPLY_TO_TOPIC = "244"; -const QString FORUM_POST_TEMPLATE = "

%2

"; -const QString SHARE_DEFAULT_ERROR = "The server isn't responding. Please try again in a few minutes."; -const QString SUCCESS_LABEL_TEMPLATE = "Success!!! Go check out your image ...
%1"; const QString SHARE_BUTTON_STYLE = "border-width:0;border-radius:9px;border-radius:9px;font-family:Arial;font-size:18px;" "font-weight:100;color:#FFFFFF;width: 120px;height: 50px;"; const QString SHARE_BUTTON_ENABLED_STYLE = "background-color: #333;"; @@ -45,33 +30,6 @@ SnapshotShareDialog::SnapshotShareDialog(QString fileName, QWidget* parent) : _fileName(fileName) { - setAttribute(Qt::WA_DeleteOnClose); - - _ui.setupUi(this); - - QPixmap snaphsotPixmap(fileName); - float snapshotRatio = static_cast(snaphsotPixmap.size().width()) / snaphsotPixmap.size().height(); - - // narrow snapshot - if (snapshotRatio > 1) { - setFixedWidth(WIDE_SNAPSHOT_DIALOG_WIDTH); - _ui.snapshotWidget->setFixedWidth(WIDE_SNAPSHOT_DIALOG_WIDTH); - } - - float labelRatio = static_cast(_ui.snapshotWidget->size().width()) / _ui.snapshotWidget->size().height(); - - // set the same aspect ratio of label as of snapshot - if (snapshotRatio > labelRatio) { - int oldHeight = _ui.snapshotWidget->size().height(); - _ui.snapshotWidget->setFixedHeight((int) (_ui.snapshotWidget->size().width() / snapshotRatio)); - - // if height is less then original, resize the window as well - if (_ui.snapshotWidget->size().height() < NARROW_SNAPSHOT_DIALOG_SIZE) { - setFixedHeight(size().height() - (oldHeight - _ui.snapshotWidget->size().height())); - } - } else { - _ui.snapshotWidget->setFixedWidth((int) (_ui.snapshotWidget->size().height() * snapshotRatio)); - } _ui.snapshotWidget->setPixmap(snaphsotPixmap); _ui.snapshotWidget->adjustSize(); @@ -85,119 +43,5 @@ void SnapshotShareDialog::accept() { uploadSnapshot(); } -void SnapshotShareDialog::uploadSnapshot() { - if (AccountManager::getInstance().getAccountInfo().getDiscourseApiKey().isEmpty()) { - OffscreenUi::warning(this, "", - "Your Discourse API key is missing, you cannot share snapshots. Please try to relog."); - return; - } - - QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); - - QHttpPart apiKeyPart; - apiKeyPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"api_key\"")); - apiKeyPart.setBody(AccountManager::getInstance().getAccountInfo().getDiscourseApiKey().toLatin1()); - - QFile* file = new QFile(_fileName); - file->open(QIODevice::ReadOnly); - - QHttpPart imagePart; - imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg")); - imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, - QVariant("form-data; name=\"file\"; filename=\"" + file->fileName() +"\"")); - imagePart.setBodyDevice(file); - file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart - - multiPart->append(apiKeyPart); - multiPart->append(imagePart); - - QUrl url(FORUM_UPLOADS_URL); - QNetworkRequest request(url); - request.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); - - QNetworkReply* reply = NetworkAccessManager::getInstance().post(request, multiPart); - connect(reply, &QNetworkReply::finished, this, &SnapshotShareDialog::uploadRequestFinished); - - QEventLoop loop; - connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); - loop.exec(); -} - -void SnapshotShareDialog::sendForumPost(QString snapshotPath) { - // post to Discourse forum - QNetworkRequest request; - request.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); - QUrl forumUrl(FORUM_POST_URL); - - QUrlQuery query; - query.addQueryItem("api_key", AccountManager::getInstance().getAccountInfo().getDiscourseApiKey()); - query.addQueryItem("topic_id", FORUM_REPLY_TO_TOPIC); - query.addQueryItem("raw", FORUM_POST_TEMPLATE.arg(snapshotPath, _ui.textEdit->toPlainText())); - forumUrl.setQuery(query); - - QByteArray postData = forumUrl.toEncoded(QUrl::RemoveFragment); - request.setUrl(forumUrl); - request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); - - QNetworkReply* requestReply = NetworkAccessManager::getInstance().post(request, postData); - connect(requestReply, &QNetworkReply::finished, this, &SnapshotShareDialog::postRequestFinished); - - QEventLoop loop; - connect(requestReply, &QNetworkReply::finished, &loop, &QEventLoop::quit); - loop.exec(); -} - -void SnapshotShareDialog::postRequestFinished() { - - QNetworkReply* requestReply = reinterpret_cast(sender()); - QJsonDocument jsonResponse = QJsonDocument::fromJson(requestReply->readAll()); - requestReply->deleteLater(); - const QJsonObject& responseObject = jsonResponse.object(); - - if (responseObject.contains("id")) { - _ui.textEdit->setHtml(""); - const QString urlTemplate = "%1/t/%2/%3/%4"; - QString link = urlTemplate.arg(FORUM_URL, - responseObject["topic_slug"].toString(), - QString::number(responseObject["topic_id"].toDouble()), - QString::number(responseObject["post_number"].toDouble())); - - _ui.successLabel->setText(SUCCESS_LABEL_TEMPLATE.arg(link)); - _ui.successLabel->setFixedHeight(SUCCESS_LABEL_HEIGHT); - - // hide input widgets - _ui.shareButton->hide(); - _ui.textEdit->hide(); - _ui.labelNotes->hide(); - - } else { - QString errorMessage(SHARE_DEFAULT_ERROR); - if (responseObject.contains("errors")) { - QJsonArray errorArray = responseObject["errors"].toArray(); - if (!errorArray.first().toString().isEmpty()) { - errorMessage = errorArray.first().toString(); - } - } - OffscreenUi::warning(this, "", errorMessage); - _ui.shareButton->setEnabled(true); - _ui.shareButton->setStyleSheet(SHARE_BUTTON_STYLE + SHARE_BUTTON_ENABLED_STYLE); - } -} - -void SnapshotShareDialog::uploadRequestFinished() { - - QNetworkReply* requestReply = reinterpret_cast(sender()); - QJsonDocument jsonResponse = QJsonDocument::fromJson(requestReply->readAll()); - const QJsonObject& responseObject = jsonResponse.object(); - - if (responseObject.contains("url")) { - sendForumPost(responseObject["url"].toString()); - } else { - OffscreenUi::warning(this, "", SHARE_DEFAULT_ERROR); - _ui.shareButton->setEnabled(true); - _ui.shareButton->setStyleSheet(SHARE_BUTTON_STYLE + SHARE_BUTTON_ENABLED_STYLE); - } - - delete requestReply; -} +#endif diff --git a/interface/src/ui/SnapshotShareDialog.h b/interface/src/ui/SnapshotShareDialog.h deleted file mode 100644 index ced9f2d951..0000000000 --- a/interface/src/ui/SnapshotShareDialog.h +++ /dev/null @@ -1,39 +0,0 @@ -// -// SnapshotShareDialog.h -// interface/src/ui -// -// Created by Stojce Slavkovski on 2/16/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_snapshotShareDialog -#define hifi_snapshotShareDialog - -#include "ui_shareSnapshot.h" - -#include -#include - -class SnapshotShareDialog : public QDialog { - Q_OBJECT - -public: - SnapshotShareDialog(QString fileName, QWidget* parent = 0); - -private: - QString _fileName; - Ui_SnapshotShareDialog _ui; - - void uploadSnapshot(); - void sendForumPost(QString snapshotPath); - -private slots: - void uploadRequestFinished(); - void postRequestFinished(); - void accept(); -}; - -#endif // hifi_snapshotShareDialog