File indexing completed on 2025-01-19 04:25:16

0001 /*
0002  * Replacement fot QT Bindings that were removed from QT5
0003  * Copyright (C) 2020  Pedro de Carvalho Gomes <pedrogomes81@gmail.com>
0004  *
0005  * This program is free software: you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation, either version 3 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This program is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017  */
0018 
0019 #ifndef COREURL_H
0020 #define COREURL_H
0021 
0022 #include "QtBinding.h"
0023 
0024 #include <QObject>
0025 #include <QUrl>
0026 
0027 namespace QtBindings
0028 {
0029     namespace Core
0030     {
0031         class Url : public QObject, public QUrl, public QtBindings::Base<Url>
0032         {
0033         Q_OBJECT
0034         public:
0035             Q_INVOKABLE Url();
0036             Q_INVOKABLE explicit Url(const QUrl &copy);
0037             Q_INVOKABLE Url(const Url &copy);
0038             Q_INVOKABLE explicit Url(const QString &url, ParsingMode mode = TolerantMode);
0039             Q_INVOKABLE explicit Url(QUrl &&other);
0040             Q_INVOKABLE static QString fromAce(const QByteArray &domain);
0041             Q_INVOKABLE static QUrl fromEncoded(const QByteArray &url, ParsingMode mode = TolerantMode);
0042             Q_INVOKABLE static QUrl fromLocalFile(const QString &localfile);
0043             Q_INVOKABLE static QString fromPercentEncoding(const QByteArray &input);
0044             Q_INVOKABLE static QList<QUrl> fromStringList(const QStringList &uris, ParsingMode mode = TolerantMode);
0045             Q_INVOKABLE static QUrl fromUserInput(const QString &userInput);
0046             Q_INVOKABLE static QUrl fromUserInput(const QString &userInput, const QString &workingDirectory, UserInputResolutionOptions options = DefaultResolution);
0047             Q_INVOKABLE static QStringList idnWhitelist();
0048             Q_INVOKABLE static void setIdnWhitelist(const QStringList &list);
0049             Q_INVOKABLE static QByteArray toAce(const QString &domain);
0050             Q_INVOKABLE static QByteArray toPercentEncoding(const QString &input, const QByteArray &exclude = QByteArray(), const QByteArray &include = QByteArray());
0051             Q_INVOKABLE static QStringList toStringList(const QList<QUrl> &uris, FormattingOptions options = FormattingOptions(PrettyDecoded));
0052             Url &operator=(const Url &other);
0053         public slots:
0054             QUrl adjusted(FormattingOptions options) const;
0055             QString authority(ComponentFormattingOptions options = PrettyDecoded) const;
0056             void clear();
0057             void detach();
0058             QString errorString() const;
0059             QString fileName(ComponentFormattingOptions options = FullyDecoded) const;
0060             QString fragment(ComponentFormattingOptions options = PrettyDecoded) const;
0061             bool hasFragment() const;
0062             bool hasQuery() const;
0063             QString host(ComponentFormattingOptions options = FullyDecoded) const;
0064             bool isDetached() const;
0065             bool isEmpty() const;
0066             bool isLocalFile() const;
0067             bool isParentOf(const QUrl &url) const;
0068             bool isRelative() const;
0069             bool isValid() const;
0070             bool matches(const QUrl &url, FormattingOptions options) const;
0071             QString password(ComponentFormattingOptions options = FullyDecoded) const;
0072             QString path(ComponentFormattingOptions options = FullyDecoded) const;
0073             int port(int defaultPort = -1) const;
0074             QString query(ComponentFormattingOptions options = PrettyDecoded) const;
0075             QUrl resolved(const QUrl &relative) const;
0076             QString scheme() const;
0077             void setAuthority(const QString &authority, ParsingMode mode = TolerantMode);
0078             void setFragment(const QString &fragment, ParsingMode mode = TolerantMode);
0079             void setHost(const QString &host, ParsingMode mode = DecodedMode);
0080             void setPassword(const QString &password, ParsingMode mode = DecodedMode);
0081             void setPath(const QString &path, ParsingMode mode = DecodedMode);
0082             void setPort(int port);
0083             void setQuery(const QString &query, ParsingMode mode = TolerantMode);
0084             void setQuery(const QUrlQuery &query);
0085             void setScheme(const QString &scheme);
0086             void setUrl(const QString &url, ParsingMode mode = TolerantMode);
0087             void setUserInfo(const QString &userInfo, ParsingMode mode = TolerantMode);
0088             void setUserName(const QString &userName, ParsingMode mode = DecodedMode);
0089             void swap(QUrl &other);
0090             QString toDisplayString(FormattingOptions options = FormattingOptions(PrettyDecoded)) const;
0091             QByteArray toEncoded(FormattingOptions options = FullyEncoded) const;
0092             QString toLocalFile() const;
0093             QString toString(FormattingOptions options = FormattingOptions(PrettyDecoded)) const;
0094             QString url(FormattingOptions options = FormattingOptions(PrettyDecoded)) const;
0095             QString userInfo(ComponentFormattingOptions options = PrettyDecoded) const;
0096             QString userName(ComponentFormattingOptions options = FullyDecoded) const;
0097         };
0098     }
0099 }
0100 Q_DECLARE_METATYPE(QtBindings::Core::Url)
0101 #endif //COREURL_H