File indexing completed on 2024-04-28 05:26:01

0001 // SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: GPL-3.0-only
0003 
0004 #pragma once
0005 
0006 #include <QQuickAsyncImageProvider>
0007 
0008 #include <KContacts/Addressee>
0009 #include <QAtomicPointer>
0010 #include <QReadWriteLock>
0011 
0012 namespace Akonadi
0013 {
0014 class ContactSearchJob;
0015 }
0016 
0017 class ThumbnailResponse : public QQuickImageResponse
0018 {
0019     Q_OBJECT
0020 public:
0021     ThumbnailResponse(QString mediaId, QSize requestedSize);
0022     ~ThumbnailResponse() override = default;
0023 
0024 private Q_SLOTS:
0025     void startRequest();
0026     void prepareResult();
0027     void doCancel();
0028 
0029 private:
0030     bool searchPhoto(const KContacts::AddresseeList &list);
0031     const QString m_email;
0032     QSize requestedSize;
0033     const QString localFile;
0034 
0035     QImage m_image;
0036     KContacts::Picture m_photo;
0037     QString errorStr;
0038     Akonadi::ContactSearchJob *job = nullptr;
0039     mutable QReadWriteLock lock; // Guards ONLY these two members above
0040 
0041     QQuickTextureFactory *textureFactory() const override;
0042     QString errorString() const override;
0043     void cancel() override;
0044 };
0045 
0046 class ContactImageProvider : public QQuickAsyncImageProvider
0047 {
0048 public:
0049     QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override;
0050 };