mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-09-05 14:43:39 +02:00
logs preview: added background logging
Change-Id: I31ef642661e99a715af0a1d9992ac540c5d19594
This commit is contained in:
parent
95fa54802b
commit
a368444afd
4 changed files with 100 additions and 100 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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*)
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -33,23 +33,18 @@ 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)
|
||||||
|
@ -58,41 +53,38 @@ Dialog {
|
||||||
Connections{
|
Connections{
|
||||||
target: SettingsAdapter
|
target: SettingsAdapter
|
||||||
function onDebugMessageReceived(message) {
|
function onDebugMessageReceived(message) {
|
||||||
var initialPosition = scroll.position
|
if (!root.visible) {
|
||||||
var oldContent = flickable.contentY
|
return;
|
||||||
|
}
|
||||||
|
var initialPosition = scrollView.ScrollBar.vertical.position
|
||||||
|
lineCounter += 1
|
||||||
|
lineSize.push(message.length)
|
||||||
if (!root.cancelPressed) {
|
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: {
|
||||||
|
if (visible && startStopToggle.checked) {
|
||||||
|
if (hasOpened && lineCounter == 0) {
|
||||||
|
logsText.append(SettingsAdapter.getLogs())
|
||||||
|
lineCounter = SettingsAdapter.getSizeOfLogs()
|
||||||
|
lineSize.push(SettingsAdapter.getFirstLogLength())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
logsText.clear()
|
logsText.clear()
|
||||||
copiedToolTip.close()
|
copiedToolTip.close()
|
||||||
if (startStopToggle.checked){
|
lineCounter = 0
|
||||||
startStopToggle.checked = false
|
lineSize = []
|
||||||
startedLogs = false
|
|
||||||
}
|
}
|
||||||
root.cancelPressed = true
|
hasOpened = true
|
||||||
monitor(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
title: JamiStrings.logsViewTitle
|
title: JamiStrings.logsViewTitle
|
||||||
|
@ -112,6 +104,7 @@ Dialog {
|
||||||
|
|
||||||
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
|
||||||
|
@ -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,29 +146,6 @@ Dialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
MaterialButton {
|
||||||
id: clearButton
|
id: clearButton
|
||||||
|
|
||||||
|
@ -194,9 +163,10 @@ 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,8 +200,6 @@ Dialog {
|
||||||
text: JamiStrings.logsViewCopied
|
text: JamiStrings.logsViewCopied
|
||||||
color: JamiTheme.textColor
|
color: JamiTheme.textColor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
background: Rectangle{
|
background: Rectangle{
|
||||||
color: JamiTheme.primaryBackgroundColor
|
color: JamiTheme.primaryBackgroundColor
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -315,12 +281,11 @@ Dialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ScrollBar.vertical: ScrollBar {
|
|
||||||
id: scroll
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue