mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 22:26:32 +02:00
Style notifications if the window manager supports it.
This commit is contained in:
@@ -58,11 +58,15 @@ namespace InfoSystem
|
|||||||
FdoNotifyPlugin::FdoNotifyPlugin()
|
FdoNotifyPlugin::FdoNotifyPlugin()
|
||||||
: InfoPlugin()
|
: InfoPlugin()
|
||||||
, m_nowPlayingId( 0 )
|
, m_nowPlayingId( 0 )
|
||||||
|
, m_wmSupportsBodyMarkup( false )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
m_supportedPushTypes << InfoNotifyUser << InfoNowPlaying << InfoTrackUnresolved << InfoNowStopped;
|
m_supportedPushTypes << InfoNotifyUser << InfoNowPlaying << InfoTrackUnresolved << InfoNowStopped;
|
||||||
}
|
|
||||||
|
|
||||||
|
// Query the window manager for its capabilties in styling notifications.
|
||||||
|
QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "GetCapabilities" );
|
||||||
|
QDBusConnection::sessionBus().callWithCallback( message, this, SLOT( dbusCapabiltiesReplyReceived( QDBusMessage ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
FdoNotifyPlugin::~FdoNotifyPlugin()
|
FdoNotifyPlugin::~FdoNotifyPlugin()
|
||||||
{
|
{
|
||||||
@@ -70,6 +74,24 @@ FdoNotifyPlugin::~FdoNotifyPlugin()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FdoNotifyPlugin::dbusCapabiltiesReplyReceived( const QDBusMessage &reply )
|
||||||
|
{
|
||||||
|
if (reply.type() != QDBusMessage::ReplyMessage ) {
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Did not receive a ReplyMessage";
|
||||||
|
}
|
||||||
|
const QStringList &list = reply.arguments().at( 0 ).toStringList();
|
||||||
|
QListIterator<QString> iter( list );
|
||||||
|
while ( iter.hasNext() ) {
|
||||||
|
QString capabilty = iter.next();
|
||||||
|
if ( capabilty.compare( "body-markup" ) == 0 ) {
|
||||||
|
m_wmSupportsBodyMarkup = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FdoNotifyPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData )
|
FdoNotifyPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData )
|
||||||
{
|
{
|
||||||
@@ -152,7 +174,12 @@ FdoNotifyPlugin::nowPlaying( const QVariant &input )
|
|||||||
if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) )
|
if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString messageText = tr( "Tomahawk is playing \"%1\" by %2%3." )
|
// If the window manager supports notification styling then use it.
|
||||||
|
const char* messageTemplate = "\"%1\" by %2%3.";
|
||||||
|
if ( m_wmSupportsBodyMarkup ) {
|
||||||
|
messageTemplate = "%1<br /><i>by</i> %2%3.";
|
||||||
|
}
|
||||||
|
QString messageText = tr( messageTemplate )
|
||||||
.arg( hash[ "title" ] )
|
.arg( hash[ "title" ] )
|
||||||
.arg( hash[ "artist" ] )
|
.arg( hash[ "artist" ] )
|
||||||
.arg( hash[ "album" ].isEmpty() ? QString() : QString( " %1" ).arg( tr( "on \"%1\"" ).arg( hash[ "album" ] ) ) );
|
.arg( hash[ "album" ].isEmpty() ? QString() : QString( " %1" ).arg( tr( "on \"%1\"" ).arg( hash[ "album" ] ) ) );
|
||||||
@@ -164,7 +191,7 @@ FdoNotifyPlugin::nowPlaying( const QVariant &input )
|
|||||||
arguments << QString( "Tomahawk" ); //app_name
|
arguments << QString( "Tomahawk" ); //app_name
|
||||||
arguments << m_nowPlayingId; //notification_id
|
arguments << m_nowPlayingId; //notification_id
|
||||||
arguments << QString(); //app_icon
|
arguments << QString(); //app_icon
|
||||||
arguments << QString( "Tomahawk" ); //summary
|
arguments << QString( "Tomahawk - Now Playing" ); //summary
|
||||||
arguments << messageText; //body
|
arguments << messageText; //body
|
||||||
arguments << QStringList(); //actions
|
arguments << QStringList(); //actions
|
||||||
QVariantMap dict;
|
QVariantMap dict;
|
||||||
|
@@ -45,6 +45,7 @@ protected slots:
|
|||||||
virtual void init() {}
|
virtual void init() {}
|
||||||
|
|
||||||
virtual void dbusPlayingReplyReceived( const QDBusMessage &reply );
|
virtual void dbusPlayingReplyReceived( const QDBusMessage &reply );
|
||||||
|
virtual void dbusCapabiltiesReplyReceived( const QDBusMessage &reply );
|
||||||
|
|
||||||
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
|
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
|
||||||
{
|
{
|
||||||
@@ -67,6 +68,9 @@ private:
|
|||||||
void nowPlaying( const QVariant &input );
|
void nowPlaying( const QVariant &input );
|
||||||
|
|
||||||
quint32 m_nowPlayingId;
|
quint32 m_nowPlayingId;
|
||||||
|
|
||||||
|
// Does the window manger support basic XML-based markup (a small HTML subset), see Desktop Notifications specification
|
||||||
|
bool m_wmSupportsBodyMarkup;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user