Messagelib

contentjobbase.h
1 /*
2  SPDX-FileCopyrightText: 2009 Constantin Berzan <[email protected]>
3 
4  Based on ideas by Stephen Kelly.
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #pragma once
10 
11 #include "jobbase.h"
12 #include "messagecomposer_export.h"
13 
14 namespace KMime
15 {
16 class Content;
17 }
18 
19 namespace MessageComposer
20 {
21 class ContentJobBasePrivate;
22 /**
23  * @brief The ContentJobBase class
24  */
25 class MESSAGECOMPOSER_EXPORT ContentJobBase : public JobBase
26 {
27  Q_OBJECT
28 
29 public:
30  explicit ContentJobBase(QObject *parent = nullptr);
31  ~ContentJobBase() override;
32 
33  /**
34  Starts processing this ContentJobBase asynchronously.
35  This processes all children in order first, then calls process().
36  Emits finished() after all processing is done, and the
37  content is reachable through content().
38  */
39  void start() override;
40 
41  /**
42  Get the resulting KMime::Content that the ContentJobBase has generated.
43  Jobs never delete their content.
44  */
45  Q_REQUIRED_RESULT KMime::Content *content() const;
46 
47  /**
48  This is meant to be used instead of KCompositeJob::addSubjob(), making
49  it possible to add subjobs from the outside.
50  Transfers ownership of the @p job to this object.
51  */
52  Q_REQUIRED_RESULT bool appendSubjob(ContentJobBase *job);
53 
54  /**
55  Set some extra content to be saved with the job, and available
56  later, for example, in slot handling result of job.
57  Job does not take care of deleting extra content.
58  */
59  void setExtraContent(KMime::Content *extra);
60 
61  /**
62  Get extra content that was previously added.
63  */
64  Q_REQUIRED_RESULT KMime::Content *extraContent() const;
65 
66 protected:
67  ContentJobBase(ContentJobBasePrivate &dd, QObject *parent);
68 
69  /** Use appendSubjob() instead. */
70  bool addSubjob(KJob *job) override;
71 
72 protected Q_SLOTS:
73  /**
74  Reimplement to do additional stuff before processing children, such as
75  adding more subjobs. Remember to call the base implementation.
76  */
77  virtual void doStart();
78 
79  /**
80  This is called after all the children have been processed.
81  (You must use their resulting contents, or delete them.)
82  Reimplement in subclasses to process concrete content. Call
83  emitResult() when finished.
84  */
85  virtual void process() = 0;
86 
87  void slotResult(KJob *job) override;
88 
89 private:
90  Q_DECLARE_PRIVATE(ContentJobBase)
91 };
92 } // namespace MessageComposer
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
Q_SCRIPTABLE Q_NOREPLY void start()
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-2023 The KDE developers.
Generated on Sun Mar 26 2023 04:08:10 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.