diff options
Diffstat (limited to 'utils/rbutilqt/systrace.cpp')
-rw-r--r-- | utils/rbutilqt/systrace.cpp | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/utils/rbutilqt/systrace.cpp b/utils/rbutilqt/systrace.cpp new file mode 100644 index 0000000000..a20056b508 --- /dev/null +++ b/utils/rbutilqt/systrace.cpp | |||
@@ -0,0 +1,138 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2007 by Dominik Riebeling | ||
10 | * | ||
11 | * All files in this archive are subject to the GNU General Public License. | ||
12 | * See the file COPYING in the source tree root for full license agreement. | ||
13 | * | ||
14 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
15 | * KIND, either express or implied. | ||
16 | * | ||
17 | ****************************************************************************/ | ||
18 | |||
19 | #include <QFileDialog> | ||
20 | #include <QScrollBar> | ||
21 | #include "systrace.h" | ||
22 | #include "ui_systracefrm.h" | ||
23 | |||
24 | #include "rbsettings.h" | ||
25 | #include "Logger.h" | ||
26 | |||
27 | |||
28 | SysTrace::SysTrace(QWidget *parent) : QDialog(parent) | ||
29 | { | ||
30 | ui.setupUi(this); | ||
31 | ui.textTrace->setReadOnly(true); | ||
32 | ui.textTrace->setLayoutDirection(Qt::LeftToRight); | ||
33 | refresh(); | ||
34 | |||
35 | connect(ui.buttonClose, &QAbstractButton::clicked, this, &SysTrace::close); | ||
36 | connect(ui.buttonSave, &QAbstractButton::clicked, this, &SysTrace::saveCurrentTrace); | ||
37 | connect(ui.buttonSavePrevious, &QAbstractButton::clicked, this, &SysTrace::savePreviousTrace); | ||
38 | connect(ui.buttonRefresh, &QAbstractButton::clicked, this, &SysTrace::refresh); | ||
39 | } | ||
40 | |||
41 | void SysTrace::refresh(void) | ||
42 | { | ||
43 | int pos = ui.textTrace->verticalScrollBar()->value(); | ||
44 | |||
45 | QString debugbuffer; | ||
46 | QFile tracefile(QDir::tempPath() + "/rbutil-trace.log"); | ||
47 | tracefile.open(QIODevice::ReadOnly); | ||
48 | QTextStream c(&tracefile); | ||
49 | QString line; | ||
50 | QString color; | ||
51 | while(!c.atEnd()) { | ||
52 | line = c.readLine(); | ||
53 | if(line.contains("Warning")) | ||
54 | color = "orange"; | ||
55 | else if(line.contains("Error")) | ||
56 | color = "red"; | ||
57 | else if(line.contains("Debug")) | ||
58 | color = "blue"; | ||
59 | #if 0 | ||
60 | else if(line.contains("INFO")) | ||
61 | color = "green"; | ||
62 | #endif | ||
63 | else | ||
64 | color = "black"; | ||
65 | debugbuffer += QString("<div style='color:%1;'>%2</div>").arg(color, line); | ||
66 | } | ||
67 | tracefile.close(); | ||
68 | ui.textTrace->setHtml("<pre>" + debugbuffer + "</pre>"); | ||
69 | ui.textTrace->verticalScrollBar()->setValue(pos); | ||
70 | QString oldlog = RbSettings::value(RbSettings::CachePath).toString() | ||
71 | + "/rbutil-trace.log"; | ||
72 | ui.buttonSavePrevious->setEnabled(QFileInfo(oldlog).isFile()); | ||
73 | } | ||
74 | |||
75 | |||
76 | QString SysTrace::getTrace(void) | ||
77 | { | ||
78 | QString debugbuffer; | ||
79 | QFile tracefile(QDir::tempPath() + "/rbutil-trace.log"); | ||
80 | tracefile.open(QIODevice::ReadOnly); | ||
81 | QTextStream c(&tracefile); | ||
82 | debugbuffer = c.readAll(); | ||
83 | tracefile.close(); | ||
84 | |||
85 | return debugbuffer; | ||
86 | } | ||
87 | |||
88 | |||
89 | void SysTrace::save(QString filename) | ||
90 | { | ||
91 | if(filename.isEmpty()) | ||
92 | return; | ||
93 | LOG_INFO() << "saving trace at" << QDateTime::currentDateTime().toString(Qt::ISODate); | ||
94 | QFile::copy(QDir::tempPath() + "/rbutil-trace.log", filename); | ||
95 | |||
96 | } | ||
97 | |||
98 | void SysTrace::saveCurrentTrace(void) | ||
99 | { | ||
100 | QString fp = QFileDialog::getSaveFileName(this, tr("Save system trace log"), | ||
101 | QDir::homePath(), "*.log"); | ||
102 | if(!fp.isEmpty()) | ||
103 | save(fp); | ||
104 | } | ||
105 | |||
106 | |||
107 | void SysTrace::savePreviousTrace(void) | ||
108 | { | ||
109 | QString fp = QFileDialog::getSaveFileName(this, tr("Save system trace log"), | ||
110 | QDir::homePath(), "*.log"); | ||
111 | if(fp.isEmpty()) | ||
112 | return; | ||
113 | |||
114 | QString oldlog = QDir::tempPath() + "/rbutil-trace.log.1"; | ||
115 | QFile::copy(oldlog, fp); | ||
116 | return; | ||
117 | } | ||
118 | |||
119 | |||
120 | void SysTrace::rotateTrace(void) | ||
121 | { | ||
122 | QString f = QDir::tempPath() + "/rbutil-trace.log.1"; | ||
123 | if(QFileInfo::exists(f)) { | ||
124 | QFile::remove(f); | ||
125 | } | ||
126 | QFile::rename(QDir::tempPath() + "/rbutil-trace.log", f); | ||
127 | } | ||
128 | |||
129 | |||
130 | void SysTrace::changeEvent(QEvent *e) | ||
131 | { | ||
132 | if(e->type() == QEvent::LanguageChange) { | ||
133 | ui.retranslateUi(this); | ||
134 | } else { | ||
135 | QWidget::changeEvent(e); | ||
136 | } | ||
137 | } | ||
138 | |||