Commit afa56dcf authored by Alexandre Lision's avatar Alexandre Lision Committed by Alexandre Lision

images: cache contact photos

Use a QHash to store contact photos.
Is saves around 25% of memory used at startup

Note: if contact photo is updated on the system it will only reflect
in Ring at next startup due to this caching

Tuleap: #663
Change-Id: I10bf90b8425efcdf120b16d088a56be015ffdda3
parent 4f264629
......@@ -63,6 +63,7 @@ namespace Interfaces {
CGImageRef resizeCGImage(CGImageRef image, const QSize& size);
QHash<QString, QPixmap> m_hDefaultUserPixmap;
QHash<QString, QPixmap> m_hContactsPixmap;
/**
* Return a version of size destSize centered of the bigger photo
......
......@@ -46,6 +46,13 @@ namespace Interfaces {
QVariant ImageManipulationDelegate::contactPhoto(Person* c, const QSize& size, bool displayPresence) {
const int radius = size.height() / 2;
auto index = QStringLiteral("%1%2%3").arg(size.width())
.arg(size.height())
.arg(QString::fromUtf8(c->uid()));
if (m_hContactsPixmap.contains(index)) {
return m_hContactsPixmap.value(index);
}
QPixmap pxm;
if (c && c->photo().isValid()) {
QPixmap contactPhoto(qvariant_cast<QPixmap>(c->photo()).scaled(size, Qt::KeepAspectRatioByExpanding,
......@@ -87,6 +94,8 @@ namespace Interfaces {
pxm = drawDefaultUserPixmap(size);
}
m_hContactsPixmap.insert(index, pxm);
return pxm;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment