From 971e84337f669e39b00ae537060ea8ba457d30db Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Sun, 24 Feb 2013 16:30:28 +0100 Subject: [PATCH] More translator friendly string formatting * Add escaping of supplied strings since they may interfere with the xml-based markup. --- .../linux/fdonotify/FdoNotifyPlugin.cpp | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.cpp b/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.cpp index acbf21092..c07694560 100644 --- a/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.cpp +++ b/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.cpp @@ -48,6 +48,8 @@ #include #include +// QTextDocument provides Qt::escape() +#include namespace Tomahawk { @@ -174,17 +176,28 @@ FdoNotifyPlugin::nowPlaying( const QVariant &input ) if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) ) return; + QString messageText; // If the window manager supports notification styling then use it. - const char* messageTemplate = "\"%1\" by %2%3."; - const char* albumMessageTemplate = "on \"%1\""; if ( m_wmSupportsBodyMarkup ) { - messageTemplate = "%1
by %2%3."; - albumMessageTemplate = "
on %1"; + // Remark: If using xml-based markup in notifications, the supplied strings need to be escaped. + QString album; + if ( !hash[ "album" ].isEmpty() ) + album = tr( "
on %1" ).arg( Qt::escape( hash[ "album" ] ) ); + messageText = tr( "%1
by %2%3." ) + .arg( Qt::escape( hash[ "title" ] ) ) + .arg( Qt::escape( hash[ "artist" ] ) ) + .arg( album ); } - QString messageText = tr( messageTemplate ) + else + { + QString album; + if ( !hash[ "album" ].isEmpty() ) + album = QString( " %1" ).arg( tr( "on \"%1\"" ).arg( hash[ "album" ] ) ); + messageText = tr( "\"%1\" by %2%3." ) .arg( hash[ "title" ] ) .arg( hash[ "artist" ] ) - .arg( hash[ "album" ].isEmpty() ? QString() : QString( " %1" ).arg( tr( albumMessageTemplate ).arg( hash[ "album" ] ) ) ); + .arg( album ); + } tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "sending message" << messageText;