aboutsummaryrefslogtreecommitdiff
path: root/qml/components/NoticeOptional.qml
blob: 83e0198fd1c9edcc729f6e0a7ca4dd52b664f83f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import QtQuick 2.6
import Sailfish.Silica 1.0

/// Helper to allow using Notice without breaking compilation on SailfishOS 3.4.
/// This helper conditionally loads either a Notice or a Notification
/// (or nothing if useNotificationFallback is disabled) based on the availability
/// of the Notice type.
Loader {
    property string text
    property string duration : "Notice.Short"
    property bool useNotificationFallback : true
    property bool transientNotificationFallback : duration === "Notice.Short"

    readonly property bool noticesAvailable : typeof(Notices) !== "undefined"

    function show() {
        asynchronous = false;
        if(item){
            if(item.show) {
                item.show();
                return;
            }
            else if(item.publish){
                item.publish();
                return;
            }
        }
        console.log("Notice could not be shown: " + text);
    }

    asynchronous: true
    source: noticesAvailable
            ? "../helpers/NoticeLoadable.qml"
            : (useNotificationFallback ? "../helpers/NotificationLoadable.qml" : "")

    Binding {
        target: item
        property: "text"
        value: text
        when: noticesAvailable && status == Loader.Ready
    }
    Binding {
        target: item
        property: "duration"
        value: duration
        when: noticesAvailable && status == Loader.Ready
    }
    //----------------------------------------------------------
    //fallback bindings
    Binding {
        target: item
        property: "summary"
        value: text
        when: !noticesAvailable && useNotificationFallback && status == Loader.Ready
    }
    Binding {
        target: item
        property: "previewSummary"
        value: text
        when: !noticesAvailable && useNotificationFallback && status == Loader.Ready
    }
    Binding {
        target: item
        property: "isTransient"
        value: transientNotificationFallback
        when: !noticesAvailable && useNotificationFallback && status == Loader.Ready
    }
}