void FdoNotifyPlugin::nowPlaying( 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; InfoStringHash hash = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) ) 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. QString album; if ( !hash[ "album" ].isEmpty() ) album = tr( "<br /><i>on</i> %1", "%1 is an album name" ).arg( Qt::escape( hash[ "album" ] ) ); messageText = tr( "%1<br /><i>by</i> %2%3.", "%1 is a title, %2 is an artist and %3 is replaced by either the previous message or nothing" ) .arg( Qt::escape( hash[ "title" ] ) ) .arg( Qt::escape( hash[ "artist" ] ) ) .arg( album ); } else { QString album; if ( !hash[ "album" ].isEmpty() ) album = QString( " %1" ).arg( tr( "on \"%1\"", "%1 is an album name" ).arg( hash[ "album" ] ) ); messageText = tr( "\"%1\" by %2%3.", "%1 is a title, %2 is an artist and %3 is replaced by either the previous message or nothing" ) .arg( hash[ "title" ] ) .arg( hash[ "artist" ] ) .arg( album ); } 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 - Now Playing" ); //summary arguments << messageText; //body arguments << QStringList(); //actions QVariantMap dict; dict["desktop-entry"] = QString( "tomahawk" ); // If there is a cover availble use it, else use Tomahawk logo as default. QImage image; if ( map.contains( "coveruri" ) && map[ "coveruri" ].canConvert< QString >() ) image = QImage( map[ "coveruri" ].toString(), "PNG" ); else image = QImage( RESPATH "icons/tomahawk-icon-512x512.png" ); // Convert image to QVariant and scale to a consistent size. dict[ "image_data" ] = ImageConverter::variantForImage( image.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().callWithCallback( message, this, SLOT( dbusPlayingReplyReceived( QDBusMessage ) ) ); }
void FdoNotifyPlugin::notifyUser( const QString& messageText ) { QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify" ); QList<QVariant> arguments; arguments << QString( "Tomahawk" ); //app_name arguments << quint32( 0 ); //notification_id arguments << QString(); //app_icon 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() ) ); arguments << dict; //hints arguments << qint32( -1 ); //expire_timeout message.setArguments( arguments ); 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( escapeHtml( src["friendlyname"] ) ) .arg( escapeHtml( hash[ "title" ] ) ) .arg( escapeHtml( 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; QVariantMap hints; hints["desktop-entry"] = QString( "tomahawk" ); // Convert image to QVariant and scale to a consistent size. hints[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "images/inbox-512x512.png" ).scaledToHeight( getNotificationIconHeight() ) ); notifications_interface->Notify( "Tomahawk", // app_name m_nowPlayingId, // notification_id "", // app_icon "Tomahawk - Track received", // summary messageText, // body QStringList(), // actions hints, // hints -1 // expire_timeout ); }
void FdoNotifyPlugin::nowPlaying( 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; InfoStringHash hash = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) ) 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. QString album; if ( !hash[ "album" ].isEmpty() ) album = QString( "\n<i>%1</i> %2" ) .arg( tr( "on", "'on' is followed by an album name" ) ) .arg( escapeHtml( hash[ "album" ] ) ); messageText = tr( "%1%4 %2%3.", "%1 is a title, %2 is an artist and %3 is replaced by either the previous message or nothing, %4 is the preposition used to link track and artist ('by' in english)" ) .arg( escapeHtml( hash[ "title" ] ) ) .arg( escapeHtml( hash[ "artist" ] ) ) .arg( album ) .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 { QString album; if ( !hash[ "album" ].isEmpty() ) album = QString( " %1" ).arg( tr( "on \"%1\"", "%1 is an album name" ).arg( hash[ "album" ] ) ); messageText = tr( "\"%1\" by %2%3.", "%1 is a title, %2 is an artist and %3 is replaced by either the previous message or nothing" ) .arg( hash[ "title" ] ) .arg( hash[ "artist" ] ) .arg( album ); } tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "sending message" << messageText; QVariantMap hints; hints["desktop-entry"] = QString( "tomahawk" ); // If there is a cover availble use it, else use Tomahawk logo as default. QImage image; if ( map.contains( "coveruri" ) && map[ "coveruri" ].canConvert< QString >() ) image = QImage( map[ "coveruri" ].toString(), "PNG" ); else image = QImage( RESPATH "icons/tomahawk-icon-512x512.png" ); // Convert image to QVariant and scale to a consistent size. hints[ "image_data" ] = ImageConverter::variantForImage( image.scaledToHeight( getNotificationIconHeight() ) ); QDBusPendingReply<> reply = notifications_interface->Notify( TOMAHAWK_APPLICATION_NAME, // app_name m_nowPlayingId, // notification_id "", // app_icon tr( "Tomahawk - Now Playing" ), // summary messageText, // body QStringList(), // actions hints, // hints -1 // expire_timeout ); QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher( reply, this ); connect( watcher, SIGNAL( finished( QDBusPendingCallWatcher* ) ), SLOT( dbusPlayingReplyReceived( QDBusPendingCallWatcher* ) ) ); }
void FdoNotifyPlugin::notifyUser( const QString& messageText ) { QVariantMap hints; hints["desktop-entry"] = QString( "tomahawk" ); hints[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "icons/tomahawk-icon-512x512.png" ).scaledToHeight( getNotificationIconHeight() ) ); notifications_interface->Notify( "Tomahawk", // app_name 0, // notification_id "", // app_icon "Tomahawk", // summary messageText, // body QStringList(), // actions hints, // hints -1 // expire_timeout ); }