swift
Loading...
Searching...
No Matches
url.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_MISC_NETWORK_URL_H
7#define SWIFT_MISC_NETWORK_URL_H
8
9#include <QJsonObject>
10#include <QMetaType>
11#include <QNetworkRequest>
12#include <QString>
13#include <QUrl>
14
15#include "misc/metaclass.h"
18#include "misc/valueobject.h"
19
20SWIFT_DECLARE_VALUEOBJECT_MIXINS(swift::misc::network, CUrl)
21
22namespace swift::misc::network
23{
26 class SWIFT_MISC_EXPORT CUrl : public CValueObject<CUrl>
27 {
28 public:
31 {
32 IndexScheme = CPropertyIndexRef::GlobalIndexCUrl,
33 IndexHost,
34 IndexPort,
35 IndexPath,
36 IndexQuery
37 };
38
40 CUrl(const QString &fullUrl = QString());
41
43 CUrl(const char *url);
44
46 CUrl(const QUrl &url);
47
49 CUrl(const QString &address, int port);
50
52 CUrl(const QString &scheme, const QString &address, int port, const QString &path);
53
55 const QString &getHost() const { return m_host; }
56
58 void setHost(const QString &address) { m_host = address.trimmed(); }
59
61 const QString &getScheme() const { return m_scheme; }
62
64 void setScheme(const QString &protocol);
65
67 bool hasScheme() const { return !m_scheme.isEmpty(); }
68
70 const QString &getPath() const { return m_path; }
71
73 void setPath(const QString &path);
74
76 QString appendPath(const QString &pathToAppend);
77
79 bool hasPath() const { return !m_path.isEmpty(); }
80
82 int getPort() const;
83
85 void setPort(int port) { m_port = port; }
86
88 bool hasPort() const;
89
91 bool hasDefaultPort() const;
92
94 QString getQuery() const { return m_query; }
95
97 void setQuery(const QString &query);
98
100 bool hasQuery() const;
101
103 void appendQuery(const QString &queryToAppend);
104
106 void appendQuery(const QString &key, const QString &value);
107
109 bool hasFragment() const;
110
112 void setFragment(const QString &fragment);
113
115 bool isEmpty() const;
116
118 QString getFullUrl(bool withQuery = true) const;
119
121 void setFullUrl(const QString &fullUrl);
122
124 QString getFileName() const;
125
127 QUrl toQUrl() const;
128
130 void setQUrl(const QUrl &url);
131
133 QNetworkRequest toNetworkRequest() const;
134
136 CUrl withAppendedPath(const QString &path) const;
137
139 CUrl withAppendedQuery(const QString &query) const;
140
142 CUrl withSwitchedScheme(const QString &protocol, int port) const;
143
145 bool pathEndsWith(const QString &ending, Qt::CaseSensitivity cs = Qt::CaseInsensitive) const;
146
149 bool isFile() const;
150
152 bool isFileWithSuffix(const QString &suffix = {}) const;
153
156 QString getFileSuffix() const;
157
159 QString getFileSuffixPlusDot() const;
160
162 bool isHavingHtmlSuffix() const;
163
165 bool isExecutableFile() const;
166
168 bool isSwiftInstaller() const;
169
171 QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const;
172
174 void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant);
175
177 QString convertToQString(bool i18n = false) const;
178
180 QJsonObject toJson() const;
181
183 void convertFromJson(const QJsonObject &json);
184
186 static int protocolToDefaultPort(const QString &protocol);
187
189 static bool isDefaultPort(const QString &protocol, int port);
190
192 static CUrl fromLocalFile(const QString &localFile);
193
195 operator QUrl() const { return this->toQUrl(); }
196
197 private:
198 QString m_scheme;
199 QString m_host;
200 int m_port = -1;
201 QString m_path;
202 QString m_query;
203 QString m_fragment;
204
205 static QString stripQueryString(const QString &query);
206
208 CUrl,
209 SWIFT_METAMEMBER(scheme),
210 SWIFT_METAMEMBER(host),
211 SWIFT_METAMEMBER(port),
212 SWIFT_METAMEMBER(path),
213 SWIFT_METAMEMBER(query),
214 SWIFT_METAMEMBER(fragment));
215 };
216} // namespace swift::misc::network
217
218Q_DECLARE_METATYPE(swift::misc::network::CUrl)
219
220#endif // SWIFT_MISC_NETWORK_URL_H
Non-owning reference to a CPropertyIndex with a subset of its features.
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
Definition url.h:27
bool hasPath() const
Has path?
Definition url.h:79
QString getQuery() const
Get query part.
Definition url.h:94
ColumnIndex
Properties by index.
Definition url.h:31
bool hasScheme() const
Protocol.
Definition url.h:67
const QString & getScheme() const
Get protocl.
Definition url.h:61
const QString & getHost() const
Get host.
Definition url.h:55
CUrl(const QString &fullUrl=QString())
Default constructor.
Definition url.cpp:17
const QString & getPath() const
Get path.
Definition url.h:70
void setHost(const QString &address)
Set address (e.g. myserver.foo.com).
Definition url.h:58
void setPort(int port)
Set port.
Definition url.h:85
QUrl toQUrl() const
To QUrl.
Definition url.cpp:137
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition metaclass.h:72
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition metaclass.h:52
QString trimmed() const const
CaseSensitivity
#define SWIFT_MISC_EXPORT
Export a class or function from the library.
#define SWIFT_DECLARE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template declaration of mixins for a CValueObject subclass to be placed near the top of the ...
Definition valueobject.h:65