KDECore
kcompositejob.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 Copyright (C) 2006 Kevin Ottens <ervin@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 00018 */ 00019 00020 #include "kcompositejob.h" 00021 #include "kcompositejob_p.h" 00022 00023 KCompositeJobPrivate::KCompositeJobPrivate() 00024 { 00025 } 00026 00027 KCompositeJobPrivate::~KCompositeJobPrivate() 00028 { 00029 qDeleteAll(subjobs); 00030 } 00031 00032 KCompositeJob::KCompositeJob( QObject *parent ) 00033 : KJob( *new KCompositeJobPrivate, parent ) 00034 { 00035 } 00036 00037 KCompositeJob::KCompositeJob( KCompositeJobPrivate &dd, QObject *parent ) 00038 : KJob( dd, parent) 00039 { 00040 } 00041 00042 KCompositeJob::~KCompositeJob() 00043 { 00044 } 00045 00046 bool KCompositeJob::addSubjob( KJob *job ) 00047 { 00048 Q_D(KCompositeJob); 00049 if ( job == 0 || d->subjobs.contains( job ) ) 00050 { 00051 return false; 00052 } 00053 00054 d->subjobs.append(job); 00055 00056 connect( job, SIGNAL(result(KJob*)), 00057 SLOT(slotResult(KJob*)) ); 00058 00059 // Forward information from that subjob. 00060 connect( job, SIGNAL(infoMessage(KJob*,QString,QString)), 00061 SLOT(slotInfoMessage(KJob*,QString,QString)) ); 00062 00063 return true; 00064 } 00065 00066 bool KCompositeJob::removeSubjob( KJob *job ) 00067 { 00068 Q_D(KCompositeJob); 00069 if ( job == 0 ) 00070 { 00071 return false; 00072 } 00073 00074 d->subjobs.removeAll( job ); 00075 00076 return true; 00077 } 00078 00079 // KDE5: Make this method const 00080 bool KCompositeJob::hasSubjobs() 00081 { 00082 return !d_func()->subjobs.isEmpty(); 00083 } 00084 00085 const QList<KJob*> &KCompositeJob::subjobs() const 00086 { 00087 return d_func()->subjobs; 00088 } 00089 00090 void KCompositeJob::clearSubjobs() 00091 { 00092 Q_D(KCompositeJob); 00093 d->subjobs.clear(); 00094 } 00095 00096 void KCompositeJob::slotResult( KJob *job ) 00097 { 00098 // Did job have an error ? 00099 if ( job->error() && !error() ) 00100 { 00101 // Store it in the parent only if first error 00102 setError( job->error() ); 00103 setErrorText( job->errorText() ); 00104 emitResult(); 00105 } 00106 00107 removeSubjob(job); 00108 } 00109 00110 void KCompositeJob::slotInfoMessage( KJob *job, const QString &plain, const QString &rich ) 00111 { 00112 emit infoMessage( job, plain, rich ); 00113 } 00114 00115 #include "kcompositejob.moc"
KDE 4.6 API Reference