File indexing completed on 2025-01-12 03:39:38
0001 /* 0002 SPDX-FileCopyrightText: 2000-2001, 2003, 2010 Dawit Alemayehu <adawit at kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #pragma once 0007 0008 #include "kiogui_export.h" 0009 #include "kurifilter.h" 0010 0011 #include <KPluginMetaData> 0012 0013 /** 0014 * @class KUriFilterPlugin kurifilter.h <KUriFilter> 0015 * 0016 * Base class for URI filter plugins. 0017 * 0018 * This class applies a single filter to a URI. All plugins designed to provide 0019 * URI filtering service should inherit from this abstract class and provide a 0020 * concrete implementation. 0021 * 0022 * All inheriting classes need to implement the pure virtual function 0023 * @ref filterUri. 0024 * 0025 * @short Abstract class for URI filter plugins. 0026 */ 0027 class KIOGUI_EXPORT KUriFilterPlugin : public QObject 0028 { 0029 Q_OBJECT 0030 0031 public: 0032 /** 0033 * Constructs a filter plugin with a given name 0034 * 0035 * @param parent the parent object, or @c nullptr for no parent 0036 * @param name the name of the plugin, mandatory 0037 */ 0038 explicit KUriFilterPlugin(QObject *parent, const KPluginMetaData &data); 0039 0040 ~KUriFilterPlugin() override; 0041 0042 public: 0043 /** 0044 * Filters a URI. 0045 * 0046 * @param data the URI data to be filtered. 0047 * @return A boolean indicating whether the URI has been changed. 0048 */ 0049 virtual bool filterUri(KUriFilterData &data) const = 0; 0050 0051 protected: 0052 /** 0053 * Sets the URL in @p data to @p uri. 0054 */ 0055 void setFilteredUri(KUriFilterData &data, const QUrl &uri) const; 0056 0057 /** 0058 * Sets the error message in @p data to @p errormsg. 0059 */ 0060 void setErrorMsg(KUriFilterData &data, const QString &errmsg) const; 0061 0062 /** 0063 * Sets the URI type in @p data to @p type. 0064 */ 0065 void setUriType(KUriFilterData &data, KUriFilterData::UriTypes type) const; 0066 0067 /** 0068 * Sets the arguments and options string in @p data to @p args if any were 0069 * found during filtering. 0070 */ 0071 void setArguments(KUriFilterData &data, const QString &args) const; 0072 0073 /** 0074 * Sets the name of the search provider, the search term and keyword/term 0075 * separator in @p data. 0076 */ 0077 void setSearchProvider(KUriFilterData &data, const QString &provider, const QString &term, const QChar &separator) const; 0078 0079 /** 0080 * Sets the information about the search @p providers in @p data. 0081 */ 0082 void setSearchProviders(KUriFilterData &data, const QList<KUriFilterSearchProvider *> &providers) const; 0083 0084 /** 0085 * Returns the icon name for the given @p url and URI @p type. 0086 */ 0087 QString iconNameFor(const QUrl &url, KUriFilterData::UriTypes type) const; 0088 0089 /** 0090 * Performs a DNS lookup for @p hostname and returns the result. 0091 * 0092 * This function uses the KIO DNS cache to speed up the 0093 * lookup. It also avoids doing a reverse lookup if the given 0094 * host name is already an ip address. 0095 * 0096 * \note All uri filter plugins that need to perform a hostname 0097 * lookup should use this function. 0098 * 0099 * @param hostname the hostname to lookup. 0100 * @param timeout the amount of time in msecs to wait for the lookup. 0101 * @return the result of the host name lookup. 0102 */ 0103 QHostInfo resolveName(const QString &hostname, unsigned long timeout) const; 0104 0105 private: 0106 class KUriFilterPluginPrivate *const d; 0107 };