ApplicationConfiguration.qml 5.65 KB
Newer Older
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
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
/*
 * Copyright 2019 Kai Uwe Broulik <kde@privat.broulik.de>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License or (at your option) version 3 or any later version
 * accepted by the membership of KDE e.V. (or its successor approved
 * by the membership of KDE e.V.), which shall act as a proxy
 * defined in Section 14 of version 3 of the license.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.9
import QtQml.Models 2.2
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.3 as QtControls

import org.kde.kirigami 2.7 as Kirigami
import org.kde.kcm 1.2 as KCM

import org.kde.notificationmanager 1.0 as NotificationManager

import org.kde.private.kcms.notifications 1.0 as Private

ColumnLayout {
    id: configColumn

    property var rootIndex

38
39
    readonly property string otherAppsId: "@other"

Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
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
    readonly property string appDisplayName: kcm.sourcesModel.data(rootIndex, Qt.DisplayRole) || ""
    readonly property string appIconName: kcm.sourcesModel.data(rootIndex, Qt.DecorationRole) || ""
    readonly property string desktopEntry: kcm.sourcesModel.data(rootIndex, Private.SourcesModel.DesktopEntryRole) || ""
    readonly property string notifyRcName: kcm.sourcesModel.data(rootIndex, Private.SourcesModel.NotifyRcNameRole) || ""

    property int behavior: {
        if (configColumn.desktopEntry) {
            return kcm.settings.applicationBehavior(configColumn.desktopEntry);
        } else if (configColumn.notifyRcName) {
            return kcm.settings.serviceBehavior(configColumn.notifyRcName);
        }
        return -1;
    }

    function setBehavior(flag, enable) {
        var newBehavior = behavior;
        if (enable) {
            newBehavior |= flag;
        } else {
            newBehavior &= ~flag;
        }

        if (configColumn.desktopEntry) {
            return kcm.settings.setApplicationBehavior(configColumn.desktopEntry, newBehavior);
        } else if (configColumn.notifyRcName) {
            return kcm.settings.setServiceBehavior(configColumn.notifyRcName, newBehavior);
        }
    }

    function configureEvents(eventId) {
        kcm.configureEvents(configColumn.notifyRcName, eventId, this)
    }

    spacing: Kirigami.Units.smallSpacing

    Kirigami.FormLayout {
        id: form

        RowLayout {
            Kirigami.FormData.isSection: true
            spacing: Kirigami.Units.smallSpacing

            Kirigami.Icon {
                Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium
                Layout.preferredHeight: Kirigami.Units.iconSizes.smallMedium
                source: configColumn.appIconName
            }

            Kirigami.Heading {
                level: 2
                text: configColumn.appDisplayName
                elide: Text.ElideRight
                textFormat: Text.PlainText
            }
        }

        QtControls.CheckBox {
            id: showPopupsCheck
            text: i18n("Show popups")
            checked: configColumn.behavior & NotificationManager.Settings.ShowPopups
            onClicked: configColumn.setBehavior(NotificationManager.Settings.ShowPopups, checked)
        }

103
        RowLayout { // just for indentation
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
104
            QtControls.CheckBox {
105
106
                Layout.leftMargin: mirrored ? 0 : indicator.width
                Layout.rightMargin: mirrored ? indicator.width : 0
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
                text: i18n("Show in do not disturb mode")
                enabled: showPopupsCheck.checked
                checked: configColumn.behavior & NotificationManager.Settings.ShowPopupsInDoNotDisturbMode
                onClicked: configColumn.setBehavior(NotificationManager.Settings.ShowPopupsInDoNotDisturbMode, checked)
            }
        }

        QtControls.CheckBox {
            text: i18n("Show in history")
            checked: configColumn.behavior & NotificationManager.Settings.ShowInHistory
            onClicked: configColumn.setBehavior(NotificationManager.Settings.ShowInHistory, checked)
        }

        QtControls.CheckBox {
            text: i18n("Show notification badges")
122
            enabled: !!configColumn.desktopEntry && configColumn.desktopEntry !== configColumn.otherAppsId
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
123
124
125
126
127
128
            checked: configColumn.behavior & NotificationManager.Settings.ShowBadges
            onClicked: configColumn.setBehavior(NotificationManager.Settings.ShowBadges, checked)
        }

        Kirigami.Separator {
            Kirigami.FormData.isSection: true
129
            visible: configureEventsButton.visible || noEventsLabel.visible
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
130
131
132
133
134
135
136
137
138
139
140
141
        }

        QtControls.Button {
            id: configureEventsButton
            text: i18n("Configure Events...")
            icon.name: "preferences-desktop-notification"
            visible: !!configColumn.notifyRcName
            onClicked: configColumn.configureEvents()
        }
    }

    QtControls.Label {
142
        id: noEventsLabel
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
143
144
145
146
        Layout.alignment: Qt.AlignHCenter
        Layout.preferredWidth: form.implicitWidth
        text: i18n("This application does not support configuring notifications on a per-event basis.");
        wrapMode: Text.WordWrap
147
        visible: !configColumn.notifyRcName && configColumn.desktopEntry !== configColumn.otherAppsId
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
148
149
150
151
152
153
154
    }

    // compact layout
    Item {
        Layout.fillHeight: true
    }
}