| 1 | /* |
| 2 | kshorturifilter.h |
| 3 | |
| 4 | This file is part of the KDE project |
| 5 | SPDX-FileCopyrightText: 2000 Dawit Alemayehu <adawit@kde.org> |
| 6 | SPDX-FileCopyrightText: 2000 Malte Starostik <starosti@zedat.fu-berlin.de> |
| 7 | |
| 8 | SPDX-License-Identifier: GPL-2.0-or-later |
| 9 | */ |
| 10 | |
| 11 | #ifndef KSHORTURIFILTER_H |
| 12 | #define KSHORTURIFILTER_H |
| 13 | |
| 14 | #include <QList> |
| 15 | #include <QRegularExpression> |
| 16 | |
| 17 | #include "kurifilterplugin_p.h" |
| 18 | #include <kurifilter.h> |
| 19 | |
| 20 | /*! |
| 21 | * This is short URL filter class. |
| 22 | * |
| 23 | * @short A filter that converts short URLs into fully qualified ones. |
| 24 | * |
| 25 | * @author Dawit Alemayehu <adawit@kde.org> |
| 26 | * @author Malte Starostik <starosti@zedat.fu-berlin.de> |
| 27 | */ |
| 28 | class KShortUriFilter : public KUriFilterPlugin |
| 29 | { |
| 30 | Q_OBJECT |
| 31 | public: |
| 32 | explicit KShortUriFilter(QObject *parent, const KPluginMetaData &data); |
| 33 | |
| 34 | /*! |
| 35 | * Converts short URIs into fully qualified valid URIs |
| 36 | * whenever possible. |
| 37 | * |
| 38 | * Parses any given invalid URI to determine whether it |
| 39 | * is a known short URI and converts it to its fully |
| 40 | * qualified version. |
| 41 | * |
| 42 | * \a data the data to be filtered |
| 43 | * Returns true if the url has been filtered |
| 44 | */ |
| 45 | bool filterUri(KUriFilterData &data) const override; |
| 46 | |
| 47 | public Q_SLOTS: |
| 48 | void configure(); |
| 49 | |
| 50 | private: |
| 51 | struct URLHint { |
| 52 | URLHint() |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | URLHint(const QString &r, const QString &p, KUriFilterData::UriTypes t = KUriFilterData::NetProtocol) |
| 57 | : hintRe(r) |
| 58 | , prepend(p) |
| 59 | , type(t) |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | QRegularExpression hintRe; // if this matches, then... |
| 64 | QString prepend; // ...prepend this to the url |
| 65 | KUriFilterData::UriTypes type; |
| 66 | }; |
| 67 | |
| 68 | QList<URLHint> m_urlHints; |
| 69 | QString m_strDefaultUrlScheme; |
| 70 | }; |
| 71 | |
| 72 | #endif |
| 73 | |