Skip to content

Commit

Permalink
Reduce ThumbnailProvider interface to bare bones
Browse files Browse the repository at this point in the history
Just because I can!
  • Loading branch information
Kitsune Ral committed Dec 30, 2023
1 parent 796313c commit 6cdd6d1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
28 changes: 20 additions & 8 deletions client/thumbnailprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,28 @@ class AvatarResponse : public AbstractThumbnailResponse {

#include "thumbnailprovider.moc" // Because we define a Q_OBJECT in the cpp file

template <>
QQuickImageResponse* AvatarProvider::requestImageResponse(
const QString& id, const QSize& requestedSize)
template <class ResponseT>
class ImageProviderTemplate : public QQuickAsyncImageProvider {
public:
explicit ImageProviderTemplate(TimelineWidget* parent) : timeline(parent) {}

private:
QQuickImageResponse* requestImageResponse(const QString& id,
const QSize& requestedSize) override
{
return new ResponseT(timeline, id, requestedSize);
}

const TimelineWidget* const timeline;
Q_DISABLE_COPY(ImageProviderTemplate)
};

QQuickAsyncImageProvider* makeAvatarProvider(TimelineWidget* parent)
{
return new AvatarResponse(timeline, id, requestedSize);
return new ImageProviderTemplate<AvatarResponse>(parent);
}

template <>
QQuickImageResponse* ThumbnailProvider::requestImageResponse(
const QString& id, const QSize& requestedSize)
QQuickAsyncImageProvider* makeThumbnailProvider(TimelineWidget* parent)
{
return new ThumbnailResponse(timeline, id, requestedSize);
return new ImageProviderTemplate<ThumbnailResponse>(parent);
}
17 changes: 2 additions & 15 deletions client/thumbnailprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,5 @@

class TimelineWidget;

template <bool Avatar>
class ImageProviderTemplate : public QQuickAsyncImageProvider {
public:
explicit ImageProviderTemplate(TimelineWidget* parent) : timeline(parent) {}

QQuickImageResponse* requestImageResponse(
const QString& id, const QSize& requestedSize) override;

private:
const TimelineWidget* const timeline;
Q_DISABLE_COPY(ImageProviderTemplate)
};

using AvatarProvider = ImageProviderTemplate<true>;
using ThumbnailProvider = ImageProviderTemplate<false>;
QQuickAsyncImageProvider* makeAvatarProvider(TimelineWidget* parent);
QQuickAsyncImageProvider* makeThumbnailProvider(TimelineWidget* parent);
4 changes: 2 additions & 2 deletions client/timelinewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ TimelineWidget::TimelineWidget(ChatRoomWidget* chatRoomWidget)

setResizeMode(SizeRootObjectToView);

engine()->addImageProvider("avatar"_ls, new AvatarProvider(this));
engine()->addImageProvider("thumbnail"_ls, new ThumbnailProvider(this));
engine()->addImageProvider("avatar"_ls, makeAvatarProvider(this));
engine()->addImageProvider("thumbnail"_ls, makeThumbnailProvider(this));

auto* ctxt = rootContext();
ctxt->setContextProperty("messageModel"_ls, m_messageModel);
Expand Down

0 comments on commit 6cdd6d1

Please sign in to comment.