Give pitch_detector the IRAMming it deserves.
[kugel-rb.git] / rbutil / rbutilqt / systrace.cpp
bloba1e8bd023936b8b76c6a15d9a0051c00ae54384b
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Riebeling
10 * $Id$
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 ****************************************************************************/
20 #include <QtGui>
21 #include "systrace.h"
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)
32 ui.setupUi(this);
33 ui.textTrace->setReadOnly(true);
34 ui.textTrace->setLayoutDirection(Qt::LeftToRight);
35 refresh();
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();
46 flush();
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
61 flush();
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");
67 QFile fh(filename);
68 if(!fh.open(QIODevice::WriteOnly))
69 return;
70 fh.write(debugbuffer.toUtf8(), debugbuffer.size());
71 fh.close();
74 void SysTrace::saveCurrentTrace(void)
76 QString fp = QFileDialog::getSaveFileName(this, tr("Save system trace log"),
77 QDir::homePath(), "*.log");
78 if(!fp.isEmpty())
79 save(fp);
83 void SysTrace::savePreviousTrace(void)
85 QString fp = QFileDialog::getSaveFileName(this, tr("Save system trace log"),
86 QDir::homePath(), "*.log");
87 if(fp.isEmpty())
88 return;
90 QString oldlog = RbSettings::value(RbSettings::CachePath).toString()
91 + "/rbutil-trace.log";
92 QFile::copy(oldlog, fp);
93 return;
96 void SysTrace::debug(QtMsgType type, const char* msg)
98 (void)type;
99 if(lastmessage != msg) {
100 lastmessage = msg;
101 flush();
102 debugbuffer.append(msg);
103 debugbuffer.append("\n");
104 #if !defined(NODEBUG)
105 fprintf(stderr, "%s\n", msg);
106 #endif
107 repeat = 1;
109 else {
110 repeat++;
114 void SysTrace::flush(void)
116 if(repeat > 1) {
117 debugbuffer.append(
118 QString(" (Last message repeasted %1 times.)\n").arg(repeat));
119 #if !defined(NODEBUG)
120 fprintf(stderr, " (Last message repeated %i times.)\n", repeat);
121 #endif