2
* This file is part of system-settings
4
* Copyright (C) 2014 Canonical Ltd.
6
* Contact: Pat McGowan <pat.mcgowan@canonical.com>
8
* This program is free software: you can redistribute it and/or modify it
9
* under the terms of the GNU General Public License version 3, as published
10
* by the Free Software Foundation.
12
* This program is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranties of
14
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
* PURPOSE. See the GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License along
18
* with this program. If not, see <http://www.gnu.org/licenses/>.
22
import QtQuick.Layouts 1.1
23
import SystemSettings 1.0
24
import Ubuntu.Components 1.1
25
import Ubuntu.Components.ListItems 1.0 as ListItem
28
objectName: "customapnPage"
31
// "internet" or "mms"
34
// dict of "type" : ctx
35
property var contexts;
37
/// work around LP(#1361919)
38
property var activateCb;
42
property var typeText : type === "internet" ? i18n.tr("Internet") : i18n.tr("MMS")
43
property bool isMms : type === "mms"
45
property bool isValid : false
47
function validateFields() {
48
if (apnName.text === "") {
53
if (mmsc.text === "") {
57
/// @todo validate proxy
58
/// @todo force port to be integer and validate it's value
66
//TRANSLATORS: %1 is either i18n.tr("Internet") or i18n.tr("MMS")
67
title: i18n.tr("Custom %1 APN").arg(d.typeText)
69
// workaround of getting the following error on startup:
70
// WARNING - ... : QML Page: Binding loop detected for property "flickable"
72
Component.onCompleted: {
73
flickable: scrollWidget
77
ctx = contexts["mms"];
78
if (ctx === undefined) {
83
ctx = contexts["internet"]
86
apnName.text = ctx.accessPointName;
87
userName.text = ctx.username;
88
pword.text = ctx.password;
89
mmsc.text = ctx.messageCenter;
90
var proxyText = ctx.messageProxy.split(":");
91
proxy.text = proxyText[0] !== undefined ? proxyText[0] : "";
92
port.text = proxyText[1] !== undefined ? proxyText[1] : "";
93
/// @todo protocol values
96
/// @todo disabled for now
97
doBoth.checked = false;
99
var internetApn = contexts["internet"]
100
if (ctx.accessPointName === internetApn.accessPointName &&
101
ctx.username == internetApn.username &&
102
ctx.password == internetApn.password
103
/* auth + procol */) {
104
doBoth.checked = true;
107
doBoth.checked = false;
117
bottom: parent.bottom
120
contentWidth: parent.width
122
contentHeight: theContents.height
123
boundsBehavior: (contentHeight > height) ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds
124
flickableDirection: Flickable.VerticalFlick
140
/// @todo disable for now
143
text: i18n.tr("Same APN as for Internet")
147
anchors.verticalCenter: parent.verticalCenter
150
var internetApn = contexts["internet"]
151
apnName.text = internetApn.accessPointName;
152
userName.text = internetApn.username;
153
pword.text = internetApn.password;
162
columnSpacing: units.gu(1)
163
rowSpacing: units.gu(1)
170
//TRANSLATORS: %1 is either i18n.tr("Internet") or i18n.tr("MMS")
171
text: i18n.tr("%1 APN").arg(d.typeText)
175
enabled: !doBoth.checked
176
onTextChanged: d.validateFields()
177
inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
181
text: i18n.tr("MMSC")
187
onTextChanged: d.validateFields()
188
inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
191
text: i18n.tr("Proxy")
197
onTextChanged: d.validateFields()
198
inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
208
onTextChanged: d.validateFields()
209
inputMethodHints: Qt.ImhDigitsOnly | Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
213
text: i18n.tr("Username")
217
enabled: !doBoth.checked
218
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
222
text: i18n.tr("Password")
226
enabled: !doBoth.checked
227
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
229
/// @todo support for ipv6 will be added after RTM
235
height: cancelButton.height + units.gu(2)
245
text: i18n.tr("Cancel")
249
right: parent.horizontalCenter
250
bottom: parent.bottom
251
topMargin: units.gu(1)
252
rightMargin: units.gu(1)
253
bottomMargin: units.gu(1)
264
text: d.isMms ? i18n.tr("Save") : i18n.tr("Activate")
267
left: parent.horizontalCenter
269
bottom: parent.bottom
270
topMargin: units.gu(1)
271
leftMargin: units.gu(1)
272
rightMargin: units.gu(4)
273
bottomMargin: units.gu(1)
281
ctx = contexts["mms"];
283
ctx = contexts["internet"];
285
/// @bug LP(:#1362795)
286
if (d.isMms && ctx === undefined) {
288
mmsData["accessPointName"] = apnName.text;
289
mmsData["username"] = userName.text;
290
mmsData["password"] = pword.text;
291
mmsData["messageCenter"] = mmsc.text
293
if (proxy.text !== "") {
294
proxyValue = proxy.text;
295
if (port.text !== "")
296
proxyValue = proxyValue + ":" + port.text;
298
mmsData["messageProxy"] = proxyValue;
299
activateCb("mms", undefined, mmsData);
304
ctx.accessPointName = apnName.text;
305
ctx.username = userName.text;
306
ctx.password = pword.text;
308
ctx.messageCenter = mmsc.text;
310
if (proxy.text !== "") {
311
proxyValue = proxy.text;
312
if (port.text !== "")
313
proxyValue = proxyValue + ":" + port.text;
315
ctx.messageProxy = proxyValue
317
/// @todo map protocol values
319
activateCb(ctx.type, ctx.contextPath);
323
} // item for buttons