Commit 3c7d0322 authored by Ming Rui Zhang's avatar Ming Rui Zhang Committed by Sébastien Blin
Browse files

accountMigration: use the existing loader mechanism to avoid crash

1. Avoid direct window declaration under ApplicationWindow
2. UI refactor

Change-Id: I7991e22d3f85b1c17d85475000ab8b8c2fbc3391
parent be41f0e7
......@@ -71,7 +71,7 @@ set(COMMON_SOURCES
${SRC_DIR}/pluginhandleritemlistmodel.cpp
${SRC_DIR}/preferenceitemlistmodel.cpp
${SRC_DIR}/mediacodeclistmodel.cpp
${SRC_DIR}/accountstomigratelistmodel.cpp
${SRC_DIR}/currentaccounttomigrate.cpp
${SRC_DIR}/audiodevicemodel.cpp
${SRC_DIR}/pluginlistpreferencemodel.cpp
${SRC_DIR}/audiomanagerlistmodel.cpp
......@@ -125,7 +125,7 @@ set(COMMON_HEADERS
${SRC_DIR}/pluginhandleritemlistmodel.h
${SRC_DIR}/preferenceitemlistmodel.h
${SRC_DIR}/mediacodeclistmodel.h
${SRC_DIR}/accountstomigratelistmodel.h
${SRC_DIR}/currentaccounttomigrate.h
${SRC_DIR}/audiodevicemodel.h
${SRC_DIR}/pluginlistpreferencemodel.h
${SRC_DIR}/audiomanagerlistmodel.h
......
......@@ -15,7 +15,6 @@
<file>src/commoncomponents/CustomBorder.qml</file>
<file>src/commoncomponents/PushButton.qml</file>
<file>src/commoncomponents/JamiFileDialog.qml</file>
<file>src/commoncomponents/AccountMigrationDialog.qml</file>
<file>src/commoncomponents/MaterialButton.qml</file>
<file>src/commoncomponents/ElidedTextLabel.qml</file>
<file>src/commoncomponents/SpinnerButton.qml</file>
......@@ -173,5 +172,6 @@
<file>src/commoncomponents/JamiScrollBar.qml</file>
<file>qtquickcontrols2.conf</file>
<file>src/commoncomponents/JamiFlickable.qml</file>
<file>src/AccountMigrationView.qml</file>
</qresource>
</RCC>
......@@ -25,110 +25,36 @@ import net.jami.Models 1.1
import net.jami.Adapters 1.1
import net.jami.Constants 1.1
import "../wizardview/components"
import "commoncomponents"
// Account Migration Dialog for migrating account
Rectangle {
id: root
Window {
id: accountMigrationDialog
AccountsToMigrateListModel {
id: accountsToMigrateListModel
lrcInstance: LRCInstance
enum AccountMigrationStep {
PasswordEnter,
Synching
}
property string accountID: ""
property string password: ""
property bool nonOperationClosing: true
property bool successState : true
signal accountMigrationFinished
function startAccountMigrationOfTopStack() {
passwordInputLineEdit.clear()
accountsToMigrateListModel.reset()
if (accountsToMigrateListModel.rowCount() <= 0) {
closeWithoutOperation()
property bool successState: true
return false
}
var managerUsername = accountsToMigrateListModel.data(accountsToMigrateListModel.index(
0, 0), AccountsToMigrateListModel.ManagerUsername)
var managerUri = accountsToMigrateListModel.data(accountsToMigrateListModel.index(
0, 0), AccountsToMigrateListModel.ManagerUri)
var username = accountsToMigrateListModel.data(accountsToMigrateListModel.index(
0, 0), AccountsToMigrateListModel.Username)
var alias = accountsToMigrateListModel.data(accountsToMigrateListModel.index(
0, 0), AccountsToMigrateListModel.Alias)
if (managerUri.length !== 0) {
managerUriInputLabel.text = managerUri
} else {
managerUriInputLabel.text = "N/A"
}
if (username.length !== 0) {
usernameInputLabel.text = username
} else if (managerUsername.length !== 0) {
usernameInputLabel.text = managerUsername
} else {
usernameInputLabel.text = "N/A"
}
// signal to redirect the page to main view
signal loaderSourceChangeRequested(int sourceToLoad)
if (alias.length !== 0) {
aliasInputLabel.text = alias
} else {
aliasInputLabel.text = "N/A"
}
accountID = accountsToMigrateListModel.data(accountsToMigrateListModel.index(
0, 0), AccountsToMigrateListModel.Account_ID)
connectionMigrationEnded.enabled = false
migrationPushButton.enabled = false
stackedWidget.currentIndex = 0
successState = true
nonOperationClosing = true
accountMigrationDialog.show()
return true
}
function slotMigrationButtonClicked() {
stackedWidget.currentIndex = AccountMigrationView.AccountMigrationStep.Synching
function checkIfAccountMigrationFinishedAndClose() {
accountsToMigrateListModel.reset()
if (accountsToMigrateListModel.rowCount() > 0) {
startAccountMigrationOfTopStack()
} else {
accountMigrationFinished()
if (!nonOperationClosing) {
nonOperationClosing = true
accountMigrationDialog.close()
}
}
AccountAdapter.setArchivePasswordAsync(
CurrentAccountToMigrate.accountId, passwordInputLineEdit.text)
}
function acceptMigration() {
nonOperationClosing = false
accountsToMigrateListModel.dataChanged(accountsToMigrateListModel.index(0, 0),
accountsToMigrateListModel.index(
accountsToMigrateListModel.rowCount() - 1, 0))
checkIfAccountMigrationFinishedAndClose()
}
function slotDeleteButtonClicked() {
stackedWidget.currentIndex = AccountMigrationView.AccountMigrationStep.Synching
function refuseMigrationAndDeleteAccount() {
AccountAdapter.model.removeAccount(accountID)
acceptMigration()
CurrentAccountToMigrate.removeCurrentAccountToMigrate()
}
function closeWithoutOperation() {
nonOperationClosing = false
accountMigrationDialog.close()
}
color: JamiTheme.backgroundColor
Timer {
id: timerFailureReturn
......@@ -137,73 +63,46 @@ Window {
repeat: false
onTriggered: {
stackedWidget.currentIndex = 0
stackedWidget.currentIndex =
AccountMigrationView.AccountMigrationStep.PasswordEnter
successState = true
}
}
Connections {
id: connectionMigrationEnded
enabled: false
target: AccountAdapter.model
function onMigrationEnded(accountIdIn, ok) {
nonOperationClosing = true
connectionMigrationEnded.enabled = false
if (accountID !== accountIdIn) {
return
}
target: CurrentAccountToMigrate
function onMigrationEnded(ok) {
successState = ok
if (ok) {
acceptMigration()
passwordInputLineEdit.clear()
stackedWidget.currentIndex =
AccountMigrationView.AccountMigrationStep.PasswordEnter
} else {
successState = false
timerFailureReturn.restart()
}
}
}
function slotMigrationButtonClicked() {
successState = true
stackedWidget.currentIndex = 1
connectionMigrationEnded.enabled = true
AccountAdapter.setArchivePasswordAsync(accountID,password)
}
function slotDeleteButtonClicked() {
nonOperationClosing = false
refuseMigrationAndDeleteAccount()
}
function onCurrentAccountToMigrateRemoved() {
successState = true
passwordInputLineEdit.clear()
onClosing: {
connectionMigrationEnded.enabled = false
stackedWidget.currentIndex = 0
accountID = ""
password = ""
passwordInputLineEdit.clear()
managerUriInputLabel.text = ""
usernameInputLabel.text = ""
aliasInputLabel.text = ""
if (nonOperationClosing) {
checkIfAccountMigrationFinishedAndClose()
stackedWidget.currentIndex =
AccountMigrationView.AccountMigrationStep.PasswordEnter
}
nonOperationClosing = true
}
visible: false
title: JamiStrings.authenticate
flags: Qt.WindowStaysOnTopHint
width: 600
height: 600
minimumWidth: 600
minimumHeight: 600
Component.onCompleted: {
setX(Screen.width / 2 - width / 2)
setY(Screen.height / 2 - height / 2)
function onAllMigrationsFinished() {
if (UtilsAdapter.getAccountListSize() === 0)
root.loaderSourceChangeRequested(
MainApplicationWindow.LoadedSource.WizardView)
else
root.loaderSourceChangeRequested(
MainApplicationWindow.LoadedSource.MainView)
}
}
ColumnLayout {
......@@ -217,22 +116,14 @@ Window {
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter
currentIndex: 0
// Index = 0
Rectangle {
id: accountMigrationPage
Layout.fillWidth: true
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter
ColumnLayout {
spacing: 8
width: stackedWidget.width
height: stackedWidget.height
Layout.alignment: Qt.AlignHCenter
anchors.fill: accountMigrationPage
Label {
id: accountMigrationLabel
......@@ -266,7 +157,7 @@ Window {
verticalAlignment: Text.AlignVCenter
}
Label {
Avatar {
id: avatarLabel
Layout.preferredWidth: 200
......@@ -274,19 +165,9 @@ Window {
Layout.alignment: Qt.AlignHCenter
background: Rectangle {
id: avatarLabelBackground
anchors.fill: parent
color: "transparent"
Avatar {
anchors.fill: parent
showPresenceIndicator: false
mode: Avatar.Mode.Account
imageId: accountID
}
}
showPresenceIndicator: false
mode: Avatar.Mode.Account
imageId: CurrentAccountToMigrate.accountId
}
GridLayout {
......@@ -321,6 +202,13 @@ Window {
Layout.preferredWidth: JamiTheme.preferredFieldWidth
Layout.preferredHeight: JamiTheme.preferredFieldHeight
text: {
if (CurrentAccountToMigrate.alias.length !== 0) {
return CurrentAccountToMigrate.alias
} else {
return JamiStrings.notAvailable
}
}
font.pointSize: JamiTheme.textFontSize
font.kerning: true
......@@ -349,6 +237,15 @@ Window {
Layout.preferredWidth: JamiTheme.preferredFieldWidth
Layout.preferredHeight: JamiTheme.preferredFieldHeight
text: {
if (CurrentAccountToMigrate.username.length !== 0) {
return CurrentAccountToMigrate.username
} else if (CurrentAccountToMigrate.managerUsername.length !== 0) {
return CurrentAccountToMigrate.managerUsername
} else {
return JamiStrings.notAvailable
}
}
font.pointSize: JamiTheme.textFontSize
font.kerning: true
......@@ -377,6 +274,13 @@ Window {
Layout.preferredWidth: JamiTheme.preferredFieldWidth
Layout.preferredHeight: JamiTheme.preferredFieldHeight
text: {
if (CurrentAccountToMigrate.managerUri.length !== 0) {
return CurrentAccountToMigrate.managerUri
} else {
return JamiStrings.notAvailable
}
}
font.pointSize: JamiTheme.textFontSize
font.kerning: true
......@@ -410,22 +314,15 @@ Window {
Layout.preferredHeight: 48
echoMode: TextInput.Password
placeholderText: JamiStrings.password
onTextChanged: {
migrationPushButton.enabled = text.length > 0
password = text
}
onEditingFinished: {
password = text
}
onAccepted: slotMigrationButtonClicked()
}
}
RowLayout {
spacing: 80
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter
Layout.bottomMargin: JamiTheme.preferredMarginSize
......@@ -441,12 +338,11 @@ Window {
hoveredColor: JamiTheme.buttonTintedBlackHovered
pressedColor: JamiTheme.buttonTintedBlackPressed
outlined: true
enabled: passwordInputLineEdit.text.length > 0
text: JamiStrings.authenticate
onClicked: {
slotMigrationButtonClicked()
}
onClicked: slotMigrationButtonClicked()
}
MaterialButton {
......@@ -462,9 +358,7 @@ Window {
outlined: true
text: JamiStrings.deleteAccount
onClicked: {
slotDeleteButtonClicked()
}
onClicked: slotDeleteButtonClicked()
}
}
}
......@@ -491,7 +385,24 @@ Window {
Layout.alignment: Qt.AlignHCenter
Layout.fillWidth: true
Label {
ResponsiveImage {
id: errorLabel
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: 200
Layout.preferredHeight: 200
containerHeight: Layout.preferredHeight
containerWidth: Layout.preferredWidth
visible: !successState
source: JamiResources.round_remove_circle_24dp_svg
color: JamiTheme.redColor
}
AnimatedImage {
id: spinnerLabel
Layout.alignment: Qt.AlignHCenter
......@@ -499,29 +410,13 @@ Window {
Layout.preferredWidth: 200
Layout.preferredHeight: 200
property string spinnerDisplyState: successState ? "spinnerLabel_Regular" : "spinnerLabel_Failure"
onSpinnerDisplyStateChanged: {
switch (spinnerDisplyState) {
case "spinnerLabel_Regular":
background = Qt.createQmlObject("import QtQuick;
import \"qrc:/src/constant/\";
AnimatedImage {
source: JamiResources.jami_eclipse_spinner_gif
playing: true
paused: false
fillMode: Image.PreserveAspectFit
mipmap: true}", spinnerLabel)
break
case "spinnerLabel_Failure":
background = Qt.createQmlObject("import QtQuick;
import \"qrc:/src/constant/\";
Image {
anchors.fill: parent;
source: JamiResources.error_outline_black_24dp_svg;
mipmap: true;}", spinnerLabel)
break
}
}
visible: successState
source: JamiResources.jami_eclipse_spinner_gif
playing: successState
fillMode: Image.PreserveAspectFit
mipmap: true
}
}
......@@ -532,9 +427,10 @@ Window {
Layout.fillWidth: true
Layout.bottomMargin: 80
color: successState? "black" : "red"
text: successState? JamiStrings.inProgress : JamiStrings.authenticationFailed
font.pointSize: JamiTheme.textFontSize
color: successState ? JamiTheme.textColor : JamiTheme.redColor
text: successState ? JamiStrings.inProgress :
JamiStrings.authenticationFailed
font.pointSize: JamiTheme.textFontSize + 5
font.kerning: true
horizontalAlignment: Text.AlignHCenter
......
......@@ -42,6 +42,7 @@ ApplicationWindow {
enum LoadedSource {
WizardView = 0,
MainView,
AccountMigrationView,
None
}
......@@ -63,11 +64,7 @@ ApplicationWindow {
return MainApplicationWindow.LoadedSource.None
}
function startAccountMigration(){
return accountMigrationDialog.startAccountMigrationOfTopStack()
}
function startClient(){
function startClient() {
if (UtilsAdapter.getAccountListSize() !== 0) {
mainApplicationLoader.setSource(JamiQmlUtils.mainViewLoadPath)
} else {
......@@ -75,6 +72,10 @@ ApplicationWindow {
}
}
function startAccountMigration() {
mainApplicationLoader.setSource(JamiQmlUtils.accountMigrationViewLoadPath)
}
function close(force = false) {
// If we're in the onboarding wizard or 'MinimizeOnClose'
// is set, then we can quit
......@@ -123,14 +124,6 @@ ApplicationWindow {
anchors.fill: parent
}
AccountMigrationDialog {
id: accountMigrationDialog
visible: false
onAccountMigrationFinished: startClient()
}
DaemonReconnectPopup {
id: daemonReconnectPopup
}
......@@ -225,9 +218,11 @@ ApplicationWindow {
onScreenChanged: JamiQmlUtils.mainApplicationScreen = root.screen
Component.onCompleted: {
if(!startAccountMigration()){
if (CurrentAccountToMigrate.accountToMigrateListSize <= 0)
startClient()
}
else
startAccountMigration()
JamiQmlUtils.mainApplicationScreen = root.screen
if (Qt.platform.os !== "windows")
......
/*
* Copyright (C) 2019-2020 by Savoir-faire Linux
* Author: Yang Wang <yang.wang@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "accountstomigratelistmodel.h"
#include "lrcinstance.h"
#include "api/account.h"
#include "api/contact.h"
#include "api/conversation.h"
#include "api/newdevicemodel.h"
AccountsToMigrateListModel::AccountsToMigrateListModel(QObject* parent)
: AbstractListModelBase(parent)
{}
AccountsToMigrateListModel::~AccountsToMigrateListModel() {}
int
AccountsToMigrateListModel::rowCount(const QModelIndex& parent) const
{
if (!parent.isValid() && lrcInstance_) {
/*
* Count.
*/
auto accountList = lrcInstance_->accountModel().getAccountList();
int countAccountToMigrate = 0;
for (const QString& i : accountList) {
auto accountStatus = lrcInstance_->accountModel().getAccountInfo(i).status;
if (accountStatus == lrc::api::account::Status::ERROR_NEED_MIGRATION) {
countAccountToMigrate++;
}
}
return countAccountToMigrate;
}
/*
* A valid QModelIndex returns 0 as no entry has sub-elements.
*/
return 0;
}
int
AccountsToMigrateListModel::columnCount(const QModelIndex& parent) const
{
Q_UNUSED(parent);
/*
* Only need one column.
*/
return 1;
}
QVariant
AccountsToMigrateListModel::data(const QModelIndex& index, int role) const
{
auto accountList = lrcInstance_->accountModel().getAccountList();
if (!index.isValid() || accountList.size() <= index.row()) {
return QVariant();