monero-gui/pages/settings/SettingsLog.qml

275 lines
11 KiB
QML
Raw Normal View History

2024-01-27 19:12:09 +00:00
// Copyright (c) 2014-2024, The Monero Project
2018-08-05 18:53:20 +00:00
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2019-04-11 01:17:29 +00:00
import QtQuick 2.9
2018-07-18 13:20:13 +00:00
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.2
2018-07-18 13:20:13 +00:00
import "../../js/Utils.js" as Utils
import "../../components" as MoneroComponents
Rectangle {
property alias consoleArea: consoleArea
color: "transparent"
Layout.fillWidth: true
2019-12-20 14:26:45 +00:00
property alias logHeight: settingsLog.height
2018-07-18 16:26:34 +00:00
2018-07-18 13:20:13 +00:00
ColumnLayout {
id: settingsLog
2019-04-25 19:09:23 +00:00
property int itemHeight: 60
2018-07-18 13:20:13 +00:00
Layout.fillWidth: true
anchors.left: parent.left
anchors.top: parent.top
anchors.right: parent.right
2019-09-05 22:11:12 +00:00
anchors.margins: 20
2018-07-18 13:20:13 +00:00
anchors.topMargin: 0
spacing: 10
// Rectangle {
// // divider
2019-04-25 19:09:23 +00:00
// Layout.preferredHeight: 1
2018-07-18 13:20:13 +00:00
// Layout.fillWidth: true
2019-04-25 19:09:23 +00:00
// Layout.bottomMargin: 8
2018-07-18 13:20:13 +00:00
// color: MoneroComponents.Style.dividerColor
// opacity: MoneroComponents.Style.dividerOpacity
// }
2018-07-18 16:26:34 +00:00
2019-04-11 01:17:29 +00:00
MoneroComponents.TextPlain {
2019-04-25 19:09:23 +00:00
Layout.bottomMargin: 2
2018-07-18 13:20:13 +00:00
color: MoneroComponents.Style.defaultFontColor
2019-04-25 19:09:23 +00:00
font.pixelSize: 18
2018-07-18 13:20:13 +00:00
font.family: MoneroComponents.Style.fontRegular.name
text: qsTr("Log level") + translationManager.emptyString
}
ColumnLayout {
2019-04-25 19:09:23 +00:00
spacing: 10
2018-07-18 13:20:13 +00:00
Layout.fillWidth: true
id: logColumn
2018-07-18 13:20:13 +00:00
z: parent.z + 1
ListModel {
id: logLevel
ListElement { column1: "0"; name: "none"; }
ListElement { column1: "1"; }
ListElement { column1: "2"; }
ListElement { column1: "3"; }
ListElement { column1: "4"; }
ListElement { column1: "custom"; }
}
2018-07-18 13:20:13 +00:00
MoneroComponents.StandardDropdown {
id: logLevelDropdown
dataModel: logLevel
2019-04-25 19:09:23 +00:00
itemTopMargin: 2
currentIndex: appWindow.persistentSettings.logLevel;
onChanged: {
if (currentIndex == 5) {
console.log("log categories changed: ", logCategories.text);
walletManager.setLogCategories(logCategories.text);
}
else {
console.log("log level changed: ",currentIndex);
walletManager.setLogLevel(currentIndex);
2018-07-18 13:20:13 +00:00
}
appWindow.persistentSettings.logLevel = currentIndex;
2018-07-18 13:20:13 +00:00
}
Layout.fillWidth: true
Layout.preferredWidth: logColumn.width
z: parent.z + 1
2018-07-18 13:20:13 +00:00
}
MoneroComponents.LineEdit {
id: logCategories
visible: logLevelDropdown.currentIndex === 5
2018-07-18 13:20:13 +00:00
Layout.fillWidth: true
Layout.preferredWidth: logColumn.width
2018-07-18 13:20:13 +00:00
text: appWindow.persistentSettings.logCategories
placeholderText: "(e.g. *:WARNING,net.p2p:DEBUG)"
2019-04-25 19:09:23 +00:00
placeholderFontSize: 14
fontSize: 14
2018-07-18 13:20:13 +00:00
enabled: logLevelDropdown.currentIndex === 5
onEditingFinished: {
if(enabled) {
console.log("log categories changed: ", text);
walletManager.setLogCategories(text);
appWindow.persistentSettings.logCategories = text;
}
}
}
}
2019-04-11 01:17:29 +00:00
MoneroComponents.TextPlain {
2019-04-25 19:09:23 +00:00
Layout.topMargin: 10
Layout.bottomMargin: 2
2018-07-18 13:20:13 +00:00
color: MoneroComponents.Style.defaultFontColor
2019-04-25 19:09:23 +00:00
font.pixelSize: 18
2018-07-18 13:20:13 +00:00
font.family: MoneroComponents.Style.fontRegular.name
text: qsTr("Daemon log") + translationManager.emptyString
themeTransition: false
onColorChanged: {
var flickableContentYBefore = flickable.contentY
var daemonLogText = consoleArea.text
consoleArea.clear();
if (MoneroComponents.Style.blackTheme) {
consoleArea.append(daemonLogText.replace(/#000000/g, '#ffffff').replace(/#008000/g, '#00ff00'));
} else {
consoleArea.append(daemonLogText.replace(/#ffffff/g, '#000000').replace(/#00ff00/g, '#008000'));
}
flickable.contentY = flickableContentYBefore
}
2018-07-18 13:20:13 +00:00
}
Item {
Layout.fillHeight: true
2018-07-18 13:20:13 +00:00
Layout.fillWidth: true
2019-04-25 19:09:23 +00:00
Layout.preferredHeight: 240
2018-07-18 13:20:13 +00:00
Rectangle {
2018-07-18 13:20:13 +00:00
anchors.fill: parent
color: "transparent"
2019-04-11 01:17:29 +00:00
border.color: MoneroComponents.Style.inputBorderColorInActive
border.width: 1
radius: 4
}
2018-07-18 13:20:13 +00:00
Flickable {
id: flickable
anchors.fill: parent
boundsBehavior: isMac ? Flickable.DragAndOvershootBounds : Flickable.StopAtBounds
2018-07-18 13:20:13 +00:00
TextArea.flickable: TextArea {
id : consoleArea
color: MoneroComponents.Style.defaultFontColor
2019-04-11 01:17:29 +00:00
selectionColor: MoneroComponents.Style.textSelectionColor
textFormat: TextEdit.RichText
selectByMouse: true
selectByKeyboard: true
font.family: MoneroComponents.Style.fontRegular.name
2019-04-25 19:09:23 +00:00
font.pixelSize: 14
wrapMode: TextEdit.Wrap
readOnly: true
function logCommand(msg){
msg = log_color(msg, MoneroComponents.Style.blackTheme ? "lime" : "green");
consoleArea.append(msg);
}
function logMessage(msg){
msg = msg.trim();
2019-04-11 01:17:29 +00:00
var color = MoneroComponents.Style.defaultFontColor;
if(msg.toLowerCase().indexOf('error') >= 0){
2019-04-11 01:17:29 +00:00
color = MoneroComponents.Style.errorColor;
} else if (msg.toLowerCase().indexOf('warning') >= 0){
color = "#fa6800"
}
// format multi-lines
if(msg.split("\n").length >= 2){
msg = msg.split("\n").join('<br>');
}
log(msg, color);
}
function log_color(msg, color){
return "<span style='color: " + color + ";' >" + msg + "</span>";
}
function log(msg, color){
var timestamp = Utils.formatDate(new Date(), {
weekday: undefined,
month: "numeric",
timeZoneName: undefined
});
2019-04-11 01:17:29 +00:00
var _timestamp = log_color("[" + timestamp + "]", MoneroComponents.Style.defaultFontColor);
var _msg = log_color(msg, color);
consoleArea.append(_timestamp + " " + _msg);
// scroll to bottom
//if(flickable.contentHeight > content.height){
// flickable.contentY = flickable.contentHeight;
//}
}
2018-07-18 13:20:13 +00:00
}
ScrollBar.vertical: ScrollBar {
onActiveChanged: if (!active && !isMac) active = true
policy: isMac ? ScrollBar.AsNeeded : ScrollBar.AlwaysOn
}
2018-07-18 13:20:13 +00:00
}
}
MoneroComponents.LineEdit {
id: sendCommandText
Layout.fillWidth: true
inputPaddingTop: 0
inputPaddingBottom: 0
2020-07-14 20:38:54 +00:00
property var lastCommands: []
property int currentCommandIndex
enabled: !persistentSettings.useRemoteNode
2018-07-18 13:20:13 +00:00
fontBold: false
fontSize: 16
placeholderText: qsTr("Type a command (e.g '%1' or '%2') and press Enter").arg("help").arg("status") + translationManager.emptyString
2019-04-25 19:09:23 +00:00
placeholderFontSize: 16
2020-07-14 20:38:54 +00:00
Keys.onUpPressed: {
if (currentCommandIndex != 0) {
sendCommandText.text = lastCommands[currentCommandIndex - 1]
currentCommandIndex = currentCommandIndex - 1
}
}
Keys.onDownPressed: {
if (currentCommandIndex == lastCommands.length - 1) {
currentCommandIndex = lastCommands.length;
return text = "";
}
if (currentCommandIndex != lastCommands.length) {
sendCommandText.text = lastCommands[currentCommandIndex + 1]
currentCommandIndex = currentCommandIndex + 1
}
}
2018-07-18 13:20:13 +00:00
onAccepted: {
if(text.length > 0) {
consoleArea.logCommand(">>> " + text)
daemonManager.sendCommandAsync(text.split(" "), currentWallet.nettype, persistentSettings.blockchainDataDir, function(result) {
if (!result) {
appWindow.showStatusMessage(qsTr("Failed to send command"), 3);
}
});
2018-07-18 13:20:13 +00:00
}
2020-07-14 20:38:54 +00:00
lastCommands.push(text);
currentCommandIndex = lastCommands.length;
2018-07-18 13:20:13 +00:00
text = ""
}
}
}
Component.onCompleted: {
if(typeof daemonManager != "undefined")
daemonManager.daemonConsoleUpdated.connect(onDaemonConsoleUpdated)
}
}