mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 04:44:08 +02:00
commit
672bafc09d
8 changed files with 187 additions and 78 deletions
|
@ -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) {
|
||||
|
@ -212,28 +212,31 @@ Window {
|
|||
});
|
||||
}
|
||||
|
||||
property var uploadOpen: false;
|
||||
function uploadClicked() {
|
||||
if (uploadOpen) {
|
||||
return;
|
||||
}
|
||||
uploadOpen = true;
|
||||
|
||||
var fileUrl = fileUrlTextField.text
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
reload();
|
||||
});
|
||||
uploadOpen = false;
|
||||
}
|
||||
|
||||
function errorMessageBox(message) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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: "|"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,6 @@
|
|||
#include <BuildInfo.h>
|
||||
#include <AssetClient.h>
|
||||
#include <AssetUpload.h>
|
||||
#include <AssetMappingsScriptingInterface.h>
|
||||
#include <AutoUpdater.h>
|
||||
#include <AudioInjectorManager.h>
|
||||
#include <CursorManager.h>
|
||||
|
@ -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"
|
||||
|
@ -426,7 +426,6 @@ bool setupEssentials(int& argc, char** argv) {
|
|||
DependencyManager::set<MessagesClient>();
|
||||
DependencyManager::set<UserInputMapper>();
|
||||
DependencyManager::set<controller::ScriptingInterface, ControllerScriptingInterface>();
|
||||
DependencyManager::set<AssetMappingsScriptingInterface>();
|
||||
DependencyManager::set<InterfaceParentFinder>();
|
||||
DependencyManager::set<EntityTreeRenderer>(true, qApp, qApp);
|
||||
DependencyManager::set<CompositorHelper>();
|
||||
|
@ -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<AssetMappingsScriptingInterface>().data());
|
||||
rootContext->setContextProperty("Assets", new AssetMappingsScriptingInterface());
|
||||
|
||||
rootContext->setContextProperty("AvatarList", DependencyManager::get<AvatarManager>().data());
|
||||
|
||||
|
|
|
@ -12,11 +12,13 @@
|
|||
#include "AssetMappingsScriptingInterface.h"
|
||||
|
||||
#include <QtScript/QScriptEngine>
|
||||
#include <QtCore/QFile>
|
||||
|
||||
#include <AssetRequest.h>
|
||||
#include <AssetUpload.h>
|
||||
#include <MappingRequest.h>
|
||||
#include <NetworkLogging.h>
|
||||
#include <OffscreenUi.h>
|
||||
|
||||
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,64 @@ 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) {
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||
auto result = offscreenUi->inputDialog(OffscreenUi::ICON_NONE, "Enter asset path:", "", mapping);
|
||||
|
||||
if (!result.isValid()) {
|
||||
return;
|
||||
}
|
||||
mapping = result.toString();
|
||||
|
||||
// Check for override
|
||||
if (isKnownMapping(mapping)) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
auto upload = DependencyManager::get<AssetClient>()->createUpload(path);
|
||||
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<AssetClient>();
|
||||
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 +144,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 +160,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();
|
||||
|
@ -198,7 +236,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;
|
|
@ -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)
|
||||
|
@ -59,12 +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<AssetRequest*> _pendingRequests;
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue