blob: f379dfef9c3f808fab62bbf024ebce42b78fb268 [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001/*
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
19import QtQuick 2.14
20import QtQuick.Layouts 1.3
21import QtQuick.Controls 2.14
22import Qt.labs.platform 1.1
Sébastien Blinc75335f2020-08-04 20:54:02 -040023import net.jami.Models 1.0
Sébastien Blin1f915762020-08-03 13:27:42 -040024
25import "../../constant"
26import "../../commoncomponents"
27
Sébastien Blinc75335f2020-08-04 20:54:02 -040028Rectangle {
29 id: root
30
Sébastien Blin1f915762020-08-03 13:27:42 -040031 property alias text_passwordFromBackupEditAlias: passwordFromBackupEdit.text
32 property string fileImportBtnText: qsTr("Archive(none)")
33
Sébastien Blinc75335f2020-08-04 20:54:02 -040034 property string filePath: ""
35 property string errorText: ""
Sébastien Blin1f915762020-08-03 13:27:42 -040036
37 function clearAllTextFields() {
38 passwordFromBackupEdit.clear()
Sébastien Blinc75335f2020-08-04 20:54:02 -040039 errorText = ""
Sébastien Blin1f915762020-08-03 13:27:42 -040040 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 Blinc75335f2020-08-04 20:54:02 -040050 nameFilters: [qsTr("Jami archive files") + " (*.gz)", qsTr("All files") + " (*)"]
Sébastien Blin1f915762020-08-03 13:27:42 -040051
52 onAccepted: {
Sébastien Blinc75335f2020-08-04 20:54:02 -040053 filePath = file
54 if (file.length != 0) {
55 fileImportBtnText = ClientWrapper.utilsAdaptor.toFileInfoName(file)
56 } else {
57 fileImportBtnText = qsTr("Archive(none)")
58 }
Sébastien Blin1f915762020-08-03 13:27:42 -040059 }
60 }
61
Sébastien Blinc75335f2020-08-04 20:54:02 -040062 anchors.fill: parent
Sébastien Blin1f915762020-08-03 13:27:42 -040063
Sébastien Blinc75335f2020-08-04 20:54:02 -040064 color: JamiTheme.backgroundColor
65
66 signal leavePage
67 signal importAccount
Sébastien Blin1f915762020-08-03 13:27:42 -040068
69 ColumnLayout {
Sébastien Blin1f915762020-08-03 13:27:42 -040070 spacing: 12
71
Sébastien Blinc75335f2020-08-04 20:54:02 -040072 anchors.verticalCenter: parent.verticalCenter
73 anchors.horizontalCenter: root.horizontalCenter
74 Layout.preferredWidth: parent.width
75 Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Sébastien Blin1f915762020-08-03 13:27:42 -040076
Sébastien Blinc75335f2020-08-04 20:54:02 -040077 Text {
78 anchors.left: connectBtn.left
79 anchors.right: connectBtn.right
Sébastien Blin1f915762020-08-03 13:27:42 -040080
Sébastien Blinc75335f2020-08-04 20:54:02 -040081 text: qsTr("Import from backup")
82 font.pointSize: JamiTheme.menuFontSize
Sébastien Blin1f915762020-08-03 13:27:42 -040083 }
84
Sébastien Blinc75335f2020-08-04 20:54:02 -040085 MaterialButton {
Sébastien Blin1f915762020-08-03 13:27:42 -040086 id: fileImportBtn
87
Sébastien Blin1f915762020-08-03 13:27:42 -040088 text: fileImportBtnText
Sébastien Blinc75335f2020-08-04 20:54:02 -040089 toolTipText: qsTr("Import your account's archive")
90 source: "qrc:/images/icons/round-folder-24px.svg"
91 color: JamiTheme.buttonTintedGrey
Sébastien Blin1f915762020-08-03 13:27:42 -040092
93 onClicked: {
94 importFromFile_Dialog.open()
95 }
96 }
97
Sébastien Blinc75335f2020-08-04 20:54:02 -040098 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 Blin1f915762020-08-03 13:27:42 -0400107 id: passwordFromBackupEdit
108
Sébastien Blin1f915762020-08-03 13:27:42 -0400109 selectByMouse: true
Sébastien Blin1f915762020-08-03 13:27:42 -0400110 placeholderText: qsTr("Password")
Sébastien Blinc75335f2020-08-04 20:54:02 -0400111 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 Blin1f915762020-08-03 13:27:42 -0400131 }
132
133 Label {
Sébastien Blinc75335f2020-08-04 20:54:02 -0400134 text: errorText
Sébastien Blin1f915762020-08-03 13:27:42 -0400135
Sébastien Blinc75335f2020-08-04 20:54:02 -0400136 anchors.left: connectBtn.left
137 anchors.right: connectBtn.right
Sébastien Blin1f915762020-08-03 13:27:42 -0400138 Layout.alignment: Qt.AlignHCenter
Sébastien Blin1f915762020-08-03 13:27:42 -0400139
Sébastien Blinc75335f2020-08-04 20:54:02 -0400140 font.pointSize: JamiTheme.textFontSize
141 color: "red"
Sébastien Blin1f915762020-08-03 13:27:42 -0400142
Sébastien Blinc75335f2020-08-04 20:54:02 -0400143 height: 32
Sébastien Blin1f915762020-08-03 13:27:42 -0400144 }
145 }
146
Sébastien Blinc75335f2020-08-04 20:54:02 -0400147 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 Blin1f915762020-08-03 13:27:42 -0400182 }
183}