mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-01-17 22:38:33 +01:00
Add desktop notifications for received tracks
This commit is contained in:
parent
30f82b7d2a
commit
62b25991b6
BIN
data/images/inbox-512x512.png
Normal file
BIN
data/images/inbox-512x512.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
@ -153,5 +153,6 @@
|
||||
<file>data/images/inbox.svg</file>
|
||||
<file>data/images/new-inbox.svg</file>
|
||||
<file>data/images/outbox.svg</file>
|
||||
<file>data/images/inbox-512x512.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -63,7 +63,7 @@ FdoNotifyPlugin::FdoNotifyPlugin()
|
||||
, m_wmSupportsBodyMarkup( false )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
m_supportedPushTypes << InfoNotifyUser << InfoNowPlaying << InfoTrackUnresolved << InfoNowStopped;
|
||||
m_supportedPushTypes << InfoNotifyUser << InfoNowPlaying << InfoTrackUnresolved << InfoNowStopped << InfoInboxReceived;
|
||||
|
||||
// Query the window manager for its capabilties in styling notifications.
|
||||
QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "GetCapabilities" );
|
||||
@ -127,6 +127,10 @@ FdoNotifyPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData )
|
||||
nowPlaying( pushData.infoPair.second );
|
||||
return;
|
||||
|
||||
case Tomahawk::InfoSystem::InfoInboxReceived:
|
||||
inboxReceived( pushData.infoPair.second );
|
||||
return;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
@ -166,6 +170,73 @@ FdoNotifyPlugin::notifyUser( const QString& messageText )
|
||||
QDBusConnection::sessionBus().send( message );
|
||||
}
|
||||
|
||||
void FdoNotifyPlugin::inboxReceived(const QVariant &input)
|
||||
{
|
||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
|
||||
if ( !input.canConvert< QVariantMap >() )
|
||||
return;
|
||||
|
||||
QVariantMap map = input.toMap();
|
||||
|
||||
if ( !map.contains( "trackinfo" ) || !map[ "trackinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
|
||||
return;
|
||||
|
||||
if ( !map.contains( "sourceinfo" ) || !map[ "sourceinfo" ].canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
|
||||
return;
|
||||
|
||||
InfoStringHash hash = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >();
|
||||
if ( !hash.contains( "title" ) || !hash.contains( "artist" ) )
|
||||
return;
|
||||
|
||||
InfoStringHash src = map[ "sourceinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >();
|
||||
if ( !src.contains( "friendlyname" ) )
|
||||
return;
|
||||
|
||||
QString messageText;
|
||||
// If the window manager supports notification styling then use it.
|
||||
if ( m_wmSupportsBodyMarkup )
|
||||
{
|
||||
// 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( QString( "\n<i>%1</i>" ).arg( tr( "by", "preposition to link track and artist" ) ) );
|
||||
|
||||
// Dirty hack(TM) so that KNotify/QLabel recognizes the message as Rich Text
|
||||
messageText = QString( "<i></i>%1" ).arg( messageText );
|
||||
}
|
||||
else
|
||||
{
|
||||
messageText = tr( "%1 sent you \"%2\" by %3.", "%1 is a nickname, %2 is a title, %3 is an artist" )
|
||||
.arg( src["friendlyname"] )
|
||||
.arg( hash[ "title" ] )
|
||||
.arg( hash[ "artist" ] );
|
||||
}
|
||||
|
||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "sending message" << messageText;
|
||||
|
||||
QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify" );
|
||||
QList<QVariant> arguments;
|
||||
arguments << QString( "Tomahawk" ); //app_name
|
||||
arguments << m_nowPlayingId; //notification_id
|
||||
arguments << QString(); //app_icon
|
||||
arguments << QString( "Tomahawk - Track received" ); //summary
|
||||
arguments << messageText; //body
|
||||
arguments << QStringList(); //actions
|
||||
QVariantMap dict;
|
||||
dict["desktop-entry"] = QString( "tomahawk" );
|
||||
|
||||
// Convert image to QVariant and scale to a consistent size.
|
||||
dict[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "images/inbox-512x512.png" ).scaledToHeight( getNotificationIconHeight() ) );
|
||||
|
||||
arguments << dict; //hints
|
||||
arguments << qint32( -1 ); //expire_timeout
|
||||
message.setArguments( arguments );
|
||||
|
||||
// Handle reply in a callback, so that this a non-blocking call
|
||||
QDBusConnection::sessionBus().send( message );
|
||||
}
|
||||
|
||||
void
|
||||
FdoNotifyPlugin::nowPlaying( const QVariant& input )
|
||||
|
@ -65,6 +65,7 @@ private:
|
||||
int getNotificationIconHeight();
|
||||
|
||||
void notifyUser( const QString& messageText );
|
||||
void inboxReceived( const QVariant& input );
|
||||
void nowPlaying( const QVariant& input );
|
||||
|
||||
quint32 m_nowPlayingId;
|
||||
|
@ -216,7 +216,9 @@ namespace Tomahawk
|
||||
|
||||
InfoNotifyUser = 100,
|
||||
|
||||
InfoLastInfo = 101 //WARNING: *ALWAYS* keep this last!
|
||||
InfoInboxReceived = 101,
|
||||
|
||||
InfoLastInfo = 102 //WARNING: *ALWAYS* keep this last!
|
||||
};
|
||||
|
||||
class InfoPlugin;
|
||||
|
@ -225,7 +225,7 @@ InfoSystem::getInfo( const QString &caller, const QVariantMap &customData, const
|
||||
bool
|
||||
InfoSystem::pushInfo( InfoPushData pushData )
|
||||
{
|
||||
tDebug() << Q_FUNC_INFO << "type is " << pushData.type;
|
||||
tDebug() << Q_FUNC_INFO << "type is" << pushData.type;
|
||||
if ( !m_inited || !m_infoSystemWorkerThreadController->worker() )
|
||||
{
|
||||
init();
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
enum Side
|
||||
{
|
||||
Sending = 0,
|
||||
Receiving
|
||||
Receiving = 1
|
||||
};
|
||||
|
||||
explicit InboxJobItem( Side side,
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "database/DatabaseCommand_DeleteInboxEntry.h"
|
||||
#include "database/DatabaseCommand_ModifyInboxEntry.h"
|
||||
#include "SourceList.h"
|
||||
#include "TomahawkSettings.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Closure.h"
|
||||
#include "jobview/JobStatusModel.h"
|
||||
@ -138,6 +139,24 @@ InboxModel::showNotification( InboxJobItem::Side side,
|
||||
JobStatusView::instance()->model()->addJob( new InboxJobItem( side,
|
||||
src->friendlyName(),
|
||||
track ) );
|
||||
|
||||
if ( side == InboxJobItem::Receiving )
|
||||
{
|
||||
Tomahawk::InfoSystem::InfoStringHash trackInfo;
|
||||
trackInfo["title"] = track->track();
|
||||
trackInfo["artist"] = track->artist();
|
||||
|
||||
Tomahawk::InfoSystem::InfoStringHash sourceInfo;
|
||||
sourceInfo["friendlyname"] = src->friendlyName();
|
||||
|
||||
QVariantMap playInfo;
|
||||
playInfo["trackinfo"] = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo );
|
||||
playInfo["private"] = TomahawkSettings::instance()->privateListeningMode();
|
||||
playInfo["sourceinfo"] = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( sourceInfo );
|
||||
|
||||
Tomahawk::InfoSystem::InfoPushData pushData ( "InboxModel", Tomahawk::InfoSystem::InfoInboxReceived, playInfo, Tomahawk::InfoSystem::PushShortUrlFlag );
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( pushData );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user