Warning, file /frameworks/kio/src/core/jobuidelegatefactory.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2013 David Faure <faure+bluesystems@kde.org>
0004     SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef KIO_JOBUIDELEGATEFACTORY_H
0010 #define KIO_JOBUIDELEGATEFACTORY_H
0011 
0012 #include "job_base.h"
0013 #include "kiocore_export.h"
0014 #include <KJobUiDelegate>
0015 #include <QDateTime>
0016 #include <kio/global.h>
0017 
0018 #include <KCompositeJob>
0019 
0020 class QWidget;
0021 
0022 namespace KIO
0023 {
0024 /**
0025  * @class KIO::JobUiDelegateFactory jobuidelegatefactory.h <KIO/JobUiDelegateFactory>
0026  *
0027  * A factory for creating job ui delegates.
0028  * Every KIO job will get a delegate from this factory.
0029  * \since 5.0
0030  */
0031 class KIOCORE_EXPORT JobUiDelegateFactory
0032 {
0033 protected:
0034     /**
0035      * Constructor
0036      */
0037     JobUiDelegateFactory();
0038 
0039     /**
0040      * Destructor
0041      */
0042     virtual ~JobUiDelegateFactory();
0043 
0044 public:
0045     virtual KJobUiDelegate *createDelegate() const = 0;
0046 
0047 private:
0048     class Private;
0049     Private *const d;
0050 };
0051 
0052 class KIOCORE_EXPORT JobUiDelegateFactoryV2 : public JobUiDelegateFactory
0053 {
0054 protected:
0055     using JobUiDelegateFactory::JobUiDelegateFactory;
0056 
0057 public:
0058     KJobUiDelegate *createDelegate() const override = 0;
0059     virtual KJobUiDelegate *createDelegate(KJobUiDelegate::Flags flags, QWidget *window) const = 0;
0060 };
0061 
0062 /**
0063  * Convenience method: use default factory, if there's one, to create a delegate and return it.
0064  */
0065 KIOCORE_EXPORT KJobUiDelegate *createDefaultJobUiDelegate();
0066 
0067 /**
0068  * Convenience method: use default factory, if there's one, to create a delegate and return it.
0069  *
0070  * @since 5.98
0071  */
0072 KIOCORE_EXPORT KJobUiDelegate *createDefaultJobUiDelegate(KJobUiDelegate::Flags flags, QWidget *window);
0073 
0074 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 98)
0075 /**
0076  * Returns the default job UI delegate factory to be used by all KIO jobs (in which HideProgressInfo is not set)
0077  * Can return nullptr, if no kio GUI library is loaded.
0078  * @since 5.0
0079  * @deprecated Since 5.98, use defaultJobUiDelegateFactoryV2 instead.
0080  */
0081 KIOCORE_EXPORT
0082 KIOCORE_DEPRECATED_VERSION(5, 98, "use defaultJobUiDelegateFactoryV2")
0083 JobUiDelegateFactory *defaultJobUiDelegateFactory();
0084 #endif
0085 
0086 /**
0087  * Returns the default job UI delegate factory to be used by all KIO jobs (in which HideProgressInfo is not set)
0088  * Can return nullptr, if no kio GUI library is loaded.
0089  * @since 5.98
0090  */
0091 KIOCORE_EXPORT JobUiDelegateFactoryV2 *defaultJobUiDelegateFactoryV2();
0092 
0093 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 98)
0094 /**
0095  * Internal. Allows the KIO widgets library to register its widget-based job UI delegate factory
0096  * automatically.
0097  * @since 5.0
0098  * @deprecated Since 5.98, use setDefaultJobUiDelegateFactoryV2
0099  */
0100 KIOCORE_EXPORT
0101 KIOCORE_DEPRECATED_VERSION(5, 98, "use setDefaultJobUiDelegateFactoryV2")
0102 void setDefaultJobUiDelegateFactory(JobUiDelegateFactory *factory);
0103 #endif
0104 
0105 /**
0106  * Internal. Allows the KIO widgets library to register its widget-based job UI delegate factory
0107  * automatically.
0108  * @since 5.98
0109  */
0110 KIOCORE_EXPORT void setDefaultJobUiDelegateFactoryV2(JobUiDelegateFactoryV2 *factory);
0111 
0112 /**
0113  * Returns the child of the job's uiDelegate() that implements the given extension,
0114  * or nullptr if none was found (or if the job had no uiDelegate).
0115  * @since 5.78
0116  */
0117 template<typename T>
0118 inline T delegateExtension(KJob *job)
0119 {
0120     KJobUiDelegate *ui = job->uiDelegate();
0121 
0122     // If setParentJob() was used, try the uiDelegate of parentJob first
0123     if (!ui) {
0124         if (KIO::Job *kiojob = qobject_cast<KIO::Job *>(job)) {
0125             if (KJob *parentJob = kiojob->parentJob()) {
0126                 ui = parentJob->uiDelegate();
0127             }
0128         }
0129     }
0130 
0131     // Still nothing? if compositeJob->addSubjob(job) was used, try the ui delegate
0132     // of compositeJob
0133     while (!ui) {
0134         job = qobject_cast<KCompositeJob *>(job->parent());
0135         if (job) {
0136             ui = job->uiDelegate();
0137         } else {
0138             break;
0139         }
0140     }
0141 
0142     return ui ? ui->findChild<T>(QString(), Qt::FindDirectChildrenOnly) : nullptr;
0143 }
0144 
0145 } // namespace KIO
0146 
0147 #endif