File: ConfigEntries.qml

package info (click to toggle)
plasma-workspace 4%3A5.8.6-2.1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 54,996 kB
  • sloc: cpp: 70,006; sh: 868; xml: 867; python: 46; makefile: 16
file content (245 lines) | stat: -rw-r--r-- 8,895 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
 *  Copyright 2013 Sebastian Kügler <sebas@kde.org>
 *  Copyright 2014 Marco Martin <mart@kde.org>
 *
 *  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) any later version.
 *
 *  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, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  2.010-1301, USA.
 */

import QtQuick 2.0
import QtQuick.Controls 1.0 as QtControls
import QtQuick.Layouts 1.1 as QtLayouts

import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.kquickcontrolsaddons 2.0
import org.kde.kquickcontrols 2.0 as KQC

QtLayouts.GridLayout {
    id: iconsPage

    signal configurationChanged

    property var cfg_shownItems: []
    property var cfg_hiddenItems: []
    property alias cfg_showAllItems: showAllCheckBox.checked

    columns: 2 // so we can indent the entries below...

    function saveConfig () {
        for (var i in tableView.model) {
            //tableView.model[i].applet.globalShortcut = tableView.model[i].shortcut
        }
    }

    QtControls.CheckBox {
        id: showAllCheckBox
        QtLayouts.Layout.fillWidth: true
        QtLayouts.Layout.columnSpan: iconsPage.columns
        QtLayouts.Layout.row: 1
        text: i18n("Always show all entries")
    }

    QtControls.Button { // just for measurement
        id: measureButton
        text: "measureButton"
        visible: false
    }

    // resizeToContents does not take into account the heading
    QtControls.Label {
        id: shortcutColumnMeasureLabel
        text: shortcutColumn.title
        visible: false
    }

    function retrieveAllItems() {
        print(plasmoid)
        print(plasmoid.rootItem.statusNotifierModel)
        var list = [];
        for (var i = 0; i < plasmoid.rootItem.statusNotifierModel.count; ++i) {
            var item = plasmoid.rootItem.statusNotifierModel.get(i);
            list.push({
                "index": i,
                "taskId": item.Id,
                "name": item.Title,
                "iconName": item.IconName,
                "icon": item.Icon
            });
        }
        var lastIndex = list.length;
        for (var i = 0; i < plasmoid.applets.length; ++i) {
            var item = plasmoid.applets[i]
            list.push({
                "index": (i + lastIndex),
                "applet": item,
                "taskId": item.pluginName,
                "name": item.title,
                "iconName": item.icon,
                "shortcut": item.globalShortcut
            });
        }
        return list;
    }

    QtControls.TableView {
        id: tableView
        QtLayouts.Layout.fillWidth: true
        QtLayouts.Layout.fillHeight: true
        QtLayouts.Layout.row: 2
        QtLayouts.Layout.column: 1

        model: retrieveAllItems()
        horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
        flickableItem.boundsBehavior: Flickable.StopAtBounds

        Component.onCompleted: {
            visibilityColumn.resizeToContents()
            shortcutColumn.resizeToContents()
        }

        // Taken from QtQuickControls BasicTableViewStyle, just to make its height sensible...
        rowDelegate: BorderImage {
            visible: styleData.selected || styleData.alternate
            source: "image://__tablerow/" + (styleData.alternate ? "alternate_" : "")
                    + (tableView.activeFocus ? "active" : "")
            height: measureButton.height
            border.left: 4 ; border.right: 4
        }

        QtControls.TableViewColumn {
            id: entryColumn
            width: tableView.viewport.width - visibilityColumn.width - shortcutColumn.width
            title: i18nc("Name of the system tray entry", "Entry")
            movable: false
            resizable: false

            delegate: QtLayouts.RowLayout {
                Item { // spacer
                    QtLayouts.Layout.preferredWidth: 1
                    QtLayouts.Layout.fillHeight: true
                }

                QIconItem {
                    width: units.iconSizes.small
                    height: width
                    icon: modelData.iconName || modelData.icon || ""
                }

                QtControls.Label {
                    QtLayouts.Layout.fillWidth: true
                    text: modelData.name
                    elide: Text.ElideRight
                    wrapMode: Text.NoWrap
                }
            }
        }

        QtControls.TableViewColumn {
            id: visibilityColumn
            title: i18n("Visibility")
            movable: false
            resizable: false

            delegate: QtControls.ComboBox {
                implicitWidth: Math.round(units.gridUnit * 6.5) // ComboBox sizing is broken

                enabled: !showAllCheckBox.checked
                currentIndex: {
                    if (cfg_shownItems.indexOf(modelData.taskId) != -1) {
                        return 1;
                    } else if (cfg_hiddenItems.indexOf(modelData.taskId) != -1) {
                        return 2;
                    } else {
                        return 0;
                    }
                }

                // activated, in contrast to currentIndexChanged, only fires if the user himself changed the value
                onActivated: {
                    var shownIndex = cfg_shownItems.indexOf(modelData.taskId);
                    var hiddenIndex = cfg_hiddenItems.indexOf(modelData.taskId);

                    switch (index) {
                    case 0: {
                        if (shownIndex > -1) {
                            cfg_shownItems.splice(shownIndex, 1);
                        }
                        if (hiddenIndex > -1) {
                            cfg_hiddenItems.splice(hiddenIndex, 1);
                        }
                        break;
                    }
                    case 1: {
                        if (shownIndex == -1) {
                            cfg_shownItems.push(modelData.taskId);
                        }
                        if (hiddenIndex > -1) {
                            cfg_hiddenItems.splice(hiddenIndex, 1);
                        }
                        break;
                    }
                    case 2: {
                        if (shownIndex > -1) {
                            cfg_shownItems.splice(shownIndex, 1);
                        }
                        if (hiddenIndex == -1) {
                            cfg_hiddenItems.push(modelData.taskId);
                        }
                        break;
                    }
                    }
                    iconsPage.configurationChanged();
                }
                model: [i18n("Auto"), i18n("Shown"), i18n("Hidden")]
            }
        }

        QtControls.TableViewColumn {
            id: shortcutColumn
            title: i18n("Keyboard Shortcut") // FIXME doesn't fit
            movable: false
            resizable: false

            // this Item wrapper prevents TableView from ripping apart the two KeySequenceItem buttons
            delegate: Item {
                implicitWidth: Math.max(shortcutColumnMeasureLabel.width, keySequenceItem.width) + 10
                height: keySequenceItem.height

                KQC.KeySequenceItem {
                    id: keySequenceItem
                    anchors.right: parent.right

                    keySequence: modelData.shortcut
                    // only Plasmoids have that
                    visible: modelData.hasOwnProperty("shortcut")
                    onKeySequenceChanged: {
                        if (keySequence != modelData.shortcut) {
                            // both SNIs and plasmoids are listed in the same TableView
                            // but they come from two separate models, so we need to subtract
                            // the SNI model count to get the actual plasmoid index
                            var index = modelData.index - plasmoid.rootItem.statusNotifierModel.count
                            plasmoid.applets[index].globalShortcut = keySequence

                            iconsPage.configurationChanged()
                        }

                        shortcutColumn.resizeToContents()
                    }
                }
            }
        }
    }
}