• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • kdecore
  • jobs
kcompositejob.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  Copyright (C) 2006 Kevin Ottens <ervin@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 
18 */
19 
20 #include "kcompositejob.h"
21 #include "kcompositejob_p.h"
22 
23 KCompositeJobPrivate::KCompositeJobPrivate()
24 {
25 }
26 
27 KCompositeJobPrivate::~KCompositeJobPrivate()
28 {
29 }
30 
31 KCompositeJob::KCompositeJob( QObject *parent )
32  : KJob( *new KCompositeJobPrivate, parent )
33 {
34 }
35 
36 KCompositeJob::KCompositeJob( KCompositeJobPrivate &dd, QObject *parent )
37  : KJob( dd, parent)
38 {
39 }
40 
41 KCompositeJob::~KCompositeJob()
42 {
43 }
44 
45 bool KCompositeJob::addSubjob( KJob *job )
46 {
47  Q_D(KCompositeJob);
48  if ( job == 0 || d->subjobs.contains( job ) )
49  {
50  return false;
51  }
52 
53  job->setParent(this);
54  d->subjobs.append(job);
55  connect( job, SIGNAL(result(KJob*)),
56  SLOT(slotResult(KJob*)) );
57 
58  // Forward information from that subjob.
59  connect( job, SIGNAL(infoMessage(KJob*,QString,QString)),
60  SLOT(slotInfoMessage(KJob*,QString,QString)) );
61 
62  return true;
63 }
64 
65 bool KCompositeJob::removeSubjob( KJob *job )
66 {
67  Q_D(KCompositeJob);
68  if ( job == 0 )
69  {
70  return false;
71  }
72 
73  job->setParent(0);
74  d->subjobs.removeAll( job );
75 
76  return true;
77 }
78 
79 // KDE5: Make this method const
80 bool KCompositeJob::hasSubjobs()
81 {
82  return !d_func()->subjobs.isEmpty();
83 }
84 
85 const QList<KJob*> &KCompositeJob::subjobs() const
86 {
87  return d_func()->subjobs;
88 }
89 
90 void KCompositeJob::clearSubjobs()
91 {
92  Q_D(KCompositeJob);
93  Q_FOREACH(KJob *job, d->subjobs) {
94  job->setParent(0);
95  }
96  d->subjobs.clear();
97 }
98 
99 void KCompositeJob::slotResult( KJob *job )
100 {
101  // Did job have an error ?
102  if ( job->error() && !error() )
103  {
104  // Store it in the parent only if first error
105  setError( job->error() );
106  setErrorText( job->errorText() );
107  emitResult();
108  }
109 
110  removeSubjob(job);
111 }
112 
113 void KCompositeJob::slotInfoMessage( KJob *job, const QString &plain, const QString &rich )
114 {
115  emit infoMessage( job, plain, rich );
116 }
117 
118 #include "kcompositejob.moc"
KCompositeJob::addSubjob
virtual bool addSubjob(KJob *job)
Add a job that has to be finished before a result is emitted.
Definition: kcompositejob.cpp:45
KCompositeJob::~KCompositeJob
virtual ~KCompositeJob()
Destroys a KCompositeJob object.
Definition: kcompositejob.cpp:41
KCompositeJobPrivate
Definition: kcompositejob_p.h:30
KJob::emitResult
void emitResult()
Utility function to emit the result signal, and suicide this job.
Definition: kjob.cpp:306
KJob::setError
void setError(int errorCode)
Sets the error code.
Definition: kjob.cpp:250
KCompositeJobPrivate::KCompositeJobPrivate
KCompositeJobPrivate()
Definition: kcompositejob.cpp:23
KCompositeJob::slotInfoMessage
virtual void slotInfoMessage(KJob *job, const QString &plain, const QString &rich)
Forward signal from subjob.
Definition: kcompositejob.cpp:113
kcompositejob_p.h
KJob::setErrorText
void setErrorText(const QString &errorText)
Sets the error text.
Definition: kjob.cpp:256
KCompositeJobPrivate::~KCompositeJobPrivate
~KCompositeJobPrivate()
Definition: kcompositejob.cpp:27
kcompositejob.h
QObject
KCompositeJob::slotResult
virtual void slotResult(KJob *job)
Called whenever a subjob finishes.
Definition: kcompositejob.cpp:99
QString
QList< KJob * >
KCompositeJob::KCompositeJob
KCompositeJob(QObject *parent=0)
Creates a new KCompositeJob object.
Definition: kcompositejob.cpp:31
QObject::setParent
void setParent(QObject *parent)
KCompositeJob::clearSubjobs
void clearSubjobs()
Clears the list of subjobs.
Definition: kcompositejob.cpp:90
KCompositeJob::subjobs
const QList< KJob * > & subjobs() const
Retrieves the list of the subjobs.
Definition: kcompositejob.cpp:85
KCompositeJob::hasSubjobs
bool hasSubjobs()
Checks if this job has subjobs running.
Definition: kcompositejob.cpp:80
KJob::result
void result(KJob *job)
Emitted when the job is finished (except when killed with KJob::Quietly).
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KCompositeJob
The base class for all jobs able to be composed of one or more subjobs.
Definition: kcompositejob.h:33
KJob::infoMessage
void infoMessage(KJob *job, const QString &plain, const QString &rich=QString())
Emitted to display state information about this job.
KJob
The base class for all jobs.
Definition: kjob.h:84
KJob::errorText
QString errorText() const
Returns the error text if there has been an error.
Definition: kjob.cpp:225
KJob::error
int error() const
Returns the error code, if there has been an error.
Definition: kjob.cpp:220
KCompositeJob::removeSubjob
virtual bool removeSubjob(KJob *job)
Mark a sub job as being done.
Definition: kcompositejob.cpp:65
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal