The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
notifications.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2017 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project http://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 
16 
17 #include "preferences/game.hpp"
18 #include "gettext.hpp"
19 
20 #include "video.hpp" //CVideo::get_singleton().window_state()
21 
22 #ifdef HAVE_LIBDBUS
24 #endif
25 
26 #ifdef __APPLE__
28 #endif
29 
30 #ifdef _WIN32
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__
51 #else
52  return true;
53 #endif
54 }
55 
56 void send(const std::string& owner, const std::string& message, type t)
57 {
59  if(window == nullptr) {
60  return;
61  }
62 
63  int app_state = window->get_flags();
64 
65  // Do not show notifications when the window is visible...
66  if ((app_state & SDL_WINDOW_SHOWN) != 0)
67  {
68  // ... and it has a focus.
69  if ((app_state & (SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_FOCUS)) != 0) {
70  return;
71  }
72  }
73 
74 #ifdef HAVE_LIBDBUS
75  dbus::send_notification(owner, message, t == CHAT);
76 #endif
77 
78 #ifdef __APPLE__
79  apple_notifications::send_notification(owner, message, t);
80 #endif
81 
82 #ifdef _WIN32
83  std::string notification_title;
84  std::string notification_message;
85 
86  switch (t) {
87  case CHAT:
88  notification_title = _("Chat message");
89  notification_message = owner + ": " + message;
90  break;
91  case TURN_CHANGED:
92  case OTHER:
93  notification_title = owner;
94  notification_message = message;
95  break;
96  }
97 
98  windows_tray_notification::show(notification_title, notification_message);
99 #endif
100 }
101 #endif //end #else (defined(HAVE_LIBDBUS) || defined(HAVE_GROWL) || defined(_WIN32))
102 
103 } //end namespace notifications
104 
105 } //end namespace desktop
std::vector< char_t > string
static CVideo & get_singleton()
Definition: video.hpp:50
-file util.hpp
void send_notification(const std::string &owner, const std::string &message, bool with_history)
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:89
The wrapper class for the SDL_Window class.
Definition: window.hpp:44
sdl::window * get_window()
Definition: video.cpp:367
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:56
double t
Definition: astarsearch.cpp:64
static bool show(std::string title, std::string message)
Displays a tray notification.
int get_flags()
Definition: window.cpp:145