diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp index 292a002..ececb78 100644 --- a/rbutil/rbutilqt/rbutilqt.cpp +++ b/rbutil/rbutilqt/rbutilqt.cpp @@ -149,6 +149,7 @@ void RbUtilQt::shutdown(void) // object destruction -- the trace object could already be destroyed. // Fixes segfaults on exit. qInstallMsgHandler(0); + SysTrace::save(); this->close(); } diff --git a/rbutil/rbutilqt/systrace.cpp b/rbutil/rbutilqt/systrace.cpp index 1aed5c0..6f2f9ba 100644 --- a/rbutil/rbutilqt/systrace.cpp +++ b/rbutil/rbutilqt/systrace.cpp @@ -21,6 +21,7 @@ #include "systrace.h" #include "ui_systracefrm.h" +#include "rbsettings.h" QString SysTrace::debugbuffer; @@ -32,7 +33,8 @@ SysTrace::SysTrace(QWidget *parent) : QDialog(parent) refresh(); connect(ui.buttonClose, SIGNAL(clicked()), this, SLOT(close())); - connect(ui.buttonSave, SIGNAL(clicked()), this, SLOT(save())); + connect(ui.buttonSave, SIGNAL(clicked()), this, SLOT(saveCurrentTrace())); + connect(ui.buttonSavePrevious, SIGNAL(clicked()), this, SLOT(savePreviousTrace())); connect(ui.buttonRefresh, SIGNAL(clicked()), this, SLOT(refresh())); } @@ -41,22 +43,49 @@ void SysTrace::refresh(void) int pos = ui.textTrace->verticalScrollBar()->value(); ui.textTrace->setHtml("
" + debugbuffer + "
"); ui.textTrace->verticalScrollBar()->setValue(pos); + QString oldlog = RbSettings::value(RbSettings::CachePath).toString() + + "/rbutil-trace.log"; + ui.buttonSavePrevious->setEnabled(QFileInfo(oldlog).isFile()); } -void SysTrace::save(void) + +void SysTrace::save(QString filename) { - QString fp = QFileDialog::getSaveFileName(this, tr("Save system trace log"), - QDir::homePath(), "*.log"); - if(fp == "") - return; - - QFile fh(fp); + if(filename.isEmpty()) + filename = RbSettings::value(RbSettings::CachePath).toString() + + "/rbutil-trace.log"; + debugbuffer.append("[SysTrace] saving trace at "); + debugbuffer.append(QDateTime::currentDateTime().toString(Qt::ISODate)); + debugbuffer.append("\n"); + QFile fh(filename); if(!fh.open(QIODevice::WriteOnly)) return; fh.write(debugbuffer.toUtf8(), debugbuffer.size()); fh.close(); } +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; +} + void SysTrace::debug(QtMsgType type, const char* msg) { (void)type; diff --git a/rbutil/rbutilqt/systrace.h b/rbutil/rbutilqt/systrace.h index a8253ce..4e6206a 100644 --- a/rbutil/rbutilqt/systrace.h +++ b/rbutil/rbutilqt/systrace.h @@ -31,14 +31,15 @@ class SysTrace : public QDialog public: SysTrace(QWidget *parent); static void debug(QtMsgType type, const char* msg); - static QString getTrace() {return debugbuffer;} + static void save(QString filename = ""); private: Ui::SysTraceFrm ui; static QString debugbuffer; private slots: - void save(void); + void saveCurrentTrace(void); + void savePreviousTrace(void); void refresh(void); }; diff --git a/rbutil/rbutilqt/systracefrm.ui b/rbutil/rbutilqt/systracefrm.ui index 7a83eec..eb8bb6d 100644 --- a/rbutil/rbutilqt/systracefrm.ui +++ b/rbutil/rbutilqt/systracefrm.ui @@ -1,7 +1,8 @@ - + + SysTraceFrm - - + + 0 0 @@ -9,29 +10,29 @@ 550 - + System Trace - - - - + + + + System State trace - + true - - + + - - - + + + Qt::Horizontal - + 487 26 @@ -39,43 +40,54 @@ - - - + + + &Close - - + + :/icons/process-stop.png:/icons/process-stop.png - - - + + + &Save - - + + :/icons/document-save.png:/icons/document-save.png - - - + + + &Refresh - - + + :/icons/view-refresh.png:/icons/view-refresh.png + + + + Save &previous + + + + :/icons/document-save.png:/icons/document-save.png + + + - +