util
executecompositejob.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "executecompositejob.h"
00021
00022 #include <kdebug.h>
00023
00024 namespace KDevelop
00025 {
00026 class ExecuteCompositeJobPrivate
00027 {
00028 public:
00029 bool m_killing;
00030 };
00031
00032 ExecuteCompositeJob::ExecuteCompositeJob(QObject* parent, const QList<KJob*>& jobs)
00033 : KCompositeJob(parent), d(new ExecuteCompositeJobPrivate)
00034 {
00035 d->m_killing = false;
00036 setCapabilities(Killable);
00037
00038 qDebug() << "execute composite" << jobs;
00039 foreach(KJob* job, jobs) {
00040 addSubjob(job);
00041 }
00042 }
00043
00044 ExecuteCompositeJob::~ExecuteCompositeJob()
00045 {
00046 delete d;
00047 }
00048
00049 void ExecuteCompositeJob::start()
00050 {
00051 if(hasSubjobs())
00052 subjobs().first()->start();
00053 else
00054 emitResult();
00055 }
00056
00057 void ExecuteCompositeJob::slotResult(KJob* job)
00058 {
00059 kDebug() << "finished: "<< job << job->error() << error();
00060 KCompositeJob::slotResult(job);
00061
00062 if(hasSubjobs() && !error() && !d->m_killing)
00063 {
00064 kDebug() << "remaining: " << subjobs().count() << subjobs();
00065 KJob* nextJob=subjobs().first();
00066 nextJob->start();
00067 } else {
00068 emitResult();
00069 }
00070 }
00071
00072 bool ExecuteCompositeJob::doKill()
00073 {
00074 d->m_killing = true;
00075 while(hasSubjobs()) {
00076 KJob* j = subjobs().first();
00077 if( !j ) {
00078 removeSubjob(j);
00079 continue;
00080 }
00081 if (j->kill()) {
00082 removeSubjob(j);
00083 } else {
00084 return false;
00085 }
00086 }
00087 return true;
00088 }
00089
00090 }
00091
00092 #include "executecompositejob.moc"