1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 16:44:05 +02:00

Update to Snorenotify 0.6

This commit is contained in:
Hannah von Reth
2015-11-05 12:39:48 +01:00
parent 77e5704a2a
commit c838af6d17
4 changed files with 46 additions and 101 deletions

View File

@@ -395,12 +395,8 @@ if( WIN32 )
endif( WIN32 ) endif( WIN32 )
if( WIN32 OR APPLE ) if( WIN32 OR APPLE )
if( TOMAHAWK_QT5 ) macro_optional_find_package(LibsnoreQt5 0.5.70 QUIET)
macro_optional_find_package(LibsnoreQt5 QUIET) macro_log_feature(LibsnoreQt5_FOUND "Libsnore" "Library for notifications" "https://projects.kde.org/projects/playground/libs/snorenotify" FALSE "" "")
else()
macro_optional_find_package(Libsnore QUIET)
endif()
macro_log_feature(LIBSNORE_FOUND "Libsnore" "Library for notifications" "https://github.com/TheOneRing/Snorenotify" FALSE "" "")
endif() endif()
find_package(LIBVLC REQUIRED 2.1.0) find_package(LIBVLC REQUIRED 2.1.0)

View File

@@ -3,17 +3,15 @@ include_directories(
${Boost_INCLUDE_DIR} ${Boost_INCLUDE_DIR}
) )
if(WIN32 OR APPLE) if(WIN32 OR APPLE)
if(BUILD_GUI AND LIBSNORE_FOUND) if(BUILD_GUI AND LibsnoreQt5_FOUND)
SET(snore_srcs SET(snore_srcs
snorenotify/SnoreNotifyPlugin.cpp snorenotify/SnoreNotifyPlugin.cpp
) )
SET(SNORE_LINK_LIBRARIES ${LINK_LIBRARIES} ${LIBSNORE_LIBRARIES} )
tomahawk_add_plugin(snorenotify tomahawk_add_plugin(snorenotify
TYPE infoplugin EXPORT_MACRO INFOPLUGINDLLEXPORT_PRO TYPE infoplugin EXPORT_MACRO INFOPLUGINDLLEXPORT_PRO
SOURCES "${snore_srcs}" LINK_LIBRARIES "${SNORE_LINK_LIBRARIES}" SOURCES "${snore_srcs}" LINK_LIBRARIES Snore::Libsnore
) )
endif(BUILD_GUI AND LIBSNORE_FOUND) endif()
endif(WIN32 OR APPLE) endif(WIN32 OR APPLE)
list(APPEND simple_plugins list(APPEND simple_plugins

View File

@@ -1,6 +1,6 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2013-2014, Patrick von Reth <vonreth@kde.org> * Copyright 2013-2015, Hannah von Reth <vonreth@kde.org>
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org> * Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
* *
@@ -27,12 +27,13 @@
#include "TomahawkVersion.h" #include "TomahawkVersion.h"
#include <snore/core/application.h> #include <libsnore/application.h>
#include <snore/core/notification/icon.h> #include <libsnore/notification/icon.h>
#include <QApplication> #include <QApplication>
#include <QImage> #include <QImage>
#include <QPixmap>
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
@@ -61,27 +62,13 @@ SnoreNotifyPlugin::SnoreNotifyPlugin()
tDebug( LOGVERBOSE ) << Q_FUNC_INFO; tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
m_supportedPushTypes << InfoNotifyUser << InfoNowPlaying << InfoTrackUnresolved << InfoNowStopped << InfoInboxReceived; m_supportedPushTypes << InfoNotifyUser << InfoNowPlaying << InfoTrackUnresolved << InfoNowStopped << InfoInboxReceived;
m_snore = new Snore::SnoreCore(); Snore::SnoreCore &snore = Snore::SnoreCore::instance();
m_snore->loadPlugins( Snore::SnorePlugin::BACKEND ); snore.loadPlugins( Snore::SnorePlugin::BACKEND | Snore::SnorePlugin::SECONDARY_BACKEND );
QString backend = qgetenv( "SNORE_BACKEND" ).constData(); snore.setDefaultSettingsValue("Silent", true, Snore::LOCAL_SETTING);
if( backend.isEmpty() )
{
m_snore->setPrimaryNotificationBackend();
}
else
{
if( !m_snore->setPrimaryNotificationBackend( backend ) )
{
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Ivalid or unavailible Snore backend: " << backend << " availible backens: " << m_snore->notificationBackends();
m_snore->setPrimaryNotificationBackend();
}
}
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << m_snore->primaryNotificationBackend();
m_application = Snore::Application( qApp->applicationName(), m_defaultIcon ); m_application = Snore::Application( qApp->applicationName(), m_defaultIcon );
m_application.hints().setValue( "windows_app_id", TOMAHAWK_APPLICATION_PACKAGE_NAME ); m_application.hints().setValue( "use-markup", true );
m_application.hints().setValue( "windows-app-id", TOMAHAWK_APPLICATION_PACKAGE_NAME );
m_application.hints().setValue( "desktop-entry", TOMAHAWK_APPLICATION_NAME ); m_application.hints().setValue( "desktop-entry", TOMAHAWK_APPLICATION_NAME );
addAlert( InfoNotifyUser, tr( "Notify User" ) ); addAlert( InfoNotifyUser, tr( "Notify User" ) );
@@ -90,9 +77,10 @@ SnoreNotifyPlugin::SnoreNotifyPlugin()
addAlert( InfoNowStopped, tr( "Playback Stopped" ) ); addAlert( InfoNowStopped, tr( "Playback Stopped" ) );
addAlert( InfoInboxReceived, tr( "You received a Song recommendation" ) ); addAlert( InfoInboxReceived, tr( "You received a Song recommendation" ) );
m_snore->registerApplication( m_application ); snore.registerApplication( m_application );
snore.setDefaultApplication( m_application );
connect( m_snore, SIGNAL( actionInvoked( Snore::Notification ) ), this, SLOT( slotActionInvoked( Snore::Notification ) ) ); connect( &snore, SIGNAL( actionInvoked( Snore::Notification ) ), this, SLOT( slotActionInvoked( Snore::Notification ) ) );
} }
@@ -100,8 +88,7 @@ SnoreNotifyPlugin::~SnoreNotifyPlugin()
{ {
tDebug( LOGVERBOSE ) << Q_FUNC_INFO; tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
m_snore->deregisterApplication( m_application ); Snore::SnoreCore::instance().deregisterApplication( m_application );
m_snore->deleteLater();
} }
void void
@@ -111,25 +98,19 @@ SnoreNotifyPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData )
if ( !TomahawkSettings::instance()->songChangeNotificationEnabled() ) if ( !TomahawkSettings::instance()->songChangeNotificationEnabled() )
return; return;
if( m_snore->primaryNotificationBackend().isNull() )
{
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "no notification backend set";
return;
}
switch ( pushData.type ) switch ( pushData.type )
{ {
case Tomahawk::InfoSystem::InfoTrackUnresolved: case Tomahawk::InfoSystem::InfoTrackUnresolved:
notifyUser( Tomahawk::InfoSystem::InfoTrackUnresolved, tr( "The current track could not be resolved. %applicationName will pick back up with the next resolvable track from this source." ) ); notifyUser( Tomahawk::InfoSystem::InfoTrackUnresolved, tr( "The current track could not be resolved. %applicationName will pick back up with the next resolvable track from this source." ), m_defaultIcon );
return; return;
case Tomahawk::InfoSystem::InfoNotifyUser: case Tomahawk::InfoSystem::InfoNotifyUser:
notifyUser( Tomahawk::InfoSystem::InfoNotifyUser,pushData.infoPair.second.toString() ); notifyUser( Tomahawk::InfoSystem::InfoNotifyUser,pushData.infoPair.second.toString(), m_defaultIcon );
return; return;
case Tomahawk::InfoSystem::InfoNowStopped: case Tomahawk::InfoSystem::InfoNowStopped:
notifyUser( Tomahawk::InfoSystem::InfoNowStopped, tr( "%applicationName stopped playback." ) ); notifyUser( Tomahawk::InfoSystem::InfoNowStopped, tr( "%applicationName stopped playback." ), m_defaultIcon );
return; return;
case Tomahawk::InfoSystem::InfoNowPlaying: case Tomahawk::InfoSystem::InfoNowPlaying:
@@ -157,15 +138,10 @@ SnoreNotifyPlugin::slotActionInvoked( Snore::Notification n )
void void
SnoreNotifyPlugin::notifyUser( Tomahawk::InfoSystem::InfoType type, const QString& messageText, Snore::Icon icon ) SnoreNotifyPlugin::notifyUser( Tomahawk::InfoSystem::InfoType type, const QString& messageText, Snore::Icon icon )
{ {
if(!icon.isValid())
{
icon = m_defaultIcon;
}
const Snore::Alert &alert = m_alerts[ type ]; const Snore::Alert &alert = m_alerts[ type ];
Snore::Notification n( m_application , alert, alert.name(), messageText, icon ); Snore::Notification n( m_application , alert, alert.name(), messageText, icon );
m_snore->broadcastNotification( n ); Snore::SnoreCore::instance().broadcastNotification( n );
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "showing notification:" << messageText; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "showing notification:" << messageText;
} }
void void
@@ -194,8 +170,7 @@ SnoreNotifyPlugin::nowPlaying( const QVariant& input )
QString messageText; QString messageText;
// If the window manager supports notification styling then use it. // If the window manager supports notification styling then use it.
if ( m_snore->primaryBackendSupportsRichtext() )
{
// Remark: If using xml-based markup in notifications, the supplied strings need to be escaped. // Remark: If using xml-based markup in notifications, the supplied strings need to be escaped.
QString album; QString album;
if ( !hash[ "album" ].isEmpty() ) if ( !hash[ "album" ].isEmpty() )
@@ -209,26 +184,14 @@ SnoreNotifyPlugin::nowPlaying( const QVariant& input )
// Dirty hack(TM) so that KNotify/QLabel recognizes the message as Rich Text // Dirty hack(TM) so that KNotify/QLabel recognizes the message as Rich Text
messageText = QString( "<i></i>%1" ).arg( messageText ); 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; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "sending message" << messageText;
// If there is a cover availble use it, else use Tomahawk logo as default. // If there is a cover availble use it, else use Tomahawk logo as default.
Snore::Icon image; Snore::Icon image = m_defaultIcon;
if ( map.contains( "cover" ) && map[ "cover" ].canConvert< QImage >() ) if ( map.contains( "cover" ) && map[ "cover" ].canConvert< QImage >() )
{ {
image = Snore::Icon( map[ "cover" ].value< QImage >() ); image = Snore::Icon( QPixmap::fromImage( map[ "cover" ].value< QImage >() ) );
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << image; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << image;
} }
notifyUser( InfoNowPlaying, messageText, image ); notifyUser( InfoNowPlaying, messageText, image );
@@ -259,9 +222,6 @@ SnoreNotifyPlugin::inboxReceived( const QVariant& input )
return; return;
QString messageText; QString messageText;
// If the window manager supports notification styling then use it.
if ( m_snore->primaryBackendSupportsRichtext() )
{
// Remark: If using xml-based markup in notifications, the supplied strings need to be escaped. // 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)" ) 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( src["friendlyname"] ) )
@@ -271,14 +231,6 @@ SnoreNotifyPlugin::inboxReceived( const QVariant& input )
// Dirty hack(TM) so that KNotify/QLabel recognizes the message as Rich Text // Dirty hack(TM) so that KNotify/QLabel recognizes the message as Rich Text
messageText = QString( "<i></i>%1" ).arg( messageText ); 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" ] );
}
Snore::Icon icon( RESPATH "images/inbox-512x512.png" ); Snore::Icon icon( RESPATH "images/inbox-512x512.png" );
notifyUser( Tomahawk::InfoSystem::InfoInboxReceived, messageText, icon ); notifyUser( Tomahawk::InfoSystem::InfoInboxReceived, messageText, icon );

View File

@@ -1,6 +1,6 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2013-2014, Patrick von Reth <vonreth@kde.org> * Copyright 2013-2015, Hannah von Reth <vonreth@kde.org>
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org> * Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
* *
@@ -24,7 +24,7 @@
#include "../../InfoPluginDllMacro.h" #include "../../InfoPluginDllMacro.h"
#include "infosystem/InfoSystem.h" #include "infosystem/InfoSystem.h"
#include <snore/core/snore.h> #include <libsnore/snore.h>
namespace Tomahawk namespace Tomahawk
{ {
@@ -63,9 +63,8 @@ protected slots:
void slotActionInvoked(Snore::Notification n); void slotActionInvoked(Snore::Notification n);
private: private:
void notifyUser( InfoType type, const QString &messageText, Snore::Icon icon = Snore::Icon() ); void notifyUser( InfoType type, const QString &messageText, Snore::Icon icon );
void addAlert( Tomahawk::InfoSystem::InfoType type, const QString &title ); void addAlert( Tomahawk::InfoSystem::InfoType type, const QString &title );
Snore::SnoreCore *m_snore;
Snore::Application m_application; Snore::Application m_application;
Snore::Icon m_defaultIcon; Snore::Icon m_defaultIcon;
QHash< Tomahawk::InfoSystem::InfoType, Snore::Alert > m_alerts; QHash< Tomahawk::InfoSystem::InfoType, Snore::Alert > m_alerts;