mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-08 07:07:05 +02:00
Add desktop notifications for received tracks
This commit is contained in:
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/inbox.svg</file>
|
||||||
<file>data/images/new-inbox.svg</file>
|
<file>data/images/new-inbox.svg</file>
|
||||||
<file>data/images/outbox.svg</file>
|
<file>data/images/outbox.svg</file>
|
||||||
|
<file>data/images/inbox-512x512.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
@@ -63,7 +63,7 @@ FdoNotifyPlugin::FdoNotifyPlugin()
|
|||||||
, m_wmSupportsBodyMarkup( false )
|
, m_wmSupportsBodyMarkup( false )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
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.
|
// Query the window manager for its capabilties in styling notifications.
|
||||||
QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "GetCapabilities" );
|
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 );
|
nowPlaying( pushData.infoPair.second );
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
case Tomahawk::InfoSystem::InfoInboxReceived:
|
||||||
|
inboxReceived( pushData.infoPair.second );
|
||||||
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -166,6 +170,73 @@ FdoNotifyPlugin::notifyUser( const QString& messageText )
|
|||||||
QDBusConnection::sessionBus().send( message );
|
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
|
void
|
||||||
FdoNotifyPlugin::nowPlaying( const QVariant& input )
|
FdoNotifyPlugin::nowPlaying( const QVariant& input )
|
||||||
|
@@ -65,6 +65,7 @@ private:
|
|||||||
int getNotificationIconHeight();
|
int getNotificationIconHeight();
|
||||||
|
|
||||||
void notifyUser( const QString& messageText );
|
void notifyUser( const QString& messageText );
|
||||||
|
void inboxReceived( const QVariant& input );
|
||||||
void nowPlaying( const QVariant& input );
|
void nowPlaying( const QVariant& input );
|
||||||
|
|
||||||
quint32 m_nowPlayingId;
|
quint32 m_nowPlayingId;
|
||||||
|
@@ -216,7 +216,9 @@ namespace Tomahawk
|
|||||||
|
|
||||||
InfoNotifyUser = 100,
|
InfoNotifyUser = 100,
|
||||||
|
|
||||||
InfoLastInfo = 101 //WARNING: *ALWAYS* keep this last!
|
InfoInboxReceived = 101,
|
||||||
|
|
||||||
|
InfoLastInfo = 102 //WARNING: *ALWAYS* keep this last!
|
||||||
};
|
};
|
||||||
|
|
||||||
class InfoPlugin;
|
class InfoPlugin;
|
||||||
|
@@ -225,7 +225,7 @@ InfoSystem::getInfo( const QString &caller, const QVariantMap &customData, const
|
|||||||
bool
|
bool
|
||||||
InfoSystem::pushInfo( InfoPushData pushData )
|
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() )
|
if ( !m_inited || !m_infoSystemWorkerThreadController->worker() )
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
|
@@ -33,7 +33,7 @@ public:
|
|||||||
enum Side
|
enum Side
|
||||||
{
|
{
|
||||||
Sending = 0,
|
Sending = 0,
|
||||||
Receiving
|
Receiving = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit InboxJobItem( Side side,
|
explicit InboxJobItem( Side side,
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#include "database/DatabaseCommand_DeleteInboxEntry.h"
|
#include "database/DatabaseCommand_DeleteInboxEntry.h"
|
||||||
#include "database/DatabaseCommand_ModifyInboxEntry.h"
|
#include "database/DatabaseCommand_ModifyInboxEntry.h"
|
||||||
#include "SourceList.h"
|
#include "SourceList.h"
|
||||||
|
#include "TomahawkSettings.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "utils/Closure.h"
|
#include "utils/Closure.h"
|
||||||
#include "jobview/JobStatusModel.h"
|
#include "jobview/JobStatusModel.h"
|
||||||
@@ -138,6 +139,24 @@ InboxModel::showNotification( InboxJobItem::Side side,
|
|||||||
JobStatusView::instance()->model()->addJob( new InboxJobItem( side,
|
JobStatusView::instance()->model()->addJob( new InboxJobItem( side,
|
||||||
src->friendlyName(),
|
src->friendlyName(),
|
||||||
track ) );
|
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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user