15 namespace swift::misc::network
29 : m_host(address.trimmed()), m_port(port), m_path(path.trimmed())
40 if (pathToAppend.
isEmpty()) {
return m_path; }
48 if (m_port > 0) {
return m_port; }
60 const QString q(stripQueryString(query));
68 if (queryToAppend.
isEmpty()) {
return; }
69 const QString q(stripQueryString(queryToAppend));
86 if (m_host.
isEmpty()) {
return {}; }
117 if (path.
isEmpty()) {
return *
this; }
129 const CUrl url(qurl);
156 if (i < 0)
return {};
157 if (f.
length() <= i + 1)
return {};
165 if (i < 0)
return {};
166 if (f.
length() <= i + 1)
return {};
172 static const QString h1(
".html");
173 static const QString h2(
".htm");
179 if (query.
isEmpty()) {
return *
this; }
193 const QPair<QString, QJsonValue> v(
"url",
getFullUrl());
208 if (p ==
"ftp")
return 20;
209 if (p ==
"https")
return 443;
210 if (p ==
"http")
return 80;
217 if (p < 0) {
return false; }
226 if (q.startsWith(
"?") || q.startsWith(
"&")) { q = q.mid(1); }
227 if (q.endsWith(
"?") || q.endsWith(
"&")) { q = q.left(q.size() - 1); }
256 case IndexPort: this->
setPort(variant.
value<qint32>());
break;
static bool isExecutableFile(const QString &fileName)
Executable file (decided by appendix)
static bool isSwiftInstaller(const QString &fileName)
swift installer
static QString appendFilePaths(const QString &path1, const QString &path2)
Append file paths.
Thrown when a convertFromJson method encounters an unrecoverable error in JSON data.
Non-owning reference to a CPropertyIndex with a subset of its features.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
ColumnIndex
Base class enums.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
static QNetworkRequest getSwiftNetworkRequest(const QUrl &url, RequestType type=Get, const QString &userAgentDetails={})
Our tweaked network request with swift header.
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
QString convertToQString(bool i18n=false) const
Cast as QString.
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
bool isSwiftInstaller() const
swift installer
CUrl withSwitchedScheme(const QString &protocol, int port) const
Switch protocol.
QString getFileSuffix() const
File appendix if any, otherwise empty, does not include the ".".
bool hasPath() const
Has path?
void setQUrl(const QUrl &url)
To QUrl.
QString getFileName() const
File name.
int getPort() const
Get port.
bool isFile() const
A path ends with "/", and file is anythingy beyond that, e.g. "path/file".
static int protocolToDefaultPort(const QString &protocol)
Protocol to default port.
bool hasScheme() const
Protocol.
QString appendPath(const QString &pathToAppend)
Append path.
QString getFileSuffixPlusDot() const
Suffix plus dot.
CUrl(const QString &fullUrl=QString())
Default constructor.
const QString & getScheme() const
Get protocl.
void setScheme(const QString &protocol)
Set protocol.
bool isEmpty() const
Empty.
void setQuery(const QString &query)
Set query.
CUrl withAppendedPath(const QString &path) const
Append path.
CUrl withAppendedQuery(const QString &query) const
Append path.
bool isHavingHtmlSuffix() const
Likely a HTM file?
bool isFileWithSuffix(const QString &suffix={}) const
Stricter version of isFile()
bool hasPort() const
Port?
bool hasQuery() const
Query string?
void appendQuery(const QString &queryToAppend)
Append query.
bool isExecutableFile() const
Executable file (decided by appendix)
void setHost(const QString &address)
Set address (e.g. myserver.foo.com)
void setPort(int port)
Set port.
QNetworkRequest toNetworkRequest() const
To request.
QJsonObject toJson() const
Cast to JSON object.
void setPath(const QString &path)
Set path.
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
const QString & getPath() const
Get path.
bool pathEndsWith(const QString &ending, Qt::CaseSensitivity cs=Qt::CaseInsensitive) const
Path ending with?
bool hasDefaultPort() const
Default port.
static bool isDefaultPort(const QString &protocol, int port)
Default port for given protocol.
static CUrl fromLocalFile(const QString &localFile)
From local file path.
void setFullUrl(const QString &fullUrl)
Set full URL.
QUrl toQUrl() const
To QUrl.
void convertFromJson(const QJsonObject &json)
Assign from JSON object.
void setFragment(const QString &fragment)
Set fragment.
bool hasFragment() const
Fragment string?
QString getFullUrl(bool withQuery=true) const
Qualified name.
QJsonValue value(QLatin1StringView key) const const
bool isUndefined() const const
QString toString() const const
QString & append(QChar ch)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
qsizetype lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const const
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) &&
QString number(double n, char format, int precision)
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
QString simplified() const const
QString toLower() const const
QString trimmed() const const
QString fileName(QUrl::ComponentFormattingOptions options) const const
QString fragment(QUrl::ComponentFormattingOptions options) const const
QUrl fromLocalFile(const QString &localFile)
QString host(QUrl::ComponentFormattingOptions options) const const
QString path(QUrl::ComponentFormattingOptions options) const const
int port(int defaultPort) const const
QString query(QUrl::ComponentFormattingOptions options) const const
QString scheme() const const
void setScheme(const QString &scheme)
QVariant fromValue(T &&value)
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.