diff --git a/pages/settings/SettingsLog.qml b/pages/settings/SettingsLog.qml new file mode 100644 index 00000000..61b54901 --- /dev/null +++ b/pages/settings/SettingsLog.qml @@ -0,0 +1,214 @@ +import QtQuick 2.7 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 2.0 + +import "../../js/Utils.js" as Utils +import "../../components" as MoneroComponents + + +Rectangle { + property alias consoleArea: consoleArea + color: "transparent" + height: 1400 + Layout.fillWidth: true + + ColumnLayout { + id: settingsLog + property int itemHeight: 60 * scaleRatio + Layout.fillWidth: true + anchors.left: parent.left + anchors.top: parent.top + anchors.right: parent.right + anchors.margins: (isMobile)? 17 : 20 + anchors.topMargin: 0 + spacing: 10 + +// Rectangle { +// // divider +// Layout.preferredHeight: 1 * scaleRatio +// Layout.fillWidth: true +// Layout.bottomMargin: 8 * scaleRatio +// color: MoneroComponents.Style.dividerColor +// opacity: MoneroComponents.Style.dividerOpacity +// } + + Text { + Layout.bottomMargin: 2 * scaleRatio + color: MoneroComponents.Style.defaultFontColor + font.pixelSize: 18 * scaleRatio + font.family: MoneroComponents.Style.fontRegular.name + text: qsTr("Log level") + translationManager.emptyString + } + + GridLayout { + columns: appWindow.persistentSettings.logLevel === 5 ? 2 : 1 + Layout.fillWidth: true + columnSpacing: 32 * scaleRatio + z: parent.z + 1 + + ColumnLayout { + spacing: 0 + Layout.fillWidth: true + + ListModel { + id: logLevel + ListElement { column1: "0"; name: "none"; } + ListElement { column1: "1"; } + ListElement { column1: "2"; } + ListElement { column1: "3"; } + ListElement { column1: "4"; } + ListElement { column1: "custom"; } + } + + MoneroComponents.StandardDropdown { + id: logLevelDropdown + dataModel: logLevel + itemTopMargin: 2 * scaleRatio + 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); + } + appWindow.persistentSettings.logLevel = currentIndex; + } + Layout.fillWidth: true + shadowReleasedColor: "#FF4304" + shadowPressedColor: "#B32D00" + releasedColor: "#363636" + pressedColor: "#202020" + } + } + + MoneroComponents.LineEdit { + id: logCategories + visible: persistentSettings.logLevel === 5 + Layout.fillWidth: true + text: appWindow.persistentSettings.logCategories + placeholderText: "(e.g. *:WARNING,net.p2p:DEBUG)" + placeholderFontSize: 14 * scaleRatio + enabled: logLevelDropdown.currentIndex === 5 + onEditingFinished: { + if(enabled) { + console.log("log categories changed: ", text); + walletManager.setLogCategories(text); + appWindow.persistentSettings.logCategories = text; + } + } + } + } + + Text { + Layout.topMargin: 10 * scaleRatio + Layout.bottomMargin: 2 * scaleRatio + color: MoneroComponents.Style.defaultFontColor + font.pixelSize: 18 * scaleRatio + font.family: MoneroComponents.Style.fontRegular.name + text: qsTr("Daemon log") + translationManager.emptyString + } + + Flickable { + id: flickable + Layout.fillWidth: true + Layout.preferredHeight: 240 * scaleRatio + + TextArea.flickable: TextArea { + id : consoleArea + anchors.fill: parent + color: MoneroComponents.Style.defaultFontColor + selectionColor: MoneroComponents.Style.dimmedFontColor + textFormat: TextEdit.RichText + selectByMouse: true + selectByKeyboard: true + font.family: "Ariel" + font.pixelSize: 14 * scaleRatio + wrapMode: TextEdit.Wrap + readOnly: true + background: Rectangle { + color: "transparent" + anchors.fill: parent + border.color: Qt.rgba(255, 255, 255, 0.25); + border.width: 1 + radius: 4 + } + function logCommand(msg){ + msg = log_color(msg, "lime"); + consoleArea.append(msg); + } + function logMessage(msg){ + msg = msg.trim(); + var color = "white"; + if(msg.toLowerCase().indexOf('error') >= 0){ + color = "red"; + } else if (msg.toLowerCase().indexOf('warning') >= 0){ + color = "yellow"; + } + + // format multi-lines + if(msg.split("\n").length >= 2){ + msg = msg.split("\n").join('
'); + } + + log(msg, color); + } + function log_color(msg, color){ + return "" + msg + ""; + } + function log(msg, color){ + var timestamp = Utils.formatDate(new Date(), { + weekday: undefined, + month: "numeric", + timeZoneName: undefined + }); + + var _timestamp = log_color("[" + timestamp + "]", "#FFFFFF"); + var _msg = log_color(msg, color); + consoleArea.append(_timestamp + " " + _msg); + + // scroll to bottom + //if(flickable.contentHeight > content.height){ + // flickable.contentY = flickable.contentHeight; + //} + } + } + + ScrollBar.vertical: ScrollBar { + // TODO: scrollbar always visible is buggy. + // QT 5.9 introduces `policy: ScrollBar.AlwaysOn` + contentItem.opacity: 1 + anchors.top: flickable.top + anchors.left: flickable.right + anchors.leftMargin: 10 * scaleRatio + anchors.bottom: flickable.bottom + } + } + + MoneroComponents.LineEdit { + id: sendCommandText + Layout.fillWidth: true + fontBold: false + fontFamily: MoneroComponents.Style.fontRegular.name + placeholderText: qsTr("command + enter (e.g help)") + translationManager.emptyString + placeholderFontSize: 16 * scaleRatio + onAccepted: { + if(text.length > 0) { + consoleArea.logCommand(">>> " + text) + daemonManager.sendCommand(text, currentWallet.nettype); + } + text = "" + } + } + } + + Component.onCompleted: { + logLevelDropdown.currentIndex = persistentSettings.logLevel; + logLevelDropdown.update(); + + if(typeof daemonManager != "undefined") + daemonManager.daemonConsoleUpdated.connect(onDaemonConsoleUpdated) + } +}