1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Riebeling
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
22 #include "ui_systracefrm.h"
24 #include "rbsettings.h"
26 QString
SysTrace::debugbuffer
;
27 QString
SysTrace::lastmessage
;
28 unsigned int SysTrace::repeat
= 0;
30 SysTrace::SysTrace(QWidget
*parent
) : QDialog(parent
)
33 ui
.textTrace
->setReadOnly(true);
34 ui
.textTrace
->setLayoutDirection(Qt::LeftToRight
);
37 connect(ui
.buttonClose
, SIGNAL(clicked()), this, SLOT(close()));
38 connect(ui
.buttonSave
, SIGNAL(clicked()), this, SLOT(saveCurrentTrace()));
39 connect(ui
.buttonSavePrevious
, SIGNAL(clicked()), this, SLOT(savePreviousTrace()));
40 connect(ui
.buttonRefresh
, SIGNAL(clicked()), this, SLOT(refresh()));
43 void SysTrace::refresh(void)
45 int pos
= ui
.textTrace
->verticalScrollBar()->value();
47 ui
.textTrace
->setHtml("<pre>" + debugbuffer
+ "</pre>");
48 ui
.textTrace
->verticalScrollBar()->setValue(pos
);
49 QString oldlog
= RbSettings::value(RbSettings::CachePath
).toString()
50 + "/rbutil-trace.log";
51 ui
.buttonSavePrevious
->setEnabled(QFileInfo(oldlog
).isFile());
55 void SysTrace::save(QString filename
)
57 if(filename
.isEmpty())
58 filename
= RbSettings::value(RbSettings::CachePath
).toString()
59 + "/rbutil-trace.log";
60 // make sure any repeat detection is flushed
62 // append save date to the trace. Append it directly instead of using
63 // qDebug() as the handler might have been unregistered.
64 debugbuffer
.append("[SysTrace] saving trace at ");
65 debugbuffer
.append(QDateTime::currentDateTime().toString(Qt::ISODate
));
66 debugbuffer
.append("\n");
68 if(!fh
.open(QIODevice::WriteOnly
))
70 fh
.write(debugbuffer
.toUtf8(), debugbuffer
.size());
74 void SysTrace::saveCurrentTrace(void)
76 QString fp
= QFileDialog::getSaveFileName(this, tr("Save system trace log"),
77 QDir::homePath(), "*.log");
83 void SysTrace::savePreviousTrace(void)
85 QString fp
= QFileDialog::getSaveFileName(this, tr("Save system trace log"),
86 QDir::homePath(), "*.log");
90 QString oldlog
= RbSettings::value(RbSettings::CachePath
).toString()
91 + "/rbutil-trace.log";
92 QFile::copy(oldlog
, fp
);
96 void SysTrace::debug(QtMsgType type
, const char* msg
)
99 if(lastmessage
!= msg
) {
102 debugbuffer
.append(msg
);
103 debugbuffer
.append("\n");
104 #if !defined(NODEBUG)
105 fprintf(stderr
, "%s\n", msg
);
114 void SysTrace::flush(void)
118 QString(" (Last message repeasted %1 times.)\n").arg(repeat
));
119 #if !defined(NODEBUG)
120 fprintf(stderr
, " (Last message repeated %i times.)\n", repeat
);