Switched to CamelCase convenction and deletion of activated notification

This commit is contained in:
jendas 2015-06-29 10:01:41 +02:00
parent 89b3b0ad3f
commit ada7a30dac
2 changed files with 16 additions and 22 deletions

View File

@ -30,7 +30,6 @@ class OSXNotificationCenter : public Snore::SnoreBackend
public: public:
OSXNotificationCenter(); OSXNotificationCenter();
~OSXNotificationCenter(); ~OSXNotificationCenter();
bool initialize() override;
public slots: public slots:
void slotNotify(Snore::Notification notification) override; void slotNotify(Snore::Notification notification) override;

View File

@ -12,8 +12,8 @@
using namespace Snore; using namespace Snore;
QMap<int, Notification> id_to_notification; QMap<int, Notification> m_IdToNotification;
NSMutableDictionary * id_to_nsnotification; NSMutableDictionary * m_IdToNSNotification;
void emitNotificationClicked(Notification notification) { void emitNotificationClicked(Notification notification) {
@ -39,15 +39,15 @@ void emitNotificationClicked(Notification notification) {
{ {
snoreDebug(SNORE_DEBUG) << "User clicked on notification"; snoreDebug(SNORE_DEBUG) << "User clicked on notification";
int notification_id = [notification.userInfo[@"id"] intValue]; int notificationId = [notification.userInfo[@"id"] intValue];
[center removeDeliveredNotification: notification]; [center removeDeliveredNotification: notification];
if (not id_to_notification.contains(notification_id)) { if (not m_IdToNotification.contains(notificationId)) {
snoreDebug(SNORE_WARNING) << "User clicked on notification that was not recognized"; snoreDebug(SNORE_WARNING) << "User clicked on notification that was not recognized";
return; return;
} }
Notification snore_notification = id_to_notification[notification_id]; auto snoreNotification = m_IdToNotification.take(notificationId);
snore_notification.data()->setCloseReason(Notification::ACTIVATED); snoreNotification.data()->setCloseReason(Notification::ACTIVATED);
emitNotificationClicked(snore_notification); emitNotificationClicked(snoreNotification);
} }
@end @end
@ -82,7 +82,7 @@ UserNotificationItemClass * delegate;
OSXNotificationCenter::OSXNotificationCenter() OSXNotificationCenter::OSXNotificationCenter()
{ {
id_to_nsnotification = [[[NSMutableDictionary alloc] init] autorelease]; m_IdToNSNotification = [[[NSMutableDictionary alloc] init] autorelease];
delegate = new UserNotificationItemClass(); delegate = new UserNotificationItemClass();
} }
@ -91,23 +91,18 @@ OSXNotificationCenter::~OSXNotificationCenter()
delete delegate; delete delegate;
} }
bool OSXNotificationCenter::initialize()
{
return SnoreBackend::initialize();
}
void OSXNotificationCenter::slotNotify(Snore::Notification notification) void OSXNotificationCenter::slotNotify(Snore::Notification notification)
{ {
NSUserNotification * osx_notification = [[[NSUserNotification alloc] init] autorelease]; NSUserNotification * osxNotification = [[[NSUserNotification alloc] init] autorelease];
NSString * notification_id = [NSString stringWithFormat:@"%d",notification.id()]; NSString * notificationId = [NSString stringWithFormat:@"%d",notification.id()];
osx_notification.title = NSStringFromQString(notification.title()); osxNotification.title = NSStringFromQString(notification.title());
osx_notification.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:notification_id, @"id", nil]; osxNotification.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:notificationId, @"id", nil];
osx_notification.informativeText = NSStringFromQString(notification.text()); osxNotification.informativeText = NSStringFromQString(notification.text());
// Add notification to mapper from id to Nofification / NSUserNotification // Add notification to mapper from id to Nofification / NSUserNotification
id_to_notification.insert(notification.id(), notification); m_IdToNotification.insert(notification.id(), notification);
[id_to_nsnotification setObject:osx_notification forKey: notification_id]; [m_IdToNSNotification setObject:osxNotification forKey: notificationId];
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: osx_notification]; [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: osxNotification];
slotNotificationDisplayed(notification); slotNotificationDisplayed(notification);
} }