Differential D28487 Diff 79120 applets/systemmonitor/systemmonitor/package/contents/ui/config/SaveDialog.qml
Changeset View
Changeset View
Standalone View
Standalone View
applets/systemmonitor/systemmonitor/package/contents/ui/config/SaveDialog.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2019 Marco Martin <mart@kde.org> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU Library General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Library General Public | ||||
15 | * License along with this program; if not, write to the | ||||
16 | * Free Software Foundation, Inc., | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | import QtQuick 2.3 | ||||
21 | import QtQuick.Layouts 1.1 | ||||
22 | import QtQuick.Controls 2.2 | ||||
23 | import QtQuick.Dialogs 1.2 | ||||
24 | import org.kde.kirigami 2.8 as Kirigami | ||||
25 | import org.kde.plasma.plasmoid 2.0 | ||||
26 | | ||||
27 | Dialog { | ||||
28 | id: dialog | ||||
29 | property alias pluginName: pluginNameField.text | ||||
30 | property alias comment: commentField.text | ||||
31 | property alias author: authorField.text | ||||
32 | property alias email: emailField.text | ||||
33 | property alias license: licenseField.editText | ||||
34 | property alias website: websiteField.text | ||||
35 | | ||||
36 | property bool canEdit: false | ||||
37 | | ||||
38 | width: 500 | ||||
39 | title: i18n("Save Preset %1", plasmoid.configuration.title) | ||||
40 | | ||||
41 | onVisibleChanged: { | ||||
42 | pluginNameField.focus = true | ||||
43 | } | ||||
44 | | ||||
45 | contentItem: Rectangle { | ||||
46 | implicitWidth: layout.Layout.minimumWidth + units.smallSpacing*2 | ||||
47 | implicitHeight: layout.Layout.minimumHeight + units.smallSpacing*2 | ||||
48 | | ||||
49 | Keys.onPressed: { | ||||
50 | if (event.key == Qt.Key_Enter || event.key == Qt.Key_Return) { | ||||
51 | dialog.accept(); | ||||
52 | } else if (event.key == Qt.Key_Escape) { | ||||
53 | dialog.reject(); | ||||
54 | } | ||||
55 | } | ||||
56 | | ||||
57 | color: Kirigami.Theme.backgroundColor | ||||
58 | | ||||
59 | ColumnLayout { | ||||
60 | id: layout | ||||
61 | anchors { | ||||
62 | fill: parent | ||||
63 | margins: units.smallSpacing | ||||
64 | } | ||||
65 | Kirigami.InlineMessage { //standard comp | ||||
66 | id: errorMessage | ||||
67 | type: Kirigami.MessageType.Error | ||||
68 | text: "" | ||||
69 | Layout.fillWidth: true | ||||
70 | visible: text.length > 0 | ||||
71 | } | ||||
72 | Kirigami.FormLayout { | ||||
73 | Layout.fillWidth: true | ||||
74 | | ||||
75 | TextField { | ||||
76 | id: pluginNameField | ||||
77 | Layout.fillWidth: true | ||||
78 | Kirigami.FormData.label: i18n("Theme Plugin Name:") | ||||
79 | onTextChanged: { | ||||
80 | var presetsModel = plasmoid.nativeInterface.availablePresetsModel; | ||||
81 | for (var i = 0; i < plasmoid.nativeInterface.availablePresetsModel.rowCount(); ++i) { | ||||
82 | var idx = presetsModel.index(i, 0); | ||||
83 | if (pluginNameField.text == presetsModel.data(idx, Qt.UserRole + 1)) { // FIXME proper enum | ||||
84 | dialog.canEdit = false; | ||||
85 | errorMessage.text = i18n("This theme plugin name already exists"); | ||||
86 | return; | ||||
87 | } | ||||
88 | } | ||||
89 | errorMessage.text = ""; | ||||
90 | dialog.canEdit = true; | ||||
91 | } | ||||
92 | } | ||||
93 | TextField { | ||||
94 | id: commentField | ||||
95 | Kirigami.FormData.label: i18n("Comment:") | ||||
96 | Layout.fillWidth: true | ||||
97 | } | ||||
98 | TextField { | ||||
99 | id: authorField | ||||
100 | Kirigami.FormData.label: i18n("Author:") | ||||
101 | Layout.fillWidth: true | ||||
102 | } | ||||
103 | TextField { | ||||
104 | id: emailField | ||||
105 | Kirigami.FormData.label: i18n("Email:") | ||||
106 | Layout.fillWidth: true | ||||
107 | } | ||||
108 | ComboBox { | ||||
109 | id: licenseField | ||||
110 | Kirigami.FormData.label: i18n("License:") | ||||
111 | Layout.fillWidth: true | ||||
112 | editable: true | ||||
113 | editText: "LGPL 2.1+" | ||||
114 | model: ["LGPL 2.1+", "GPL 2+", "GPL 3+", "LGPL 3+", "BSD"] | ||||
115 | } | ||||
116 | TextField { | ||||
117 | id: websiteField | ||||
118 | Kirigami.FormData.label: i18n("Website:") | ||||
119 | Layout.fillWidth: true | ||||
120 | } | ||||
121 | } | ||||
122 | Item { | ||||
123 | Layout.fillHeight: true | ||||
124 | } | ||||
125 | RowLayout { | ||||
126 | Layout.alignment: Qt.AlignRight | ||||
127 | Button { | ||||
128 | text: i18n("OK") | ||||
129 | onClicked: dialog.accept() | ||||
130 | enabled: canEdit && authorField.text && emailField.text && websiteField.text | ||||
131 | } | ||||
132 | Button { | ||||
133 | text: i18n("Cancel") | ||||
134 | onClicked: dialog.reject() | ||||
135 | } | ||||
136 | } | ||||
137 | } | ||||
138 | } | ||||
139 | | ||||
140 | onAccepted: { | ||||
141 | plasmoid.nativeInterface.createNewPreset(pluginNameField.text, commentField.text, authorField.text, emailField.text, licenseField.editText, websiteField.text); | ||||
142 | } | ||||
143 | } |