File indexing completed on 2024-05-12 04:45:59

0001 #include "contactimage.h"
0002 #ifdef Q_OS_ANDROID
0003 #include "androidinterface.h"
0004 #else
0005 #include "linuxinterface.h"
0006 #endif
0007 #include <QDebug>
0008 
0009 ContactImage::ContactImage(ImageType type)
0010     : QQuickImageProvider(type, Flags())
0011     , no_image(QImage(":/portrait.jpg"))
0012 {
0013     //    this->blockSignals(false);
0014 }
0015 
0016 ContactImage::ContactImage(ImageType type, Flags flags)
0017     : QQuickImageProvider(type, flags)
0018     , no_image(QImage(":/portrait.jpg"))
0019 {
0020     //    this->blockSignals(false);
0021 }
0022 
0023 QImage ContactImage::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
0024 {
0025     qDebug() << "requesting contact image with id " << id;
0026     QImage result;
0027 #ifdef Q_OS_ANDROID
0028     result = AndroidInterface::contactPhoto(id);
0029 #else
0030     result = LinuxInterface::contactPhoto(id);
0031 #endif
0032 
0033     if (result.isNull()) {
0034         result = this->no_image;
0035     }
0036 
0037     if (size) {
0038         *size = result.size();
0039     }
0040 
0041     if (requestedSize.width() > 0 && requestedSize.height() > 0) {
0042         result = result.scaled(requestedSize.width(), requestedSize.height(), Qt::KeepAspectRatio);
0043     }
0044 
0045     return result;
0046 }
0047 
0048 void ContactImage::updateImage(const QImage &image)
0049 {
0050     if (this->image != image) {
0051         this->image = image;
0052         emit imageChanged();
0053     }
0054 }