kitchensync

pluckerprocesshandler.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2004 Holger Hans Peter Freyther <freyther@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 */
00020 
00021 
00022 #include "pluckerprocesshandler.h"
00023 #include "pluckerconfig.h"
00024 
00025 #include <kdebug.h>
00026 
00027 namespace KSPlucker {
00028 PluckerProcessHandler::PluckerProcessHandler( enum Mode m, bool forget,
00029                                 const QString& file, QObject* p )
00030   : QObject( p ), m_mode( m ), m_forget( forget ),
00031     m_file( file ), m_useList( false )
00032 {}
00033 
00034 PluckerProcessHandler::PluckerProcessHandler( enum Mode m, bool forget,
00035                                 const QStringList& file, const QString& dest,
00036                                 QObject* p )
00037   : QObject( p ), m_mode( m ), m_forget( forget ),  m_dir( dest ),
00038     m_files( file ), m_useList( true )
00039 {}
00040 
00041 PluckerProcessHandler::~PluckerProcessHandler()
00042 {}
00043 
00044 void PluckerProcessHandler::runConfig( KProcess* proc )
00045 {
00046   PluckerConfig *conf = PluckerConfig::self();
00047   *proc << conf->javaPath();
00048   *proc << "-jar" << conf->pluckerPath()+"/jpluckx.jar" << m_file;
00049 }
00050 
00051 void PluckerProcessHandler::runConvert( KProcess* proc )
00052 {
00053   PluckerConfig *conf = PluckerConfig::self();
00054   *proc << conf->javaPath();
00055   *proc << "-jar" << conf->pluckerPath()+"/jpluckc.jar"
00056         << "-destination" << m_dir << m_file;
00057 }
00058 
00059 void PluckerProcessHandler::run()
00060 {
00061   if ( m_useList )
00062     popFirst();
00063 
00064   KProcess *proc = new KProcess( this );
00065 
00066   /*
00067    * Set the Configuration
00068    */
00069   if ( m_mode == Configure )
00070     runConfig( proc );
00071   else
00072     runConvert( proc );
00073 
00074   connect(proc, SIGNAL(processExited(KProcess*)),
00075           this, SLOT(slotExited(KProcess*)) );
00076   connect(proc, SIGNAL(receivedStdout(KProcess*,char*,int)),
00077           this, SLOT(slotStdOutput(KProcess*,char*,int)) );
00078 
00079 
00080   if ( !proc->start(m_forget ? KProcess::DontCare        : KProcess::NotifyOnExit,
00081                     m_forget ? KProcess::NoCommunication : KProcess::AllOutput ) ) {
00082     kdDebug() << "Failed To Execute" << endl;
00083     emit sigFinished( this );
00084   }
00085 
00086 }
00087 
00088 void PluckerProcessHandler::slotExited( KProcess* proc )
00089 {
00090   proc->deleteLater();
00091 
00092   if ( !m_useList || m_files.isEmpty() )
00093     emit sigFinished(this);
00094   else
00095     run();
00096 
00097 }
00098 
00099 void PluckerProcessHandler::slotStdOutput( KProcess* ,
00100                                     char* buffer, int buflen ) {
00101   QString str = QString::fromLatin1( buffer, buflen );
00102   emit sigProgress( str );
00103 }
00104 
00105 /*
00106  * For converting we need to be able to convert
00107  * a series of documents. So once one
00108  * Document is Finished we will continue with the next one
00109  */
00110 void PluckerProcessHandler::popFirst()
00111 {
00112   m_file = m_files.first();
00113   m_files.remove( m_file );
00114 }
00115 
00116 }
00117 
00118 #include "pluckerprocesshandler.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys