File: NotificationsComponent.qml

package info (click to toggle)
plasma-mobile 6.3.6-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 18,612 kB
  • sloc: xml: 38,470; cpp: 18,437; javascript: 139; sh: 82; makefile: 5
file content (111 lines) | stat: -rw-r--r-- 3,626 bytes parent folder | download
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// SPDX-FileCopyrightText: 2022 Devin Lin <espidev@gmail.com>
// SPDX-License-Identifier: GPL-2.0-or-later

import QtQuick
import QtQuick.Layouts

import org.kde.plasma.private.mobileshell as MobileShell
import org.kde.kirigami as Kirigami

import org.kde.notificationmanager as NotificationManager

Loader {
    id: root
    required property var lockScreenState

    property var notificationsModel: []
    property var notificationSettings: NotificationManager.Settings {}

    property real leftMargin: 0
    property real rightMargin: 0
    property real topMargin: 0
    property real bottomMargin: 0

    property real topPadding: 0

    readonly property bool notificationsShown: item && item.notificationsList.hasNotifications
    readonly property bool listOverflowing: item && item.notificationsList.listView.listOverflowing

    property bool scrollLock: false

    property var notificationsList: item ? item.notificationsList : null

    signal passwordRequested()

    // perform delayed loading of notifications
    active: false
    Timer {
        interval: 500
        running: true
        onTriggered: root.active = true
    }

    Connections {
        target: lockScreenState

        function onUnlockSucceeded() {
            // run pending action if successfully unlocked
            if (notificationsList.requestNotificationAction) {
                notificationsList.runPendingAction();
                notificationsList.requestNotificationAction = false;
            }
        }

        function onUnlockFailed() {
            notificationsList.requestNotificationAction = false;
        }
    }

    sourceComponent: Item {
        clip: true

        property alias notificationsList: notificationsList

        Item {
            anchors.top: parent.top
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.topMargin: root.topMargin
            anchors.leftMargin: root.leftMargin
            anchors.rightMargin: root.rightMargin

            Kirigami.Theme.colorSet: Kirigami.Theme.Window
            Kirigami.Theme.inherit: false

            height: Math.min(parent.height - root.topMargin - root.bottomMargin, notificationsList.listView.listHeight + Kirigami.Units.gridUnit)

            MobileShell.NotificationsWidget {
                id: notificationsList
                anchors.fill: parent
                opacity: 0 // we display with the opacity gradient below

                historyModelType: MobileShell.NotificationsModelType.WatchedNotificationsModel
                actionsRequireUnlock: true
                historyModel: root.notificationsModel
                notificationSettings: root.notificationSettings
                inLockscreen: true
                topPadding: root.topPadding // Kirigami.Units.gridUnit
                bottomPadding: Kirigami.Units.gridUnit
                listView.interactive: !root.scrollLock && listView.listOverflowing

                property bool requestNotificationAction: false

                onUnlockRequested: {
                    requestNotificationAction = true;
                    root.passwordRequested();
                }
            }

            // opacity gradient at flickable edges
            MobileShell.FlickableOpacityGradient {
                anchors {
                    top: notificationsList.top
                    left: notificationsList.left
                    right: notificationsList.right
                }
                height: notificationsList.listView.height
                flickable: notificationsList.listView
            }
        }
    }
}