PageSettingsStorage.qml 10 KB
Newer Older
1
/*
2
 * Copyright (C) 2014-2019 CZ.NIC
3 4 5 6 7 8 9 10 11 12 13 14
 *
 * 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
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */

24
import QtQuick 2.7
25 26
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.1
27
import cz.nic.mobileDatovka 1.0
28

29 30
Item {
    id: pageSettingsStorage
31

32 33 34 35
    /* These properties must be set by caller. */
    property var pageView
    property var statusBar
    property var accountModel: null
36

37
    property int currentZfoSize: 0
38 39
    /* Possibility to change db location is implicit disabled now for all OS */
    property bool showChangeDbLocation: false
40

41
    Component.onCompleted: {
42 43 44 45 46 47 48 49 50
        dbPathLabel.visible = showChangeDbLocation
        dbPathText.visible = showChangeDbLocation
        dbPathButton.visible = showChangeDbLocation
        dbResetPathButton.visible = (showChangeDbLocation && settings.showDefaultButton())
        messageLifeSpinBox.setVal(settings.messageLifeDays())
        attachLifeSpinBox.setVal(settings.attachmentLifeDays())
        currentZfoSize = settings.zfoDbSizeMBs()
        zfoDbSizeSpinBox.value = currentZfoSize
        dbPathText.text = settings.dbPath()
51
    }
52 53 54 55 56 57 58 59

    Component.onDestruction: {
        settings.saveAllSettings(accountModel)
        if (currentZfoSize > zfoDbSizeSpinBox.value) {
            zfo.reduceZfoDbSize(currentZfoSize-zfoDbSizeSpinBox.value);
        }
    }

60 61 62
    PageHeader {
        id: headerBar
        title: qsTr("Storage settings")
63 64
        onBackClicked: {
            pageView.pop(StackView.Immediate)
65
        }
66
    }
67 68 69 70 71 72 73 74 75 76 77
    Flickable {
        id: flickable
        z: 0
        anchors.top: headerBar.bottom
        anchors.right: parent.right
        anchors.left: parent.left
        anchors.bottom: parent.bottom
        contentHeight: flickContent.implicitHeight
        Pane {
            id: flickContent
            anchors.fill: parent
78
            Column {
79
                anchors.right: parent.right
80
                anchors.left: parent.left
81
                spacing: formItemVerticalSpacing
82
                AccessibleText {
83 84 85
                    id: messageLifeLabel
                    color: datovkaPalette.text
                    text: qsTr("Number of days to keep messages")
86
                }
87
                AccessibleSpinBoxZeroMax {
88 89
                    /* Holds value in days. */
                    id: messageLifeSpinBox
90

91 92
                    /* Must be a non-decreasing list ending with infinity. */
                    items: [90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170, 175, 180, qsTr("don't delete")]
93
                    dfltIdx: 19
94 95 96

                    accessibleDescription: qsTr("Select the number of days how long downloaded messages are kept in local storage after download.")

97
                    onValueModified: settings.setMessageLifeDays(messageLifeSpinBox.val())
98
                }
99
                AccessibleText {
100
                    color: datovkaPalette.mid
101
                    width: parent.width
102
                    text: if (messageLifeSpinBox.val() === 0) {
103 104
                              qsTr("Messages won't automatically be deleted from the local storage.")
                        } else {
105
                              qsTr("Messages will be locally stored for a period of %1 days since their acceptance time. By default they are not deleted.").arg(messageLifeSpinBox.val())
106
                        }
107 108
                    wrapMode: Text.Wrap
                }
109
                AccessibleText {
110 111 112 113
                    id: attachLifeLabel
                    color: datovkaPalette.text
                    text: qsTr("Number of days to keep attachments")
                }
114
                AccessibleSpinBoxZeroMax {
115 116
                    /* Holds value in days. */
                    id: attachLifeSpinBox
117

118 119
                    /* Must be a non-decreasing list ending with infinity. */
                    items: [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, qsTr("like messages")]
120
                    dfltIdx: 17
121 122 123

                    accessibleDescription: qsTr("Select the number of days how long message content is kept in local storage after download.")

124
                    onValueModified: settings.setAttachmentLifeDays(attachLifeSpinBox.val())
125
                }
126
                AccessibleText {
127
                    color: datovkaPalette.mid
128
                    width: parent.width
129
                    text: if (attachLifeSpinBox.val() === 0) {
130 131
                              qsTr("Attachments won't be deleted from the local storage as long as the corresponding messages won't be deleted.")
                        } else {
132
                              qsTr("Attachments will be locally stored, but no longer than corresponding messages, for a period of %1 days since their download time. Default value corresponds with message settings.").arg(attachLifeSpinBox.val())
133
                        }
134 135
                    wrapMode: Text.Wrap
                }
136
                AccessibleText {
137 138
                    id: zfoLifeLabel
                    color: datovkaPalette.text
139
                    text: qsTr("ZFO storage size limit in MB")
140
                }
141
                AccessibleSpinBox {
142 143
                    /* Holds value in MBs. */
                    id: zfoDbSizeSpinBox
144

145 146 147
                    from: 0
                    to: 1000
                    stepSize: 100
148 149 150 151

                    accessibleDescription: qsTr("Specify the maximal amount of memory for preserving recently downloaded messages.")

                    onValueModified: settings.setZfoDbSizeMBs(zfoDbSizeSpinBox.val())
152
                }
153
                AccessibleText {
154 155
                    color: datovkaPalette.mid
                    width: parent.width
156
                    text: if (zfoDbSizeSpinBox.val() === 0) {
157 158
                              qsTr("Message ZFO data won't be automatically stored.")
                        } else {
159
                              qsTr("Maximum size of stored message ZFO data is set to %1 MB. Default is %2 MB.").arg(zfoDbSizeSpinBox.val()).arg(200)
160 161 162
                        }
                    wrapMode: Text.Wrap
                }
163
                AccessibleText {
164 165 166 167
                    id: dbPathLabel
                    color: datovkaPalette.text
                    text: qsTr("Databases location")
                }
168
                AccessibleText {
169 170
                    id: dbPathText
                    color: datovkaPalette.mid
171
                    width: parent.width
172 173 174
                    wrapMode: Text.Wrap
                    text: ""
                }
175
                AccessibleButton {
176 177 178 179 180 181
                    id: dbPathButton
                    font.pointSize: defaultTextFont.font.pointSize
                    height: inputItemHeight
                    text: qsTr("Change location")
                    onClicked: {
                        var newLocation = settings.changeDbPath(dbPathText.text.toString(), false)
182 183
                        if (newLocation !== "") {
                            if (newLocation !== dbPathText.text) {
184 185 186
                                if (messages.moveOrCreateNewDbsToNewLocation(newLocation)) {
                                    dbPathText.text = newLocation;
                                    dbResetPathButton.visible = true
187
                                    settings.setDbPath(newLocation)
188 189 190
                                }
                            }
                        }
191
                    }
192
                }
193
                AccessibleButton {
194 195 196 197 198 199
                    id: dbResetPathButton
                    text: qsTr("Set default")
                    font.pointSize: defaultTextFont.font.pointSize
                    height: inputItemHeight
                    onClicked: {
                        var newLocation = settings.changeDbPath(dbPathText.text.toString(), true)
200 201
                        if (newLocation !== "") {
                            if (newLocation !== dbPathText.text) {
202 203 204
                                if (messages.moveOrCreateNewDbsToNewLocation(newLocation)) {
                                    dbPathText.text = newLocation;
                                    dbResetPathButton.visible = false
205
                                    settings.setDbPath(newLocation)
206
                                }
207 208 209
                            }
                        }
                    }
210
                }
211
                AccessibleText {
212 213 214 215
                    id: vacuumLabel
                    color: datovkaPalette.text
                    text: qsTr("Clean up all databases")
                }
216
                AccessibleButton {
217 218 219 220 221 222
                    id: vacuumButton
                    font.pointSize: defaultTextFont.font.pointSize
                    height: inputItemHeight
                    text: qsTr("Clean now")
                    onClicked: {
                       files.vacuumFileDbs()
223
                    }
224
                }
225
                AccessibleText {
226 227
                    id: vacuumText
                    color: datovkaPalette.mid
228
                    width: parent.width
229 230 231 232 233 234 235 236
                    wrapMode: Text.Wrap
                    text: qsTr("The action performs a clean-up in local databases in order to optimise their speed and size. Note: It may take a while to complete this action.")
                }
            } // Column layout
        } // Pane
        ScrollIndicator.vertical: ScrollIndicator {}
    } // Flickable
} // Item