File indexing completed on 2024-04-28 03:55:44

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 
0017 #include "kurifilterplugin_p.h"
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     explicit KShortUriFilter(QObject *parent, const KPluginMetaData &data);
0033 
0034     /**
0035      * Converts short URIs into fully qualified valid URIs
0036      * whenever possible.
0037      *
0038      * Parses any given invalid URI to determine whether it
0039      * is a known short URI and converts it to its fully
0040      * qualified version.
0041      *
0042      * @param data the data to be filtered
0043      * @return true if the url has been filtered
0044      */
0045     bool filterUri(KUriFilterData &data) const override;
0046 
0047 public Q_SLOTS:
0048     void configure();
0049 
0050 private:
0051     struct URLHint {
0052         URLHint()
0053         {
0054         }
0055 
0056         URLHint(const QString &r, const QString &p, KUriFilterData::UriTypes t = KUriFilterData::NetProtocol)
0057             : hintRe(r)
0058             , prepend(p)
0059             , type(t)
0060         {
0061         }
0062 
0063         QRegularExpression hintRe; // if this matches, then...
0064         QString prepend; // ...prepend this to the url
0065         KUriFilterData::UriTypes type;
0066     };
0067 
0068     QList<URLHint> m_urlHints;
0069     QString m_strDefaultUrlScheme;
0070 };
0071 
0072 #endif