diff options
-rw-r--r-- | gtad/gtad.yaml | 3 | ||||
-rw-r--r-- | lib/avatar.h | 2 | ||||
-rw-r--r-- | lib/converters.h | 33 | ||||
-rw-r--r-- | lib/csapi/content-repo.cpp | 6 | ||||
-rw-r--r-- | lib/csapi/content-repo.h | 11 | ||||
-rw-r--r-- | lib/csapi/definitions/public_rooms_response.h | 2 | ||||
-rw-r--r-- | lib/csapi/definitions/request_token_response.h | 2 | ||||
-rw-r--r-- | lib/csapi/definitions/wellknown/homeserver.h | 2 | ||||
-rw-r--r-- | lib/csapi/definitions/wellknown/identity_server.h | 2 | ||||
-rw-r--r-- | lib/csapi/profile.cpp | 2 | ||||
-rw-r--r-- | lib/csapi/profile.h | 6 | ||||
-rw-r--r-- | lib/csapi/pusher.h | 4 | ||||
-rw-r--r-- | lib/csapi/rooms.h | 2 | ||||
-rw-r--r-- | lib/csapi/search.h | 2 | ||||
-rw-r--r-- | lib/csapi/users.h | 2 | ||||
-rw-r--r-- | lib/user.cpp | 12 |
16 files changed, 45 insertions, 48 deletions
diff --git a/gtad/gtad.yaml b/gtad/gtad.yaml index 928a1495..58e1909c 100644 --- a/gtad/gtad.yaml +++ b/gtad/gtad.yaml @@ -68,6 +68,9 @@ analyzer: - dateTime: type: QDateTime initializer: QDateTime::fromString("{{defaultValue}}") + - uri: + type: QUrl + initializer: QUrl::fromEncoded("{{defaultValue}}") - //: &QString type: QString initializer: QStringLiteral("{{defaultValue}}") diff --git a/lib/avatar.h b/lib/avatar.h index be125c17..37e1eeef 100644 --- a/lib/avatar.h +++ b/lib/avatar.h @@ -21,7 +21,7 @@ public: Avatar& operator=(Avatar&&); using get_callback_t = std::function<void()>; - using upload_callback_t = std::function<void(QString)>; + using upload_callback_t = std::function<void(QUrl)>; QImage get(Connection* connection, int dimension, get_callback_t callback) const; diff --git a/lib/converters.h b/lib/converters.h index af6c0192..cc6378e4 100644 --- a/lib/converters.h +++ b/lib/converters.h @@ -151,10 +151,17 @@ struct JsonConverter<QDate> { }; template <> -struct JsonConverter<QUrl> : JsonConverter<QString> { - static auto dump(const QUrl& url) // Override on top of that for QString +struct JsonConverter<QUrl> { + static auto load(const QJsonValue& jv) + { + // QT_NO_URL_CAST_FROM_STRING makes this a bit more verbose + QUrl url; + url.setUrl(jv.toString()); + return url; + } + static auto dump(const QUrl& url) { - return JsonConverter<QString>::dump(url.toString(QUrl::FullyEncoded)); + return url.toString(QUrl::FullyEncoded); } }; @@ -164,15 +171,6 @@ struct JsonConverter<QJsonArray> : public TrivialJsonDumper<QJsonArray> { }; template <> -struct JsonConverter<QByteArray> { - static QString dump(const QByteArray& ba) { return ba.constData(); } - static auto load(const QJsonValue& jv) - { - return fromJson<QString>(jv).toLatin1(); - } -}; - -template <> struct JsonConverter<QVariant> { static QJsonValue dump(const QVariant& v); static QVariant load(const QJsonValue& jv); @@ -304,16 +302,15 @@ namespace _impl { q.addQueryItem(k, v ? QStringLiteral("true") : QStringLiteral("false")); } - inline void addTo(QUrlQuery& q, const QString& k, const QStringList& vals) + inline void addTo(QUrlQuery& q, const QString& k, const QUrl& v) { - for (const auto& v : vals) - q.addQueryItem(k, v); + q.addQueryItem(k, v.toEncoded()); } - inline void addTo(QUrlQuery& q, const QString&, const QJsonObject& vals) + inline void addTo(QUrlQuery& q, const QString& k, const QStringList& vals) { - for (auto it = vals.begin(); it != vals.end(); ++it) - q.addQueryItem(it.key(), it.value().toString()); + for (const auto& v : vals) + q.addQueryItem(k, v); } // This one is for types that don't have isEmpty() and for all types diff --git a/lib/csapi/content-repo.cpp b/lib/csapi/content-repo.cpp index e913bfd1..00bc9706 100644 --- a/lib/csapi/content-repo.cpp +++ b/lib/csapi/content-repo.cpp @@ -122,7 +122,7 @@ GetContentThumbnailJob::GetContentThumbnailJob(const QString& serverName, setExpectedContentTypes({ "image/jpeg", "image/png" }); } -auto queryToGetUrlPreview(const QString& url, Omittable<qint64> ts) +auto queryToGetUrlPreview(const QUrl& url, Omittable<qint64> ts) { QUrlQuery _q; addParam<>(_q, QStringLiteral("url"), url); @@ -130,7 +130,7 @@ auto queryToGetUrlPreview(const QString& url, Omittable<qint64> ts) return _q; } -QUrl GetUrlPreviewJob::makeRequestUrl(QUrl baseUrl, const QString& url, +QUrl GetUrlPreviewJob::makeRequestUrl(QUrl baseUrl, const QUrl& url, Omittable<qint64> ts) { return BaseJob::makeRequestUrl(std::move(baseUrl), @@ -139,7 +139,7 @@ QUrl GetUrlPreviewJob::makeRequestUrl(QUrl baseUrl, const QString& url, queryToGetUrlPreview(url, ts)); } -GetUrlPreviewJob::GetUrlPreviewJob(const QString& url, Omittable<qint64> ts) +GetUrlPreviewJob::GetUrlPreviewJob(const QUrl& url, Omittable<qint64> ts) : BaseJob(HttpVerb::Get, QStringLiteral("GetUrlPreviewJob"), QStringLiteral("/_matrix/media/r0") % "/preview_url", queryToGetUrlPreview(url, ts)) diff --git a/lib/csapi/content-repo.h b/lib/csapi/content-repo.h index f3d7309a..28409f5c 100644 --- a/lib/csapi/content-repo.h +++ b/lib/csapi/content-repo.h @@ -34,10 +34,7 @@ public: /// The [MXC URI](/client-server-api/#matrix-content-mxc-uris) to the /// uploaded content. - QString contentUri() const - { - return loadFromJson<QString>("content_uri"_ls); - } + QUrl contentUri() const { return loadFromJson<QUrl>("content_uri"_ls); } }; /*! \brief Download content from the content repository. @@ -219,14 +216,14 @@ public: * return a newer version if it does not have the requested version * available. */ - explicit GetUrlPreviewJob(const QString& url, Omittable<qint64> ts = none); + explicit GetUrlPreviewJob(const QUrl& url, Omittable<qint64> ts = none); /*! \brief Construct a URL without creating a full-fledged job object * * This function can be used when a URL for GetUrlPreviewJob * is necessary but the job itself isn't. */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& url, + static QUrl makeRequestUrl(QUrl baseUrl, const QUrl& url, Omittable<qint64> ts = none); // Result properties @@ -239,7 +236,7 @@ public: /// An [MXC URI](/client-server-api/#matrix-content-mxc-uris) to the image. /// Omitted if there is no image. - QString ogImage() const { return loadFromJson<QString>("og:image"_ls); } + QUrl ogImage() const { return loadFromJson<QUrl>("og:image"_ls); } }; /*! \brief Get the configuration for the content repository. diff --git a/lib/csapi/definitions/public_rooms_response.h b/lib/csapi/definitions/public_rooms_response.h index 34b447d2..2938b4ec 100644 --- a/lib/csapi/definitions/public_rooms_response.h +++ b/lib/csapi/definitions/public_rooms_response.h @@ -36,7 +36,7 @@ struct PublicRoomsChunk { bool guestCanJoin; /// The URL for the room's avatar, if one is set. - QString avatarUrl; + QUrl avatarUrl; /// The room's join rule. When not present, the room is assumed to /// be `public`. Note that rooms with `invite` join rules are not diff --git a/lib/csapi/definitions/request_token_response.h b/lib/csapi/definitions/request_token_response.h index f9981100..d5fbbadb 100644 --- a/lib/csapi/definitions/request_token_response.h +++ b/lib/csapi/definitions/request_token_response.h @@ -25,7 +25,7 @@ struct RequestTokenResponse { /// will happen without the client's involvement provided the homeserver /// advertises this specification version in the `/versions` response /// (ie: r0.5.0). - QString submitUrl; + QUrl submitUrl; }; template <> diff --git a/lib/csapi/definitions/wellknown/homeserver.h b/lib/csapi/definitions/wellknown/homeserver.h index 5cfaca24..b7db4182 100644 --- a/lib/csapi/definitions/wellknown/homeserver.h +++ b/lib/csapi/definitions/wellknown/homeserver.h @@ -10,7 +10,7 @@ namespace Quotient { /// Used by clients to discover homeserver information. struct HomeserverInformation { /// The base URL for the homeserver for client-server connections. - QString baseUrl; + QUrl baseUrl; }; template <> diff --git a/lib/csapi/definitions/wellknown/identity_server.h b/lib/csapi/definitions/wellknown/identity_server.h index 3bd07bd1..885e3d34 100644 --- a/lib/csapi/definitions/wellknown/identity_server.h +++ b/lib/csapi/definitions/wellknown/identity_server.h @@ -10,7 +10,7 @@ namespace Quotient { /// Used by clients to discover identity server information. struct IdentityServerInformation { /// The base URL for the identity server for client-server connections. - QString baseUrl; + QUrl baseUrl; }; template <> diff --git a/lib/csapi/profile.cpp b/lib/csapi/profile.cpp index 8436b8e6..745fa488 100644 --- a/lib/csapi/profile.cpp +++ b/lib/csapi/profile.cpp @@ -33,7 +33,7 @@ GetDisplayNameJob::GetDisplayNameJob(const QString& userId) false) {} -SetAvatarUrlJob::SetAvatarUrlJob(const QString& userId, const QString& avatarUrl) +SetAvatarUrlJob::SetAvatarUrlJob(const QString& userId, const QUrl& avatarUrl) : BaseJob(HttpVerb::Put, QStringLiteral("SetAvatarUrlJob"), QStringLiteral("/_matrix/client/r0") % "/profile/" % userId % "/avatar_url") diff --git a/lib/csapi/profile.h b/lib/csapi/profile.h index 8bbe4f8c..7f9c9e95 100644 --- a/lib/csapi/profile.h +++ b/lib/csapi/profile.h @@ -73,7 +73,7 @@ public: * \param avatarUrl * The new avatar URL for this user. */ - explicit SetAvatarUrlJob(const QString& userId, const QString& avatarUrl); + explicit SetAvatarUrlJob(const QString& userId, const QUrl& avatarUrl); }; /*! \brief Get the user's avatar URL. @@ -101,7 +101,7 @@ public: // Result properties /// The user's avatar URL if they have set one, otherwise not present. - QString avatarUrl() const { return loadFromJson<QString>("avatar_url"_ls); } + QUrl avatarUrl() const { return loadFromJson<QUrl>("avatar_url"_ls); } }; /*! \brief Get this user's profile information. @@ -130,7 +130,7 @@ public: // Result properties /// The user's avatar URL if they have set one, otherwise not present. - QString avatarUrl() const { return loadFromJson<QString>("avatar_url"_ls); } + QUrl avatarUrl() const { return loadFromJson<QUrl>("avatar_url"_ls); } /// The user's display name if they have set one, otherwise not present. QString displayname() const diff --git a/lib/csapi/pusher.h b/lib/csapi/pusher.h index 13c9ec25..622b0df6 100644 --- a/lib/csapi/pusher.h +++ b/lib/csapi/pusher.h @@ -21,7 +21,7 @@ public: struct PusherData { /// Required if `kind` is `http`. The URL to use to send /// notifications to. - QString url; + QUrl url; /// The format to use when sending notifications to the Push /// Gateway. QString format; @@ -119,7 +119,7 @@ public: /// Required if `kind` is `http`. The URL to use to send /// notifications to. MUST be an HTTPS URL with a path of /// `/_matrix/push/v1/notify`. - QString url; + QUrl url; /// The format to send notifications in to Push Gateways if the /// `kind` is `http`. The details about what fields the /// homeserver should send to the push gateway are defined in the diff --git a/lib/csapi/rooms.h b/lib/csapi/rooms.h index 51af2c65..2620582b 100644 --- a/lib/csapi/rooms.h +++ b/lib/csapi/rooms.h @@ -175,7 +175,7 @@ public: /// The display name of the user this object is representing. QString displayName; /// The mxc avatar url of the user this object is representing. - QString avatarUrl; + QUrl avatarUrl; }; // Construction/destruction diff --git a/lib/csapi/search.h b/lib/csapi/search.h index b56d9154..3d02752a 100644 --- a/lib/csapi/search.h +++ b/lib/csapi/search.h @@ -81,7 +81,7 @@ public: /// Performs a full text search across different categories. QString displayname; /// Performs a full text search across different categories. - QString avatarUrl; + QUrl avatarUrl; }; /// Context for result, if requested. diff --git a/lib/csapi/users.h b/lib/csapi/users.h index eab18f6c..ec186592 100644 --- a/lib/csapi/users.h +++ b/lib/csapi/users.h @@ -41,7 +41,7 @@ public: /// The display name of the user, if one exists. QString displayName; /// The avatar url, as an MXC, if one exists. - QString avatarUrl; + QUrl avatarUrl; }; // Construction/destruction diff --git a/lib/user.cpp b/lib/user.cpp index a7e0efd9..a4abed37 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -135,17 +135,17 @@ template <typename SourceT> inline bool User::doSetAvatar(SourceT&& source) { return d->defaultAvatar.upload( - connection(), source, [this](const QString& contentUri) { + connection(), source, [this](const QUrl& contentUri) { auto* j = connection()->callApi<SetAvatarUrlJob>(id(), contentUri); connect(j, &BaseJob::success, this, - [this, newUrl = QUrl(contentUri)] { - if (newUrl == d->defaultAvatar.url()) { - d->defaultAvatar.updateUrl(newUrl); + [this, contentUri] { + if (contentUri == d->defaultAvatar.url()) { + d->defaultAvatar.updateUrl(contentUri); emit defaultAvatarChanged(); } else qCWarning(MAIN) << "User" << id() << "already has avatar URL set to" - << newUrl.toDisplayString(); + << contentUri.toDisplayString(); }); }); } @@ -162,7 +162,7 @@ bool User::setAvatar(QIODevice* source) void User::removeAvatar() { - connection()->callApi<SetAvatarUrlJob>(id(), ""); + connection()->callApi<SetAvatarUrlJob>(id(), QUrl()); } void User::requestDirectChat() { connection()->requestDirectChat(this); } |