/[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 115 by capela, Mon Jun 7 21:41:43 2004 UTC revision 1465 by capela, Thu Nov 1 17:49:27 2007 UTC
# Line 1  Line 1 
1  // qsamplerMessages.cpp  // qsamplerMessages.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2003-2004, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.
5       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
8     modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
# Line 13  Line 14 
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License along
18     along with this program; if not, write to the Free Software     with this program; if not, write to the Free Software Foundation, Inc.,
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20    
21  *****************************************************************************/  *****************************************************************************/
22    
23    #include "qsamplerAbout.h"
24  #include "qsamplerMessages.h"  #include "qsamplerMessages.h"
25    
26  #include <qsocketnotifier.h>  #include <QSocketNotifier>
27  #include <qstringlist.h>  #include <QTextEdit>
28  #include <qtextedit.h>  #include <QTextCursor>
29  #include <qdatetime.h>  #include <QTextBlock>
30  #include <qtooltip.h>  #include <QScrollBar>
31  #include <qpixmap.h>  #include <QDateTime>
32    #include <QIcon>
 #include "config.h"  
33    
34  #if !defined(WIN32)  #if !defined(WIN32)
35  #include <unistd.h>  #include <unistd.h>
# Line 48  Line 49 
49  //  //
50    
51  // Constructor.  // Constructor.
52  qsamplerMessages::qsamplerMessages ( QWidget *pParent, const char *pszName )  qsamplerMessages::qsamplerMessages ( QWidget *pParent )
53      : QDockWindow(pParent, pszName)      : QDockWidget(pParent)
54  {  {
55      // Initialize default message limit.          // Surely a name is crucial (e.g.for storing geometry settings)
56      m_iMessagesLimit = QSAMPLER_MESSAGES_MAXLINES;          QDockWidget::setObjectName("qsamplerMessages");
57    
58      // Intialize stdout capture stuff.      // Intialize stdout capture stuff.
59      m_pStdoutNotifier = NULL;      m_pStdoutNotifier = NULL;
60      m_fdStdout[QSAMPLER_MESSAGES_FDREAD]  = QSAMPLER_MESSAGES_FDNIL;      m_fdStdout[QSAMPLER_MESSAGES_FDREAD]  = QSAMPLER_MESSAGES_FDNIL;
61      m_fdStdout[QSAMPLER_MESSAGES_FDWRITE] = QSAMPLER_MESSAGES_FDNIL;      m_fdStdout[QSAMPLER_MESSAGES_FDWRITE] = QSAMPLER_MESSAGES_FDNIL;
62    
63      // Surely a name is crucial (e.g.for storing geometry settings)          // Create local text view widget.
64      if (pszName == 0)          m_pTextView = new QTextEdit(this);
         QDockWindow::setName("qsamplerMessages");  
   
     // Create local text view widget.  
     m_pTextView = new QTextEdit(this);  
65  //  QFont font(m_pTextView->font());  //  QFont font(m_pTextView->font());
66  //  font.setFamily("Fixed");  //  font.setFamily("Fixed");
67  //  m_pTextView->setFont(font);  //  m_pTextView->setFont(font);
68      m_pTextView->setWordWrap(QTextEdit::NoWrap);          m_pTextView->setLineWrapMode(QTextEdit::NoWrap);
69      m_pTextView->setReadOnly(true);          m_pTextView->setReadOnly(true);
70      m_pTextView->setUndoRedoEnabled(false);          m_pTextView->setUndoRedoEnabled(false);
71    //      m_pTextView->setTextFormat(Qt::LogText);
72      // Prepare the dockable window stuff.  
73      QDockWindow::setWidget(m_pTextView);          // Initialize default message limit.
74      QDockWindow::setOrientation(Qt::Horizontal);          m_iMessagesLines = 0;
75      QDockWindow::setCloseMode(QDockWindow::Always);          setMessagesLimit(QSAMPLER_MESSAGES_MAXLINES);
76      QDockWindow::setResizeEnabled(true);  
77            // Prepare the dockable window stuff.
78      // Finally set the default caption and tooltip.          QDockWidget::setWidget(m_pTextView);
79      QString sCaption = tr("Messages");          QDockWidget::setFeatures(QDockWidget::AllDockWidgetFeatures);
80      QToolTip::add(this, sCaption);          QDockWidget::setAllowedAreas(
81      QDockWindow::setCaption(sCaption);                  Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
82            // Some specialties to this kind of dock window...
83            QDockWidget::setMinimumHeight(120);
84    
85            // Finally set the default caption and tooltip.
86            const QString& sCaption = tr("Messages");
87            QDockWidget::setWindowTitle(sCaption);
88    //      QDockWidget::setWindowIcon(QIcon(":/icons/qsamplerMessages.png"));
89            QDockWidget::setToolTip(sCaption);
90  }  }
91    
92    
# Line 113  void qsamplerMessages::stdoutNotify ( in Line 118  void qsamplerMessages::stdoutNotify ( in
118  // Stdout buffer handler -- now splitted by complete new-lines...  // Stdout buffer handler -- now splitted by complete new-lines...
119  void qsamplerMessages::appendStdoutBuffer ( const QString& s )  void qsamplerMessages::appendStdoutBuffer ( const QString& s )
120  {  {
121      m_sStdoutBuffer.append(s);          m_sStdoutBuffer.append(s);
122    
123      int iLength = m_sStdoutBuffer.findRev('\n') + 1;          int iLength = m_sStdoutBuffer.lastIndexOf('\n') + 1;
124      if (iLength > 0) {          if (iLength > 0) {
125          QString sTemp = m_sStdoutBuffer.left(iLength);                  QString sTemp = m_sStdoutBuffer.left(iLength);
126          m_sStdoutBuffer.remove(0, iLength);                  m_sStdoutBuffer.remove(0, iLength);
127          QStringList list = QStringList::split('\n', sTemp, true);                  QStringList list = sTemp.split('\n');
128          for (QStringList::Iterator iter = list.begin(); iter != list.end(); iter++)                  QStringListIterator iter(list);
129              appendMessagesText(*iter);                  while (iter.hasNext())
130      }                          appendMessagesText(iter.next());
131            }
132  }  }
133    
134    
# Line 148  void qsamplerMessages::setCaptureEnabled Line 154  void qsamplerMessages::setCaptureEnabled
154      flushStdoutBuffer();      flushStdoutBuffer();
155    
156  #if !defined(WIN32)  #if !defined(WIN32)
157      // Destroy if already enabled.          // Destroy if already enabled.
158      if (!bCapture && m_pStdoutNotifier) {          if (!bCapture && m_pStdoutNotifier) {
159          delete m_pStdoutNotifier;                  delete m_pStdoutNotifier;
160          m_pStdoutNotifier = NULL;                  m_pStdoutNotifier = NULL;
161          // Close the notification pipes.                  // Close the notification pipes.
162          if (m_fdStdout[QSAMPLER_MESSAGES_FDREAD] != QSAMPLER_MESSAGES_FDNIL) {                  if (m_fdStdout[QSAMPLER_MESSAGES_FDREAD] != QSAMPLER_MESSAGES_FDNIL) {
163              ::close(m_fdStdout[QSAMPLER_MESSAGES_FDREAD]);                          ::close(m_fdStdout[QSAMPLER_MESSAGES_FDREAD]);
164              m_fdStdout[QSAMPLER_MESSAGES_FDREAD]  = QSAMPLER_MESSAGES_FDNIL;                          m_fdStdout[QSAMPLER_MESSAGES_FDREAD]  = QSAMPLER_MESSAGES_FDNIL;
165          }                  }
166          if (m_fdStdout[QSAMPLER_MESSAGES_FDREAD] != QSAMPLER_MESSAGES_FDNIL) {                  if (m_fdStdout[QSAMPLER_MESSAGES_FDREAD] != QSAMPLER_MESSAGES_FDNIL) {
167              ::close(m_fdStdout[QSAMPLER_MESSAGES_FDREAD]);                          ::close(m_fdStdout[QSAMPLER_MESSAGES_FDREAD]);
168              m_fdStdout[QSAMPLER_MESSAGES_FDREAD]  = QSAMPLER_MESSAGES_FDNIL;                          m_fdStdout[QSAMPLER_MESSAGES_FDREAD]  = QSAMPLER_MESSAGES_FDNIL;
169          }                  }
170      }          }
171      // Are we going to make up the capture?          // Are we going to make up the capture?
172      if (bCapture && m_pStdoutNotifier == NULL && ::pipe(m_fdStdout) == 0) {          if (bCapture && m_pStdoutNotifier == NULL && ::pipe(m_fdStdout) == 0) {
173          ::dup2(m_fdStdout[QSAMPLER_MESSAGES_FDWRITE], STDOUT_FILENO);                  ::dup2(m_fdStdout[QSAMPLER_MESSAGES_FDWRITE], STDOUT_FILENO);
174          ::dup2(m_fdStdout[QSAMPLER_MESSAGES_FDWRITE], STDERR_FILENO);                  ::dup2(m_fdStdout[QSAMPLER_MESSAGES_FDWRITE], STDERR_FILENO);
175          m_pStdoutNotifier = new QSocketNotifier(m_fdStdout[QSAMPLER_MESSAGES_FDREAD], QSocketNotifier::Read, this);                  m_pStdoutNotifier = new QSocketNotifier(
176          QObject::connect(m_pStdoutNotifier, SIGNAL(activated(int)), this, SLOT(stdoutNotify(int)));                          m_fdStdout[QSAMPLER_MESSAGES_FDREAD], QSocketNotifier::Read, this);
177      }                  QObject::connect(m_pStdoutNotifier,
178                            SIGNAL(activated(int)),
179                            SLOT(stdoutNotify(int)));
180            }
181  #endif  #endif
182  }  }
183    
# Line 194  int qsamplerMessages::messagesLimit (voi Line 203  int qsamplerMessages::messagesLimit (voi
203  void qsamplerMessages::setMessagesLimit ( int iMessagesLimit )  void qsamplerMessages::setMessagesLimit ( int iMessagesLimit )
204  {  {
205      m_iMessagesLimit = iMessagesLimit;      m_iMessagesLimit = iMessagesLimit;
206        m_iMessagesHigh  = iMessagesLimit + (iMessagesLimit / 3);
207  }  }
208    
209    
# Line 205  void qsamplerMessages::appendMessages ( Line 215  void qsamplerMessages::appendMessages (
215    
216  void qsamplerMessages::appendMessagesColor ( const QString& s, const QString &c )  void qsamplerMessages::appendMessagesColor ( const QString& s, const QString &c )
217  {  {
218      appendMessagesText("<font color=\"" + c + "\">" + QTime::currentTime().toString("hh:mm:ss.zzz") + " " + s + "</font>");          appendMessagesText("<font color=\"" + c + "\">"
219                    + QTime::currentTime().toString("hh:mm:ss.zzz")
220                    + ' ' + s + "</font>");
221  }  }
222    
223  void qsamplerMessages::appendMessagesText ( const QString& s )  void qsamplerMessages::appendMessagesText ( const QString& s )
224  {  {
225      // Check for message line limit...      // Check for message line limit...
226      if (m_iMessagesLimit > 0) {      if (m_iMessagesLines > m_iMessagesHigh) {
227          int iParagraphs = m_pTextView->paragraphs();                  m_pTextView->setUpdatesEnabled(false);
228          if (iParagraphs > m_iMessagesLimit) {                  QTextCursor textCursor(m_pTextView->document()->begin());
229              m_pTextView->setUpdatesEnabled(false);                  while (m_iMessagesLines > m_iMessagesLimit) {
230              while (iParagraphs > m_iMessagesLimit) {                          // Move cursor extending selection
231                  m_pTextView->removeParagraph(0);                          // from start to next line-block...
232                  iParagraphs--;                          textCursor.movePosition(
233              }                                  QTextCursor::NextBlock, QTextCursor::KeepAnchor);
234              m_pTextView->scrollToBottom();                          m_iMessagesLines--;
235              m_pTextView->setUpdatesEnabled(true);                  }
236          }                  // Remove the excessive line-blocks...
237      }                  textCursor.removeSelectedText();
238      m_pTextView->append(s);                  m_pTextView->setUpdatesEnabled(true);
239        }
240    
241            // Count always as a new line out there...
242            m_pTextView->append(s);
243            m_iMessagesLines++;
244  }  }
245    
246    
247  // One time scroll to the most recent message.  // History reset.
248  void qsamplerMessages::scrollToBottom (void)  void qsamplerMessages::clear (void)
249  {  {
250      flushStdoutBuffer();          m_iMessagesLines = 0;
251      m_pTextView->scrollToBottom();          m_pTextView->clear();
252  }  }
253    
254    

Legend:
Removed from v.115  
changed lines
  Added in v.1465

  ViewVC Help
Powered by ViewVC