Allow compilers that don't support OS X 10.8 to compile notifications.

This commit is contained in:
Alarantalara 2014-12-13 09:45:17 -05:00
parent 533cf432be
commit c73215ecb9

View file

@ -14,8 +14,12 @@
#include "apple_notification.hpp" #include "apple_notification.hpp"
#if defined MAC_OS_X_VERSION_10_8 && (MAC_OS_X_VERSION_10_8 <= MAC_OS_X_VERSION_MAX_ALLOWED)
#define HAVE_NS_USER_NOTIFICATION
#endif
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#if HAVE_GROWL #ifdef HAVE_GROWL
#import "Growl/Growl.h" #import "Growl/Growl.h"
@interface WesnothGrowlDelegate : NSObject <GrowlApplicationBridgeDelegate> @interface WesnothGrowlDelegate : NSObject <GrowlApplicationBridgeDelegate>
@ -28,23 +32,36 @@
namespace apple_notifications { namespace apple_notifications {
#ifdef HAVE_NS_USER_NOTIFICATION
void send_cocoa_notification(const std::string& owner, const std::string& message); void send_cocoa_notification(const std::string& owner, const std::string& message);
#endif
#ifdef HAVE_GROWL
void send_growl_notification(const std::string& owner, const std::string& message, const std::string& note_name); void send_growl_notification(const std::string& owner, const std::string& message, const std::string& note_name);
#endif
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter" #pragma clang diagnostic ignored "-Wunused-parameter"
#ifdef HAVE_NS_USER_NOTIFICATION
void send_notification(const std::string& owner, const std::string& message, const std::string& note_name) { void send_notification(const std::string& owner, const std::string& message, const std::string& note_name) {
Class appleNotificationClass = NSClassFromString(@"NSUserNotificationCenter"); Class appleNotificationClass = NSClassFromString(@"NSUserNotificationCenter");
if (appleNotificationClass) { if (appleNotificationClass) {
send_cocoa_notification(owner, message); send_cocoa_notification(owner, message);
} else { } else {
#if HAVE_GROWL #ifdef HAVE_GROWL
send_growl_notification(owner, message, note_name); send_growl_notification(owner, message, note_name);
#endif #endif
} }
} }
#else
void send_notification(const std::string& owner, const std::string& message, const std::string& note_name) {
#ifdef HAVE_GROWL
send_growl_notification(owner, message, note_name);
#endif
}
#endif
#pragma clang diagnostic pop #pragma clang diagnostic pop
#ifdef HAVE_NS_USER_NOTIFICATION
void send_cocoa_notification(const std::string& owner, const std::string& message) { void send_cocoa_notification(const std::string& owner, const std::string& message) {
NSString *title = [NSString stringWithCString:owner.c_str() encoding:NSUTF8StringEncoding]; NSString *title = [NSString stringWithCString:owner.c_str() encoding:NSUTF8StringEncoding];
NSString *description = [NSString stringWithCString:message.c_str() encoding:NSUTF8StringEncoding]; NSString *description = [NSString stringWithCString:message.c_str() encoding:NSUTF8StringEncoding];
@ -55,8 +72,9 @@ void send_cocoa_notification(const std::string& owner, const std::string& messag
[[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification:notification]; [[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification:notification];
} }
#endif
#if HAVE_GROWL #ifdef HAVE_GROWL
void send_growl_notification(const std::string& owner, const std::string& message, const std::string& note_name) { void send_growl_notification(const std::string& owner, const std::string& message, const std::string& note_name) {
static WesnothGrowlDelegate *delegate = nil; static WesnothGrowlDelegate *delegate = nil;
if (!delegate) { if (!delegate) {