1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-09-04 22:23:32 +02:00

logs preview: added background logging

Change-Id: I31ef642661e99a715af0a1d9992ac540c5d19594
This commit is contained in:
Trevor Tabah 2021-06-15 14:04:30 -04:00 committed by Sébastien Blin
parent 95fa54802b
commit a368444afd
4 changed files with 100 additions and 100 deletions

View file

@ -1100,17 +1100,44 @@ SettingsAdapter::isAllModeratorsEnabled(const QString& accountId)
return lrcInstance_->accountModel().isAllModerators(accountId); return lrcInstance_->accountModel().isAllModerators(accountId);
} }
QString
SettingsAdapter::getLogs() const
{
return logList_.join("\n");
}
int
SettingsAdapter::getSizeOfLogs() const
{
return logList_.size();
}
int
SettingsAdapter::getFirstLogLength() const
{
return logList_.isEmpty() ? 0 : (logList_.first()).length();
}
void
SettingsAdapter::clearLogs()
{
logList_.clear();
}
void void
SettingsAdapter::monitor(const bool& continuous) SettingsAdapter::monitor(const bool& continuous)
{ {
disconnect(debugMessageReceivedConnection_);
if (continuous) if (continuous)
debugMessageReceivedConnection_ debugMessageReceivedConnection_
= QObject::connect(&lrcInstance_->behaviorController(), = QObject::connect(&lrcInstance_->behaviorController(),
&lrc::api::BehaviorController::debugMessageReceived, &lrc::api::BehaviorController::debugMessageReceived,
this, [this](const QString& data) {
&SettingsAdapter::debugMessageReceived, logList_.append(data);
Qt::ConnectionType::UniqueConnection); if (logList_.size() >= LOGSLIMIT) {
else logList_.removeFirst();
disconnect(debugMessageReceivedConnection_); }
Q_EMIT SettingsAdapter::debugMessageReceived(data);
});
lrcInstance_->monitor(continuous); lrcInstance_->monitor(continuous);
} }

View file

