Title: Sailfish Development

Sailfish Development - Lessons learned

(this page is WIP)

avaRisk is my first App (not only for SailfishOS) and my first software with qml components. I learned a lot of basic stuff which I want to sum here up. Some things listed are things where I missed some documentation from official sources. For most stuff there should be a 'Real World Example' linked. Code examples are (mostly) QML only.

QML Specific

Forward Information from Page to Page

Forwarding some variables from page to page is very easy. In this example the page is pushed to the stack and a list is added with the name of the property on the new page and the current content/information that is handed over.

property var prop_1: "Hallo"
property var prop_2: 123
pageStack.push(Qt.resolvedUrl("SamplePage.qml"), {"var_1": prop_1, "var_2": prop_2})

On the Target-Page you only need to define these two properties under the Page. They will receive the value.

page {
    property var var_1
    property var var_2
}

Resources

source: "qrc:///res/harbour-avarisk.png"

(Example)

Sailfish Specific

Allowed requires for Sailfish Harbour

I did find the list of allowed requires for sailfish very late. The List helps to check what you can use. If only I would have known earlier that pythons lxml is allowed... ;-) GitHub Page - allowed requires

A good overview is given by OMP here, google translate seems to give an acceptable translation.

UPDATE: Now there is a wiki entry.

Store Data locally

Use the QtStandardPaths (and forward them to python if needed)

StandardPaths.cache

In this example it is used and forwarded to python code.

Open Link in Sailfish Standard Browser

Qt.openUrlExternally(link);

(Example)

Visibility

There is for most Silica components a visible: property, as used here.

Sailfish, Python and PyOtherSide

General Use

There is a little tutorial how to use PyOtherSide in Sailfish to create QML apps with python code in the Background. What is not mentioned there but rather important: To run it on a Phone and in the Emulator you need to add the following to the *.yaml File in the rpm folder of your project under the Requires:-Section

  - pyotherside-qml-plugin-python3-qt5

Send Parameters to Function Call

You can call a python function with parameter list. For example this python function can be called with this call including parameters:

Python function (file in same dir as qml 'python.py'):

class Example:
    def example_func(self, par_1, par_2):
        do stuff

# Make Instance:
example_instance = Example()

QML call:

call('python.example_instance.example_func', [par_1_var, par_2_var], function() {});

Is the Device online?

Therefore you can check out this mer-package. I useed it for example here to store the current State of the connection in the var connection.

import org.freedesktop.contextkit 1.0

...

ContextProperty {
    key: "Internet.NetworkState"

    onValueChanged: {
        connection = value
    }
}

I don't need the Information at this point, but as it seems to give back an empty string (meaning not connected) initially, I forwarded the current state on user interaction to the next page. On the next page it's decided to trigger the python code to download or not based on the connection information without any need to wait. On both pages the state is updated if it changes. For this I use a little trick to not overwrite a "connected" with the empty string indicating no connection:

ContextProperty {
    key: "Internet.NetworkState"

    onValueChanged: {
        if (connection == "" || connectionOnceUpdated) {
            connection = value
            connectionOnceUpdated = true
        }
        if (connection == "connected") {
            connectionOnceUpdated = true
        }
    }
}

Once again you also need to add this code to the *.yaml File in the rpm folder of your project under the Requires:-Section

  - qml(org.freedesktop.contextkit)