File indexing completed on 2024-06-23 05:18:32

0001 /*
0002   SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
0003 
0004   Based on ideas by Stephen Kelly.
0005 
0006   SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #pragma once
0010 
0011 #include "jobbase.h"
0012 #include "messagecomposer_export.h"
0013 
0014 namespace KMime
0015 {
0016 class Content;
0017 }
0018 
0019 namespace MessageComposer
0020 {
0021 class ContentJobBasePrivate;
0022 /**
0023  * @brief The ContentJobBase class
0024  */
0025 class MESSAGECOMPOSER_EXPORT ContentJobBase : public JobBase
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     explicit ContentJobBase(QObject *parent = nullptr);
0031     ~ContentJobBase() override;
0032 
0033     /**
0034       Starts processing this ContentJobBase asynchronously.
0035       This processes all children in order first, then calls process().
0036       Emits finished() after all processing is done, and the
0037       content is reachable through content().
0038     */
0039     void start() override;
0040 
0041     /**
0042       Get the resulting KMime::Content that the ContentJobBase has generated.
0043       Jobs never delete their content.
0044     */
0045     [[nodiscard]] KMime::Content *content() const;
0046 
0047     /**
0048       This is meant to be used instead of KCompositeJob::addSubjob(), making
0049       it possible to add subjobs from the outside.
0050       Transfers ownership of the @p job to this object.
0051     */
0052     [[nodiscard]] bool appendSubjob(ContentJobBase *job);
0053 
0054     /**
0055       Set some extra content to be saved with the job, and available
0056         later, for example, in slot handling result of job.
0057       Job does not take care of deleting extra content.
0058       */
0059     void setExtraContent(KMime::Content *extra);
0060 
0061     /**
0062       Get extra content that was previously added.
0063      */
0064     [[nodiscard]] KMime::Content *extraContent() const;
0065 
0066 protected:
0067     ContentJobBase(ContentJobBasePrivate &dd, QObject *parent);
0068 
0069     /** Use appendSubjob() instead. */
0070     bool addSubjob(KJob *job) override;
0071 
0072 protected Q_SLOTS:
0073     /**
0074       Reimplement to do additional stuff before processing children, such as
0075       adding more subjobs.  Remember to call the base implementation.
0076     */
0077     virtual void doStart();
0078 
0079     /**
0080       This is called after all the children have been processed.
0081       (You must use their resulting contents, or delete them.)
0082       Reimplement in subclasses to process concrete content.  Call
0083       emitResult() when finished.
0084     */
0085     virtual void process() = 0;
0086 
0087     void slotResult(KJob *job) override;
0088 
0089 private:
0090     Q_DECLARE_PRIVATE(ContentJobBase)
0091 };
0092 } // namespace MessageComposer