Permalink
Browse files

Add property that reflects the connection state

It's not possible to mark properties as read only from pure QML. The
property will just not have any effect if written to by the client.
  • Loading branch information...
1 parent bfbe097 commit 6d6c2804023daaf0c8c1825face8303e2fb9b5eb @torarnv committed Oct 4, 2011
Showing with 12 additions and 4 deletions.
  1. +12 −4 src/api/Cometd.qml
View
@@ -67,6 +67,8 @@ Item {
onAppendMessageTypeToURLChanged: pimpl.setConfigurationProperty()
onAutoBatchChanged: pimpl.setConfigurationProperty()
+ property bool connected: false
+
// Public API, matching the API from Cometd.js
function configure() {
@@ -115,13 +117,19 @@ Item {
function getConfiguration() { return pimpl.call(); }
function getAdvice() { return pimpl.call(); }
- Component.onCompleted: {
- pimpl.updateConfiguration()
- }
-
Cometd {
id: pimpl
+ Component.onCompleted: {
+ updateConfiguration()
+ addListener('/meta/connect', updateConnectionStatus);
+ addListener('/meta/disconnect', updateConnectionStatus);
+ }
+
+ function updateConnectionStatus() {
+ api.connected = !isDisconnected();
+ }
+
function call() {
var caller = arguments.callee.caller;
return forward(caller.name, caller.arguments);

0 comments on commit 6d6c280

Please sign in to comment.