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 * 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 * @ref filterUri.
24 *
25 * @short Abstract class for URI filter plugins.
26 */
27class KIOGUI_EXPORT KUriFilterPlugin : public QObject
28{
29 Q_OBJECT
30
31public:
32 /**
33 * Constructs a filter plugin with a given name
34 *
35 * @param parent the parent object, or @c nullptr for no parent
36 * @param name the name of the plugin, mandatory
37 */
38 explicit KUriFilterPlugin(QObject *parent, const KPluginMetaData &data);
39
40 ~KUriFilterPlugin() override;
41
42public:
43 /**
44 * Filters a URI.
45 *
46 * @param data the URI data to be filtered.
47 * @return A boolean indicating whether the URI has been changed.
48 */
49 virtual bool filterUri(KUriFilterData &data) const = 0;
50
51protected:
52 /**
53 * Sets the URL in @p data to @p uri.
54 */
55 void setFilteredUri(KUriFilterData &data, const QUrl &uri) const;
56
57 /**
58 * Sets the error message in @p data to @p errormsg.
59 */
60 void setErrorMsg(KUriFilterData &data, const QString &errmsg) const;
61
62 /**
63 * Sets the URI type in @p data to @p type.
64 */
65 void setUriType(KUriFilterData &data, KUriFilterData::UriTypes type) const;
66
67 /**
68 * Sets the arguments and options string in @p data to @p args if any were
69 * found during filtering.
70 */
71 void setArguments(KUriFilterData &data, const QString &args) const;
72
73 /**
74 * Sets the name of the search provider, the search term and keyword/term
75 * separator in @p data.
76 */
77 void setSearchProvider(KUriFilterData &data, KUriFilterSearchProvider *provider, const QString &term, const QChar &separator) const;
78
79 /**
80 * Sets the information about the search @p providers in @p data.
81 */
82 void setSearchProviders(KUriFilterData &data, const QList<KUriFilterSearchProvider *> &providers) const;
83
84 /**
85 * Returns the icon name for the given @p url and URI @p type.
86 */
87 QString iconNameFor(const QUrl &url, KUriFilterData::UriTypes type) const;
88
89 /**
90 * Performs a DNS lookup for @p hostname and returns the result.
91 *
92 * This function uses the KIO DNS cache to speed up the
93 * lookup. It also avoids doing a reverse lookup if the given
94 * host name is already an ip address.
95 *
96 * \note All uri filter plugins that need to perform a hostname
97 * lookup should use this function.
98 *
99 * @param hostname the hostname to lookup.
100 * @param timeout the amount of time in msecs to wait for the lookup.
101 * @return the result of the host name lookup.
102 */
103 QHostInfo resolveName(const QString &hostname, unsigned long timeout) const;
104
105private:
106 class KUriFilterPluginPrivate *const d;
107};
108

source code of kio/src/gui/kurifilterplugin_p.h