KDE/kdesdk
Kevin Kofler
kevin.kofler at chello.at
Sat Feb 23 12:21:51 CET 2008
SVN commit 778322 by kkofler:
Kompare:
Port from K3Process to KProcess.
Don't use shell just to set LANG=C, use setEnv instead.
Let KProcess accumulate the stdout/stderr buffers.
Don't check for success in KompareProcess::start() because it requires blocking (waitForStarted) and all users were throwing away the return value sooner or later anyway.
Also build Kompare on non-*nix platforms, should work now. WARNING: Not actually tested on Win32, YMMV.
Add missing kde4_add_app_icon.
CCMAIL: kde-windows at kde.org
M +1 -3 CMakeLists.txt
M +1 -1 kompare/CMakeLists.txt
M +3 -2 kompare/libdiff2/komparemodellist.cpp
M +33 -48 kompare/libdiff2/kompareprocess.cpp
M +5 -6 kompare/libdiff2/kompareprocess.h
--- trunk/KDE/kdesdk/CMakeLists.txt #778321:778322
@@ -45,9 +45,7 @@
#TODO: replace with a check for glibc
macro_optional_add_subdirectory(kmtrace)
endif (CMAKE_SYSTEM_NAME MATCHES Linux)
-if( UNIX )
- macro_optional_add_subdirectory(kompare)
-endif( UNIX )
+macro_optional_add_subdirectory(kompare)
macro_optional_add_subdirectory(kprofilemethod)
message(STATUS "remember to port kspy to Qt4's metaobjects")
#add_subdirectory(kspy)
--- trunk/KDE/kdesdk/kompare/CMakeLists.txt #778321:778322
@@ -17,8 +17,8 @@
kompareurldialog.cpp
)
+kde4_add_app_icon(kompare_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/pics/hi*-app-kompare.png")
-
kde4_add_executable(kompare ${kompare_SRCS})
target_link_libraries(kompare kompareinterface komparediff2 komparedialogpages ${KDE4_KTEXTEDITOR_LIBS} ${KDE4_KDE3SUPPORT_LIBS} )
--- trunk/KDE/kdesdk/kompare/libdiff2/komparemodellist.cpp #778321:778322
@@ -4,7 +4,7 @@
begin : Tue Jun 26 2001
copyright : (C) 2001-2004 Otto Bruggeman
(C) 2001-2003 John Firebaugh
- (C) 2007 Kevin Kofler
+ (C) 2007-2008 Kevin Kofler
email : jfirebaugh at kde.org
otto.bruggeman at home.nl
kevin.kofler at chello.at
@@ -611,7 +611,8 @@
this, SLOT(slotWriteDiffOutput( bool )) );
emit status( Kompare::RunningDiff );
- return m_diffProcess->start();
+ m_diffProcess->start();
+ return true;
}
void KompareModelList::slotWriteDiffOutput( bool success )
--- trunk/KDE/kdesdk/kompare/libdiff2/kompareprocess.cpp #778321:778322
@@ -4,7 +4,7 @@
begin : Sun Mar 4 2001
copyright : (C) 2001-2003 by Otto Bruggeman
and John Firebaugh
- (C) 2007 Kevin Kofler
+ (C) 2007-2008 Kevin Kofler
email : otto.bruggeman at home.nl
jfirebaugh at kde.org
kevin.kofler at chello.at
@@ -25,7 +25,6 @@
//Added by qt3to4:
#include <Q3ValueList>
#include <Q3CString>
-#include <kshell.h>
#include <kcharsets.h>
#include <kdebug.h>
#include <kglobal.h>
@@ -34,24 +33,16 @@
#include "kompareprocess.h"
KompareProcess::KompareProcess( DiffSettings* diffSettings, enum Kompare::DiffMode mode, QString source, QString destination, QString dir )
- : K3Process(),
+ : KProcess(),
m_diffSettings( diffSettings ),
m_mode( mode ),
m_textDecoder( 0 )
{
- setUseShell( true );
-
- // connect the stdout and stderr signals
- connect( this, SIGNAL( receivedStdout( K3Process*, char*, int ) ),
- SLOT ( slotReceivedStdout( K3Process*, char*, int ) ) );
- connect( this, SIGNAL( receivedStderr( K3Process*, char*, int ) ),
- SLOT ( slotReceivedStderr( K3Process*, char*, int ) ) );
-
// connect the signal that indicates that the proces has exited
- connect( this, SIGNAL( processExited( K3Process* ) ),
- SLOT ( slotProcessExited( K3Process* ) ) );
+ connect( this, SIGNAL( finished( int, QProcess::ExitStatus ) ),
+ SLOT ( slotFinished( int, QProcess::ExitStatus ) ) );
- *this << "LANG=C";
+ setEnv( "LANG", "C" );
// Write command and options
if( m_mode == Kompare::Default )
@@ -64,13 +55,13 @@
}
if( !dir.isEmpty() ) {
- QDir::setCurrent( dir );
+ setWorkingDirectory( dir );
}
// Write file names
*this << "--";
- *this << KShell::quoteArg( constructRelativePath( dir, source ) );
- *this << KShell::quoteArg( constructRelativePath( dir, destination ) );
+ *this << constructRelativePath( dir, source );
+ *this << constructRelativePath( dir, destination );
}
void KompareProcess::writeDefaultCommandLine()
@@ -166,7 +157,7 @@
if ( m_diffSettings->m_ignoreRegExp && !m_diffSettings->m_ignoreRegExpText.isEmpty() )
{
- *this << "-I " << KShell::quoteArg( m_diffSettings->m_ignoreRegExpText );
+ *this << "-I " << m_diffSettings->m_ignoreRegExpText;
}
if ( m_diffSettings->m_showCFunctionChange )
@@ -201,13 +192,13 @@
QStringList::ConstIterator end = m_diffSettings->m_excludeFilePatternList.end();
for ( ; it != end; ++it )
{
- *this << "-x" << KShell::quoteArg( *it );
+ *this << "-x" << *it;
}
}
if ( m_diffSettings->m_excludeFilesFile && !m_diffSettings->m_excludeFilesFileURL.isEmpty() )
{
- *this << "-X" << KShell::quoteArg( m_diffSettings->m_excludeFilesFileURL );
+ *this << "-X" << m_diffSettings->m_excludeFilesFileURL;
}
}
@@ -235,43 +226,37 @@
}
}
-void KompareProcess::slotReceivedStdout( K3Process* /* process */, char* buffer, int length )
+void KompareProcess::start()
{
- // add all output to m_stdout
- if ( m_textDecoder )
- m_stdout += m_textDecoder->toUnicode( buffer, length );
- else
- kDebug(8101) << "KompareProcess::slotReceivedStdout : No decoder !!!" << endl;
-}
-
-void KompareProcess::slotReceivedStderr( K3Process* /* process */, char* buffer, int length )
-{
- // add all output to m_stderr
- if ( m_textDecoder )
- m_stderr += m_textDecoder->toUnicode( buffer, length );
- else
- kDebug(8101) << "KompareProcess::slotReceivedStderr : No decoder !!!" << endl;
-}
-
-bool KompareProcess::start()
-{
#ifndef NDEBUG
QString cmdLine;
- QList<QByteArray>::ConstIterator it = arguments.begin();
- for (; it != arguments.end(); ++it )
+ QStringList program = KProcess::program();
+ QStringList::ConstIterator it = program.begin();
+ for (; it != program.end(); ++it )
cmdLine += "\"" + (*it) + "\" ";
kDebug(8101) << cmdLine << endl;
#endif
- return( K3Process::start( K3Process::NotifyOnExit, K3Process::AllOutput ) );
+ setOutputChannelMode( SeparateChannels );
+ setNextOpenMode( ReadOnly );
+ KProcess::start();
}
-void KompareProcess::slotProcessExited( K3Process* /* proc */ )
+void KompareProcess::slotFinished( int exitCode, QProcess::ExitStatus exitStatus )
{
- // exit status of 0: no differences
- // 1: some differences
- // 2: error but there may be differences !
- kDebug(8101) << "Exited with exit status : " << exitStatus() << endl;
- emit diffHasFinished( normalExit() && exitStatus() != 0 );
+ // add all output to m_stdout/m_stderr
+ if ( m_textDecoder )
+ {
+ m_stdout = m_textDecoder->toUnicode( readAllStandardOutput() );
+ m_stderr = m_textDecoder->toUnicode( readAllStandardError() );
+ }
+ else
+ kDebug(8101) << "KompareProcess::slotFinished : No decoder !!!" << endl;
+
+ // exit code of 0: no differences
+ // 1: some differences
+ // 2: error but there may be differences !
+ kDebug(8101) << "Exited with exit code : " << exitCode << endl;
+ emit diffHasFinished( exitStatus == NormalExit && exitCode != 0 );
}
#include "kompareprocess.moc"
--- trunk/KDE/kdesdk/kompare/libdiff2/kompareprocess.h #778321:778322
@@ -4,6 +4,7 @@
begin : Sun Mar 4 2001
copyright : (C) 2001-2003 by Otto Bruggeman
and John Firebaugh
+ (C) 2008 Kevin Kofler
email : otto.bruggeman at home.nl
jfirebaugh at kde.org
****************************************************************************/
@@ -20,7 +21,7 @@
#ifndef KOMPAREPROCESS_H
#define KOMPAREPROCESS_H
-#include <k3process.h>
+#include <kprocess.h>
#include "kompare.h"
@@ -28,7 +29,7 @@
class DiffSettings;
-class KompareProcess : public K3Process, public KompareFunctions
+class KompareProcess : public KProcess, public KompareFunctions
{
Q_OBJECT
@@ -36,7 +37,7 @@
KompareProcess( DiffSettings* diffSettings, enum Kompare::DiffMode mode, QString source, QString destination, QString directory = QString() );
~KompareProcess();
- bool start();
+ void start();
QString diffOutput() { return m_stdout; }
QString stdOut() { return m_stdout; }
@@ -52,9 +53,7 @@
void writeCommandLine();
protected slots:
- void slotReceivedStdout( K3Process*, char*, int );
- void slotReceivedStderr( K3Process*, char*, int );
- void slotProcessExited( K3Process* proc );
+ void slotFinished( int, QProcess::ExitStatus );
private:
DiffSettings* m_diffSettings;
More information about the Kde-windows
mailing list