Debian Codegraph @

notify/src/Notify.qml

raw
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 import Lomiri.Components 1.3
19
20 Item {
21 id: notify
22 anchors.fill: parent
23 property alias notificationOnScreen: queue.notificationOnScreen
24 property alias count: queue.notificationCount
25
26 property NotifyConfiguration config: NotifyConfiguration{}
27
28 function send(title, body, props) {
29 if (typeof body === "object" || body instanceof Object) {
30 console.log("[dekko-notify] >> Properties passed as body argument. Correcting....")
31 props = body
32 body = ""
33 }
34 if (props) {
35 console.log("[dekko-notify] >> Queueing custom notification")
36 sendCustom(title, body, props)
37 } else if (body) {
38 if (typeof body === "string" || body instanceof String) {
39 console.log("[dekko-notify] >> Queueing subtitles notification")
40 sendStandard(title, body)
41 } else {
42 console.error("[dekko-notify] >> Invalid body type.")
43 }
44 } else {
45 console.log("[dekko-notify] >> Queueing simple notification")
46 sendStandard(title, "")
47 }
48 }
49
50 function sendStandard(title, body) {
51 sendCustom(title, body, notify.config)
52 }
53
54 function sendCustom(title, body, conf) {
55 var props = {
56 "title" : title,
57 "body" : body,
58 "action": conf.action,
59 "position" : conf.position,
60 "displayTime": conf.displayTime,
61 "iconName" : conf.iconName,
62 "iconColor" : conf.iconColor
63 }
64 queue.notify(conf.source, QuickUtils.rootItem(notify), props)
65 }
66
67 NotifyQueue {
68 id: queue
69 }
70 }