LogDownload.qml 7.65 KB
Newer Older
dogmaphobic's avatar
dogmaphobic committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

QGROUNDCONTROL 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.

QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

import QtQuick                  2.5
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.2
import QtQuick.Dialogs          1.2

import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0
import QGroundControl.Controllers   1.0
import QGroundControl.ScreenTools   1.0

QGCView {
    viewPanel:  panel

dogmaphobic's avatar
dogmaphobic committed
37 38
    property real _margins:         ScreenTools.defaultFontPixelHeight
    property real _butttonWidth:    ScreenTools.defaultFontPixelWidth * 10
dogmaphobic's avatar
dogmaphobic committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

    LogDownloadController {
        id:         controller
        factPanel:  panel
        onSelectionChanged: {
            tableView.selection.clear()
            for(var i = 0; i < controller.model.count; i++) {
                var o = controller.model.get(i)
                if (o && o.selected) {
                    tableView.selection.select(i, i)
                }
            }
        }
    }

    QGCPalette { id: palette; colorGroupEnabled: enabled }

    QGCViewPanel {
        id:             panel
        anchors.fill:   parent

        TableView {
            id: tableView
            anchors.margins:    _margins
            anchors.left:       parent.left
            anchors.right:      refreshButton.left
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
            model:              controller.model
            selectionMode:      SelectionMode.MultiSelection

            TableViewColumn {
71
                title: qsTr("Id")
72
                width: ScreenTools.defaultFontPixelWidth * 6
dogmaphobic's avatar
dogmaphobic committed
73 74 75 76 77 78 79 80 81 82 83
                horizontalAlignment: Text.AlignHCenter
                delegate : Text  {
                    horizontalAlignment: Text.AlignHCenter
                    text: {
                        var o = controller.model.get(styleData.row)
                        return o ? o.id : ""
                    }
                }
            }

            TableViewColumn {
84
                title: qsTr("Date")
85
                width: ScreenTools.defaultFontPixelWidth * 34
dogmaphobic's avatar
dogmaphobic committed
86 87 88 89 90 91 92 93
                horizontalAlignment: Text.AlignHCenter
                delegate : Text  {
                    text: {
                        var o = controller.model.get(styleData.row)
                        if (o) {
                            //-- Have we received this entry already?
                            if(controller.model.get(styleData.row).received) {
                                var d = controller.model.get(styleData.row).time
dogmaphobic's avatar
dogmaphobic committed
94
                                if(d.getUTCFullYear() < 2010)
95
                                    return qsTr("Date Unknown")
dogmaphobic's avatar
dogmaphobic committed
96 97 98 99 100 101 102 103 104 105
                                else
                                    return d.toLocaleString()
                            }
                        }
                        return ""
                    }
                }
            }

            TableViewColumn {
106
                title: qsTr("Size")
107
                width: ScreenTools.defaultFontPixelWidth * 18
dogmaphobic's avatar
dogmaphobic committed
108 109 110 111 112
                horizontalAlignment: Text.AlignHCenter
                delegate : Text  {
                    horizontalAlignment: Text.AlignRight
                    text: {
                        var o = controller.model.get(styleData.row)
113
                        return o ? o.sizeStr : ""
dogmaphobic's avatar
dogmaphobic committed
114 115 116 117 118
                    }
                }
            }

            TableViewColumn {
119
                title: qsTr("Status")
120
                width: ScreenTools.defaultFontPixelWidth * 22
dogmaphobic's avatar
dogmaphobic committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
                horizontalAlignment: Text.AlignHCenter
                delegate : Text  {
                    horizontalAlignment: Text.AlignHCenter
                    text: {
                        var o = controller.model.get(styleData.row)
                        return o ? o.status : ""
                    }
                }
            }

        }

        QGCButton {
            id:                 refreshButton
            anchors.margins:    _margins
            anchors.top:        parent.top
            anchors.right:      parent.right
            enabled:            !controller.requestingList && !controller.downloadingLogs
139
            text:               qsTr("Refresh")
dogmaphobic's avatar
dogmaphobic committed
140
            width:              _butttonWidth
dogmaphobic's avatar
dogmaphobic committed
141 142 143 144 145 146 147 148 149 150 151
            onClicked: {
                controller.refresh()
            }
        }

        QGCButton {
            id:                 downloadButton
            anchors.margins:    _margins
            anchors.top:        refreshButton.bottom
            anchors.right:      parent.right
            enabled:            !controller.requestingList && !controller.downloadingLogs && tableView.selection.count > 0
152
            text:               qsTr("Download")
dogmaphobic's avatar
dogmaphobic committed
153
            width:              _butttonWidth
dogmaphobic's avatar
dogmaphobic committed
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
            onClicked: {
                //-- Clear selection
                for(var i = 0; i < controller.model.count; i++) {
                    var o = controller.model.get(i)
                    if (o) o.selected = false
                }
                //-- Flag selected log files
                tableView.selection.forEach(function(rowIndex){
                    var o = controller.model.get(rowIndex)
                    if (o) o.selected = true
                })
                //-- Download them
                controller.download()
            }
        }

        QGCButton {
            id:                 eraseAllButton
            anchors.margins:    _margins
            anchors.top:        downloadButton.bottom
            anchors.right:      parent.right
            enabled:            !controller.requestingList && !controller.downloadingLogs && controller.model.count > 0
176
            text:               qsTr("Erase All")
dogmaphobic's avatar
dogmaphobic committed
177
            width:              _butttonWidth
dogmaphobic's avatar
dogmaphobic committed
178 179 180 181 182 183 184 185
            onClicked: {
                eraseAllDialog.visible = true
            }
            MessageDialog {
                id:         eraseAllDialog
                visible:    false
                icon:       StandardIcon.Warning
                standardButtons: StandardButton.Yes | StandardButton.No
186 187
                title:      qsTr("Delete All Log Files")
                text:       qsTr("All log files will be erased permanently. Is this really what you want?")
dogmaphobic's avatar
dogmaphobic committed
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
                onYes: {
                    controller.eraseAll()
                    eraseAllDialog.visible = false
                }
                onNo: {
                    eraseAllDialog.visible = false
                }
            }
        }

        QGCButton {
            id:                 cancelButton
            anchors.margins:    _margins
            anchors.top:        eraseAllButton.bottom
            anchors.right:      parent.right
203
            text:               qsTr("Cancel")
dogmaphobic's avatar
dogmaphobic committed
204
            width:              _butttonWidth
dogmaphobic's avatar
dogmaphobic committed
205 206 207 208 209 210 211
            enabled:            controller.requestingList || controller.downloadingLogs
            onClicked: {
                controller.cancel()
            }
        }
    }
}