2
import Ubuntu.Components 1.3
3
import Ubuntu.OnlineAccounts 0.1
8
readonly property string keyPrefix: "telepathy/"
9
readonly property var accountObjectHandle: account ? account.objectHandle : undefined
10
readonly property alias isValid: paramsRepeater.fieldHasValues
12
property string manager
13
property string protocol
16
property var advancedParams
17
property bool hasCrendentials: true
21
height: fields.childrenRect.height +
24
function getAccountService() {
25
var service = serviceModel.get(0, "accountServiceHandle")
27
console.warn("No service handle from model")
31
return accountServiceComponent.createObject(null,
32
{"objectHandle": service})
36
function extendedSettings(inputFields)
39
//Helper class to be extended by derived class
43
function formatDisplayName(inputFields)
45
return inputFields['account']
46
// Helper function that allow the derived class to format a different display name
49
function saveServiceSettings(serviceIM, creds) {
50
var settingsIM = serviceIM.settings
53
settingsIM[root.keyPrefix + 'manager'] = root.manager
54
settingsIM[root.keyPrefix + 'protocol'] = root.protocol
55
settingsIM[root.keyPrefix + 'Icon'] = root.icon
58
for (var i=0; i < paramsRepeater.count; i++) {
59
var fieldData = root.params[i]
60
var field = paramsRepeater.itemAt(i)
61
var fieldParamName = root.keyPrefix + 'param-' + fieldData.name
64
delete settingsIM[fieldParamName]
66
inputFields[fieldData.name] = field.value
67
if (fieldData.store) {
68
settingsIM[fieldParamName] = field.value
74
for (var i=0; i < advancedParamsRepeater.count; i++) {
75
var xFieldData = root.advancedParams[i]
76
var xField = advancedParamsRepeater.itemAt(i)
77
var xFieldParamName = root.keyPrefix + 'param-' + xFieldData.name
80
delete settingsIM[xFieldParamName]
82
inputFields[xFieldData.name] = xField.value
84
if (xFieldData.store) {
85
settingsIM[xFieldParamName] = xField.value
91
var xSettings = extendedSettings(inputFields)
92
for (var key in xSettings) {
93
settingsIM[root.keyPrefix + key] = xSettings[key]
96
account.updateDisplayName(formatDisplayName(inputFields))
98
serviceIM.updateSettings(settingsIM)
99
//serviceIM.credentials = creds
100
//serviceIM.updateServiceEnabled(true)
103
function continueAccountSave(creds) {
104
var imService = root.getAccountService()
106
console.warn("Fail to retrieve account service")
110
root.saveServiceSettings(imService, creds)
112
globalAccountService.credentials = creds
113
globalAccountService.updateServiceEnabled(true)
115
account.synced.connect(root.finished)
119
function credentialsStored() {
120
if (creds.credentialsId === 0) {
121
console.warn("Credentials not stored correct")
125
var imService = root.getAccountService()
127
console.warn("Fail to retrieve account service")
131
continueAccountSave(creds)
134
function parseCrendentials() {
135
var credentials = {'userName': '', 'password': ''}
137
for (var i=0; i < paramsRepeater.count; i++) {
138
var fieldData = root.params[i]
139
var field = paramsRepeater.itemAt(i)
141
if (fieldData.name === 'account')
142
credentials['userName'] = field.value
144
if (fieldData.name === 'password')
145
credentials['password'] = field.value
152
account.removed.connect(root.finished)
153
account.remove(Account.RemoveCredentials)
157
var info = root.parseCrendentials()
159
account.updateDisplayName(info.userName)
160
if (root.hasCrendentials) {
161
creds.userName = info.userName
162
creds.secret = info.password
165
continueAccountSave(null)
174
topMargin: units.gu(5)
178
height: childrenRect.height
182
anchors.horizontalCenter: fields.horizontalCenter
189
property bool fieldHasValues: false
191
function checkFieldsHasValues()
193
var hasEmptyField = false
194
for (var i = 0; i < paramsRepeater.count; i++) {
196
var child = paramsRepeater.itemAt(i)
197
if (child && child.isEmpty) {
202
fieldHasValues = !hasEmptyField
214
onValueChanged: paramsRepeater.checkFieldsHasValues()
226
visible: root.advancedParams.length > 0
230
id: advancedParamsTitle
237
visible: root.advancedParams.length > 0
238
text: i18n.tr("Advanced Options")
239
textSize: Label.Medium
243
id: advancedParamsRepeater
246
model: root.advancedParams
259
id: globalAccountService
261
objectHandle: account.accountServiceHandle
268
caption: account.provider.id
269
acl: "*" // untill later
271
onCredentialsIdChanged: {
272
console.debug("Credetials id changed")
273
root.credentialsStored()
277
// necessary to store settings on the "IM" service
278
AccountServiceModel {
281
includeDisabled: true
282
account: root.accountObjectHandle
287
id: accountServiceComponent