mirror of
https://github.com/lubosz/overte.git
synced 2025-04-27 13:15:45 +02:00
better implementation
This commit is contained in:
parent
5f3e31b119
commit
2ab8eb98e8
5 changed files with 52 additions and 37 deletions
interface/src
libraries/script-engine
|
@ -2342,6 +2342,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
|
|||
return viewFrustum.getPosition();
|
||||
});
|
||||
|
||||
DependencyManager::get<UsersScriptingInterface>()->setKickConfirmationOperator([this] (const QUuid& nodeID) { userKickConfirmation(nodeID); });
|
||||
|
||||
render::entities::WebEntityRenderer::setAcquireWebSurfaceOperator([this](const QString& url, bool htmlContent, QSharedPointer<OffscreenQmlSurface>& webSurface, bool& cachedWebSurface) {
|
||||
bool isTablet = url == TabletScriptingInterface::QML;
|
||||
if (htmlContent) {
|
||||
|
@ -3287,6 +3289,40 @@ void Application::onDesktopRootItemCreated(QQuickItem* rootItem) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void Application::userKickConfirmation(const QUuid& nodeID) {
|
||||
auto avatarHashMap = DependencyManager::get<AvatarHashMap>();
|
||||
auto avatar = avatarHashMap->getAvatarBySessionID(nodeID);
|
||||
|
||||
QString userName;
|
||||
|
||||
if (avatar) {
|
||||
userName = avatar->getSessionDisplayName();
|
||||
} else {
|
||||
userName = nodeID.toString();
|
||||
}
|
||||
|
||||
QString kickMessage = "Do you wish to kick " + userName + " from your domain";
|
||||
ModalDialogListener* dlg = OffscreenUi::asyncQuestion("Kick User", kickMessage,
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
|
||||
if (dlg->getDialogItem()) {
|
||||
|
||||
QObject::connect(dlg, &ModalDialogListener::response, this, [=] (QVariant answer) {
|
||||
QObject::disconnect(dlg, &ModalDialogListener::response, this, nullptr);
|
||||
|
||||
bool yes = (static_cast<QMessageBox::StandardButton>(answer.toInt()) == QMessageBox::Yes);
|
||||
// ask the NodeList to kick the user with the given session ID
|
||||
|
||||
if (yes) {
|
||||
DependencyManager::get<NodeList>()->kickNodeBySessionID(nodeID);
|
||||
}
|
||||
|
||||
DependencyManager::get<UsersScriptingInterface>()->setWaitForKickResponse(false);
|
||||
});
|
||||
DependencyManager::get<UsersScriptingInterface>()->setWaitForKickResponse(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::setupQmlSurface(QQmlContext* surfaceContext, bool setAdditionalContextProperties) {
|
||||
surfaceContext->setContextProperty("Users", DependencyManager::get<UsersScriptingInterface>().data());
|
||||
surfaceContext->setContextProperty("HMD", DependencyManager::get<HMDScriptingInterface>().data());
|
||||
|
|
|
@ -593,6 +593,7 @@ private:
|
|||
void toggleTabletUI(bool shouldOpen = false) const;
|
||||
|
||||
static void setupQmlSurface(QQmlContext* surfaceContext, bool setAdditionalContextProperties);
|
||||
void userKickConfirmation(const QUuid& nodeID);
|
||||
|
||||
MainWindow* _window;
|
||||
QElapsedTimer& _sessionRunTimer;
|
||||
|
|
|
@ -17,6 +17,6 @@ if (NOT ANDROID)
|
|||
|
||||
endif ()
|
||||
|
||||
link_hifi_libraries(shared networking octree shaders gpu procedural graphics material-networking model-networking ktx recording avatars fbx hfm entities controllers animation audio physics image midi ui qml)
|
||||
link_hifi_libraries(shared networking octree shaders gpu procedural graphics material-networking model-networking ktx recording avatars fbx hfm entities controllers animation audio physics image midi)
|
||||
# ui includes gl, but link_hifi_libraries does not use transitive includes, so gl must be explicit
|
||||
include_hifi_library_headers(gl)
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
#include "UsersScriptingInterface.h"
|
||||
|
||||
#include <NodeList.h>
|
||||
#include <AvatarHashMap.h>
|
||||
#include <OffscreenUi.h>
|
||||
|
||||
UsersScriptingInterface::UsersScriptingInterface() {
|
||||
// emit a signal when kick permissions have changed
|
||||
|
@ -54,42 +52,14 @@ float UsersScriptingInterface::getAvatarGain(const QUuid& nodeID) {
|
|||
}
|
||||
|
||||
void UsersScriptingInterface::kick(const QUuid& nodeID) {
|
||||
bool waitingForKickResponse = _kickResponseLock.resultWithReadLock<bool>([&] { return _waitingForKickResponse; });
|
||||
if (getCanKick() && !waitingForKickResponse) {
|
||||
|
||||
|
||||
auto avatarHashMap = DependencyManager::get<AvatarHashMap>();
|
||||
auto avatar = avatarHashMap->getAvatarBySessionID(nodeID);
|
||||
|
||||
QString userName;
|
||||
|
||||
if (avatar) {
|
||||
userName = avatar->getSessionDisplayName();
|
||||
} else {
|
||||
userName = nodeID.toString();
|
||||
}
|
||||
|
||||
QString kickMessage = "Do you wish to kick " + userName + " from your domain";
|
||||
ModalDialogListener* dlg = OffscreenUi::asyncQuestion("Kick User", kickMessage,
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
|
||||
if (dlg->getDialogItem()) {
|
||||
|
||||
QObject::connect(dlg, &ModalDialogListener::response, this, [=] (QVariant answer) {
|
||||
QObject::disconnect(dlg, &ModalDialogListener::response, this, nullptr);
|
||||
|
||||
bool yes = (static_cast<QMessageBox::StandardButton>(answer.toInt()) == QMessageBox::Yes);
|
||||
// ask the NodeList to kick the user with the given session ID
|
||||
|
||||
if (yes) {
|
||||
DependencyManager::get<NodeList>()->kickNodeBySessionID(nodeID);
|
||||
}
|
||||
|
||||
_kickResponseLock.withWriteLock([&] { _waitingForKickResponse = false; });
|
||||
});
|
||||
|
||||
_kickResponseLock.withWriteLock([&] { _waitingForKickResponse = true; });
|
||||
if (_kickConfirmationOperator) {
|
||||
bool waitingForKickResponse = _kickResponseLock.resultWithReadLock<bool>([&] { return _waitingForKickResponse; });
|
||||
if (getCanKick() && !waitingForKickResponse) {
|
||||
_kickConfirmationOperator(nodeID);
|
||||
}
|
||||
} else {
|
||||
DependencyManager::get<NodeList>()->kickNodeBySessionID(nodeID);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,12 @@ class UsersScriptingInterface : public QObject, public Dependency {
|
|||
|
||||
public:
|
||||
UsersScriptingInterface();
|
||||
void setKickConfirmationOperator(std::function<void(const QUuid& nodeID)> kickConfirmationOperator) {
|
||||
_kickConfirmationOperator = kickConfirmationOperator;
|
||||
}
|
||||
|
||||
bool getWaitForKickResponse() { return _kickResponseLock.resultWithReadLock<bool>([&] { return _waitingForKickResponse; }); }
|
||||
void setWaitForKickResponse(bool waitForKickResponse) { _kickResponseLock.withWriteLock([&] { _waitingForKickResponse = waitForKickResponse; }); }
|
||||
|
||||
public slots:
|
||||
|
||||
|
@ -197,6 +203,8 @@ private:
|
|||
bool getRequestsDomainListData();
|
||||
void setRequestsDomainListData(bool requests);
|
||||
|
||||
std::function<void(const QUuid& nodeID)> _kickConfirmationOperator;
|
||||
|
||||
ReadWriteLockable _kickResponseLock;
|
||||
bool _waitingForKickResponse { false };
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue