The Battle for Wesnoth
1.19.5+dev
desktop
notifications.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2003 - 2024
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 "
gettext.hpp
"
19
20
#include "
video.hpp
"
// window_has_flags()
21
22
#ifdef HAVE_LIBDBUS
23
#include "
desktop/dbus_features.hpp
"
24
#endif
25
26
#ifdef __APPLE__
27
#include "
desktop/apple_notification.hpp
"
28
#endif
29
30
#ifdef _WIN32
31
#include "
desktop/windows_tray_notification.hpp
"
32
#endif
33
34
namespace
desktop
{
35
36
namespace
notifications {
37
38
#if !(defined(HAVE_LIBDBUS) || defined(__APPLE__) || defined(_WIN32))
39
40
bool
available
() {
return
false
; }
41
42
void
send
(
const
std::string&
/*owner*/
,
const
std::string&
/*message*/
,
type
/*t*/
)
43
{}
44
45
#else
46
47
bool
available
()
48
{
49
#ifdef __APPLE__
50
return
apple_notifications::available
();
51
#else
52
return
true
;
53
#endif
54
}
55
56
void
send
(
const
std::string& owner,
const
std::string& message,
type
t
)
57
{
58
// Do not show notifications when the window is visible and has focus
59
if
(
video::window_is_visible
() &&
video::window_has_focus
()) {
60
return
;
61
}
62
63
#ifdef HAVE_LIBDBUS
64
dbus::send_notification
(owner, message,
t
==
CHAT
);
65
#endif
66
67
#ifdef __APPLE__
68
apple_notifications::send_notification
(owner, message,
t
);
69
#endif
70
71
#ifdef _WIN32
72
std::string notification_title;
73
std::string notification_message;
74
75
switch
(
t
) {
76
case
CHAT
:
77
notification_title =
_
(
"Chat message"
);
78
notification_message = owner +
": "
+
message
;
79
break
;
80
case
TURN_CHANGED
:
81
case
OTHER
:
82
notification_title = owner;
83
notification_message =
message
;
84
break
;
85
}
86
87
windows_tray_notification::show
(notification_title, notification_message);
88
#endif
89
}
90
#endif
//end #else (defined(HAVE_LIBDBUS) || defined(_WIN32))
91
92
}
//end namespace notifications
93
94
}
//end namespace desktop
apple_notification.hpp
t
double t
Definition:
astarsearch.cpp:63
windows_tray_notification::show
static bool show(std::string title, std::string message)
Displays a tray notification.
Definition:
windows_tray_notification.cpp:210
dbus_features.hpp
gettext.hpp
_
static std::string _(const char *str)
Definition:
gettext.hpp:93
apple_notifications::send_notification
void send_notification(const std::string &owner, const std::string &message, const desktop::notifications::type note_type)
apple_notifications::available
bool available()
dbus::send_notification
void send_notification(const std::string &owner, const std::string &message, bool with_history)
Definition:
dbus_features.cpp:266
desktop::notifications::available
bool available()
Returns whether we were compiled with support for desktop notifications.
Definition:
notifications.cpp:40
desktop::notifications::type
type
Definition:
notifications.hpp:24
desktop::notifications::CHAT
@ CHAT
Definition:
notifications.hpp:24
desktop::notifications::TURN_CHANGED
@ TURN_CHANGED
Definition:
notifications.hpp:24
desktop::notifications::OTHER
@ OTHER
Definition:
notifications.hpp:24
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:42
desktop
Definition:
apple_battery_info.hpp:20
mp::notify_mode::message
@ message
video::window_is_visible
bool window_is_visible()
True iff the window is not hidden.
Definition:
video.cpp:691
video::window_has_focus
bool window_has_focus()
True iff the window has mouse or input focus.
Definition:
video.cpp:696
notifications.hpp
video.hpp
windows_tray_notification.hpp
Generated by
1.9.1