Cleanup JS<->QML messaging

This commit is contained in:
Zach Fox 2017-03-16 15:37:59 -07:00
parent 140ef736ee
commit fc2a501474
7 changed files with 47 additions and 48 deletions

View file

@ -156,7 +156,10 @@ Item {
autoScroll: false;
// Signals
onEditingFinished: {
pal.sendToScript({method: 'displayNameUpdate', params: text})
if (MyAvatar.displayName !== text) {
MyAvatar.displayName = text;
UserActivityLogger.palAction("display_name_change", text);
}
cursorPosition = 0
focus = false
myDisplayName.border.width = 0
@ -233,7 +236,10 @@ Item {
anchors.fill: parent
enabled: selected && pal.activeTab == "nearbyTab" && thisNameCard.userName !== "";
hoverEnabled: enabled
onClicked: pal.sendToScript({method: 'goToUser', params: thisNameCard.userName});
onClicked: {
AddressManager.goToUser(thisNameCard.userName);
UserActivityLogger.palAction("go_to_user", thisNameCard.userName);
}
onEntered: {
displayNameText.color = hifi.colors.blueHighlight;
userNameText.color = hifi.colors.blueHighlight;
@ -323,7 +329,10 @@ Item {
anchors.fill: parent
enabled: selected && pal.activeTab == "nearbyTab" && thisNameCard.userName !== "";
hoverEnabled: enabled
onClicked: pal.sendToScript({method: 'goToUser', params: thisNameCard.userName});
onClicked: {
AddressManager.goToUser(thisNameCard.userName);
UserActivityLogger.palAction("go_to_user", thisNameCard.userName);
}
onEntered: {
displayNameText.color = hifi.colors.blueHighlight;
userNameText.color = hifi.colors.blueHighlight;

View file

@ -42,7 +42,6 @@ Rectangle {
property var connectionsUserModelData: []; // This simple list is essentially a mirror of the connectionsUserModel listModel without all the extra complexities.
property bool iAmAdmin: false;
property var activeTab: "nearbyTab";
property int usernameAvailability;
property bool currentlyEditingDisplayName: false
HifiConstants { id: hifi; }
@ -162,6 +161,18 @@ Rectangle {
verticalAlignment: Text.AlignTop;
}
HifiControlsUit.TabletComboBox {
function determineAvailabilityIndex() {
var globalServicesAvailability = GlobalServices.findableBy;
if (globalServicesAvailability === "all") {
return 0;
} else if (globalServicesAvailability === "friends") {
return 1;
} else if (globalServicesAvailability === "none") {
return 2;
} else {
return 1;
}
}
id: availabilityComboBox;
// Anchors
anchors.top: parent.top;
@ -169,14 +180,18 @@ Rectangle {
// Size
width: parent.width;
height: 40;
currentIndex: usernameAvailability;
currentIndex: determineAvailabilityIndex();
model: ListModel {
id: availabilityComboBoxListItems
ListElement { text: "Everyone"; value: "all"; }
ListElement { text: "Friends Only"; value: "friends"; }
ListElement { text: "Appear Offline"; value: "none" }
}
onCurrentIndexChanged: { pal.sendToScript({method: 'setAvailability', params: availabilityComboBoxListItems.get(currentIndex).value})}
onCurrentIndexChanged: {
GlobalServices.findableBy = availabilityComboBoxListItems.get(currentIndex).value;
UserActivityLogger.palAction("set_availability", availabilityComboBoxListItems.get(currentIndex).value);
print('Setting availability:', JSON.stringify(GlobalServices.findableBy));
}
}
}
}
@ -928,7 +943,10 @@ Rectangle {
anchors.fill: parent
hoverEnabled: enabled
enabled: connectionsNameCard.selected && pal.activeTab == "connectionsTab"
onClicked: pal.sendToScript({method: 'goToUser', params: model.userName});
onClicked: {
AddressManager.goToUser(model.userName);
UserActivityLogger.palAction("go_to_user", model.userName);
}
onEntered: connectionsLocationData.color = hifi.colors.blueHighlight;
onExited: connectionsLocationData.color = hifi.colors.darkGray;
}
@ -1260,9 +1278,6 @@ Rectangle {
var sessionID = message.params[0];
delete ignored[sessionID];
break;
case 'updateAvailability':
usernameAvailability = message.params;
break;
default:
console.log('Unrecognized message:', JSON.stringify(message));
}

View file

@ -18,6 +18,7 @@
#include <QScriptValue>
#include <QString>
#include <QStringList>
#include <DiscoverabilityManager.h>
class DownloadInfoResult {
public:

View file

@ -40,6 +40,8 @@
#include <Preferences.h>
#include "FileDialogHelper.h"
#include <OffscreenUi.h>
#include "avatar/AvatarManager.h"
#include "scripting/GlobalServicesScriptingInterface.h"
static const float DPI = 30.47f;
static const float INCHES_TO_METERS = 1.0f / 39.3701f;
@ -171,6 +173,8 @@ void Web3DOverlay::loadSourceURL() {
_webSurface->getRootContext()->setContextProperty("Account", AccountScriptingInterface::getInstance());
_webSurface->getRootContext()->setContextProperty("HMD", DependencyManager::get<HMDScriptingInterface>().data());
_webSurface->getRootContext()->setContextProperty("fileDialogHelper", new FileDialogHelper());
_webSurface->getRootContext()->setContextProperty("MyAvatar", DependencyManager::get<AvatarManager>()->getMyAvatar().get());
_webSurface->getRootContext()->setContextProperty("GlobalServices", GlobalServicesScriptingInterface::getInstance());
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface->getRootItem(), _webSurface.data());
// Override min fps for tablet UI, for silky smooth scrolling

View file

@ -340,7 +340,7 @@ class AvatarData : public QObject, public SpatiallyNestable {
Q_PROPERTY(float audioLoudness READ getAudioLoudness WRITE setAudioLoudness)
Q_PROPERTY(float audioAverageLoudness READ getAudioAverageLoudness WRITE setAudioAverageLoudness)
Q_PROPERTY(QString displayName READ getDisplayName WRITE setDisplayName)
Q_PROPERTY(QString displayName READ getDisplayName WRITE setDisplayName NOTIFY displayNameChanged)
// sessionDisplayName is sanitized, defaulted version displayName that is defined by the AvatarMixer rather than by Interface clients.
// The result is unique among all avatars present at the time.
Q_PROPERTY(QString sessionDisplayName READ getSessionDisplayName WRITE setSessionDisplayName)
@ -614,6 +614,9 @@ public:
signals:
void displayNameChanged();
public slots:
void sendAvatarDataPacket();
void sendIdentityPacket();

View file

@ -41,7 +41,7 @@ class AddressManager : public QObject, public Dependency {
Q_PROPERTY(QString pathname READ currentPath)
Q_PROPERTY(QString placename READ getPlaceName)
Q_PROPERTY(QString domainId READ getDomainId)
Q_PROPERTY(QUrl metaverseServerUrl READ getMetaverseServerUrl)
Q_PROPERTY(QUrl metaverseServerUrl READ getMetaverseServerUrl NOTIFY metaverseServerUrlChanged)
public:
Q_INVOKABLE QString protocolVersion();
using PositionGetter = std::function<glm::vec3()>;
@ -123,6 +123,8 @@ signals:
void goBackPossible(bool isPossible);
void goForwardPossible(bool isPossible);
void metaverseServerUrlChanged();
protected:
AddressManager();
private slots:

View file

@ -1,6 +1,6 @@
"use strict";
/*jslint vars:true, plusplus:true, forin:true*/
/*global Tablet, Settings, Script, AvatarList, Users, Entities, MyAvatar, Camera, Overlays, Vec3, Quat, HMD, Controller, Account, UserActivityLogger, Messages, Window, XMLHttpRequest, print, location, getControllerWorldLocation, GlobalServices*/
/*global Tablet, Settings, Script, AvatarList, Users, Entities, MyAvatar, Camera, Overlays, Vec3, Quat, HMD, Controller, Account, UserActivityLogger, Messages, Window, XMLHttpRequest, print, location, getControllerWorldLocation*/
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
//
// pal.js
@ -265,24 +265,6 @@ function fromQml(message) { // messages are {method, params}, like json-rpc. See
getConnectionData();
UserActivityLogger.palAction("refresh_connections", "");
break;
case 'displayNameUpdate':
if (MyAvatar.displayName !== message.params) {
MyAvatar.displayName = message.params;
UserActivityLogger.palAction("display_name_change", "");
}
break;
case 'goToUser':
location.goToUser(message.params);
UserActivityLogger.palAction("go_to_user", "");
break;
case 'setAvailability':
GlobalServices.findableBy = message.params;
UserActivityLogger.palAction("set_availability", "");
print('Setting availability:', JSON.stringify(message));
break;
case 'getAvailability':
findableByChanged(GlobalServices.findableBy);
break;
default:
print('Unrecognized message from Pal.qml:', JSON.stringify(message));
}
@ -709,7 +691,6 @@ function startup() {
Messages.subscribe(CHANNEL);
Messages.messageReceived.connect(receiveMessage);
Users.avatarDisconnected.connect(avatarDisconnected);
GlobalServices.findableByChanged.connect(findableByChanged);
}
startup();
@ -747,7 +728,6 @@ function onTabletButtonClicked() {
onPalScreen = true;
Users.requestsDomainListData = true;
populateNearbyUserList();
findableByChanged(GlobalServices.findableBy);
isWired = true;
Script.update.connect(updateOverlays);
Controller.mousePressEvent.connect(handleMouseEvent);
@ -857,20 +837,6 @@ function avatarDisconnected(nodeID) {
sendToQml({method: 'avatarDisconnected', params: [nodeID]});
}
function findableByChanged(usernameAvailability) {
// Update PAL availability dropdown
// Default to "friends" if undeterminable
var availability = 1;
if (usernameAvailability === "all") {
availability = 0;
} else if (usernameAvailability === "friends") {
availability = 1;
} else if (usernameAvailability === "none") {
availability = 2;
}
sendToQml({ method: 'updateAvailability', params: availability });
}
function clearLocalQMLDataAndClosePAL() {
sendToQml({ method: 'clearLocalQMLData' });
}
@ -888,7 +854,6 @@ function shutdown() {
Messages.subscribe(CHANNEL);
Messages.messageReceived.disconnect(receiveMessage);
Users.avatarDisconnected.disconnect(avatarDisconnected);
GlobalServices.findableByChanged.disconnect(findableByChanged);
off();
}