2020-10-19 14:51:31 -04:00
|
|
|
/*
|
2021-06-29 10:39:06 -04:00
|
|
|
* Copyright (C) 2020-2021 by Savoir-faire Linux
|
2020-10-19 14:51:31 -04:00
|
|
|
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
|
2021-06-29 10:39:06 -04:00
|
|
|
* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
|
2020-10-19 14:51:31 -04:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-03-11 13:30:45 -05:00
|
|
|
#include "quickimageproviderbase.h"
|
2020-10-19 14:51:31 -04:00
|
|
|
#include "utils.h"
|
2020-12-15 11:55:38 -05:00
|
|
|
#include "lrcinstance.h"
|
2020-10-19 14:51:31 -04:00
|
|
|
|
|
|
|
#include <QImage>
|
|
|
|
|
2021-03-11 13:30:45 -05:00
|
|
|
class AvatarImageProvider : public QuickImageProviderBase
|
2020-10-19 14:51:31 -04:00
|
|
|
{
|
|
|
|
public:
|
2021-03-11 13:30:45 -05:00
|
|
|
AvatarImageProvider(LRCInstance* instance = nullptr)
|
|
|
|
: QuickImageProviderBase(QQuickImageProvider::Image,
|
2021-04-19 13:10:53 -04:00
|
|
|
QQmlImageProviderBase::ForceAsynchronousImageLoading,
|
|
|
|
instance)
|
2020-10-19 14:51:31 -04:00
|
|
|
{}
|
|
|
|
|
|
|
|
QImage requestImage(const QString& id, QSize* size, const QSize& requestedSize) override
|
|
|
|
{
|
|
|
|
Q_UNUSED(size)
|
|
|
|
|
2021-07-13 22:56:32 -04:00
|
|
|
if (requestedSize == QSize(0, 0)) {
|
|
|
|
qWarning() << Q_FUNC_INFO << "Image request has no dimensions";
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2021-06-29 10:39:06 -04:00
|
|
|
// the first string is the item uri and the second is a uid
|
|
|
|
// that is used for trigger a reload of the underlying image
|
|
|
|
// data and can be discarded at this point
|
2020-10-19 14:51:31 -04:00
|
|
|
auto idInfo = id.split("_");
|
|
|
|
|
2021-06-29 10:39:06 -04:00
|
|
|
if (idInfo.size() < 2) {
|
|
|
|
qWarning() << Q_FUNC_INFO << "Missing element(s) in the image url";
|
|
|
|
return {};
|
|
|
|
}
|
2020-10-19 14:51:31 -04:00
|
|
|
|
2021-06-29 10:39:06 -04:00
|
|
|
auto imageId = idInfo.at(1);
|
|
|
|
if (!imageId.size()) {
|
|
|
|
qWarning() << Q_FUNC_INFO << "Missing id in the image url";
|
|
|
|
return {};
|
2020-10-19 14:51:31 -04:00
|
|
|
}
|
2021-06-29 10:39:06 -04:00
|
|
|
|
|
|
|
auto type = idInfo.at(0);
|
|
|
|
if (type == "conversation")
|
|
|
|
return Utils::conversationAvatar(lrcInstance_, imageId, requestedSize);
|
|
|
|
else if (type == "account")
|
|
|
|
return Utils::accountPhoto(lrcInstance_, imageId, requestedSize);
|
|
|
|
else if (type == "contact")
|
|
|
|
return Utils::contactPhoto(lrcInstance_, imageId, requestedSize);
|
|
|
|
|
|
|
|
qWarning() << Q_FUNC_INFO << "Missing valid prefix in the image url";
|
|
|
|
return {};
|
2020-10-19 14:51:31 -04:00
|
|
|
}
|
|
|
|
};
|