Messagelib

contentjobbase.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Constantin Berzan <[email protected]>
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/kmime_content.h>
13 
14 using namespace MessageComposer;
15 
16 void 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 
27 void 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 
38 ContentJobBase::ContentJobBase(QObject *parent)
39  : JobBase(*new ContentJobBasePrivate(this), parent)
40 {
41  Q_D(ContentJobBase);
42  d->init(parent);
43 }
44 
45 ContentJobBase::ContentJobBase(ContentJobBasePrivate &dd, QObject *parent)
46  : JobBase(dd, parent)
47 {
48  Q_D(ContentJobBase);
49  d->init(parent);
50 }
51 
52 ContentJobBase::~ContentJobBase()
53 {
54 }
55 
56 void ContentJobBase::start()
57 {
58  doStart();
59 }
60 
61 KMime::Content *ContentJobBase::content() const
62 {
63  Q_D(const ContentJobBase);
64  // Q_ASSERT( !hasSubjobs() ); // Finished. // JobBase::hasSubjobs is not const :-/ TODO const_cast??
65  Q_ASSERT(d->resultContent); // process() should do something.
66  return d->resultContent;
67 }
68 
69 bool ContentJobBase::appendSubjob(ContentJobBase *job)
70 {
71  job->setParent(this);
72  return KCompositeJob::addSubjob(job);
73 }
74 
75 void ContentJobBase::setExtraContent(KMime::Content *extra)
76 {
77  Q_D(ContentJobBase);
78 
79  d->extraContent = extra;
80 }
81 
82 KMime::Content *ContentJobBase::extraContent() const
83 {
84  Q_D(const ContentJobBase);
85 
86  return d->extraContent;
87 }
88 
89 bool ContentJobBase::addSubjob(KJob *job)
90 {
91  Q_UNUSED(job)
92  qCCritical(MESSAGECOMPOSER_LOG) << "Use appendJob() instead.";
93  Q_ASSERT(false);
94  return false;
95 }
96 
97 void ContentJobBase::doStart()
98 {
99  Q_D(ContentJobBase);
100  Q_ASSERT(d->resultContent == nullptr && d->subjobContents.isEmpty()); // Not started.
101  Q_ASSERT(!error()); // Jobs emitting an error in doStart should not call ContentJobBase::doStart().
102  d->doNextSubjob();
103 }
104 
105 void ContentJobBase::slotResult(KJob *job)
106 {
107  Q_D(ContentJobBase);
108  KCompositeJob::slotResult(job); // Handles errors and removes subjob.
109  qCDebug(MESSAGECOMPOSER_LOG) << "A subjob finished." << subjobs().count() << "more to go.";
110  if (error()) {
111  return;
112  }
113 
114  Q_ASSERT(dynamic_cast<ContentJobBase *>(job));
115  auto cjob = static_cast<ContentJobBase *>(job);
116  d->subjobContents.append(cjob->content());
117  d->doNextSubjob();
118 }
virtual bool addSubjob(KJob *job)
virtual void slotResult(KJob *job)
void setParent(QObject *parent)
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
A dummy abstract class defining some errors pertaining to the Composer.
Definition: jobbase.h:24
The ContentJobBase class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Jul 29 2021 23:14:38 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.