1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
|
import QtQuick 2.4
import Lomiri.Components 1.3
import Lomiri.OnlineAccounts 2.0
import QtQuick.LocalStorage 2.0
Page {
id: targetPage
property var db
/* Pass paramters */
property int targetID: 0
/* Required when creating a new record */
property int accountID: 0
/* Other parameters */
property string accountUser: ""
property string accountPassword: ""
property string accountRemoteAddress: ""
/* Account status */
property bool accountEnabled: false
property bool accountConfigured: false
// accounts may be not ready ...
property bool accountsLoaded: false
// remote browser could be open - only when credentials were obtained succesfully
property bool credentialsLoaded: false
property bool askForRemoteBrowser: false
function updateSymbol() {
if (accountEnabled === false) {
targetSymbol.color = owncloud.settings.color_targetAccountDisabled
accountSymbol.color = owncloud.settings.color_accountDisabled
accountStateDescription.text = i18n.tr("Account Disabled") + "\n(" + i18n.tr("target will NOT sync") + ")"
accountStateIcon.name = "dialog-warning-symbolic"
} else if (accountConfigured === false) {
accountName.text = i18n.tr("Account Not Configured")
targetSymbol.color = owncloud.settings.color_targetAccountDisabled
accountSymbol.color = owncloud.settings.color_accountEnabledNotConfigured
accountStateDescription.text = i18n.tr("Account Not Configured") + "\n(" + i18n.tr("target will NOT sync") + ")"
accountStateIcon.name = "dialog-warning-symbolic"
} else if (activeSwitch.checked === false) {
targetSymbol.color = owncloud.settings.color_targetInactive
accountSymbol.color = owncloud.settings.color_accountEnabled
accountStateDescription.text = i18n.tr("Target Disabled") + "\n(" + i18n.tr("target will NOT sync") + ")"
accountStateIcon.name = "dialog-warning-symbolic"
} else {
targetSymbol.color = owncloud.settings.color_targetActive
accountSymbol.color = owncloud.settings.color_accountEnabled
accountStateDescription.text = i18n.tr("Target Enabled") + "\n(" + i18n.tr("target will sync") + ")"
accountStateIcon.name = "info"
}
targetSymbolText.text = "" + targetName.text.charAt(0).toUpperCase()
accountSymbolText.text = "" + accountName.text.charAt(0).toUpperCase()
}
function loadDB() {
if (accounts.ready === false) {
return
} else {
accountsLoaded = true
}
targetPage.db = LocalStorage.openDatabaseSync("UBsync", "1.0", "UBsync", 1000000);
console.log("EditTarget :: Loading SyncTargets ID " + targetPage.targetID)
targetPage.db.transaction(
function(tx) {
// Create table if it doesn't already exist
//tx.executeSql('CREATE TABLE IF NOT EXISTS SyncTargets(targetID INTEGER PRIMARY KEY AUTOINCREMENT, accountID INTEGER, localPath TEXT, remotePath TEXT, targetName TEXT, active BOOLEAN)');
// load selected target
var rs = tx.executeSql('SELECT * FROM SyncTargets WHERE targetID = (?)', targetPage.targetID);
for(var i = 0; i < rs.rows.length; i++) {
targetPage.accountID = rs.rows.item(i).accountID
targetName.text = rs.rows.item(i).targetName
localPath.text = rs.rows.item(i).localPath
remotePath.text = rs.rows.item(i).remotePath
console.log("EditTarget :: Target Enabled: " + rs.rows.item(i).active)
activeSwitch.checked = rs.rows.item(i).active
}
}
)
targetPage.db.transaction(
function(tx) {
// load selected target
var rs = tx.executeSql('SELECT * FROM SyncAccounts WHERE accountID = (?)', targetPage.accountID);
if (rs.rows.length === 0) {
accountConfigured = false
} else {
accountConfigured = true
for(var i = 0; i < rs.rows.length; i++) {
accountName.text = rs.rows.item(i).accountName
targetPage.accountUser = rs.rows.item(i).remoteUser
targetPage.accountRemoteAddress = rs.rows.item(i).remoteAddress
}
}
}
)
// test if account is enabled in online accounts
targetPage.accountEnabled = false
for (var j = 0; j < accounts.count; j++) {
if (accounts.get(j, "account").accountId === targetPage.accountID) {
// account is enabled!
targetPage.accountEnabled = true
break
}
}
updateSymbol()
}
function updateDB() {
targetPage.db.transaction(
function(tx) {
var rs = tx.executeSql('SELECT * FROM SyncTargets WHERE targetID = (?)', targetPage.targetID);
if (rs.rows.length === 0) {
console.log("EditTarget :: Inserting SyncTargets ID " + targetPage.targetID)
tx.executeSql('INSERT INTO SyncTargets VALUES(NULL, (?), (?), (?), (?), 1, "")', [
targetPage.accountID,
localPath.text,
remotePath.text,
targetName.text]);
// load inserted ID
rs = tx.executeSql('SELECT * FROM SyncTargets');
targetPage.targetID = rs.rows.item(rs.rows.length - 1).targetID
targetIDText.text = "ID: " + targetPage.targetID
} else {
console.log("EditTarget :: Updating SyncTargets ID " + targetPage.targetID)
tx.executeSql('UPDATE SyncTargets SET accountID=(?), localPath=(?), remotePath=(?), targetName=(?), active=(?) WHERE targetID = (?)', [
targetPage.accountID,
localPath.text,
remotePath.text,
targetName.text,
activeSwitch.checked,
targetPage.targetID]);
}
}
)
}
AccountModel {
id: accounts
applicationId: "lomiri-cloudsync-app"
}
Timer {
// This timer checks if a accounts are ready
id: continuousCheck
interval: 250
running: true
repeat: true
onTriggered: {
// if accounts were not ready update again as soon as possible ...
if (accountsLoaded === false) {
targetPage.loadDB()
} else {
console.log("EditTarget :: Authenticate accountID: " + targetPage.accountID)
console.log("EditTarget :: - account CNT: " + accounts.count)
for (var j = 0; j < accounts.count; j++) {
//console.log("EditTarget :: - accountID: " + accounts.get(j, "account").accountId)
if (accounts.get(j, "account").accountId === targetPage.accountID) {
console.log("EditTarget :: Account auth to get password ... ")
accountConnection.target = accounts.get(j, "account")
credentialsLoaded = false // set to false until auth is finished
accounts.get(j, "account").authenticate({})
}
}
continuousCheck.repeat = false
}
}
}
Timer {
// This timer checks if credentials are ready to open remote browser
id: openRemoteBrowser
interval: 250
running: true
repeat: true
onTriggered: {
if (askForRemoteBrowser === true) {
// wait until credentials are not ready
if (credentialsLoaded === true) {
askForRemoteBrowser = false
apl.addPageToNextColumn(targetPage, Qt.resolvedUrl("WebdavFileBrowser.qml"), {caller:remotePath, paramUsername: targetPage.accountUser, paramPassword: targetPage.accountPassword, paramServerUrl: targetPage.accountRemoteAddress})
}
}
}
}
Connections {
id: accountConnection
target: null
onAuthenticationReply: {
var reply = authenticationData
if ("errorCode" in reply) {
console.warn("Authentication error: " + reply.errorText + " (" + reply.errorCode + ")")
// TODO: report an error to user ?
} else {
targetPage.accountUser = reply.Username
targetPage.accountPassword = reply.Password
credentialsLoaded = true
/* TODO: activate in debug mode? */
//console.log("EditTarget :: Account details are: " + reply.Username + ":" + reply.Password )
}
}
}
Connections {
target: targetPage
onActiveChanged: {
/* re-render anytime page is shown */
console.log("EditTarget :: editTargetPage activated")
targetPage.loadDB()
}
}
header: PageHeader {
id: header
title: i18n.tr("Target Settings")
flickable: flickable
trailingActionBar{
actions: [
Action {
iconName: "tick"
onTriggered: {
targetPage.updateDB();
apl.removePages(targetPage);
}
}
]
}
}
Flickable {
id: flickable
flickableDirection: Flickable.AutoFlickIfNeeded
anchors.fill: parent
contentHeight: accountEditColumn.height
Column {
id: accountEditColumn
spacing: units.gu(1.5)
anchors {
top: parent.top; left: parent.left; right: parent.right; margins: units.gu(2)
}
Item {
width: parent.width
height: targetSymbol.height
anchors.topMargin: units.gu(10)
Rectangle {
id: targetSymbol
color: "silver" /*"#0000B5"*/
width: units.gu(15)
height: units.gu(15)
border.width: 0
radius: units.gu(2)
anchors {
left: parent.left; top: parent.top
}
}
Label {
id: targetSymbolText
text: "U" /* Modified by Name change */
color: "white"
font.pixelSize: units.gu(10)
anchors {
horizontalCenter: targetSymbol.horizontalCenter; verticalCenter: targetSymbol.verticalCenter
}
}
TextEdit {
id: targetName
text: "New Target"
height: targetSymbol.height/3
color: targetIDText.color // inherit text color from the element following the system color theme
anchors.leftMargin: units.gu(2)
font.pixelSize: units.gu(3)
wrapMode: TextEdit.WrapAnywhere
inputMethodHints: Qt.ImhNoPredictiveText
width: parent.width - targetSymbol.width - targetNameEditIcon.width - units.gu(4)
anchors {
left: targetSymbol.right; top: targetSymbol.top
}
readOnly: true
}
Item {
width: targetNameEditIcon.width
height: targetNameEditIcon.height
anchors {
right: parent.right; top: targetSymbol.top
}
MouseArea {
width: targetNameEditIcon.width
height: targetNameEditIcon.height
onClicked: {
/* Init name editing */
if (targetName.readOnly === true) {
targetName.readOnly = false;
//targetName.selectAll()
targetName.forceActiveFocus()
targetName.cursorVisible = true
targetNameEditIcon.name = "ok"
targetName.cursorPosition = 0
console.log("EditTarget :: Change Name Start")
} else {
targetName.readOnly = true;
//targetName.deselect()
targetNameEditIcon.name = "edit"
console.log("EditTarget :: Change Name Finished: " + targetName.text)
targetSymbolText.text = "" + targetName.text.charAt(0).toUpperCase()
targetPage.updateDB()
targetPage.loadDB()
}
}
}
Icon {
id: targetNameEditIcon
name: "edit"
width: units.gu(4)
height: width
}
}
Label {
id: targetIDText
text: "ID: " + targetPage.targetID
anchors.leftMargin: units.gu(2)
anchors.topMargin: units.gu(1)
anchors.bottomMargin: units.gu(1)
font.pixelSize: units.gu(3)
anchors {
left: targetSymbol.right; bottom: targetSymbol.bottom
}
onTextChanged: {
// Invoke load DB
targetPage.loadDB()
}
}
}
Item {
width: parent.width
height: accountSymbol.height
MouseArea {
width: accountSymbol.width
height: accountSymbol.height
onClicked: {
console.log("EditTarget :: Edit Account")
apl.addPageToNextColumn(targetPage, Qt.resolvedUrl("EditAccount.qml"), {accountID: targetPage.accountID, isEditable: accountConfigured })
}
Rectangle {
id: accountSymbol
color: "silver" // "Unknown" color code
width: units.gu(6)
height: units.gu(6)
border.width: 0
radius: units.gu(0.9)
anchors {
left: parent.left; top: parent.top
}
}
Label {
id: accountSymbolText
text: "U" /* Modified by accountName change */
color: "white"
font.pixelSize: units.gu(4)
anchors {
horizontalCenter: accountSymbol.horizontalCenter; verticalCenter: accountSymbol.verticalCenter
}
}
Label {
id: accountName
text: i18n.tr("Unknown Account")
wrapMode: Text.WrapAnywhere
maximumLineCount: 2
width: parent.width - accountSymbol.width - units.gu(4)
anchors.leftMargin: units.gu(2)
font.pixelSize: units.gu(2)
anchors {
left: accountSymbol.right; verticalCenter: accountSymbol.verticalCenter
}
}
}
}
Item {
anchors.topMargin: units.gu(10)
width: parent.width
height: localIcon.height
MouseArea {
width: localIcon.width
height: localIcon.height
onClicked: {
console.log("EditTarget :: Change Local Folder")
apl.addPageToNextColumn(targetPage, Qt.resolvedUrl("LocalFileBrowser.qml"), {caller:localPath})
}
Icon {
id: localIcon
name: "folder-symbolic"
width: units.gu(6)
height: width
anchors {
left: parent.left; top: parent.top
}
}
Label {
id: localPath
text: ""
wrapMode: Text.WrapAnywhere
maximumLineCount: 2
//width: parent.width - localIcon.width - units.gu(10)
width: targetName.width + units.gu(12) /* TODO remove this hack - computing width from parent fails here ... why? */
anchors.leftMargin: units.gu(3)
anchors.verticalCenterOffset: 0
font.pixelSize: units.gu(2)
anchors {
left: localIcon.right; verticalCenter: localIcon.verticalCenter
}
onTextChanged: {
/* Invoke update DB */
targetPage.updateDB()
targetPage.loadDB()
}
}
}
}
Item {
anchors.topMargin: units.gu(10)
width: parent.width
height: remoteIcon.height
MouseArea {
width: remoteIcon.width
height: remoteIcon.height
onClicked: {
console.log("EditTarget :: Change Remote Folder")
askForRemoteBrowser = true
// apl.addPageToNextColumn(targetPage, Qt.resolvedUrl("WebdavFileBrowser.qml"), {caller:remotePath, paramUsername: targetPage.accountUser, paramPassword: targetPage.accountPassword, paramServerUrl: targetPage.accountRemoteAddress})
}
Icon {
id: remoteIcon
name: "network-server-symbolic"
width: units.gu(6)
height: width
anchors {
left: parent.left; top: parent.top
}
}
Label {
id: remotePath
text: ""
wrapMode: Text.WrapAnywhere
maximumLineCount: 2
//width: parent.width - remoteIcon.width - units.gu(10)
width: targetName.width + units.gu(12) /* TODO remove this hack - computing width from parent fails here ... why? */
anchors.leftMargin: units.gu(3)
anchors.verticalCenterOffset: 0
font.pixelSize: units.gu(2)
anchors {
left: remoteIcon.right; verticalCenter: remoteIcon.verticalCenter
}
onTextChanged: {
/* Invoke update DB */
targetPage.updateDB()
targetPage.loadDB()
}
}
}
}
Item {
id: mobileDataItem
anchors.topMargin: units.gu(10)
width: parent.width
height: mobileDataLabel.height
Label{
id: mobileDataLabel
font.pixelSize: units.gu(2)
anchors.topMargin: units.gu(2)
text: i18n.tr("Enable/Disable this Target")
anchors {
left: parent.left; top: parent.top
}
}
Switch{
id: activeSwitch
checked: null
anchors {
right: parent.right; verticalCenter: mobileDataLabel.verticalCenter
}
onCheckedChanged: {
/* Invoke update DB */
targetPage.updateDB()
targetPage.loadDB()
}
}
}
/* State information */
Item {
width: parent.width
height: 2 * warningIcon.height + units.gu(10)
Icon {
id: warningIcon
visible: !(serviceController.serviceRunning)
name: "dialog-warning-symbolic"
width: units.gu(6)
height: width
anchors {
left: parent.left
bottom: parent.bottom
}
}
Icon {
id: accountStateIcon
visible: (serviceController.serviceRunning)
name: "info"
width: units.gu(6)
height: width
anchors {
left: parent.left
bottom: parent.bottom
}
}
Label{
id: syncServiceStatus
visible: !(serviceController.serviceRunning)
font.pixelSize: units.gu(2)
width: parent.width - warningIcon.width - units.gu(4)
wrapMode: Text.WordWrap
text: serviceController.serviceRunning ? "" : i18n.tr("Synchronization service not running! Please, go to UBsync Settings and start the sync service, otherwise the target synchronization will not begin.")
anchors {
left: warningIcon.right; verticalCenter: warningIcon.verticalCenter
leftMargin: units.gu(2)
}
}
Label {
id: accountStateDescription
visible: (serviceController.serviceRunning)
text: ""
anchors.leftMargin: units.gu(2)
anchors.topMargin: units.gu(1)
font.pixelSize: units.gu(2)
anchors {
left: accountStateIcon.right; verticalCenter: accountStateIcon.verticalCenter
leftMargin: units.gu(2)
}
}
}
}
}
}
|