KIO

jobuidelegatefactory.h
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2013 David Faure <faure+bluesystems@kde.org>
4 SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef KIO_JOBUIDELEGATEFACTORY_H
10#define KIO_JOBUIDELEGATEFACTORY_H
11
12#include "job_base.h"
13#include "kiocore_export.h"
14#include <KJobUiDelegate>
15#include <QDateTime>
16#include <kio/global.h>
17
18#include <KCompositeJob>
19
20class QWidget;
21
22namespace KIO
23{
24/**
25 * @class KIO::JobUiDelegateFactory jobuidelegatefactory.h <KIO/JobUiDelegateFactory>
26 *
27 * A factory for creating job ui delegates.
28 * Every KIO job will get a delegate from this factory.
29 * \since 5.0
30 */
31class KIOCORE_EXPORT JobUiDelegateFactory
32{
33protected:
34 /**
35 * Constructor
36 */
38
39 /**
40 * Destructor
41 */
43
44public:
45 virtual KJobUiDelegate *createDelegate() const = 0;
46
47 /**
48 * @since 6.0
49 */
50 virtual KJobUiDelegate *createDelegate(KJobUiDelegate::Flags flags, QWidget *window) const = 0;
51
52private:
53 class Private;
54 Private *const d;
55};
56
57/**
58 * Convenience method: use default factory, if there's one, to create a delegate and return it.
59 */
61
62/**
63 * Convenience method: use default factory, if there's one, to create a delegate and return it.
64 *
65 * @since 5.98
66 */
68
69/**
70 * Returns the default job UI delegate factory to be used by all KIO jobs (in which HideProgressInfo is not set)
71 * Can return nullptr, if no kio GUI library is loaded.
72 * @since 6.0
73 */
75
76/**
77 * Internal. Allows the KIO widgets library to register its widget-based job UI delegate factory
78 * automatically.
79 * @since 6.0
80 */
81KIOCORE_EXPORT void setDefaultJobUiDelegateFactory(JobUiDelegateFactory *factory);
82
83/**
84 * Returns the child of the job's uiDelegate() that implements the given extension,
85 * or nullptr if none was found (or if the job had no uiDelegate).
86 * @since 5.78
87 */
88template<typename T>
89inline T delegateExtension(KJob *job)
90{
91 KJobUiDelegate *ui = job->uiDelegate();
92
93 // If setParentJob() was used, try the uiDelegate of parentJob first
94 if (!ui) {
95 if (KIO::Job *kiojob = qobject_cast<KIO::Job *>(job)) {
96 if (KJob *parentJob = kiojob->parentJob()) {
97 ui = parentJob->uiDelegate();
98 }
99 }
100 }
101
102 // Still nothing? if compositeJob->addSubjob(job) was used, try the ui delegate
103 // of compositeJob
104 while (!ui) {
105 job = qobject_cast<KCompositeJob *>(job->parent());
106 if (job) {
107 ui = job->uiDelegate();
108 } else {
109 break;
110 }
111 }
112
113 return ui ? ui->findChild<T>(QString(), Qt::FindDirectChildrenOnly) : nullptr;
114}
115
116} // namespace KIO
117
118#endif
A factory for creating job ui delegates.
virtual KJobUiDelegate * createDelegate(KJobUiDelegate::Flags flags, QWidget *window) const =0
virtual ~JobUiDelegateFactory()
Destructor.
The base class for all jobs.
KJobUiDelegate * uiDelegate() const
A namespace for KIO globals.
KIOCORE_EXPORT JobUiDelegateFactory * defaultJobUiDelegateFactory()
Returns the default job UI delegate factory to be used by all KIO jobs (in which HideProgressInfo is ...
T delegateExtension(KJob *job)
Returns the child of the job's uiDelegate() that implements the given extension, or nullptr if none w...
KIOCORE_EXPORT KJobUiDelegate * createDefaultJobUiDelegate()
Convenience method: use default factory, if there's one, to create a delegate and return it.
KIOCORE_EXPORT void setDefaultJobUiDelegateFactory(JobUiDelegateFactory *factory)
Internal.
T findChild(const QString &name, Qt::FindChildOptions options) const const
QObject * parent() const const
FindDirectChildrenOnly
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.