1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2020 David Faure <faure@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#ifndef KIO_MIMETYPEFINDERJOB_H
9#define KIO_MIMETYPEFINDERJOB_H
10
11#include "kiocore_export.h"
12#include <KCompositeJob>
13#include <memory>
14
15class QUrl;
16
17namespace KIO
18{
19class MimeTypeFinderJobPrivate;
20
21/*!
22 * \class KIO::MimeTypeFinderJob
23 * \inheaderfile KIO/MimeTypeFinderJob
24 * \inmodule KIOCore
25 *
26 * \brief MimeTypeFinderJob finds out the MIME type of a URL.
27 *
28 * \since 5.80
29 */
30class KIOCORE_EXPORT MimeTypeFinderJob : public KCompositeJob
31{
32 Q_OBJECT
33public:
34 /*!
35 * Creates an MimeTypeFinderJob for a URL.
36 *
37 * \a url the URL of the file/directory to examine
38 */
39 explicit MimeTypeFinderJob(const QUrl &url, QObject *parent = nullptr);
40
41 /*!
42 * Destructor
43 *
44 * Note that by default jobs auto-delete themselves after emitting result.
45 */
46 ~MimeTypeFinderJob() override;
47
48 /*!
49 * Sets whether the job should follow URL redirections.
50 * This is enabled by default.
51 *
52 * \a b whether to follow redirections or not
53 */
54 void setFollowRedirections(bool b);
55
56 /*!
57 * Sets the file name to use in the case of downloading the file to a tempfile,
58 * in order to give it to a non-URL-aware application.
59 * Some apps rely on the extension to determine the MIME type of the file.
60 * Usually the file name comes from the URL, but in the case of the
61 * HTTP Content-Disposition header, we need to override the file name.
62 *
63 * \a suggestedFileName the file name
64 */
65 void setSuggestedFileName(const QString &suggestedFileName);
66
67 /*!
68 * Returns the suggested filename, either set by setSuggestedFileName
69 * or returned by the KIO::get job
70 */
71 QString suggestedFileName() const;
72
73 /*!
74 * Enable/disable authentication prompt, if the URL requires one.
75 * They are enabled by default.
76 * This method allows to disable such prompts for jobs that should
77 * fail rather than bother the user, if authentication is needed.
78 * Example: for starting the associated program (i.e. when OpenUrlJob
79 * uses MimeTypeFinderJob), we want auth prompts.
80 * But for using a nice icon in a notification, we don't.
81 */
82 void setAuthenticationPromptEnabled(bool enable);
83
84 /*!
85 * Returns where authentication prompts are enabled or disabled.
86 * \sa setAuthenticationPromptEnabled()
87 */
88 bool isAuthenticationPromptEnabled() const;
89
90 /*!
91 * Starts the job.
92 * You must call this, after having called all the needed setters.
93 * \reimp
94 */
95 void start() override;
96
97 /*!
98 * Returns the MIME type.
99 *
100 * Only valid after the result() signal has been emitted.
101 */
102 QString mimeType() const;
103
104protected:
105 bool doKill() override;
106 void slotResult(KJob *job) override;
107
108private:
109 friend class MimeTypeFinderJobPrivate;
110 std::unique_ptr<MimeTypeFinderJobPrivate> d;
111};
112
113} // namespace KIO
114
115#endif
116

source code of kio/src/core/mimetypefinderjob.h