Commit fe545486 authored by kaniini's avatar kaniini

notifications: add mac support

parent 76d24965
......@@ -64,3 +64,8 @@ ICON = Michabo.icns
unix:!macx {
QT += dbus
}
macx {
SOURCES += ui/notificationimpl_osx.mm
LIBS += -framework Foundation -framework AppKit
}
#include "notificationimpl.h"
#include <QCoreApplication>
#include <QTextDocument>
NotificationImpl::NotificationImpl(QObject *parent) : QObject(parent)
{
......@@ -146,6 +147,24 @@ void NotificationImpl::showNotification(Michabo::Account *a, std::shared_ptr<Mic
-1);
}
#elif defined(Q_OS_MAC)
extern void show_notification_osx (QString &topic, QString &message, QImage &avatar);
void NotificationImpl::showNotification(Michabo::Account *, std::shared_ptr<Michabo::Notification> n)
{
// prepare our message
QString action = notification_action (n->m_type);
QString message = notification_message (n);
QString topic = QString ("%1 %2 (%3)").arg(n->m_identity->m_display_name, action, qApp->applicationName ());
QTextDocument doc;
doc.setHtml (message);
message = doc.toPlainText ();
show_notification_osx (topic, message, n->m_identity->m_avatar);
}
#else
void NotificationImpl::showNotification(Michabo::Account *, std::shared_ptr<Michabo::Notification>)
......
#include "notificationimpl.h"
#include <AppKit/AppKit.h>
#include <Foundation/Foundation.h>
void show_notification_osx (QString &topic, QString &message, QImage &avatar)
{
qDebug() << "delivering notification";
NSUserNotification *notification = [[[NSUserNotification alloc] init] autorelease];
notification.title = topic.toNSString ();
notification.informativeText = message.toNSString ();
CGImageRef cg_img = avatar.toCGImage ();
CGSize cg_size = avatar.size ().toCGSize ();
NSImage *img = [[[NSImage alloc] initWithCGImage:cg_img size:cg_size] autorelease];
notification.contentImage = img;
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: notification];
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment