1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-19 15:29:42 +01:00

Make Freedesktop notification Qt5 compatible

This commit is contained in:
Uwe L. Korn 2014-07-14 19:49:48 +01:00
parent 8612ab71b3
commit 93bec146da
2 changed files with 28 additions and 26 deletions

View File

@ -1,24 +1,15 @@
# don't build with Qt5 because QX11Info is missing there
if(NOT Qt5Core_DIR)
SET(fdo_srcs
fdonotify/FdoNotifyPlugin.cpp
fdonotify/ImageConverter.cpp
)
SET(FDO_LINK_LIBRARIES ${LINK_LIBRARIES})
qt_add_dbus_interface(fdo_srcs fdonotify/org.freedesktop.Notifications.xml
FreedesktopNotificationsProxy)
IF(BUILD_GUI AND X11_FOUND)
INCLUDE_DIRECTORIES( ${THIRDPARTY_DIR}/libqnetwm )
SET(fdo_srcs
fdonotify/FdoNotifyPlugin.cpp
fdonotify/ImageConverter.cpp
${THIRDPARTY_DIR}/libqnetwm/libqnetwm/netwm.cpp
)
SET(FDO_LINK_LIBRARIES ${LINK_LIBRARIES} ${X11_LIBRARIES})
qt_add_dbus_interface(fdo_srcs fdonotify/org.freedesktop.Notifications.xml
FreedesktopNotificationsProxy)
tomahawk_add_plugin(fdonotify
TYPE infoplugin EXPORT_MACRO INFOPLUGINDLLEXPORT_PRO
SOURCES "${fdo_srcs}" LINK_LIBRARIES "${FDO_LINK_LIBRARIES}"
)
ENDIF()
endif()
tomahawk_add_plugin(fdonotify
TYPE infoplugin EXPORT_MACRO INFOPLUGINDLLEXPORT_PRO
SOURCES "${fdo_srcs}" LINK_LIBRARIES "${FDO_LINK_LIBRARIES}"
)
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} )
SET(mpris_srcs

View File

@ -2,6 +2,7 @@
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
* Copyright 2013-2014, Uwe L. Korn <uwelk@xhochy.com>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -60,6 +61,14 @@ namespace Tomahawk
namespace InfoSystem
{
QString escapeHtml( const QString& str ) {
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
return str.toHtmlEscaped();
#else
return Qt::escape( str );
#endif
}
FdoNotifyPlugin::FdoNotifyPlugin()
: InfoPlugin()
, m_nowPlayingId( 0 )
@ -195,9 +204,9 @@ void FdoNotifyPlugin::inboxReceived( const QVariant& input )
{
// Remark: If using xml-based markup in notifications, the supplied strings need to be escaped.
messageText = tr( "%1 sent you\n%2%4 %3.", "%1 is a nickname, %2 is a title, %3 is an artist, %4 is the preposition used to link track and artist ('by' in english)" )
.arg( Qt::escape( src["friendlyname"] ) )
.arg( Qt::escape( hash[ "title" ] ) )
.arg( Qt::escape( hash[ "artist" ] ) )
.arg( escapeHtml( src["friendlyname"] ) )
.arg( escapeHtml( hash[ "title" ] ) )
.arg( escapeHtml( hash[ "artist" ] ) )
.arg( QString( "\n<i>%1</i>" ).arg( tr( "by", "preposition to link track and artist" ) ) );
// Dirty hack(TM) so that KNotify/QLabel recognizes the message as Rich Text
@ -253,11 +262,13 @@ FdoNotifyPlugin::nowPlaying( const QVariant& input )
// Remark: If using xml-based markup in notifications, the supplied strings need to be escaped.
QString album;
if ( !hash[ "album" ].isEmpty() )
album = QString( "\n<i>%1</i> %2" ).arg( tr( "on", "'on' is followed by an album name" ) ).arg( Qt::escape( hash[ "album" ] ) );
album = QString( "\n<i>%1</i> %2" )
.arg( tr( "on", "'on' is followed by an album name" ) )
.arg( escapeHtml( hash[ "album" ] ) );
messageText = tr( "%1%4 %2%3.", "%1 is a title, %2 is an artist and %3 is replaced by either the previous message or nothing, %4 is the preposition used to link track and artist ('by' in english)" )
.arg( Qt::escape( hash[ "title" ] ) )
.arg( Qt::escape( hash[ "artist" ] ) )
.arg( escapeHtml( hash[ "title" ] ) )
.arg( escapeHtml( hash[ "artist" ] ) )
.arg( album )
.arg( QString( "\n<i>%1</i>" ).arg( tr( "by", "preposition to link track and artist" ) ) );