| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2000-2001, 2003, 2010 Dawit Alemayehu <adawit at kde.org> |
| 3 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 4 | */ |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include "kiogui_export.h" |
| 9 | #include "kurifilter.h" |
| 10 | |
| 11 | #include <KPluginMetaData> |
| 12 | |
| 13 | /*! |
| 14 | * \class KUriFilterPlugin kurifilter.h <KUriFilter> |
| 15 | * |
| 16 | * \brief Base class for URI filter plugins. |
| 17 | * |
| 18 | * This class applies a single filter to a URI. All plugins designed to provide |
| 19 | * URI filtering service should inherit from this abstract class and provide a |
| 20 | * concrete implementation. |
| 21 | * |
| 22 | * All inheriting classes need to implement the pure virtual function |
| 23 | * filterUri. |
| 24 | * |
| 25 | * \internal |
| 26 | */ |
| 27 | class KIOGUI_EXPORT KUriFilterPlugin : public QObject |
| 28 | { |
| 29 | Q_OBJECT |
| 30 | |
| 31 | public: |
| 32 | /*! |
| 33 | * Constructs a filter plugin with a given name |
| 34 | * |
| 35 | * \a parent the parent object, or \c nullptr for no parent |
| 36 | * |
| 37 | * \a name the name of the plugin, mandatory |
| 38 | */ |
| 39 | explicit KUriFilterPlugin(QObject *parent, const KPluginMetaData &data); |
| 40 | |
| 41 | ~KUriFilterPlugin() override; |
| 42 | |
| 43 | public: |
| 44 | /*! |
| 45 | * Filters a URI. |
| 46 | * |
| 47 | * \a data the URI data to be filtered. |
| 48 | * Returns A boolean indicating whether the URI has been changed. |
| 49 | */ |
| 50 | virtual bool filterUri(KUriFilterData &data) const = 0; |
| 51 | |
| 52 | protected: |
| 53 | /*! |
| 54 | * Sets the URL in @short Filters the given input into a valid url whenever possible.\a data to \a uri. |
| 55 | */ |
| 56 | void setFilteredUri(KUriFilterData &data, const QUrl &uri) const; |
| 57 | |
| 58 | /*! |
| 59 | * Sets the error message in \a data to \a errormsg. |
| 60 | */ |
| 61 | void setErrorMsg(KUriFilterData &data, const QString &errmsg) const; |
| 62 | |
| 63 | /*! |
| 64 | * Sets the URI type in \a data to \a type. |
| 65 | */ |
| 66 | void setUriType(KUriFilterData &data, KUriFilterData::UriTypes type) const; |
| 67 | |
| 68 | /*! |
| 69 | * Sets the arguments and options string in \a data to \a args if any were |
| 70 | * found during filtering. |
| 71 | */ |
| 72 | void setArguments(KUriFilterData &data, const QString &args) const; |
| 73 | |
| 74 | /*! |
| 75 | * Sets the name of the search provider, the search term and keyword/term |
| 76 | * separator in \a data. |
| 77 | */ |
| 78 | void setSearchProvider(KUriFilterData &data, KUriFilterSearchProvider *provider, const QString &term, const QChar &separator) const; |
| 79 | |
| 80 | /*! |
| 81 | * Sets the information about the search \a providers in \a data. |
| 82 | */ |
| 83 | void setSearchProviders(KUriFilterData &data, const QList<KUriFilterSearchProvider *> &providers) const; |
| 84 | |
| 85 | /*! |
| 86 | * Returns the icon name for the given \a url and URI \a type. |
| 87 | */ |
| 88 | QString iconNameFor(const QUrl &url, KUriFilterData::UriTypes type) const; |
| 89 | |
| 90 | /*! |
| 91 | * Performs a DNS lookup for \a hostname and returns the result. |
| 92 | * |
| 93 | * This function uses the KIO DNS cache to speed up the |
| 94 | * lookup. It also avoids doing a reverse lookup if the given |
| 95 | * host name is already an ip address. |
| 96 | * |
| 97 | * \note All uri filter plugins that need to perform a hostname |
| 98 | * lookup should use this function. |
| 99 | * |
| 100 | * \a hostname the hostname to lookup. |
| 101 | * |
| 102 | * \a timeout the amount of time in msecs to wait for the lookup. |
| 103 | * |
| 104 | * Returns the result of the host name lookup. |
| 105 | */ |
| 106 | QHostInfo resolveName(const QString &hostname, unsigned long timeout) const; |
| 107 | |
| 108 | private: |
| 109 | class KUriFilterPluginPrivate *const d; |
| 110 | }; |
| 111 | |