1 |
// qsamplerMessages.cpp |
// qsamplerMessages.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2017, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2020, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007, Christian Schoenebeck |
Copyright (C) 2007, Christian Schoenebeck |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
63 |
QDockWidget::setObjectName("qsamplerMessages"); |
QDockWidget::setObjectName("qsamplerMessages"); |
64 |
|
|
65 |
// Intialize stdout capture stuff. |
// Intialize stdout capture stuff. |
66 |
m_pStdoutNotifier = NULL; |
m_pStdoutNotifier = nullptr; |
67 |
m_fdStdout[QSAMPLER_MESSAGES_FDREAD] = QSAMPLER_MESSAGES_FDNIL; |
m_fdStdout[QSAMPLER_MESSAGES_FDREAD] = QSAMPLER_MESSAGES_FDNIL; |
68 |
m_fdStdout[QSAMPLER_MESSAGES_FDWRITE] = QSAMPLER_MESSAGES_FDNIL; |
m_fdStdout[QSAMPLER_MESSAGES_FDWRITE] = QSAMPLER_MESSAGES_FDNIL; |
69 |
|
|
81 |
m_iMessagesLines = 0; |
m_iMessagesLines = 0; |
82 |
setMessagesLimit(QSAMPLER_MESSAGES_MAXLINES); |
setMessagesLimit(QSAMPLER_MESSAGES_MAXLINES); |
83 |
|
|
84 |
m_pMessagesLog = NULL; |
m_pMessagesLog = nullptr; |
85 |
|
|
86 |
// Prepare the dockable window stuff. |
// Prepare the dockable window stuff. |
87 |
QDockWidget::setWidget(m_pMessagesTextView); |
QDockWidget::setWidget(m_pMessagesTextView); |
182 |
// Stdout capture accessors. |
// Stdout capture accessors. |
183 |
bool Messages::isCaptureEnabled (void) |
bool Messages::isCaptureEnabled (void) |
184 |
{ |
{ |
185 |
return (m_pStdoutNotifier != NULL); |
return (m_pStdoutNotifier != nullptr); |
186 |
} |
} |
187 |
|
|
188 |
void Messages::setCaptureEnabled ( bool bCapture ) |
void Messages::setCaptureEnabled ( bool bCapture ) |
194 |
// Destroy if already enabled. |
// Destroy if already enabled. |
195 |
if (!bCapture && m_pStdoutNotifier) { |
if (!bCapture && m_pStdoutNotifier) { |
196 |
delete m_pStdoutNotifier; |
delete m_pStdoutNotifier; |
197 |
m_pStdoutNotifier = NULL; |
m_pStdoutNotifier = nullptr; |
198 |
// Close the notification pipes. |
// Close the notification pipes. |
199 |
if (m_fdStdout[QSAMPLER_MESSAGES_FDREAD] != QSAMPLER_MESSAGES_FDNIL) { |
if (m_fdStdout[QSAMPLER_MESSAGES_FDREAD] != QSAMPLER_MESSAGES_FDNIL) { |
200 |
::close(m_fdStdout[QSAMPLER_MESSAGES_FDREAD]); |
::close(m_fdStdout[QSAMPLER_MESSAGES_FDREAD]); |
202 |
} |
} |
203 |
} |
} |
204 |
// Are we going to make up the capture? |
// Are we going to make up the capture? |
205 |
if (bCapture && m_pStdoutNotifier == NULL && ::pipe(m_fdStdout) == 0) { |
if (bCapture && m_pStdoutNotifier == nullptr && ::pipe(m_fdStdout) == 0) { |
206 |
::dup2(m_fdStdout[QSAMPLER_MESSAGES_FDWRITE], STDOUT_FILENO); |
::dup2(m_fdStdout[QSAMPLER_MESSAGES_FDWRITE], STDOUT_FILENO); |
207 |
::dup2(m_fdStdout[QSAMPLER_MESSAGES_FDWRITE], STDERR_FILENO); |
::dup2(m_fdStdout[QSAMPLER_MESSAGES_FDWRITE], STDERR_FILENO); |
208 |
m_pStdoutNotifier = new QSocketNotifier( |
m_pStdoutNotifier = new QSocketNotifier( |
242 |
// Messages logging stuff. |
// Messages logging stuff. |
243 |
bool Messages::isLogging (void) const |
bool Messages::isLogging (void) const |
244 |
{ |
{ |
245 |
return (m_pMessagesLog != NULL); |
return (m_pMessagesLog != nullptr); |
246 |
} |
} |
247 |
|
|
248 |
void Messages::setLogging ( bool bEnabled, const QString& sFilename ) |
void Messages::setLogging ( bool bEnabled, const QString& sFilename ) |
252 |
.arg(QDateTime::currentDateTime().toString())); |
.arg(QDateTime::currentDateTime().toString())); |
253 |
m_pMessagesLog->close(); |
m_pMessagesLog->close(); |
254 |
delete m_pMessagesLog; |
delete m_pMessagesLog; |
255 |
m_pMessagesLog = NULL; |
m_pMessagesLog = nullptr; |
256 |
} |
} |
257 |
|
|
258 |
if (bEnabled) { |
if (bEnabled) { |
262 |
.arg(QDateTime::currentDateTime().toString())); |
.arg(QDateTime::currentDateTime().toString())); |
263 |
} else { |
} else { |
264 |
delete m_pMessagesLog; |
delete m_pMessagesLog; |
265 |
m_pMessagesLog = NULL; |
m_pMessagesLog = nullptr; |
266 |
} |
} |
267 |
} |
} |
268 |
} |
} |
272 |
void Messages::appendMessagesLog ( const QString& s ) |
void Messages::appendMessagesLog ( const QString& s ) |
273 |
{ |
{ |
274 |
if (m_pMessagesLog) { |
if (m_pMessagesLog) { |
275 |
QTextStream(m_pMessagesLog) << s << endl; |
QTextStream(m_pMessagesLog) << s << Qt::endl; |
276 |
m_pMessagesLog->flush(); |
m_pMessagesLog->flush(); |
277 |
} |
} |
278 |
} |
} |