From 93bec146daba5265cf210946312066b7902a21d6 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Mon, 14 Jul 2014 19:49:48 +0100 Subject: [PATCH] Make Freedesktop notification Qt5 compatible --- src/infoplugins/linux/CMakeLists.txt | 31 +++++++------------ .../linux/fdonotify/FdoNotifyPlugin.cpp | 23 ++++++++++---- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/infoplugins/linux/CMakeLists.txt b/src/infoplugins/linux/CMakeLists.txt index 083eae697..aa53663d7 100644 --- a/src/infoplugins/linux/CMakeLists.txt +++ b/src/infoplugins/linux/CMakeLists.txt @@ -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 diff --git a/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.cpp b/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.cpp index f23d34ccc..6245c8620 100644 --- a/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.cpp +++ b/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.cpp @@ -2,6 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2012, Jeff Mitchell + * Copyright 2013-2014, Uwe L. Korn * * 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%1" ).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%1 %2" ).arg( tr( "on", "'on' is followed by an album name" ) ).arg( Qt::escape( hash[ "album" ] ) ); + album = QString( "\n%1 %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%1" ).arg( tr( "by", "preposition to link track and artist" ) ) );