2009-08-15 17:02:25 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Dominik Riebeling
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-01-27 11:01:56 +00:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QScrollBar>
|
2009-08-15 17:02:25 +00:00
|
|
|
#include "systrace.h"
|
|
|
|
#include "ui_systracefrm.h"
|
|
|
|
|
2010-03-23 22:07:17 +00:00
|
|
|
#include "rbsettings.h"
|
2013-11-03 10:08:18 +00:00
|
|
|
#include "Logger.h"
|
2009-08-15 17:02:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
SysTrace::SysTrace(QWidget *parent) : QDialog(parent)
|
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
|
|
|
ui.textTrace->setReadOnly(true);
|
2009-10-31 17:16:34 +00:00
|
|
|
ui.textTrace->setLayoutDirection(Qt::LeftToRight);
|
2009-08-15 17:02:25 +00:00
|
|
|
refresh();
|
|
|
|
|
2020-11-22 18:48:08 +00:00
|
|
|
connect(ui.buttonClose, &QAbstractButton::clicked, this, &SysTrace::close);
|
|
|
|
connect(ui.buttonSave, &QAbstractButton::clicked, this, &SysTrace::saveCurrentTrace);
|
|
|
|
connect(ui.buttonSavePrevious, &QAbstractButton::clicked, this, &SysTrace::savePreviousTrace);
|
|
|
|
connect(ui.buttonRefresh, &QAbstractButton::clicked, this, &SysTrace::refresh);
|
2009-08-15 17:02:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SysTrace::refresh(void)
|
|
|
|
{
|
|
|
|
int pos = ui.textTrace->verticalScrollBar()->value();
|
2013-11-03 10:08:18 +00:00
|
|
|
|
|
|
|
QString debugbuffer;
|
|
|
|
QFile tracefile(QDir::tempPath() + "/rbutil-trace.log");
|
|
|
|
tracefile.open(QIODevice::ReadOnly);
|
|
|
|
QTextStream c(&tracefile);
|
|
|
|
QString line;
|
|
|
|
QString color;
|
|
|
|
while(!c.atEnd()) {
|
|
|
|
line = c.readLine();
|
2020-06-08 19:13:11 +00:00
|
|
|
if(line.contains("Warning"))
|
2013-11-03 10:08:18 +00:00
|
|
|
color = "orange";
|
2020-06-08 19:13:11 +00:00
|
|
|
else if(line.contains("Error"))
|
2013-11-03 10:08:18 +00:00
|
|
|
color = "red";
|
2020-06-08 19:13:11 +00:00
|
|
|
else if(line.contains("Debug"))
|
2015-12-28 11:20:33 +00:00
|
|
|
color = "blue";
|
2013-11-03 10:08:18 +00:00
|
|
|
#if 0
|
|
|
|
else if(line.contains("INFO"))
|
|
|
|
color = "green";
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
color = "black";
|
|
|
|
debugbuffer += QString("<div style='color:%1;'>%2</div>").arg(color, line);
|
|
|
|
}
|
|
|
|
tracefile.close();
|
2009-08-15 17:02:25 +00:00
|
|
|
ui.textTrace->setHtml("<pre>" + debugbuffer + "</pre>");
|
|
|
|
ui.textTrace->verticalScrollBar()->setValue(pos);
|
2010-03-23 22:07:17 +00:00
|
|
|
QString oldlog = RbSettings::value(RbSettings::CachePath).toString()
|
|
|
|
+ "/rbutil-trace.log";
|
|
|
|
ui.buttonSavePrevious->setEnabled(QFileInfo(oldlog).isFile());
|
2009-08-15 17:02:25 +00:00
|
|
|
}
|
|
|
|
|
2010-03-23 22:07:17 +00:00
|
|
|
|
2013-11-03 10:08:18 +00:00
|
|
|
QString SysTrace::getTrace(void)
|
|
|
|
{
|
|
|
|
QString debugbuffer;
|
|
|
|
QFile tracefile(QDir::tempPath() + "/rbutil-trace.log");
|
|
|
|
tracefile.open(QIODevice::ReadOnly);
|
|
|
|
QTextStream c(&tracefile);
|
|
|
|
debugbuffer = c.readAll();
|
|
|
|
tracefile.close();
|
|
|
|
|
|
|
|
return debugbuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 22:07:17 +00:00
|
|
|
void SysTrace::save(QString filename)
|
2009-08-15 17:02:25 +00:00
|
|
|
{
|
2010-03-23 22:07:17 +00:00
|
|
|
if(filename.isEmpty())
|
2009-08-29 18:55:52 +00:00
|
|
|
return;
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "saving trace at" << QDateTime::currentDateTime().toString(Qt::ISODate);
|
|
|
|
QFile::copy(QDir::tempPath() + "/rbutil-trace.log", filename);
|
|
|
|
|
2009-08-15 17:02:25 +00:00
|
|
|
}
|
|
|
|
|
2010-03-23 22:07:17 +00:00
|
|
|
void SysTrace::saveCurrentTrace(void)
|
|
|
|
{
|
|
|
|
QString fp = QFileDialog::getSaveFileName(this, tr("Save system trace log"),
|
|
|
|
QDir::homePath(), "*.log");
|
|
|
|
if(!fp.isEmpty())
|
|
|
|
save(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SysTrace::savePreviousTrace(void)
|
|
|
|
{
|
|
|
|
QString fp = QFileDialog::getSaveFileName(this, tr("Save system trace log"),
|
|
|
|
QDir::homePath(), "*.log");
|
|
|
|
if(fp.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2013-11-03 10:08:18 +00:00
|
|
|
QString oldlog = QDir::tempPath() + "/rbutil-trace.log.1";
|
2010-03-23 22:07:17 +00:00
|
|
|
QFile::copy(oldlog, fp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-15 17:02:25 +00:00
|
|
|
|
2013-11-03 10:08:18 +00:00
|
|
|
void SysTrace::rotateTrace(void)
|
2010-05-07 16:18:41 +00:00
|
|
|
{
|
2013-11-03 10:08:18 +00:00
|
|
|
QString f = QDir::tempPath() + "/rbutil-trace.log.1";
|
2020-11-19 19:52:09 +00:00
|
|
|
if(QFileInfo::exists(f)) {
|
2013-11-03 10:08:18 +00:00
|
|
|
QFile::remove(f);
|
2010-05-07 16:18:41 +00:00
|
|
|
}
|
2013-11-03 10:08:18 +00:00
|
|
|
QFile::rename(QDir::tempPath() + "/rbutil-trace.log", f);
|
2009-08-15 17:02:25 +00:00
|
|
|
}
|
|
|
|
|
2011-10-02 14:30:05 +00:00
|
|
|
|
|
|
|
void SysTrace::changeEvent(QEvent *e)
|
|
|
|
{
|
|
|
|
if(e->type() == QEvent::LanguageChange) {
|
|
|
|
ui.retranslateUi(this);
|
|
|
|
} else {
|
|
|
|
QWidget::changeEvent(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|