File indexing completed on 2024-09-15 03:38:33
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2020 David Faure <faure@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #ifndef KIO_MIMETYPEFINDERJOB_H 0009 #define KIO_MIMETYPEFINDERJOB_H 0010 0011 #include "kiocore_export.h" 0012 #include <KCompositeJob> 0013 #include <memory> 0014 0015 class QUrl; 0016 0017 namespace KIO 0018 { 0019 class MimeTypeFinderJobPrivate; 0020 0021 /** 0022 * @class MimeTypeFinderJob MimeTypeFinderjob.h <KIO/MimeTypeFinderJob> 0023 * 0024 * @brief MimeTypeFinderJob finds out the MIME type of a URL. 0025 * 0026 * @since 5.80 0027 */ 0028 class KIOCORE_EXPORT MimeTypeFinderJob : public KCompositeJob 0029 { 0030 Q_OBJECT 0031 public: 0032 /** 0033 * @brief Creates an MimeTypeFinderJob for a URL. 0034 * @param url the URL of the file/directory to examine 0035 */ 0036 explicit MimeTypeFinderJob(const QUrl &url, QObject *parent = nullptr); 0037 0038 /** 0039 * Destructor 0040 * 0041 * Note that by default jobs auto-delete themselves after emitting result. 0042 */ 0043 ~MimeTypeFinderJob() override; 0044 0045 /** 0046 * Sets whether the job should follow URL redirections. 0047 * This is enabled by default. 0048 * @param b whether to follow redirections or not 0049 */ 0050 void setFollowRedirections(bool b); 0051 0052 /** 0053 * Sets the file name to use in the case of downloading the file to a tempfile, 0054 * in order to give it to a non-URL-aware application. 0055 * Some apps rely on the extension to determine the MIME type of the file. 0056 * Usually the file name comes from the URL, but in the case of the 0057 * HTTP Content-Disposition header, we need to override the file name. 0058 * @param suggestedFileName the file name 0059 */ 0060 void setSuggestedFileName(const QString &suggestedFileName); 0061 0062 /** 0063 * Returns the suggested filename, either set by setSuggestedFileName 0064 * or returned by the KIO::get job 0065 */ 0066 QString suggestedFileName() const; 0067 0068 /** 0069 * Enable/disable authentication prompt, if the URL requires one. 0070 * They are enabled by default. 0071 * This method allows to disable such prompts for jobs that should 0072 * fail rather than bother the user, if authentication is needed. 0073 * Example: for starting the associated program (i.e. when OpenUrlJob 0074 * uses MimeTypeFinderJob), we want auth prompts. 0075 * But for using a nice icon in a notification, we don't. 0076 */ 0077 void setAuthenticationPromptEnabled(bool enable); 0078 0079 /** 0080 * Returns where authentication prompts are enabled or disabled. 0081 * @see setAuthenticationPromptEnabled 0082 */ 0083 bool isAuthenticationPromptEnabled() const; 0084 0085 /** 0086 * Starts the job. 0087 * You must call this, after having called all the needed setters. 0088 */ 0089 void start() override; 0090 0091 /** 0092 * @return the MIME type. Only valid after the result() signal has been emitted. 0093 */ 0094 QString mimeType() const; 0095 0096 protected: 0097 bool doKill() override; 0098 void slotResult(KJob *job) override; 0099 0100 private: 0101 friend class MimeTypeFinderJobPrivate; 0102 std::unique_ptr<MimeTypeFinderJobPrivate> d; 0103 }; 0104 0105 } // namespace KIO 0106 0107 #endif