1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 11:20:22 +02:00

* Style fixes for FdoNotifyPlugin.

This commit is contained in:
Christian Muehlhaeuser
2013-06-03 03:30:01 +02:00
parent 0bb1dd6245
commit 56eba6d054
2 changed files with 50 additions and 46 deletions

View File

@@ -38,16 +38,18 @@
*/ */
#include "FdoNotifyPlugin.h" #include "FdoNotifyPlugin.h"
#include "utils/TomahawkUtils.h"
#include "ImageConverter.h" #include "ImageConverter.h"
#include "FreedesktopNotificationsProxy.h" #include "FreedesktopNotificationsProxy.h"
#include "TomahawkSettings.h" #include "TomahawkSettings.h"
#include "utils/TomahawkUtils.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/TomahawkUtilsGui.h" #include "utils/TomahawkUtilsGui.h"
#include <QDBusConnection> #include <QDBusConnection>
#include <QDBusPendingCallWatcher>
#include <QImage> #include <QImage>
// QTextDocument provides Qt::escape() // QTextDocument provides Qt::escape()
#include <QTextDocument> #include <QTextDocument>
@@ -63,22 +65,22 @@ FdoNotifyPlugin::FdoNotifyPlugin()
, m_nowPlayingId( 0 ) , m_nowPlayingId( 0 )
, m_wmSupportsBodyMarkup( false ) , m_wmSupportsBodyMarkup( false )
{ {
qDebug() << Q_FUNC_INFO; tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
m_supportedPushTypes << InfoNotifyUser << InfoNowPlaying << InfoTrackUnresolved << InfoNowStopped << InfoInboxReceived; m_supportedPushTypes << InfoNotifyUser << InfoNowPlaying << InfoTrackUnresolved << InfoNowStopped << InfoInboxReceived;
// Query the window manager for its capabilties in styling notifications. // Query the window manager for its capabilties in styling notifications.
notifications_interface = new org::freedesktop::Notifications("org.freedesktop.Notifications", "/org/freedesktop/Notifications", notifications_interface = new org::freedesktop::Notifications( "org.freedesktop.Notifications", "/org/freedesktop/Notifications",
QDBusConnection::sessionBus(), this); QDBusConnection::sessionBus(), this );
QDBusPendingReply<QStringList> reply = notifications_interface->GetCapabilities(); QDBusPendingReply<QStringList> reply = notifications_interface->GetCapabilities();
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(reply, this); QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher( reply, this );
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(dbusCapabilitiesReplyReceived(QDBusPendingCallWatcher*))); connect( watcher, SIGNAL( finished( QDBusPendingCallWatcher* ) ), SLOT( dbusCapabilitiesReplyReceived( QDBusPendingCallWatcher* ) ) );
} }
FdoNotifyPlugin::~FdoNotifyPlugin() FdoNotifyPlugin::~FdoNotifyPlugin()
{ {
qDebug() << Q_FUNC_INFO; tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
} }
@@ -88,19 +90,20 @@ FdoNotifyPlugin::dbusCapabilitiesReplyReceived( QDBusPendingCallWatcher* watcher
QDBusMessage reply = watcher->reply(); QDBusMessage reply = watcher->reply();
watcher->deleteLater(); watcher->deleteLater();
if (reply.type() == QDBusMessage::ErrorMessage) { if ( reply.type() == QDBusMessage::ErrorMessage )
{
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Failed to request capabilities of notifications"; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Failed to request capabilities of notifications";
} }
const QStringList &capability_list = reply.arguments().at( 0 ).toStringList(); const QStringList& capability_list = reply.arguments().first().toStringList();
m_wmSupportsBodyMarkup = capability_list.contains("body-markup"); m_wmSupportsBodyMarkup = capability_list.contains( "body-markup" );
} }
void void
FdoNotifyPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData ) FdoNotifyPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData )
{ {
qDebug() << Q_FUNC_INFO << "showing notification: " << TomahawkSettings::instance()->songChangeNotificationEnabled(); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "showing notification:" << TomahawkSettings::instance()->songChangeNotificationEnabled();
if ( !TomahawkSettings::instance()->songChangeNotificationEnabled() ) if ( !TomahawkSettings::instance()->songChangeNotificationEnabled() )
return; return;
@@ -154,17 +157,18 @@ FdoNotifyPlugin::notifyUser( const QString& messageText )
hints[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "icons/tomahawk-icon-512x512.png" ).scaledToHeight( getNotificationIconHeight() ) ); hints[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "icons/tomahawk-icon-512x512.png" ).scaledToHeight( getNotificationIconHeight() ) );
notifications_interface->Notify( notifications_interface->Notify(
"Tomahawk", // app_name "Tomahawk", // app_name
0, // notification_id 0, // notification_id
"", // app_icon "", // app_icon
"Tomahawk", // summary "Tomahawk", // summary
messageText, // body messageText, // body
QStringList(), // actions QStringList(), // actions
hints, // hints hints, // hints
-1 // expire_timeout -1 // expire_timeout
); );
} }
void FdoNotifyPlugin::inboxReceived(const QVariant &input)
void FdoNotifyPlugin::inboxReceived( const QVariant& input )
{ {
tDebug( LOGVERBOSE ) << Q_FUNC_INFO; tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
if ( !input.canConvert< QVariantMap >() ) if ( !input.canConvert< QVariantMap >() )
@@ -174,7 +178,6 @@ void FdoNotifyPlugin::inboxReceived(const QVariant &input)
if ( !map.contains( "trackinfo" ) || !map[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) if ( !map.contains( "trackinfo" ) || !map[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
return; return;
if ( !map.contains( "sourceinfo" ) || !map[ "sourceinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) if ( !map.contains( "sourceinfo" ) || !map[ "sourceinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
return; return;
@@ -217,16 +220,17 @@ void FdoNotifyPlugin::inboxReceived(const QVariant &input)
hints[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "images/inbox-512x512.png" ).scaledToHeight( getNotificationIconHeight() ) ); hints[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "images/inbox-512x512.png" ).scaledToHeight( getNotificationIconHeight() ) );
notifications_interface->Notify( notifications_interface->Notify(
"Tomahawk", // app_name "Tomahawk", // app_name
m_nowPlayingId, // notification_id m_nowPlayingId, // notification_id
"", // app_icon "", // app_icon
"Tomahawk - Track received", // summary "Tomahawk - Track received", // summary
messageText, // body messageText, // body
QStringList(), // actions QStringList(), // actions
hints, // hints hints, // hints
-1 // expire_timeout -1 // expire_timeout
); );
} }
void void
FdoNotifyPlugin::nowPlaying( const QVariant& input ) FdoNotifyPlugin::nowPlaying( const QVariant& input )
{ {
@@ -235,7 +239,6 @@ FdoNotifyPlugin::nowPlaying( const QVariant& input )
return; return;
QVariantMap map = input.toMap(); QVariantMap map = input.toMap();
if ( !map.contains( "trackinfo" ) || !map[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) if ( !map.contains( "trackinfo" ) || !map[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
return; return;
@@ -290,18 +293,17 @@ FdoNotifyPlugin::nowPlaying( const QVariant& input )
QDBusPendingReply<> reply = notifications_interface->Notify( QDBusPendingReply<> reply = notifications_interface->Notify(
"Tomahawk", // app_name "Tomahawk", // app_name
m_nowPlayingId, // notification_id m_nowPlayingId, // notification_id
"", // app_icon "", // app_icon
"Tomahawk - Now Playing", // summary "Tomahawk - Now Playing", // summary
messageText, // body messageText, // body
QStringList(), // actions QStringList(), // actions
hints, // hints hints, // hints
-1 // expire_timeout -1 // expire_timeout
); );
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(reply, this); QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher( reply, this );
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), connect( watcher, SIGNAL( finished( QDBusPendingCallWatcher* ) ), SLOT( RegisterFinished( dbusPlayingReplyReceived* ) ) );
this, SLOT(RegisterFinished(dbusPlayingReplyReceived*)));
} }
@@ -314,14 +316,16 @@ FdoNotifyPlugin::dbusPlayingReplyReceived( QDBusPendingCallWatcher* watcher )
{ {
QDBusMessage reply = watcher->reply(); QDBusMessage reply = watcher->reply();
watcher->deleteLater(); watcher->deleteLater();
if (reply.type() == QDBusMessage::ErrorMessage) {
if ( reply.type() == QDBusMessage::ErrorMessage )
{
tLog(LOGVERBOSE) << "Failed to grab media keys" << reply.errorName() << reply.errorMessage(); tLog(LOGVERBOSE) << "Failed to grab media keys" << reply.errorName() << reply.errorMessage();
return; return;
} }
const QVariantList& list = reply.arguments(); const QVariantList& list = reply.arguments();
if ( list.count() > 0 ) if ( !list.isEmpty() )
m_nowPlayingId = list.at( 0 ).toInt(); m_nowPlayingId = list.first().toInt();
} }
} //ns InfoSystem } //ns InfoSystem

View File

@@ -25,7 +25,7 @@
#include "infosystem/InfoSystem.h" #include "infosystem/InfoSystem.h"
#include "FreedesktopNotificationsProxy.h" #include "FreedesktopNotificationsProxy.h"
#include <QtDBus> class QDBusPendingCallWatcher;
namespace Tomahawk namespace Tomahawk
{ {