kdeprint Library API Documentation

kprintprocess.cpp

00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License version 2 as published by the Free Software Foundation. 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 "kprintprocess.h" 00021 #include <kapplication.h> 00022 #include <klocale.h> 00023 #include <qfile.h> 00024 00025 KPrintProcess::KPrintProcess() 00026 : KShellProcess() 00027 { 00028 // redirect everything to a single buffer 00029 connect(this,SIGNAL(receivedStdout(KProcess*,char*,int)),SLOT(slotReceivedStderr(KProcess*,char*,int))); 00030 connect(this,SIGNAL(receivedStderr(KProcess*,char*,int)),SLOT(slotReceivedStderr(KProcess*,char*,int))); 00031 connect( this, SIGNAL( processExited( KProcess* ) ), SLOT( slotExited( KProcess* ) ) ); 00032 m_state = None; 00033 } 00034 00035 KPrintProcess::~KPrintProcess() 00036 { 00037 if ( !m_tempoutput.isEmpty() ) 00038 QFile::remove( m_tempoutput ); 00039 if ( m_tempfiles.size() > 0 ) 00040 for ( QStringList::ConstIterator it=m_tempfiles.begin(); it!=m_tempfiles.end(); ++it ) 00041 QFile::remove( *it ); 00042 } 00043 00044 QString KPrintProcess::errorMessage() const 00045 { 00046 return m_buffer; 00047 } 00048 00049 bool KPrintProcess::print() 00050 { 00051 m_buffer = QString::null; 00052 m_state = Printing; 00053 return start(NotifyOnExit,All); 00054 } 00055 00056 void KPrintProcess::slotReceivedStderr(KProcess *proc, char *buf, int len) 00057 { 00058 if (proc == this) 00059 { 00060 QCString str = QCString(buf,len).stripWhiteSpace(); 00061 m_buffer.append(str.append("\n")); 00062 } 00063 } 00064 00065 void KPrintProcess::slotExited( KProcess* ) 00066 { 00067 switch ( m_state ) 00068 { 00069 case Printing: 00070 if ( !m_output.isEmpty() ) 00071 { 00072 clearArguments(); 00073 *this << "kfmclient" << "copy" << m_tempoutput << m_output; 00074 m_state = Finishing; 00075 m_buffer = i18n( "File transfer failed." ); 00076 if ( start( NotifyOnExit ) ) 00077 return; 00078 } 00079 case Finishing: 00080 if ( !normalExit() ) 00081 emit printError( this, i18n( "Abnormal process termination (<b>%1</b>)." ).arg( m_command ) ); 00082 else if ( exitStatus() != 0 ) 00083 emit printError( this, i18n( "<b>%1</b>: execution failed with message:<p>%2</p>" ).arg( m_command ).arg( m_buffer ) ); 00084 else 00085 emit printTerminated( this ); 00086 break; 00087 default: 00088 emit printError( this, "Internal error, printing terminated in unexpected state. " 00089 "Report bug at <a href=\"http://bugs.kde.org\">http://bugs.kde.org</a>." ); 00090 break; 00091 } 00092 } 00093 00094 #include "kprintprocess.moc"
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Sep 29 09:41:52 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003