diff options
Diffstat (limited to 'qml/components/NoticeOptional.qml')
| -rw-r--r-- | qml/components/NoticeOptional.qml | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/qml/components/NoticeOptional.qml b/qml/components/NoticeOptional.qml new file mode 100644 index 0000000..83e0198 --- /dev/null +++ b/qml/components/NoticeOptional.qml @@ -0,0 +1,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 + } +} |
