From 5f73b76be755175c766e709e6965fe4e4b651b6e Mon Sep 17 00:00:00 2001 From: stojce Date: Sun, 2 Mar 2014 14:36:01 +0100 Subject: [PATCH 01/15] Share dialog --- interface/src/ui/Snapshot.cpp | 3 + interface/src/ui/SnapshotShareDialog.cpp | 13 ++++ interface/src/ui/SnapshotShareDialog.h | 14 ++++ interface/ui/shareSnapshot.ui | 99 ++++++++++++++++++++++++ snapshotShareDialog.cpp | 9 +++ snapshotShareDialog.h | 14 ++++ 6 files changed, 152 insertions(+) create mode 100644 interface/src/ui/SnapshotShareDialog.cpp create mode 100644 interface/src/ui/SnapshotShareDialog.h create mode 100644 interface/ui/shareSnapshot.ui create mode 100644 snapshotShareDialog.cpp create mode 100644 snapshotShareDialog.h diff --git a/interface/src/ui/Snapshot.cpp b/interface/src/ui/Snapshot.cpp index f0fef33cee..89b0d56a0b 100644 --- a/interface/src/ui/Snapshot.cpp +++ b/interface/src/ui/Snapshot.cpp @@ -9,6 +9,7 @@ #include "Snapshot.h" #include +#include #include #include @@ -41,6 +42,8 @@ void Snapshot::saveSnapshot(QGLWidget* widget, QString username, glm::vec3 locat QString fileName = FileUtils::standardPath(SNAPSHOTS_DIRECTORY); fileName.append(QString(FILENAME_PATH_FORMAT.arg(username, now.toString(DATETIME_FORMAT), formattedLocation))); shot.save(fileName, 0, 100); + + } diff --git a/interface/src/ui/SnapshotShareDialog.cpp b/interface/src/ui/SnapshotShareDialog.cpp new file mode 100644 index 0000000000..76556e0222 --- /dev/null +++ b/interface/src/ui/SnapshotShareDialog.cpp @@ -0,0 +1,13 @@ +// +// snapshotShareDialog.cpp +// hifi +// +// Created by Stojce Slavkovski on 2/16/14. +// +// + +#include "snapshotShareDialog.h" + +#include "ui_shareSnapshot.h" + + diff --git a/interface/src/ui/SnapshotShareDialog.h b/interface/src/ui/SnapshotShareDialog.h new file mode 100644 index 0000000000..77e92216fd --- /dev/null +++ b/interface/src/ui/SnapshotShareDialog.h @@ -0,0 +1,14 @@ +// +// snapshotShareDialog.h +// hifi +// +// Created by Stojce Slavkovski on 2/16/14. +// +// + +#ifndef __hifi__snapshotShareDialog__ +#define __hifi__snapshotShareDialog__ + +#include + +#endif /* defined(__hifi__snapshotShareDialog__) */ diff --git a/interface/ui/shareSnapshot.ui b/interface/ui/shareSnapshot.ui new file mode 100644 index 0000000000..94c1b4220e --- /dev/null +++ b/interface/ui/shareSnapshot.ui @@ -0,0 +1,99 @@ + + + Dialog + + + Qt::NonModal + + + + 0 + 0 + 808 + 577 + + + + PointingHandCursor + + + Share with community + + + background-color: rgb(255, 255, 255); + + + + + -1 + -1 + 681 + 511 + + + + + + + + 0 + 0 + + + + background-color: #000; + + + + + + + + 0 + 0 + + + + Notes about this image + + + + + + + + + + 0 + 0 + + + + + + + + background-color: #333333; + border-width: 0; + border-radius: 9px; + border-radius: 9px; + font-family: Arial; + font-size: 18px; + font-weight: 100; + color: #FFFFFF; + width: 120px; + height: 50px; + + + Share + + + + + + + + + + + diff --git a/snapshotShareDialog.cpp b/snapshotShareDialog.cpp new file mode 100644 index 0000000000..53a445292f --- /dev/null +++ b/snapshotShareDialog.cpp @@ -0,0 +1,9 @@ +// +// snapshotShareDialog.cpp +// hifi +// +// Created by Stojce Slavkovski on 2/16/14. +// +// + +#include "snapshotShareDialog.h" diff --git a/snapshotShareDialog.h b/snapshotShareDialog.h new file mode 100644 index 0000000000..77e92216fd --- /dev/null +++ b/snapshotShareDialog.h @@ -0,0 +1,14 @@ +// +// snapshotShareDialog.h +// hifi +// +// Created by Stojce Slavkovski on 2/16/14. +// +// + +#ifndef __hifi__snapshotShareDialog__ +#define __hifi__snapshotShareDialog__ + +#include + +#endif /* defined(__hifi__snapshotShareDialog__) */ From e2eb34b6c997bb428004a56f12930b80d7d6645a Mon Sep 17 00:00:00 2001 From: stojce Date: Sun, 23 Mar 2014 07:03:20 +0100 Subject: [PATCH 02/15] Layout setup image ratio fixed image centre position --- interface/interface_en.ts | 33 +++- interface/src/Application.cpp | 7 +- interface/src/Application.h | 2 + interface/src/ui/Snapshot.cpp | 5 +- interface/src/ui/Snapshot.h | 2 +- interface/src/ui/SnapshotShareDialog.cpp | 23 ++- interface/src/ui/SnapshotShareDialog.h | 15 +- interface/ui/shareSnapshot.ui | 187 +++++++++++++++++++++-- 8 files changed, 247 insertions(+), 27 deletions(-) diff --git a/interface/interface_en.ts b/interface/interface_en.ts index 34e3614716..f8de770fca 100644 --- a/interface/interface_en.ts +++ b/interface/interface_en.ts @@ -14,12 +14,12 @@ - + Open Script - + JavaScript Files (*.js) @@ -113,18 +113,18 @@ Menu - + Open .ini config file - - + + Text files (*.ini) - + Save .ini config file @@ -158,4 +158,25 @@ + + SnapshotShareDialog + + + + Share with community + + + + + + Notes about this image + + + + + + Share + + + diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9563cbf3b4..e819422d46 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3671,5 +3671,10 @@ void Application::takeSnapshot() { player->setMedia(QUrl::fromLocalFile(inf.absoluteFilePath())); player->play(); - Snapshot::saveSnapshot(_glWidget, _myAvatar); + QString fileName = Snapshot::saveSnapshot(_glWidget, _myAvatar); + + if (!_snapshotShareDialog) { + _snapshotShareDialog = new SnapshotShareDialog(fileName, _glWidget); + } + _snapshotShareDialog->exec(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 28060113a9..bc401c7de5 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -66,6 +66,7 @@ #include "ui/BandwidthDialog.h" #include "ui/OctreeStatsDialog.h" #include "ui/RearMirrorTools.h" +#include "ui/SnapshotShareDialog.h" #include "ui/LodToolsDialog.h" #include "ui/LogDialog.h" #include "ui/UpdateDialog.h" @@ -473,6 +474,7 @@ private: std::vector _voxelFades; ControllerScriptingInterface _controllerScriptingInterface; QPointer _logDialog; + QPointer _snapshotShareDialog; FileLogger* _logger; diff --git a/interface/src/ui/Snapshot.cpp b/interface/src/ui/Snapshot.cpp index 998aef82e4..90a226c594 100644 --- a/interface/src/ui/Snapshot.cpp +++ b/interface/src/ui/Snapshot.cpp @@ -11,7 +11,6 @@ #include #include -#include #include "Snapshot.h" @@ -61,7 +60,7 @@ SnapshotMetaData* Snapshot::parseSnapshotData(QString snapshotPath) { return data; } -void Snapshot::saveSnapshot(QGLWidget* widget, Avatar* avatar) { +QString Snapshot::saveSnapshot(QGLWidget* widget, Avatar* avatar) { QImage shot = widget->grabFrameBuffer(); glm::vec3 location = avatar->getPosition(); @@ -93,7 +92,7 @@ void Snapshot::saveSnapshot(QGLWidget* widget, Avatar* avatar) { fileName.append(QString(FILENAME_PATH_FORMAT.arg(username, now.toString(DATETIME_FORMAT), formattedLocation))); shot.save(fileName, 0, 100); - + return fileName; } diff --git a/interface/src/ui/Snapshot.h b/interface/src/ui/Snapshot.h index 1b78e8328e..83cfe5bc85 100644 --- a/interface/src/ui/Snapshot.h +++ b/interface/src/ui/Snapshot.h @@ -38,7 +38,7 @@ private: class Snapshot { public: - static void saveSnapshot(QGLWidget* widget, Avatar* avatar); + static QString saveSnapshot(QGLWidget* widget, Avatar* avatar); static SnapshotMetaData* parseSnapshotData(QString snapshotPath); }; diff --git a/interface/src/ui/SnapshotShareDialog.cpp b/interface/src/ui/SnapshotShareDialog.cpp index 76556e0222..2af564ff0b 100644 --- a/interface/src/ui/SnapshotShareDialog.cpp +++ b/interface/src/ui/SnapshotShareDialog.cpp @@ -1,13 +1,30 @@ // -// snapshotShareDialog.cpp +// SnapshotShareDialog.cpp // hifi // // Created by Stojce Slavkovski on 2/16/14. // // -#include "snapshotShareDialog.h" +#include "SnapshotShareDialog.h" -#include "ui_shareSnapshot.h" +SnapshotShareDialog::SnapshotShareDialog(QString fileName, QWidget* parent) : QDialog(parent), _fileName(fileName) { + setAttribute(Qt::WA_DeleteOnClose); + ui.setupUi(this); + + QPixmap snaphsotPixmap(fileName); + float snapshotRatio = static_cast(snaphsotPixmap.size().width()) / snaphsotPixmap.size().height(); + 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) { + ui.snapshotWidget->setFixedHeight(ui.snapshotWidget->size().width() / snapshotRatio); + } else { + ui.snapshotWidget->setFixedWidth(ui.snapshotWidget->size().height() * snapshotRatio); + } + + ui.snapshotWidget->setPixmap(snaphsotPixmap); + ui.snapshotWidget->adjustSize(); +} diff --git a/interface/src/ui/SnapshotShareDialog.h b/interface/src/ui/SnapshotShareDialog.h index 77e92216fd..077acd182b 100644 --- a/interface/src/ui/SnapshotShareDialog.h +++ b/interface/src/ui/SnapshotShareDialog.h @@ -1,5 +1,5 @@ // -// snapshotShareDialog.h +// SnapshotShareDialog.h // hifi // // Created by Stojce Slavkovski on 2/16/14. @@ -9,6 +9,17 @@ #ifndef __hifi__snapshotShareDialog__ #define __hifi__snapshotShareDialog__ -#include +#include "ui_shareSnapshot.h" + +class SnapshotShareDialog : public QDialog { + Q_OBJECT + +public: + SnapshotShareDialog(QString fileName, QWidget* parent = 0); + +private: + QString _fileName; + Ui_SnapshotShareDialog ui; +}; #endif /* defined(__hifi__snapshotShareDialog__) */ diff --git a/interface/ui/shareSnapshot.ui b/interface/ui/shareSnapshot.ui index 94c1b4220e..039e611115 100644 --- a/interface/ui/shareSnapshot.ui +++ b/interface/ui/shareSnapshot.ui @@ -1,7 +1,7 @@ - Dialog - + SnapshotShareDialog + Qt::NonModal @@ -9,10 +9,28 @@ 0 0 - 808 - 577 + 789 + 645 + + + 0 + 0 + + + + + 789 + 645 + + + + + 789 + 645 + + PointingHandCursor @@ -22,33 +40,149 @@ background-color: rgb(255, 255, 255); + + true + -1 -1 - 681 - 511 + 792 + 645 - + - + 0 0 - - background-color: #000; + + + 790 + 510 + + + background-color: #333; + + + QFrame::StyledPanel + + + QFrame::Raised + + + 0 + + + + + -1 + 1 + 791 + 512 + + + + + 0 + + + + + + 0 + 0 + + + + + 790 + 510 + + + + background-color: #ccc; + + + 0 + + + true + + + Qt::AlignCenter + + + 0 + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + - + 0 0 @@ -56,10 +190,25 @@ Notes about this image + + 0 + + + 20 + + + 0 + + + 20 + + + 20 + @@ -70,6 +219,22 @@ + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + From 0a0515b652d359bc833faacecea08ce3b42aa330 Mon Sep 17 00:00:00 2001 From: stojce Date: Mon, 24 Mar 2014 20:35:28 +0100 Subject: [PATCH 03/15] layout / font changes --- interface/interface_en.ts | 10 +++++----- interface/ui/shareSnapshot.ui | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/interface/interface_en.ts b/interface/interface_en.ts index f8de770fca..ce777b8551 100644 --- a/interface/interface_en.ts +++ b/interface/interface_en.ts @@ -162,19 +162,19 @@ SnapshotShareDialog - + Share with community - - + + Notes about this image - - + + Share diff --git a/interface/ui/shareSnapshot.ui b/interface/ui/shareSnapshot.ui index 039e611115..3d729cf9df 100644 --- a/interface/ui/shareSnapshot.ui +++ b/interface/ui/shareSnapshot.ui @@ -53,6 +53,9 @@ + + 0 + @@ -68,13 +71,13 @@ - background-color: #333; + background-color: #000 - QFrame::StyledPanel + QFrame::NoFrame - QFrame::Raised + QFrame::Plain 0 @@ -84,7 +87,7 @@ -1 1 - 791 + 792 512 @@ -187,9 +190,28 @@ 0 + + + 0 + 30 + + + + + Helvetica + 75 + true + + + + color: #666; + Notes about this image + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + 0 @@ -217,6 +239,11 @@ 0 + + + Helvetica + + From 63a29cad0a591c1c6598dd6520f4b2788ffcfb0c Mon Sep 17 00:00:00 2001 From: stojce Date: Mon, 24 Mar 2014 20:39:13 +0100 Subject: [PATCH 04/15] layout fixes --- interface/interface_en.ts | 10 +++--- interface/ui/shareSnapshot.ui | 68 ++++++++--------------------------- 2 files changed, 19 insertions(+), 59 deletions(-) diff --git a/interface/interface_en.ts b/interface/interface_en.ts index ce777b8551..2d2f4c1c07 100644 --- a/interface/interface_en.ts +++ b/interface/interface_en.ts @@ -162,19 +162,19 @@ SnapshotShareDialog - + Share with community - - + + Notes about this image - - + + Share diff --git a/interface/ui/shareSnapshot.ui b/interface/ui/shareSnapshot.ui index 3d729cf9df..85334cbc65 100644 --- a/interface/ui/shareSnapshot.ui +++ b/interface/ui/shareSnapshot.ui @@ -59,7 +59,7 @@ - + 0 0 @@ -70,6 +70,12 @@ 510 + + + 790 + 510 + + background-color: #000 @@ -95,7 +101,7 @@ 0 - + @@ -109,6 +115,12 @@ 510 + + + 790 + 510 + + background-color: #ccc; @@ -126,58 +138,6 @@ - - - - Qt::Vertical - - - - 0 - 0 - - - - - - - - Qt::Horizontal - - - - 0 - 0 - - - - - - - - Qt::Horizontal - - - - 0 - 0 - - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - From e5a66ddb90909210635a1a4596e10fafdcf1abd2 Mon Sep 17 00:00:00 2001 From: stojce Date: Tue, 25 Mar 2014 21:56:20 +0100 Subject: [PATCH 05/15] New layout behaviour --- interface/interface_en.ts | 21 ++ interface/src/ui/SnapshotShareDialog.cpp | 16 + interface/ui/shareSnapshot.ui | 374 +++++++++++------------ 3 files changed, 214 insertions(+), 197 deletions(-) diff --git a/interface/interface_en.ts b/interface/interface_en.ts index beada5df43..0a5b7e4057 100644 --- a/interface/interface_en.ts +++ b/interface/interface_en.ts @@ -158,4 +158,25 @@ + + SnapshotShareDialog + + + + Share with community + + + + + + Notes about this image + + + + + + Share + + + diff --git a/interface/src/ui/SnapshotShareDialog.cpp b/interface/src/ui/SnapshotShareDialog.cpp index 2af564ff0b..d57951a484 100644 --- a/interface/src/ui/SnapshotShareDialog.cpp +++ b/interface/src/ui/SnapshotShareDialog.cpp @@ -6,6 +6,9 @@ // // +const int NARROW_SNAPSHOT_DIALOG_SIZE = 500; +const int WIDE_SNAPSHOT_DIALOG_WIDTH = 650; + #include "SnapshotShareDialog.h" SnapshotShareDialog::SnapshotShareDialog(QString fileName, QWidget* parent) : QDialog(parent), _fileName(fileName) { @@ -16,11 +19,24 @@ SnapshotShareDialog::SnapshotShareDialog(QString fileName, QWidget* parent) : QD 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(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(ui.snapshotWidget->size().height() * snapshotRatio); } diff --git a/interface/ui/shareSnapshot.ui b/interface/ui/shareSnapshot.ui index 85334cbc65..cb8754a46d 100644 --- a/interface/ui/shareSnapshot.ui +++ b/interface/ui/shareSnapshot.ui @@ -9,26 +9,26 @@ 0 0 - 789 - 645 + 502 + 625 - + 0 0 - 789 - 645 + 500 + 625 - 789 - 645 + 502 + 625 @@ -43,189 +43,168 @@ true - - - - -1 - -1 - 792 - 645 - + + + 0 - - - 0 - - - - - - 0 - 0 - - - - - 790 - 510 - - - - - 790 - 510 - - - - background-color: #000 - - - QFrame::NoFrame - - - QFrame::Plain - - - 0 - - - - - -1 - 1 - 792 - 512 - + + 0 + + + 0 + + + 0 + + + 0 + + + + + QLayout::SetMinAndMaxSize + + + + + + 0 + 0 + + + + + 500 + 500 + + + + + 30 + 2000 + + + + background-color: #ccc; + + + 0 + + + true + + + Qt::AlignCenter + + + 0 - - - 0 - - - - - - 0 - 0 - - - - - 790 - 510 - - - - - 790 - 510 - - - - background-color: #ccc; - - - 0 - - - true - - - Qt::AlignCenter - - - 0 - - - - - - - - - - - 0 - 0 - - - - - 0 - 30 - - - - - Helvetica - 75 - true - - - - color: #666; - - - Notes about this image - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - 0 - - - 20 - - - - - - - 0 - - - 20 - - - 20 - - - - - - 0 - 0 - - - - - Helvetica - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - background-color: #333333; + + + + + + 0 + 0 + + + + + 0 + 30 + + + + + Helvetica + 75 + true + + + + color: #666; +padding-left:20px; + + + 0 + + + Notes about this image + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + 0 + + + 0 + + + + + + + 0 + + + QLayout::SetFixedSize + + + 20 + + + 20 + + + + + + 0 + 0 + + + + + 16777215 + 60 + + + + + Helvetica + 14 + + + + QFrame::Box + + + QFrame::Plain + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + background-color: #333333; border-width: 0; border-radius: 9px; border-radius: 9px; @@ -235,16 +214,17 @@ color: #FFFFFF; width: 120px; height: 50px; - - - Share - - - - - - - + + + Share + + + + + + + + From b223d10e700d40a53455196fc1b6cca4d87ca23d Mon Sep 17 00:00:00 2001 From: stojce Date: Wed, 26 Mar 2014 21:24:18 +0100 Subject: [PATCH 06/15] Layout fixes --- interface/interface_en.ts | 39 ++++++++----- interface/ui/shareSnapshot.ui | 106 ++++++++++++++++++++++++++++++---- 2 files changed, 120 insertions(+), 25 deletions(-) diff --git a/interface/interface_en.ts b/interface/interface_en.ts index 39e9142400..6baf4e7054 100644 --- a/interface/interface_en.ts +++ b/interface/interface_en.ts @@ -4,22 +4,22 @@ Application - + Export Voxels - + Sparse Voxel Octree Files (*.svo) - + Open Script - + JavaScript Files (*.js) @@ -113,18 +113,18 @@ Menu - + Open .ini config file - - + + Text files (*.ini) - + Save .ini config file @@ -162,19 +162,30 @@ SnapshotShareDialog - - Share with community + + Share with Alphas + Share with community - - + + Notes about this image - - + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Helvetica'; font-size:14pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + + + + + Share diff --git a/interface/ui/shareSnapshot.ui b/interface/ui/shareSnapshot.ui index cb8754a46d..988acfcd56 100644 --- a/interface/ui/shareSnapshot.ui +++ b/interface/ui/shareSnapshot.ui @@ -10,7 +10,7 @@ 0 0 502 - 625 + 616 @@ -22,20 +22,20 @@ 500 - 625 + 616 502 - 625 + 616 PointingHandCursor - Share with community + Share with Alphas background-color: rgb(255, 255, 255); @@ -61,6 +61,9 @@ + + 0 + QLayout::SetMinAndMaxSize @@ -101,10 +104,26 @@ + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 9 + + + + - + 0 0 @@ -112,12 +131,13 @@ 0 - 30 + 19 Helvetica + 14 75 true @@ -126,6 +146,9 @@ color: #666; padding-left:20px; + + QFrame::NoFrame + 0 @@ -152,11 +175,27 @@ padding-left:20px; QLayout::SetFixedSize - 20 + 0 - 20 + 0 + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 19 + 20 + + + + @@ -177,12 +216,25 @@ padding-left:20px; 14 + + border-color: #c00 + - QFrame::Box + QFrame::StyledPanel QFrame::Plain + + 1 + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Helvetica'; font-size:14pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> + @@ -195,8 +247,8 @@ padding-left:20px; - 20 - 20 + 25 + 19 @@ -220,8 +272,40 @@ padding-left:20px; + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 25 + 20 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 11 + + + + From 9f05d71796d47f0899ef2f81cbfbdea7fecc7ecd Mon Sep 17 00:00:00 2001 From: stojce Date: Wed, 26 Mar 2014 21:30:02 +0100 Subject: [PATCH 07/15] fixed QTextEdit border color --- interface/ui/shareSnapshot.ui | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/ui/shareSnapshot.ui b/interface/ui/shareSnapshot.ui index 988acfcd56..19857bfb28 100644 --- a/interface/ui/shareSnapshot.ui +++ b/interface/ui/shareSnapshot.ui @@ -217,16 +217,16 @@ padding-left:20px; - border-color: #c00 + border: 1px solid #c5c5c5; - QFrame::StyledPanel + QFrame::NoFrame QFrame::Plain - 1 + 0 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> From d90e15ad5801928bd788460f0ea5e4194ddb1407 Mon Sep 17 00:00:00 2001 From: stojce Date: Thu, 27 Mar 2014 17:56:42 +0100 Subject: [PATCH 08/15] Don't show share dialog for anonymous users --- interface/src/Application.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 42c8efb952..1e0976c021 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3715,6 +3715,11 @@ void Application::takeSnapshot() { QString fileName = Snapshot::saveSnapshot(_glWidget, _myAvatar); + AccountManager& accountManager = AccountManager::getInstance(); + if (!accountManager.isLoggedIn()) { + return; + } + if (!_snapshotShareDialog) { _snapshotShareDialog = new SnapshotShareDialog(fileName, _glWidget); } From d3fecd7a31b503c9bf820b1f3c03cb2ff5eb932b Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Fri, 2 May 2014 22:16:19 +0200 Subject: [PATCH 09/15] store discourse api key --- interface/src/ui/SnapshotShareDialog.cpp | 6 ++++++ interface/src/ui/SnapshotShareDialog.h | 3 +++ interface/ui/shareSnapshot.ui | 19 ++++++++++++++++++- .../networking/src/DataServerAccountInfo.cpp | 10 +++++++++- .../networking/src/DataServerAccountInfo.h | 6 +++++- 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/interface/src/ui/SnapshotShareDialog.cpp b/interface/src/ui/SnapshotShareDialog.cpp index d57951a484..081d3518b2 100644 --- a/interface/src/ui/SnapshotShareDialog.cpp +++ b/interface/src/ui/SnapshotShareDialog.cpp @@ -44,3 +44,9 @@ SnapshotShareDialog::SnapshotShareDialog(QString fileName, QWidget* parent) : QD ui.snapshotWidget->setPixmap(snaphsotPixmap); ui.snapshotWidget->adjustSize(); } + +void SnapshotShareDialog::accept() { + // post to Discourse forum + + close(); +} diff --git a/interface/src/ui/SnapshotShareDialog.h b/interface/src/ui/SnapshotShareDialog.h index 077acd182b..2823c8b78d 100644 --- a/interface/src/ui/SnapshotShareDialog.h +++ b/interface/src/ui/SnapshotShareDialog.h @@ -20,6 +20,9 @@ public: private: QString _fileName; Ui_SnapshotShareDialog ui; + +private slots: + void accept(); }; #endif /* defined(__hifi__snapshotShareDialog__) */ diff --git a/interface/ui/shareSnapshot.ui b/interface/ui/shareSnapshot.ui index 19857bfb28..0f59349442 100644 --- a/interface/ui/shareSnapshot.ui +++ b/interface/ui/shareSnapshot.ui @@ -311,5 +311,22 @@ p, li { white-space: pre-wrap; } - + + + shareButton + clicked() + SnapshotShareDialog + accept() + + + 420 + 565 + + + 250 + 307 + + + + diff --git a/libraries/networking/src/DataServerAccountInfo.cpp b/libraries/networking/src/DataServerAccountInfo.cpp index 87d3b694a7..d7cbd91e78 100644 --- a/libraries/networking/src/DataServerAccountInfo.cpp +++ b/libraries/networking/src/DataServerAccountInfo.cpp @@ -16,7 +16,8 @@ DataServerAccountInfo::DataServerAccountInfo() : _accessToken(), _username(), - _xmppPassword() + _xmppPassword(), + _discourseApiKey() { } @@ -29,6 +30,7 @@ DataServerAccountInfo::DataServerAccountInfo(const QJsonObject& jsonObject) : QJsonObject userJSONObject = jsonObject["user"].toObject(); setUsername(userJSONObject["username"].toString()); setXMPPPassword(userJSONObject["xmpp_password"].toString()); + setDiscourseApiKey(userJSONObject["discourse_api_key"].toString()); } DataServerAccountInfo::DataServerAccountInfo(const DataServerAccountInfo& otherInfo) { @@ -65,6 +67,12 @@ void DataServerAccountInfo::setXMPPPassword(const QString& xmppPassword) { } } +void DataServerAccountInfo::setDiscourseApiKey(const QString& discourseApiKey) { + if (_discourseApiKey != discourseApiKey) { + _discourseApiKey = discourseApiKey; + } +} + QDataStream& operator<<(QDataStream &out, const DataServerAccountInfo& info) { out << info._accessToken << info._username << info._xmppPassword; return out; diff --git a/libraries/networking/src/DataServerAccountInfo.h b/libraries/networking/src/DataServerAccountInfo.h index 21380c0855..a7d1fa9cb0 100644 --- a/libraries/networking/src/DataServerAccountInfo.h +++ b/libraries/networking/src/DataServerAccountInfo.h @@ -31,7 +31,10 @@ public: const QString& getXMPPPassword() const { return _xmppPassword; } void setXMPPPassword(const QString& xmppPassword); - + + const QString& getDiscourseApiKey() const { return _discourseApiKey; } + void setDiscourseApiKey(const QString& discourseApiKey); + friend QDataStream& operator<<(QDataStream &out, const DataServerAccountInfo& info); friend QDataStream& operator>>(QDataStream &in, DataServerAccountInfo& info); private: @@ -40,6 +43,7 @@ private: OAuthAccessToken _accessToken; QString _username; QString _xmppPassword; + QString _discourseApiKey; }; #endif // hifi_DataServerAccountInfo_h From c400630bc440e13171ea06397b0bc9660bf9761a Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Sat, 3 May 2014 21:12:20 +0200 Subject: [PATCH 10/15] 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) { From d93480458f0941281db882ee63db2f0b7fa461bd Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Sun, 4 May 2014 18:30:58 +0200 Subject: [PATCH 11/15] Posting Image to forum --- interface/src/Application.cpp | 2 +- interface/src/ui/SnapshotShareDialog.cpp | 125 ++++++++++++++++------- interface/src/ui/SnapshotShareDialog.h | 23 +++-- 3 files changed, 102 insertions(+), 48 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0d99f60f58..a6fd36a0d8 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3663,7 +3663,7 @@ void Application::takeSnapshot() { if (!_snapshotShareDialog) { _snapshotShareDialog = new SnapshotShareDialog(fileName, _glWidget); } - _snapshotShareDialog->exec(); + _snapshotShareDialog->show(); } void Application::urlGoTo(int argc, const char * constArgv[]) { diff --git a/interface/src/ui/SnapshotShareDialog.cpp b/interface/src/ui/SnapshotShareDialog.cpp index 921400ba1e..a5d598dc8b 100644 --- a/interface/src/ui/SnapshotShareDialog.cpp +++ b/interface/src/ui/SnapshotShareDialog.cpp @@ -1,28 +1,41 @@ // // SnapshotShareDialog.cpp -// hifi +// 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 // #include "SnapshotShareDialog.h" #include "AccountManager.h" -#include +#include #include -#include #include const int NARROW_SNAPSHOT_DIALOG_SIZE = 500; const int WIDE_SNAPSHOT_DIALOG_WIDTH = 650; -const QString FORUM_POST_URL = "http://localhost:4000"; -SnapshotShareDialog::SnapshotShareDialog(QString fileName, QWidget* parent) : QDialog(parent), _fileName(fileName) { +const QString FORUM_URL = "http://localhost:4000"; +const QString FORUM_UPLOADS_URL = FORUM_URL + "/uploads"; +const QString FORUM_POST_URL = FORUM_URL + "/posts"; +const QString FORUM_REPLY_TO_TOPIC = "64"; +const QString FORUM_POST_TEMPLATE = "

