Unity 8
 All Classes Functions
NotificationMenuItemFactory.qml
1 /*
2  * Copyright 2013 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  *
16  * Authors:
17  * Nick Dedekind <nick.dedekind@canonical.com>
18  */
19 
20 import QtQuick 2.0
21 import Ubuntu.Components 0.1
22 import QMenuModel 0.1
23 import "../Components"
24 
25 Loader {
26  id: menuFactory
27 
28  property QtObject menuModel: null
29  property QtObject menuData: null
30  property int menuIndex : -1
31  property int maxHeight
32  readonly property bool fullscreen: menuData.type === "com.canonical.snapdecision.pinlock"
33 
34  signal accepted()
35 
36  property var _map: {
37  "com.canonical.snapdecision.textfield": textfield,
38  "com.canonical.snapdecision.pinlock" : pinLock,
39  }
40 
41  sourceComponent: {
42  if (menuData.type !== undefined) {
43  var component = _map[menuData.type];
44  if (component !== undefined) {
45  return component;
46  }
47  }
48  }
49 
50  function getExtendedProperty(object, propertyName, defaultValue) {
51  if (object && object.hasOwnProperty(propertyName)) {
52  return object[propertyName];
53  }
54  return defaultValue;
55  }
56 
57  Component {
58  id: textfield
59 
60  Column {
61  spacing: units.gu(2)
62 
63  anchors {
64  left: parent.left
65  right: parent.right
66  margins: spacing
67  }
68 
69  Component.onCompleted: {
70  menuModel.loadExtendedAttributes(menuIndex, {"x-echo-mode-password": "bool"});
71  checkBox.checked = menuData.ext.xEchoModePassword ? false : true
72  checkBoxRow.visible = menuData.ext.xEchoModePassword
73  }
74 
75  Label {
76  text: menuData.label
77  color: notification.sdFontColor
78  }
79 
80  TextField {
81  id: textfield
82 
83  // TODO using Qt.ImhNoPredictiveText here until lp #1291575 is fixed for ubuntu-ui-toolkit
84  inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
85  anchors {
86  left: parent.left
87  right: parent.right
88  }
89  echoMode: checkBox.checked ? TextInput.Normal : TextInput.Password
90  height: units.gu(5)
91  Component.onCompleted: {
92  forceActiveFocus();
93  }
94  onTextChanged: {
95  menuModel.changeState(menuIndex, text);
96  }
97  onAccepted: {
98  menuFactory.accepted()
99  }
100  }
101 
102  Row {
103  id: checkBoxRow
104 
105  spacing: units.gu(.5)
106 
107  CheckBox {
108  id: checkBox
109 
110  checked: false
111  activeFocusOnPress: false
112  }
113 
114  Label {
115  anchors.verticalCenter: checkBox.verticalCenter
116  text: i18n.tr("Show password")
117  color: notification.sdFontColor
118  }
119  }
120  }
121  }
122 
123  Component {
124  id: pinLock
125 
126  Lockscreen {
127  anchors {
128  left: parent.left
129  right: parent.right
130  }
131  height: menuFactory.maxHeight
132  infoText: notification.summary
133  errorText: errorAction.valid ? errorAction.state : ""
134  retryText: notification.body
135  background: shell.background
136 
137  onEntered: {
138  menuModel.changeState(menuIndex, passphrase);
139  clear(false);
140  }
141 
142  onCancel: {
143  menuModel.activate(menuIndex, false);
144  }
145 
146  onEmergencyCall: {
147  shell.activateApplication("dialer-app")
148  menuModel.activate(menuIndex, false)
149  }
150 
151  property var extendedData: menuData && menuData.ext || undefined
152 
153  property var pinMinMaxAction : UnityMenuAction {
154  model: menuModel
155  index: menuIndex
156  name: getExtendedProperty(extendedData, "xCanonicalPinMinMax", "")
157 
158  onStateChanged: {
159  var min = pinMinMaxAction.state[0];
160  var max = pinMinMaxAction.state[1];
161 
162  if (min === 0) min = -1;
163  if (max === 0) max = -1;
164 
165  minPinLength = min
166  maxPinLength = max
167  }
168  }
169 
170  property var popupAction: UnityMenuAction {
171  model: menuModel
172  index: menuIndex
173  name: getExtendedProperty(extendedData, "xCanonicalPinPopup", "")
174  onStateChanged: {
175  if (state !== "")
176  showInfoPopup("", state);
177  }
178  }
179  onInfoPopupConfirmed: {
180  popupAction.activate();
181  }
182 
183  Timer {
184  id: errorTimer
185  interval: 4000;
186  running: false;
187  repeat: false
188  onTriggered: {
189  errorAction.activate();
190  }
191  }
192  property var errorAction: UnityMenuAction {
193  model: menuModel
194  index: menuIndex
195  name: getExtendedProperty(extendedData, "xCanonicalPinError", "")
196  onStateChanged: {
197  errorText = state;
198  if (state !== "") {
199  clear(true);
200  errorTimer.running = true;
201  }
202  }
203  }
204 
205  function loadAttributes() {
206  if (!menuModel || menuIndex == -1) return;
207  menuModel.loadExtendedAttributes(menuIndex, {'x-canonical-pin-min-max': 'string',
208  'x-canonical-pin-popup': 'string',
209  'x-canonical-pin-error': 'string'});
210  }
211  Component.onCompleted: {
212  loadAttributes();
213  }
214  }
215  }
216 }