/[svn]/qsampler/trunk/src/qsamplerMessages.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerMessages.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3358 by capela, Wed Oct 18 08:57:21 2017 UTC revision 3855 by capela, Thu Feb 4 10:09:42 2021 UTC
# Line 1  Line 1 
1  // qsamplerMessages.cpp  // qsamplerMessages.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2017, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2021, 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
# Line 26  Line 26 
26  #include <QSocketNotifier>  #include <QSocketNotifier>
27    
28  #include <QFile>  #include <QFile>
29  #include <QTextEdit>  #include <QTextBrowser>
30  #include <QTextCursor>  #include <QTextCursor>
31  #include <QTextStream>  #include <QTextStream>
32  #include <QTextBlock>  #include <QTextBlock>
 #include <QScrollBar>  
33  #include <QDateTime>  #include <QDateTime>
34  #include <QIcon>  #include <QIcon>
35    
# Line 40  Line 39 
39  #endif  #endif
40    
41    
42    // Deprecated QTextStreamFunctions/Qt namespaces workaround.
43    #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
44    #define endl    Qt::endl
45    #endif
46    
47    
48  namespace QSampler {  namespace QSampler {
49    
50  // The default maximum number of message lines.  // The default maximum number of message lines.
# Line 63  Messages::Messages ( QWidget *pParent ) Line 68  Messages::Messages ( QWidget *pParent )
68          QDockWidget::setObjectName("qsamplerMessages");          QDockWidget::setObjectName("qsamplerMessages");
69    
70          // Intialize stdout capture stuff.          // Intialize stdout capture stuff.
71          m_pStdoutNotifier = NULL;          m_pStdoutNotifier = nullptr;
72          m_fdStdout[QSAMPLER_MESSAGES_FDREAD]  = QSAMPLER_MESSAGES_FDNIL;          m_fdStdout[QSAMPLER_MESSAGES_FDREAD]  = QSAMPLER_MESSAGES_FDNIL;
73          m_fdStdout[QSAMPLER_MESSAGES_FDWRITE] = QSAMPLER_MESSAGES_FDNIL;          m_fdStdout[QSAMPLER_MESSAGES_FDWRITE] = QSAMPLER_MESSAGES_FDNIL;
74    
75          // Create local text view widget.          // Create local text view widget.
76          m_pMessagesTextView = new QTextEdit(this);          m_pMessagesTextView = new QTextBrowser(this);
77  //  QFont font(m_pMessagesTextView->font());  //  QFont font(m_pMessagesTextView->font());
78  //  font.setFamily("Fixed");  //  font.setFamily("Fixed");
79  //  m_pMessagesTextView->setFont(font);  //  m_pMessagesTextView->setFont(font);
80          m_pMessagesTextView->setLineWrapMode(QTextEdit::NoWrap);          m_pMessagesTextView->setLineWrapMode(QTextEdit::NoWrap);
81          m_pMessagesTextView->setReadOnly(true);  //      m_pMessagesTextView->setReadOnly(true);
82          m_pMessagesTextView->setUndoRedoEnabled(false);  //      m_pMessagesTextView->setUndoRedoEnabled(false);
83  //      m_pMessagesTextView->setTextFormat(Qt::LogText);  //      m_pMessagesTextView->setTextFormat(Qt::LogText);
84    
85          // Initialize default message limit.          // Initialize default message limit.
86          m_iMessagesLines = 0;          m_iMessagesLines = 0;
87          setMessagesLimit(QSAMPLER_MESSAGES_MAXLINES);          setMessagesLimit(QSAMPLER_MESSAGES_MAXLINES);
88    
89          m_pMessagesLog = NULL;          m_pMessagesLog = nullptr;
90    
91          // Prepare the dockable window stuff.          // Prepare the dockable window stuff.
92          QDockWidget::setWidget(m_pMessagesTextView);          QDockWidget::setWidget(m_pMessagesTextView);
93          QDockWidget::setFeatures(QDockWidget::AllDockWidgetFeatures);  //      QDockWidget::setFeatures(QDockWidget::AllDockWidgetFeatures);
94          QDockWidget::setAllowedAreas(          QDockWidget::setAllowedAreas(
95                  Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);                  Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
96          // Some specialties to this kind of dock window...          // Some specialties to this kind of dock window...
# Line 113  Messages::~Messages (void) Line 118  Messages::~Messages (void)
118  }  }
119    
120    
121    #if defined(Q_CC_GNU) || defined(Q_CC_MINGW)
122    #pragma GCC diagnostic push
123    #pragma GCC diagnostic ignored "-Wunused-parameter"
124    #endif
125    
126  // Set stdout/stderr blocking mode.  // Set stdout/stderr blocking mode.
127  bool Messages::stdoutBlock ( int fd, bool bBlock ) const  bool Messages::stdoutBlock ( int fd, bool bBlock ) const
128  {  {
# Line 151  void Messages::stdoutNotify ( int fd ) Line 161  void Messages::stdoutNotify ( int fd )
161  #endif  #endif
162  }  }
163    
164    #if defined(Q_CC_GNU) || defined(Q_CC_MINGW)
165    #pragma GCC diagnostic pop
166    #endif
167    
168    
169  // Stdout buffer handler -- now splitted by complete new-lines...  // Stdout buffer handler -- now splitted by complete new-lines...
170  void Messages::appendStdoutBuffer ( const QString& s )  void Messages::appendStdoutBuffer ( const QString& s )
171  {  {
172          m_sStdoutBuffer.append(s);          m_sStdoutBuffer.append(s);
173    
174            processStdoutBuffer();
175    }
176    
177    void Messages::processStdoutBuffer (void)
178    {
179          const int iLength = m_sStdoutBuffer.lastIndexOf('\n');          const int iLength = m_sStdoutBuffer.lastIndexOf('\n');
180          if (iLength > 0) {          if (iLength > 0) {
181                  const QString& sTemp = m_sStdoutBuffer.left(iLength);                  const QString& sTemp = m_sStdoutBuffer.left(iLength);
# Line 173  void Messages::appendStdoutBuffer ( cons Line 192  void Messages::appendStdoutBuffer ( cons
192  void Messages::flushStdoutBuffer (void)  void Messages::flushStdoutBuffer (void)
193  {  {
194          if (!m_sStdoutBuffer.isEmpty()) {          if (!m_sStdoutBuffer.isEmpty()) {
195                  appendMessagesText(m_sStdoutBuffer);                  processStdoutBuffer();
196                  m_sStdoutBuffer.clear();                  m_sStdoutBuffer.clear();
197          }          }
198  }  }
# Line 182  void Messages::flushStdoutBuffer (void) Line 201  void Messages::flushStdoutBuffer (void)
201  // Stdout capture accessors.  // Stdout capture accessors.
202  bool Messages::isCaptureEnabled (void)  bool Messages::isCaptureEnabled (void)
203  {  {
204          return (m_pStdoutNotifier != NULL);          return (m_pStdoutNotifier != nullptr);
205  }  }
206    
207  void Messages::setCaptureEnabled ( bool bCapture )  void Messages::setCaptureEnabled ( bool bCapture )
# Line 194  void Messages::setCaptureEnabled ( bool Line 213  void Messages::setCaptureEnabled ( bool
213          // Destroy if already enabled.          // Destroy if already enabled.
214          if (!bCapture && m_pStdoutNotifier) {          if (!bCapture && m_pStdoutNotifier) {
215                  delete m_pStdoutNotifier;                  delete m_pStdoutNotifier;
216                  m_pStdoutNotifier = NULL;                  m_pStdoutNotifier = nullptr;
217                  // Close the notification pipes.                  // Close the notification pipes.
218                  if (m_fdStdout[QSAMPLER_MESSAGES_FDREAD] != QSAMPLER_MESSAGES_FDNIL) {                  if (m_fdStdout[QSAMPLER_MESSAGES_FDREAD] != QSAMPLER_MESSAGES_FDNIL) {
219                          ::close(m_fdStdout[QSAMPLER_MESSAGES_FDREAD]);                          ::close(m_fdStdout[QSAMPLER_MESSAGES_FDREAD]);
# Line 202  void Messages::setCaptureEnabled ( bool Line 221  void Messages::setCaptureEnabled ( bool
221                  }                  }
222          }          }
223          // Are we going to make up the capture?          // Are we going to make up the capture?
224          if (bCapture && m_pStdoutNotifier == NULL && ::pipe(m_fdStdout) == 0) {          if (bCapture && m_pStdoutNotifier == nullptr && ::pipe(m_fdStdout) == 0) {
225                  ::dup2(m_fdStdout[QSAMPLER_MESSAGES_FDWRITE], STDOUT_FILENO);                  ::dup2(m_fdStdout[QSAMPLER_MESSAGES_FDWRITE], STDOUT_FILENO);
226                  ::dup2(m_fdStdout[QSAMPLER_MESSAGES_FDWRITE], STDERR_FILENO);                  ::dup2(m_fdStdout[QSAMPLER_MESSAGES_FDWRITE], STDERR_FILENO);
227                  m_pStdoutNotifier = new QSocketNotifier(                  m_pStdoutNotifier = new QSocketNotifier(
# Line 242  void Messages::setMessagesLimit ( int iM Line 261  void Messages::setMessagesLimit ( int iM
261  // Messages logging stuff.  // Messages logging stuff.
262  bool Messages::isLogging (void) const  bool Messages::isLogging (void) const
263  {  {
264          return (m_pMessagesLog != NULL);          return (m_pMessagesLog != nullptr);
265  }  }
266    
267  void Messages::setLogging ( bool bEnabled, const QString& sFilename )  void Messages::setLogging ( bool bEnabled, const QString& sFilename )
# Line 252  void Messages::setLogging ( bool bEnable Line 271  void Messages::setLogging ( bool bEnable
271                          .arg(QDateTime::currentDateTime().toString()));                          .arg(QDateTime::currentDateTime().toString()));
272                  m_pMessagesLog->close();                  m_pMessagesLog->close();
273                  delete m_pMessagesLog;                  delete m_pMessagesLog;
274                  m_pMessagesLog = NULL;                  m_pMessagesLog = nullptr;
275          }          }
276    
277          if (bEnabled) {          if (bEnabled) {
# Line 262  void Messages::setLogging ( bool bEnable Line 281  void Messages::setLogging ( bool bEnable
281                                  .arg(QDateTime::currentDateTime().toString()));                                  .arg(QDateTime::currentDateTime().toString()));
282                  } else {                  } else {
283                          delete m_pMessagesLog;                          delete m_pMessagesLog;
284                          m_pMessagesLog = NULL;                          m_pMessagesLog = nullptr;
285                  }                  }
286          }          }
287  }  }
# Line 272  void Messages::setLogging ( bool bEnable Line 291  void Messages::setLogging ( bool bEnable
291  void Messages::appendMessagesLog ( const QString& s )  void Messages::appendMessagesLog ( const QString& s )
292  {  {
293          if (m_pMessagesLog) {          if (m_pMessagesLog) {
294                  QTextStream(m_pMessagesLog) << s << endl;                  QTextStream(m_pMessagesLog)
295                            << QTime::currentTime().toString("hh:mm:ss.zzz")
296                            << ' ' << s << endl;
297                  m_pMessagesLog->flush();                  m_pMessagesLog->flush();
298          }          }
299  }  }
# Line 304  void Messages::appendMessagesLine ( cons Line 325  void Messages::appendMessagesLine ( cons
325  // The main utility methods.  // The main utility methods.
326  void Messages::appendMessages ( const QString& s )  void Messages::appendMessages ( const QString& s )
327  {  {
328          appendMessagesColor(s, "#999999");          appendMessagesColor(s, Qt::gray);
329  }  }
330    
331  void Messages::appendMessagesColor ( const QString& s, const QString &c )  void Messages::appendMessagesColor ( const QString& s, const QColor& rgb )
332  {  {
333          const QString& sText          appendMessagesLine("<font color=\"" + rgb.name() + "\">" + s + "</font>");
334                  = QTime::currentTime().toString("hh:mm:ss.zzz") + ' ' + s;          appendMessagesLog(s);
         appendMessagesLine("<font color=\"" + c + "\">" + sText + "</font>");  
         appendMessagesLog(sText);  
335  }  }
336    
337  void Messages::appendMessagesText ( const QString& s )  void Messages::appendMessagesText ( const QString& s )

Legend:
Removed from v.3358  
changed lines
  Added in v.3855

  ViewVC Help
Powered by ViewVC