kprintprocess.cpp
00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001 Michael Goffioul <tdeprint@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., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 **/ 00019 00020 #include "kprintprocess.h" 00021 #include <tdeapplication.h> 00022 #include <tdelocale.h> 00023 #include <tqfile.h> 00024 00025 KPrintProcess::KPrintProcess() 00026 : KShellProcess() 00027 { 00028 // redirect everything to a single buffer 00029 connect(this,TQT_SIGNAL(receivedStdout(TDEProcess*,char*,int)),TQT_SLOT(slotReceivedStderr(TDEProcess*,char*,int))); 00030 connect(this,TQT_SIGNAL(receivedStderr(TDEProcess*,char*,int)),TQT_SLOT(slotReceivedStderr(TDEProcess*,char*,int))); 00031 connect( this, TQT_SIGNAL( processExited( TDEProcess* ) ), TQT_SLOT( slotExited( TDEProcess* ) ) ); 00032 m_state = None; 00033 } 00034 00035 KPrintProcess::~KPrintProcess() 00036 { 00037 if ( !m_tempoutput.isEmpty() ) 00038 TQFile::remove( m_tempoutput ); 00039 if ( m_tempfiles.size() > 0 ) 00040 for ( TQStringList::ConstIterator it=m_tempfiles.begin(); it!=m_tempfiles.end(); ++it ) 00041 TQFile::remove( *it ); 00042 } 00043 00044 TQString KPrintProcess::errorMessage() const 00045 { 00046 return m_buffer; 00047 } 00048 00049 bool KPrintProcess::print() 00050 { 00051 m_buffer = TQString(); 00052 m_state = Printing; 00053 return start(NotifyOnExit,All); 00054 } 00055 00056 void KPrintProcess::slotReceivedStderr(TDEProcess *proc, char *buf, int len) 00057 { 00058 if (proc == this) 00059 { 00060 TQCString str = TQCString(buf,len).stripWhiteSpace(); 00061 m_buffer.append(str.append("\n")); 00062 } 00063 } 00064 00065 void KPrintProcess::slotExited( TDEProcess* ) 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.trinitydesktop.org\">http://bugs.trinitydesktop.org</a>." ); 00090 break; 00091 } 00092 } 00093 00094 #include "kprintprocess.moc"