1 /*
2  * Replacement fot QT Bindings that were removed from QT5
3  * Copyright (C) 2020  Pedro de Carvalho Gomes <pedrogomes81@gmail.com>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef COREURL_H
20 #define COREURL_H
21 
22 #include "QtBinding.h"
23 
24 #include <QObject>
25 #include <QUrl>
26 
27 namespace QtBindings
28 {
29     namespace Core
30     {
31         class Url : public QObject, public QUrl, public QtBindings::Base<Url>
32         {
33         Q_OBJECT
34         public:
35             Q_INVOKABLE Url();
36             Q_INVOKABLE explicit Url(const QUrl &copy);
37             Q_INVOKABLE Url(const Url &copy);
38             Q_INVOKABLE explicit Url(const QString &url, ParsingMode mode = TolerantMode);
39             Q_INVOKABLE explicit Url(QUrl &&other);
40             Q_INVOKABLE static QString fromAce(const QByteArray &domain);
41             Q_INVOKABLE static QUrl fromEncoded(const QByteArray &url, ParsingMode mode = TolerantMode);
42             Q_INVOKABLE static QUrl fromLocalFile(const QString &localfile);
43             Q_INVOKABLE static QString fromPercentEncoding(const QByteArray &input);
44             Q_INVOKABLE static QList<QUrl> fromStringList(const QStringList &uris, ParsingMode mode = TolerantMode);
45             Q_INVOKABLE static QUrl fromUserInput(const QString &userInput);
46             Q_INVOKABLE static QUrl fromUserInput(const QString &userInput, const QString &workingDirectory, UserInputResolutionOptions options = DefaultResolution);
47             Q_INVOKABLE static QStringList idnWhitelist();
48             Q_INVOKABLE static void setIdnWhitelist(const QStringList &list);
49             Q_INVOKABLE static QByteArray toAce(const QString &domain);
50             Q_INVOKABLE static QByteArray toPercentEncoding(const QString &input, const QByteArray &exclude = QByteArray(), const QByteArray &include = QByteArray());
51             Q_INVOKABLE static QStringList toStringList(const QList<QUrl> &uris, FormattingOptions options = FormattingOptions(PrettyDecoded));
52             Url &operator=(const Url &other);
53         public slots:
54             QUrl adjusted(FormattingOptions options) const;
55             QString authority(ComponentFormattingOptions options = PrettyDecoded) const;
56             void clear();
57             void detach();
58             QString errorString() const;
59             QString fileName(ComponentFormattingOptions options = FullyDecoded) const;
60             QString fragment(ComponentFormattingOptions options = PrettyDecoded) const;
61             bool hasFragment() const;
62             bool hasQuery() const;
63             QString host(ComponentFormattingOptions options = FullyDecoded) const;
64             bool isDetached() const;
65             bool isEmpty() const;
66             bool isLocalFile() const;
67             bool isParentOf(const QUrl &url) const;
68             bool isRelative() const;
69             bool isValid() const;
70             bool matches(const QUrl &url, FormattingOptions options) const;
71             QString password(ComponentFormattingOptions options = FullyDecoded) const;
72             QString path(ComponentFormattingOptions options = FullyDecoded) const;
73             int port(int defaultPort = -1) const;
74             QString query(ComponentFormattingOptions options = PrettyDecoded) const;
75             QUrl resolved(const QUrl &relative) const;
76             QString scheme() const;
77             void setAuthority(const QString &authority, ParsingMode mode = TolerantMode);
78             void setFragment(const QString &fragment, ParsingMode mode = TolerantMode);
79             void setHost(const QString &host, ParsingMode mode = DecodedMode);
80             void setPassword(const QString &password, ParsingMode mode = DecodedMode);
81             void setPath(const QString &path, ParsingMode mode = DecodedMode);
82             void setPort(int port);
83             void setQuery(const QString &query, ParsingMode mode = TolerantMode);
84             void setQuery(const QUrlQuery &query);
85             void setScheme(const QString &scheme);
86             void setUrl(const QString &url, ParsingMode mode = TolerantMode);
87             void setUserInfo(const QString &userInfo, ParsingMode mode = TolerantMode);
88             void setUserName(const QString &userName, ParsingMode mode = DecodedMode);
89             void swap(QUrl &other);
90             QString toDisplayString(FormattingOptions options = FormattingOptions(PrettyDecoded)) const;
91             QByteArray toEncoded(FormattingOptions options = FullyEncoded) const;
92             QString toLocalFile() const;
93             QString topLevelDomain(ComponentFormattingOptions options = FullyDecoded) const;
94             QString toString(FormattingOptions options = FormattingOptions(PrettyDecoded)) const;
95             QString url(FormattingOptions options = FormattingOptions(PrettyDecoded)) const;
96             QString userInfo(ComponentFormattingOptions options = PrettyDecoded) const;
97             QString userName(ComponentFormattingOptions options = FullyDecoded) const;
98         };
99     }
100 }
101 Q_DECLARE_METATYPE(QtBindings::Core::Url)
102 #endif //COREURL_H
103