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"
|
2009-08-15 17:02:25 +00:00
|
|
|
|
|
|
|
QString SysTrace::debugbuffer;
|
2010-05-07 16:18:41 +00:00
|
|
|
QString SysTrace::lastmessage;
|
|
|
|
unsigned int SysTrace::repeat = 0;
|
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();
|
|
|
|
|
|
|
|
connect(ui.buttonClose, SIGNAL(clicked()), this, SLOT(close()));
|
2010-03-23 22:07:17 +00:00
|
|
|
connect(ui.buttonSave, SIGNAL(clicked()), this, SLOT(saveCurrentTrace()));
|
|
|
|
connect(ui.buttonSavePrevious, SIGNAL(clicked()), this, SLOT(savePreviousTrace()));
|
2009-08-15 17:02:25 +00:00
|
|
|
connect(ui.buttonRefresh, SIGNAL(clicked()), this, SLOT(refresh()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SysTrace::refresh(void)
|
|
|
|
{
|
|
|
|
int pos = ui.textTrace->verticalScrollBar()->value();
|
2010-05-07 16:18:41 +00:00
|
|
|
flush();
|
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
|
|
|
|
|
|
|
void SysTrace::save(QString filename)
|
2009-08-15 17:02:25 +00:00
|
|
|
{
|
2010-03-23 22:07:17 +00:00
|
|
|
if(filename.isEmpty())
|
|
|
|
filename = RbSettings::value(RbSettings::CachePath).toString()
|
|
|
|
+ "/rbutil-trace.log";
|
2010-05-07 16:18:41 +00:00
|
|
|
// make sure any repeat detection is flushed
|
|
|
|
flush();
|
2010-03-23 22:07:17 +00:00
|
|
|
// append save date to the trace. Append it directly instead of using
|
|
|
|
// qDebug() as the handler might have been unregistered.
|
|
|
|
debugbuffer.append("[SysTrace] saving trace at ");
|
|
|
|
debugbuffer.append(QDateTime::currentDateTime().toString(Qt::ISODate));
|
|
|
|
debugbuffer.append("\n");
|
|
|
|
QFile fh(filename);
|
2009-08-29 18:55:52 +00:00
|
|
|
if(!fh.open(QIODevice::WriteOnly))
|
|
|
|
return;
|
2009-08-15 17:02:25 +00:00
|
|
|
fh.write(debugbuffer.toUtf8(), debugbuffer.size());
|
|
|
|
fh.close();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
QString oldlog = RbSettings::value(RbSettings::CachePath).toString()
|
|
|
|
+ "/rbutil-trace.log";
|
|
|
|
QFile::copy(oldlog, fp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-28 20:18:12 +00:00
|
|
|
#if QT_VERSION < 0x050000
|
2009-08-15 17:02:25 +00:00
|
|
|
void SysTrace::debug(QtMsgType type, const char* msg)
|
|
|
|
{
|
2009-08-15 18:57:58 +00:00
|
|
|
(void)type;
|
2010-05-07 16:18:41 +00:00
|
|
|
if(lastmessage != msg) {
|
|
|
|
lastmessage = msg;
|
|
|
|
flush();
|
2011-02-04 21:08:59 +00:00
|
|
|
debugbuffer.append(QString::fromLocal8Bit(msg) + "\n");
|
2009-08-15 17:02:25 +00:00
|
|
|
#if !defined(NODEBUG)
|
2010-05-07 16:18:41 +00:00
|
|
|
fprintf(stderr, "%s\n", msg);
|
2009-08-15 17:02:25 +00:00
|
|
|
#endif
|
2010-05-07 16:18:41 +00:00
|
|
|
repeat = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
repeat++;
|
|
|
|
}
|
|
|
|
}
|
2013-01-28 20:18:12 +00:00
|
|
|
#else
|
|
|
|
void SysTrace::debug(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
|
|
|
{
|
|
|
|
(void)type;
|
2013-04-03 21:43:27 +00:00
|
|
|
(void)context;
|
2013-01-28 20:18:12 +00:00
|
|
|
QByteArray localMsg = msg.toLocal8Bit();
|
|
|
|
if(lastmessage != msg) {
|
|
|
|
lastmessage = msg;
|
|
|
|
flush();
|
|
|
|
debugbuffer.append(msg + "\n");
|
|
|
|
#if !defined(NODEBUG)
|
|
|
|
fprintf(stderr, "%s\n", localMsg.constData());
|
|
|
|
#endif
|
|
|
|
repeat = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
repeat++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2009-08-15 17:02:25 +00:00
|
|
|
|
2010-05-07 16:18:41 +00:00
|
|
|
void SysTrace::flush(void)
|
|
|
|
{
|
|
|
|
if(repeat > 1) {
|
|
|
|
debugbuffer.append(
|
2010-07-28 18:37:07 +00:00
|
|
|
QString(" (Last message repeated %1 times.)\n").arg(repeat));
|
2010-05-07 16:18:41 +00:00
|
|
|
#if !defined(NODEBUG)
|
|
|
|
fprintf(stderr, " (Last message repeated %i times.)\n", repeat);
|
|
|
|
#endif
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|