Messagelib

contentjobbase.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "contentjobbase.h"
8#include "contentjobbase_p.h"
9
10#include "messagecomposer_debug.h"
11
12#include <KMime/Content>
13
14using namespace MessageComposer;
15
16void ContentJobBasePrivate::init(QObject *parent)
17{
18 Q_Q(ContentJobBase);
19 auto parentJob = qobject_cast<ContentJobBase *>(parent);
20 if (parentJob) {
21 if (!parentJob->appendSubjob(q)) {
22 qCWarning(MESSAGECOMPOSER_LOG) << "Impossible to add subjob.";
23 }
24 }
25}
26
27void ContentJobBasePrivate::doNextSubjob()
28{
29 Q_Q(ContentJobBase);
30 if (q->hasSubjobs()) {
31 q->subjobs().first()->start();
32 } else {
33 qCDebug(MESSAGECOMPOSER_LOG) << "Calling process.";
34 q->process();
35 }
36}
37
38ContentJobBase::ContentJobBase(QObject *parent)
39 : JobBase(*new ContentJobBasePrivate(this), parent)
40{
42 d->init(parent);
43}
44
45ContentJobBase::ContentJobBase(ContentJobBasePrivate &dd, QObject *parent)
46 : JobBase(dd, parent)
47{
49 d->init(parent);
50}
51
52ContentJobBase::~ContentJobBase() = default;
53
55{
56 doStart();
57}
58
60{
61 Q_D(const ContentJobBase);
62 // Q_ASSERT( !hasSubjobs() ); // Finished. // JobBase::hasSubjobs is not const :-/ TODO const_cast??
63 Q_ASSERT(d->resultContent); // process() should do something.
64 return d->resultContent;
65}
66
68{
69 job->setParent(this);
70 return KCompositeJob::addSubjob(job);
71}
72
74{
76
77 d->extraContent = extra;
78}
79
81{
82 Q_D(const ContentJobBase);
83
84 return d->extraContent;
85}
86
88{
89 Q_UNUSED(job)
90 qCCritical(MESSAGECOMPOSER_LOG) << "Use appendJob() instead.";
91 Q_ASSERT(false);
92 return false;
93}
94
96{
98 Q_ASSERT(d->resultContent == nullptr && d->subjobContents.isEmpty()); // Not started.
99 Q_ASSERT(!error()); // Jobs emitting an error in doStart should not call ContentJobBase::doStart().
100 d->doNextSubjob();
101}
102
103void ContentJobBase::slotResult(KJob *job)
104{
106 KCompositeJob::slotResult(job); // Handles errors and removes subjob.
107 qCDebug(MESSAGECOMPOSER_LOG) << "A subjob finished." << subjobs().count() << "more to go.";
108 if (error()) {
109 return;
110 }
111
112 Q_ASSERT(dynamic_cast<ContentJobBase *>(job));
113 auto cjob = static_cast<ContentJobBase *>(job);
114 d->subjobContents.append(cjob->content());
115 d->doNextSubjob();
116}
117
118#include "moc_contentjobbase.cpp"
virtual bool addSubjob(KJob *job)
const QList< KJob * > & subjobs() const
virtual void slotResult(KJob *job)
int error() const
The ContentJobBase class.
void setExtraContent(KMime::Content *extra)
Set some extra content to be saved with the job, and available later, for example,...
bool addSubjob(KJob *job) override
Use appendSubjob() instead.
virtual void doStart()
Reimplement to do additional stuff before processing children, such as adding more subjobs.
void start() override
Starts processing this ContentJobBase asynchronously.
bool appendSubjob(ContentJobBase *job)
This is meant to be used instead of KCompositeJob::addSubjob(), making it possible to add subjobs fro...
KMime::Content * content() const
Get the resulting KMime::Content that the ContentJobBase has generated.
KMime::Content * extraContent() const
Get extra content that was previously added.
A dummy abstract class defining some errors pertaining to the Composer.
Definition jobbase.h:25
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
void setParent(QObject *parent)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:05:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.