/* Klat - A LaTeX editor for KDE Copyright (C) 2002-2004 Jori Liesenborgs (jori@lumumba.luc.ac.be) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "klatoutputtab.h" #include "klatoutputtab.moc" #include #include #include #include KlatOutputTab::KlatOutputTab(QWidget *parent) : QTabWidget(parent) { out = new KEdit(this); err = new KEdit(this); out->setReadOnly(true); err->setReadOnly(true); addTab(out,"Stdout"); addTab(err,"Stderr"); currentpid = 0; } KlatOutputTab::~KlatOutputTab() { } void KlatOutputTab::newProcess(pid_t newpid,const QString &cmd) { out->clear(); err->clear(); QString cmdinfo = "Executing the following command line:\n"; cmdinfo += cmd; cmdinfo += "\n\n"; addTextToEditWidget(out,cmdinfo.latin1(),cmdinfo.length()); addTextToEditWidget(err,cmdinfo.latin1(),cmdinfo.length()); currentpid = newpid; } #define BUFSIZE 1024 void KlatOutputTab::slotAddStdout(KProcess *proc,char *buffer,int buflen) { if (proc->pid() != currentpid) return; addTextToEditWidget(out,buffer,buflen); } void KlatOutputTab::slotAddStderr(KProcess *proc,char *buffer,int buflen) { if (proc->pid() != currentpid) return; addTextToEditWidget(err,buffer,buflen); } void KlatOutputTab::addTextToEditWidget(KEdit *w,const char *buffer,int buflen) { int len,remaining,pos; int line,col; char tmp[BUFSIZE]; QString text; remaining = buflen; pos = 0; line = 0; while (remaining > 0) { if (remaining > (BUFSIZE-1)) len = BUFSIZE-1; else len = remaining; memcpy(tmp,buffer+pos,len); tmp[len] = 0; pos += len; remaining -= len; QString linestr; line = w->numLines()-1; linestr = w->textLine(line); col = linestr.length(); w->insertAt(tmp,line,col); line = w->numLines()-1; } w->setCursorPosition(line,0); } void KlatOutputTab::finishedProcess(pid_t procpid) { if (procpid != currentpid) return; QString info = "\nProcess finished\n"; addTextToEditWidget(out,info.latin1(),info.length()); addTextToEditWidget(err,info.latin1(),info.length()); }