The Battle for Wesnoth  1.13.4+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 - 2016 by David White <[email protected]>
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 
15 #include "notifications.hpp"
16 #include "global.hpp"
17 
18 #include "game_preferences.hpp"
19 #include "gettext.hpp"
20 
21 #include "sdl/compat.hpp"
22 
23 #include "video.hpp" //SDL_GetAppState()
24 
25 #ifdef HAVE_LIBDBUS
26 #include "dbus_notification.hpp"
27 #endif
28 
29 #ifdef __APPLE__
30 #include "apple_notification.hpp"
31 #endif
32 
33 #ifdef _WIN32
35 #endif
36 
37 namespace desktop {
38 
39 namespace notifications {
40 
41 #if !(defined(HAVE_LIBDBUS) || defined(__APPLE__) || defined(_WIN32))
42 
43 bool available() { return false; }
44 
45 void send(const std::string& /*owner*/, const std::string& /*message*/, type /*t*/)
46 {}
47 
48 #else
49 
50 bool available() { return true; }
51 
52 void send(const std::string& owner, const std::string& message, type t)
53 {
54  Uint8 app_state = SDL_GetAppState();
55 
56  // Do not show notifications when the window is visible...
57  if ((app_state & SDL_APPACTIVE) != 0)
58  {
59  // ... and it has a focus.
60  if ((app_state & (SDL_APPMOUSEFOCUS | SDL_APPINPUTFOCUS)) != 0) {
61  return;
62  }
63  }
64 
65 #ifdef HAVE_LIBDBUS
66  dbus::send_notification(owner, message, t == CHAT);
67 #endif
68 
69 #ifdef __APPLE__
70  apple_notifications::send_notification(owner, message, t);
71 #endif
72 
73 #ifdef _WIN32
74  std::string notification_title;
75  std::string notification_message;
76 
77  switch (t) {
78  case CHAT:
79  notification_title = _("Chat message");
80  notification_message = owner + ": " + message;
81  break;
82  case TURN_CHANGED:
83  case OTHER:
84  notification_title = owner;
85  notification_message = message;
86  break;
87  }
88 
89  windows_tray_notification::show(notification_title, notification_message);
90 #endif
91 }
92 #endif //end #else (defined(HAVE_LIBDBUS) || defined(HAVE_GROWL) || defined(_WIN32))
93 
94 } //end namespace notifications
95 
96 } //end namespace desktop
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
GLdouble GLdouble t
Definition: glew.h:1366
-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:82
#define SDL_APPINPUTFOCUS
The app has input focus.
Definition: video.hpp:39
Compatibility layer for using SDL 1.2 and 2.0.
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.
#define SDL_APPMOUSEFOCUS
The app has mouse coverage.
Definition: video.hpp:38
#define SDL_APPACTIVE
The application is active.
Definition: video.hpp:40
#define SDL_GetAppState
Definition: compat.hpp:40
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
static bool show(std::string title, std::string message)
Displays a tray notification.
GLsizei const GLcharARB ** string
Definition: glew.h:4503