Added support for kde's desktop notification DBus service.
For now disabled by default. Enabled with 'scons notifications=true notifications_backend=kde". Compilation requires only QtDBus but they'll only work if wesnoth is run in a kde4.2 session.
This commit is contained in:
parent
f0bc2145bd
commit
0308567800
2 changed files with 38 additions and 9 deletions
15
SConstruct
15
SConstruct
|
@ -60,7 +60,8 @@ opts.AddVariables(
|
|||
BoolVariable('editor', 'Enable editor', True),
|
||||
BoolVariable('lowmem', 'Set to reduce memory usage by removing extra functionality', False),
|
||||
BoolVariable('lua', 'Enable Lua support', True),
|
||||
BoolVariable('notifications', 'Enable support for desktop notifications using libnotify', False),
|
||||
BoolVariable('notifications', 'Enable support for desktop notifications', False),
|
||||
EnumVariable('notifications_backend', "Desktop notifications backend: Galago project's libnotify or KDE's org.kde.VisualNotifications DBus service", 'libnotify', ["libnotify", "kde"]),
|
||||
BoolVariable('nls','enable compile/install of gettext message catalogs',True),
|
||||
BoolVariable('dummy_locales','enable support for dummy locales',False),
|
||||
PathVariable('prefix', 'autotools-style installation prefix', "/usr/local", PathVariable.PathAccept),
|
||||
|
@ -246,9 +247,15 @@ if env["prereqs"]:
|
|||
have_X = conf.CheckLib('X11')
|
||||
|
||||
if env["notifications"]:
|
||||
have_client_prereqs = conf.CheckPKG("gtkmm-2.4 >= 2.8.0") and conf.CheckPKG("libnotifymm-1.0") or \
|
||||
Warning("gtkmm and libnotifymm are required for desktop notifications support")
|
||||
client_env.Append(CPPDEFINES = "HAVE_LIBNOTIFY")
|
||||
if env["notifications_backend"] == "libnotify":
|
||||
have_client_prereqs = have_client_prereqs and conf.CheckPKG("gtkmm-2.4 >= 2.8.0") and conf.CheckPKG("libnotifymm-1.0") or \
|
||||
Warning("gtkmm and libnotifymm are required for desktop notifications support")
|
||||
client_env.Append(CPPDEFINES = ["HAVE_LIBNOTIFY"])
|
||||
|
||||
if env["notifications_backend"] == "kde":
|
||||
have_client_prereqs = have_client_prereqs and conf.CheckPKG("QtDBus") or \
|
||||
Warning("QtDBus is required for KDE desktop notifications support")
|
||||
client_env.Append(CPPDEFINES = ["HAVE_QTDBUS"])
|
||||
|
||||
if client_env['fribidi']:
|
||||
client_env['fribidi'] = conf.CheckLibWithHeader('fribidi', 'fribidi/fribidi.h', 'C', 'fribidi_utf8_to_unicode(NULL,0,NULL);') or Warning("Can't find libfribidi, disabling freebidi support.")
|
||||
|
|
|
@ -25,6 +25,10 @@
|
|||
#include <libnotifymm-1.0/libnotifymm.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_QTDBUS
|
||||
#include <QtDBus>
|
||||
#endif
|
||||
|
||||
#include "actions.hpp"
|
||||
#include "foreach.hpp"
|
||||
#include "halo.hpp"
|
||||
|
@ -1028,9 +1032,9 @@ std::string game_display::current_team_name() const
|
|||
return std::string();
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBNOTIFY
|
||||
void game_display::send_notification(const std::string& owner, const std::string& message)
|
||||
{
|
||||
#if defined(HAVE_LIBNOTIFY) || defined(HAVE_QTDBUS)
|
||||
// SDL_APPACTIVE, SDL_APPINPUTFOCUS, SDL_APPMOUSEFOCUS
|
||||
Uint8 app_state = SDL_GetAppState();
|
||||
|
||||
|
@ -1043,22 +1047,40 @@ void game_display::send_notification(const std::string& owner, const std::string
|
|||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBNOTIFY
|
||||
try {
|
||||
Notify::init("Wesnoth");
|
||||
|
||||
// I tried to use the fancy Gtk::IconTheme stuff but it didn't seem worth it. -- method
|
||||
Glib::ustring wesnoth_icon_info = game_config::path + "images/wesnoth-icon-small.png";
|
||||
Glib::ustring wesnoth_icon_info = game_config::path + "/images/wesnoth-icon-small.png";
|
||||
Notify::Notification notification(owner, message, wesnoth_icon_info);
|
||||
notification.show();
|
||||
} catch(const Glib::Error& error) {
|
||||
ERR_DP << "Failed to send libnotify notification: " << error.what() << "\n";
|
||||
}
|
||||
}
|
||||
#else
|
||||
void game_display::send_notification(const std::string&, const std::string&) {}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_QTDBUS
|
||||
QDBusInterface notify("org.kde.VisualNotifications", "/VisualNotifications", "org.kde.VisualNotifications");
|
||||
QList<QVariant> args;
|
||||
args.append("Battle for Wesnoth");
|
||||
args.append(0U);
|
||||
args.append("");
|
||||
args.append((game_config::path + "/data/core/images/wesnoth-icon.png").c_str());
|
||||
args.append(QString::fromUtf8(owner.c_str()));
|
||||
args.append(QString::fromUtf8(message.c_str()));
|
||||
args.append(QStringList());
|
||||
args.append(QVariantMap());
|
||||
args.append(5000);
|
||||
QDBusMessage result = notify.callWithArgumentList(QDBus::Block, "Notify", args);
|
||||
if(result.type() == QDBusMessage::ErrorMessage) {
|
||||
ERR_DP << "Failed to send a KDE notification with DBus: " << result.errorMessage().toLocal8Bit().data();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void game_display::set_team(size_t teamindex, bool show_everything)
|
||||
{
|
||||
assert(teamindex < teams_.size());
|
||||
|
|
Loading…
Add table
Reference in a new issue