LogDownloadPage.qml 8.42 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

10 11
import QtQuick              2.3
import QtQuick.Controls     1.2
12
import QtQuick.Dialogs      1.2
13
import QtQuick.Layouts      1.2
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

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

AnalyzePage {
    id:                 logDownloadPage
    pageComponent:      pageComponent
    pageName:           qsTr("Log Download")
    pageDescription:    qsTr("Log Download allows you to download binary log files from your vehicle. Click Refresh to get list of available logs.")

    property real _margin:          ScreenTools.defaultFontPixelWidth
    property real _butttonWidth:    ScreenTools.defaultFontPixelWidth * 10

    QGCPalette { id: palette; colorGroupEnabled: enabled }

    Component {
        id: pageComponent

        RowLayout {
            width:  availableWidth
            height: availableHeight

39 40 41 42 43 44 45 46 47 48 49 50 51
            Connections {
                target: logController
                onSelectionChanged: {
                    tableView.selection.clear()
                    for(var i = 0; i < logController.model.count; i++) {
                        var o = logController.model.get(i)
                        if (o && o.selected) {
                            tableView.selection.select(i, i)
                        }
                    }
                }
            }

52 53 54 55
            TableView {
                id: tableView
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
56
                model:              logController.model
57 58 59 60 61 62 63 64 65 66
                selectionMode:      SelectionMode.MultiSelection
                Layout.fillWidth:   true

                TableViewColumn {
                    title: qsTr("Id")
                    width: ScreenTools.defaultFontPixelWidth * 6
                    horizontalAlignment: Text.AlignHCenter
                    delegate : Text  {
                        horizontalAlignment: Text.AlignHCenter
                        text: {
67
                            var o = logController.model.get(styleData.row)
68 69 70 71 72 73 74 75 76 77 78
                            return o ? o.id : ""
                        }
                    }
                }

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

                TableViewColumn {
                    title: qsTr("Size")
                    width: ScreenTools.defaultFontPixelWidth * 18
                    horizontalAlignment: Text.AlignHCenter
                    delegate : Text  {
                        horizontalAlignment: Text.AlignRight
                        text: {
102
                            var o = logController.model.get(styleData.row)
103 104 105 106 107 108 109 110 111 112 113 114
                            return o ? o.sizeStr : ""
                        }
                    }
                }

                TableViewColumn {
                    title: qsTr("Status")
                    width: ScreenTools.defaultFontPixelWidth * 22
                    horizontalAlignment: Text.AlignHCenter
                    delegate : Text  {
                        horizontalAlignment: Text.AlignHCenter
                        text: {
115
                            var o = logController.model.get(styleData.row)
116 117 118 119 120 121 122 123 124 125 126
                            return o ? o.status : ""
                        }
                    }
                }
            }

            Column {
                spacing:            _margin
                Layout.alignment:   Qt.AlignTop | Qt.AlignLeft

                QGCButton {
127
                    enabled:    !logController.requestingList && !logController.downloadingLogs
128 129 130 131 132 133 134
                    text:       qsTr("Refresh")
                    width:      _butttonWidth

                    onClicked: {
                        if (!QGroundControl.multiVehicleManager.activeVehicle || QGroundControl.multiVehicleManager.activeVehicle.isOfflineEditingVehicle) {
                            logDownloadPage.showMessage(qsTr("Log Refresh"), qsTr("You must be connected to a vehicle in order to download logs."), StandardButton.Ok)
                        } else {
135
                            logController.refresh()
136 137 138 139 140
                        }
                    }
                }

                QGCButton {
141
                    enabled:    !logController.requestingList && !logController.downloadingLogs && tableView.selection.count > 0
142 143 144 145
                    text:       qsTr("Download")
                    width:      _butttonWidth
                    onClicked: {
                        //-- Clear selection
146 147
                        for(var i = 0; i < logController.model.count; i++) {
                            var o = logController.model.get(i)
148 149 150 151
                            if (o) o.selected = false
                        }
                        //-- Flag selected log files
                        tableView.selection.forEach(function(rowIndex){
152
                            var o = logController.model.get(rowIndex)
153 154
                            if (o) o.selected = true
                        })
155 156 157
                        fileDialog.qgcView =        logDownloadPage
                        fileDialog.title =          qsTr("Select save directory")
                        fileDialog.selectExisting = true
DonLakeFlyer's avatar
DonLakeFlyer committed
158
                        fileDialog.folder =         QGroundControl.settingsManager.appSettings.logSavePath
159 160 161 162 163 164 165 166 167 168 169
                        fileDialog.selectFolder =   true
                        fileDialog.openForLoad()
                    }

                    QGCFileDialog {
                        id: fileDialog

                        onAcceptedForLoad: {
                            logController.download(file)
                            close()
                        }
170 171 172 173
                    }
                }

                QGCButton {
174
                    enabled:    !logController.requestingList && !logController.downloadingLogs && logController.model.count > 0
175 176 177 178 179 180 181 182 183 184 185 186 187 188
                    text:       qsTr("Erase All")
                    width:      _butttonWidth
                    onClicked:  logDownloadPage.showDialog(eraseAllMessage,
                                                           qsTr("Delete All Log Files"),
                                                           logDownloadPage.showDialogDefaultWidth,
                                                           StandardButton.Yes | StandardButton.No)

                    Component {
                        id: eraseAllMessage

                        QGCViewMessage {
                            message:    qsTr("All log files will be erased permanently. Is this really what you want?")

                            function accept() {
DonLakeFlyer's avatar
DonLakeFlyer committed
189
                                hideDialog()
190
                                logController.eraseAll()
191 192 193 194 195 196 197 198
                            }
                        }
                    }
                }

                QGCButton {
                    text:       qsTr("Cancel")
                    width:      _butttonWidth
199 200
                    enabled:    logController.requestingList || logController.downloadingLogs
                    onClicked:  logController.cancel()
201 202 203 204 205
                }
            } // Column - Buttons
        } // RowLayout
    } // Component
} // AnalyzePage