From 796df668855a33909abd2876908d781e98f7a64b Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Tue, 19 Mar 2013 10:02:47 +0100 Subject: [PATCH] * Some FdoNotifyPlugin cleanups. --- .../linux/fdonotify/FdoNotifyPlugin.cpp | 39 ++++++++++++------- .../linux/fdonotify/FdoNotifyPlugin.h | 9 ++--- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.cpp b/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.cpp index c07694560..8825dfcc8 100644 --- a/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.cpp +++ b/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.cpp @@ -70,6 +70,7 @@ FdoNotifyPlugin::FdoNotifyPlugin() QDBusConnection::sessionBus().callWithCallback( message, this, SLOT( dbusCapabiltiesReplyReceived( QDBusMessage ) ) ); } + FdoNotifyPlugin::~FdoNotifyPlugin() { qDebug() << Q_FUNC_INFO; @@ -77,23 +78,27 @@ FdoNotifyPlugin::~FdoNotifyPlugin() void -FdoNotifyPlugin::dbusCapabiltiesReplyReceived( const QDBusMessage &reply ) +FdoNotifyPlugin::dbusCapabiltiesReplyReceived( const QDBusMessage& reply ) { - if (reply.type() != QDBusMessage::ReplyMessage ) { + if ( reply.type() != QDBusMessage::ReplyMessage ) + { tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Did not receive a ReplyMessage"; } + const QStringList &list = reply.arguments().at( 0 ).toStringList(); QListIterator iter( list ); - while ( iter.hasNext() ) { + while ( iter.hasNext() ) + { QString capabilty = iter.next(); - if ( capabilty.compare( "body-markup" ) == 0 ) { + if ( capabilty.compare( "body-markup" ) == 0 ) + { m_wmSupportsBodyMarkup = true; + break; } } } - void FdoNotifyPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData ) { @@ -135,14 +140,15 @@ FdoNotifyPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData ) int FdoNotifyPlugin::getNotificationIconHeight() { - return 6*TomahawkUtils::defaultFontHeight(); + return 6 * TomahawkUtils::defaultFontHeight(); } void -FdoNotifyPlugin::notifyUser( const QString &messageText ) +FdoNotifyPlugin::notifyUser( const QString& messageText ) { QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify" ); + QList arguments; arguments << QString( "Tomahawk" ); //app_name arguments << quint32( 0 ); //notification_id @@ -150,6 +156,7 @@ FdoNotifyPlugin::notifyUser( const QString &messageText ) arguments << QString( "Tomahawk" ); //summary arguments << QString( messageText ); //body arguments << QStringList(); //actions + QVariantMap dict; dict["desktop-entry"] = QString( "tomahawk" ); dict[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "icons/tomahawk-icon-512x512.png" ).scaledToHeight( getNotificationIconHeight() ) ); @@ -161,7 +168,7 @@ FdoNotifyPlugin::notifyUser( const QString &messageText ) void -FdoNotifyPlugin::nowPlaying( const QVariant &input ) +FdoNotifyPlugin::nowPlaying( const QVariant& input ) { tDebug( LOGVERBOSE ) << Q_FUNC_INFO; if ( !input.canConvert< QVariantMap >() ) @@ -178,11 +185,13 @@ FdoNotifyPlugin::nowPlaying( const QVariant &input ) QString messageText; // If the window manager supports notification styling then use it. - if ( m_wmSupportsBodyMarkup ) { + if ( m_wmSupportsBodyMarkup ) + { // 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" ] ) ) @@ -192,7 +201,8 @@ FdoNotifyPlugin::nowPlaying( const QVariant &input ) { QString album; if ( !hash[ "album" ].isEmpty() ) - album = QString( " %1" ).arg( tr( "on \"%1\"" ).arg( hash[ "album" ] ) ); + album = QString( " %1" ).arg( tr( "on \"%1\"" ).arg( hash[ "album" ] ) ); + messageText = tr( "\"%1\" by %2%3." ) .arg( hash[ "title" ] ) .arg( hash[ "artist" ] ) @@ -229,15 +239,16 @@ FdoNotifyPlugin::nowPlaying( const QVariant &input ) QDBusConnection::sessionBus().callWithCallback( message, this, SLOT( dbusPlayingReplyReceived( QDBusMessage ) ) ); } + /** * Handle the DBus reply triggered by FdoNotifyPlugin::nowPlaying */ void -FdoNotifyPlugin::dbusPlayingReplyReceived( const QDBusMessage &reply ) +FdoNotifyPlugin::dbusPlayingReplyReceived( const QDBusMessage& reply ) { - const QVariantList &list = reply.arguments(); - if ( list.count() > 0 ) - m_nowPlayingId = list.at( 0 ).toInt(); + const QVariantList& list = reply.arguments(); + if ( list.count() > 0 ) + m_nowPlayingId = list.at( 0 ).toInt(); } } //ns InfoSystem diff --git a/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.h b/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.h index f65bf0b02..c9f3e78e0 100644 --- a/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.h +++ b/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.h @@ -44,8 +44,8 @@ public: protected slots: virtual void init() {} - virtual void dbusPlayingReplyReceived( const QDBusMessage &reply ); - virtual void dbusCapabiltiesReplyReceived( const QDBusMessage &reply ); + virtual void dbusPlayingReplyReceived( const QDBusMessage& reply ); + virtual void dbusCapabiltiesReplyReceived( const QDBusMessage& reply ); virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) { @@ -63,9 +63,8 @@ protected slots: private: int getNotificationIconHeight(); - void notifyUser( const QString &messageText ); - - void nowPlaying( const QVariant &input ); + void notifyUser( const QString& messageText ); + void nowPlaying( const QVariant& input ); quint32 m_nowPlayingId;