on d45fc13 help sign in
unity8/qml/Notifications/NotificationMenuItemFactory.qml
231 lines 7.9 kB history raw
1/*
2 * Copyright 2013-2016 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17import QtQuick 2.4
18import Ubuntu.Components 1.3
19import QMenuModel 0.1
20import "../Components"
22Loader {
23 id: menuFactory
25 property QtObject menuModel: null
26 property QtObject menuData: null
27 property int menuIndex : -1
28 property int maxHeight
29 readonly property bool fullscreen: menuData.type === "com.canonical.snapdecision.pinlock"
30 property url background: ""
32 signal accepted()
34 property var _map: {
35 "com.canonical.snapdecision.textfield": textfield,
36 "com.canonical.snapdecision.pinlock" : pinLock,
37 }
39 sourceComponent: {
40 if (menuData.type !== undefined) {
41 var component = _map[menuData.type];
42 if (component !== undefined) {
43 if (component === pinLock && shell.hasLockedApp) {
44 // In case we are in emergency mode, just skip this unlock.
45 // Happens with two locked SIMs but the user clicks
46 // Emergency Call on the first unlock dialog.
47 // TODO: if we ever allow showing the indicators in
48 // emergency mode, we'll need to differentiate between
49 // user-initiated ones which we *do* want to show and the
50 // dialogs that appear on boot, which we don't. But for
51 // now we can get away with skipping all such dialogs.
52 menuModel.activate(menuIndex, false);
53 return null;
54 }
55 return component;
56 }
57 }
58 }
60 function getExtendedProperty(object, propertyName, defaultValue) {
61 if (object && object.hasOwnProperty(propertyName)) {
62 return object[propertyName];
63 }
64 return defaultValue;
65 }
67 Component {
68 id: textfield
70 Column {
71 spacing: notification.margins
73 anchors {
74 left: parent.left
75 right: parent.right
76 margins: spacing
77 }
79 Component.onCompleted: {
80 menuModel.loadExtendedAttributes(menuIndex, {"x-echo-mode-password": "bool"});
81 checkBox.checked = menuData.ext.xEchoModePassword ? false : true
82 checkBoxRow.visible = menuData.ext.xEchoModePassword
83 }
85 Label {
86 text: menuData.label
87 color: theme.palette.normal.backgroundSecondaryText
88 }
90 TextField {
91 // TODO using Qt.ImhNoPredictiveText here until lp #1291575 is fixed for ubuntu-ui-toolkit
92 inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
93 anchors {
94 left: parent.left
95 right: parent.right
96 }
97 echoMode: checkBox.checked ? TextInput.Normal : TextInput.Password
98 height: units.gu(5)
99 Component.onCompleted: {
100 print("forcing active focus on notification!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11111")
101 forceActiveFocus();
102 }
103 onTextChanged: {
104 menuModel.changeState(menuIndex, text);
105 }
106 onAccepted: {
107 menuFactory.accepted()
108 }
109 }
111 Row {
112 id: checkBoxRow
114 spacing: notification.margins
116 CheckBox {
117 id: checkBox
119 checked: false
120 activeFocusOnPress: false
121 }
123 Label {
124 anchors.verticalCenter: checkBox.verticalCenter
125 text: i18n.tr("Show password")
126 color: theme.palette.normal.backgroundSecondaryText
128 MouseArea {
129 anchors.fill: parent
130 onClicked: { checkBox.checked = !checkBox.checked }
131 }
132 }
133 }
134 }
135 }
137 Component {
138 id: pinLock
140 Lockscreen {
141 anchors {
142 left: parent.left
143 right: parent.right
144 }
145 height: menuFactory.maxHeight
146 infoText: notification.summary
147 errorText: errorAction.valid ? errorAction.state : ""
148 retryText: notification.body
149 background: menuFactory.background
150 darkenBackground: 0.4
152 onEntered: {
153 menuModel.changeState(menuIndex, passphrase);
154 clear(false);
155 }
157 onCancel: {
158 menuModel.activate(menuIndex, false);
159 }
161 onEmergencyCall: {
162 shell.startLockedApp("dialer-app");
163 menuModel.activate(menuIndex, false);
164 }
166 property var extendedData: menuData && menuData.ext || undefined
168 property var pinMinMaxAction : UnityMenuAction {
169 model: menuModel
170 index: menuIndex
171 name: getExtendedProperty(extendedData, "xCanonicalPinMinMax", "")
173 onStateChanged: {
174 var min = pinMinMaxAction.state[0];
175 var max = pinMinMaxAction.state[1];
177 if (min === 0) min = -1;
178 if (max === 0) max = -1;
180 minPinLength = min
181 maxPinLength = max
182 }
183 }
185 property var popupAction: UnityMenuAction {
186 model: menuModel
187 index: menuIndex
188 name: getExtendedProperty(extendedData, "xCanonicalPinPopup", "")
189 onStateChanged: {
190 if (state !== "")
191 showInfoPopup("", state);
192 }
193 }
194 onInfoPopupConfirmed: {
195 popupAction.activate();
196 }
198 Timer {
199 id: errorTimer
200 interval: 4000;
201 running: false;
202 repeat: false
203 onTriggered: {
204 errorAction.activate();
205 }
206 }
207 property var errorAction: UnityMenuAction {
208 model: menuModel
209 index: menuIndex
210 name: getExtendedProperty(extendedData, "xCanonicalPinError", "")
211 onStateChanged: {
212 errorText = state;
213 if (state !== "") {
214 clear(true);
215 errorTimer.running = true;
216 }
217 }
218 }
220 function loadAttributes() {
221 if (!menuModel || menuIndex == -1) return;
222 menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-pin-min-max': 'string',
223 'x-canonical-pin-popup': 'string',
224 'x-canonical-pin-error': 'string'});
225 }
226 Component.onCompleted: {
227 loadAttributes();
228 }
229 }
230 }