diff --git a/interface/resources/qml/AssetServer.qml b/interface/resources/qml/AssetServer.qml index 34f6502b40..fdb9b81d87 100644 --- a/interface/resources/qml/AssetServer.qml +++ b/interface/resources/qml/AssetServer.qml @@ -35,6 +35,7 @@ Window { property var scripts: ScriptDiscoveryService; property var scriptsModel: scripts.scriptsModelFilter property var currentDirectory; + property alias currentFileUrl: fileUrlTextField.text; Settings { category: "Overlay.AssetServer" @@ -43,10 +44,58 @@ Window { property alias directory: root.currentDirectory } + function doDeleteFile(path) { + console.log("Deleting " + path); + + } + function doUploadFile(path, mapping, addToWorld) { + console.log("Uploading " + path + " to " + mapping + " (addToWorld: " + addToWorld + ")"); + + + } + function doRenameFile(oldPath, newPath) { + console.log("Renaming " + oldPath + " to " + newPath); + + } + + function fileExists(destinationPath) { + return true; // TODO get correct value + } + + function askForOverride(path, callback) { + var object = desktop.messageBox({ + icon: OriginalDialogs.StandardIcon.Question, + buttons: OriginalDialogs.StandardButton.Yes | OriginalDialogs.StandardButton.No, + defaultButton: OriginalDialogs.StandardButton.No, + text: "Override?", + informativeText: "The following file already exists:\n" + path + + "\nDo you want to override it?" + }); + object.selected.connect(function(button) { + if (button === OriginalDialogs.StandardButton.Yes) { + callback(); + } + }); + } + + function canAddToWorld() { + var supportedExtensions = [/\.fbx\b/i, /\.obj\b/i]; + var path = scriptsModel.data(treeView.currentIndex, 0x100); + + return supportedExtensions.reduce(function(total, current) { + return total | new RegExp(current).test(path); + }, false); + } + function reload() { print("reload"); } function addToWorld() { + var path = scriptsModel.data(treeView.currentIndex, 0x100); + if (!path) { + return; + } + print("addToWorld"); } function renameFile() { @@ -61,12 +110,13 @@ Window { placeholderText: "Enter path here" }); object.selected.connect(function(destinationPath) { - console.log("Renaming " + path + " to " + destinationPath); - - - - - + if (fileExists(destinationPath)) { + askForOverride(path, function() { + doRenameFile(path, destinationPath); + }); + } else { + doRenameFile(path, destinationPath); + } }); } function deleteFile() { @@ -86,10 +136,7 @@ Window { }); object.selected.connect(function(button) { if (button === OriginalDialogs.StandardButton.Yes) { - console.log("Deleting " + path); - - - + doDeleteFile(path); } }); } @@ -119,12 +166,13 @@ Window { placeholderText: "Enter path here" }); object.selected.connect(function(destinationPath) { - console.log("Uploading " + fileUrl + " to " + destinationPath + " (addToWorld: " + addToWorld + ")"); - - - - - + if (fileExists(destinationPath)) { + askForOverride(fileUrl, function() { + doUploadFile(fileUrl, destinationPath, addToWorld); + }); + } else { + doUploadFile(fileUrl, destinationPath, addToWorld); + } }); } @@ -160,6 +208,8 @@ Window { height: 26 width: 120 + enabled: canAddToWorld() + onClicked: root.addToWorld() } diff --git a/interface/resources/qml/hifi/MenuOption.qml b/interface/resources/qml/hifi/MenuOption.qml index 477197f57e..da28d1daf3 100644 --- a/interface/resources/qml/hifi/MenuOption.qml +++ b/interface/resources/qml/hifi/MenuOption.qml @@ -155,7 +155,6 @@ QtObject { readonly property string toolWindow: "Tool Window"; readonly property string transmitterDrive: "Transmitter Drive"; readonly property string turnWithHead: "Turn using Head"; - readonly property string uploadAsset: "Upload File to Asset Server"; readonly property string useAudioForMouth: "Use Audio for Mouth"; readonly property string useCamera: "Use Camera"; readonly property string velocityFilter: "Velocity Filter"; diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 464e77ef6f..40670d42d7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -158,7 +158,6 @@ #include "Stars.h" #include "ui/AddressBarDialog.h" #include "ui/AvatarInputs.h" -#include "ui/AssetUploadDialogFactory.h" #include "ui/DialogsManager.h" #include "ui/LoginDialog.h" #include "ui/overlays/Cube3DOverlay.h" @@ -3978,9 +3977,6 @@ void Application::nodeAdded(SharedNodePointer node) { if (node->getType() == NodeType::AvatarMixer) { // new avatar mixer, send off our identity packet right away getMyAvatar()->sendIdentityPacket(); - } else if (node->getType() == NodeType::AssetServer) { - // the addition of an asset-server always re-enables the upload to asset server menu option - Menu::getInstance()->getActionForOption(MenuOption::UploadAsset)->setEnabled(true); } } @@ -4030,10 +4026,6 @@ void Application::nodeKilled(SharedNodePointer node) { } else if (node->getType() == NodeType::AvatarMixer) { // our avatar mixer has gone away - clear the hash of avatars DependencyManager::get()->clearOtherAvatars(); - } else if (node->getType() == NodeType::AssetServer - && !DependencyManager::get()->soloNodeOfType(NodeType::AssetServer)) { - // this was our last asset server - disable the menu option to upload an asset - Menu::getInstance()->getActionForOption(MenuOption::UploadAsset)->setEnabled(false); } } void Application::trackIncomingOctreePacket(ReceivedMessage& message, SharedNodePointer sendingNode, bool wasStatsPacket) { @@ -4259,7 +4251,10 @@ bool Application::acceptURL(const QString& urlString, bool defaultUpload) { } } - return defaultUpload && askToUploadAsset(urlString); + if (defaultUpload) { + toggleAssetServerWidget(urlString); + } + return defaultUpload; } void Application::setSessionUUID(const QUuid& sessionUUID) { @@ -4321,80 +4316,6 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) { return true; } -bool Application::askToUploadAsset(const QString& filename) { - if (!DependencyManager::get()->getThisNodeCanRez()) { - OffscreenUi::warning(_window, "Failed Upload", - QString("You don't have upload rights on that domain.\n\n")); - return false; - } - - QUrl url { filename }; - if (auto upload = DependencyManager::get()->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, Qt::CaseInsensitive) || filename.endsWith(OBJ_EXTENSION, Qt::CaseInsensitive)) { - auto checkBox = new QCheckBox(&messageBox); - checkBox->setText("Add to scene"); - 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 - 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 - upload->start(); - return true; - } - - // display a message box with the error - OffscreenUi::warning(_window, "Failed Upload", QString("Failed to upload %1.\n\n").arg(filename)); - return false; -} - -void Application::modelUploadFinished(AssetUpload* upload, const QString& hash) { - auto fileInfo = QFileInfo(upload->getFilename()); - auto filename = fileInfo.fileName(); - - if ((upload->getError() == AssetUpload::NoError) && - (filename.endsWith(FBX_EXTENSION, Qt::CaseInsensitive) || - filename.endsWith(OBJ_EXTENSION, Qt::CaseInsensitive))) { - - auto entities = DependencyManager::get(); - - EntityItemProperties properties; - properties.setType(EntityTypes::Model); - properties.setModelURL(QString("%1:%2.%3").arg(URL_SCHEME_ATP).arg(hash).arg(fileInfo.completeSuffix())); - 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); - } -} - bool Application::askToWearAvatarAttachmentUrl(const QString& url) { QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); @@ -4494,9 +4415,12 @@ void Application::toggleRunningScriptsWidget() { //} } -void Application::toggleAssetServerWidget() { +void Application::toggleAssetServerWidget(QString filePath) { static const QUrl url("AssetServer.qml"); - DependencyManager::get()->show(url, "AssetServer"); + auto urlSetter = [=](QQmlContext* context, QObject* newObject){ + newObject->setProperty("currentFileUrl", filePath); + }; + DependencyManager::get()->show(url, "AssetServer", urlSetter); } void Application::packageModel() { diff --git a/interface/src/Application.h b/interface/src/Application.h index c704e61bfd..61da53e437 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -242,7 +242,7 @@ public slots: Q_INVOKABLE void loadScriptURLDialog(); void toggleLogDialog(); void toggleRunningScriptsWidget(); - void toggleAssetServerWidget(); + void toggleAssetServerWidget(QString filePath = ""); void handleLocalServerConnection(); void readArgumentsFromLocalSocket(); @@ -304,8 +304,6 @@ private slots: bool acceptSnapshot(const QString& urlString); bool askToSetAvatarUrl(const QString& url); bool askToLoadScript(const QString& scriptFilenameOrURL); - bool askToUploadAsset(const QString& asset); - void modelUploadFinished(AssetUpload* upload, const QString& hash); bool askToWearAvatarAttachmentUrl(const QString& url); void displayAvatarAttachmentWarning(const QString& message) const; diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index d91829b26a..ad512865ec 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -35,7 +35,6 @@ #include "MainWindow.h" #include "render/DrawStatus.h" #include "scripting/MenuScriptingInterface.h" -#include "ui/AssetUploadDialogFactory.h" #include "ui/DialogsManager.h" #include "ui/StandAloneJSConsole.h" #include "InterfaceLogging.h" @@ -365,17 +364,6 @@ Menu::Menu() { // Developer > Assets >>> MenuWrapper* assetDeveloperMenu = developerMenu->addMenu("Assets"); - auto& assetDialogFactory = AssetUploadDialogFactory::getInstance(); - assetDialogFactory.setDialogParent(this); - QAction* assetUpload = addActionToQMenuAndActionHash(assetDeveloperMenu, - MenuOption::UploadAsset, - 0, - &assetDialogFactory, - SLOT(showDialog())); - - // disable the asset upload action by default - it gets enabled only if asset server becomes present - assetUpload->setEnabled(false); - auto& atpMigrator = ATPAssetMigrator::getInstance(); atpMigrator.setDialogParent(this); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 880b48a51b..3e18da10b9 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -169,7 +169,6 @@ namespace MenuOption { const QString ToolWindow = "Tool Window"; const QString TransmitterDrive = "Transmitter Drive"; const QString TurnWithHead = "Turn using Head"; - const QString UploadAsset = "Upload File to Asset Server"; const QString UseAudioForMouth = "Use Audio for Mouth"; const QString UseCamera = "Use Camera"; const QString UseAnimPreAndPostRotations = "Use Anim Pre and Post Rotations";