aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-01-12 23:22:49 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-01-12 23:22:49 +0900
commit6d77401c5bf1d67d1660c0661c695ed241fdf58a (patch)
tree4e8b8410f060390a315da62fc8ca4781035bc0be
parent24b60a9693d032cc30ce75803730e4727b418087 (diff)
downloadlibquotient-6d77401c5bf1d67d1660c0661c695ed241fdf58a.tar.gz
libquotient-6d77401c5bf1d67d1660c0661c695ed241fdf58a.zip
Connection::getThumbnail: Add an overload for QString
Connection::getThumbnail(QString,...) is better fitting to retrieve images for QML image providers - one doesn't need to create a QUrl (which if made naively ends up being incorrect) and also doesn't need to stack up "mxc://" before the mediaId. Just call Connection::getThumbnail with the id the QML engine gives you.
-rw-r--r--connection.cpp17
-rw-r--r--connection.h5
2 files changed, 19 insertions, 3 deletions
diff --git a/connection.cpp b/connection.cpp
index 85d310cc..e7646b82 100644
--- a/connection.cpp
+++ b/connection.cpp
@@ -297,9 +297,24 @@ RoomMessagesJob* Connection::getMessages(Room* room, const QString& from) const
return callApi<RoomMessagesJob>(room->id(), from);
}
+inline auto splitMediaId(const QString& mediaId)
+{
+ auto idParts = mediaId.split('/');
+ Q_ASSERT_X(idParts.size() == 2, __FUNCTION__,
+ "mediaId should have a form 'serverName/localMediaId' (without apostrophes)");
+ return idParts;
+}
+
+MediaThumbnailJob* Connection::getThumbnail(const QString& mediaId, QSize requestedSize) const
+{
+ auto idParts = splitMediaId(mediaId);
+ return callApi<MediaThumbnailJob>(idParts.front(), idParts.back(),
+ requestedSize);
+}
+
MediaThumbnailJob* Connection::getThumbnail(const QUrl& url, QSize requestedSize) const
{
- return callApi<MediaThumbnailJob>(url, requestedSize);
+ return getThumbnail(url.authority() + url.path(), requestedSize);
}
MediaThumbnailJob* Connection::getThumbnail(const QUrl& url, int requestedWidth,
diff --git a/connection.h b/connection.h
index 8dda2bbf..1d483fe8 100644
--- a/connection.h
+++ b/connection.h
@@ -174,9 +174,11 @@ namespace QMatrixClient
void sync(int timeout = -1);
void stopSync();
- virtual MediaThumbnailJob* getThumbnail(const QUrl& url,
+ virtual MediaThumbnailJob* getThumbnail(const QString& mediaId,
QSize requestedSize) const;
MediaThumbnailJob* getThumbnail(const QUrl& url,
+ QSize requestedSize) const;
+ MediaThumbnailJob* getThumbnail(const QUrl& url,
int requestedWidth,
int requestedHeight) const;
@@ -297,7 +299,6 @@ namespace QMatrixClient
*/
Room* provideRoom(const QString& roomId, JoinState joinState);
-
/**
* Completes loading sync data.
*/