From a39bfea9920c52949fa4160bc32c88d834aef4b8 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Sun, 13 Jul 2014 23:19:47 -0400 Subject: [PATCH] give a warning when notifications enabled but not available The "disable notifications" option in advanced preferences allows the user to toggle desktop notifications on and off. However, if the game was not compiled with support for these, the option won't do anything. In this revision, if disable_notifications is set to false, but notifications are not available, a dialog is launched which explains that this executable was not compiled with support for notifications. The preference *is* toggled however -- this is because all versions of wesnoth use the same preference file (at least under linux), so we would rather to allow the user to change the file at will -- a different wesnoth binary which they have may indeed support notifications. So we only give a warning but allow them to toggle. --- src/game_preferences_display.cpp | 12 ++++++++++-- src/notifications/notifications.cpp | 7 +++++++ src/notifications/notifications.hpp | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/game_preferences_display.cpp b/src/game_preferences_display.cpp index 9562544d7f49..dfbdcbcab6a3 100644 --- a/src/game_preferences_display.cpp +++ b/src/game_preferences_display.cpp @@ -27,6 +27,7 @@ #include "gui/dialogs/transient_message.hpp" #include "lobby_preferences.hpp" #include "marked-up_text.hpp" +#include "notifications/notifications.hpp" //needed to check if notifications are not available #include "preferences_display.hpp" #include "wml_separators.hpp" #include "widgets/combo.hpp" @@ -1375,6 +1376,13 @@ void preferences_dialog::process_event() if(pref["field"] == "color_cursors") { set_color_cursors(advanced_button_.checked()); } + + if (pref["field"] == "disable_notifications" && !advanced_button_check && !notifications::available()) { + gui::dialog(*display::get_singleton() + , _("Notifications Not Available") + , _("Support for notifications was not found. Please check with the packager for your platform, or if compiling yourself, check that you have the appropriate dependencies for your platform to support this feature.") + , gui::OK_ONLY).show(); + } } } @@ -1663,7 +1671,7 @@ void preferences_dialog::set_selection(int index) advanced_option_label_.hide(hide_advanced_int && hide_advanced_combo); } -} +} //end anonymous namespace void show_preferences_dialog(display& disp, const config& game_cfg) { @@ -1788,4 +1796,4 @@ std::string show_wesnothd_server_search(display& disp) } -} +} // end namespace preferences diff --git a/src/notifications/notifications.cpp b/src/notifications/notifications.cpp index fe8184e6d8cb..e5234962ac87 100644 --- a/src/notifications/notifications.cpp +++ b/src/notifications/notifications.cpp @@ -40,11 +40,18 @@ namespace notifications { + #if !(defined(HAVE_LIBDBUS) || defined(HAVE_GROWL) || defined(_WIN32)) + +bool available() { return false; } + void send_notification(const std::string& /*owner*/, const std::string& /*message*/, type /*t*/) {} + #else +bool available() { return true; } + void send_notification(const std::string& owner, const std::string& message, type t) { if (preferences::get("disable_notifications", false)) { return; } diff --git a/src/notifications/notifications.hpp b/src/notifications/notifications.hpp index fd8743834985..cb63e6df7729 100644 --- a/src/notifications/notifications.hpp +++ b/src/notifications/notifications.hpp @@ -22,6 +22,8 @@ namespace notifications enum type {CHAT, TURN_CHANGED, OTHER}; void send_notification(const std::string& owner, const std::string& message, type t); + + bool available(); } #endif