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 {
58  CVideo& video = CVideo::get_singleton();
59 
60  // Do not show notifications when the window is visible...
61  if(video.window_has_flags(SDL_WINDOW_SHOWN)) {
62  // ... and it has a focus.
63  if(video.window_has_flags(SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_FOCUS)) {
64  return;
65  }
66  }
67 
68 #ifdef HAVE_LIBDBUS
69  dbus::send_notification(owner, message, t == CHAT);
70 #endif
71 
72 #ifdef __APPLE__
73  apple_notifications::send_notification(owner, message, t);
74 #endif
75 
76 #ifdef _WIN32
77  std::string notification_title;
78  std::string notification_message;
79 
80  switch (t) {
81  case CHAT:
82  notification_title = _("Chat message");
83  notification_message = owner + ": " + message;
84  break;
85  case TURN_CHANGED:
86  case OTHER:
87  notification_title = owner;
88  notification_message = message;
89  break;
90  }
91 
92  windows_tray_notification::show(notification_title, notification_message);
93 #endif
94 }
95 #endif //end #else (defined(HAVE_LIBDBUS) || defined(HAVE_GROWL) || defined(_WIN32))
96 
97 } //end namespace notifications
98 
99 } //end namespace desktop
std::vector< char_t > string
Definition: video.hpp:31
static CVideo & get_singleton()
Definition: video.hpp:43
-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
bool window_has_flags(uint32_t flags) const
Tests whether the given flags are currently set on the SDL window.
Definition: video.cpp:384
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.