MCPcopy Create free account
hub / github.com/KangLin/RabbitRemoteControl / addSignal

Function addSignal

Plugins/WebBrowser/Resource/js/QWebChannel.js:248–299  ·  view source on GitHub ↗
(signalData, isPropertyNotifySignal)

Source from the content-addressed store, hash-verified

246 }
247
248 function addSignal(signalData, isPropertyNotifySignal)
249 {
250 var signalName = signalData[0];
251 var signalIndex = signalData[1];
252 object[signalName] = {
253 connect: function(callback) {
254 if (typeof(callback) !== "function") {
255 console.error("Bad callback given to connect to signal " + signalName);
256 return;
257 }
258
259 object.__objectSignals__[signalIndex] = object.__objectSignals__[signalIndex] || [];
260 object.__objectSignals__[signalIndex].push(callback);
261
262 // only required for "pure" signals, handled separately for properties in propertyUpdate
263 if (isPropertyNotifySignal)
264 return;
265
266 // also note that we always get notified about the destroyed signal
267 if (signalName === "destroyed" || signalName === "destroyed()" || signalName === "destroyed(QObject*)")
268 return;
269
270 // and otherwise we only need to be connected only once
271 if (object.__objectSignals__[signalIndex].length == 1) {
272 webChannel.exec({
273 type: QWebChannelMessageTypes.connectToSignal,
274 object: object.__id__,
275 signal: signalIndex
276 });
277 }
278 },
279 disconnect: function(callback) {
280 if (typeof(callback) !== "function") {
281 console.error("Bad callback given to disconnect from signal " + signalName);
282 return;
283 }
284 // This makes a new list. This is important because it won't interfere with
285 // signal processing if a disconnection happens while emittig a signal
286 object.__objectSignals__[signalIndex] = (object.__objectSignals__[signalIndex] || []).filter(function(c) {
287 return c != callback;
288 });
289 if (!isPropertyNotifySignal && object.__objectSignals__[signalIndex].length === 0) {
290 // only required for "pure" signals, handled separately for properties in propertyUpdate
291 webChannel.exec({
292 type: QWebChannelMessageTypes.disconnectFromSignal,
293 object: object.__id__,
294 signal: signalIndex
295 });
296 }
297 }
298 };
299 }
300
301 /**
302 * Invokes all callbacks for the given signalname. Also works for property notify callbacks.

Callers 2

bindGetterSetterFunction · 0.85
QObjectFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected