[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: [PATCH] KProcess port of khelpcenter
From: Ralf Habacker <ralf.habacker () freenet ! de>
Date: 2007-12-13 17:43:25
Message-ID: 47616F3D.5090604 () freenet ! de
[Download RAW message or body]
Hi,
appended is a patch which ports KHelpcenter to KProcess. Are there any
objecitivies against submitting ?
Ralf
["kdebase_runtime_khelpcenter_kprocess.patch" (text/plain)]
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt (revision 747562)
+++ CMakeLists.txt (working copy)
@@ -6,7 +6,6 @@
include (KDE4Defaults)
include (MacroLibrary)
include(MacroOptionalAddSubdirectory)
-
macro_optional_find_package(USB)
macro_optional_find_package(Fontconfig)
macro_optional_find_package(OpenSSL)
Index: runtime/CMakeLists.txt
===================================================================
--- runtime/CMakeLists.txt (revision 747562)
+++ runtime/CMakeLists.txt (working copy)
@@ -26,8 +26,8 @@
add_subdirectory(kuiserver)
if ( NOT WIN32 )
add_subdirectory(drkonqi)
- add_subdirectory(khelpcenter)
endif ( NOT WIN32 )
+add_subdirectory(khelpcenter)
add_subdirectory(kioexec)
add_subdirectory(kioslave)
add_subdirectory(knetattach)
Index: runtime/khelpcenter/glossary.cpp
===================================================================
--- runtime/khelpcenter/glossary.cpp (revision 747562)
+++ runtime/khelpcenter/glossary.cpp (working copy)
@@ -26,7 +26,7 @@
#include <kiconloader.h>
#include <klocale.h>
#include <kxmlguiwindow.h>
-#include <k3process.h>
+#include <kprocess.h>
#include <kstandarddirs.h>
#include <kstatusbar.h>
@@ -147,25 +147,34 @@
void Glossary::rebuildGlossaryCache()
{
KXmlGuiWindow *mainWindow = dynamic_cast<KXmlGuiWindow *>( kapp->activeWindow() );
+#ifndef Q_WS_WIN
Q_ASSERT( mainWindow );
+#else
+ // there is a case when mainwindow is zero
+ if (mainWindow)
+#endif
mainWindow->statusBar()->showMessage( i18n( "Rebuilding cache..." ) );
- K3Process *meinproc = new K3Process;
- connect( meinproc, SIGNAL( processExited( K3Process * ) ),
- this, SLOT( meinprocExited( K3Process * ) ) );
+ m_meinProc = new KProcess;
+ connect( m_meinProc, SIGNAL(finished(int,QProcess::ExitStatus)),
+ this, SLOT( meinprocFinished(int,QProcess::ExitStatus)));
+
+#ifdef Q_WS_WIN
+ // KStandardDirs::locate return "" on win32
+ *m_meinProc << "meinproc4";
+#else
+ *m_meinProc << KStandardDirs::locate( "exe", QLatin1String( "meinproc4" ) );
+#endif
+ *m_meinProc << QLatin1String( "--output" ) << m_cacheFile;
+ *m_meinProc << QLatin1String( "--stylesheet" )
+ << KStandardDirs::locate( "data", QLatin1String( "khelpcenter/glossary.xslt" ) );
+ *m_meinProc << m_sourceFile;
- *meinproc << KStandardDirs::locate( "exe", QLatin1String( "meinproc4" ) );
- *meinproc << QLatin1String( "--output" ) << m_cacheFile;
- *meinproc << QLatin1String( "--stylesheet" )
- << KStandardDirs::locate( "data", QLatin1String( "khelpcenter/glossary.xslt" ) );
- *meinproc << m_sourceFile;
-
- meinproc->start( K3Process::NotifyOnExit );
+ m_meinProc->start();
}
-
-void Glossary::meinprocExited( K3Process *meinproc )
+void Glossary::meinprocFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
- delete meinproc;
+ delete m_meinProc;
if ( !QFile::exists( m_cacheFile ) )
return;
@@ -177,7 +186,11 @@
m_status = CacheOk;
KXmlGuiWindow *mainWindow = dynamic_cast<KXmlGuiWindow *>( kapp->activeWindow() );
+#ifndef Q_WS_WIN
Q_ASSERT( mainWindow );
+#else
+ if (mainWindow)
+#endif
mainWindow->statusBar()->showMessage( i18n( "Rebuilding cache... done." ), 2000 );
buildGlossaryTree();
Index: runtime/khelpcenter/glossary.h
===================================================================
--- runtime/khelpcenter/glossary.h (revision 747562)
+++ runtime/khelpcenter/glossary.h (working copy)
@@ -26,9 +26,8 @@
#include <QList>
#include <ksharedconfig.h>
#include <QHash>
+#include <KProcess>
-class K3Process;
-
class EntryItem;
namespace KHC {
@@ -115,7 +114,7 @@
void entrySelected( const GlossaryEntry &entry );
private Q_SLOTS:
- void meinprocExited( K3Process *meinproc );
+ void meinprocFinished(int exitCode, QProcess::ExitStatus exitStatus);
void treeItemSelected( Q3ListViewItem *item );
protected:
@@ -137,8 +136,9 @@
QString m_cacheFile;
CacheStatus m_status;
QHash<QString, GlossaryEntry*> m_glossEntries;
- QHash<QString, EntryItem*> m_idDict;
- bool m_initialized;
+ QHash<QString, EntryItem*> m_idDict;
+ bool m_initialized;
+ KProcess *m_meinProc;
};
}
Index: runtime/khelpcenter/kcmhelpcenter.cpp
===================================================================
--- runtime/khelpcenter/kcmhelpcenter.cpp (revision 747562)
+++ runtime/khelpcenter/kcmhelpcenter.cpp (working copy)
@@ -37,7 +37,7 @@
#include <kaboutdata.h>
#include <kdialog.h>
#include <kstandarddirs.h>
-#include <k3process.h>
+#include <kprocess.h>
#include <kapplication.h>
#include <ktemporaryfile.h>
#include <kurlrequester.h>
@@ -470,8 +470,7 @@
{
kDebug() << "KCMHelpCenter::startIndexProcess()";
- mProcess = new K3Process;
-
+ mProcess = new KProcess;
if ( mRunAsRoot ) {
*mProcess << "kdesu" << "--nonewdcop";
kDebug() << "Run as root";
@@ -481,17 +480,15 @@
*mProcess << mCmdFile->name();
*mProcess << Prefs::indexDirectory();
- connect( mProcess, SIGNAL( processExited( K3Process * ) ),
- SLOT( slotIndexFinished( K3Process * ) ) );
- connect( mProcess, SIGNAL( receivedStdout( K3Process *, char *, int ) ),
- SLOT( slotReceivedStdout(K3Process *, char *, int ) ) );
- connect( mProcess, SIGNAL( receivedStderr( K3Process *, char *, int ) ),
- SLOT( slotReceivedStderr( K3Process *, char *, int ) ) );
+ mProcess->setOutputChannelMode(KProcess::SeparateChannels);
+ connect( mProcess, SIGNAL( readyReadStandardError() ),
+ SLOT( slotReceivedStdout() ) );
+ connect( mProcess, SIGNAL( readyReadStandardOutput() ),
+ SLOT( slotReceivedStderr() ) );
+ connect( mProcess, SIGNAL( finished(int, QProcess::ExitStatus) ),
+ SLOT( slotIndexFinished(int, QProcess::ExitStatus) ) );
- if ( !mProcess->start( K3Process::NotifyOnExit, K3Process::AllOutput ) ) {
- kError() << "KCMHelpcenter::startIndexProcess(): Failed to start process."
- << endl;
- }
+ mProcess->start();
}
void KCMHelpCenter::cancelBuildIndex()
@@ -507,21 +504,11 @@
}
}
-void KCMHelpCenter::slotIndexFinished( K3Process *proc )
+void KCMHelpCenter::slotIndexFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
kDebug() << "KCMHelpCenter::slotIndexFinished()";
- if ( proc == 0 ) {
- kWarning() << "Process null." ;
- return;
- }
-
- if ( proc != mProcess ) {
- kError() << "Unexpected Process finished." << endl;
- return;
- }
-
- if ( mProcess->normalExit() && mProcess->exitStatus() == 2 ) {
+ if ( exitStatus == KProcess::NormalExit && exitCode == 2 ) {
if ( mRunAsRoot ) {
kError() << "Insufficient permissions." << endl;
} else {
@@ -531,8 +518,8 @@
startIndexProcess();
return;
}
- } else if ( !mProcess->normalExit() || mProcess->exitStatus() != 0 ) {
- kDebug() << "K3Process reported an error.";
+ } else if ( exitStatus == KProcess::CrashExit || exitCode != 0 ) {
+ kDebug() << "KProcess reported an error.";
KMessageBox::error( this, i18n("Failed to build index.") );
} else {
mConfig->group( "Search" ).writeEntry( "IndexExists", true );
@@ -610,10 +597,10 @@
}
}
-void KCMHelpCenter::slotReceivedStdout( K3Process *, char *buffer, int buflen )
+void KCMHelpCenter::slotReceivedStdout()
{
- QString text = QString::fromLocal8Bit( buffer, buflen );
- int pos = text.lastIndexOf( QLatin1Char('\n') );
+ QByteArray text= mProcess->readAllStandardOutput();
+ int pos = text.lastIndexOf( '\n' );
if ( pos < 0 ) {
mStdOut.append( text );
} else {
@@ -624,9 +611,9 @@
}
}
-void KCMHelpCenter::slotReceivedStderr( K3Process *, char *buffer, int buflen )
+void KCMHelpCenter::slotReceivedStderr( )
{
- QString text = QString::fromLocal8Bit( buffer, buflen );
+ QString text = mProcess->readAllStandardError();
int pos = text.lastIndexOf( QLatin1Char('\n') );
if ( pos < 0 ) {
mStdErr.append( text );
Index: runtime/khelpcenter/kcmhelpcenter.h
===================================================================
--- runtime/khelpcenter/kcmhelpcenter.h (revision 747562)
+++ runtime/khelpcenter/kcmhelpcenter.h (working copy)
@@ -23,6 +23,7 @@
#include <kdialog.h>
#include <ksharedconfig.h>
+#include <KProcess>
#include "scopeitem.h"
@@ -31,7 +32,6 @@
class QTextEdit;
class QLabel;
-class K3Process;
class KAboutData;
class KTemporaryFile;
class KUrlRequester;
@@ -113,9 +113,9 @@
protected Q_SLOTS:
bool buildIndex();
void cancelBuildIndex();
- void slotIndexFinished( K3Process * );
- void slotReceivedStdout(K3Process *proc, char *buffer, int buflen);
- void slotReceivedStderr(K3Process *proc, char *buffer, int buflen);
+ void slotIndexFinished( int exitCode, QProcess::ExitStatus exitStatus );
+ void slotReceivedStdout();
+ void slotReceivedStderr();
void slotProgressClosed();
void slotOk();
@@ -154,7 +154,7 @@
KTemporaryFile *mCmdFile;
- K3Process *mProcess;
+ KProcess *mProcess;
bool mIsClosing;
Index: runtime/khelpcenter/khc_indexbuilder.cpp
===================================================================
--- runtime/khelpcenter/khc_indexbuilder.cpp (revision 747562)
+++ runtime/khelpcenter/khc_indexbuilder.cpp (working copy)
@@ -28,7 +28,7 @@
#include <kcmdlineargs.h>
#include <kuniqueapplication.h>
#include <kdebug.h>
-#include <k3process.h>
+#include <kprocess.h>
#include <kconfig.h>
#include <QFile>
@@ -82,56 +82,56 @@
kDebug(1402) << "PROCESS: " << cmd;
- K3Process *proc = new K3Process;
- proc->setRunPrivileged( true );
+ mProcess = new KProcess;
QStringList args = cmd.split( " ");
- *proc << args;
+ *mProcess << args;
- connect( proc, SIGNAL( processExited( K3Process * ) ),
- SLOT( slotProcessExited( K3Process * ) ) );
- connect( proc, SIGNAL( receivedStdout(K3Process *, char *, int ) ),
- SLOT( slotReceivedStdout(K3Process *, char *, int ) ) );
- connect( proc, SIGNAL( receivedStderr(K3Process *, char *, int ) ),
- SLOT( slotReceivedStderr(K3Process *, char *, int ) ) );
+ connect( mProcess, SIGNAL( finished( int exitCode, QProcess::ExitStatus exitStatus ) ),
+ SLOT( slotProcessExited( int exitCode, QProcess::ExitStatus exitStatus ) ) );
+ connect( mProcess, SIGNAL( readAllStandardOutput() ),
+ SLOT( slotReceivedStdout() ) );
+ connect( mProcess, SIGNAL( readAllStandardError() ),
+ SLOT( slotReceivedStderr() ) );
mCmdQueue.erase( it );
- if ( !proc->start( K3Process::NotifyOnExit, K3Process::AllOutput ) ) {
+ mProcess->start();
+ while (mProcess->state() == KProcess::Starting)
+ ;
+ if (mProcess->state() == KProcess::NotRunning) {
sendErrorSignal( i18n("Unable to start command '%1'.", cmd ) );
processCmdQueue();
- delete proc;
+ delete mProcess;
}
}
-void IndexBuilder::slotProcessExited( K3Process *proc )
+void IndexBuilder::slotProcessExited( int exitCode, QProcess::ExitStatus exitStatus )
{
kDebug(1402) << "IndexBuilder::slotIndexFinished()";
- if ( !proc->normalExit() ) {
+ if ( exitStatus != KProcess::NormalExit ) {
kError(1402) << "Process failed" << endl;
} else {
- int status = proc->exitStatus();
+ int status = exitCode;
kDebug(1402) << "Exit status: " << status;
}
- delete proc;
+ delete mProcess;
sendProgressSignal();
processCmdQueue();
}
-void IndexBuilder::slotReceivedStdout( K3Process *, char *buffer, int buflen )
+void IndexBuilder::slotReceivedStdout()
{
- QString text = QString::fromLocal8Bit( buffer, buflen );
- std::cout << text.toLocal8Bit().data() << std::flush;
+ std::cout << mProcess->readAllStandardOutput().data() << std::flush;
}
-void IndexBuilder::slotReceivedStderr( K3Process *, char *buffer, int buflen )
+void IndexBuilder::slotReceivedStderr()
{
- QString text = QString::fromLocal8Bit( buffer, buflen );
- std::cerr << text.toLocal8Bit().data() << std::flush;
+ std::cerr << mProcess->readAllStandardError().data() << std::flush;
}
void IndexBuilder::sendErrorSignal( const QString &error )
Index: runtime/khelpcenter/khc_indexbuilder.h
===================================================================
--- runtime/khelpcenter/khc_indexbuilder.h (revision 747562)
+++ runtime/khelpcenter/khc_indexbuilder.h (working copy)
@@ -22,12 +22,11 @@
#define KHC_INDEXBUILDER_H
#include <kuniqueapplication.h>
+#include <KProcess>
#include <QObject>
#include <QTimer>
-class K3Process;
-
namespace KHC {
class IndexBuilder : public QObject
@@ -45,14 +44,15 @@
protected Q_SLOTS:
void buildIndices();
- void slotProcessExited( K3Process * );
- void slotReceivedStdout( K3Process *, char *buffer, int buflen );
- void slotReceivedStderr( K3Process *, char *buffer, int buflen );
+ void slotProcessExited( int exitCode, QProcess::ExitStatus exitStatus );
+ void slotReceivedStdout();
+ void slotReceivedStderr();
private:
QString m_cmdFile;
QTimer mTimer;
QStringList mCmdQueue;
+ KProcess *mProcess;
};
}
Index: runtime/khelpcenter/navigator.cpp
===================================================================
--- runtime/khelpcenter/navigator.cpp (revision 747562)
+++ runtime/khelpcenter/navigator.cpp (working copy)
@@ -53,7 +53,6 @@
#include <KLineEdit>
#include <kmessagebox.h>
#include <kiconloader.h>
-#include <k3procio.h>
#include <kcharsets.h>
#include <kdialog.h>
#include <kdesktopfile.h>
Index: runtime/khelpcenter/scrollkeepertreebuilder.cpp
===================================================================
--- runtime/khelpcenter/scrollkeepertreebuilder.cpp (revision 747562)
+++ runtime/khelpcenter/scrollkeepertreebuilder.cpp (working copy)
@@ -28,7 +28,9 @@
#include <kdebug.h>
#include <kglobal.h>
#include <klocale.h>
+#ifndef Q_WS_WIN
#include <k3procio.h>
+#endif
#include <QtXml/QtXml>
#include <QFile>
@@ -57,6 +59,10 @@
QString lang = KGlobal::locale()->language();
kDebug(1400) << "ScrollKeeper language: " << lang;
+#ifdef Q_WS_WIN
+ kDebug(1400) << "running \"scrollkeeper-get-content-list\" not implemented yet";
+ return 0;
+#else
K3ProcIO proc;
proc << "scrollkeeper-get-content-list";
@@ -72,6 +78,7 @@
<< "' does not exist." << endl;
return 0;
}
+#endif
QDomDocument doc("ScrollKeeperContentsList");
QFile f(mContentsList);
@@ -108,10 +115,12 @@
void ScrollKeeperTreeBuilder::getContentsList( K3ProcIO *proc )
{
+#ifndef Q_WS_WIN
QString filename;
proc->readln( filename, true );
mContentsList = filename;
+#endif
}
int ScrollKeeperTreeBuilder::insertSection( NavigatorItem *parent,
Index: runtime/khelpcenter/searchengine.cpp
===================================================================
--- runtime/khelpcenter/searchengine.cpp (revision 747562)
+++ runtime/khelpcenter/searchengine.cpp (working copy)
@@ -7,7 +7,7 @@
#include <KConfig>
#include <KDebug>
#include <KStandardDirs>
-#include <K3Process>
+#include <KProcess>
#include <KLocale>
#include <KMessageBox>
@@ -245,32 +245,17 @@
return true;
}
-
-void SearchEngine::searchStdout(K3Process *, char *buffer, int len)
+void SearchEngine::searchStdout()
{
- if ( !buffer || len == 0 )
- return;
-
- QString bufferStr;
- char *p;
- p = (char*) malloc( sizeof(char) * (len+1) );
- p = strncpy( p, buffer, len );
- p[len] = '\0';
-
- mSearchResult += bufferStr.fromUtf8(p);
-
- free(p);
+ mSearchResult += mProc->readAllStandardOutput();
}
-void SearchEngine::searchStderr(K3Process *, char *buffer, int len)
+void SearchEngine::searchStderr()
{
- if ( !buffer || len == 0 )
- return;
-
- mStderr.append( QString::fromUtf8( buffer, len ) );
+ mStderr.append(mProc->readAllStandardError());
}
-void SearchEngine::searchExited(K3Process *)
+void SearchEngine::searchExited(int exitCode, QProcess::ExitStatus exitStatus)
{
kDebug() << "Search terminated";
mSearchRunning = false;
@@ -339,8 +324,7 @@
kDebug() << "Common Search: " << commonSearchProgram;
- mProc = new K3Process();
-
+ mProc = new KProcess();
QStringList cmd = commonSearchProgram.split( " ");
QStringList::ConstIterator it;
for( it = cmd.begin(); it != cmd.end(); ++it ) {
@@ -349,26 +333,26 @@
arg.endsWith(QLatin1Char('\"'))) {
arg = arg.mid( 1, arg.length() - 2 );
}
- *mProc << arg.toUtf8();
+ mProc << arg.toUtf8();
}
- connect( mProc, SIGNAL( receivedStdout( K3Process *, char *, int ) ),
- SLOT( searchStdout( K3Process *, char *, int ) ) );
- connect( mProc, SIGNAL( receivedStderr( K3Process *, char *, int ) ),
- SLOT( searchStderr( K3Process *, char *, int ) ) );
- connect( mProc, SIGNAL( processExited( K3Process * ) ),
- SLOT( searchExited( K3Process * ) ) );
+ connect( mProc, SIGNAL( readyReadStandardError() ),
+ SLOT( searchStdout() ) );
+ connect( mProc, SIGNAL( readyReadStandardOutput() ),
+ SLOT( searchStderr() ) );
+ connect( mProc, SIGNAL( finished(int, QProcess::ExitStatus) ),
+ SLOT( searchExited(int, QProcess::ExitStatus) ) );
mSearchRunning = true;
mSearchResult = "";
mStderr = "<b>" + commonSearchProgram + "</b>\n\n";
- mProc->start(K3Process::NotifyOnExit, K3Process::All);
+ mProc->start();
- while (mSearchRunning && mProc->isRunning())
+ while (mSearchRunning && mProc->state() == QProcess::Running)
kapp->processEvents();
- if ( !mProc->normalExit() || mProc->exitStatus() != 0 ) {
+ if ( mProc->exitStatus() == KProcess::CrashExit || mProc->exitCode() != 0 ) {
kError() << "Unable to run search program '" << commonSearchProgram
<< "'" << endl;
delete mProc;
Index: runtime/khelpcenter/searchengine.h
===================================================================
--- runtime/khelpcenter/searchengine.h (revision 747562)
+++ runtime/khelpcenter/searchengine.h (working copy)
@@ -4,11 +4,11 @@
#include <QObject>
+#include <KProcess>
#include <kio/job.h>
#include "docentrytraverser.h"
-class K3Process;
namespace KHC {
@@ -109,15 +109,15 @@
void searchFinished();
protected Q_SLOTS:
- void searchStdout(K3Process *proc, char *buffer, int buflen);
- void searchStderr(K3Process *proc, char *buffer, int buflen);
- void searchExited(K3Process *proc);
+ void searchStdout();
+ void searchStderr();
+ void searchExited(int, QProcess::ExitStatus);
protected:
void processSearchQueue();
private:
- K3Process *mProc;
+ KProcess *mProc;
bool mSearchRunning;
QString mSearchResult;
Index: runtime/khelpcenter/searchhandler.cpp
===================================================================
--- runtime/khelpcenter/searchhandler.cpp (revision 747562)
+++ runtime/khelpcenter/searchhandler.cpp (working copy)
@@ -25,7 +25,7 @@
#include "docentry.h"
#include <kdesktopfile.h>
-#include <k3process.h>
+#include <KProcess>
#include <kdebug.h>
#include <kmessagebox.h>
#include <klocale.h>
@@ -35,6 +35,99 @@
using namespace KHC;
+SearchJob::SearchJob(DocEntry *entry) : mEntry( entry ), mProcess( 0 ), mKioJob( 0 )
+{
+}
+
+bool SearchJob::startLocal(const QString &cmdString)
+{
+ mProcess = new KProcess;
+ mCmd = cmdString;
+
+ QStringList cmd = cmdString.split( " ");
+ QStringList::ConstIterator it;
+ for( it = cmd.begin(); it != cmd.end(); ++it ) {
+ QString arg = *it;
+ if ( arg.left( 1 ) == "\"" && arg.right( 1 ) =="\"" ) {
+ arg = arg.mid( 1, arg.length() - 2 );
+ }
+ *mProcess << arg.toUtf8();
+ }
+ connect( mProcess, SIGNAL( readyReadStandardError() ),
+ this, SLOT( searchStdout() ) );
+ connect( mProcess, SIGNAL( readyReadStandardOutput() ),
+ this, SLOT( searchStderr() ) );
+ connect( mProcess, SIGNAL( finished(int, QProcess::ExitStatus) ),
+ this, SLOT( searchExited(int, QProcess::ExitStatus) ) );
+
+ mProcess->start();
+ while (mProcess->state() == KProcess::Starting)
+ ;
+ if (mProcess->state() == KProcess::NotRunning) {
+ QString txt = i18n("Error executing search command '%1'.", cmdString );
+ emit searchFinished( this, mEntry, txt );
+ return false;
+ }
+ return true;
+ }
+
+bool SearchJob::startRemote(const QString &urlString)
+{
+ KIO::TransferJob *job = KIO::get( KUrl( urlString ) );
+ connect( job, SIGNAL( result( KJob * ) ),
+ this, SLOT( slotJobResult( KJob * ) ) );
+ connect( job, SIGNAL( data( KIO::Job *, const QByteArray & ) ),
+ this, SLOT( slotJobData( KIO::Job *, const QByteArray & ) ) );
+
+ mKioJob = job;
+ return true;
+}
+
+SearchJob::~SearchJob()
+{
+ delete mProcess;
+ delete mKioJob;
+}
+
+void SearchJob::searchStdout()
+{
+ mResult += mProcess->readAllStandardOutput();
+}
+
+void SearchJob::searchStderr()
+{
+ mError += mProcess->readAllStandardOutput();
+}
+
+void SearchJob::searchExited( int exitCode, QProcess::ExitStatus exitStatus )
+{
+ QString error = QLatin1String("<em>") + mCmd + QLatin1String("</em>\n") + mError;
+
+ if ( exitStatus == KProcess::NormalExit && exitCode == 0 ) {
+ emit searchFinished( this, mEntry, mResult );
+ } else {
+ emit searchError( this, mEntry, error );
+ }
+}
+
+void SearchJob::slotJobResult( KJob *job )
+{
+ QString result;
+ DocEntry *entry = 0;
+
+ if ( job->error() ) {
+ emit searchError( this, mEntry, i18n("Error: %1", job->errorString() ) );
+ } else {
+ emit searchFinished( this, mEntry, mResult );
+ }
+}
+
+void SearchJob::slotJobData( KIO::Job *job, const QByteArray &data )
+{
+ mResult += data.data();
+}
+
+
SearchHandler::SearchHandler()
{
mLang = KGlobal::locale()->language().left( 2 );
@@ -102,148 +195,42 @@
kDebug() << "SearchHandler::search() CMD: " << cmdString;
- K3Process *proc = new K3Process();
+ SearchJob *searchJob = new SearchJob(entry);
+ connect(searchJob, SIGNAL(searchFinished( SearchJob *, DocEntry *, const QString & )),
+ this, SLOT(searchFinished( SearchJob *, DocEntry *, const QString & )));
+ connect(searchJob, SIGNAL(searchFinished( SearchJob *, DocEntry *, const QString & )),
+ this, SLOT(searchError( SearchJob *, DocEntry *, const QString & )));
+ searchJob->startLocal(cmdString);
- QStringList cmd = cmdString.split( " ");
- QStringList::ConstIterator it;
- for( it = cmd.begin(); it != cmd.end(); ++it ) {
- QString arg = *it;
- if ( arg.left( 1 ) == "\"" && arg.right( 1 ) =="\"" ) {
- arg = arg.mid( 1, arg.length() - 2 );
- }
- *proc << arg.toUtf8();
- }
-
- connect( proc, SIGNAL( receivedStdout( K3Process *, char *, int ) ),
- SLOT( searchStdout( K3Process *, char *, int ) ) );
- connect( proc, SIGNAL( receivedStderr( K3Process *, char *, int ) ),
- SLOT( searchStderr( K3Process *, char *, int ) ) );
- connect( proc, SIGNAL( processExited( K3Process * ) ),
- SLOT( searchExited( K3Process * ) ) );
-
- SearchJob *searchJob = new SearchJob;
- searchJob->mEntry = entry;
- searchJob->mProcess = proc;
- searchJob->mCmd = cmdString;
-
- mProcessJobs.insert( proc, searchJob );
-
- if ( !proc->start( K3Process::NotifyOnExit, K3Process::All ) ) {
- QString txt = i18n("Error executing search command '%1'.", cmdString );
- emit searchFinished( this, entry, txt );
- }
} else if ( !mSearchUrl.isEmpty() ) {
QString urlString = SearchEngine::substituteSearchQuery( mSearchUrl,
entry->identifier(), words, maxResults, operation, mLang );
kDebug() << "SearchHandler::search() URL: " << urlString;
- KIO::TransferJob *job = KIO::get( KUrl( urlString ) );
- connect( job, SIGNAL( result( KJob * ) ),
- SLOT( slotJobResult( KJob * ) ) );
- connect( job, SIGNAL( data( KIO::Job *, const QByteArray & ) ),
- SLOT( slotJobData( KIO::Job *, const QByteArray & ) ) );
+ SearchJob *searchJob = new SearchJob(entry);
+ connect(searchJob, SIGNAL(searchError( SearchJob *, DocEntry *, const QString & )),
+ this, SLOT(searchFinished( SearchJob *, DocEntry *, const QString & )));
+ connect(searchJob, SIGNAL(searchError( SearchJob *, DocEntry *, const QString & )),
+ this, SLOT(searchError( SearchJob *, DocEntry *, const QString & )));
+ searchJob->startRemote(urlString);
- SearchJob *searchJob = new SearchJob;
- searchJob->mEntry = entry;
- searchJob->mKioJob = job;
- mKioJobs.insert( job, searchJob );
} else {
QString txt = i18n("No search command or URL specified.");
emit searchFinished( this, entry, txt );
- return;
}
}
-void SearchHandler::searchStdout( K3Process *proc, char *buffer, int len )
+void SearchHandler::searchFinished( SearchJob *job, DocEntry *entry, const QString &result )
{
- if ( !buffer || len == 0 )
- return;
-
- QString bufferStr;
- char *p;
- p = (char*) malloc( sizeof(char) * ( len + 1 ) );
- p = strncpy( p, buffer, len );
- p[len] = '\0';
-
- QMap<K3Process *, SearchJob *>::ConstIterator it = mProcessJobs.find( proc );
- if ( it != mProcessJobs.end() ) {
- (*it)->mResult += bufferStr.fromUtf8( p );
- }
-
- free( p );
+ delete job;
+ emit searchFinished( this, entry, result);
}
-void SearchHandler::searchStderr( K3Process *proc, char *buffer, int len )
+void SearchHandler::searchError( SearchJob *job, DocEntry *entry, const QString &error )
{
- if ( !buffer || len == 0 )
- return;
-
- QMap<K3Process *, SearchJob *>::ConstIterator it = mProcessJobs.find( proc );
- if ( it != mProcessJobs.end() ) {
- (*it)->mError += QString::fromUtf8( buffer, len );
- }
+ delete job;
+ emit searchError(this, entry, error);
}
-void SearchHandler::searchExited( K3Process *proc )
-{
-// kDebug() << "SearchHandler::searchExited()";
-
- QString result;
- QString error;
- DocEntry *entry = 0;
-
- QMap<K3Process *, SearchJob *>::ConstIterator it = mProcessJobs.find( proc );
- if ( it != mProcessJobs.end() ) {
- SearchJob *j = *it;
- entry = j->mEntry;
- result = j->mResult;
- error = QLatin1String("<em>") + j->mCmd + QLatin1String("</em>\n") + j->mError;
-
- mProcessJobs.remove( proc );
- delete j;
- } else {
- kError() << "No search job for exited process found." << endl;
- }
-
- if ( proc->normalExit() && proc->exitStatus() == 0 ) {
- emit searchFinished( this, entry, result );
- } else {
- emit searchError( this, entry, error );
- }
-}
-
-void SearchHandler::slotJobResult( KJob *job )
-{
- QString result;
- DocEntry *entry = 0;
-
- QMap<KJob *, SearchJob *>::ConstIterator it = mKioJobs.find( job );
- if ( it != mKioJobs.end() ) {
- SearchJob *j = *it;
-
- entry = j->mEntry;
- result = j->mResult;
-
- mKioJobs.remove( job );
- delete j;
- }
-
- if ( job->error() ) {
- emit searchError( this, entry, i18n("Error: %1", job->errorString() ) );
- } else {
- emit searchFinished( this, entry, result );
- }
-}
-
-void SearchHandler::slotJobData( KIO::Job *job, const QByteArray &data )
-{
-// kDebug() << "SearchHandler::slotJobData()";
-
- QMap<KJob *, SearchJob *>::ConstIterator it = mKioJobs.find( job );
- if ( it != mKioJobs.end() ) {
- (*it)->mResult += data.data();
- }
-}
-
#include "searchhandler.moc"
Index: runtime/khelpcenter/searchhandler.h
===================================================================
--- runtime/khelpcenter/searchhandler.h (revision 747562)
+++ runtime/khelpcenter/searchhandler.h (working copy)
@@ -30,18 +30,31 @@
namespace KHC {
-class SearchJob
-{
+class SearchJob : public QObject {
+ Q_OBJECT
public:
- SearchJob() : mProcess( 0 ), mKioJob( 0 ) {}
+ SearchJob(DocEntry *entry);
+ ~SearchJob();
+ bool startLocal(const QString &cmdString);
+ bool startRemote(const QString &url);
+
+ Q_SIGNALS:
+ void searchFinished( SearchJob *, DocEntry *, const QString & );
+ void searchError( SearchJob *, DocEntry *, const QString & );
+
+ protected Q_SLOTS:
+ void searchStdout( );
+ void searchStderr( );
+ void searchExited( int exitCode, QProcess::ExitStatus );
+ void slotJobResult( KJob *job );
+ void slotJobData( KIO::Job *, const QByteArray &data );
+
+ protected:
DocEntry *mEntry;
-
- K3Process *mProcess;
+ KProcess *mProcess;
KIO::Job *mKioJob;
-
QString mCmd;
-
QString mResult;
QString mError;
};
@@ -66,17 +79,14 @@
void searchFinished( SearchHandler *, DocEntry *, const QString & );
void searchError( SearchHandler *, DocEntry *, const QString & );
+
protected:
bool checkBinary( const QString &cmd ) const;
+
+ private slots:
+ void searchFinished( SearchJob *, DocEntry *, const QString & );
+ void searchError( SearchJob *, DocEntry *, const QString & );
- protected Q_SLOTS:
- void searchStdout( K3Process *proc, char *buffer, int buflen );
- void searchStderr( K3Process *proc, char *buffer, int buflen );
- void searchExited( K3Process *proc );
-
- void slotJobResult( KJob *job );
- void slotJobData( KIO::Job *, const QByteArray &data );
-
private:
SearchHandler();
@@ -87,8 +97,7 @@
QString mIndexCommand;
QStringList mDocumentTypes;
- QMap<K3Process *,SearchJob *> mProcessJobs;
- QMap<KJob *,SearchJob *> mKioJobs;
+ QList<SearchJob *> mSearchJobs;
};
}
Index: runtime/khelpcenter/toc.cpp
===================================================================
--- runtime/khelpcenter/toc.cpp (revision 747562)
+++ runtime/khelpcenter/toc.cpp (working copy)
@@ -23,7 +23,7 @@
#include "docentry.h"
#include <kiconloader.h>
-#include <k3process.h>
+#include <kprocess.h>
#include <kstandarddirs.h>
#include <kdebug.h>
@@ -134,26 +134,31 @@
void TOC::buildCache()
{
- K3Process *meinproc = new K3Process;
- connect( meinproc, SIGNAL( processExited( K3Process * ) ),
- this, SLOT( meinprocExited( K3Process * ) ) );
+ m_meinproc = new KProcess;
+ connect( m_meinproc, SIGNAL( finished( int, QProcess::exitStatus) ),
+ this, SLOT( meinprocExited( int, QProcess::exitStatus) ) );
- *meinproc << KStandardDirs::locate( "exe", "meinproc4" );
- *meinproc << "--stylesheet" << KStandardDirs::locate( "data", "khelpcenter/table-of-contents.xslt" );
- *meinproc << "--output" << m_cacheFile;
- *meinproc << m_sourceFile;
+#ifdef Q_WS_WIN
+ // KStandardDirs::locate return "" on win32, hardcoded for now
+ *m_meinproc << "meinproc4";
+#else
+ *m_meinproc << *m_meinproc << KStandardDirs::locate( "exe", "meinproc4" );
+#endif
+ *m_meinproc << "--stylesheet" << KStandardDirs::locate( "data", "khelpcenter/table-of-contents.xslt" );
+ *m_meinproc << "--output" << m_cacheFile;
+ *m_meinproc << m_sourceFile;
- meinproc->start( K3Process::NotifyOnExit );
+ m_meinproc->start();
}
-void TOC::meinprocExited( K3Process *meinproc )
+void TOC::meinprocExited( int exitCode, QProcess::ExitStatus exitStatus)
{
- if ( !meinproc->normalExit() || meinproc->exitStatus() != 0 ) {
- delete meinproc;
+ if ( exitStatus == KProcess::CrashExit || exitCode != 0 ) {
+ delete m_meinproc;
return;
}
- delete meinproc;
+ delete m_meinproc;
QFile f( m_cacheFile );
if ( !f.open( QIODevice::ReadWrite ) )
Index: runtime/khelpcenter/toc.h
===================================================================
--- runtime/khelpcenter/toc.h (revision 747562)
+++ runtime/khelpcenter/toc.h (working copy)
@@ -26,7 +26,7 @@
#include <Qt3Support/Q3CheckListItem>
#include <QObject>
-class K3Process;
+#include <KProcess>
namespace KHC {
@@ -47,7 +47,7 @@
private Q_SLOTS:
void slotItemSelected( Q3ListViewItem *item );
- void meinprocExited( K3Process *meinproc );
+ void meinprocExited( int exitCode, QProcess::ExitStatus exitStatus);
private:
enum CacheStatus { NeedRebuild, CacheOk };
@@ -64,6 +64,7 @@
QString m_sourceFile;
NavigatorItem *m_parentItem;
+ KProcess *m_meinproc;
};
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic