2021-04-17 23:38:34 +03:00
|
|
|
/**
|
|
|
|
* Battery Buddy, a Sailfish application to prolong battery lifetime
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019-2020 Matti Viljanen
|
|
|
|
*
|
|
|
|
* Battery Buddy 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.
|
|
|
|
*
|
|
|
|
* Battery Buddy 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 Battery Buddy. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author: Matti Viljanen
|
|
|
|
*/
|
2022-03-20 21:16:24 +03:00
|
|
|
import QtQuick 2.6
|
2021-04-17 23:38:34 +03:00
|
|
|
import Sailfish.Silica 1.0
|
|
|
|
import "../components"
|
|
|
|
|
|
|
|
Page {
|
|
|
|
allowedOrientations: Orientation.Portrait | Orientation.Landscape | Orientation.LandscapeInverted
|
|
|
|
|
2022-08-10 21:40:18 +03:00
|
|
|
// Invisible; used to determine
|
|
|
|
// the ColumnView delegate size.
|
2022-08-10 21:34:10 +03:00
|
|
|
Label {
|
2022-08-10 21:40:18 +03:00
|
|
|
id: metrics
|
2022-08-10 21:34:10 +03:00
|
|
|
text: "X"
|
|
|
|
font.pixelSize: Theme.fontSizeTiny
|
|
|
|
opacity: 0
|
|
|
|
enabled: false
|
|
|
|
}
|
|
|
|
|
2021-04-17 23:38:34 +03:00
|
|
|
SilicaFlickable {
|
2022-08-10 21:40:18 +03:00
|
|
|
id: flickable
|
2021-04-17 23:38:34 +03:00
|
|
|
anchors.fill: parent
|
2022-08-10 21:34:10 +03:00
|
|
|
contentHeight: header.height
|
|
|
|
+ flow.height
|
|
|
|
+ Theme.paddingLarge
|
|
|
|
+ logView.height
|
|
|
|
|
|
|
|
ScrollDecorator {
|
2022-08-10 21:40:18 +03:00
|
|
|
flickable: flickable
|
2022-08-10 21:34:10 +03:00
|
|
|
}
|
2021-04-17 23:38:34 +03:00
|
|
|
|
|
|
|
PageHeader {
|
|
|
|
id: header
|
|
|
|
title: qsTr("View log")
|
|
|
|
}
|
|
|
|
|
2022-08-10 21:40:18 +03:00
|
|
|
// Layout the ComboBox and the buttons either
|
|
|
|
// on top each other (portait) or
|
|
|
|
// next to each other (landscape)
|
2022-08-10 21:34:10 +03:00
|
|
|
Flow {
|
|
|
|
id: flow
|
|
|
|
anchors.top: header.bottom
|
|
|
|
width: parent.width
|
2021-04-17 23:38:34 +03:00
|
|
|
|
2021-04-24 17:44:25 +03:00
|
|
|
ComboBox {
|
2022-08-10 21:34:10 +03:00
|
|
|
width: page.isPortrait ? page.width : page.width / 2
|
2021-04-24 17:44:25 +03:00
|
|
|
label: qsTr("Log level")
|
|
|
|
currentIndex: 0
|
|
|
|
menu: ContextMenu {
|
|
|
|
MenuItem { text: qsTr("Quiet", "Low log setting") }
|
|
|
|
MenuItem { text: qsTr("Verbose", "Medium log setting") }
|
|
|
|
MenuItem { text: qsTr("Debug", "High log setting") }
|
|
|
|
}
|
|
|
|
onCurrentIndexChanged: settings.logLevel = currentIndex
|
|
|
|
Component.onCompleted: currentIndex = settings.logLevel
|
|
|
|
}
|
|
|
|
|
|
|
|
Row {
|
2022-08-10 21:34:10 +03:00
|
|
|
width: page.isPortrait ? page.width : page.width / 2
|
2021-04-24 17:44:25 +03:00
|
|
|
height: updateButton.height
|
|
|
|
|
|
|
|
Column {
|
|
|
|
width: parent.width / 2
|
|
|
|
Button {
|
|
|
|
id: updateButton
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
text: qsTr("Update")
|
2022-08-10 21:34:10 +03:00
|
|
|
onClicked: logView.updateText()
|
2021-04-24 17:44:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Column {
|
|
|
|
width: parent.width / 2
|
|
|
|
Button {
|
|
|
|
id: daemonStopButton
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
text: qsTr("Copy")
|
2022-08-10 21:34:10 +03:00
|
|
|
onClicked: Clipboard.text = logView.text
|
2021-04-24 17:44:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-10 21:34:10 +03:00
|
|
|
}
|
2021-04-24 17:44:25 +03:00
|
|
|
|
2022-08-10 21:34:10 +03:00
|
|
|
ColumnView {
|
|
|
|
id: logView
|
|
|
|
anchors {
|
|
|
|
top: flow.bottom
|
|
|
|
topMargin: Theme.paddingLarge
|
|
|
|
left: parent.left
|
|
|
|
right: parent.right
|
|
|
|
leftMargin: Theme.horizontalPageMargin
|
2021-04-17 23:38:34 +03:00
|
|
|
}
|
2022-08-10 21:40:18 +03:00
|
|
|
itemHeight: metrics.height
|
2022-08-10 11:28:05 +03:00
|
|
|
clip: true
|
|
|
|
model: ListModel {}
|
2022-08-10 21:34:10 +03:00
|
|
|
delegate: Component {
|
|
|
|
Label {
|
|
|
|
clip: true
|
|
|
|
text: line
|
|
|
|
width: logView.width
|
|
|
|
wrapMode: TextEdit.NoWrap
|
|
|
|
truncationMode: TruncationMode.Fade
|
|
|
|
font.bold: true
|
|
|
|
font.pixelSize: Theme.fontSizeTiny
|
|
|
|
color: {
|
|
|
|
switch (text.split(" ")[1]) {
|
2022-08-10 11:28:05 +03:00
|
|
|
case "Charger:":
|
|
|
|
return Theme.highlightFromColor("yellow", Theme.colorScheme)
|
2022-08-10 21:34:10 +03:00
|
|
|
case "State:":
|
|
|
|
return Theme.highlightFromColor("red", Theme.colorScheme)
|
2022-08-10 11:28:05 +03:00
|
|
|
case "Temperature:":
|
|
|
|
return Theme.highlightFromColor("orange", Theme.colorScheme)
|
|
|
|
case "Health:":
|
2022-08-10 21:34:10 +03:00
|
|
|
return Theme.highlightFromColor("blue", Theme.colorScheme)
|
|
|
|
case "Battery:":
|
|
|
|
return Theme.highlightFromColor("green", Theme.colorScheme)
|
|
|
|
}
|
|
|
|
font.bold = false
|
2022-08-10 11:28:05 +03:00
|
|
|
return Theme.secondaryColor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-10 21:40:18 +03:00
|
|
|
// ColumnView only instantiates and renders delegates
|
|
|
|
// as they are about to be shown, so we can
|
|
|
|
// simply dump the full log at it.
|
2022-08-10 21:34:10 +03:00
|
|
|
Component.onCompleted: updateText()
|
2022-08-10 11:28:05 +03:00
|
|
|
property string text: ""
|
|
|
|
function updateText() {
|
2022-08-10 21:34:10 +03:00
|
|
|
logView.text = logger.readLogfile(settings.logFilename)
|
|
|
|
logView.text.split("\n").forEach(
|
|
|
|
function(str) {
|
|
|
|
model.append({ "line": str })
|
|
|
|
}
|
2022-08-10 11:28:05 +03:00
|
|
|
);
|
|
|
|
}
|
2021-04-17 23:38:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|