diff options
author | Roeland Jago Douma <rullzer@owncloud.com> | 2015-12-21 18:19:09 +0300 |
---|---|---|
committer | ckamm <mail@ckamm.de> | 2017-11-21 18:33:03 +0300 |
commit | 6b9b5252dedb0a1cbba0e7e5fb59512beb61cd1d (patch) | |
tree | 53b47e84d88b38e38e813f39fc1148ccfd97e9ab /src/gui/shareusergroupwidget.cpp | |
parent | d949ec687741b984b7cb090606775c6968296536 (diff) |
User shares: Show avatars
[Sharing] Show placeholders for avatars
Just like on the web show placeholders for avatars in the sharing dialog
[Sharing] Show avatars!
[Sharing] Show same avatar placeholder for group/federated shares as on
web
Diffstat (limited to 'src/gui/shareusergroupwidget.cpp')
-rw-r--r-- | src/gui/shareusergroupwidget.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp index 848ecfbfb..21dbb314c 100644 --- a/src/gui/shareusergroupwidget.cpp +++ b/src/gui/shareusergroupwidget.cpp @@ -26,6 +26,7 @@ #include "thumbnailjob.h" #include "sharee.h" #include "sharemanager.h" +#include "avatarjob.h" #include "QProgressIndicator.h" #include <QBuffer> @@ -41,6 +42,9 @@ #include <QAction> #include <QDesktopServices> #include <QMessageBox> +#include <QCryptographicHash> +#include <QColor> +#include <QPainter> namespace OCC { @@ -416,6 +420,103 @@ ShareUserLine::ShareUserLine(QSharedPointer<Share> share, if (!share->account()->capabilities().shareResharing()) { _ui->permissionShare->hide(); } + + loadAvatar(); +} + +void ShareUserLine::loadAvatar() +{ + /* Set the default place holder + * This is calculated the same way as on the webinterface + * So that the colors match + * + * This is done first so that we can directly show something + */ + + // Set size of the placeholder + _ui->avatar->setMinimumHeight(48); + _ui->avatar->setMinimumWidth(48); + _ui->avatar->setMaximumHeight(48); + _ui->avatar->setMaximumWidth(48); + _ui->avatar->setAlignment(Qt::AlignCenter); + + /* Calculate the hue + * We could use more digits but we have the MSB now which + * is already plenty + */ + const QString text = _share->getShareWith()->displayName(); + + QString seed = _share->getShareWith()->shareWith(); + if (_share->getShareWith()->type() != Sharee::User) { + seed += QString(" %1").arg(_share->getShareWith()->type()); + } + + const QByteArray hash = QCryptographicHash::hash(seed.toUtf8(), QCryptographicHash::Md5); + int hue = ((double)hash.mid(0, 3).toHex().toInt(0, 16) / (double)0xffffff) * 255; + + const QColor bg = QColor::fromHsl(hue, 230, 166); + const QString style = QString("* {\ + color: #fff;\ + background-color: %1;\ + border-radius: 24px;\ + font-size: 26px\ + }").arg(bg.name()); + + // Set the style + _ui->avatar->setStyleSheet(style); + + // Set the placeholder text + _ui->avatar->setText(text.at(0).toUpper()); + + // We can only fetch avatars for local users currently + if (_share->getShareWith()->type() == Sharee::User) { + AvatarJob2 *job = new AvatarJob2(_share->getShareWith()->shareWith(), 48, _share->account(), this); + connect(job, SIGNAL(avatarReady(QByteArray, QString)), SLOT(slotAvatarLoaded(QByteArray, QString))); + job->start(); + } +} + +void ShareUserLine::slotAvatarLoaded(const QByteArray &data, const QString &mimeType) +{ + QPixmap p; + bool valid = false; + if (mimeType == "image/png") { + valid = p.loadFromData(data, "PNG"); + } else if (mimeType == "image/jpeg") { + valid = p.loadFromData(data, "JPG"); + } else { + // Guess the filetype + valid = p.loadFromData(data); + } + + // If the image was loaded succesfully set it! + if (valid) { + + /* + * We want round avatars so create a new pixmap to draw + * the round avatar on and set a transparent background + */ + QPixmap avatar(p.width(), p.height()); + avatar.fill(QColor(0,0,0,0)); + + // Initialise our painer + QPainter painter(&avatar); + painter.setRenderHint(QPainter::Antialiasing); + + // Set to draw only a cricle + QPainterPath path; + path.addEllipse(0,0,p.width(),p.height()); + painter.setClipPath(path); + + // Draw the round avatar + painter.drawPixmap(0,0,p.width(),p.width(),p); + + // Set the avatar + _ui->avatar->setPixmap(avatar); + + // Remove the stylesheet + _ui->avatar->setStyleSheet(""); + } } void ShareUserLine::on_deleteShareButton_clicked() |