|
|
@ -19,6 +19,35 @@ |
|
|
|
#include "Utils.h" |
|
|
|
#include "Utils.h" |
|
|
|
#include "jdenticoninterface.h" |
|
|
|
#include "jdenticoninterface.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Jdenticon { |
|
|
|
|
|
|
|
JdenticonInterface * |
|
|
|
|
|
|
|
getJdenticonInterface() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
static JdenticonInterface *interface = nullptr; |
|
|
|
|
|
|
|
static bool interfaceExists{true}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (interface == nullptr && interfaceExists) { |
|
|
|
|
|
|
|
QDir pluginsDir(qApp->applicationDirPath()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPluginLoader pluginLoader("qtjdenticon"); |
|
|
|
|
|
|
|
QObject *plugin = pluginLoader.instance(); |
|
|
|
|
|
|
|
if (plugin) { |
|
|
|
|
|
|
|
interface = qobject_cast<JdenticonInterface *>(plugin); |
|
|
|
|
|
|
|
if (interface) { |
|
|
|
|
|
|
|
nhlog::ui()->info("Loaded jdenticon plugin."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!interface) { |
|
|
|
|
|
|
|
nhlog::ui()->info("jdenticon plugin not found."); |
|
|
|
|
|
|
|
interfaceExists = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return interface; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static QPixmap |
|
|
|
static QPixmap |
|
|
|
clipRadius(QPixmap img, double radius) |
|
|
|
clipRadius(QPixmap img, double radius) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -39,6 +68,17 @@ clipRadius(QPixmap img, double radius) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
JdenticonResponse::JdenticonResponse(const QString &key, |
|
|
|
JdenticonResponse::JdenticonResponse(const QString &key, |
|
|
|
|
|
|
|
bool crop, |
|
|
|
|
|
|
|
double radius, |
|
|
|
|
|
|
|
const QSize &requestedSize, |
|
|
|
|
|
|
|
QThreadPool *pool) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto runnable = new JdenticonRunnable(key, crop, radius, requestedSize); |
|
|
|
|
|
|
|
connect(runnable, &JdenticonRunnable::done, this, &JdenticonResponse::handleDone); |
|
|
|
|
|
|
|
pool->start(runnable); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JdenticonRunnable::JdenticonRunnable(const QString &key, |
|
|
|
bool crop, |
|
|
|
bool crop, |
|
|
|
double radius, |
|
|
|
double radius, |
|
|
|
const QSize &requestedSize) |
|
|
|
const QSize &requestedSize) |
|
|
@ -46,25 +86,27 @@ JdenticonResponse::JdenticonResponse(const QString &key, |
|
|
|
, m_crop{crop} |
|
|
|
, m_crop{crop} |
|
|
|
, m_radius{radius} |
|
|
|
, m_radius{radius} |
|
|
|
, m_requestedSize(requestedSize.isValid() ? requestedSize : QSize(100, 100)) |
|
|
|
, m_requestedSize(requestedSize.isValid() ? requestedSize : QSize(100, 100)) |
|
|
|
, m_pixmap{m_requestedSize} |
|
|
|
{} |
|
|
|
, jdenticonInterface_{Jdenticon::getJdenticonInterface()} |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
setAutoDelete(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|
JdenticonResponse::run() |
|
|
|
JdenticonRunnable::run() |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_pixmap.fill(Qt::transparent); |
|
|
|
QPixmap pixmap(m_requestedSize); |
|
|
|
|
|
|
|
pixmap.fill(Qt::transparent); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto jdenticon = Jdenticon::getJdenticonInterface(); |
|
|
|
|
|
|
|
if (!jdenticon) { |
|
|
|
|
|
|
|
emit done(pixmap.toImage()); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QPainter painter; |
|
|
|
QPainter painter; |
|
|
|
painter.begin(&m_pixmap); |
|
|
|
painter.begin(&pixmap); |
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true); |
|
|
|
painter.setRenderHint(QPainter::Antialiasing, true); |
|
|
|
painter.setRenderHint(QPainter::SmoothPixmapTransform, true); |
|
|
|
painter.setRenderHint(QPainter::SmoothPixmapTransform, true); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
QSvgRenderer renderer{ |
|
|
|
QSvgRenderer renderer{jdenticon->generate(m_key, m_requestedSize.width()).toUtf8()}; |
|
|
|
jdenticonInterface_->generate(m_key, m_requestedSize.width()).toUtf8()}; |
|
|
|
|
|
|
|
renderer.render(&painter); |
|
|
|
renderer.render(&painter); |
|
|
|
} catch (std::exception &e) { |
|
|
|
} catch (std::exception &e) { |
|
|
|
nhlog::ui()->error( |
|
|
|
nhlog::ui()->error( |
|
|
@ -73,36 +115,13 @@ JdenticonResponse::run() |
|
|
|
|
|
|
|
|
|
|
|
painter.end(); |
|
|
|
painter.end(); |
|
|
|
|
|
|
|
|
|
|
|
m_pixmap = clipRadius(m_pixmap, m_radius); |
|
|
|
pixmap = clipRadius(pixmap, m_radius); |
|
|
|
|
|
|
|
|
|
|
|
emit finished(); |
|
|
|
emit done(pixmap.toImage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
namespace Jdenticon { |
|
|
|
bool |
|
|
|
JdenticonInterface * |
|
|
|
JdenticonProvider::isAvailable() |
|
|
|
getJdenticonInterface() |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
static JdenticonInterface *interface = nullptr; |
|
|
|
return Jdenticon::getJdenticonInterface() != nullptr; |
|
|
|
static bool interfaceExists{true}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (interface == nullptr && interfaceExists) { |
|
|
|
|
|
|
|
QDir pluginsDir(qApp->applicationDirPath()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPluginLoader pluginLoader("qtjdenticon"); |
|
|
|
|
|
|
|
QObject *plugin = pluginLoader.instance(); |
|
|
|
|
|
|
|
if (plugin) { |
|
|
|
|
|
|
|
interface = qobject_cast<JdenticonInterface *>(plugin); |
|
|
|
|
|
|
|
if (interface) { |
|
|
|
|
|
|
|
nhlog::ui()->info("Loaded jdenticon plugin."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!interface) { |
|
|
|
|
|
|
|
nhlog::ui()->info("jdenticon plugin not found."); |
|
|
|
|
|
|
|
interfaceExists = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return interface; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|