Fix Windows build

This commit is contained in:
Konstantinos Sideris 2018-07-14 16:27:51 +03:00
parent 888700743a
commit c4613b210e
4 changed files with 114 additions and 121 deletions

View File

@ -41,7 +41,7 @@ client();
void void
handle_to_device_messages(const std::vector<nlohmann::json> &msgs); handle_to_device_messages(const std::vector<nlohmann::json> &msgs);
boost::optional<json> nlohmann::json
try_olm_decryption(const std::string &sender_key, try_olm_decryption(const std::string &sender_key,
const mtx::events::msg::OlmCipherContent &content); const mtx::events::msg::OlmCipherContent &content);

View File

@ -90,9 +90,9 @@ handle_olm_message(const OlmMessage &msg)
auto payload = try_olm_decryption(msg.sender_key, cipher.second); auto payload = try_olm_decryption(msg.sender_key, cipher.second);
if (payload) { if (!payload.is_null()) {
nhlog::crypto()->info("decrypted olm payload: {}", payload.value().dump(2)); nhlog::crypto()->info("decrypted olm payload: {}", payload.dump(2));
create_inbound_megolm_session(msg.sender, msg.sender_key, payload.value()); create_inbound_megolm_session(msg.sender, msg.sender_key, payload);
return; return;
} }
@ -184,7 +184,7 @@ encrypt_group_message(const std::string &room_id,
return data; return data;
} }
boost::optional<json> nlohmann::json
try_olm_decryption(const std::string &sender_key, const mtx::events::msg::OlmCipherContent &msg) try_olm_decryption(const std::string &sender_key, const mtx::events::msg::OlmCipherContent &msg)
{ {
auto session_ids = cache::client()->getOlmSessions(sender_key); auto session_ids = cache::client()->getOlmSessions(sender_key);
@ -203,7 +203,6 @@ try_olm_decryption(const std::string &sender_key, const mtx::events::msg::OlmCip
try { try {
text = olm::client()->decrypt_message(session->get(), msg.type, msg.body); text = olm::client()->decrypt_message(session->get(), msg.type, msg.body);
cache::client()->saveOlmSession(id, std::move(session.value())); cache::client()->saveOlmSession(id, std::move(session.value()));
} catch (const olm_exception &e) { } catch (const olm_exception &e) {
nhlog::crypto()->info("failed to decrypt olm message ({}, {}) with {}: {}", nhlog::crypto()->info("failed to decrypt olm message ({}, {}) with {}: {}",
msg.type, msg.type,

View File

@ -1,50 +1,45 @@
#include "notifications/Manager.h" #include "notifications/Manager.h"
#include <QImage>
#include <QDebug> #include <QDebug>
#include <QImage>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusMessage> #include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusMetaType> #include <QtDBus/QDBusMetaType>
#include <QtDBus/QDBusConnection>
NotificationsManager::NotificationsManager(QObject *parent) : NotificationsManager::NotificationsManager(QObject *parent)
QObject(parent), : QObject(parent)
dbus( , dbus("org.freedesktop.Notifications",
"org.freedesktop.Notifications", "/org/freedesktop/Notifications",
"/org/freedesktop/Notifications", "org.freedesktop.Notifications",
"org.freedesktop.Notifications", QDBusConnection::sessionBus(),
QDBusConnection::sessionBus(), this)
this)
{ {
qDBusRegisterMetaType<QImage>(); qDBusRegisterMetaType<QImage>();
//connectSlot("ActionInvoked", SLOT(actionInvoked(uint, QString))); QDBusConnection::sessionBus().connect("org.freedesktop.Notifications",
//connectSlot("NotificationClosed", SLOT(notificationClosed(uint, uint))); "/org/freedesktop/Notifications",
QDBusConnection::sessionBus().connect( "org.freedesktop.Notifications",
"org.freedesktop.Notifications", "ActionInvoked",
"/org/freedesktop/Notifications", this,
"org.freedesktop.Notifications", SLOT(actionInvoked(uint, QString)));
"ActionInvoked", QDBusConnection::sessionBus().connect("org.freedesktop.Notifications",
this, "/org/freedesktop/Notifications",
SLOT(actionInvoked(uint, QString))); "org.freedesktop.Notifications",
QDBusConnection::sessionBus().connect( "NotificationClosed",
"org.freedesktop.Notifications", this,
"/org/freedesktop/Notifications", SLOT(notificationClosed(uint, uint)));
"org.freedesktop.Notifications",
"NotificationClosed",
this,
SLOT(notificationClosed(uint, uint)));
} }
void void
NotificationsManager::postNotification(const QString &roomid, NotificationsManager::postNotification(const QString &roomid,
const QString &eventid, const QString &eventid,
const QString &roomname, const QString &roomname,
const QString &sender, const QString &sender,
const QString &text, const QString &text,
const QImage &icon) const QImage &icon)
{ {
uint id = showNotification(roomname, sender+": "+text, icon); uint id = showNotification(roomname, sender + ": " + text, icon);
notificationIds[id] = roomEventId{roomid,eventid}; notificationIds[id] = roomEventId{roomid, eventid};
} }
/** /**
* This function is based on code from * This function is based on code from
@ -53,33 +48,32 @@ NotificationsManager::postNotification(const QString &roomid,
* Licensed under the GNU General Public License, version 3 * Licensed under the GNU General Public License, version 3
*/ */
uint uint
NotificationsManager::showNotification(const QString summary, const QString text, const QImage image) NotificationsManager::showNotification(const QString summary,
const QString text,
const QImage image)
{ {
QVariantMap hints; QVariantMap hints;
hints["image_data"] = image; hints["image_data"] = image;
QList<QVariant> argumentList; QList<QVariant> argumentList;
argumentList << "nheko"; //app_name argumentList << "nheko"; // app_name
argumentList << (uint)0; // replace_id argumentList << (uint)0; // replace_id
argumentList << ""; // app_icon argumentList << ""; // app_icon
argumentList << summary; // summary argumentList << summary; // summary
argumentList << text; // body argumentList << text; // body
argumentList << (QStringList("default")<<"reply"); // actions argumentList << (QStringList("default") << "reply"); // actions
argumentList << hints; // hints argumentList << hints; // hints
argumentList << (int)0; // timeout in ms argumentList << (int)0; // timeout in ms
static QDBusInterface notifyApp( static QDBusInterface notifyApp("org.freedesktop.Notifications",
"org.freedesktop.Notifications", "/org/freedesktop/Notifications",
"/org/freedesktop/Notifications", "org.freedesktop.Notifications");
"org.freedesktop.Notifications"); QDBusMessage reply =
QDBusMessage reply = notifyApp.callWithArgumentList( notifyApp.callWithArgumentList(QDBus::AutoDetect, "Notify", argumentList);
QDBus::AutoDetect, if (reply.type() == QDBusMessage::ErrorMessage) {
"Notify", qDebug() << "D-Bus Error:" << reply.errorMessage();
argumentList); return 0;
if(reply.type() == QDBusMessage::ErrorMessage) {
qDebug() << "D-Bus Error:" << reply.errorMessage();
return 0;
} else { } else {
return reply.arguments().first().toUInt(); return reply.arguments().first().toUInt();
} }
return true; return true;
} }
@ -109,50 +103,54 @@ NotificationsManager::notificationClosed(uint id, uint reason)
* *
* Copyright 2010, David Sansome <me@davidsansome.com> * Copyright 2010, David Sansome <me@davidsansome.com>
*/ */
QDBusArgument& operator<<(QDBusArgument& arg, const QImage& image) { QDBusArgument &
if(image.isNull()) { operator<<(QDBusArgument &arg, const QImage &image)
arg.beginStructure(); {
arg << 0 << 0 << 0 << false << 0 << 0 << QByteArray(); if (image.isNull()) {
arg.endStructure(); arg.beginStructure();
return arg; arg << 0 << 0 << 0 << false << 0 << 0 << QByteArray();
} arg.endStructure();
return arg;
}
QImage scaled = image.scaledToHeight(100, Qt::SmoothTransformation); QImage scaled = image.scaledToHeight(100, Qt::SmoothTransformation);
scaled = scaled.convertToFormat(QImage::Format_ARGB32); scaled = scaled.convertToFormat(QImage::Format_ARGB32);
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
// ABGR -> ARGB // ABGR -> ARGB
QImage i = scaled.rgbSwapped(); QImage i = scaled.rgbSwapped();
#else #else
// ABGR -> GBAR // ABGR -> GBAR
QImage i(scaled.size(), scaled.format()); QImage i(scaled.size(), scaled.format());
for (int y = 0; y < i.height(); ++y) { for (int y = 0; y < i.height(); ++y) {
QRgb* p = (QRgb*) scaled.scanLine(y); QRgb *p = (QRgb *)scaled.scanLine(y);
QRgb* q = (QRgb*) i.scanLine(y); QRgb *q = (QRgb *)i.scanLine(y);
QRgb* end = p + scaled.width(); QRgb *end = p + scaled.width();
while (p < end) { while (p < end) {
*q = qRgba(qGreen(*p), qBlue(*p), qAlpha(*p), qRed(*p)); *q = qRgba(qGreen(*p), qBlue(*p), qAlpha(*p), qRed(*p));
p++; p++;
q++; q++;
} }
} }
#endif #endif
arg.beginStructure(); arg.beginStructure();
arg << i.width(); arg << i.width();
arg << i.height(); arg << i.height();
arg << i.bytesPerLine(); arg << i.bytesPerLine();
arg << i.hasAlphaChannel(); arg << i.hasAlphaChannel();
int channels = i.isGrayscale() ? 1 : (i.hasAlphaChannel() ? 4 : 3); int channels = i.isGrayscale() ? 1 : (i.hasAlphaChannel() ? 4 : 3);
arg << i.depth() / channels; arg << i.depth() / channels;
arg << channels; arg << channels;
arg << QByteArray(reinterpret_cast<const char*>(i.bits()), i.byteCount()); arg << QByteArray(reinterpret_cast<const char *>(i.bits()), i.byteCount());
arg.endStructure(); arg.endStructure();
return arg; return arg;
} }
const QDBusArgument& operator>>(const QDBusArgument& arg, QImage&) { const QDBusArgument &
// This is needed to link but shouldn't be called. operator>>(const QDBusArgument &arg, QImage &)
Q_ASSERT(0); {
return arg; // This is needed to link but shouldn't be called.
Q_ASSERT(0);
return arg;
} }

View File

@ -27,43 +27,39 @@ init()
} }
} }
NotificationsManager::NotificationsManager(QObject *parent): QObject(parent) NotificationsManager::NotificationsManager(QObject *parent)
{ : QObject(parent)
{}
}
void void
NotificationsManager::postNotification(const QString &, //roomid NotificationsManager::postNotification(const QString &room_id,
const QString &, //eventid const QString &event_id,
const QString &roomname, const QString &room_name,
const QString &sender, const QString &sender,
const QString &text, const QString &text,
const QImage &) //icon const QImage &icon)
{ {
Q_UNUSED(room_id)
Q_UNUSED(event_id)
Q_UNUSED(icon)
if (!isInitialized) if (!isInitialized)
init(); init();
auto templ = WinToastTemplate(WinToastTemplate::ImageAndText02); auto templ = WinToastTemplate(WinToastTemplate::ImageAndText02);
if (roomname != sender) if (room_name != sender)
templ.setTextField(QString("%1 - %2").arg(sender).arg(roomname).toStdWString(), templ.setTextField(QString("%1 - %2").arg(sender).arg(room_name).toStdWString(),
WinToastTemplate::FirstLine); WinToastTemplate::FirstLine);
else else
templ.setTextField(QString("%1").arg(user).toStdWString(), templ.setTextField(QString("%1").arg(sender).toStdWString(),
WinToastTemplate::FirstLine); WinToastTemplate::FirstLine);
templ.setTextField(QString("%1").arg(msg).toStdWString(), WinToastTemplate::SecondLine); templ.setTextField(QString("%1").arg(text).toStdWString(), WinToastTemplate::SecondLine);
// TODO: implement room or user avatar // TODO: implement room or user avatar
// templ.setImagePath(L"C:/example.png"); // templ.setImagePath(L"C:/example.png");
WinToast::instance()->showToast(templ, new CustomHandler()); WinToast::instance()->showToast(templ, new CustomHandler());
} }
//unused void NotificationsManager::actionInvoked(uint, QString) {}
void
NotificationsManager::actionInvoked(uint, QString)
{
}
void void NotificationsManager::notificationClosed(uint, uint) {}
NotificationsManager::notificationClosed(uint, uint)
{
}