mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 18:25:52 +02:00
Merge pull request #6058 from Atlante45/asset-drop
All file types eligible for upload to asset server
This commit is contained in:
commit
ae32b0dc98
3 changed files with 66 additions and 69 deletions
|
@ -126,6 +126,7 @@
|
||||||
#include "Stars.h"
|
#include "Stars.h"
|
||||||
#include "ui/AddressBarDialog.h"
|
#include "ui/AddressBarDialog.h"
|
||||||
#include "ui/AvatarInputs.h"
|
#include "ui/AvatarInputs.h"
|
||||||
|
#include "ui/AssetUploadDialogFactory.h"
|
||||||
#include "ui/DataWebDialog.h"
|
#include "ui/DataWebDialog.h"
|
||||||
#include "ui/DialogsManager.h"
|
#include "ui/DialogsManager.h"
|
||||||
#include "ui/LoginDialog.h"
|
#include "ui/LoginDialog.h"
|
||||||
|
@ -159,6 +160,7 @@ static const QString SVO_JSON_EXTENSION = ".svo.json";
|
||||||
static const QString JS_EXTENSION = ".js";
|
static const QString JS_EXTENSION = ".js";
|
||||||
static const QString FST_EXTENSION = ".fst";
|
static const QString FST_EXTENSION = ".fst";
|
||||||
static const QString FBX_EXTENSION = ".fbx";
|
static const QString FBX_EXTENSION = ".fbx";
|
||||||
|
static const QString OBJ_EXTENSION = ".obj";
|
||||||
|
|
||||||
static const int MIRROR_VIEW_TOP_PADDING = 5;
|
static const int MIRROR_VIEW_TOP_PADDING = 5;
|
||||||
static const int MIRROR_VIEW_LEFT_PADDING = 10;
|
static const int MIRROR_VIEW_LEFT_PADDING = 10;
|
||||||
|
@ -179,9 +181,6 @@ static const unsigned int THROTTLED_SIM_FRAMERATE = 15;
|
||||||
static const int TARGET_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / TARGET_SIM_FRAMERATE;
|
static const int TARGET_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / TARGET_SIM_FRAMERATE;
|
||||||
static const int THROTTLED_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / THROTTLED_SIM_FRAMERATE;
|
static const int THROTTLED_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / THROTTLED_SIM_FRAMERATE;
|
||||||
|
|
||||||
const QString CHECK_VERSION_URL = "https://highfidelity.com/latestVersion.xml";
|
|
||||||
const QString SKIP_FILENAME = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/hifi.skipversion";
|
|
||||||
|
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||||
#else
|
#else
|
||||||
|
@ -197,8 +196,7 @@ const QHash<QString, Application::AcceptURLMethod> Application::_acceptedExtensi
|
||||||
{ SVO_EXTENSION, &Application::importSVOFromURL },
|
{ SVO_EXTENSION, &Application::importSVOFromURL },
|
||||||
{ SVO_JSON_EXTENSION, &Application::importSVOFromURL },
|
{ SVO_JSON_EXTENSION, &Application::importSVOFromURL },
|
||||||
{ JS_EXTENSION, &Application::askToLoadScript },
|
{ JS_EXTENSION, &Application::askToLoadScript },
|
||||||
{ FST_EXTENSION, &Application::askToSetAvatarUrl },
|
{ FST_EXTENSION, &Application::askToSetAvatarUrl }
|
||||||
{ FBX_EXTENSION, &Application::askToUploadAsset }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
@ -2023,21 +2021,14 @@ void Application::dropEvent(QDropEvent *event) {
|
||||||
const QMimeData* mimeData = event->mimeData();
|
const QMimeData* mimeData = event->mimeData();
|
||||||
for (auto& url : mimeData->urls()) {
|
for (auto& url : mimeData->urls()) {
|
||||||
QString urlString = url.toString();
|
QString urlString = url.toString();
|
||||||
if (canAcceptURL(urlString) && acceptURL(urlString)) {
|
if (acceptURL(urlString, true)) {
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::dragEnterEvent(QDragEnterEvent* event) {
|
void Application::dragEnterEvent(QDragEnterEvent* event) {
|
||||||
const QMimeData* mimeData = event->mimeData();
|
event->acceptProposedAction();
|
||||||
for (auto& url : mimeData->urls()) {
|
|
||||||
auto urlString = url.toString();
|
|
||||||
if (canAcceptURL(urlString)) {
|
|
||||||
event->acceptProposedAction();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::acceptSnapshot(const QString& urlString) {
|
bool Application::acceptSnapshot(const QString& urlString) {
|
||||||
|
@ -3973,26 +3964,26 @@ bool Application::canAcceptURL(const QString& urlString) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::acceptURL(const QString& urlString) {
|
bool Application::acceptURL(const QString& urlString, bool defaultUpload) {
|
||||||
if (urlString.startsWith(HIFI_URL_SCHEME)) {
|
if (urlString.startsWith(HIFI_URL_SCHEME)) {
|
||||||
// this is a hifi URL - have the AddressManager handle it
|
// this is a hifi URL - have the AddressManager handle it
|
||||||
QMetaObject::invokeMethod(DependencyManager::get<AddressManager>().data(), "handleLookupString",
|
QMetaObject::invokeMethod(DependencyManager::get<AddressManager>().data(), "handleLookupString",
|
||||||
Qt::AutoConnection, Q_ARG(const QString&, urlString));
|
Qt::AutoConnection, Q_ARG(const QString&, urlString));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
QUrl url(urlString);
|
|
||||||
QHashIterator<QString, AcceptURLMethod> i(_acceptedExtensions);
|
QUrl url(urlString);
|
||||||
QString lowerPath = url.path().toLower();
|
QHashIterator<QString, AcceptURLMethod> i(_acceptedExtensions);
|
||||||
while (i.hasNext()) {
|
QString lowerPath = url.path().toLower();
|
||||||
i.next();
|
while (i.hasNext()) {
|
||||||
if (lowerPath.endsWith(i.key())) {
|
i.next();
|
||||||
AcceptURLMethod method = i.value();
|
if (lowerPath.endsWith(i.key())) {
|
||||||
(this->*method)(urlString);
|
AcceptURLMethod method = i.value();
|
||||||
return true;
|
return (this->*method)(urlString);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
return defaultUpload && askToUploadAsset(urlString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::setSessionUUID(const QUuid& sessionUUID) {
|
void Application::setSessionUUID(const QUuid& sessionUUID) {
|
||||||
|
@ -4076,8 +4067,36 @@ bool Application::askToUploadAsset(const QString& filename) {
|
||||||
|
|
||||||
QUrl url { filename };
|
QUrl url { filename };
|
||||||
if (auto upload = DependencyManager::get<AssetClient>()->createUpload(url.toLocalFile())) {
|
if (auto upload = DependencyManager::get<AssetClient>()->createUpload(url.toLocalFile())) {
|
||||||
|
|
||||||
|
QMessageBox messageBox;
|
||||||
|
messageBox.setWindowTitle("Asset upload");
|
||||||
|
messageBox.setText("You are about to upload the following file to the asset server:\n" +
|
||||||
|
url.toDisplayString());
|
||||||
|
messageBox.setInformativeText("Do you want to continue?");
|
||||||
|
messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
||||||
|
messageBox.setDefaultButton(QMessageBox::Ok);
|
||||||
|
|
||||||
|
// Option to drop model in world for models
|
||||||
|
if (filename.endsWith(FBX_EXTENSION) || filename.endsWith(OBJ_EXTENSION)) {
|
||||||
|
auto checkBox = new QCheckBox(&messageBox);
|
||||||
|
checkBox->setText("Drop model in world.");
|
||||||
|
messageBox.setCheckBox(checkBox);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (messageBox.exec() != QMessageBox::Ok) {
|
||||||
|
upload->deleteLater();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// connect to the finished signal so we know when the AssetUpload is done
|
// connect to the finished signal so we know when the AssetUpload is done
|
||||||
QObject::connect(upload, &AssetUpload::finished, this, &Application::assetUploadFinished);
|
if (messageBox.checkBox() && (messageBox.checkBox()->checkState() == Qt::Checked)) {
|
||||||
|
// Custom behavior for models
|
||||||
|
QObject::connect(upload, &AssetUpload::finished, this, &Application::modelUploadFinished);
|
||||||
|
} else {
|
||||||
|
QObject::connect(upload, &AssetUpload::finished,
|
||||||
|
&AssetUploadDialogFactory::getInstance(),
|
||||||
|
&AssetUploadDialogFactory::handleUploadFinished);
|
||||||
|
}
|
||||||
|
|
||||||
// start the upload now
|
// start the upload now
|
||||||
upload->start();
|
upload->start();
|
||||||
|
@ -4089,47 +4108,26 @@ bool Application::askToUploadAsset(const QString& filename) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::assetUploadFinished(AssetUpload* upload, const QString& hash) {
|
void Application::modelUploadFinished(AssetUpload* upload, const QString& hash) {
|
||||||
if (upload->getError() != AssetUpload::NoError) {
|
auto filename = QFileInfo(upload->getFilename()).fileName();
|
||||||
// figure out the right error message for the message box
|
|
||||||
QString additionalError;
|
if ((upload->getError() == AssetUpload::NoError) &&
|
||||||
|
(filename.endsWith(FBX_EXTENSION) || filename.endsWith(OBJ_EXTENSION))) {
|
||||||
|
|
||||||
switch (upload->getError()) {
|
auto entities = DependencyManager::get<EntityScriptingInterface>();
|
||||||
case AssetUpload::PermissionDenied:
|
|
||||||
additionalError = "You do not have permission to upload content to this asset-server.";
|
|
||||||
break;
|
|
||||||
case AssetUpload::TooLarge:
|
|
||||||
additionalError = "The uploaded content was too large and could not be stored in the asset-server.";
|
|
||||||
break;
|
|
||||||
case AssetUpload::FileOpenError:
|
|
||||||
additionalError = "The file could not be opened. Please check your permissions and try again.";
|
|
||||||
break;
|
|
||||||
case AssetUpload::NetworkError:
|
|
||||||
additionalError = "The file could not be opened. Please check your network connectivity.";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// not handled, do not show a message box
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// display a message box with the error
|
EntityItemProperties properties;
|
||||||
auto filename = QFileInfo(upload->getFilename()).fileName();
|
properties.setType(EntityTypes::Model);
|
||||||
QString errorMessage = QString("Failed to upload %1.\n\n%2").arg(filename, additionalError);
|
properties.setModelURL(QString("%1:%2.%3").arg(ATP_SCHEME).arg(hash).arg(upload->getExtension()));
|
||||||
QMessageBox::warning(_window, "Failed Upload", errorMessage);
|
properties.setPosition(_myCamera.getPosition() + _myCamera.getOrientation() * Vectors::FRONT * 2.0f);
|
||||||
|
properties.setName(QUrl(upload->getFilename()).fileName());
|
||||||
|
|
||||||
|
entities->addEntity(properties);
|
||||||
|
|
||||||
|
upload->deleteLater();
|
||||||
|
} else {
|
||||||
|
AssetUploadDialogFactory::getInstance().handleUploadFinished(upload, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto entities = DependencyManager::get<EntityScriptingInterface>();
|
|
||||||
auto myAvatar = getMyAvatar();
|
|
||||||
|
|
||||||
EntityItemProperties properties;
|
|
||||||
properties.setType(EntityTypes::Model);
|
|
||||||
properties.setModelURL(QString("%1:%2.%3").arg(ATP_SCHEME).arg(hash).arg(upload->getExtension()));
|
|
||||||
properties.setPosition(myAvatar->getPosition() + myAvatar->getOrientation() * Vectors::FRONT * 2.0f);
|
|
||||||
properties.setName(QUrl(upload->getFilename()).fileName());
|
|
||||||
|
|
||||||
entities->addEntity(properties);
|
|
||||||
|
|
||||||
upload->deleteLater();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUserLoaded,
|
ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUserLoaded,
|
||||||
|
|
|
@ -211,7 +211,7 @@ public:
|
||||||
void setScriptsLocation(const QString& scriptsLocation);
|
void setScriptsLocation(const QString& scriptsLocation);
|
||||||
|
|
||||||
bool canAcceptURL(const QString& url);
|
bool canAcceptURL(const QString& url);
|
||||||
bool acceptURL(const QString& url);
|
bool acceptURL(const QString& url, bool defaultUpload = false);
|
||||||
|
|
||||||
void setMaxOctreePacketsPerSecond(int maxOctreePPS);
|
void setMaxOctreePacketsPerSecond(int maxOctreePPS);
|
||||||
int getMaxOctreePacketsPerSecond();
|
int getMaxOctreePacketsPerSecond();
|
||||||
|
@ -329,7 +329,7 @@ private slots:
|
||||||
bool askToSetAvatarUrl(const QString& url);
|
bool askToSetAvatarUrl(const QString& url);
|
||||||
bool askToLoadScript(const QString& scriptFilenameOrURL);
|
bool askToLoadScript(const QString& scriptFilenameOrURL);
|
||||||
bool askToUploadAsset(const QString& asset);
|
bool askToUploadAsset(const QString& asset);
|
||||||
void assetUploadFinished(AssetUpload* upload, const QString& hash);
|
void modelUploadFinished(AssetUpload* upload, const QString& hash);
|
||||||
|
|
||||||
void setSessionUUID(const QUuid& sessionUUID);
|
void setSessionUUID(const QUuid& sessionUUID);
|
||||||
void domainChanged(const QString& domainHostname);
|
void domainChanged(const QString& domainHostname);
|
||||||
|
|
|
@ -30,7 +30,6 @@ public:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void showDialog();
|
void showDialog();
|
||||||
private slots:
|
|
||||||
void handleUploadFinished(AssetUpload* upload, const QString& hash);
|
void handleUploadFinished(AssetUpload* upload, const QString& hash);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue