From 194226103c5cabc1a6bd5e9129b5188a3d90d570 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 1 Apr 2016 11:13:59 -0700 Subject: [PATCH] refresh the Asset Browser when switching domains --- interface/resources/qml/AssetServer.qml | 6 ++++- interface/src/Application.cpp | 25 ++++++++++++++++--- .../AssetMappingsScriptingInterface.cpp | 14 +++++++++++ .../AssetMappingsScriptingInterface.h | 4 ++- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/interface/resources/qml/AssetServer.qml b/interface/resources/qml/AssetServer.qml index 37291480b2..bcbd2a87e3 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: "My Asset Server" + title: "Asset Browser" resizable: true destroyOnInvisible: true x: 40; y: 40 @@ -125,6 +125,10 @@ Window { }, false); } + function clear() { + Assets.mappingModel.clear(); + } + function reload() { Assets.mappingModel.refresh(); treeView.selection.clear(); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ffc9b0333c..4b924d4095 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4121,6 +4121,16 @@ 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) { + // asset server just connected - check if we have the asset browser showing + + auto offscreenUi = DependencyManager::get(); + auto assetDialog = offscreenUi->getRootItem()->findChild("AssetServer"); + + if (assetDialog) { + // call reload on the shown asset browser dialog to get the mappings (if permissions allow) + QMetaObject::invokeMethod(assetDialog, "reload"); + } } } @@ -4136,10 +4146,7 @@ void Application::nodeKilled(SharedNodePointer node) { if (node->getType() == NodeType::AudioMixer) { QMetaObject::invokeMethod(DependencyManager::get().data(), "audioMixerKilled"); - } - - if (node->getType() == NodeType::EntityServer) { - + } else if (node->getType() == NodeType::EntityServer) { QUuid nodeUUID = node->getUUID(); // see if this is the first we've heard of this node... _entityServerJurisdictions.withReadLock([&] { @@ -4170,6 +4177,16 @@ 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) { + // asset server going away - check if we have the asset browser showing + + auto offscreenUi = DependencyManager::get(); + auto assetDialog = offscreenUi->getRootItem()->findChild("AssetServer"); + + if (assetDialog) { + // call reload on the shown asset browser dialog + QMetaObject::invokeMethod(assetDialog, "clear"); + } } } void Application::trackIncomingOctreePacket(ReceivedMessage& message, SharedNodePointer sendingNode, bool wasStatsPacket) { diff --git a/interface/src/scripting/AssetMappingsScriptingInterface.cpp b/interface/src/scripting/AssetMappingsScriptingInterface.cpp index 005f8a597c..3f11bd1fd8 100644 --- a/interface/src/scripting/AssetMappingsScriptingInterface.cpp +++ b/interface/src/scripting/AssetMappingsScriptingInterface.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -20,6 +21,19 @@ #include #include +void AssetMappingModel::clear() { + // make sure we are on the same thread before we touch the hash + if (thread() != QThread::currentThread()) { + QMetaObject::invokeMethod(this, "clear"); + return; + } + + qDebug() << "Clearing loaded asset mappings for Asset Browser"; + + _pathToItemMap.clear(); + QStandardItemModel::clear(); +} + AssetMappingsScriptingInterface::AssetMappingsScriptingInterface() { _proxyModel.setSourceModel(&_assetMappingModel); _proxyModel.setSortRole(Qt::DisplayRole); diff --git a/interface/src/scripting/AssetMappingsScriptingInterface.h b/interface/src/scripting/AssetMappingsScriptingInterface.h index 831b30513a..459f01b512 100644 --- a/interface/src/scripting/AssetMappingsScriptingInterface.h +++ b/interface/src/scripting/AssetMappingsScriptingInterface.h @@ -21,7 +21,6 @@ #include - class AssetMappingModel : public QStandardItemModel { Q_OBJECT public: @@ -30,6 +29,9 @@ public: bool isKnownMapping(QString path) const { return _pathToItemMap.contains(path); } bool isKnownFolder(QString path) const; +public slots: + void clear(); + signals: void errorGettingMappings(QString errorString);