diff options
author | Loren Burkholder <computersemiexpert@outlook.com> | 2020-12-25 09:14:00 -0500 |
---|---|---|
committer | Loren Burkholder <computersemiexpert@outlook.com> | 2021-09-11 19:35:31 -0400 |
commit | d2e193ff78c491f7108476b00340aea97f4feed3 (patch) | |
tree | 18fe17ffd6f1ad667b54fbc09d424658b25fb54c /src/JdenticonProvider.cpp | |
parent | Merge pull request #722 from Thulinma/noHtmlFixes (diff) | |
download | nheko-d2e193ff78c491f7108476b00340aea97f4feed3.tar.xz |
Add jdenticon support
Diffstat (limited to 'src/JdenticonProvider.cpp')
-rw-r--r-- | src/JdenticonProvider.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/JdenticonProvider.cpp b/src/JdenticonProvider.cpp new file mode 100644 index 00000000..4be972dc --- /dev/null +++ b/src/JdenticonProvider.cpp @@ -0,0 +1,68 @@ +#include "JdenticonProvider.h" + +#include <QApplication> +#include <QDir> +#include <QPainter> +#include <QPluginLoader> +#include <QSvgRenderer> + +#include <mtxclient/crypto/client.hpp> + +#include "Cache.h" +#include "Logging.h" +#include "MatrixClient.h" +#include "Utils.h" +#include "jdenticoninterface.h" + +JdenticonResponse::JdenticonResponse(const QString &key, const QSize &requestedSize) + : m_key(key) + , m_requestedSize(requestedSize.isValid() ? requestedSize : QSize(100, 100)) + , m_pixmap{m_requestedSize} + , jdenticonInterface_{Jdenticon::getJdenticonInterface()} +{ + setAutoDelete(false); +} + +void +JdenticonResponse::run() +{ + m_pixmap.fill(Qt::transparent); + QPainter painter{&m_pixmap}; + QSvgRenderer renderer{ + jdenticonInterface_->generate(m_key, m_requestedSize.width()).toUtf8()}; + // m_image = QImage::fromData(jdenticonInterface_->generate(m_key, + // size->width()).toUtf8()); + renderer.render(&painter); + + emit finished(); +} + +namespace Jdenticon { +JdenticonInterface * +getJdenticonInterface() +{ + static JdenticonInterface *interface = nullptr; + + if (interface == nullptr) { + QDir pluginsDir(qApp->applicationDirPath()); + + bool plugins = pluginsDir.cd("plugins"); + if (plugins) { + for (QString fileName : pluginsDir.entryList(QDir::Files)) { + QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName)); + QObject *plugin = pluginLoader.instance(); + if (plugin) { + interface = qobject_cast<JdenticonInterface *>(plugin); + if (interface) { + nhlog::ui()->info("Loaded jdenticon plugin."); + break; + } + } + } + } else + nhlog::ui()->info("jdenticon plugin not found."); + } + + return interface; +} +} |