The Battle for Wesnoth
1.17.4+dev
desktop
notifications.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2003 - 2022
3
by David White <dave@whitevine.net>
4
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY.
12
13
See the COPYING file for more details.
14
*/
15
16
#include "
desktop/notifications.hpp
"
17
18
#include "
preferences/game.hpp
"
19
#include "
gettext.hpp
"
20
21
#include "
video.hpp
"
//CVideo::get_singleton().window_state()
22
23
#ifdef HAVE_LIBDBUS
24
#include "
desktop/dbus_features.hpp
"
25
#endif
26
27
#ifdef __APPLE__
28
#include "
desktop/apple_notification.hpp
"
29
#endif
30
31
#ifdef _WIN32
32
#include "
desktop/windows_tray_notification.hpp
"
33
#endif
34
35
namespace
desktop
{
36
37
namespace
notifications {
38
39
#if !(defined(HAVE_LIBDBUS) || defined(__APPLE__) || defined(_WIN32))
40
41
bool
available
() {
return
false
; }
42
43
void
send
(
const
std::string&
/*owner*/
,
const
std::string&
/*message*/
,
type
/*t*/
)
44
{}
45
46
#else
47
48
bool
available
()
49
{
50
#ifdef __APPLE__
51
return
apple_notifications::available
();
52
#else
53
return
true
;
54
#endif
55
}
56
57
void
send
(
const
std::string& owner,
const
std::string& message,
type
t
)
58
{
59
CVideo
& video =
CVideo::get_singleton
();
60
61
// Do not show notifications when the window is visible...
62
if
(video.
window_has_flags
(SDL_WINDOW_SHOWN)) {
63
// ... and it has a focus.
64
if
(video.
window_has_flags
(SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_FOCUS)) {
65
return
;
66
}
67
}
68
69
#ifdef HAVE_LIBDBUS
70
dbus::send_notification
(owner, message, t ==
CHAT
);
71
#endif
72
73
#ifdef __APPLE__
74
apple_notifications::send_notification
(owner, message, t);
75
#endif
76
77
#ifdef _WIN32
78
std::string notification_title;
79
std::string notification_message;
80
81
switch
(t) {
82
case
CHAT
:
83
notification_title =
_
(
"Chat message"
);
84
notification_message = owner +
": "
+ message;
85
break
;
86
case
TURN_CHANGED
:
87
case
OTHER
:
88
notification_title = owner;
89
notification_message = message;
90
break
;
91
}
92
93
windows_tray_notification::show
(notification_title, notification_message);
94
#endif
95
}
96
#endif //end #else (defined(HAVE_LIBDBUS) || defined(_WIN32))
97
98
}
//end namespace notifications
99
100
}
//end namespace desktop
gettext.hpp
desktop::notifications::OTHER
Definition:
notifications.hpp:24
CVideo
Definition:
video.hpp:36
desktop::notifications::CHAT
Definition:
notifications.hpp:24
desktop
Definition:
apple_battery_info.hpp:20
CVideo::get_singleton
static CVideo & get_singleton()
Definition:
video.hpp:53
_
static std::string _(const char *str)
Definition:
gettext.hpp:93
video.hpp
dbus::send_notification
void send_notification(const std::string &owner, const std::string &message, bool with_history)
Definition:
dbus_features.cpp:266
apple_notification.hpp
desktop::notifications::available
bool available()
Returns whether we were compiled with support for desktop notifications.
Definition:
notifications.cpp:41
apple_notifications::send_notification
void send_notification(const std::string &owner, const std::string &message, const desktop::notifications::type note_type)
desktop::notifications::send
void send(const std::string &, const std::string &, type)
Displays a desktop notification message, from owner, of type t.
Definition:
notifications.cpp:43
notifications.hpp
desktop::notifications::type
type
Definition:
notifications.hpp:24
apple_notifications::available
bool available()
Whether wesnoth was compiled with support for a clipboard.
Definition:
clipboard.cpp:55
dbus_features.hpp
t
double t
Definition:
astarsearch.cpp:65
windows_tray_notification::show
static bool show(std::string title, std::string message)
Displays a tray notification.
Definition:
windows_tray_notification.cpp:210
desktop::notifications::TURN_CHANGED
Definition:
notifications.hpp:24
game.hpp
CVideo::window_has_flags
bool window_has_flags(uint32_t flags) const
Tests whether the given flags are currently set on the SDL window.
Definition:
video.cpp:718
windows_tray_notification.hpp
Generated by
1.8.13