The Battle for Wesnoth  1.15.0-dev
apple_notification.mm
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by Google Inc.
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifdef __APPLE__
16 
18 
19 #import <Foundation/Foundation.h>
20 
21 namespace apple_notifications {
22 
23 bool available() {
24  Class notificationClass = NSClassFromString(@"NSUserNotificationCenter");
25  if(notificationClass) {
26  return true;
27  }
28  return false;
29 }
30 
31 void send_cocoa_notification(const std::string& owner, const std::string& message);
32 
33 #pragma clang diagnostic push
34 #pragma clang diagnostic ignored "-Wunused-parameter"
35 void send_notification(const std::string& owner, const std::string& message, const desktop::notifications::type note_type) {
36  @autoreleasepool {
37  Class appleNotificationClass = NSClassFromString(@"NSUserNotificationCenter");
38  if (appleNotificationClass) {
39  send_cocoa_notification(owner, message);
40  }
41  }
42 }
43 #pragma clang diagnostic pop
44 
45 void send_cocoa_notification(const std::string& owner, const std::string& message) {
46  NSString *title = [NSString stringWithCString:owner.c_str() encoding:NSUTF8StringEncoding];
47  NSString *description = [NSString stringWithCString:message.c_str() encoding:NSUTF8StringEncoding];
48  NSUserNotification *notification = [[NSUserNotification alloc] init];
49  notification.title = title;
50  notification.informativeText = description;
51  notification.deliveryDate = [NSDate date];
52 
53  [[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification:notification];
54 }
55 
56 }
57 #endif //end __APPLE__
struct utils::detail::formula_initer init
void send_notification(const std::string &owner, const std::string &message, const desktop::notifications::type note_type)
bool available()
Whether wesnoth was compiled with support for a clipboard.
Definition: clipboard.cpp:56