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
;
28 SysTrace::SysTrace(QWidget
*parent
) : QDialog(parent
)
31 ui
.textTrace
->setReadOnly(true);
32 ui
.textTrace
->setLayoutDirection(Qt::LeftToRight
);
35 connect(ui
.buttonClose
, SIGNAL(clicked()), this, SLOT(close()));
36 connect(ui
.buttonSave
, SIGNAL(clicked()), this, SLOT(saveCurrentTrace()));
37 connect(ui
.buttonSavePrevious
, SIGNAL(clicked()), this, SLOT(savePreviousTrace()));
38 connect(ui
.buttonRefresh
, SIGNAL(clicked()), this, SLOT(refresh()));
41 void SysTrace::refresh(void)
43 int pos
= ui
.textTrace
->verticalScrollBar()->value();
44 ui
.textTrace
->setHtml("<pre>" + debugbuffer
+ "</pre>");
45 ui
.textTrace
->verticalScrollBar()->setValue(pos
);
46 QString oldlog
= RbSettings::value(RbSettings::CachePath
).toString()
47 + "/rbutil-trace.log";
48 ui
.buttonSavePrevious
->setEnabled(QFileInfo(oldlog
).isFile());
52 void SysTrace::save(QString filename
)
54 if(filename
.isEmpty())
55 filename
= RbSettings::value(RbSettings::CachePath
).toString()
56 + "/rbutil-trace.log";
57 // append save date to the trace. Append it directly instead of using
58 // qDebug() as the handler might have been unregistered.
59 debugbuffer
.append("[SysTrace] saving trace at ");
60 debugbuffer
.append(QDateTime::currentDateTime().toString(Qt::ISODate
));
61 debugbuffer
.append("\n");
63 if(!fh
.open(QIODevice::WriteOnly
))
65 fh
.write(debugbuffer
.toUtf8(), debugbuffer
.size());
69 void SysTrace::saveCurrentTrace(void)
71 QString fp
= QFileDialog::getSaveFileName(this, tr("Save system trace log"),
72 QDir::homePath(), "*.log");
78 void SysTrace::savePreviousTrace(void)
80 QString fp
= QFileDialog::getSaveFileName(this, tr("Save system trace log"),
81 QDir::homePath(), "*.log");
85 QString oldlog
= RbSettings::value(RbSettings::CachePath
).toString()
86 + "/rbutil-trace.log";
87 QFile::copy(oldlog
, fp
);
91 void SysTrace::debug(QtMsgType type
, const char* msg
)
94 debugbuffer
.append(msg
);
95 debugbuffer
.append("\n");
97 fprintf(stderr
, "%s\n", msg
);