-
-
Notifications
You must be signed in to change notification settings - Fork 990
/
notifications.cpp
116 lines (89 loc) · 2.47 KB
/
notifications.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
Copyright (C) 2003 - 2014 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#include "notifications.hpp"
#include "global.hpp"
#include "game_preferences.hpp"
#include "gettext.hpp"
#include "sdl/compat.hpp"
#if SDL_VERSION_ATLEAST(2,0,0)
#include "video.hpp"
#else
#include "SDL_active.h"
#endif
#ifdef HAVE_LIBDBUS
#include "dbus_notification.hpp"
#endif
#ifdef HAVE_GROWL
#include "growl_notification.hpp"
#endif
#ifdef _WIN32
#include "windows_tray_notification.hpp"
#endif
namespace desktop {
namespace notifications
{
#if !(defined(HAVE_LIBDBUS) || defined(HAVE_GROWL) || defined(_WIN32))
bool available() { return false; }
void send(const std::string& /*owner*/, const std::string& /*message*/, type /*t*/)
{}
#else
bool available() { return true; }
void send(const std::string& owner, const std::string& message, type t)
{
if (preferences::get("disable_notifications", false)) { return; }
Uint8 app_state = SDL_GetAppState();
// Do not show notifications when the window is visible...
if ((app_state & SDL_APPACTIVE) != 0)
{
// ... and it has a focus.
if ((app_state & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) != 0) {
return;
}
}
#ifdef HAVE_LIBDBUS
dbus::send_notification(owner, message, t == CHAT);
#endif
#ifdef HAVE_GROWL
std::string note_name = "";
switch (t) {
case CHAT:
note_name = _("Chat Message");
break;
case TURN_CHANGED:
note_name = _("Turn Changed");
break;
case OTHER:
note_name = _("Wesnoth");
break;
}
growl::send_notification(owner, message, note_name);
#endif
#ifdef _WIN32
std::string notification_title;
std::string notification_message;
switch (t) {
case CHAT:
notification_title = _("Chat message");
notification_message = owner + ": " + message;
break;
case TURN_CHANGED:
case OTHER:
notification_title = owner;
notification_message = message;
break;
}
windows_tray_notification::show(notification_title, notification_message);
#endif
}
#endif //end #else !defined(NO_NOTIFICATIONS)
} //end namespace notifications
} //end namespace desktop