@ -31,6 +31,9 @@
class SettingsAdapter : public QmlAdapterBase class SettingsAdapter : public QmlAdapterBase
{ {
Q_OBJECT Q_OBJECT
#define LOGSLIMIT 10000
public: public:
explicit SettingsAdapter(AppSettingsManager* settingsManager, explicit SettingsAdapter(AppSettingsManager* settingsManager,
LRCInstance* instance, LRCInstance* instance,
@ -229,6 +232,10 @@ public:
Q_INVOKABLE bool isAllModeratorsEnabled(const QString& accountId); Q_INVOKABLE bool isAllModeratorsEnabled(const QString& accountId);
Q_INVOKABLE void monitor(const bool& continuous); Q_INVOKABLE void monitor(const bool& continuous);
Q_INVOKABLE QString getLogs() const;
Q_INVOKABLE int getSizeOfLogs() const;
Q_INVOKABLE int getFirstLogLength() const;
Q_INVOKABLE void clearLogs();
Q_SIGNALS: Q_SIGNALS:
void debugMessageReceived(const QString& message); void debugMessageReceived(const QString& message);
@ -237,5 +244,7 @@ private:
AppSettingsManager* settingsManager_; AppSettingsManager* settingsManager_;
QMetaObject::Connection debugMessageReceivedConnection_; QMetaObject::Connection debugMessageReceivedConnection_;
QStringList logList_;
}; };
Q_DECLARE_METATYPE(SettingsAdapter*) Q_DECLARE_METATYPE(SettingsAdapter*)

View file

@ -84,7 +84,6 @@ Rectangle {
Layout.rightMargin: JamiTheme.preferredMarginSize Layout.rightMargin: JamiTheme.preferredMarginSize
Layout.bottomMargin: JamiTheme.preferredMarginSize Layout.bottomMargin: JamiTheme.preferredMarginSize
itemWidth: preferredColumnWidth itemWidth: preferredColumnWidth
visible: Qt.platform.os == "windows" ? false : true
} }
// update setting panel // update setting panel

View file

@ -33,66 +33,58 @@ Dialog {
id: root id: root
property bool cancelPressed: false property bool cancelPressed: false
property bool startedLogs: false property bool logging: false
property bool isStopped: false property bool isStopped: false
property bool hasOpened: false
property int itemWidth: Math.min(root.width / 2 - 50, 350) * 1.5 property int itemWidth: Math.min(root.width / 2 - 50, 350) * 1.5
property int widthDivisor: 4 property int widthDivisor: 4
property int selectBeginning property int selectBeginning
property int selectEnd property int selectEnd
property var lineSize: []
property var lineCounter: 0
function findNthIndexInText(substring, n){
var i;
var t = logsText.text
var index = t.indexOf(substring)
for (i = 0; i < n - 1; i++){
index = t.indexOf(substring, index + 1)
}
return index
}
function monitor(continuous){ function monitor(continuous) {
SettingsAdapter.monitor(continuous) SettingsAdapter.monitor(continuous)
} }
Connections{ Connections{
target: SettingsAdapter target: SettingsAdapter
function onDebugMessageReceived(message){ function onDebugMessageReceived(message) {
var initialPosition = scroll.position if (!root.visible) {
var oldContent = flickable.contentY return;
if (!root.cancelPressed){ }
var initialPosition = scrollView.ScrollBar.vertical.position
lineCounter += 1
lineSize.push(message.length)
if (!root.cancelPressed) {
logsText.append(message); logsText.append(message);
} }
if (logsText.lineCount >= 10000){ if (lineCounter >= 10000){
var index = findNthIndexInText("\n", 10) lineCounter -= 1
logsText.remove(0, index) logsText.remove(0, lineSize[0])
} lineSize.shift()
var approximateBottom = (1.0 - flickable.visibleArea.heightRatio);
if (!isStopped){
if (initialPosition < 0){
flickable.flick(0, -(100))
}
else if (initialPosition >= approximateBottom * .8){
flickable.contentY = flickable.contentHeight - flickable.height
flickable.flick(0, -(flickable.maximumFlickVelocity))
}
else{
flickable.contentY = oldContent
}
} }
scrollView.ScrollBar.vertical.position = initialPosition > (.8*(1.0 - scrollView.ScrollBar.vertical.size)) ? 1.0 - scrollView.ScrollBar.vertical.size : initialPosition
} }
} }
onVisibleChanged: { onVisibleChanged: {
logsText.clear() if (visible && startStopToggle.checked) {
copiedToolTip.close() if (hasOpened && lineCounter == 0) {
if (startStopToggle.checked){ logsText.append(SettingsAdapter.getLogs())
startStopToggle.checked = false lineCounter = SettingsAdapter.getSizeOfLogs()
startedLogs = false lineSize.push(SettingsAdapter.getFirstLogLength())
}
} else {
logsText.clear()
copiedToolTip.close()
lineCounter = 0
lineSize = []
} }
root.cancelPressed = true hasOpened = true
monitor(false)
} }
title: JamiStrings.logsViewTitle title: JamiStrings.logsViewTitle
@ -101,7 +93,7 @@ Dialog {
height: 700 height: 700
standardButtons: StandardButton.NoButton standardButtons: StandardButton.NoButton
ColumnLayout{ ColumnLayout {
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
Layout.fillWidth: true Layout.fillWidth: true
@ -110,8 +102,9 @@ Dialog {
height: root.height height: root.height
width: root.width width: root.width
Rectangle{ Rectangle {
id: buttonRectangleBackground id: buttonRectangleBackground
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
@ -122,7 +115,7 @@ Dialog {
border.width: 0 border.width: 0
height: JamiTheme.preferredFieldHeight*2 height: JamiTheme.preferredFieldHeight*2
RowLayout{ RowLayout {
id: buttons id: buttons
Layout.alignment: Qt.AlignTop| Qt.AlignHCenter Layout.alignment: Qt.AlignTop| Qt.AlignHCenter
@ -140,13 +133,12 @@ Dialog {
fontPointSize: JamiTheme.settingsFontSize fontPointSize: JamiTheme.settingsFontSize
onSwitchToggled: { onSwitchToggled: {
startedLogs = !startedLogs logging = !logging
if (startedLogs){ if (logging){
isStopped = false isStopped = false
root.cancelPressed = false root.cancelPressed = false
monitor(true) monitor(true)
} } else {
else{
isStopped = true isStopped = true
root.cancelPressed = true root.cancelPressed = true
monitor(false) monitor(false)
@ -154,30 +146,7 @@ Dialog {
} }
} }
MaterialButton{ MaterialButton {
id: showStatsButton
Layout.preferredHeight: JamiTheme.preferredFieldHeight
Layout.preferredWidth: itemWidth/widthDivisor
Layout.topMargin: JamiTheme.preferredMarginSize
Layout.bottomMargin: JamiTheme.preferredMarginSize
Layout.alignment: Qt.AlignHCenter
text: JamiStrings.logsViewShowStats
color: startedLogs ? JamiTheme.buttonTintedGreyInactive : JamiTheme.buttonTintedBlack
hoveredColor: startedLogs ? JamiTheme.buttonTintedGreyInactive : JamiTheme.buttonTintedBlackHovered
pressedColor: startedLogs ? JamiTheme.buttonTintedGreyInactive : JamiTheme.buttonTintedBlackPressed
outlined: true
onClicked:{
if (!startedLogs){
root.cancelPressed = false
monitor(false)
}
}
}
MaterialButton{
id: clearButton id: clearButton
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
@ -194,14 +163,15 @@ Dialog {
onClicked: { onClicked: {
logsText.clear() logsText.clear()
startedLogs = false logging = false
startStopToggle.checked = false startStopToggle.checked = false
root.cancelPressed = true root.cancelPressed = true
SettingsAdapter.clearLogs()
monitor(false) monitor(false)
} }
} }
MaterialButton{ MaterialButton {
id: copyButton id: copyButton
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
@ -227,18 +197,16 @@ Dialog {
height: JamiTheme.preferredFieldHeight height: JamiTheme.preferredFieldHeight
TextArea{ TextArea{
text: JamiStrings.logsViewCopied text: JamiStrings.logsViewCopied
color: JamiTheme.textColor color: JamiTheme.textColor
} }
background: Rectangle{ background: Rectangle{
color: JamiTheme.primaryBackgroundColor color: JamiTheme.primaryBackgroundColor
} }
} }
} }
MaterialButton{ MaterialButton {
id: reportButton id: reportButton
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
@ -259,7 +227,7 @@ Dialog {
} }
} }
Rectangle{ Rectangle {
id: flickableRectangleBackground id: flickableRectangleBackground
property alias text: logsText.text property alias text: logsText.text
@ -273,16 +241,14 @@ Dialog {
height: root.height - buttonRectangleBackground.height height: root.height - buttonRectangleBackground.height
Flickable { ScrollView{
id: flickable id: scrollView
Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true
anchors.fill: flickableRectangleBackground anchors.fill: flickableRectangleBackground
boundsBehavior: Flickable.StopAtBounds TextArea{
TextArea.flickable: TextArea {
id: logsText id: logsText
readOnly: true readOnly: true
@ -291,36 +257,35 @@ Dialog {
wrapMode: TextArea.Wrap wrapMode: TextArea.Wrap
selectByMouse: true selectByMouse: true
MouseArea{ MouseArea {
anchors.fill: logsText anchors.fill: logsText
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
hoverEnabled: true hoverEnabled: true
onClicked:{ onClicked: {
selectBeginning = logsText.selectionStart selectBeginning = logsText.selectionStart
selectEnd = logsText.selectionEnd selectEnd = logsText.selectionEnd
rightClickMenu.open() rightClickMenu.open()
logsText.select(selectBeginning, selectEnd) logsText.select(selectBeginning, selectEnd)
} }
Menu{ Menu {
id: rightClickMenu id: rightClickMenu
MenuItem{ MenuItem {
text: JamiStrings.logsViewCopy text: JamiStrings.logsViewCopy
onTriggered:{ onTriggered: {
logsText.copy() logsText.copy()
} }
} }
} }
} }
} }
ScrollBar.vertical: ScrollBar {
id: scroll
}
} }
} }
} }
} }