2
import Ubuntu.Components 1.3
4
import Ubuntu.OnlineAccounts 2.0
6
import QtQuick.LocalStorage 2.0
15
property int targetID: 0
17
/* Required when creating a new record */
18
property int accountID: 0
20
/* Other parameters */
21
property string accountUser: ""
22
property string accountPassword: ""
23
property string accountRemoteAddress: ""
28
targetPage.db = LocalStorage.openDatabaseSync("UBsync", "1.0", "UBsync", 1000000);
30
console.log("Loading SyncTargets ID " + targetPage.targetID)
32
targetPage.db.transaction(
34
// Create table if it doesn't already exist
35
tx.executeSql('CREATE TABLE IF NOT EXISTS SyncTargets(targetID INTEGER PRIMARY KEY AUTOINCREMENT, accountID INTEGER, localPath TEXT, remotePath TEXT, targetName TEXT, active BOOLEAN)');
37
// load selected target
38
var rs = tx.executeSql('SELECT * FROM SyncTargets WHERE targetID = (?)', targetPage.targetID);
40
for(var i = 0; i < rs.rows.length; i++) {
41
targetPage.accountID = rs.rows.item(i).accountID
43
targetName.text = rs.rows.item(i).targetName
45
localPath.text = rs.rows.item(i).localPath
46
remotePath.text = rs.rows.item(i).remotePath
48
console.log("Target Enabled: " + rs.rows.item(i).active)
49
activeSwitch.checked = rs.rows.item(i).active
54
targetPage.db.transaction(
56
// load selected target
57
var rs = tx.executeSql('SELECT * FROM SyncAccounts WHERE accountID = (?)', targetPage.accountID);
59
for(var i = 0; i < rs.rows.length; i++) {
60
accountName.text = rs.rows.item(i).accountName
62
targetPage.accountUser = rs.rows.item(i).remoteUser
63
targetPage.accountRemoteAddress = rs.rows.item(i).remoteAddress
70
targetPage.db.transaction(
73
var rs = tx.executeSql('SELECT * FROM SyncTargets WHERE targetID = (?)', targetPage.targetID);
75
if (rs.rows.length === 0) {
76
console.log("Inserting SyncTargets ID " + targetPage.targetID)
77
tx.executeSql('INSERT INTO SyncTargets VALUES(NULL, (?), (?), (?), (?), 1)', [
84
rs = tx.executeSql('SELECT * FROM SyncTargets');
85
targetPage.targetID = rs.rows.item(rs.rows.length - 1).targetID
87
targetIDText.text = "ID: " + targetPage.targetID
90
console.log("Updating SyncTargets ID " + targetPage.targetID)
91
tx.executeSql('UPDATE SyncTargets SET accountID=(?), localPath=(?), remotePath=(?), targetName=(?), active=(?) WHERE targetID = (?)', [
97
targetPage.targetID]);
105
applicationId: "ubsyncdev_UBsyncDEV"
110
id: accountConnection
113
onAuthenticationReply: {
114
var reply = authenticationData
116
if ("errorCode" in reply) {
117
console.warn("Authentication error: " + reply.errorText + " (" + reply.errorCode + ")")
118
// TODO: report an error to user ?
121
targetPage.accountUser = reply.Username
122
targetPage.accountPassword = reply.Password
123
/* TODO: activate in debug mode? */
124
//console.log("Account details are: " + reply.Username + ":" + reply.Password )
134
for (var j = 0; j < accounts.count; j++) {
135
if (accounts.get(j, "account").accountId === targetPage.accountID) {
136
console.log("Account auth to get password ... ")
137
accountConnection.target = accounts.get(j, "account")
138
accounts.get(j, "account").authenticate({})
144
/* re-render anytime page is shown */
145
console.log("editTargetPage activated")
146
targetPage.loadDB(targetPage.accountID)
147
targetPage.updateDB(targetPage.accountID)
149
console.log("Authenticat accountID: " + targetPage.accountID)
150
console.log(" - account CNT: " + accounts.count)
152
for (var j = 0; j < accounts.count; j++) {
153
console.log(" - accountID: " + accounts.get(j, "account").accountId)
154
if (accounts.get(j, "account").accountId === targetPage.accountID) {
155
console.log("Account auth to get password ... ")
156
accountConnection.target = accounts.get(j, "account")
157
accounts.get(j, "account").authenticate({})
166
title: i18n.tr("Account Settings")
179
contentHeight: accountEditColumn.height
182
id: accountEditColumn
184
spacing: units.gu(1.5)
186
top: parent.top; left: parent.left; right: parent.right; margins: units.gu(2)
191
height: targetSymbol.height
192
anchors.topMargin: units.gu(10)
196
color: "silver" /*"#0000B5"*/
202
left: parent.left; top: parent.top
208
text: "U" /* Modified by Name change */
210
font.pixelSize: units.gu(10)
212
horizontalCenter: targetSymbol.horizontalCenter; verticalCenter: targetSymbol.verticalCenter
220
anchors.leftMargin: units.gu(2)
221
font.pixelSize: units.gu(3)
223
left: targetSymbol.right; top: targetSymbol.top
226
targetSymbolText.text = "" + text.charAt(0).toUpperCase()
227
/* Invoke update DB */
228
targetPage.updateDB()
234
text: "ID: " + targetPage.targetID
235
anchors.leftMargin: units.gu(2)
236
anchors.topMargin: units.gu(1)
237
font.pixelSize: units.gu(3)
239
left: targetSymbol.right; top: targetName.bottom
251
height: accountSymbol.height
255
color: "steelblue" /*"#0000B5"*/
259
radius: units.gu(0.9)
261
left: parent.left; top: parent.top
266
id: accountSymbolText
267
text: "U" /* Modified by accountName change */
269
font.pixelSize: units.gu(4)
271
horizontalCenter: accountSymbol.horizontalCenter; verticalCenter: accountSymbol.verticalCenter
278
text: "Unknown Account"
279
anchors.leftMargin: units.gu(2)
280
font.pixelSize: units.gu(2)
282
left: accountSymbol.right; verticalCenter: accountSymbol.verticalCenter
285
accountSymbolText.text = "" + text.charAt(0).toUpperCase()
286
/* Invoke update DB */
287
targetPage.updateDB()
294
anchors.topMargin: units.gu(10)
296
height: localIcon.height
300
width: localIcon.width
301
height: localIcon.height
304
console.log("Change Local Folder")
305
apl.addPageToNextColumn(targetPage, Qt.resolvedUrl("LocalFileBrowser.qml"), {caller:localPath})
309
name: "folder-symbolic"
313
left: parent.left; top: parent.top
320
anchors.leftMargin: units.gu(3)
321
anchors.verticalCenterOffset: 0
322
font.pixelSize: units.gu(2)
324
left: localIcon.right; verticalCenter: localIcon.verticalCenter
327
/* Invoke update DB */
328
targetPage.updateDB()
337
anchors.topMargin: units.gu(10)
339
height: remoteIcon.height
343
width: remoteIcon.width
344
height: remoteIcon.height
347
console.log("Change Remote Folder")
348
apl.addPageToNextColumn(targetPage, Qt.resolvedUrl("WebdavFileBrowser.qml"), {caller:remotePath, paramUsername: targetPage.accountUser, paramPassword: targetPage.accountPassword, paramServerUrl: targetPage.accountRemoteAddress})
352
name: "network-server-symbolic"
356
left: parent.left; top: parent.top
363
anchors.leftMargin: units.gu(3)
364
anchors.verticalCenterOffset: 0
365
font.pixelSize: units.gu(2)
367
left: remoteIcon.right; verticalCenter: remoteIcon.verticalCenter
370
/* Invoke update DB */
371
targetPage.updateDB()
380
anchors.topMargin: units.gu(10)
382
height: mobileDataLabel.height
386
font.pixelSize: units.gu(2)
387
anchors.topMargin: units.gu(2)
388
text: i18n.tr("Enable/Disable this Target")
390
left: parent.left; top: parent.top
398
right: parent.right; verticalCenter: mobileDataLabel.verticalCenter
401
/* Invoke update DB */
402
targetPage.updateDB()
403
/* Change activity indication color */
404
if (activeSwitch.checked == true) {
405
targetSymbol.color = "orange"
407
targetSymbol.color = "silver"