File indexing completed on 2024-09-29 06:32:16
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 1999 Torben Weis <weis@kde.org> 0004 SPDX-FileCopyrightText: 2000-2001 Waldo Bastian <bastian@kde.org> 0005 SPDX-FileCopyrightText: 2012 David Faure <faure@kde.org> 0006 0007 SPDX-License-Identifier: LGPL-2.0-only 0008 */ 0009 0010 #ifndef KPROTOCOLINFO_H 0011 #define KPROTOCOLINFO_H 0012 0013 #include "kiocore_export.h" 0014 #include <QMetaType> 0015 #include <QStringList> 0016 0017 /** 0018 * \class KProtocolInfo kprotocolinfo.h <KProtocolInfo> 0019 * 0020 * Information about I/O (Internet, etc.) protocols supported by KDE. 0021 0022 * KProtocolInfo is useful if you want to know which protocols 0023 * KDE supports. In addition you can find out lots of information 0024 * about a certain protocol. All of the functionality is provided by the static 0025 * methods. 0026 * The implementation scans the *.protocol files of all installed KIO workers to get 0027 * this information and stores the result into an internal cache. 0028 * 0029 * *.protocol files are installed in the "services" resource. 0030 * 0031 * The KProtocolInfo methods are reentrant (i.e. can be called from multiple threads simultaneously). 0032 */ 0033 class KIOCORE_EXPORT KProtocolInfo 0034 { 0035 public: 0036 // 0037 // Static functions: 0038 // 0039 0040 /** 0041 * Returns list of all known protocols. 0042 * @return a list of all known protocols 0043 */ 0044 static QStringList protocols(); 0045 0046 /** 0047 * Returns whether a protocol is installed that is able to handle @p url. 0048 * 0049 * @param url the url to check 0050 * @return true if the protocol is known 0051 * @see name() 0052 */ 0053 static bool isKnownProtocol(const QUrl &url); 0054 0055 /** 0056 * Same as above except you can supply just the protocol instead of 0057 * the whole URL. 0058 */ 0059 static bool isKnownProtocol(const QString &protocol, bool updateCacheIfNotfound = true); 0060 0061 /** 0062 * Returns the library / executable to open for the protocol @p protocol 0063 * Example : "kio_ftp", meaning either the executable "kio_ftp" or 0064 * the library "kio_ftp.la" (recommended), whichever is available. 0065 * 0066 * This corresponds to the "exec=" field in the protocol description file. 0067 * @param protocol the protocol to check 0068 * @return the executable of library to open, or QString() for 0069 * unsupported protocols 0070 * @see KUrl::protocol() 0071 */ 0072 static QString exec(const QString &protocol); 0073 0074 /** 0075 * Describes the type of a protocol. 0076 * For instance ftp:// appears as a filesystem with folders and files, 0077 * while bzip2:// appears as a single file (a stream of data), 0078 * and telnet:// doesn't output anything. 0079 * @see outputType 0080 */ 0081 enum Type { 0082 T_STREAM, ///< stream of data (e.g.\ single file) 0083 T_FILESYSTEM, ///< structured directory 0084 T_NONE, ///< no information about the type available 0085 T_ERROR, ///< used to signal an error 0086 }; 0087 0088 /** 0089 * Definition of an extra field in the UDS entries, returned by a listDir operation. 0090 * 0091 * The name is the name of the column, translated. 0092 * 0093 * The type name comes from QMetaType::name() 0094 * Currently supported types: "QString", "QDateTime" (ISO-8601 format) 0095 */ 0096 struct ExtraField { 0097 enum Type { String = QMetaType::QString, DateTime = QMetaType::QDateTime, Invalid = QMetaType::UnknownType }; 0098 0099 ExtraField() 0100 : type(Invalid) 0101 { 0102 } 0103 ExtraField(const QString &_name, Type _type) 0104 : name(_name) 0105 , type(_type) 0106 { 0107 } 0108 QString name; 0109 Type type; 0110 }; 0111 typedef QList<ExtraField> ExtraFieldList; 0112 /** 0113 * Definition of extra fields in the UDS entries, returned by a listDir operation. 0114 * 0115 * This corresponds to the "ExtraNames=" and "ExtraTypes=" fields in the protocol description file. 0116 * Those two lists should be separated with ',' in the protocol description file. 0117 * See ExtraField for details about names and types 0118 */ 0119 static ExtraFieldList extraFields(const QUrl &url); 0120 0121 /** 0122 * Returns whether the protocol can act as a helper protocol. 0123 * A helper protocol invokes an external application and does not return 0124 * a file or stream. 0125 * 0126 * This corresponds to the "helper=" field in the protocol description file. 0127 * Valid values for this field are "true" or "false" (default). 0128 * 0129 * @param url the url to check 0130 * @return true if the protocol is a helper protocol (e.g. vnc), false 0131 * if not (e.g. http) 0132 */ 0133 static bool isHelperProtocol(const QUrl &url); 0134 0135 /** 0136 * Same as above except you can supply just the protocol instead of 0137 * the whole URL. 0138 */ 0139 static bool isHelperProtocol(const QString &protocol); 0140 0141 /** 0142 * Returns whether the protocol can act as a filter protocol. 0143 * 0144 * A filter protocol can operate on data that is passed to it 0145 * but does not retrieve/store data itself, like gzip. 0146 * A filter protocol is the opposite of a source protocol. 0147 * 0148 * The "source=" field in the protocol description file determines 0149 * whether a protocol is a source protocol or a filter protocol. 0150 * Valid values for this field are "true" (default) for source protocol or 0151 * "false" for filter protocol. 0152 * 0153 * @param url the url to check 0154 * @return true if the protocol is a filter (e.g. gzip), false if the 0155 * protocol is a helper or source 0156 */ 0157 static bool isFilterProtocol(const QUrl &url); 0158 0159 /** 0160 * Same as above except you can supply just the protocol instead of 0161 * the whole URL. 0162 */ 0163 static bool isFilterProtocol(const QString &protocol); 0164 0165 /** 0166 * Returns the name of the icon, associated with the specified protocol. 0167 * 0168 * This corresponds to the "Icon=" field in the protocol description file. 0169 * 0170 * @param protocol the protocol to check 0171 * @return the icon of the protocol, or an empty string if unknown 0172 */ 0173 static QString icon(const QString &protocol); 0174 0175 /** 0176 * Returns the name of the config file associated with the 0177 * specified protocol. This is useful if two similar protocols 0178 * need to share a single config file, e.g. http and https. 0179 * 0180 * This corresponds to the "config=" field in the protocol description file. 0181 * The default is the protocol name, see name() 0182 * 0183 * @param protocol the protocol to check 0184 * @return the config file, or an empty string if unknown 0185 */ 0186 static QString config(const QString &protocol); 0187 0188 /** 0189 * Returns the soft limit on the number of KIO workers for this protocol. 0190 * This limits the number of workers used for a single operation, note 0191 * that multiple operations may result in a number of instances that 0192 * exceeds this soft limit. 0193 * 0194 * This corresponds to the "maxInstances=" field in the protocol's worker metadata. 0195 * The default is 1. 0196 * 0197 * @param protocol the protocol to check 0198 * @return the maximum number of workers, or 1 if unknown 0199 * 0200 * @since 5.101 0201 */ 0202 static int maxWorkers(const QString &protocol); 0203 0204 /** 0205 * Returns the limit on the number of KIO workers for this protocol per host. 0206 * 0207 * This corresponds to the "maxInstancesPerHost=" field in the protocol's worker metadata. 0208 * The default is 0 which means there is no per host limit. 0209 * 0210 * @param protocol the protocol to check 0211 * @return the maximum number of workers, or 1 if unknown 0212 * 0213 * @since 5.101 0214 */ 0215 static int maxWorkersPerHost(const QString &protocol); 0216 0217 /** 0218 * Returns whether MIME types can be determined based on extension for this 0219 * protocol. For some protocols, e.g. http, the filename extension in the URL 0220 * can not be trusted to truly reflect the file type. 0221 * 0222 * This corresponds to the "determineMimetypeFromExtension=" field in the protocol description file. 0223 * Valid values for this field are "true" (default) or "false". 0224 * 0225 * @param protocol the protocol to check 0226 * @return true if the MIME types can be determined by extension 0227 */ 0228 static bool determineMimetypeFromExtension(const QString &protocol); 0229 0230 /** 0231 * Returns the default MIME type for the specified protocol, if one exists. 0232 * 0233 * This corresponds to the "defaultMimetype=" field in the protocol description file. 0234 * 0235 * @param protocol the protocol to check 0236 * @return the default MIME type of the protocol, or an empty string if none set or protocol unknown 0237 * @since 5.60 0238 */ 0239 static QString defaultMimetype(const QString &protocol); 0240 0241 /** 0242 * Returns the documentation path for the specified protocol. 0243 * 0244 * This corresponds to the "X-DocPath=" or "DocPath=" field in the protocol description file. 0245 * 0246 * @param protocol the protocol to check 0247 * @return the docpath of the protocol, or an empty string if unknown 0248 */ 0249 static QString docPath(const QString &protocol); 0250 0251 /** 0252 * Returns the protocol class for the specified protocol. 0253 * 0254 * This corresponds to the "Class=" field in the protocol description file. 0255 * 0256 * The following classes are defined: 0257 * @li ":internet" for common internet protocols 0258 * @li ":local" for protocols that access local resources 0259 * 0260 * Protocol classes always start with a ':' so that they can not be confused with 0261 * the protocols themselves. 0262 * 0263 * @param protocol the protocol to check 0264 * @return the class of the protocol, or an empty string if unknown 0265 */ 0266 static QString protocolClass(const QString &protocol); 0267 0268 /** 0269 * Returns whether file previews should be shown for the specified protocol. 0270 * 0271 * This corresponds to the "ShowPreviews=" field in the protocol description file. 0272 * 0273 * By default previews are shown if protocolClass is :local. 0274 * 0275 * @param protocol the protocol to check 0276 * @return true if previews should be shown by default, false otherwise 0277 */ 0278 static bool showFilePreview(const QString &protocol); 0279 0280 /** 0281 * Returns the list of capabilities provided by the KIO worker implementing 0282 * this protocol. 0283 * 0284 * This corresponds to the "Capabilities=" field in the protocol description file. 0285 * 0286 * The capability names are not defined globally, they are up to each 0287 * worker implementation. For example when adding support for a new 0288 * special command for mounting, one would add the string "Mount" to the 0289 * capabilities list, and applications could check for that string 0290 * before sending a special() command that would otherwise do nothing 0291 * on older KIO worker implementations. 0292 * 0293 * @param protocol the protocol to check 0294 * @return the list of capabilities. 0295 */ 0296 static QStringList capabilities(const QString &protocol); 0297 0298 /** 0299 * Returns the list of archive MIME types handled by the KIO worker implementing 0300 * this protocol. 0301 * 0302 * This corresponds to the "archiveMimetype=" field in the protocol description file. 0303 * 0304 * @param protocol the protocol to check 0305 * @return the list of archive MIME types (e.g. application/x-zip) handled. 0306 * @since 5.23 0307 */ 0308 static QStringList archiveMimetypes(const QString &protocol); 0309 0310 /** 0311 * Returns the name of the protocol through which the request 0312 * will be routed if proxy support is enabled. 0313 * 0314 * A good example of this is the ftp protocol for which proxy 0315 * support is commonly handled by the http protocol. 0316 * 0317 * This corresponds to the "ProxiedBy=" in the protocol description file. 0318 */ 0319 static QString proxiedBy(const QString &protocol); 0320 0321 typedef enum { Name, FromUrl, DisplayName } FileNameUsedForCopying; 0322 0323 private: 0324 Q_DISABLE_COPY(KProtocolInfo) 0325 }; 0326 0327 #endif