From c838af6d178004c1060dd469194e1a32f7183e4e Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Thu, 5 Nov 2015 12:39:48 +0100 Subject: [PATCH] Update to Snorenotify 0.6 --- CMakeLists.txt | 8 +- src/infoplugins/generic/CMakeLists.txt | 8 +- .../generic/snorenotify/SnoreNotifyPlugin.cpp | 124 ++++++------------ .../generic/snorenotify/SnoreNotifyPlugin.h | 7 +- 4 files changed, 46 insertions(+), 101 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7098f2e2a..2eedd5e4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -395,12 +395,8 @@ if( WIN32 ) endif( WIN32 ) if( WIN32 OR APPLE ) -if( TOMAHAWK_QT5 ) - macro_optional_find_package(LibsnoreQt5 QUIET) -else() - macro_optional_find_package(Libsnore QUIET) -endif() - macro_log_feature(LIBSNORE_FOUND "Libsnore" "Library for notifications" "https://github.com/TheOneRing/Snorenotify" FALSE "" "") + macro_optional_find_package(LibsnoreQt5 0.5.70 QUIET) + macro_log_feature(LibsnoreQt5_FOUND "Libsnore" "Library for notifications" "https://projects.kde.org/projects/playground/libs/snorenotify" FALSE "" "") endif() find_package(LIBVLC REQUIRED 2.1.0) diff --git a/src/infoplugins/generic/CMakeLists.txt b/src/infoplugins/generic/CMakeLists.txt index d863fabc4..af1c0cfaa 100644 --- a/src/infoplugins/generic/CMakeLists.txt +++ b/src/infoplugins/generic/CMakeLists.txt @@ -3,17 +3,15 @@ include_directories( ${Boost_INCLUDE_DIR} ) if(WIN32 OR APPLE) -if(BUILD_GUI AND LIBSNORE_FOUND) +if(BUILD_GUI AND LibsnoreQt5_FOUND) SET(snore_srcs snorenotify/SnoreNotifyPlugin.cpp ) - SET(SNORE_LINK_LIBRARIES ${LINK_LIBRARIES} ${LIBSNORE_LIBRARIES} ) - tomahawk_add_plugin(snorenotify 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) list(APPEND simple_plugins diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp index 2f9581cc9..b4858c4f1 100644 --- a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp @@ -1,6 +1,6 @@ /* === This file is part of Tomahawk Player - === * - * Copyright 2013-2014, Patrick von Reth + * Copyright 2013-2015, Hannah von Reth * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2012, Jeff Mitchell * @@ -27,12 +27,13 @@ #include "TomahawkVersion.h" -#include -#include +#include +#include #include #include +#include #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) @@ -61,27 +62,13 @@ SnoreNotifyPlugin::SnoreNotifyPlugin() tDebug( LOGVERBOSE ) << Q_FUNC_INFO; m_supportedPushTypes << InfoNotifyUser << InfoNowPlaying << InfoTrackUnresolved << InfoNowStopped << InfoInboxReceived; - m_snore = new Snore::SnoreCore(); - m_snore->loadPlugins( Snore::SnorePlugin::BACKEND ); - QString backend = qgetenv( "SNORE_BACKEND" ).constData(); - - 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(); + Snore::SnoreCore &snore = Snore::SnoreCore::instance(); + snore.loadPlugins( Snore::SnorePlugin::BACKEND | Snore::SnorePlugin::SECONDARY_BACKEND ); + snore.setDefaultSettingsValue("Silent", true, Snore::LOCAL_SETTING); 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 ); addAlert( InfoNotifyUser, tr( "Notify User" ) ); @@ -90,9 +77,10 @@ SnoreNotifyPlugin::SnoreNotifyPlugin() addAlert( InfoNowStopped, tr( "Playback Stopped" ) ); 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; - m_snore->deregisterApplication( m_application ); - m_snore->deleteLater(); + Snore::SnoreCore::instance().deregisterApplication( m_application ); } void @@ -111,25 +98,19 @@ SnoreNotifyPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData ) if ( !TomahawkSettings::instance()->songChangeNotificationEnabled() ) return; - if( m_snore->primaryNotificationBackend().isNull() ) - { - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "no notification backend set"; - return; - } - switch ( pushData.type ) { 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; case Tomahawk::InfoSystem::InfoNotifyUser: - notifyUser( Tomahawk::InfoSystem::InfoNotifyUser,pushData.infoPair.second.toString() ); + notifyUser( Tomahawk::InfoSystem::InfoNotifyUser,pushData.infoPair.second.toString(), m_defaultIcon ); return; case Tomahawk::InfoSystem::InfoNowStopped: - notifyUser( Tomahawk::InfoSystem::InfoNowStopped, tr( "%applicationName stopped playback." ) ); + notifyUser( Tomahawk::InfoSystem::InfoNowStopped, tr( "%applicationName stopped playback." ), m_defaultIcon ); return; case Tomahawk::InfoSystem::InfoNowPlaying: @@ -157,15 +138,10 @@ SnoreNotifyPlugin::slotActionInvoked( Snore::Notification n ) void 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 ]; 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; - } void @@ -194,41 +170,28 @@ SnoreNotifyPlugin::nowPlaying( const QVariant& input ) 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. - QString album; - if ( !hash[ "album" ].isEmpty() ) - album = QString( "
%1 %2" ).arg( tr( "on", "'on' is followed by an album name" ) ).arg( Qt::escape( 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( Qt::escape( hash[ "title" ] ) ) - .arg( Qt::escape( hash[ "artist" ] ) ) - .arg( album ) - .arg( QString( "
%1" ).arg( tr( "by", "preposition to link track and artist" ) ) ); + // Remark: If using xml-based markup in notifications, the supplied strings need to be escaped. + QString album; + if ( !hash[ "album" ].isEmpty() ) + album = QString( "
%1 %2" ).arg( tr( "on", "'on' is followed by an album name" ) ).arg( Qt::escape( hash[ "album" ] ) ); - // Dirty hack(TM) so that KNotify/QLabel recognizes the message as Rich Text - messageText = QString( "%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%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( Qt::escape( hash[ "title" ] ) ) + .arg( Qt::escape( hash[ "artist" ] ) ) + .arg( album ) + .arg( QString( "
%1" ).arg( tr( "by", "preposition to link track and artist" ) ) ); - 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 ); - } + // Dirty hack(TM) so that KNotify/QLabel recognizes the message as Rich Text + messageText = QString( "%1" ).arg( messageText ); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "sending message" << messageText; // 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 >() ) { - image = Snore::Icon( map[ "cover" ].value< QImage >() ); + image = Snore::Icon( QPixmap::fromImage( map[ "cover" ].value< QImage >() ) ); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << image; } notifyUser( InfoNowPlaying, messageText, image ); @@ -259,26 +222,15 @@ SnoreNotifyPlugin::inboxReceived( const QVariant& input ) return; 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. - 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%1" ).arg( tr( "by", "preposition to link track and artist" ) ) ); + // 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%1" ).arg( tr( "by", "preposition to link track and artist" ) ) ); - // Dirty hack(TM) so that KNotify/QLabel recognizes the message as Rich Text - messageText = QString( "%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" ] ); - } + // Dirty hack(TM) so that KNotify/QLabel recognizes the message as Rich Text + messageText = QString( "%1" ).arg( messageText ); Snore::Icon icon( RESPATH "images/inbox-512x512.png" ); notifyUser( Tomahawk::InfoSystem::InfoInboxReceived, messageText, icon ); diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h index fad820c79..ed2ea65a5 100644 --- a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h @@ -1,6 +1,6 @@ /* === This file is part of Tomahawk Player - === * - * Copyright 2013-2014, Patrick von Reth + * Copyright 2013-2015, Hannah von Reth * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Jeff Mitchell * @@ -24,7 +24,7 @@ #include "../../InfoPluginDllMacro.h" #include "infosystem/InfoSystem.h" -#include +#include namespace Tomahawk { @@ -63,9 +63,8 @@ protected slots: void slotActionInvoked(Snore::Notification n); 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 ); - Snore::SnoreCore *m_snore; Snore::Application m_application; Snore::Icon m_defaultIcon; QHash< Tomahawk::InfoSystem::InfoType, Snore::Alert > m_alerts;