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,15 +1,14 @@
#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(),
@ -17,17 +16,13 @@ NotificationsManager::NotificationsManager(QObject *parent) :
{ {
qDBusRegisterMetaType<QImage>(); qDBusRegisterMetaType<QImage>();
//connectSlot("ActionInvoked", SLOT(actionInvoked(uint, QString))); QDBusConnection::sessionBus().connect("org.freedesktop.Notifications",
//connectSlot("NotificationClosed", SLOT(notificationClosed(uint, uint)));
QDBusConnection::sessionBus().connect(
"org.freedesktop.Notifications",
"/org/freedesktop/Notifications", "/org/freedesktop/Notifications",
"org.freedesktop.Notifications", "org.freedesktop.Notifications",
"ActionInvoked", "ActionInvoked",
this, this,
SLOT(actionInvoked(uint, QString))); SLOT(actionInvoked(uint, QString)));
QDBusConnection::sessionBus().connect( QDBusConnection::sessionBus().connect("org.freedesktop.Notifications",
"org.freedesktop.Notifications",
"/org/freedesktop/Notifications", "/org/freedesktop/Notifications",
"org.freedesktop.Notifications", "org.freedesktop.Notifications",
"NotificationClosed", "NotificationClosed",
@ -43,8 +38,8 @@ NotificationsManager::postNotification(const QString &roomid,
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,29 +48,28 @@ 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 = notifyApp.callWithArgumentList( QDBusMessage reply =
QDBus::AutoDetect, notifyApp.callWithArgumentList(QDBus::AutoDetect, "Notify", argumentList);
"Notify", if (reply.type() == QDBusMessage::ErrorMessage) {
argumentList);
if(reply.type() == QDBusMessage::ErrorMessage) {
qDebug() << "D-Bus Error:" << reply.errorMessage(); qDebug() << "D-Bus Error:" << reply.errorMessage();
return 0; return 0;
} else { } else {
@ -109,8 +103,10 @@ 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)
{
if (image.isNull()) {
arg.beginStructure(); arg.beginStructure();
arg << 0 << 0 << 0 << false << 0 << 0 << QByteArray(); arg << 0 << 0 << 0 << false << 0 << 0 << QByteArray();
arg.endStructure(); arg.endStructure();
@ -127,9 +123,9 @@ QDBusArgument& operator<<(QDBusArgument& arg, const QImage& image) {
// 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++;
@ -146,12 +142,14 @@ QDBusArgument& operator<<(QDBusArgument& arg, const QImage& image) {
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 &
operator>>(const QDBusArgument &arg, QImage &)
{
// This is needed to link but shouldn't be called. // This is needed to link but shouldn't be called.
Q_ASSERT(0); Q_ASSERT(0);
return arg; 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)
{
}