1/**************************************************************************
2 **                                                                      **
3 ** Copyright (C) 2018 Lukas Spies                                       **
4 ** Contact: http://photoqt.org                                          **
5 **                                                                      **
6 ** This file is part of PhotoQt.                                        **
7 **                                                                      **
8 ** PhotoQt is free software: you can redistribute it and/or modify      **
9 ** it under the terms of the GNU General Public License as published by **
10 ** the Free Software Foundation, either version 2 of the License, or    **
11 ** (at your option) any later version.                                  **
12 **                                                                      **
13 ** PhotoQt is distributed in the hope that it will be useful,           **
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of       **
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        **
16 ** GNU General Public License for more details.                         **
17 **                                                                      **
18 ** You should have received a copy of the GNU General Public License    **
19 ** along with PhotoQt. If not, see <http://www.gnu.org/licenses/>.      **
20 **                                                                      **
21 **************************************************************************/
22
23import QtQuick 2.5
24import "../elements"
25
26Rectangle {
27
28    color: colour.fadein_slidein_block_bg
29
30    // Visibility handlers
31    visible: (opacity!=0)
32    opacity: 0
33    Behavior on opacity { NumberAnimation { duration: variables.animationSpeed } }
34
35    // Catch mouse events (background)
36    MouseArea {
37        anchors.fill: parent
38        hoverEnabled: true
39        onClicked: hide()
40    }
41
42    // Outer content rectangle
43    Rectangle {
44
45        // Geometry
46        x: (parent.width-width)/2
47        y: (parent.height-height)/2
48        width: 600
49        height: 500
50
51        // Some styling
52        color: colour.fadein_slidein_bg
53        border.width: 1
54        border.color: colour.fadein_slidein_border
55        radius: variables.global_element_radius
56
57        // Click on content does nothing (overrides big MouseArea above)
58        MouseArea {
59            anchors.fill: parent
60            hoverEnabled: true
61        }
62
63        // Inner content rectangle
64        Rectangle {
65
66            id: contrect
67
68            // same as outer rectangle with margin
69            anchors.fill: parent
70            anchors.margins: 10
71            color: "transparent"
72
73            // Column content
74            Column {
75
76                spacing: 20
77
78                // some spacing at the top
79                Rectangle {
80                    color: "transparent"
81                    width: contrect.width
82                    height: 5
83                }
84
85                // Header
86                Text {
87                    text: em.pty+qsTr("Export/Import settings and shortcuts")
88                    color: "white"
89                    font.pointSize: 18
90                    width: contrect.width
91                    horizontalAlignment: Text.AlignHCenter
92                    font.bold: true
93                }
94
95                // A short explanation text
96                Text {
97                    text: em.pty+qsTr("Here you can export all settings and shortcuts into a single packed file and, e.g., import it in another installation of PhotoQt.")
98                    color: "white"
99                    width: contrect.width
100                    font.pointSize: 12
101                    wrapMode: Text.WordWrap
102                    horizontalAlignment: Text.AlignHCenter
103                }
104
105                // Separator line
106                Rectangle {
107                    color: "#55ffffff"
108                    width: contrect.width
109                    height: 1
110                }
111
112                // Button to export config to file
113                CustomButton {
114                    //: Everything refers to all settings and shortcuts
115                    text: em.pty+qsTr("Export everything to file")
116                    x: (contrect.width-width)/2
117                    fontsize: 18
118                    onClickedButton: {
119                        // execute export, return value is error message
120                        var ret = getanddostuff.exportConfig()
121                        // if there's an error message, display it
122                        if(ret === "-") {
123                            // do nothing, QFileDialog cancelled by user
124                        } else if(ret !== "") {
125                            errormsg.error = ret
126                            errormsg.exp = true
127                            errormsg.show()
128                        // else hide element
129                        } else
130                            hide()
131                    }
132                }
133
134                // Separator line
135                Rectangle {
136                    color: "#55ffffff"
137                    width: contrect.width
138                    height: 1
139                }
140
141                // Selector for a file
142                CustomFileSelect {
143                    id: importfilename
144                    x: (contrect.width-width)/2
145                    width: 400
146                }
147
148                // Import selected config file
149                CustomButton {
150                    x: (contrect.width-width)/2
151                    text: em.pty+qsTr("Import settings and shortcuts")
152                    enabled: importfilename.file!=""
153                    fontsize: 18
154                    onClickedButton: {
155                        // Import files, return value is error message
156                        var ret = getanddostuff.importConfig(importfilename.file)
157                        // If error message, display error
158                        if(ret !== "") {
159                            errormsg.exp = false
160                            errormsg.error = ret
161                            errormsg.show()
162                        // else restart PhotoQt
163                        } else
164                            getanddostuff.restartPhotoQt(variables.currentDir + "/" + variables.currentFile)
165                    }
166                }
167
168                // Info text below import button
169                Text {
170                    color: enabled ? colour.text : colour.text_disabled
171                    width: parent.width
172                    enabled: importfilename.file!=""
173                    horizontalAlignment: Text.AlignHCenter
174                    wrapMode: Text.WordWrap
175                    text: em.pty+qsTr("PhotoQt will attempt to automatically restart after a successful import!")
176                }
177
178                // Separator line
179                Rectangle {
180                    height: 1
181                    width: parent.width
182                    color: "white"
183                }
184
185                // Cancel and close
186                CustomButton {
187                    x: (parent.width-width)/2
188                    fontsize: 15
189                    text: em.pty+qsTr("I don't want to do this")
190                    onClickedButton: hide()
191                }
192
193            }
194
195        }
196
197    }
198
199    // Error message box
200    CustomConfirm {
201        id: errormsg
202        header: em.pty+qsTr("Error")
203        property string error: ""
204        property bool exp: false
205        description: (exp
206                      ? em.pty+qsTr("Exporting the configuration file failed with the following error message:")
207                      : em.pty+qsTr("Importing the configuration file failed with the following error message:")) + "<br><br>" + error
208        rejectbuttontext: em.pty+qsTr("Oh, okay")
209        actAsErrorMessage: true
210    }
211
212    // Show element
213    function show() {
214        importfilename.clearText()
215        opacity = 1
216    }
217
218    // Hide element
219    function hide() {
220        opacity = 0;
221    }
222
223}
224