File indexing completed on 2024-05-05 16:13:18

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 <QStringList>
0015 #include <QVariant>
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);
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 QVariant::typeName()
0094      * Currently supported types: "QString", "QDateTime" (ISO-8601 format)
0095      */
0096     struct ExtraField {
0097         enum Type { String = QVariant::String, DateTime = QVariant::DateTime, Invalid = QVariant::Invalid };
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 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 101)
0189     /**
0190      * Returns the soft limit on the number of slaves for this protocol.
0191      * This limits the number of slaves used for a single operation, note
0192      * that multiple operations may result in a number of instances that
0193      * exceeds this soft limit.
0194      *
0195      * This corresponds to the "maxInstances=" field in the protocol description file.
0196      * The default is 1.
0197      *
0198      * @param protocol the protocol to check
0199      * @return the maximum number of slaves, or 1 if unknown
0200      *
0201      * @deprecated Since 5.101, use maxWorkers(const QString &)
0202      */
0203     static KIOCORE_DEPRECATED_VERSION(5, 101, "Use maxWorkers(const QString&)") int maxSlaves(const QString &protocol);
0204 #endif
0205 
0206 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 101)
0207     /**
0208      * Returns the limit on the number of slaves for this protocol per host.
0209      *
0210      * This corresponds to the "maxInstancesPerHost=" field in the protocol description file.
0211      * The default is 0 which means there is no per host limit.
0212      *
0213      * @param protocol the protocol to check
0214      * @return the maximum number of slaves, or 1 if unknown
0215      *
0216      * @since 4.4
0217      * @deprecated Since 5.101, use maxWorkersPerHost(const QString &)
0218      */
0219     static KIOCORE_DEPRECATED_VERSION(5, 101, "Use maxWorkersPerHost(const QString&)") int maxSlavesPerHost(const QString &protocol);
0220 #endif
0221 
0222     /**
0223      * Returns the soft limit on the number of KIO workers for this protocol.
0224      * This limits the number of workers used for a single operation, note
0225      * that multiple operations may result in a number of instances that
0226      * exceeds this soft limit.
0227      *
0228      * This corresponds to the "maxInstances=" field in the protocol's worker metadata.
0229      * The default is 1.
0230      *
0231      * @param protocol the protocol to check
0232      * @return the maximum number of workers, or 1 if unknown
0233      *
0234      * @since 5.101
0235      */
0236     static int maxWorkers(const QString &protocol);
0237 
0238     /**
0239      * Returns the limit on the number of KIO workers for this protocol per host.
0240      *
0241      * This corresponds to the "maxInstancesPerHost=" field in the protocol's worker metadata.
0242      * The default is 0 which means there is no per host limit.
0243      *
0244      * @param protocol the protocol to check
0245      * @return the maximum number of workers, or 1 if unknown
0246      *
0247      * @since 5.101
0248      */
0249     static int maxWorkersPerHost(const QString &protocol);
0250 
0251     /**
0252      * Returns whether MIME types can be determined based on extension for this
0253      * protocol. For some protocols, e.g. http, the filename extension in the URL
0254      * can not be trusted to truly reflect the file type.
0255      *
0256      * This corresponds to the "determineMimetypeFromExtension=" field in the protocol description file.
0257      * Valid values for this field are "true" (default) or "false".
0258      *
0259      * @param protocol the protocol to check
0260      * @return true if the MIME types can be determined by extension
0261      */
0262     static bool determineMimetypeFromExtension(const QString &protocol);
0263 
0264     /**
0265      * Returns the default MIME type for the specified protocol, if one exists.
0266      *
0267      * This corresponds to the "defaultMimetype=" field in the protocol description file.
0268      *
0269      * @param protocol the protocol to check
0270      * @return the default MIME type of the protocol, or an empty string if none set or protocol unknown
0271      * @since 5.60
0272      */
0273     static QString defaultMimetype(const QString &protocol);
0274 
0275     /**
0276      * Returns the documentation path for the specified protocol.
0277      *
0278      * This corresponds to the "X-DocPath=" or "DocPath=" field in the protocol description file.
0279      *
0280      * @param protocol the protocol to check
0281      * @return the docpath of the protocol, or an empty string if unknown
0282      */
0283     static QString docPath(const QString &protocol);
0284 
0285     /**
0286      * Returns the protocol class for the specified protocol.
0287      *
0288      * This corresponds to the "Class=" field in the protocol description file.
0289      *
0290      * The following classes are defined:
0291      * @li ":internet" for common internet protocols
0292      * @li ":local" for protocols that access local resources
0293      *
0294      * Protocol classes always start with a ':' so that they can not be confused with
0295      * the protocols themselves.
0296      *
0297      * @param protocol the protocol to check
0298      * @return the class of the protocol, or an empty string if unknown
0299      */
0300     static QString protocolClass(const QString &protocol);
0301 
0302     /**
0303      * Returns whether file previews should be shown for the specified protocol.
0304      *
0305      * This corresponds to the "ShowPreviews=" field in the protocol description file.
0306      *
0307      * By default previews are shown if protocolClass is :local.
0308      *
0309      * @param protocol the protocol to check
0310      * @return true if previews should be shown by default, false otherwise
0311      */
0312     static bool showFilePreview(const QString &protocol);
0313 
0314     /**
0315      * Returns the list of capabilities provided by the KIO worker implementing
0316      * this protocol.
0317      *
0318      * This corresponds to the "Capabilities=" field in the protocol description file.
0319      *
0320      * The capability names are not defined globally, they are up to each
0321      * worker implementation. For example when adding support for a new
0322      * special command for mounting, one would add the string "Mount" to the
0323      * capabilities list, and applications could check for that string
0324      * before sending a special() command that would otherwise do nothing
0325      * on older KIO worker implementations.
0326      *
0327      * @param protocol the protocol to check
0328      * @return the list of capabilities.
0329      */
0330     static QStringList capabilities(const QString &protocol);
0331 
0332     /**
0333      * Returns the list of archive MIME types handled by the KIO worker implementing
0334      * this protocol.
0335      *
0336      * This corresponds to the "archiveMimetype=" field in the protocol description file.
0337      *
0338      * @param protocol the protocol to check
0339      * @return the list of archive MIME types (e.g. application/x-zip) handled.
0340      * @since 5.23
0341      */
0342     static QStringList archiveMimetypes(const QString &protocol);
0343 
0344 #if KIOCORE_ENABLE_DEPRECATED_SINCE(5, 101)
0345     /**
0346      * Returns the list of notification types the kioslave implementing this
0347      * protocol will produce on its own, making it unnecessary for job
0348      * implementations to do so. An example would be returning "Rename"
0349      * if the kioslave's rename() method takes care of calling
0350      * KDirNotify::emitFileRenameWithLocalPath on its own.
0351      *
0352      * This corresponds to "slaveHandlesNotify=" in the protocol description file.
0353      *
0354      * @since 5.20
0355      * @deprecated Since 5.101, no known users
0356      */
0357     static KIOCORE_DEPRECATED_VERSION(5, 101, "No known users") QStringList slaveHandlesNotify(const QString &protocol);
0358 #endif
0359 
0360     /**
0361      * Returns the name of the protocol through which the request
0362      * will be routed if proxy support is enabled.
0363      *
0364      * A good example of this is the ftp protocol for which proxy
0365      * support is commonly handled by the http protocol.
0366      *
0367      * This corresponds to the "ProxiedBy=" in the protocol description file.
0368      */
0369     static QString proxiedBy(const QString &protocol);
0370 
0371     typedef enum { Name, FromUrl, DisplayName } FileNameUsedForCopying;
0372 
0373 private:
0374     Q_DISABLE_COPY(KProtocolInfo)
0375 };
0376 
0377 #endif