KIO

mimetypefinderjob.h
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 MimeTypeFinderJob MimeTypeFinderjob.h <KIO/MimeTypeFinderJob>
23 *
24 * @brief MimeTypeFinderJob finds out the MIME type of a URL.
25 *
26 * @since 5.80
27 */
28class KIOCORE_EXPORT MimeTypeFinderJob : public KCompositeJob
29{
30 Q_OBJECT
31public:
32 /**
33 * @brief Creates an MimeTypeFinderJob for a URL.
34 * @param url the URL of the file/directory to examine
35 */
36 explicit MimeTypeFinderJob(const QUrl &url, QObject *parent = nullptr);
37
38 /**
39 * Destructor
40 *
41 * Note that by default jobs auto-delete themselves after emitting result.
42 */
44
45 /**
46 * Sets whether the job should follow URL redirections.
47 * This is enabled by default.
48 * @param b whether to follow redirections or not
49 */
50 void setFollowRedirections(bool b);
51
52 /**
53 * Sets the file name to use in the case of downloading the file to a tempfile,
54 * in order to give it to a non-URL-aware application.
55 * Some apps rely on the extension to determine the MIME type of the file.
56 * Usually the file name comes from the URL, but in the case of the
57 * HTTP Content-Disposition header, we need to override the file name.
58 * @param suggestedFileName the file name
59 */
60 void setSuggestedFileName(const QString &suggestedFileName);
61
62 /**
63 * Returns the suggested filename, either set by setSuggestedFileName
64 * or returned by the KIO::get job
65 */
66 QString suggestedFileName() const;
67
68 /**
69 * Enable/disable authentication prompt, if the URL requires one.
70 * They are enabled by default.
71 * This method allows to disable such prompts for jobs that should
72 * fail rather than bother the user, if authentication is needed.
73 * Example: for starting the associated program (i.e. when OpenUrlJob
74 * uses MimeTypeFinderJob), we want auth prompts.
75 * But for using a nice icon in a notification, we don't.
76 */
77 void setAuthenticationPromptEnabled(bool enable);
78
79 /**
80 * Returns where authentication prompts are enabled or disabled.
81 * @see setAuthenticationPromptEnabled
82 */
83 bool isAuthenticationPromptEnabled() const;
84
85 /**
86 * Starts the job.
87 * You must call this, after having called all the needed setters.
88 */
89 void start() override;
90
91 /**
92 * @return the MIME type. Only valid after the result() signal has been emitted.
93 */
94 QString mimeType() const;
95
96protected:
97 bool doKill() override;
98 void slotResult(KJob *job) override;
99
100private:
101 friend class MimeTypeFinderJobPrivate;
102 std::unique_ptr<MimeTypeFinderJobPrivate> d;
103};
104
105} // namespace KIO
106
107#endif
MimeTypeFinderJob finds out the MIME type of a URL.
~MimeTypeFinderJob() override
Destructor.
Q_SCRIPTABLE Q_NOREPLY void start()
A namespace for KIO globals.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:04:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.