Fix some greedy sed changes in imported code. Also provide a sys/types.h for compatib...
[kugel-rb.git] / rbutil / rbutilqt / systrace.cpp
blob1b9de6b71313a00afb7fa38c58ee3b6b84031f33
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;
28 SysTrace::SysTrace(QWidget *parent) : QDialog(parent)
30 ui.setupUi(this);
31 ui.textTrace->setReadOnly(true);
32 ui.textTrace->setLayoutDirection(Qt::LeftToRight);
33 refresh();
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");
62 QFile fh(filename);
63 if(!fh.open(QIODevice::WriteOnly))
64 return;
65 fh.write(debugbuffer.toUtf8(), debugbuffer.size());
66 fh.close();
69 void SysTrace::saveCurrentTrace(void)
71 QString fp = QFileDialog::getSaveFileName(this, tr("Save system trace log"),
72 QDir::homePath(), "*.log");
73 if(!fp.isEmpty())
74 save(fp);
78 void SysTrace::savePreviousTrace(void)
80 QString fp = QFileDialog::getSaveFileName(this, tr("Save system trace log"),
81 QDir::homePath(), "*.log");
82 if(fp.isEmpty())
83 return;
85 QString oldlog = RbSettings::value(RbSettings::CachePath).toString()
86 + "/rbutil-trace.log";
87 QFile::copy(oldlog, fp);
88 return;
91 void SysTrace::debug(QtMsgType type, const char* msg)
93 (void)type;
94 debugbuffer.append(msg);
95 debugbuffer.append("\n");
96 #if !defined(NODEBUG)
97 fprintf(stderr, "%s\n", msg);
98 #endif