The Battle for Wesnoth  1.17.12+dev
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 
17 
18 #include "preferences/game.hpp"
19 #include "gettext.hpp"
20 
21 #include "video.hpp" // window_has_flags()
22 
23 #ifdef HAVE_LIBDBUS
25 #endif
26 
27 #ifdef __APPLE__
29 #endif
30 
31 #ifdef _WIN32
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__
52 #else
53  return true;
54 #endif
55 }
56 
57 void send(const std::string& owner, const std::string& message, type t)
58 {
59  // Do not show notifications when the window is visible and has focus
61  return;
62  }
63 
64 #ifdef HAVE_LIBDBUS
65  dbus::send_notification(owner, message, t == CHAT);
66 #endif
67 
68 #ifdef __APPLE__
69  apple_notifications::send_notification(owner, message, t);
70 #endif
71 
72 #ifdef _WIN32
73  std::string notification_title;
74  std::string notification_message;
75 
76  switch (t) {
77  case CHAT:
78  notification_title = _("Chat message");
79  notification_message = owner + ": " + message;
80  break;
81  case TURN_CHANGED:
82  case OTHER:
83  notification_title = owner;
84  notification_message = message;
85  break;
86  }
87 
88  windows_tray_notification::show(notification_title, notification_message);
89 #endif
90 }
91 #endif //end #else (defined(HAVE_LIBDBUS) || defined(_WIN32))
92 
93 } //end namespace notifications
94 
95 } //end namespace desktop
bool window_has_focus()
True iff the window has mouse or input focus.
Definition: video.cpp:682
static std::string _(const char *str)
Definition: gettext.hpp:93
void send_notification(const std::string &owner, const std::string &message, bool with_history)
bool available()
Returns whether we were compiled with support for desktop notifications.
void send_notification(const std::string &owner, const std::string &message, const desktop::notifications::type note_type)
void send(const std::string &, const std::string &, type)
Displays a desktop notification message, from owner, of type t.
bool available()
Whether wesnoth was compiled with support for a clipboard.
Definition: clipboard.cpp:55
bool window_is_visible()
True iff the window is not hidden.
Definition: video.cpp:677
double t
Definition: astarsearch.cpp:65
static bool show(std::string title, std::string message)
Displays a tray notification.