From 8cc0ae3148881697c8e37a9764129533b271b1a5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 10 Mar 2016 13:16:02 -0800 Subject: [PATCH 01/15] menu and naming changes for asset server directory --- interface/resources/qml/AssetServer.qml | 2 +- interface/src/Menu.cpp | 11 ++++++----- interface/src/Menu.h | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/interface/resources/qml/AssetServer.qml b/interface/resources/qml/AssetServer.qml index c69af702fb..2f79eae931 100644 --- a/interface/resources/qml/AssetServer.qml +++ b/interface/resources/qml/AssetServer.qml @@ -21,7 +21,7 @@ import "dialogs" Window { id: root objectName: "AssetServer" - title: "Asset Server" + title: "My Asset Server" resizable: true destroyOnInvisible: true x: 40; y: 40 diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 58617bcb7c..abb1b4e143 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -95,10 +95,6 @@ Menu::Menu() { addActionToQMenuAndActionHash(editMenu, MenuOption::RunningScripts, Qt::CTRL | Qt::Key_J, qApp, SLOT(toggleRunningScriptsWidget())); - // Edit > Asset Server - addActionToQMenuAndActionHash(editMenu, MenuOption::AssetServer, 0, - qApp, SLOT(toggleAssetServerWidget())); - // Edit > Open and Run Script from File... [advanced] addActionToQMenuAndActionHash(editMenu, MenuOption::LoadScript, Qt::CTRL | Qt::Key_O, qApp, SLOT(loadDialog()), @@ -131,10 +127,15 @@ Menu::Menu() { SLOT(toggleConsole()), QAction::NoRole, UNSPECIFIED_POSITION, "Advanced"); + editMenu->addSeparator(); + + // Edit > My Asset Server + addActionToQMenuAndActionHash(editMenu, MenuOption::AssetServer, 0, qApp, SLOT(toggleAssetServerWidget())); + // Edit > Reload All Content [advanced] addActionToQMenuAndActionHash(editMenu, MenuOption::ReloadContent, 0, qApp, SLOT(reloadResourceCaches()), QAction::NoRole, UNSPECIFIED_POSITION, "Advanced"); - + // Edit > Package Model... [advanced] addActionToQMenuAndActionHash(editMenu, MenuOption::PackageModel, 0, diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 9ed7a605dc..93394828ec 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -34,7 +34,7 @@ namespace MenuOption { const QString AnimDebugDrawDefaultPose = "Debug Draw Default Pose"; const QString AnimDebugDrawPosition= "Debug Draw Position"; const QString AssetMigration = "ATP Asset Migration"; - const QString AssetServer = "Asset Server"; + const QString AssetServer = "My Asset Server"; const QString Attachments = "Attachments..."; const QString AudioNetworkStats = "Audio Network Stats"; const QString AudioNoiseReduction = "Audio Noise Reduction"; From 1678c9be20436bcd372f6b76388b214d7c208e30 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 10 Mar 2016 13:24:11 -0800 Subject: [PATCH 02/15] add a keyboard shortcut for the asset directory --- interface/src/Menu.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index abb1b4e143..0724e75ea1 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -130,7 +130,8 @@ Menu::Menu() { editMenu->addSeparator(); // Edit > My Asset Server - addActionToQMenuAndActionHash(editMenu, MenuOption::AssetServer, 0, qApp, SLOT(toggleAssetServerWidget())); + addActionToQMenuAndActionHash(editMenu, MenuOption::AssetServer, Qt::CTRL | Qt::SHIFT | Qt::Key_A, + qApp, SLOT(toggleAssetServerWidget())); // Edit > Reload All Content [advanced] addActionToQMenuAndActionHash(editMenu, MenuOption::ReloadContent, 0, qApp, SLOT(reloadResourceCaches()), From c65b5b63f0e50f31f353411cec9a544eec5317a3 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 10 Mar 2016 14:20:16 -0800 Subject: [PATCH 03/15] better error handling for asset browser --- interface/resources/qml/AssetServer.qml | 30 +++++++------- .../src/AssetMappingsScriptingInterface.cpp | 39 +++++++++++++------ .../src/AssetMappingsScriptingInterface.h | 9 ++--- 3 files changed, 48 insertions(+), 30 deletions(-) diff --git a/interface/resources/qml/AssetServer.qml b/interface/resources/qml/AssetServer.qml index 2f79eae931..e74699f367 100644 --- a/interface/resources/qml/AssetServer.qml +++ b/interface/resources/qml/AssetServer.qml @@ -56,12 +56,13 @@ Window { Assets.deleteMappings(path, function(err) { if (err) { console.log("Error deleting path: ", path, err); - errorMessage("There was an error deleting:\n" + path + "\n\nPlease try again."); + + box = errorMessageBox("There was an error deleting:\n" + path + "\n" + Assets.getErrorString(err)); + box.selected.connect(reload); } else { console.log("Finished deleting path: ", path); + reload(); } - - reload(); }); } @@ -76,7 +77,8 @@ Window { Assets.renameMapping(oldPath, newPath, function(err) { if (err) { console.log("Error renaming: ", oldPath, "=>", newPath, " - error ", err); - errorMessage("There was an error renaming:\n" + oldPath + " to " + newPath + "\n\nPlease try again."); + box = errorMessageBox("There was an error renaming:\n" + oldPath + " to " + newPath + "\n" + Assets.getErrorString(err)); + box.selected.connect(reload); } else { console.log("Finished rename: ", oldPath, "=>", newPath); } @@ -119,9 +121,11 @@ Window { Assets.mappingModel.refresh(); } - function handleGetMappingsError() { - errorMessage("There was a problem retreiving the list of assets from your Asset Server.\n" - + "Please make sure you are connected to the Asset Server and try again. "); + function handleGetMappingsError(errorCode) { + errorMessageBox( + "There was a problem retreiving the list of assets from your Asset Server.\n" + + Assets.getErrorString(errorCode) + ); } function addToWorld() { @@ -234,12 +238,12 @@ Window { }); } - function errorMessage(message) { - desktop.messageBox({ - icon: OriginalDialogs.StandardIcon.Error, - buttons: OriginalDialogs.StandardButton.Ok, - text: "Error", - informativeText: message + function errorMessageBox(message) { + return desktop.messageBox({ + icon: hifi.icons.warning, + defaultButton: OriginalDialogs.StandardButton.Ok, + title: "Error", + text: message }); } diff --git a/libraries/script-engine/src/AssetMappingsScriptingInterface.cpp b/libraries/script-engine/src/AssetMappingsScriptingInterface.cpp index ee8deb4056..e40e47b944 100644 --- a/libraries/script-engine/src/AssetMappingsScriptingInterface.cpp +++ b/libraries/script-engine/src/AssetMappingsScriptingInterface.cpp @@ -25,6 +25,27 @@ AssetMappingsScriptingInterface::AssetMappingsScriptingInterface() { _proxyModel.sort(0); } +QString AssetMappingsScriptingInterface::getErrorString(int errorCode) const { + switch (errorCode) { + case MappingRequest::NoError: + return "No error"; + case MappingRequest::NotFound: + return "Asset not found"; + case MappingRequest::NetworkError: + return "Unable to communicate with Asset Server"; + case MappingRequest::PermissionDenied: + return "Permission denied"; + case MappingRequest::InvalidPath: + return "Path is invalid"; + case MappingRequest::InvalidHash: + return "Hash is invalid"; + case MappingRequest::UnknownError: + return "Asset Server internal error"; + default: + return QString(); + } +} + void AssetMappingsScriptingInterface::setMapping(QString path, QString hash, QJSValue callback) { auto assetClient = DependencyManager::get(); auto request = assetClient->createSetMappingRequest(path, hash); @@ -113,22 +134,16 @@ void AssetMappingsScriptingInterface::renameMapping(QString oldPath, QString new } -AssetMappingItem::AssetMappingItem(const QString& name, const QString& fullPath, bool isFolder) - : name(name), +AssetMappingItem::AssetMappingItem(const QString& name, const QString& fullPath, bool isFolder) : + name(name), fullPath(fullPath), - isFolder(isFolder) { + isFolder(isFolder) +{ } static int assetMappingModelMetatypeId = qRegisterMetaType("AssetMappingModel*"); -AssetMappingModel::AssetMappingModel() { -} - -AssetMappingModel::~AssetMappingModel() { - qDebug() << " DEST"; -} - void AssetMappingModel::refresh() { qDebug() << "Refreshing asset mapping model"; auto assetClient = DependencyManager::get(); @@ -221,7 +236,9 @@ void AssetMappingModel::refresh() { //removeitem->index(); } } else { - emit errorGettingMappings(uint8_t(request->getError())); + qDebug() << "THE ERROR IS" << request->getError(); + qDebug() << "Casted error is" << static_cast(request->getError()); + emit errorGettingMappings(static_cast(request->getError())); } }); diff --git a/libraries/script-engine/src/AssetMappingsScriptingInterface.h b/libraries/script-engine/src/AssetMappingsScriptingInterface.h index 67c0856730..3458da949a 100644 --- a/libraries/script-engine/src/AssetMappingsScriptingInterface.h +++ b/libraries/script-engine/src/AssetMappingsScriptingInterface.h @@ -33,17 +33,12 @@ class AssetMappingModel : public QStandardItemModel { Q_OBJECT public: - AssetMappingModel(); - ~AssetMappingModel(); - -// QVariant AssetMappingModel::data(const QModelIndex& index, int role) const; - Q_INVOKABLE void refresh(); bool isKnownMapping(QString path) const { return _pathToItemMap.contains(path); }; signals: - void errorGettingMappings(uint8_t error); + void errorGettingMappings(int error); private: QHash _pathToItemMap; @@ -62,6 +57,8 @@ public: Q_INVOKABLE bool isKnownMapping(QString path) const { return _assetMappingModel.isKnownMapping(path); }; + Q_INVOKABLE QString getErrorString(int errorCode) const; + Q_INVOKABLE void setMapping(QString path, QString hash, QJSValue callback); Q_INVOKABLE void getMapping(QString path, QJSValue callback); Q_INVOKABLE void deleteMappings(QStringList paths, QJSValue callback); From e93bc8317f039eb907512c9705cb67072303625a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 10 Mar 2016 14:22:50 -0800 Subject: [PATCH 04/15] remove an extra space --- assignment-client/src/assets/AssetServer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index 962e0fc583..38f4c66f4b 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -464,7 +464,6 @@ void AssetServer::loadMappingsFromFile() { shouldDrop = true; } - if (!isValidHash(it.value().toString())) { qWarning() << "Will not keep mapping for" << it.key() << "since it does not have a valid hash."; shouldDrop = true; From d077ade350087b64f67a1c0df07102bf8b15a9c5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 10 Mar 2016 14:26:45 -0800 Subject: [PATCH 05/15] fix path regex to handle leading double slash --- libraries/networking/src/AssetUtils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/networking/src/AssetUtils.h b/libraries/networking/src/AssetUtils.h index 52ed7336c2..ac3d819ae2 100644 --- a/libraries/networking/src/AssetUtils.h +++ b/libraries/networking/src/AssetUtils.h @@ -31,7 +31,7 @@ const size_t SHA256_HASH_LENGTH = 32; const size_t SHA256_HASH_HEX_LENGTH = 64; const uint64_t MAX_UPLOAD_SIZE = 1000 * 1000 * 1000; // 1GB -const QString ASSET_PATH_REGEX_STRING = "^\\/(?:[^\\/]|\\/(?!\\/))*$"; +const QString ASSET_PATH_REGEX_STRING = "^\\/(?!\\/)(?:[^\\/]|\\/(?!\\/))*$"; const QString ASSET_HASH_REGEX_STRING = QString("^[a-fA-F0-9]{%1}$").arg(SHA256_HASH_HEX_LENGTH); enum AssetServerError : uint8_t { From 5167cf69b277ec8a425fa3ab1ca1e885a504b8d7 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 10 Mar 2016 14:41:35 -0800 Subject: [PATCH 06/15] fix for add to world and delete dialog --- interface/resources/qml/AssetServer.qml | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/interface/resources/qml/AssetServer.qml b/interface/resources/qml/AssetServer.qml index e74699f367..97646de79f 100644 --- a/interface/resources/qml/AssetServer.qml +++ b/interface/resources/qml/AssetServer.qml @@ -129,7 +129,7 @@ Window { } function addToWorld() { - var url = assetMappingsModel.data(treeView.currentIndex, 0x102); + var url = assetProxyModel.data(treeView.currentIndex, 0x103); if (!url) { return; } @@ -137,15 +137,16 @@ Window { Entities.addModelEntity(url, MyAvatar.position); } - function copyURLToClipboard(index) { + function copyURLToClipboard() { if (!index) { index = treeView.currentIndex; } - var path = assetProxyModel.data(index, 0x103); - if (!path) { + + var url = assetProxyModel.data(treeView.currentIndex, 0x103); + if (!url) { return; } - Window.copyToClipboard(path); + Window.copyToClipboard(url); } function renameFile(index) { @@ -188,13 +189,11 @@ Window { var typeString = isFolder ? 'folder' : 'file'; var object = desktop.messageBox({ - icon: OriginalDialogs.StandardIcon.Question, - buttons: OriginalDialogs.StandardButton.Yes | OriginalDialogs.StandardButton.No, - defaultButton: OriginalDialogs.StandardButton.No, - text: "Deleting", - informativeText: "You are about to delete the following " + typeString + ":\n" + - path + - "\nDo you want to continue?" + icon: hifi.icons.question, + buttons: OriginalDialogs.StandardButton.Yes + OriginalDialogs.StandardButton.No, + defaultButton: OriginalDialogs.StandardButton.Yes, + title: "Delete", + text: "You are about to delete the following " + typeString + ":\n" + path + "\nDo you want to continue?" }); object.selected.connect(function(button) { if (button === OriginalDialogs.StandardButton.Yes) { From e227f68353675b2b9f7a6bb27c02d8e0aef9b6b8 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 10 Mar 2016 14:42:24 -0800 Subject: [PATCH 07/15] tweak wording for overwrite dialog --- interface/resources/qml/AssetServer.qml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/interface/resources/qml/AssetServer.qml b/interface/resources/qml/AssetServer.qml index 97646de79f..ade6563622 100644 --- a/interface/resources/qml/AssetServer.qml +++ b/interface/resources/qml/AssetServer.qml @@ -93,12 +93,11 @@ Window { function askForOverride(path, callback) { var object = desktop.messageBox({ - icon: OriginalDialogs.StandardIcon.Question, + icon: hifi.icons.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?" + defaultButton: OriginalDialogs.StandardButton.Yes, + title: "Overwrite File", + text: path + "\n" + "This file already exists. Do you want to overwrite it?" }); object.selected.connect(function(button) { if (button === OriginalDialogs.StandardButton.Yes) { From 7f0917ea00f66d5f1d9727df65ebba7ca7973a51 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 10 Mar 2016 14:47:24 -0800 Subject: [PATCH 08/15] add to world in front of MyAvatar --- interface/resources/qml/AssetServer.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/resources/qml/AssetServer.qml b/interface/resources/qml/AssetServer.qml index ade6563622..32e0a3b8ee 100644 --- a/interface/resources/qml/AssetServer.qml +++ b/interface/resources/qml/AssetServer.qml @@ -132,8 +132,8 @@ Window { if (!url) { return; } - - Entities.addModelEntity(url, MyAvatar.position); + var addPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(MyAvatar.orientation))); + Entities.addModelEntity(url, addPosition); } function copyURLToClipboard() { From b3d8b67893ed3696ed4ea88ef7e84ef962248644 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 10 Mar 2016 14:50:21 -0800 Subject: [PATCH 09/15] remove committed debug lines --- libraries/script-engine/src/AssetMappingsScriptingInterface.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/script-engine/src/AssetMappingsScriptingInterface.cpp b/libraries/script-engine/src/AssetMappingsScriptingInterface.cpp index e40e47b944..a843094df3 100644 --- a/libraries/script-engine/src/AssetMappingsScriptingInterface.cpp +++ b/libraries/script-engine/src/AssetMappingsScriptingInterface.cpp @@ -236,8 +236,6 @@ void AssetMappingModel::refresh() { //removeitem->index(); } } else { - qDebug() << "THE ERROR IS" << request->getError(); - qDebug() << "Casted error is" << static_cast(request->getError()); emit errorGettingMappings(static_cast(request->getError())); } }); From dc79d3262a979f268753fbb861377880e22bc1ba Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 9 Mar 2016 15:50:33 -0800 Subject: [PATCH 10/15] Update glyphs font --- .../qml/styles-uit/HifiConstants.qml | 131 +++++++++++++----- 1 file changed, 100 insertions(+), 31 deletions(-) diff --git a/interface/resources/qml/styles-uit/HifiConstants.qml b/interface/resources/qml/styles-uit/HifiConstants.qml index 32cf61117b..09cba6d462 100644 --- a/interface/resources/qml/styles-uit/HifiConstants.qml +++ b/interface/resources/qml/styles-uit/HifiConstants.qml @@ -35,7 +35,7 @@ Item { glyph = hifi.glyphs.alert; break; case hifi.icons.critical: - glyph = hifi.glyphs.critical; + glyph = hifi.glyphs.error; break; case hifi.icons.placemark: glyph = hifi.glyphs.placemark; @@ -159,36 +159,6 @@ Item { readonly property real disclosureButton: dimensions.largeScreen ? 20 : 15 } - Item { - id: glyphs - readonly property string alert: "+" - readonly property string backward: "E" - readonly property string caratDn: "5" - readonly property string caratR: "3" - readonly property string caratUp: "6" - readonly property string close: "w" - readonly property string closeInverted: "x" - readonly property string closeSmall: "C" - readonly property string critical: "=" - readonly property string disclosureButtonCollapse: "M" - readonly property string disclosureButtonExpand: "L" - readonly property string disclosureCollapse: "Z" - readonly property string disclosureExpand: "B" - readonly property string forward: "D" - readonly property string info: "[" - readonly property string noIcon: "" - readonly property string pin: "y" - readonly property string pinInverted: "z" - readonly property string placemark: "U" - readonly property string question: "]" - readonly property string reloadSmall: "a" - readonly property string resizeHandle: "A" - readonly property string upload: "j" - readonly property string reload: "a" - readonly property string back: "1" - - } - Item { id: icons // Values per OffscreenUi::Icon @@ -221,4 +191,103 @@ Item { id: effects readonly property int fadeInDuration: 300 } + Item { + id: glyphs + readonly property string noIcon: "" + readonly property string hmd: "b" + readonly property string screen: "c" + readonly property string keyboard: "d" + readonly property string handControllers: "e" + readonly property string headphonesMic: "f" + readonly property string gamepad: "g" + readonly property string headphones: "h" + readonly property string mic: "i" + readonly property string upload: "j" + readonly property string script: "k" + readonly property string text: "l" + readonly property string cube: "m" + readonly property string sphere: "n" + readonly property string zone: "o" + readonly property string light: "p" + readonly property string web: "q" + readonly property string web2: "r" + readonly property string edit: "s" + readonly property string market: "t" + readonly property string directory: "u" + readonly property string menu: "v" + readonly property string close: "w" + readonly property string closeInverted: "x" + readonly property string pin: "y" + readonly property string pinInverted: "z" + readonly property string resizeHandle: "A" + readonly property string disclosureExpand: "B" + readonly property string reloadSmall: "a" + readonly property string closeSmall: "C" + readonly property string forward: "D" + readonly property string backward: "E" + readonly property string reload: "F" + readonly property string unmuted: "G" + readonly property string muted: "H" + readonly property string minimize: "I" + readonly property string maximize: "J" + readonly property string maximizeInverted: "K" + readonly property string disclosureButtonExpand: "L" + readonly property string disclosureButtonCollapse: "M" + readonly property string scriptStop: "N" + readonly property string scriptReload: "O" + readonly property string scriptRun: "P" + readonly property string scriptNew: "Q" + readonly property string hifiForum: "2" + readonly property string hifiLogoSmall: "S" + readonly property string avatar1: "T" + readonly property string placemark: "U" + readonly property string box: "V" + readonly property string community: "0" + readonly property string grabHandle: "X" + readonly property string search: "Y" + readonly property string disclosureCollapse: "Z" + readonly property string scriptUpload: "R" + readonly property string code: "W" + readonly property string avatar: "<" + readonly property string arrowsH: ":" + readonly property string arrowsV: ";" + readonly property string arrows: "`" + readonly property string compress: "!" + readonly property string expand: "\"" + readonly property string placemark1: "#" + readonly property string circle: "$" + readonly property string handPointer: "9" + readonly property string plusSquareO: "%" + readonly property string sliders: "&" + readonly property string square: "'" + readonly property string alignCenter: "8" + readonly property string alignJustify: ")" + readonly property string alignLeft: "*" + readonly property string alignRight: "^" + readonly property string bars: "7" + readonly property string circleSlash: "," + readonly property string sync: "()" + readonly property string key: "-" + readonly property string link: "." + readonly property string location: "/" + readonly property string caratR: "3" + readonly property string caratL: "4" + readonly property string caratDn: "5" + readonly property string caratUp: "6" + readonly property string folderLg: ">" + readonly property string folderSm: "?" + readonly property string levelUp: "1" + readonly property string info: "[" + readonly property string question: "]" + readonly property string alert: "+" + readonly property string home: "_" + readonly property string error: "=" + readonly property string settings: "@" + readonly property string trash: "{" + readonly property string objectGroup: "" + readonly property string cm: "}" + readonly property string msvg79: "~" + readonly property string deg: "\\" + readonly property string px: "|" + } } From 7d7a683b18ae9f623b8b379e2076f6ccfdcdaeb6 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 10 Mar 2016 13:33:36 -0800 Subject: [PATCH 11/15] Add uploadFile method that prompts the user --- interface/resources/qml/AssetServer.qml | 18 ++-- .../resources/qml/dialogs/QueryDialog.qml | 4 +- interface/src/Application.cpp | 2 +- .../AssetMappingsScriptingInterface.cpp | 84 ++++++++++++++----- .../AssetMappingsScriptingInterface.h | 1 + libraries/networking/src/MappingRequest.h | 1 + 6 files changed, 74 insertions(+), 36 deletions(-) rename {libraries/script-engine/src => interface/src/scripting}/AssetMappingsScriptingInterface.cpp (76%) rename {libraries/script-engine/src => interface/src/scripting}/AssetMappingsScriptingInterface.h (96%) diff --git a/interface/resources/qml/AssetServer.qml b/interface/resources/qml/AssetServer.qml index 32e0a3b8ee..eacbd15ec5 100644 --- a/interface/resources/qml/AssetServer.qml +++ b/interface/resources/qml/AssetServer.qml @@ -159,7 +159,7 @@ Window { var object = desktop.inputDialog({ label: "Enter new path:", - prefilledText: path, + current: path, placeholderText: "Enter path here" }); object.selected.connect(function(destinationPath) { @@ -220,18 +220,12 @@ Window { var directory = path ? path.slice(0, path.lastIndexOf('/') + 1) : ""; var filename = fileUrl.slice(fileUrl.lastIndexOf('/') + 1); - var object = desktop.inputDialog({ - label: "Enter asset path:", - prefilledText: directory + filename, - placeholderText: "Enter path here" - }); - object.selected.connect(function(destinationPath) { - if (fileExists(destinationPath)) { - askForOverride(fileUrl, function() { - doUploadFile(fileUrl, destinationPath, addToWorld); - }); + Assets.uploadFile(fileUrl, directory + filename, function(err) { + if (err) { + console.log("Error uploading: ", fileUrl, " - error ", err); + errorMessage("There was an error uploading:\n" + fileUrl + "\n\nPlease try again."); } else { - doUploadFile(fileUrl, destinationPath, addToWorld); + console.log("Finished uploading: ", fileUrl); } }); } diff --git a/interface/resources/qml/dialogs/QueryDialog.qml b/interface/resources/qml/dialogs/QueryDialog.qml index 754851030c..48df9a41ce 100644 --- a/interface/resources/qml/dialogs/QueryDialog.qml +++ b/interface/resources/qml/dialogs/QueryDialog.qml @@ -34,12 +34,10 @@ ModalWindow { property var items; property string label property var result; - // FIXME not current honored - property var current; + property alias current: textResult.text // For text boxes property alias placeholderText: textResult.placeholderText - property alias prefilledText: textResult.text // For combo boxes property bool editable: true; diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 2660acfa00..e8b2384bbf 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -66,7 +66,6 @@ #include #include #include -#include #include #include #include @@ -142,6 +141,7 @@ #include "ModelPackager.h" #include "PluginContainerProxy.h" #include "scripting/AccountScriptingInterface.h" +#include "scripting/AssetMappingsScriptingInterface.h" #include "scripting/AudioDeviceScriptingInterface.h" #include "scripting/ClipboardScriptingInterface.h" #include "scripting/DesktopScriptingInterface.h" diff --git a/libraries/script-engine/src/AssetMappingsScriptingInterface.cpp b/interface/src/scripting/AssetMappingsScriptingInterface.cpp similarity index 76% rename from libraries/script-engine/src/AssetMappingsScriptingInterface.cpp rename to interface/src/scripting/AssetMappingsScriptingInterface.cpp index a843094df3..b4f9458551 100644 --- a/libraries/script-engine/src/AssetMappingsScriptingInterface.cpp +++ b/interface/src/scripting/AssetMappingsScriptingInterface.cpp @@ -12,11 +12,13 @@ #include "AssetMappingsScriptingInterface.h" #include +#include #include #include #include #include +#include AssetMappingsScriptingInterface::AssetMappingsScriptingInterface() { _proxyModel.setSourceModel(&_assetMappingModel); @@ -51,12 +53,12 @@ void AssetMappingsScriptingInterface::setMapping(QString path, QString hash, QJS auto request = assetClient->createSetMappingRequest(path, hash); connect(request, &SetMappingRequest::finished, this, [this, callback](SetMappingRequest* request) mutable { - QJSValueList args { uint8_t(request->getError()) }; - - callback.call(args); + if (callback.isCallable()) { + QJSValueList args { uint8_t(request->getError()) }; + callback.call(args); + } request->deleteLater(); - }); request->start(); @@ -67,28 +69,70 @@ void AssetMappingsScriptingInterface::getMapping(QString path, QJSValue callback auto request = assetClient->createGetMappingRequest(path); connect(request, &GetMappingRequest::finished, this, [this, callback](GetMappingRequest* request) mutable { - QJSValueList args { uint8_t(request->getError()), request->getHash() }; - - callback.call(args); + if (callback.isCallable()) { + QJSValueList args { uint8_t(request->getError()) }; + callback.call(args); + } request->deleteLater(); - }); request->start(); } +void AssetMappingsScriptingInterface::uploadFile(QString path, QString mapping, QJSValue callback) { + QFile file(path); + if (!file.open(QFile::ReadOnly)) { + qCWarning(asset_client) << "Error uploading file to asset server:\n" + << "Could not open" << qPrintable(path); + OffscreenUi::warning("File Error", "Could not open file: " + path, QMessageBox::Ok); + return; + } + + auto offscreenUi = DependencyManager::get(); + auto result = offscreenUi->inputDialog(OffscreenUi::ICON_NONE, "Enter asset path:", "", mapping); + if (!result.isValid()) { + return; + } + + // Check for override + if (isKnownMapping(result.toString())) { + auto message = "The following file already exists:\n" + path + "\nDo you want to override it?"; + auto button = offscreenUi->messageBox(OffscreenUi::ICON_QUESTION, "", message, + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + if (button == QMessageBox::No) { + return; + } + } + + auto upload = DependencyManager::get()->createUpload(file.readAll()); + QObject::connect(upload, &AssetUpload::finished, this, [=](AssetUpload* upload, const QString& hash) mutable { + if (upload->getError() != AssetUpload::NoError) { + if (callback.isCallable()) { + QJSValueList args { uint8_t(upload->getError()) }; + callback.call(args); + } + } else { + setMapping(mapping, hash, callback); + } + + upload->deleteLater(); + }); + + upload->start(); +} + void AssetMappingsScriptingInterface::deleteMappings(QStringList paths, QJSValue callback) { auto assetClient = DependencyManager::get(); auto request = assetClient->createDeleteMappingsRequest(paths); connect(request, &DeleteMappingsRequest::finished, this, [this, callback](DeleteMappingsRequest* request) mutable { - QJSValueList args { uint8_t(request->getError()) }; - - callback.call(args); + if (callback.isCallable()) { + QJSValueList args { uint8_t(request->getError()) }; + callback.call(args); + } request->deleteLater(); - }); request->start(); @@ -106,12 +150,12 @@ void AssetMappingsScriptingInterface::getAllMappings(QJSValue callback) { map.setProperty(kv.first, kv.second); } - QJSValueList args { uint8_t(request->getError()), map }; - - callback.call(args); + if (callback.isCallable()) { + QJSValueList args { uint8_t(request->getError()) }; + callback.call(args); + } request->deleteLater(); - }); request->start(); @@ -122,12 +166,12 @@ void AssetMappingsScriptingInterface::renameMapping(QString oldPath, QString new auto request = assetClient->createRenameMappingRequest(oldPath, newPath); connect(request, &RenameMappingRequest::finished, this, [this, callback](RenameMappingRequest* request) mutable { - QJSValueList args { uint8_t(request->getError()) }; - - callback.call(args); + if (callback.isCallable()) { + QJSValueList args { uint8_t(request->getError()) }; + callback.call(args); + } request->deleteLater(); - }); request->start(); diff --git a/libraries/script-engine/src/AssetMappingsScriptingInterface.h b/interface/src/scripting/AssetMappingsScriptingInterface.h similarity index 96% rename from libraries/script-engine/src/AssetMappingsScriptingInterface.h rename to interface/src/scripting/AssetMappingsScriptingInterface.h index 3458da949a..f1198ef17d 100644 --- a/libraries/script-engine/src/AssetMappingsScriptingInterface.h +++ b/interface/src/scripting/AssetMappingsScriptingInterface.h @@ -61,6 +61,7 @@ public: Q_INVOKABLE void setMapping(QString path, QString hash, QJSValue callback); Q_INVOKABLE void getMapping(QString path, QJSValue callback); + Q_INVOKABLE void uploadFile(QString path, QString mapping, QJSValue callback = QJSValue()); Q_INVOKABLE void deleteMappings(QStringList paths, QJSValue callback); Q_INVOKABLE void deleteMapping(QString path, QJSValue callback) { deleteMappings(QStringList(path), callback); } Q_INVOKABLE void getAllMappings(QJSValue callback); diff --git a/libraries/networking/src/MappingRequest.h b/libraries/networking/src/MappingRequest.h index c6a27e0274..504a0cb2fa 100644 --- a/libraries/networking/src/MappingRequest.h +++ b/libraries/networking/src/MappingRequest.h @@ -64,6 +64,7 @@ class SetMappingRequest : public MappingRequest { public: SetMappingRequest(const AssetPath& path, const AssetHash& hash); + AssetPath getPath() const { return _path; } AssetHash getHash() const { return _hash; } signals: From 548d826a4e58d6a95db92de16febec17a226706c Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 10 Mar 2016 14:04:52 -0800 Subject: [PATCH 12/15] Couple bug fixes --- interface/resources/qml/AssetServer.qml | 4 +++- interface/src/Application.cpp | 3 +-- .../scripting/AssetMappingsScriptingInterface.cpp | 15 ++++----------- .../scripting/AssetMappingsScriptingInterface.h | 2 +- libraries/networking/src/MappingRequest.cpp | 2 +- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/interface/resources/qml/AssetServer.qml b/interface/resources/qml/AssetServer.qml index eacbd15ec5..1220f288f7 100644 --- a/interface/resources/qml/AssetServer.qml +++ b/interface/resources/qml/AssetServer.qml @@ -217,7 +217,7 @@ Window { var addToWorld = addToWorldCheckBox.checked var path = assetProxyModel.data(treeView.currentIndex, 0x100); - var directory = path ? path.slice(0, path.lastIndexOf('/') + 1) : ""; + var directory = path ? path.slice(0, path.lastIndexOf('/') + 1) : "/"; var filename = fileUrl.slice(fileUrl.lastIndexOf('/') + 1); Assets.uploadFile(fileUrl, directory + filename, function(err) { @@ -227,6 +227,8 @@ Window { } else { console.log("Finished uploading: ", fileUrl); } + + reload(); }); } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e8b2384bbf..a8e64513ee 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -426,7 +426,6 @@ bool setupEssentials(int& argc, char** argv) { DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); - DependencyManager::set(); DependencyManager::set(); DependencyManager::set(true, qApp, qApp); DependencyManager::set(); @@ -1296,7 +1295,7 @@ void Application::initializeUi() { rootContext->setContextProperty("Quat", new Quat()); rootContext->setContextProperty("Vec3", new Vec3()); rootContext->setContextProperty("Uuid", new ScriptUUID()); - rootContext->setContextProperty("Assets", DependencyManager::get().data()); + rootContext->setContextProperty("Assets", new AssetMappingsScriptingInterface()); rootContext->setContextProperty("AvatarList", DependencyManager::get().data()); diff --git a/interface/src/scripting/AssetMappingsScriptingInterface.cpp b/interface/src/scripting/AssetMappingsScriptingInterface.cpp index b4f9458551..ea763210c9 100644 --- a/interface/src/scripting/AssetMappingsScriptingInterface.cpp +++ b/interface/src/scripting/AssetMappingsScriptingInterface.cpp @@ -81,22 +81,15 @@ void AssetMappingsScriptingInterface::getMapping(QString path, QJSValue callback } void AssetMappingsScriptingInterface::uploadFile(QString path, QString mapping, QJSValue callback) { - QFile file(path); - if (!file.open(QFile::ReadOnly)) { - qCWarning(asset_client) << "Error uploading file to asset server:\n" - << "Could not open" << qPrintable(path); - OffscreenUi::warning("File Error", "Could not open file: " + path, QMessageBox::Ok); - return; - } - auto offscreenUi = DependencyManager::get(); auto result = offscreenUi->inputDialog(OffscreenUi::ICON_NONE, "Enter asset path:", "", mapping); if (!result.isValid()) { return; } + mapping = result.toString(); // Check for override - if (isKnownMapping(result.toString())) { + if (isKnownMapping(mapping)) { auto message = "The following file already exists:\n" + path + "\nDo you want to override it?"; auto button = offscreenUi->messageBox(OffscreenUi::ICON_QUESTION, "", message, QMessageBox::Yes | QMessageBox::No, QMessageBox::No); @@ -105,7 +98,7 @@ void AssetMappingsScriptingInterface::uploadFile(QString path, QString mapping, } } - auto upload = DependencyManager::get()->createUpload(file.readAll()); + auto upload = DependencyManager::get()->createUpload(path); QObject::connect(upload, &AssetUpload::finished, this, [=](AssetUpload* upload, const QString& hash) mutable { if (upload->getError() != AssetUpload::NoError) { if (callback.isCallable()) { @@ -242,7 +235,7 @@ void AssetMappingModel::refresh() { auto it = existingPaths.begin(); while (it != existingPaths.end()) { auto item = _pathToItemMap[*it]; - if (item->data(Qt::UserRole + 1).toBool()) { + if (item && item->data(Qt::UserRole + 1).toBool()) { it = existingPaths.erase(it); } else { ++it; diff --git a/interface/src/scripting/AssetMappingsScriptingInterface.h b/interface/src/scripting/AssetMappingsScriptingInterface.h index f1198ef17d..2ad7da7c94 100644 --- a/interface/src/scripting/AssetMappingsScriptingInterface.h +++ b/interface/src/scripting/AssetMappingsScriptingInterface.h @@ -45,7 +45,7 @@ }; -class AssetMappingsScriptingInterface : public QObject, public Dependency { +class AssetMappingsScriptingInterface : public QObject { Q_OBJECT Q_PROPERTY(AssetMappingModel* mappingModel READ getAssetMappingModel CONSTANT) Q_PROPERTY(QAbstractProxyModel* proxyModel READ getProxyModel CONSTANT) diff --git a/libraries/networking/src/MappingRequest.cpp b/libraries/networking/src/MappingRequest.cpp index 6f76d1103f..2cc28c03be 100644 --- a/libraries/networking/src/MappingRequest.cpp +++ b/libraries/networking/src/MappingRequest.cpp @@ -109,7 +109,7 @@ void SetMappingRequest::doStart() { auto validPath = isValidPath(_path); auto validHash = isValidHash(_hash); if (!validPath || !validHash) { - _error = validPath ? MappingRequest::InvalidPath : MappingRequest::InvalidHash; + _error = !validPath ? MappingRequest::InvalidPath : MappingRequest::InvalidHash; emit finished(this); return; } From 63571a7c36d424dffa0157e67b3da2ea23d81787 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 10 Mar 2016 14:57:02 -0800 Subject: [PATCH 13/15] Make sure Upload is not clicked several times --- interface/resources/qml/AssetServer.qml | 7 +++++++ .../src/scripting/AssetMappingsScriptingInterface.cpp | 1 + 2 files changed, 8 insertions(+) diff --git a/interface/resources/qml/AssetServer.qml b/interface/resources/qml/AssetServer.qml index 1220f288f7..0490db2fa7 100644 --- a/interface/resources/qml/AssetServer.qml +++ b/interface/resources/qml/AssetServer.qml @@ -212,7 +212,13 @@ Window { }); } + property var uploadOpen: false; function uploadClicked() { + if(uploadOpen) { + return; + } + uploadOpen = true; + var fileUrl = fileUrlTextField.text var addToWorld = addToWorldCheckBox.checked @@ -230,6 +236,7 @@ Window { reload(); }); + uploadOpen = false; } function errorMessageBox(message) { diff --git a/interface/src/scripting/AssetMappingsScriptingInterface.cpp b/interface/src/scripting/AssetMappingsScriptingInterface.cpp index ea763210c9..9934b7937c 100644 --- a/interface/src/scripting/AssetMappingsScriptingInterface.cpp +++ b/interface/src/scripting/AssetMappingsScriptingInterface.cpp @@ -83,6 +83,7 @@ void AssetMappingsScriptingInterface::getMapping(QString path, QJSValue callback void AssetMappingsScriptingInterface::uploadFile(QString path, QString mapping, QJSValue callback) { auto offscreenUi = DependencyManager::get(); auto result = offscreenUi->inputDialog(OffscreenUi::ICON_NONE, "Enter asset path:", "", mapping); + if (!result.isValid()) { return; } From cf12a8d3963439e83437b0c4dda4401836cd5013 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 10 Mar 2016 15:02:19 -0800 Subject: [PATCH 14/15] always center the text in the message dialog --- interface/resources/qml/dialogs/MessageDialog.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/resources/qml/dialogs/MessageDialog.qml b/interface/resources/qml/dialogs/MessageDialog.qml index fa702090d3..4a25c51012 100644 --- a/interface/resources/qml/dialogs/MessageDialog.qml +++ b/interface/resources/qml/dialogs/MessageDialog.qml @@ -96,6 +96,7 @@ ModalWindow { } lineHeight: 2 lineHeightMode: Text.ProportionalHeight + horizontalAlignment: Text.AlignHCenter } RalewaySemiBold { From a6ccfb1685e75f77f6dfa3f39699cf44c83c6517 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 10 Mar 2016 15:03:25 -0800 Subject: [PATCH 15/15] CR --- interface/resources/qml/AssetServer.qml | 2 +- .../src/scripting/AssetMappingsScriptingInterface.cpp | 4 ++-- .../src/scripting/AssetMappingsScriptingInterface.h | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/interface/resources/qml/AssetServer.qml b/interface/resources/qml/AssetServer.qml index 0490db2fa7..c4855b7704 100644 --- a/interface/resources/qml/AssetServer.qml +++ b/interface/resources/qml/AssetServer.qml @@ -214,7 +214,7 @@ Window { property var uploadOpen: false; function uploadClicked() { - if(uploadOpen) { + if (uploadOpen) { return; } uploadOpen = true; diff --git a/interface/src/scripting/AssetMappingsScriptingInterface.cpp b/interface/src/scripting/AssetMappingsScriptingInterface.cpp index 9934b7937c..2839a0a9f6 100644 --- a/interface/src/scripting/AssetMappingsScriptingInterface.cpp +++ b/interface/src/scripting/AssetMappingsScriptingInterface.cpp @@ -91,8 +91,8 @@ void AssetMappingsScriptingInterface::uploadFile(QString path, QString mapping, // Check for override if (isKnownMapping(mapping)) { - auto message = "The following file already exists:\n" + path + "\nDo you want to override it?"; - auto button = offscreenUi->messageBox(OffscreenUi::ICON_QUESTION, "", message, + auto message = path + "\n" + "This file already exists. Do you want to overwrite it?"; + auto button = offscreenUi->messageBox(OffscreenUi::ICON_QUESTION, "Overwrite File", message, QMessageBox::Yes | QMessageBox::No, QMessageBox::No); if (button == QMessageBox::No) { return; diff --git a/interface/src/scripting/AssetMappingsScriptingInterface.h b/interface/src/scripting/AssetMappingsScriptingInterface.h index 2ad7da7c94..3a7711b340 100644 --- a/interface/src/scripting/AssetMappingsScriptingInterface.h +++ b/interface/src/scripting/AssetMappingsScriptingInterface.h @@ -59,13 +59,13 @@ public: Q_INVOKABLE QString getErrorString(int errorCode) const; - Q_INVOKABLE void setMapping(QString path, QString hash, QJSValue callback); - Q_INVOKABLE void getMapping(QString path, QJSValue callback); + Q_INVOKABLE void setMapping(QString path, QString hash, QJSValue callback = QJSValue()); + Q_INVOKABLE void getMapping(QString path, QJSValue callback = QJSValue()); Q_INVOKABLE void uploadFile(QString path, QString mapping, QJSValue callback = QJSValue()); Q_INVOKABLE void deleteMappings(QStringList paths, QJSValue callback); - Q_INVOKABLE void deleteMapping(QString path, QJSValue callback) { deleteMappings(QStringList(path), callback); } - Q_INVOKABLE void getAllMappings(QJSValue callback); - Q_INVOKABLE void renameMapping(QString oldPath, QString newPath, QJSValue callback); + Q_INVOKABLE void deleteMapping(QString path, QJSValue callback) { deleteMappings(QStringList(path), callback = QJSValue()); } + Q_INVOKABLE void getAllMappings(QJSValue callback = QJSValue()); + Q_INVOKABLE void renameMapping(QString oldPath, QString newPath, QJSValue callback = QJSValue()); protected: QSet _pendingRequests;