summaryrefslogtreecommitdiffstats
path: root/src/notifications
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-07-14 16:27:51 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-07-14 16:27:51 +0300
commitc4613b210ee6003be91b7e21a44ef1a918f96657 (patch)
tree6f71ee0cd9fa2fae0748c73e728e2a763c45bda9 /src/notifications
parent888700743a5bb1147929a4921fa418212c90c3c1 (diff)
Fix Windows build
Diffstat (limited to 'src/notifications')
-rw-r--r--src/notifications/ManagerLinux.cpp182
-rw-r--r--src/notifications/ManagerWin.cpp42
2 files changed, 109 insertions, 115 deletions
diff --git a/src/notifications/ManagerLinux.cpp b/src/notifications/ManagerLinux.cpp
index 80fdb9d8..34bfeb8a 100644
--- a/src/notifications/ManagerLinux.cpp
+++ b/src/notifications/ManagerLinux.cpp
@@ -1,50 +1,45 @@
#include "notifications/Manager.h"
-#include <QImage>
#include <QDebug>
+#include <QImage>
+#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusMetaType>
-#include <QtDBus/QDBusConnection>
-NotificationsManager::NotificationsManager(QObject *parent) :
- QObject(parent),
- dbus(
- "org.freedesktop.Notifications",
- "/org/freedesktop/Notifications",
- "org.freedesktop.Notifications",
- QDBusConnection::sessionBus(),
- this)
+NotificationsManager::NotificationsManager(QObject *parent)
+ : QObject(parent)
+ , dbus("org.freedesktop.Notifications",
+ "/org/freedesktop/Notifications",
+ "org.freedesktop.Notifications",
+ QDBusConnection::sessionBus(),
+ this)
{
qDBusRegisterMetaType<QImage>();
- //connectSlot("ActionInvoked", SLOT(actionInvoked(uint, QString)));
- //connectSlot("NotificationClosed", SLOT(notificationClosed(uint, uint)));
- QDBusConnection::sessionBus().connect(
- "org.freedesktop.Notifications",
- "/org/freedesktop/Notifications",
- "org.freedesktop.Notifications",
- "ActionInvoked",
- this,
- SLOT(actionInvoked(uint, QString)));
- QDBusConnection::sessionBus().connect(
- "org.freedesktop.Notifications",
- "/org/freedesktop/Notifications",
- "org.freedesktop.Notifications",
- "NotificationClosed",
- this,
- SLOT(notificationClosed(uint, uint)));
+ QDBusConnection::sessionBus().connect("org.freedesktop.Notifications",
+ "/org/freedesktop/Notifications",
+ "org.freedesktop.Notifications",
+ "ActionInvoked",
+ this,
+ SLOT(actionInvoked(uint, QString)));
+ QDBusConnection::sessionBus().connect("org.freedesktop.Notifications",
+ "/org/freedesktop/Notifications",
+ "org.freedesktop.Notifications",
+ "NotificationClosed",
+ this,
+ SLOT(notificationClosed(uint, uint)));
}
void
NotificationsManager::postNotification(const QString &roomid,
- const QString &eventid,
- const QString &roomname,
- const QString &sender,
- const QString &text,
- const QImage &icon)
+ const QString &eventid,
+ const QString &roomname,
+ const QString &sender,
+ const QString &text,
+ const QImage &icon)
{
- uint id = showNotification(roomname, sender+": "+text, icon);
- notificationIds[id] = roomEventId{roomid,eventid};
+ uint id = showNotification(roomname, sender + ": " + text, icon);
+ notificationIds[id] = roomEventId{roomid, eventid};
}
/**
* 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
*/
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;
hints["image_data"] = image;
QList<QVariant> argumentList;
- argumentList << "nheko"; //app_name
- argumentList << (uint)0; // replace_id
- argumentList << ""; // app_icon
- argumentList << summary; // summary
- argumentList << text; // body
- argumentList << (QStringList("default")<<"reply"); // actions
- argumentList << hints; // hints
- argumentList << (int)0; // timeout in ms
+ argumentList << "nheko"; // app_name
+ argumentList << (uint)0; // replace_id
+ argumentList << ""; // app_icon
+ argumentList << summary; // summary
+ argumentList << text; // body
+ argumentList << (QStringList("default") << "reply"); // actions
+ argumentList << hints; // hints
+ argumentList << (int)0; // timeout in ms
- static QDBusInterface notifyApp(
- "org.freedesktop.Notifications",
- "/org/freedesktop/Notifications",
- "org.freedesktop.Notifications");
- QDBusMessage reply = notifyApp.callWithArgumentList(
- QDBus::AutoDetect,
- "Notify",
- argumentList);
- if(reply.type() == QDBusMessage::ErrorMessage) {
- qDebug() << "D-Bus Error:" << reply.errorMessage();
- return 0;
+ static QDBusInterface notifyApp("org.freedesktop.Notifications",
+ "/org/freedesktop/Notifications",
+ "org.freedesktop.Notifications");
+ QDBusMessage reply =
+ notifyApp.callWithArgumentList(QDBus::AutoDetect, "Notify", argumentList);
+ if (reply.type() == QDBusMessage::ErrorMessage) {
+ qDebug() << "D-Bus Error:" << reply.errorMessage();
+ return 0;
} else {
- return reply.arguments().first().toUInt();
+ return reply.arguments().first().toUInt();
}
return true;
}
@@ -109,50 +103,54 @@ NotificationsManager::notificationClosed(uint id, uint reason)
*
* Copyright 2010, David Sansome <me@davidsansome.com>
*/
-QDBusArgument& operator<<(QDBusArgument& arg, const QImage& image) {
- if(image.isNull()) {
- arg.beginStructure();
- arg << 0 << 0 << 0 << false << 0 << 0 << QByteArray();
- arg.endStructure();
- return arg;
- }
+QDBusArgument &
+operator<<(QDBusArgument &arg, const QImage &image)
+{
+ if (image.isNull()) {
+ arg.beginStructure();
+ arg << 0 << 0 << 0 << false << 0 << 0 << QByteArray();
+ arg.endStructure();
+ return arg;
+ }
- QImage scaled = image.scaledToHeight(100, Qt::SmoothTransformation);
- scaled = scaled.convertToFormat(QImage::Format_ARGB32);
+ QImage scaled = image.scaledToHeight(100, Qt::SmoothTransformation);
+ scaled = scaled.convertToFormat(QImage::Format_ARGB32);
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
- // ABGR -> ARGB
- QImage i = scaled.rgbSwapped();
+ // ABGR -> ARGB
+ QImage i = scaled.rgbSwapped();
#else
- // ABGR -> GBAR
- QImage i(scaled.size(), scaled.format());
- for (int y = 0; y < i.height(); ++y) {
- QRgb* p = (QRgb*) scaled.scanLine(y);
- QRgb* q = (QRgb*) i.scanLine(y);
- QRgb* end = p + scaled.width();
- while (p < end) {
- *q = qRgba(qGreen(*p), qBlue(*p), qAlpha(*p), qRed(*p));
- p++;
- q++;
- }
- }
+ // ABGR -> GBAR
+ QImage i(scaled.size(), scaled.format());
+ for (int y = 0; y < i.height(); ++y) {
+ QRgb *p = (QRgb *)scaled.scanLine(y);
+ QRgb *q = (QRgb *)i.scanLine(y);
+ QRgb *end = p + scaled.width();
+ while (p < end) {
+ *q = qRgba(qGreen(*p), qBlue(*p), qAlpha(*p), qRed(*p));
+ p++;
+ q++;
+ }
+ }
#endif
- arg.beginStructure();
- arg << i.width();
- arg << i.height();
- arg << i.bytesPerLine();
- arg << i.hasAlphaChannel();
- int channels = i.isGrayscale() ? 1 : (i.hasAlphaChannel() ? 4 : 3);
- arg << i.depth() / channels;
- arg << channels;
- arg << QByteArray(reinterpret_cast<const char*>(i.bits()), i.byteCount());
- arg.endStructure();
- return arg;
+ arg.beginStructure();
+ arg << i.width();
+ arg << i.height();
+ arg << i.bytesPerLine();
+ arg << i.hasAlphaChannel();
+ int channels = i.isGrayscale() ? 1 : (i.hasAlphaChannel() ? 4 : 3);
+ arg << i.depth() / channels;
+ arg << channels;
+ arg << QByteArray(reinterpret_cast<const char *>(i.bits()), i.byteCount());
+ arg.endStructure();
+ return arg;
}
-const QDBusArgument& operator>>(const QDBusArgument& arg, QImage&) {
- // This is needed to link but shouldn't be called.
- Q_ASSERT(0);
- return arg;
+const QDBusArgument &
+operator>>(const QDBusArgument &arg, QImage &)
+{
+ // This is needed to link but shouldn't be called.
+ Q_ASSERT(0);
+ return arg;
}
diff --git a/src/notifications/ManagerWin.cpp b/src/notifications/ManagerWin.cpp
index 90367d9a..9cc4da9b 100644
--- a/src/notifications/ManagerWin.cpp
+++ b/src/notifications/ManagerWin.cpp
@@ -27,43 +27,39 @@ init()
}
}
-NotificationsManager::NotificationsManager(QObject *parent): QObject(parent)
-{
-
-}
+NotificationsManager::NotificationsManager(QObject *parent)
+ : QObject(parent)
+{}
void
-NotificationsManager::postNotification(const QString &, //roomid
- const QString &, //eventid
- const QString &roomname,
- const QString &sender,
- const QString &text,
- const QImage &) //icon
+NotificationsManager::postNotification(const QString &room_id,
+ const QString &event_id,
+ const QString &room_name,
+ const QString &sender,
+ const QString &text,
+ const QImage &icon)
{
+ Q_UNUSED(room_id)
+ Q_UNUSED(event_id)
+ Q_UNUSED(icon)
+
if (!isInitialized)
init();
auto templ = WinToastTemplate(WinToastTemplate::ImageAndText02);
- if (roomname != sender)
- templ.setTextField(QString("%1 - %2").arg(sender).arg(roomname).toStdWString(),
+ if (room_name != sender)
+ templ.setTextField(QString("%1 - %2").arg(sender).arg(room_name).toStdWString(),
WinToastTemplate::FirstLine);
else
- templ.setTextField(QString("%1").arg(user).toStdWString(),
+ templ.setTextField(QString("%1").arg(sender).toStdWString(),
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
// templ.setImagePath(L"C:/example.png");
WinToast::instance()->showToast(templ, new CustomHandler());
}
-//unused
-void
-NotificationsManager::actionInvoked(uint, QString)
-{
-}
+void NotificationsManager::actionInvoked(uint, QString) {}
-void
-NotificationsManager::notificationClosed(uint, uint)
-{
-}
+void NotificationsManager::notificationClosed(uint, uint) {}