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.14 |
| 20 | import QtQuick.Layouts 1.3 |
| 21 | import QtQuick.Controls 2.14 |
| 22 | import Qt.labs.platform 1.1 |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 23 | import net.jami.Models 1.0 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 24 | |
| 25 | import "../../constant" |
| 26 | import "../../commoncomponents" |
| 27 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 28 | Rectangle { |
| 29 | id: root |
| 30 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 31 | property alias text_passwordFromBackupEditAlias: passwordFromBackupEdit.text |
| 32 | property string fileImportBtnText: qsTr("Archive(none)") |
| 33 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 34 | property string filePath: "" |
| 35 | property string errorText: "" |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 36 | |
| 37 | function clearAllTextFields() { |
| 38 | passwordFromBackupEdit.clear() |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 39 | errorText = "" |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 40 | fileImportBtnText = qsTr("Archive(none)") |
| 41 | } |
| 42 | |
| 43 | JamiFileDialog { |
| 44 | id: importFromFile_Dialog |
| 45 | |
| 46 | mode: JamiFileDialog.OpenFile |
| 47 | title: qsTr("Open File") |
| 48 | folder: StandardPaths.writableLocation(StandardPaths.HomeLocation) + "/Desktop" |
| 49 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 50 | nameFilters: [qsTr("Jami archive files") + " (*.gz)", qsTr("All files") + " (*)"] |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 51 | |
| 52 | onAccepted: { |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 53 | filePath = file |
| 54 | if (file.length != 0) { |
| 55 | fileImportBtnText = ClientWrapper.utilsAdaptor.toFileInfoName(file) |
| 56 | } else { |
| 57 | fileImportBtnText = qsTr("Archive(none)") |
| 58 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 62 | anchors.fill: parent |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 63 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 64 | color: JamiTheme.backgroundColor |
| 65 | |
| 66 | signal leavePage |
| 67 | signal importAccount |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 68 | |
| 69 | ColumnLayout { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 70 | spacing: 12 |
| 71 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 72 | anchors.verticalCenter: parent.verticalCenter |
| 73 | anchors.horizontalCenter: root.horizontalCenter |
| 74 | Layout.preferredWidth: parent.width |
| 75 | Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 76 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 77 | Text { |
| 78 | anchors.left: connectBtn.left |
| 79 | anchors.right: connectBtn.right |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 80 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 81 | text: qsTr("Import from backup") |
| 82 | font.pointSize: JamiTheme.menuFontSize |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 83 | } |
| 84 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 85 | MaterialButton { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 86 | id: fileImportBtn |
| 87 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 88 | text: fileImportBtnText |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 89 | toolTipText: qsTr("Import your account's archive") |
| 90 | source: "qrc:/images/icons/round-folder-24px.svg" |
| 91 | color: JamiTheme.buttonTintedGrey |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 92 | |
| 93 | onClicked: { |
| 94 | importFromFile_Dialog.open() |
| 95 | } |
| 96 | } |
| 97 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 98 | Text { |
| 99 | anchors.left: connectBtn.left |
| 100 | anchors.right: connectBtn.right |
| 101 | |
| 102 | text: qsTr("You can obtain an archive by clicking on \"Export account\" in the account settings. This will create a .gz file on your device.") |
| 103 | wrapMode: Text.Wrap |
| 104 | } |
| 105 | |
| 106 | MaterialLineEdit { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 107 | id: passwordFromBackupEdit |
| 108 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 109 | selectByMouse: true |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 110 | placeholderText: qsTr("Password") |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 111 | font.pointSize: 10 |
| 112 | font.kerning: true |
| 113 | |
| 114 | echoMode: TextInput.Password |
| 115 | |
| 116 | borderColorMode: MaterialLineEdit.NORMAL |
| 117 | |
| 118 | fieldLayoutWidth: connectBtn.width |
| 119 | } |
| 120 | |
| 121 | MaterialButton { |
| 122 | id: connectBtn |
| 123 | text: qsTr("CONNECT FROM BACKUP") |
| 124 | color: filePath.length === 0? |
| 125 | JamiTheme.buttonTintedGreyInactive : JamiTheme.buttonTintedGrey |
| 126 | |
| 127 | onClicked: { |
| 128 | errorText = "" |
| 129 | importAccount() |
| 130 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | Label { |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 134 | text: errorText |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 135 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 136 | anchors.left: connectBtn.left |
| 137 | anchors.right: connectBtn.right |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 138 | Layout.alignment: Qt.AlignHCenter |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 139 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 140 | font.pointSize: JamiTheme.textFontSize |
| 141 | color: "red" |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 142 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 143 | height: 32 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
Sébastien Blin | c75335f | 2020-08-04 20:54:02 -0400 | [diff] [blame] | 147 | HoverableButton { |
| 148 | id: cancelButton |
| 149 | z: 2 |
| 150 | |
| 151 | anchors.right: parent.right |
| 152 | anchors.top: parent.top |
| 153 | |
| 154 | rightPadding: 90 |
| 155 | topPadding: 90 |
| 156 | |
| 157 | Layout.preferredWidth: 96 |
| 158 | Layout.preferredHeight: 96 |
| 159 | |
| 160 | backgroundColor: "transparent" |
| 161 | onEnterColor: "transparent" |
| 162 | onPressColor: "transparent" |
| 163 | onReleaseColor: "transparent" |
| 164 | onExitColor: "transparent" |
| 165 | |
| 166 | buttonImageHeight: 48 |
| 167 | buttonImageWidth: 48 |
| 168 | source: "qrc:/images/icons/ic_close_white_24dp.png" |
| 169 | radius: 48 |
| 170 | baseColor: "#7c7c7c" |
| 171 | toolTipText: qsTr("Return to welcome page") |
| 172 | |
| 173 | Action { |
| 174 | enabled: parent.visible |
| 175 | shortcut: StandardKey.Cancel |
| 176 | onTriggered: leavePage() |
| 177 | } |
| 178 | |
| 179 | onClicked: { |
| 180 | leavePage() |
| 181 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 182 | } |
| 183 | } |