Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 by Savoir-faire Linux |
| 3 | * Author: Yang Wang <yang.wang@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | import QtQuick 2.15 |
| 20 | import QtQuick.Controls 2.14 |
| 21 | import QtQuick.Layouts 1.14 |
| 22 | import QtQuick.Controls.Styles 1.4 |
| 23 | import net.jami.Models 1.0 |
| 24 | |
| 25 | import "../../commoncomponents" |
| 26 | |
| 27 | Dialog { |
| 28 | id: nameRegistrationDialog |
| 29 | |
| 30 | property string registerdName : "" |
| 31 | |
| 32 | function openNameRegistrationDialog(registerNameIn){ |
| 33 | registerdName = registerNameIn |
| 34 | lblRegistrationError.text = qsTr("Something went wrong") |
| 35 | passwordEdit.clear() |
| 36 | if(ClientWrapper.accountAdaptor.hasPassword()){ |
| 37 | stackedWidget.currentIndex = 0 |
| 38 | } else { |
| 39 | startRegistration() |
| 40 | } |
| 41 | |
| 42 | nameRegistrationDialog.open() |
| 43 | } |
| 44 | |
| 45 | function startRegistration(){ |
| 46 | startSpinner() |
| 47 | timerForStartRegistration.restart() |
| 48 | } |
| 49 | |
| 50 | function slotStartNameRegistration(){ |
| 51 | var password = passwordEdit.text |
| 52 | ClientWrapper.accountModel.registerName(ClientWrapper.utilsAdaptor.getCurrAccId(), password, registerdName) |
| 53 | } |
| 54 | |
| 55 | function startSpinner(){ |
| 56 | stackedWidget.currentIndex = 1 |
| 57 | spinnerLabel.visible = true |
| 58 | spinnerMovie.playing = true |
| 59 | } |
| 60 | |
| 61 | Timer{ |
| 62 | id: timerForStartRegistration |
| 63 | |
| 64 | interval: 100 |
| 65 | repeat: false |
| 66 | |
| 67 | onTriggered: { |
| 68 | slotStartNameRegistration() |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | Connections{ |
| 73 | target: ClientWrapper.nameDirectory |
| 74 | |
| 75 | function onNameRegistrationEnded(status, name){ |
| 76 | if(status === NameDirectory.RegisterNameStatus.SUCCESS){ |
| 77 | accept() |
| 78 | } else { |
| 79 | switch(status){ |
| 80 | case NameDirectory.RegisterNameStatus.WRONG_PASSWORD: |
| 81 | lblRegistrationError.text = qsTr("Incorrect password") |
| 82 | break |
| 83 | |
| 84 | case NameDirectory.RegisterNameStatus.NETWORK_ERROR: |
| 85 | lblRegistrationError.text = qsTr("Network error") |
| 86 | break |
| 87 | default: |
| 88 | break |
| 89 | } |
| 90 | stackedWidget.currentIndex = 2 |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | visible: false |
| 96 | |
| 97 | anchors.centerIn: parent.Center |
| 98 | x: (parent.width - width) / 2 |
| 99 | y: (parent.height - height) / 2 |
| 100 | |
| 101 | title: qsTr("Set Registered Name") |
| 102 | |
| 103 | onClosed: { |
| 104 | reject() |
| 105 | } |
| 106 | |
| 107 | contentItem: Rectangle{ |
| 108 | implicitWidth: 365 |
| 109 | implicitHeight: 208 |
| 110 | |
| 111 | StackLayout{ |
| 112 | id: stackedWidget |
| 113 | anchors.fill: parent |
| 114 | |
| 115 | currentIndex: 0 |
| 116 | |
| 117 | Rectangle{ |
| 118 | id: passwordConfirmPage |
| 119 | |
| 120 | Layout.fillWidth: true |
| 121 | Layout.fillHeight: true |
| 122 | |
| 123 | Layout.leftMargin: 11 |
| 124 | Layout.rightMargin: 11 |
| 125 | Layout.topMargin: 11 |
| 126 | Layout.bottomMargin: 11 |
| 127 | |
| 128 | ColumnLayout{ |
| 129 | anchors.fill: parent |
| 130 | spacing: 7 |
| 131 | |
| 132 | Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter |
| 133 | |
| 134 | Item{ |
| 135 | Layout.alignment: Qt.AlignHCenter |
| 136 | |
| 137 | Layout.fillHeight: true |
| 138 | Layout.maximumHeight: 20 |
| 139 | Layout.preferredHeight: 20 |
| 140 | Layout.minimumHeight: 20 |
| 141 | } |
| 142 | |
| 143 | Label{ |
| 144 | Layout.preferredWidth: 219 |
| 145 | Layout.alignment: Qt.AlignHCenter |
| 146 | wrapMode: Text.Wrap |
| 147 | text: qsTr("Enter your account password") |
| 148 | font.pointSize: 8 |
| 149 | font.kerning: true |
| 150 | horizontalAlignment: Text.AlignHCenter |
| 151 | verticalAlignment: Text.AlignVCenter |
| 152 | } |
| 153 | |
| 154 | Item{ |
| 155 | Layout.alignment: Qt.AlignHCenter |
| 156 | |
| 157 | Layout.fillHeight: true |
| 158 | |
| 159 | Layout.maximumHeight: 20 |
| 160 | Layout.preferredHeight: 20 |
| 161 | Layout.minimumHeight: 20 |
| 162 | } |
| 163 | |
| 164 | InfoLineEdit{ |
| 165 | id: passwordEdit |
| 166 | |
| 167 | Layout.alignment: Qt.AlignHCenter |
| 168 | |
| 169 | Layout.minimumWidth: 294 |
| 170 | Layout.preferredWidth: 294 |
| 171 | |
| 172 | Layout.preferredHeight: 30 |
| 173 | Layout.minimumHeight: 30 |
| 174 | |
| 175 | echoMode: TextInput.Password |
| 176 | |
| 177 | placeholderText: qsTr("Password") |
| 178 | } |
| 179 | |
| 180 | Item{ |
| 181 | Layout.alignment: Qt.AlignHCenter |
| 182 | |
| 183 | Layout.fillHeight: true |
| 184 | |
| 185 | Layout.maximumHeight: 20 |
| 186 | Layout.preferredHeight: 20 |
| 187 | Layout.minimumHeight: 20 |
| 188 | } |
| 189 | |
| 190 | RowLayout{ |
| 191 | spacing: 7 |
| 192 | |
| 193 | Layout.alignment: Qt.AlignHCenter |
| 194 | |
| 195 | Layout.fillWidth: true |
| 196 | |
| 197 | Item{ |
| 198 | Layout.fillWidth: true |
| 199 | |
| 200 | Layout.maximumHeight: 20 |
| 201 | Layout.preferredHeight: 20 |
| 202 | Layout.minimumHeight: 20 |
| 203 | } |
| 204 | |
| 205 | HoverableRadiusButton{ |
| 206 | id: btnRegister |
| 207 | |
| 208 | Layout.maximumWidth: 130 |
| 209 | Layout.preferredWidth: 130 |
| 210 | Layout.minimumWidth: 130 |
| 211 | |
| 212 | Layout.maximumHeight: 30 |
| 213 | Layout.preferredHeight: 30 |
| 214 | Layout.minimumHeight: 30 |
| 215 | |
| 216 | radius: height /2 |
| 217 | |
| 218 | text: qsTr("Register") |
| 219 | font.pointSize: 10 |
| 220 | font.kerning: true |
| 221 | |
| 222 | onClicked: { |
| 223 | startRegistration() |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | Item{ |
| 228 | Layout.fillWidth: true |
| 229 | Layout.minimumWidth: 40 |
| 230 | |
| 231 | Layout.maximumHeight: 20 |
| 232 | Layout.preferredHeight: 20 |
| 233 | Layout.minimumHeight: 20 |
| 234 | } |
| 235 | |
| 236 | HoverableButtonTextItem { |
| 237 | id: btnCancel |
| 238 | |
| 239 | Layout.maximumWidth: 130 |
| 240 | Layout.preferredWidth: 130 |
| 241 | Layout.minimumWidth: 130 |
| 242 | |
| 243 | Layout.maximumHeight: 30 |
| 244 | Layout.preferredHeight: 30 |
| 245 | Layout.minimumHeight: 30 |
| 246 | |
| 247 | backgroundColor: "red" |
| 248 | onEnterColor: Qt.rgba(150 / 256, 0, 0, 0.7) |
| 249 | onDisabledBackgroundColor: Qt.rgba( |
| 250 | 255 / 256, |
| 251 | 0, 0, 0.8) |
| 252 | onPressColor: backgroundColor |
| 253 | textColor: "white" |
| 254 | |
| 255 | radius: height /2 |
| 256 | |
| 257 | text: qsTr("Cancel") |
| 258 | font.pointSize: 10 |
| 259 | font.kerning: true |
| 260 | |
| 261 | onClicked: { |
| 262 | reject() |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | Item{ |
| 267 | Layout.fillWidth: true |
| 268 | Layout.minimumWidth: 40 |
| 269 | |
| 270 | Layout.maximumHeight: 20 |
| 271 | Layout.preferredHeight: 20 |
| 272 | Layout.minimumHeight: 20 |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | Item{ |
| 277 | Layout.alignment: Qt.AlignHCenter |
| 278 | |
| 279 | Layout.fillHeight: true |
| 280 | |
| 281 | Layout.maximumHeight: 20 |
| 282 | Layout.preferredHeight: 20 |
| 283 | Layout.minimumHeight: 20 |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | Rectangle{ |
| 289 | id: registeringPage |
| 290 | |
| 291 | Layout.fillWidth: true |
| 292 | Layout.fillHeight: true |
| 293 | |
| 294 | Layout.leftMargin: 11 |
| 295 | Layout.rightMargin: 11 |
| 296 | Layout.topMargin: 11 |
| 297 | Layout.bottomMargin: 11 |
| 298 | |
| 299 | ColumnLayout{ |
| 300 | anchors.fill: parent |
| 301 | spacing: 7 |
| 302 | |
| 303 | Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter |
| 304 | |
| 305 | Item{ |
| 306 | Layout.alignment: Qt.AlignHCenter |
| 307 | |
| 308 | Layout.fillHeight: true |
| 309 | Layout.minimumHeight: 40 |
| 310 | |
| 311 | Layout.maximumWidth: 20 |
| 312 | Layout.preferredWidth: 20 |
| 313 | Layout.minimumWidth: 20 |
| 314 | } |
| 315 | |
| 316 | RowLayout{ |
| 317 | Layout.fillWidth: true |
| 318 | spacing: 0 |
| 319 | |
| 320 | Layout.maximumHeight: 30 |
| 321 | |
| 322 | Item{ |
| 323 | Layout.fillWidth: true |
| 324 | |
| 325 | Layout.maximumHeight: 20 |
| 326 | Layout.preferredHeight: 20 |
| 327 | Layout.minimumHeight: 20 |
| 328 | } |
| 329 | |
| 330 | Label{ |
| 331 | Layout.alignment: Qt.AlignHCenter |
| 332 | |
| 333 | Layout.maximumWidth: 0 |
| 334 | Layout.preferredWidth: 341 |
| 335 | |
| 336 | Layout.minimumHeight: 0 |
| 337 | Layout.preferredHeight: 30 |
| 338 | Layout.maximumHeight: 30 |
| 339 | |
| 340 | wrapMode: Text.Wrap |
| 341 | text: qsTr("Registering Name") |
| 342 | font.pointSize: 8 |
| 343 | font.kerning: true |
| 344 | horizontalAlignment: Text.AlignHCenter |
| 345 | verticalAlignment: Text.AlignVCenter |
| 346 | } |
| 347 | |
| 348 | Item{ |
| 349 | Layout.fillWidth: true |
| 350 | |
| 351 | Layout.maximumHeight: 20 |
| 352 | Layout.preferredHeight: 20 |
| 353 | Layout.minimumHeight: 20 |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | Item{ |
| 358 | Layout.alignment: Qt.AlignHCenter |
| 359 | |
| 360 | Layout.fillHeight: true |
| 361 | |
| 362 | Layout.maximumWidth: 20 |
| 363 | Layout.preferredWidth: 20 |
| 364 | Layout.minimumWidth: 20 |
| 365 | } |
| 366 | |
| 367 | RowLayout{ |
| 368 | spacing: 7 |
| 369 | |
| 370 | Item{ |
| 371 | Layout.fillWidth: true |
| 372 | |
| 373 | Layout.maximumHeight: 20 |
| 374 | Layout.preferredHeight: 20 |
| 375 | Layout.minimumHeight: 20 |
| 376 | } |
| 377 | |
| 378 | Label{ |
| 379 | id: spinnerLabel |
| 380 | |
| 381 | Layout.alignment: Qt.AlignHCenter |
| 382 | |
| 383 | Layout.maximumWidth: 96 |
| 384 | Layout.preferredWidth: 96 |
| 385 | Layout.minimumWidth: 96 |
| 386 | |
| 387 | Layout.maximumHeight: 96 |
| 388 | Layout.preferredHeight: 96 |
| 389 | Layout.minimumHeight: 96 |
| 390 | |
| 391 | background: Rectangle { |
| 392 | anchors.fill: parent |
| 393 | AnimatedImage { |
| 394 | id: spinnerMovie |
| 395 | |
| 396 | anchors.fill: parent |
| 397 | |
| 398 | source: "qrc:/images/jami_eclipse_spinner.gif" |
| 399 | |
| 400 | playing: spinnerLabel.visible |
| 401 | paused: false |
| 402 | fillMode: Image.PreserveAspectFit |
| 403 | mipmap: true |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | Item{ |
| 409 | Layout.fillWidth: true |
| 410 | |
| 411 | Layout.maximumHeight: 20 |
| 412 | Layout.preferredHeight: 20 |
| 413 | Layout.minimumHeight: 20 |
| 414 | } |
| 415 | |
| 416 | } |
| 417 | |
| 418 | Item{ |
| 419 | Layout.alignment: Qt.AlignHCenter |
| 420 | |
| 421 | Layout.fillHeight: true |
| 422 | Layout.minimumHeight: 40 |
| 423 | |
| 424 | Layout.maximumWidth: 20 |
| 425 | Layout.preferredWidth: 20 |
| 426 | Layout.minimumWidth: 20 |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | Rectangle{ |
| 432 | id: nameNotRegisteredPage |
| 433 | |
| 434 | Layout.fillWidth: true |
| 435 | Layout.fillHeight: true |
| 436 | |
| 437 | ColumnLayout{ |
| 438 | anchors.fill: parent |
| 439 | |
| 440 | Item{ |
| 441 | Layout.fillHeight: true |
| 442 | Layout.minimumHeight: 40 |
| 443 | |
| 444 | Layout.maximumWidth: 20 |
| 445 | Layout.preferredWidth: 20 |
| 446 | Layout.minimumWidth: 20 |
| 447 | } |
| 448 | |
| 449 | RowLayout{ |
| 450 | spacing: 7 |
| 451 | Layout.fillWidth: true |
| 452 | |
| 453 | Item{ |
| 454 | Layout.fillWidth: true |
| 455 | |
| 456 | Layout.maximumHeight: 20 |
| 457 | Layout.preferredHeight: 20 |
| 458 | Layout.minimumHeight: 20 |
| 459 | } |
| 460 | |
| 461 | Label{ |
| 462 | id: lblRegistrationError |
| 463 | |
| 464 | Layout.alignment: Qt.AlignHCenter |
| 465 | |
| 466 | Layout.maximumWidth: 0 |
| 467 | Layout.preferredWidth: 341 |
| 468 | |
| 469 | Layout.minimumHeight: 0 |
| 470 | Layout.preferredHeight: 30 |
| 471 | Layout.maximumHeight: 30 |
| 472 | |
| 473 | wrapMode: Text.Wrap |
| 474 | text: qsTr("Something went wrong") |
| 475 | font.pointSize: 8 |
| 476 | font.kerning: true |
| 477 | color: "red" |
| 478 | horizontalAlignment: Text.AlignHCenter |
| 479 | verticalAlignment: Text.AlignVCenter |
| 480 | } |
| 481 | |
| 482 | Item{ |
| 483 | Layout.fillWidth: true |
| 484 | |
| 485 | Layout.maximumHeight: 20 |
| 486 | Layout.preferredHeight: 20 |
| 487 | Layout.minimumHeight: 20 |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | Item{ |
| 492 | Layout.fillHeight: true |
| 493 | Layout.minimumHeight: 40 |
| 494 | |
| 495 | Layout.maximumWidth: 20 |
| 496 | Layout.preferredWidth: 20 |
| 497 | Layout.minimumWidth: 20 |
| 498 | } |
| 499 | |
| 500 | RowLayout{ |
| 501 | spacing: 7 |
| 502 | Layout.fillWidth: true |
| 503 | |
| 504 | Item{ |
| 505 | Layout.fillWidth: true |
| 506 | |
| 507 | Layout.maximumHeight: 20 |
| 508 | Layout.preferredHeight: 20 |
| 509 | Layout.minimumHeight: 20 |
| 510 | } |
| 511 | |
| 512 | HoverableRadiusButton{ |
| 513 | id: btnCloseRegisterDialog |
| 514 | |
| 515 | Layout.maximumWidth: 130 |
| 516 | Layout.preferredWidth: 130 |
| 517 | Layout.minimumWidth: 130 |
| 518 | |
| 519 | Layout.maximumHeight: 30 |
| 520 | Layout.preferredHeight: 30 |
| 521 | Layout.minimumHeight: 30 |
| 522 | |
| 523 | radius: height /2 |
| 524 | |
| 525 | text: qsTr("Close") |
| 526 | font.pointSize: 10 |
| 527 | font.kerning: true |
| 528 | |
| 529 | onClicked: { |
| 530 | reject() |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | Item{ |
| 535 | Layout.fillWidth: true |
| 536 | |
| 537 | Layout.maximumHeight: 20 |
| 538 | Layout.preferredHeight: 20 |
| 539 | Layout.minimumHeight: 20 |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | Item{ |
| 544 | Layout.fillHeight: true |
| 545 | Layout.minimumHeight: 40 |
| 546 | |
| 547 | Layout.maximumWidth: 20 |
| 548 | Layout.preferredWidth: 20 |
| 549 | Layout.minimumWidth: 20 |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | } |