| 1 |
/* Copyright (C) 2016 - 2017 Dan Chapman <[email protected]> |
| 2 |
|
| 3 |
This file is part of the Dekko Project |
| 4 |
|
| 5 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
you may not use this file except in compliance with the License. |
| 7 |
You may obtain a copy of the License at |
| 8 |
|
| 9 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
|
| 11 |
Unless required by applicable law or agreed to in writing, |
| 12 |
software distributed under the License is distributed on an |
| 13 |
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
| 14 |
either express or implied. See the License for the specific |
| 15 |
language governing permissions and limitations under the License. |
| 16 |
*/ |
| 17 |
import QtQuick 2.4 |
| 18 |
|
| 19 |
QtObject { |
| 20 |
readonly property bool notificationOnScreen: d.notificationVisible |
| 21 |
readonly property int notificationCount: d.notifications.length |
| 22 |
|
| 23 |
function notify(notification, caller, properties) { |
| 24 |
d.notifications.push(notification) |
| 25 |
d.callers.push(caller) |
| 26 |
d.properties.push(properties) |
| 27 |
timer.start() |
| 28 |
} |
| 29 |
|
| 30 |
property QtObject __internal: QtObject { |
| 31 |
id: d |
| 32 |
property bool notificationVisible: false |
| 33 |
property var notifications: [] |
| 34 |
property var callers: [] |
| 35 |
property var properties: [] |
| 36 |
property var currentNotification |
| 37 |
|
| 38 |
property Timer timer: Timer { |
| 39 |
id: timer |
| 40 |
interval: 50 |
| 41 |
onTriggered: { |
| 42 |
console.log("[dekko-notify] >> Checking notification queue") |
| 43 |
if (!d.notificationVisible && d.notifications.length) { |
| 44 |
console.log("[dekko-notify] >> Notification pending. Showing now!") |
| 45 |
d.show(d.notifications.shift(), d.callers.shift(), d.properties.shift()) |
| 46 |
} else if (d.notificationVisible) { |
| 47 |
console.log("[dekko-notify] >> Notification already on screen, waiting for completion") |
| 48 |
} else { |
| 49 |
console.log("[dekko-notify] >> No notifications to show") |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
function show(notification, caller, properties) { |
| 54 |
var c = Qt.createComponent(notification) |
| 55 |
|
| 56 |
if (c.status === Component.Error) { |
| 57 |
console.log("Error: ", c.errorString()) |
| 58 |
return |
| 59 |
} |
| 60 |
|
| 61 |
d.currentNotification = c.createObject(caller, properties) |
| 62 |
d.currentNotification.closed.connect(d.handleClosed) |
| 63 |
d.notificationVisible = true |
| 64 |
} |
| 65 |
function handleClosed() { |
| 66 |
console.log("[dekko-notify] >> Notification complete. Destroying....") |
| 67 |
d.notificationVisible = false |
| 68 |
d.currentNotification.destroy() |
| 69 |
console.log("[dekko-notify] >> Notification destroyed.") |
| 70 |
timer.start() |
| 71 |
} |
| 72 |
} |
| 73 |
} |