KDevelop API Documentation

processlinemaker.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #include "processlinemaker.h"
00021 #include "processlinemaker.moc"
00022 
00023 #include <kprocess.h>
00024 
00025 ProcessLineMaker::ProcessLineMaker()
00026 {
00027 }
00028 
00029 ProcessLineMaker::ProcessLineMaker( const KProcess* proc )
00030 {
00031     connect(proc, SIGNAL(receivedStdout(KProcess*,char*,int)),
00032             this, SLOT(slotReceivedStdout(KProcess*,char*,int)) );
00033     
00034     connect(proc, SIGNAL(receivedStderr(KProcess*,char*,int)),
00035             this, SLOT(slotReceivedStderr(KProcess*,char*,int)) );
00036 }
00037 
00038 void ProcessLineMaker::slotReceivedStdout( const QString& s )
00039 {
00040     // Flush stderr buffer
00041     if (!stderrbuf.isEmpty()) {
00042         emit receivedStderrLine(stderrbuf);
00043         stderrbuf = "";
00044     }
00045     
00046     stdoutbuf += s;
00047     int pos;
00048     while ( (pos = stdoutbuf.find('\n')) != -1) {
00049         QString line = stdoutbuf.left(pos);
00050         emit receivedStdoutLine(line);
00051         stdoutbuf.remove(0, pos+1);
00052     }
00053 }
00054 
00055 void ProcessLineMaker::slotReceivedStdout( KProcess*, char *buffer, int buflen )
00056 {
00057     slotReceivedStdout( QString::fromLocal8Bit( buffer, buflen ) );
00058 }
00059 
00060 void ProcessLineMaker::slotReceivedStdout( const char* buffer )
00061 {
00062     slotReceivedStdout( QString::fromLocal8Bit( buffer ) );
00063 }
00064 
00065 void ProcessLineMaker::slotReceivedStderr( const QString& s )
00066 {
00067     // Flush stdout buffer
00068     if (!stdoutbuf.isEmpty()) {
00069         emit receivedStdoutLine(stdoutbuf);
00070         stdoutbuf = "";
00071     }
00072     
00073     stderrbuf += s;
00074     int pos;
00075     while ( (pos = stderrbuf.find('\n')) != -1) {
00076         QString line = stderrbuf.left(pos);
00077         emit receivedStderrLine(line);
00078         stderrbuf.remove(0, pos+1);
00079     }
00080 }
00081 
00082 void ProcessLineMaker::slotReceivedStderr( KProcess*, char *buffer, int buflen )
00083 {
00084     slotReceivedStderr( QString::fromLocal8Bit( buffer, buflen ) );
00085 }
00086 
00087 void ProcessLineMaker::slotReceivedStderr( const char* buffer )
00088 {
00089     slotReceivedStderr( QString::fromLocal8Bit( buffer ) );
00090 }
00091 
00092 void ProcessLineMaker::clearBuffers( )
00093 {
00094     stderrbuf = "";
00095     stdoutbuf = "";
00096 }
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:36 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003