With kind and subtle help from Coderus, I found ways to monitor network
availability. To use it in different places of the project, I'm trying
to make a singleton which holds relevant variables and states.

That part actually works - almost.

The singleton module(/object/class?): ;)

Env.qml:

  pragma Singleton

  import QtQuick 2.6

  QtObject {
      property bool isOnline: network.isOnline
      onIsOnlineChanged: console.log('Env.isOnline:', isOnline)

      property var network: {
          var component = Qt.createComponent(Qt.resolvedUrl('Network.qml'));
          return component.createObject();
      }
  }

This instantiates:

Network.qml:

import QtQuick 2.6
import org.freedesktop.contextkit 1.0

  QtObject {
      id: network
      property bool isOnline: state.value === 'connected'
      property ContextProperty state

      onIsOnlineChanged: console.log('Env.Network.isOnline:', isOnline)

      state: ContextProperty {
          id: networkOnline
          key: 'Internet.NetworkState'
          onValueChanged: {
              console.log('Env.Network.state', value, isOnline)
          }
      }
  }

Both 'onIsOnlineChanged' triggers successfully, but not so much actually
using them:

harbour-myapp.qml:

  ApplicationWindow {
      property bool isOnline: Env.isOnline // Creates no binding

      // This isn't triggered
      onIsOnlineChanged: {
          console.log('App.onIsOnlineChanged', isOnline)
      }

      // Until I make this binding
      Binding { // This does create a binding
          target: app
          property: 'isOnline'
          value: Env.isOnline
      }
  }

Is there a way to have this binding without creating it explicitly?

Next question: I need the binding to work, because I don't want to fire
off any request before I know if the network is up. Is there anything
that can be done to shorten the relatively long time it takes for the
ContextProperty to register network connectivity?

-- 
/Thomas

A: Because it breaks the logical sequence of discussion
Q: Why is top posting bad?

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

Reply via email to