File indexing completed on 2024-05-12 11:54:37
0001 /* 0002 kshorturifilter.h 0003 0004 This file is part of the KDE project 0005 SPDX-FileCopyrightText: 2000 Dawit Alemayehu <adawit@kde.org> 0006 SPDX-FileCopyrightText: 2000 Malte Starostik <starosti@zedat.fu-berlin.de> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #ifndef KSHORTURIFILTER_H 0012 #define KSHORTURIFILTER_H 0013 0014 #include <QList> 0015 #include <QRegularExpression> 0016 #include <QVariant> 0017 0018 #include <kurifilter.h> 0019 0020 /** 0021 * This is short URL filter class. 0022 * 0023 * @short A filter that converts short URLs into fully qualified ones. 0024 * 0025 * @author Dawit Alemayehu <adawit@kde.org> 0026 * @author Malte Starostik <starosti@zedat.fu-berlin.de> 0027 */ 0028 class KShortUriFilter : public KUriFilterPlugin 0029 { 0030 Q_OBJECT 0031 public: 0032 /** 0033 * Creates a Short URI filter object 0034 * 0035 * @param parent the parent of this class. 0036 * @param name the internal name for this object. 0037 */ 0038 explicit KShortUriFilter(QObject *parent = nullptr, const QVariantList &args = QVariantList()); 0039 0040 /** 0041 * Destructor 0042 */ 0043 ~KShortUriFilter() override 0044 { 0045 } 0046 0047 /** 0048 * Converts short URIs into fully qualified valid URIs 0049 * whenever possible. 0050 * 0051 * Parses any given invalid URI to determine whether it 0052 * is a known short URI and converts it to its fully 0053 * qualified version. 0054 * 0055 * @param data the data to be filtered 0056 * @return true if the url has been filtered 0057 */ 0058 bool filterUri(KUriFilterData &data) const override; 0059 0060 /** 0061 * Returns the name of the config module for 0062 * this plugin. 0063 * 0064 * @return the name of the config module. 0065 */ 0066 QString configName() const override; 0067 0068 /** 0069 * Returns an instance of the module used to configure 0070 * this object. 0071 * 0072 * @return the config module 0073 */ 0074 KCModule *configModule(QWidget *, const char *) const override; 0075 0076 public Q_SLOTS: 0077 void configure(); 0078 0079 private: 0080 struct URLHint { 0081 URLHint() 0082 { 0083 } 0084 0085 URLHint(const QString &r, const QString &p, KUriFilterData::UriTypes t = KUriFilterData::NetProtocol) 0086 : hintRe(r) 0087 , prepend(p) 0088 , type(t) 0089 { 0090 } 0091 0092 QRegularExpression hintRe; // if this matches, then... 0093 QString prepend; // ...prepend this to the url 0094 KUriFilterData::UriTypes type; 0095 }; 0096 0097 QList<URLHint> m_urlHints; 0098 QString m_strDefaultUrlScheme; 0099 }; 0100 0101 #endif