%2

"; + +Q_DECLARE_METATYPE(QNetworkAccessManager::Operation) + +SnapshotShareDialog::SnapshotShareDialog(QString fileName, QWidget* parent) : + QDialog(parent), + _fileName(fileName), + _networkAccessManager(NULL) +{ setAttribute(Qt::WA_DeleteOnClose); - ui.setupUi(this); + _ui.setupUi(this); QPixmap snaphsotPixmap(fileName); float snapshotRatio = static_cast(snaphsotPixmap.size().width()) / snaphsotPixmap.size().height(); @@ -30,70 +43,104 @@ SnapshotShareDialog::SnapshotShareDialog(QString fileName, QWidget* parent) : QD // narrow snapshot if (snapshotRatio > 1) { setFixedWidth(WIDE_SNAPSHOT_DIALOG_WIDTH); - ui.snapshotWidget->setFixedWidth(WIDE_SNAPSHOT_DIALOG_WIDTH); + _ui.snapshotWidget->setFixedWidth(WIDE_SNAPSHOT_DIALOG_WIDTH); } - float labelRatio = static_cast(ui.snapshotWidget->size().width()) / ui.snapshotWidget->size().height(); + 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(ui.snapshotWidget->size().width() / snapshotRatio); + 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())); + if (_ui.snapshotWidget->size().height() < NARROW_SNAPSHOT_DIALOG_SIZE) { + setFixedHeight(size().height() - (oldHeight - _ui.snapshotWidget->size().height())); } } else { - ui.snapshotWidget->setFixedWidth(ui.snapshotWidget->size().height() * snapshotRatio); + _ui.snapshotWidget->setFixedWidth((int) (_ui.snapshotWidget->size().height() * snapshotRatio)); } - ui.snapshotWidget->setPixmap(snaphsotPixmap); - ui.snapshotWidget->adjustSize(); + _ui.snapshotWidget->setPixmap(snaphsotPixmap); + _ui.snapshotWidget->adjustSize(); } void SnapshotShareDialog::accept() { - + uploadSnapshot(); + sendForumPost("/uploads/default/25/b607c8faea6de9c3.jpg"); close(); - - // post to Discourse forum -// AccountManager& accountManager = AccountManager::getInstance(); - QNetworkAccessManager* _networkAccessManager = NULL; +} + +void SnapshotShareDialog::uploadSnapshot() { if (!_networkAccessManager) { _networkAccessManager = new QNetworkAccessManager(this); } - QNetworkRequest request; + QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); - QUrl grantURL(FORUM_POST_URL); - grantURL.setPath("/posts"); + QHttpPart apiKeyPart; + apiKeyPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"api_key\"")); + apiKeyPart.setBody("9168f53930b2fc69ec278414d6ff04fed723ef717867a25954143150d3e2dfe8"); +// apiKeyPart.setBody(AccountManager::getInstance().getAccountInfo().getDiscourseApiKey().toLatin1()); + QFile *file = new QFile(_fileName); + file->open(QIODevice::ReadOnly); - 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())); + 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 - request.setUrl(grantURL); - request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + multiPart->append(apiKeyPart); + multiPart->append(imagePart); - QNetworkReply* requestReply = _networkAccessManager->post(request, postData); - connect(_networkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(serviceRequestFinished(QNetworkReply*))); + QUrl url(FORUM_UPLOADS_URL); + QNetworkRequest request(url); - connect(requestReply, &QNetworkReply::finished, this, &SnapshotShareDialog::requestFinished); - connect(requestReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(requestError(QNetworkReply::NetworkError))); + QNetworkReply *reply = _networkAccessManager->post(request, multiPart); + bool check; + Q_UNUSED(check); + + check = connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); + Q_ASSERT(check); } -void SnapshotShareDialog::serviceRequestFinished(QNetworkReply* reply) { - qDebug() << reply->errorString(); +void SnapshotShareDialog::sendForumPost(QString snapshotPath) { + + if (!_networkAccessManager) { + _networkAccessManager = new QNetworkAccessManager(this); + } + + // post to Discourse forum + QNetworkRequest request; + QUrl forumUrl(FORUM_POST_URL); + + QUrlQuery query; +// query.addQueryItem("api_key", accountManager.getAccountInfo().getDiscourseApiKey(); + query.addQueryItem("api_key", "9168f53930b2fc69ec278414d6ff04fed723ef717867a25954143150d3e2dfe8"); + 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); + QNetworkReply* requestReply = _networkAccessManager->post(request, postData); + + bool check; + Q_UNUSED(check); + + check = connect(requestReply, &QNetworkReply::finished, this, &SnapshotShareDialog::requestFinished); + Q_ASSERT(check); + + check = connect(requestReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(requestError(QNetworkReply::NetworkError))); + Q_ASSERT(check); } void SnapshotShareDialog::requestFinished() { - QNetworkReply* requestReply = reinterpret_cast(sender()); - qDebug() << requestReply->errorString(); delete requestReply; } @@ -101,4 +148,4 @@ void SnapshotShareDialog::requestFinished() { 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 18a66616db..ea973022f3 100644 --- a/interface/src/ui/SnapshotShareDialog.h +++ b/interface/src/ui/SnapshotShareDialog.h @@ -1,16 +1,22 @@ // // SnapshotShareDialog.h -// hifi +// 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__ +#ifndef hifi_snapshotShareDialog +#define hifi_snapshotShareDialog #include "ui_shareSnapshot.h" + +#include #include +#include class SnapshotShareDialog : public QDialog { Q_OBJECT @@ -20,15 +26,16 @@ public: private: QString _fileName; - Ui_SnapshotShareDialog ui; + QNetworkAccessManager* _networkAccessManager; + Ui_SnapshotShareDialog _ui; + + void uploadSnapshot(); + void sendForumPost(QString snapshotPath); public slots: void requestFinished(); void requestError(QNetworkReply::NetworkError error); - void serviceRequestFinished(QNetworkReply* reply); - -private slots: void accept(); }; -#endif /* defined(__hifi__snapshotShareDialog__) */ +#endif // hifi_snapshotShareDialog From f668cc85812c33fb179be2dae88902c7eb2cfc8b Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Mon, 5 May 2014 00:55:24 +0200 Subject: [PATCH 12/15] Discourse upload image - success message set - fixed signal/slots in QDialog w/QEventLoop - layout fixes --- interface/src/ui/SnapshotShareDialog.cpp | 100 +++++++++++++++++------ interface/src/ui/SnapshotShareDialog.h | 6 +- interface/ui/shareSnapshot.ui | 53 +++++++++++- 3 files changed, 125 insertions(+), 34 deletions(-) diff --git a/interface/src/ui/SnapshotShareDialog.cpp b/interface/src/ui/SnapshotShareDialog.cpp index a5d598dc8b..fc738c9761 100644 --- a/interface/src/ui/SnapshotShareDialog.cpp +++ b/interface/src/ui/SnapshotShareDialog.cpp @@ -13,17 +13,24 @@ #include "AccountManager.h" #include +#include +#include #include +#include #include + const int NARROW_SNAPSHOT_DIALOG_SIZE = 500; const int WIDE_SNAPSHOT_DIALOG_WIDTH = 650; +const int SUCCESS_LABEL_HEIGHT = 140; -const QString FORUM_URL = "http://localhost:4000"; +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 = "64"; +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"; Q_DECLARE_METATYPE(QNetworkAccessManager::Operation) @@ -67,12 +74,15 @@ SnapshotShareDialog::SnapshotShareDialog(QString fileName, QWidget* parent) : void SnapshotShareDialog::accept() { uploadSnapshot(); - sendForumPost("/uploads/default/25/b607c8faea6de9c3.jpg"); - close(); } void SnapshotShareDialog::uploadSnapshot() { + if (AccountManager::getInstance().getAccountInfo().getDiscourseApiKey().isEmpty()) { + QMessageBox::warning(this, "", "Your Discourse API key is missing, you cannot share snapshots."); + return; + } + if (!_networkAccessManager) { _networkAccessManager = new QNetworkAccessManager(this); } @@ -81,8 +91,7 @@ void SnapshotShareDialog::uploadSnapshot() { QHttpPart apiKeyPart; apiKeyPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"api_key\"")); - apiKeyPart.setBody("9168f53930b2fc69ec278414d6ff04fed723ef717867a25954143150d3e2dfe8"); -// apiKeyPart.setBody(AccountManager::getInstance().getAccountInfo().getDiscourseApiKey().toLatin1()); + apiKeyPart.setBody(AccountManager::getInstance().getAccountInfo().getDiscourseApiKey().toLatin1()); QFile *file = new QFile(_fileName); file->open(QIODevice::ReadOnly); @@ -101,11 +110,13 @@ void SnapshotShareDialog::uploadSnapshot() { QNetworkRequest request(url); QNetworkReply *reply = _networkAccessManager->post(request, multiPart); - bool check; - Q_UNUSED(check); - check = connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); - Q_ASSERT(check); + + connect(reply, &QNetworkReply::finished, this, &SnapshotShareDialog::uploadRequestFinished); + + QEventLoop loop; + connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); + loop.exec(); } void SnapshotShareDialog::sendForumPost(QString snapshotPath) { @@ -119,33 +130,68 @@ void SnapshotShareDialog::sendForumPost(QString snapshotPath) { QUrl forumUrl(FORUM_POST_URL); QUrlQuery query; -// query.addQueryItem("api_key", accountManager.getAccountInfo().getDiscourseApiKey(); - query.addQueryItem("api_key", "9168f53930b2fc69ec278414d6ff04fed723ef717867a25954143150d3e2dfe8"); + 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->post(request, postData); + connect(requestReply, &QNetworkReply::finished, this, &SnapshotShareDialog::postRequestFinished); - bool check; - Q_UNUSED(check); - - check = connect(requestReply, &QNetworkReply::finished, this, &SnapshotShareDialog::requestFinished); - Q_ASSERT(check); - - check = connect(requestReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(requestError(QNetworkReply::NetworkError))); - Q_ASSERT(check); + QEventLoop loop; + connect(requestReply, &QNetworkReply::finished, &loop, &QEventLoop::quit); + loop.exec(); } -void SnapshotShareDialog::requestFinished() { +void SnapshotShareDialog::postRequestFinished() { + QNetworkReply* requestReply = reinterpret_cast(sender()); - qDebug() << requestReply->errorString(); + QJsonDocument jsonResponse = QJsonDocument::fromJson(requestReply->readAll()); + 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(); + } + } + QMessageBox::warning(this, "", SHARE_DEFAULT_ERROR); + } +} + +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 { + QMessageBox::warning(this, "", SHARE_DEFAULT_ERROR); + } + delete requestReply; } - -void SnapshotShareDialog::requestError(QNetworkReply::NetworkError error) { - // TODO: error handling - qDebug() << "AccountManager requestError - " << error; -} diff --git a/interface/src/ui/SnapshotShareDialog.h b/interface/src/ui/SnapshotShareDialog.h index ea973022f3..bc92e63e4c 100644 --- a/interface/src/ui/SnapshotShareDialog.h +++ b/interface/src/ui/SnapshotShareDialog.h @@ -32,9 +32,9 @@ private: void uploadSnapshot(); void sendForumPost(QString snapshotPath); -public slots: - void requestFinished(); - void requestError(QNetworkReply::NetworkError error); +private slots: + void uploadRequestFinished(); + void postRequestFinished(); void accept(); }; diff --git a/interface/ui/shareSnapshot.ui b/interface/ui/shareSnapshot.ui index 0f59349442..df7fc4939f 100644 --- a/interface/ui/shareSnapshot.ui +++ b/interface/ui/shareSnapshot.ui @@ -31,9 +31,6 @@ 616 - - PointingHandCursor - Share with Alphas @@ -121,7 +118,55 @@ - + + + true + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 0 + + + + + Arial + + + + color: #666 + + + + + + Qt::RichText + + + Qt::AlignCenter + + + true + + + Qt::TextBrowserInteraction + + + + + 0 From 96a9a478712a2052414b6476970dd2f3a0db93e2 Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Thu, 8 May 2014 20:54:28 +0200 Subject: [PATCH 13/15] minor code fixes --- interface/src/ui/SnapshotShareDialog.cpp | 10 +++++----- interface/src/ui/SnapshotShareDialog.h | 4 ++-- snapshotShareDialog.cpp | 9 --------- snapshotShareDialog.h | 14 -------------- 4 files changed, 7 insertions(+), 30 deletions(-) delete mode 100644 snapshotShareDialog.cpp delete mode 100644 snapshotShareDialog.h diff --git a/interface/src/ui/SnapshotShareDialog.cpp b/interface/src/ui/SnapshotShareDialog.cpp index fc738c9761..5ba284618f 100644 --- a/interface/src/ui/SnapshotShareDialog.cpp +++ b/interface/src/ui/SnapshotShareDialog.cpp @@ -13,11 +13,11 @@ #include "AccountManager.h" #include -#include -#include -#include -#include #include +#include +#include +#include +#include const int NARROW_SNAPSHOT_DIALOG_SIZE = 500; @@ -177,7 +177,7 @@ void SnapshotShareDialog::postRequestFinished() { errorMessage = errorArray.first().toString(); } } - QMessageBox::warning(this, "", SHARE_DEFAULT_ERROR); + QMessageBox::warning(this, "", errorMessage); } } diff --git a/interface/src/ui/SnapshotShareDialog.h b/interface/src/ui/SnapshotShareDialog.h index bc92e63e4c..a8795d578a 100644 --- a/interface/src/ui/SnapshotShareDialog.h +++ b/interface/src/ui/SnapshotShareDialog.h @@ -14,9 +14,9 @@ #include "ui_shareSnapshot.h" -#include -#include #include +#include +#include class SnapshotShareDialog : public QDialog { Q_OBJECT diff --git a/snapshotShareDialog.cpp b/snapshotShareDialog.cpp deleted file mode 100644 index 53a445292f..0000000000 --- a/snapshotShareDialog.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// snapshotShareDialog.cpp -// hifi -// -// Created by Stojce Slavkovski on 2/16/14. -// -// - -#include "snapshotShareDialog.h" diff --git a/snapshotShareDialog.h b/snapshotShareDialog.h deleted file mode 100644 index 77e92216fd..0000000000 --- a/snapshotShareDialog.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// snapshotShareDialog.h -// hifi -// -// Created by Stojce Slavkovski on 2/16/14. -// -// - -#ifndef __hifi__snapshotShareDialog__ -#define __hifi__snapshotShareDialog__ - -#include - -#endif /* defined(__hifi__snapshotShareDialog__) */ From 3b7e0814fe2d2572102e03e9447d29539840ae77 Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Sun, 11 May 2014 09:57:43 +0200 Subject: [PATCH 14/15] CR fixes --- interface/src/XmppClient.cpp | 2 +- interface/src/ui/SnapshotShareDialog.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/XmppClient.cpp b/interface/src/XmppClient.cpp index 666906681c..2d421b1afa 100644 --- a/interface/src/XmppClient.cpp +++ b/interface/src/XmppClient.cpp @@ -16,7 +16,7 @@ #include "XmppClient.h" const QString DEFAULT_XMPP_SERVER = "chat.highfidelity.io"; -const QString DEFAULT_CHAT_ROOM = "public@public-chat.highfidelity.io"; +const QString DEFAULT_CHAT_ROOM = "test@public-chat.highfidelity.io"; XmppClient::XmppClient() : _xmppClient(), diff --git a/interface/src/ui/SnapshotShareDialog.cpp b/interface/src/ui/SnapshotShareDialog.cpp index 5ba284618f..2ac1c81f52 100644 --- a/interface/src/ui/SnapshotShareDialog.cpp +++ b/interface/src/ui/SnapshotShareDialog.cpp @@ -87,13 +87,13 @@ void SnapshotShareDialog::uploadSnapshot() { _networkAccessManager = new QNetworkAccessManager(this); } - QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); + 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); + QFile* file = new QFile(_fileName); file->open(QIODevice::ReadOnly); QHttpPart imagePart; @@ -109,7 +109,7 @@ void SnapshotShareDialog::uploadSnapshot() { QUrl url(FORUM_UPLOADS_URL); QNetworkRequest request(url); - QNetworkReply *reply = _networkAccessManager->post(request, multiPart); + QNetworkReply* reply = _networkAccessManager->post(request, multiPart); connect(reply, &QNetworkReply::finished, this, &SnapshotShareDialog::uploadRequestFinished); From 070d9960961766c201b4b34c9c1b5082e8eab2ef Mon Sep 17 00:00:00 2001 From: Stojce Slavkovski Date: Mon, 12 May 2014 19:47:41 +0200 Subject: [PATCH 15/15] change `key missing` message --- interface/src/ui/SnapshotShareDialog.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/ui/SnapshotShareDialog.cpp b/interface/src/ui/SnapshotShareDialog.cpp index 2ac1c81f52..b5694b3e48 100644 --- a/interface/src/ui/SnapshotShareDialog.cpp +++ b/interface/src/ui/SnapshotShareDialog.cpp @@ -79,7 +79,8 @@ void SnapshotShareDialog::accept() { void SnapshotShareDialog::uploadSnapshot() { if (AccountManager::getInstance().getAccountInfo().getDiscourseApiKey().isEmpty()) { - QMessageBox::warning(this, "", "Your Discourse API key is missing, you cannot share snapshots."); + QMessageBox::warning(this, "", + "Your Discourse API key is missing, you cannot share snapshots. Please try to relog."); return; }