Re: [SailfishDevel] Binding singleton values and network availablity

2019-08-31 Thread Thomas Tanghus
On 8/30/19 2:22 PM, Thomas Tanghus wrote:
>   Binding {
>   target: app
>   property: 'isOnline'
>   value: Env.isOnline
>   }
> 
> Is there a way to have this binding without creating it explicitly?

Having worked a bit with it, it's actually a handy way to wait for a
variable, that takes some time to initialize.
Sorry for the noise :P

-- 
/Thomas

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



signature.asc
Description: OpenPGP digital signature
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

[SailfishDevel] Binding singleton values and network availablity

2019-08-30 Thread Thomas Tanghus
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?



signature.asc
Description: OpenPGP digital signature
___
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org