00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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"