From 3f1a5e1c3b62ad8aa9a46f50c45a03fe208338b3 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Tue, 23 Jul 2013 21:17:42 +0200 Subject: [PATCH 01/16] added snorenotification support, this adds growl(on windows and mac), windows 8 and snarl nottification support --- src/infoplugins/generic/CMakeLists.txt | 14 + .../generic/snorenotify/SnoreNotifyPlugin.cpp | 285 ++++++++++++++++++ .../generic/snorenotify/SnoreNotifyPlugin.h | 83 +++++ 3 files changed, 382 insertions(+) create mode 100644 src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp create mode 100644 src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h diff --git a/src/infoplugins/generic/CMakeLists.txt b/src/infoplugins/generic/CMakeLists.txt index 549c32756..94ea682bd 100644 --- a/src/infoplugins/generic/CMakeLists.txt +++ b/src/infoplugins/generic/CMakeLists.txt @@ -2,6 +2,20 @@ include_directories( ${ECHONEST_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ) +if(WIN32 OR APPLE) +find_package(Libsnore) +if(BUILD_GUI AND LIBSNORE_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}" + ) +endif(BUILD_GUI AND LIBSNORE_FOUND) +endif(WIN32 OR APPLE) list(APPEND simple_plugins Echonest diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp new file mode 100644 index 000000000..4550559d4 --- /dev/null +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp @@ -0,0 +1,285 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013 , Patrick von Reth + * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2012, Jeff Mitchell + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +// Marked portions of this file are subject to the following copyright: +/* + * Copyright (C) 2009 by Aur??lien G??teau + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "SnoreNotifyPlugin.h" + + +#include "TomahawkSettings.h" + +#include "utils/TomahawkUtils.h" +#include "utils/Logger.h" +#include "utils/TomahawkUtilsGui.h" + +#include +#include + +#include + +#include +// QTextDocument provides Qt::escape() +#include + +namespace Tomahawk +{ + +namespace InfoSystem +{ + +SnoreNotifyPlugin::SnoreNotifyPlugin() + : InfoPlugin(), + m_defaultIcon( RESPATH "icons/tomahawk-icon-512x512.png" ) +{ + tDebug( LOGVERBOSE ) << Q_FUNC_INFO; + m_supportedPushTypes << InfoNotifyUser << InfoNowPlaying << InfoTrackUnresolved << InfoNowStopped << InfoInboxReceived; + + m_snore = new Snore::SnoreCore(); + m_snore->loadPlugins( Snore::PluginContainer::BACKEND ); + QString backend = qgetenv( "SNORE_BACKEND" ).constData(); + backend.isEmpty()?m_snore->setPrimaryNotificationBackend():m_snore->setPrimaryNotificationBackend(backend); + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << m_snore->primaryNotificationBackend(); + m_application = new Snore::Application( qApp->applicationName(), m_defaultIcon ); + + m_snore->addApplication(m_application); + m_snore->applicationIsInitialized(m_application); + + addAlert( InfoNotifyUser,tr("Notify User") ); + addAlert( InfoNowPlaying,tr("Now Playing") ); + addAlert( InfoTrackUnresolved, tr("Unresolved track") ); + addAlert( InfoNowStopped, tr("Playback Stopped") ); + addAlert( InfoInboxReceived, tr("You recived a Song recomondation") ); + + connect(m_snore,SIGNAL(actionInvoked(Snore::Notification)),this,SLOT(slotActionInvoked(Snore::Notification))); + + +} + + +SnoreNotifyPlugin::~SnoreNotifyPlugin() +{ + tDebug( LOGVERBOSE ) << Q_FUNC_INFO; + m_snore->deleteLater(); + m_application->deleteLater(); + + foreach(Snore::Alert *alert,m_alerts) + { + alert->deleteLater(); + } +} + +void +SnoreNotifyPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData ) +{ + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "showing notification:" << TomahawkSettings::instance()->songChangeNotificationEnabled(); + if ( !TomahawkSettings::instance()->songChangeNotificationEnabled() ) + return; + + + switch ( pushData.type ) + { + case Tomahawk::InfoSystem::InfoTrackUnresolved: + notifyUser( Tomahawk::InfoSystem::InfoTrackUnresolved,"The current track could not be resolved. Tomahawk will pick back up with the next resolvable track from this source." ); + return; + + case Tomahawk::InfoSystem::InfoNotifyUser: + notifyUser( Tomahawk::InfoSystem::InfoNotifyUser,pushData.infoPair.second.toString() ); + return; + + case Tomahawk::InfoSystem::InfoNowStopped: + notifyUser( Tomahawk::InfoSystem::InfoNowStopped, "Tomahawk stopped playback." ); + return; + + case Tomahawk::InfoSystem::InfoNowPlaying: + nowPlaying( pushData.infoPair.second ); + return; + + case Tomahawk::InfoSystem::InfoInboxReceived: + inboxReceived( pushData.infoPair.second ); + return; + + default: + return; + } + +} + +void +SnoreNotifyPlugin::slotActionInvoked( Snore::Notification n ) +{ + Q_UNUSED(n) + TomahawkUtils::bringToFront(); +} + + +void +SnoreNotifyPlugin::notifyUser( Tomahawk::InfoSystem::InfoType type, const QString& messageText, Snore::Icon icon ) +{ + if(!icon.isValid()) + { + icon = m_defaultIcon; + } + Snore::Alert *alert = m_alerts[type]; + Snore::Notification n( qApp->applicationName(), alert->name(), alert->title(), messageText, icon ); + m_snore->broadcastNotification(n); + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "showing notification:" << messageText; + +} + +void +SnoreNotifyPlugin::addAlert( Tomahawk::InfoSystem::InfoType type, const QString &title ) +{ + Snore::Alert *alert = new Snore::Alert( title, title, m_defaultIcon ); + m_application->addAlert( alert ); + m_alerts[ type ] = alert; +} + +void +SnoreNotifyPlugin::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_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( "\n%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( "\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 + { + 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; + + // If there is a cover availble use it, else use Tomahawk logo as default. + Snore::Icon image; + if ( map.contains( "coveruri" ) && map[ "coveruri" ].canConvert< QString >() ) + { + image = Snore::Icon( QImage(map[ "coveruri" ].toString(),"PNG")); + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << map[ "coveruri" ].toString(); + } + notifyUser( InfoNowPlaying, messageText, image ); +} + + + +void +SnoreNotifyPlugin::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_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" ) ) ); + + // 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" ] ); + } + + Snore::Icon icon( RESPATH "images/inbox-512x512.png" ); + notifyUser( Tomahawk::InfoSystem::InfoNowPlaying, messageText, icon ); +} + + +} //ns InfoSystem + +} //ns Tomahawk + +Q_EXPORT_PLUGIN2( Tomahawk::InfoSystem::InfoPlugin, Tomahawk::InfoSystem::SnoreNotifyPlugin ) diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h new file mode 100644 index 000000000..45ea97495 --- /dev/null +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h @@ -0,0 +1,83 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013 , Patrick von Reth + * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2011, Jeff Mitchell + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef SNORENOTIFYPLUGIN_H +#define SNORENOTIFYPLUGIN_H + +#include "../../InfoPluginDllMacro.h" + +#include "infosystem/InfoSystem.h" +#include + +class QDBusPendingCallWatcher; + +namespace Tomahawk +{ + +namespace InfoSystem +{ + +class INFOPLUGINDLLEXPORT SnoreNotifyPlugin : public InfoPlugin +{ + Q_PLUGIN_METADATA( IID "org.tomahawk-player.Player.InfoPlugin" ) + Q_OBJECT + Q_INTERFACES( Tomahawk::InfoSystem::InfoPlugin ) + +public: + SnoreNotifyPlugin(); + virtual ~SnoreNotifyPlugin(); + + +protected slots: + virtual void init() {} + + virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) + { + Q_UNUSED( requestData ); + } + + virtual void pushInfo( Tomahawk::InfoSystem::InfoPushData pushData ); + + virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) + { + Q_UNUSED( criteria ); + Q_UNUSED( requestData ); + } + +protected slots: + void slotActionInvoked(Snore::Notification n); + +private: + void notifyUser(InfoType type, const QString &messageText, Snore::Icon icon = Snore::Icon()); + void addAlert(Tomahawk::InfoSystem::InfoType type,const QString &title); + Snore::SnoreCore *m_snore; + Snore::Application *m_application; + Snore::Icon m_defaultIcon; + QHash m_alerts; + + void nowPlaying(const QVariant &input); + void inboxReceived(const QVariant &input); +}; + +} + +} + +#endif // SNORENOTIFYPLUGIN_H From 501a72d79b601801924d480617fdd2fe51dedb3d Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Tue, 23 Jul 2013 22:00:42 +0200 Subject: [PATCH 02/16] style fixes --- .../generic/snorenotify/SnoreNotifyPlugin.cpp | 26 +++++++++---------- .../generic/snorenotify/SnoreNotifyPlugin.h | 10 +++---- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp index 4550559d4..acb013e0a 100644 --- a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp @@ -72,20 +72,20 @@ SnoreNotifyPlugin::SnoreNotifyPlugin() m_snore = new Snore::SnoreCore(); m_snore->loadPlugins( Snore::PluginContainer::BACKEND ); QString backend = qgetenv( "SNORE_BACKEND" ).constData(); - backend.isEmpty()?m_snore->setPrimaryNotificationBackend():m_snore->setPrimaryNotificationBackend(backend); + backend.isEmpty()?m_snore->setPrimaryNotificationBackend():m_snore->setPrimaryNotificationBackend( backend ); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << m_snore->primaryNotificationBackend(); m_application = new Snore::Application( qApp->applicationName(), m_defaultIcon ); - m_snore->addApplication(m_application); - m_snore->applicationIsInitialized(m_application); + m_snore->addApplication( m_application ); + m_snore->applicationIsInitialized( m_application ); - addAlert( InfoNotifyUser,tr("Notify User") ); - addAlert( InfoNowPlaying,tr("Now Playing") ); - addAlert( InfoTrackUnresolved, tr("Unresolved track") ); - addAlert( InfoNowStopped, tr("Playback Stopped") ); - addAlert( InfoInboxReceived, tr("You recived a Song recomondation") ); + addAlert( InfoNotifyUser, tr( "Notify User" ) ); + addAlert( InfoNowPlaying, tr( "Now Playing" ) ); + addAlert( InfoTrackUnresolved, tr( "Unresolved track" ) ); + addAlert( InfoNowStopped, tr( "Playback Stopped" ) ); + addAlert( InfoInboxReceived, tr( "You recived a Song recomondation" ) ); - connect(m_snore,SIGNAL(actionInvoked(Snore::Notification)),this,SLOT(slotActionInvoked(Snore::Notification))); + connect( m_snore, SIGNAL( actionInvoked( Snore::Notification ) ), this, SLOT( slotActionInvoked( Snore::Notification ) ) ); } @@ -97,7 +97,7 @@ SnoreNotifyPlugin::~SnoreNotifyPlugin() m_snore->deleteLater(); m_application->deleteLater(); - foreach(Snore::Alert *alert,m_alerts) + foreach( Snore::Alert* alert, m_alerts ) { alert->deleteLater(); } @@ -154,9 +154,9 @@ SnoreNotifyPlugin::notifyUser( Tomahawk::InfoSystem::InfoType type, const QStrin { icon = m_defaultIcon; } - Snore::Alert *alert = m_alerts[type]; + Snore::Alert* alert = m_alerts[ type ]; Snore::Notification n( qApp->applicationName(), alert->name(), alert->title(), messageText, icon ); - m_snore->broadcastNotification(n); + m_snore->broadcastNotification( n ); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "showing notification:" << messageText; } @@ -164,7 +164,7 @@ SnoreNotifyPlugin::notifyUser( Tomahawk::InfoSystem::InfoType type, const QStrin void SnoreNotifyPlugin::addAlert( Tomahawk::InfoSystem::InfoType type, const QString &title ) { - Snore::Alert *alert = new Snore::Alert( title, title, m_defaultIcon ); + Snore::Alert* alert = new Snore::Alert( title, title, m_defaultIcon ); m_application->addAlert( alert ); m_alerts[ type ] = alert; } diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h index 45ea97495..1c6b046ff 100644 --- a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h @@ -65,15 +65,15 @@ protected slots: void slotActionInvoked(Snore::Notification n); private: - void notifyUser(InfoType type, const QString &messageText, Snore::Icon icon = Snore::Icon()); - void addAlert(Tomahawk::InfoSystem::InfoType type,const QString &title); + void notifyUser( InfoType type, const QString &messageText, Snore::Icon icon = Snore::Icon() ); + void addAlert( Tomahawk::InfoSystem::InfoType type, const QString &title ); Snore::SnoreCore *m_snore; Snore::Application *m_application; Snore::Icon m_defaultIcon; - QHash m_alerts; + QHash< Tomahawk::InfoSystem::InfoType, Snore::Alert* > m_alerts; - void nowPlaying(const QVariant &input); - void inboxReceived(const QVariant &input); + void nowPlaying( const QVariant &input ); + void inboxReceived( const QVariant &input ); }; } From 25fae630884f279517ee773a05173a4c8b3ce4e5 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Wed, 24 Jul 2013 10:33:45 +0200 Subject: [PATCH 03/16] more style fixes --- CMakeLists.txt | 5 ++ CMakeModules/FindLibsnore.cmake | 48 +++++++++++++++++ src/infoplugins/generic/CMakeLists.txt | 1 - .../generic/snorenotify/SnoreNotifyPlugin.cpp | 51 +++++++++++-------- 4 files changed, 82 insertions(+), 23 deletions(-) create mode 100644 CMakeModules/FindLibsnore.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a353e191..18e2cf624 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -297,6 +297,11 @@ if( WIN32 ) macro_log_feature(QTSPARKLE_FOUND "qtsparkle" "Library for creating auto updaters written in Qt" "https://github.com/davidsansome/qtsparkle" FALSE "" "") endif( WIN32 ) +if( WIN32 OR APPLE ) + macro_optional_find_package(Libsnore) + macro_log_feature(LIBSNORE_FOUND "SnoreNotify" "Library for notifications" "https://github.com/TheOneRing/Snorenotify" FALSE "" "") +endif() + #TODO: support external qxt set(QXTWEB_FOUND TRUE) set(QXTWEB_LIBRARIES qxtweb-standalone) diff --git a/CMakeModules/FindLibsnore.cmake b/CMakeModules/FindLibsnore.cmake new file mode 100644 index 000000000..9c46d16fe --- /dev/null +++ b/CMakeModules/FindLibsnore.cmake @@ -0,0 +1,48 @@ +######################################################################################## +# Copyright (c) 2010 Patrick von Reth # +# # +# This program is free software; you can redistribute it and/or modify it under # +# the terms of the GNU General Public License as published by the Free Software # +# Foundation; either version 2 of the License, or (at your option) any later # +# version. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT ANY # +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A # +# PARTICULAR PURPOSE. See the GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License along with # +# this program. If not, see . # +######################################################################################## + +# - Try to find the libsnore library +# Once done this will define +# +# LIBSNORE_FOUND - system has the LIBSNORE library +# LIBSNORE_LIBRARIES - The libraries needed to use LIBSNORE +# LIBSNORE_PLUGIN_PATH - Path of the plugins + +find_path(LIBSNORE_INCLUDE_DIR + NAMES snore/core/snore.h + PATHS ${KDE4_INCLUDE_DIR} +) + +find_library(LIBSNORE_LIBRARY + NAMES + libsnore + snore + PATHS ${KDE4_LIB_DIR} +) + +find_path(LIBSNORE_PLUGIN_PATH snoreplugins) + +if(LIBSNORE_LIBRARY AND LIBSNORE_PLUGIN_PATH) + set(LIBSNORE_PLUGIN_PATH ${LIBSNORE_PLUGIN_PATH}/snoreplugins) +endif() + +set(LIBSNORE_LIBRARIES ${LIBSNORE_LIBRARY}) +set(LIBSNORE_INCLUDE_DIRS ${LIBSNORE_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(LIBSNORE DEFAULT_MSG LIBSNORE_LIBRARIES LIBSNORE_INCLUDE_DIRS) + +mark_as_advanced(LIBSNORE_LIBRARIES LIBSNORE_INCLUDE_DIRS) diff --git a/src/infoplugins/generic/CMakeLists.txt b/src/infoplugins/generic/CMakeLists.txt index 94ea682bd..d863fabc4 100644 --- a/src/infoplugins/generic/CMakeLists.txt +++ b/src/infoplugins/generic/CMakeLists.txt @@ -3,7 +3,6 @@ include_directories( ${Boost_INCLUDE_DIR} ) if(WIN32 OR APPLE) -find_package(Libsnore) if(BUILD_GUI AND LIBSNORE_FOUND) SET(snore_srcs snorenotify/SnoreNotifyPlugin.cpp diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp index acb013e0a..cc8521f95 100644 --- a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp @@ -72,10 +72,19 @@ SnoreNotifyPlugin::SnoreNotifyPlugin() m_snore = new Snore::SnoreCore(); m_snore->loadPlugins( Snore::PluginContainer::BACKEND ); QString backend = qgetenv( "SNORE_BACKEND" ).constData(); - backend.isEmpty()?m_snore->setPrimaryNotificationBackend():m_snore->setPrimaryNotificationBackend( backend ); - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << m_snore->primaryNotificationBackend(); - m_application = new Snore::Application( qApp->applicationName(), m_defaultIcon ); + if( backend.isEmpty() ) + { + m_snore->setPrimaryNotificationBackend(); + } + else + { + m_snore->setPrimaryNotificationBackend( backend ); + } + + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << m_snore->primaryNotificationBackend(); + + m_application = new Snore::Application( qApp->applicationName(), m_defaultIcon ); m_snore->addApplication( m_application ); m_snore->applicationIsInitialized( m_application ); @@ -86,8 +95,6 @@ SnoreNotifyPlugin::SnoreNotifyPlugin() addAlert( InfoInboxReceived, tr( "You recived a Song recomondation" ) ); connect( m_snore, SIGNAL( actionInvoked( Snore::Notification ) ), this, SLOT( slotActionInvoked( Snore::Notification ) ) ); - - } @@ -113,28 +120,28 @@ SnoreNotifyPlugin::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData ) switch ( pushData.type ) { - case Tomahawk::InfoSystem::InfoTrackUnresolved: - notifyUser( Tomahawk::InfoSystem::InfoTrackUnresolved,"The current track could not be resolved. Tomahawk will pick back up with the next resolvable track from this source." ); - return; + case Tomahawk::InfoSystem::InfoTrackUnresolved: + notifyUser( Tomahawk::InfoSystem::InfoTrackUnresolved,"The current track could not be resolved. Tomahawk will pick back up with the next resolvable track from this source." ); + return; - case Tomahawk::InfoSystem::InfoNotifyUser: - notifyUser( Tomahawk::InfoSystem::InfoNotifyUser,pushData.infoPair.second.toString() ); - return; + case Tomahawk::InfoSystem::InfoNotifyUser: + notifyUser( Tomahawk::InfoSystem::InfoNotifyUser,pushData.infoPair.second.toString() ); + return; - case Tomahawk::InfoSystem::InfoNowStopped: - notifyUser( Tomahawk::InfoSystem::InfoNowStopped, "Tomahawk stopped playback." ); - return; + case Tomahawk::InfoSystem::InfoNowStopped: + notifyUser( Tomahawk::InfoSystem::InfoNowStopped, "Tomahawk stopped playback." ); + return; - case Tomahawk::InfoSystem::InfoNowPlaying: - nowPlaying( pushData.infoPair.second ); - return; + case Tomahawk::InfoSystem::InfoNowPlaying: + nowPlaying( pushData.infoPair.second ); + return; - case Tomahawk::InfoSystem::InfoInboxReceived: - inboxReceived( pushData.infoPair.second ); - return; + case Tomahawk::InfoSystem::InfoInboxReceived: + inboxReceived( pushData.infoPair.second ); + return; - default: - return; + default: + return; } } From 5a6b2ad4adb5a48d1e434d7195ef8a6e8f2c8b54 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Wed, 24 Jul 2013 11:54:15 +0200 Subject: [PATCH 04/16] relicenced find script --- CMakeModules/FindLibsnore.cmake | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/CMakeModules/FindLibsnore.cmake b/CMakeModules/FindLibsnore.cmake index 9c46d16fe..4dc0b9e0b 100644 --- a/CMakeModules/FindLibsnore.cmake +++ b/CMakeModules/FindLibsnore.cmake @@ -1,25 +1,11 @@ -######################################################################################## -# Copyright (c) 2010 Patrick von Reth # -# # -# This program is free software; you can redistribute it and/or modify it under # -# the terms of the GNU General Public License as published by the Free Software # -# Foundation; either version 2 of the License, or (at your option) any later # -# version. # -# # -# This program is distributed in the hope that it will be useful, but WITHOUT ANY # -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A # -# PARTICULAR PURPOSE. See the GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License along with # -# this program. If not, see . # -######################################################################################## - # - Try to find the libsnore library -# Once done this will define +# Once done this will define # # LIBSNORE_FOUND - system has the LIBSNORE library # LIBSNORE_LIBRARIES - The libraries needed to use LIBSNORE +# LIBSNORE_INCLUDE_DIRS - The includes needed to use LIBSNORE # LIBSNORE_PLUGIN_PATH - Path of the plugins +# Copyright 2013 Patrick von Reth find_path(LIBSNORE_INCLUDE_DIR NAMES snore/core/snore.h From 5c6994ae857bdd26814a6431e08b8635c1e54c0b Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Wed, 24 Jul 2013 12:01:59 +0200 Subject: [PATCH 05/16] as sugested by Dominik Schmidt remove the copiright header which was probably related to the dbus code --- .../generic/snorenotify/SnoreNotifyPlugin.cpp | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp index cc8521f95..d86ad0041 100644 --- a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp @@ -18,26 +18,6 @@ * along with Tomahawk. If not, see . */ -// Marked portions of this file are subject to the following copyright: -/* - * Copyright (C) 2009 by Aur??lien G??teau - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - #include "SnoreNotifyPlugin.h" From cdf13725d165174694017d52ff87cdd005d177ff Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Wed, 24 Jul 2013 12:09:19 +0200 Subject: [PATCH 06/16] fixed typo --- src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp index d86ad0041..607a92373 100644 --- a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp @@ -72,7 +72,7 @@ SnoreNotifyPlugin::SnoreNotifyPlugin() addAlert( InfoNowPlaying, tr( "Now Playing" ) ); addAlert( InfoTrackUnresolved, tr( "Unresolved track" ) ); addAlert( InfoNowStopped, tr( "Playback Stopped" ) ); - addAlert( InfoInboxReceived, tr( "You recived a Song recomondation" ) ); + addAlert( InfoInboxReceived, tr( "You received a Song recomondation" ) ); connect( m_snore, SIGNAL( actionInvoked( Snore::Notification ) ), this, SLOT( slotActionInvoked( Snore::Notification ) ) ); } From e9c478be75b421570b5f279c22675bc4a0613923 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Thu, 9 Jan 2014 11:03:40 +0100 Subject: [PATCH 07/16] some fixes --- .../generic/snorenotify/SnoreNotifyPlugin.cpp | 18 ++++++++++++------ .../generic/snorenotify/SnoreNotifyPlugin.h | 4 +--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp index 607a92373..bb9263b77 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 , Patrick von Reth + * Copyright 2013-2014, Patrick von Reth * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2012, Jeff Mitchell * @@ -59,14 +59,16 @@ SnoreNotifyPlugin::SnoreNotifyPlugin() } else { - m_snore->setPrimaryNotificationBackend( backend ); + 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 = new Snore::Application( qApp->applicationName(), m_defaultIcon ); - m_snore->addApplication( m_application ); - m_snore->applicationIsInitialized( m_application ); addAlert( InfoNotifyUser, tr( "Notify User" ) ); addAlert( InfoNowPlaying, tr( "Now Playing" ) ); @@ -74,6 +76,9 @@ SnoreNotifyPlugin::SnoreNotifyPlugin() addAlert( InfoNowStopped, tr( "Playback Stopped" ) ); addAlert( InfoInboxReceived, tr( "You received a Song recomondation" ) ); + m_snore->addApplication( m_application ); + m_snore->applicationIsInitialized( m_application ); + connect( m_snore, SIGNAL( actionInvoked( Snore::Notification ) ), this, SLOT( slotActionInvoked( Snore::Notification ) ) ); } @@ -81,13 +86,14 @@ SnoreNotifyPlugin::SnoreNotifyPlugin() SnoreNotifyPlugin::~SnoreNotifyPlugin() { tDebug( LOGVERBOSE ) << Q_FUNC_INFO; - m_snore->deleteLater(); - m_application->deleteLater(); + m_snore->removeApplication(m_application->name()); foreach( Snore::Alert* alert, m_alerts ) { alert->deleteLater(); } + m_snore->deleteLater(); + m_application->deleteLater(); } void diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h index 1c6b046ff..1240e25ed 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 , Patrick von Reth + * Copyright 2013-2014, Patrick von Reth * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Jeff Mitchell * @@ -26,8 +26,6 @@ #include "infosystem/InfoSystem.h" #include -class QDBusPendingCallWatcher; - namespace Tomahawk { From 68be28cf8188e6b5da36b10c0e419d7b5e80675a Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Thu, 9 Jan 2014 18:05:11 +0100 Subject: [PATCH 08/16] make sure we have a backend set --- src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp index bb9263b77..c312811df 100644 --- a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp @@ -59,7 +59,7 @@ SnoreNotifyPlugin::SnoreNotifyPlugin() } else { - if(!m_snore->setPrimaryNotificationBackend( backend )) + if( !m_snore->setPrimaryNotificationBackend( backend ) ) { tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Ivalid or unavailible Snore backend: " << backend << " availible backens: " << m_snore->notificationBackends(); m_snore->setPrimaryNotificationBackend(); @@ -103,6 +103,12 @@ 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 ) { From d23a9c4fe240d7df04ea5c1018770ecee302ef94 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Sun, 12 Jan 2014 01:42:47 +0100 Subject: [PATCH 09/16] compile with new snore api --- src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp index c312811df..27e1c9e7c 100644 --- a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp @@ -76,8 +76,7 @@ SnoreNotifyPlugin::SnoreNotifyPlugin() addAlert( InfoNowStopped, tr( "Playback Stopped" ) ); addAlert( InfoInboxReceived, tr( "You received a Song recomondation" ) ); - m_snore->addApplication( m_application ); - m_snore->applicationIsInitialized( m_application ); + m_snore->registerApplication( m_application ); connect( m_snore, SIGNAL( actionInvoked( Snore::Notification ) ), this, SLOT( slotActionInvoked( Snore::Notification ) ) ); } @@ -87,7 +86,7 @@ SnoreNotifyPlugin::~SnoreNotifyPlugin() { tDebug( LOGVERBOSE ) << Q_FUNC_INFO; - m_snore->removeApplication(m_application->name()); + m_snore->deregisterApplication( m_application ); foreach( Snore::Alert* alert, m_alerts ) { alert->deleteLater(); From 217c52cf32108e438de00a9be8cef847da3fa193 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Mon, 13 Jan 2014 14:18:02 +0100 Subject: [PATCH 10/16] updated snore api --- .../generic/snorenotify/SnoreNotifyPlugin.cpp | 17 ++++++----------- .../generic/snorenotify/SnoreNotifyPlugin.h | 4 ++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp index 27e1c9e7c..6a6ceea05 100644 --- a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp @@ -50,7 +50,7 @@ SnoreNotifyPlugin::SnoreNotifyPlugin() m_supportedPushTypes << InfoNotifyUser << InfoNowPlaying << InfoTrackUnresolved << InfoNowStopped << InfoInboxReceived; m_snore = new Snore::SnoreCore(); - m_snore->loadPlugins( Snore::PluginContainer::BACKEND ); + m_snore->loadPlugins( Snore::SnorePlugin::BACKEND ); QString backend = qgetenv( "SNORE_BACKEND" ).constData(); if( backend.isEmpty() ) @@ -68,7 +68,7 @@ SnoreNotifyPlugin::SnoreNotifyPlugin() tDebug( LOGVERBOSE ) << Q_FUNC_INFO << m_snore->primaryNotificationBackend(); - m_application = new Snore::Application( qApp->applicationName(), m_defaultIcon ); + m_application = Snore::Application( qApp->applicationName(), m_defaultIcon ); addAlert( InfoNotifyUser, tr( "Notify User" ) ); addAlert( InfoNowPlaying, tr( "Now Playing" ) ); @@ -87,12 +87,7 @@ SnoreNotifyPlugin::~SnoreNotifyPlugin() tDebug( LOGVERBOSE ) << Q_FUNC_INFO; m_snore->deregisterApplication( m_application ); - foreach( Snore::Alert* alert, m_alerts ) - { - alert->deleteLater(); - } m_snore->deleteLater(); - m_application->deleteLater(); } void @@ -152,8 +147,8 @@ SnoreNotifyPlugin::notifyUser( Tomahawk::InfoSystem::InfoType type, const QStrin { icon = m_defaultIcon; } - Snore::Alert* alert = m_alerts[ type ]; - Snore::Notification n( qApp->applicationName(), alert->name(), alert->title(), messageText, icon ); + const Snore::Alert &alert = m_alerts[ type ]; + Snore::Notification n( m_application , alert, alert.title(), messageText, icon ); m_snore->broadcastNotification( n ); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "showing notification:" << messageText; @@ -162,8 +157,8 @@ SnoreNotifyPlugin::notifyUser( Tomahawk::InfoSystem::InfoType type, const QStrin void SnoreNotifyPlugin::addAlert( Tomahawk::InfoSystem::InfoType type, const QString &title ) { - Snore::Alert* alert = new Snore::Alert( title, title, m_defaultIcon ); - m_application->addAlert( alert ); + Snore::Alert alert( title, title, m_defaultIcon ); + m_application.addAlert( alert ); m_alerts[ type ] = alert; } diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h index 1240e25ed..fad820c79 100644 --- a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.h @@ -66,9 +66,9 @@ private: void notifyUser( InfoType type, const QString &messageText, Snore::Icon icon = Snore::Icon() ); 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; - QHash< Tomahawk::InfoSystem::InfoType, Snore::Alert* > m_alerts; + QHash< Tomahawk::InfoSystem::InfoType, Snore::Alert > m_alerts; void nowPlaying( const QVariant &input ); void inboxReceived( const QVariant &input ); From a9c2a3d8c809eebd1c050d5cc17b65bfc614f579 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Sun, 19 Jan 2014 20:08:22 +0100 Subject: [PATCH 11/16] set desktop-entry in notification hints --- src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp index 6a6ceea05..afb279d37 100644 --- a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp @@ -69,6 +69,7 @@ SnoreNotifyPlugin::SnoreNotifyPlugin() tDebug( LOGVERBOSE ) << Q_FUNC_INFO << m_snore->primaryNotificationBackend(); m_application = Snore::Application( qApp->applicationName(), m_defaultIcon ); + m_application.hints().setValue("desktop-entry","tomahawk"); addAlert( InfoNotifyUser, tr( "Notify User" ) ); addAlert( InfoNowPlaying, tr( "Now Playing" ) ); From 341bc6c2cf1fe759151443d31303eacbd43a4e2b Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Mon, 20 Jan 2014 17:11:12 +0100 Subject: [PATCH 12/16] api fix and use the qimage directly instead of loading the tmp file again --- .../generic/snorenotify/SnoreNotifyPlugin.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp index afb279d37..b0f5320b0 100644 --- a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp @@ -149,7 +149,7 @@ SnoreNotifyPlugin::notifyUser( Tomahawk::InfoSystem::InfoType type, const QStrin icon = m_defaultIcon; } const Snore::Alert &alert = m_alerts[ type ]; - Snore::Notification n( m_application , alert, alert.title(), messageText, icon ); + Snore::Notification n( m_application , alert, alert.name(), messageText, icon ); m_snore->broadcastNotification( n ); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "showing notification:" << messageText; @@ -158,7 +158,7 @@ SnoreNotifyPlugin::notifyUser( Tomahawk::InfoSystem::InfoType type, const QStrin void SnoreNotifyPlugin::addAlert( Tomahawk::InfoSystem::InfoType type, const QString &title ) { - Snore::Alert alert( title, title, m_defaultIcon ); + Snore::Alert alert( title, m_defaultIcon ); m_application.addAlert( alert ); m_alerts[ type ] = alert; } @@ -213,10 +213,10 @@ SnoreNotifyPlugin::nowPlaying( const QVariant& input ) // If there is a cover availble use it, else use Tomahawk logo as default. Snore::Icon image; - if ( map.contains( "coveruri" ) && map[ "coveruri" ].canConvert< QString >() ) + if ( map.contains( "cover" ) && map[ "cover" ].canConvert< QImage >() ) { - image = Snore::Icon( QImage(map[ "coveruri" ].toString(),"PNG")); - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << map[ "coveruri" ].toString(); + image = Snore::Icon( map[ "cover" ].value() ); + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << image; } notifyUser( InfoNowPlaying, messageText, image ); } From 2d024af17cc530c1e0abe6d6112dc68c17cc228e Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Tue, 4 Feb 2014 12:36:08 +0100 Subject: [PATCH 13/16] codestyle --- src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp index b0f5320b0..340522871 100644 --- a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp @@ -69,7 +69,7 @@ SnoreNotifyPlugin::SnoreNotifyPlugin() tDebug( LOGVERBOSE ) << Q_FUNC_INFO << m_snore->primaryNotificationBackend(); m_application = Snore::Application( qApp->applicationName(), m_defaultIcon ); - m_application.hints().setValue("desktop-entry","tomahawk"); + m_application.hints().setValue( "desktop-entry" ,"tomahawk" ); addAlert( InfoNotifyUser, tr( "Notify User" ) ); addAlert( InfoNowPlaying, tr( "Now Playing" ) ); @@ -215,7 +215,7 @@ SnoreNotifyPlugin::nowPlaying( const QVariant& input ) Snore::Icon image; if ( map.contains( "cover" ) && map[ "cover" ].canConvert< QImage >() ) { - image = Snore::Icon( map[ "cover" ].value() ); + image = Snore::Icon( map[ "cover" ].value< QImage >() ); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << image; } notifyUser( InfoNowPlaying, messageText, image ); From 7c8cd781693682bb755fb16ea8c37d8a166ed616 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Tue, 18 Feb 2014 13:02:02 +0100 Subject: [PATCH 14/16] correctly escape newline --- src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp index 340522871..603d608d8 100644 --- a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp @@ -186,13 +186,13 @@ SnoreNotifyPlugin::nowPlaying( const QVariant& input ) // Remark: If using xml-based markup in notifications, the supplied strings need to be escaped. QString album; if ( !hash[ "album" ].isEmpty() ) - album = QString( "\n%1 %2" ).arg( tr( "on", "'on' is followed by an album name" ) ).arg( Qt::escape( hash[ "album" ] ) ); + 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( "\n%1" ).arg( tr( "by", "preposition to link track and artist" ) ) ); + .arg( QString( "
%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 ); From 1b85b9c0d65c3eb0a4271234f0421ca89ef45714 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Fri, 4 Apr 2014 10:55:08 +0200 Subject: [PATCH 15/16] qt5 support for snore --- CMakeLists.txt | 8 +++-- CMakeModules/FindLibsnore.cmake | 34 ------------------- .../generic/snorenotify/SnoreNotifyPlugin.cpp | 12 +++++++ 3 files changed, 18 insertions(+), 36 deletions(-) delete mode 100644 CMakeModules/FindLibsnore.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 18e2cf624..b45934a64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -298,8 +298,12 @@ if( WIN32 ) endif( WIN32 ) if( WIN32 OR APPLE ) - macro_optional_find_package(Libsnore) - macro_log_feature(LIBSNORE_FOUND "SnoreNotify" "Library for notifications" "https://github.com/TheOneRing/Snorenotify" FALSE "" "") +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 "" "") endif() #TODO: support external qxt diff --git a/CMakeModules/FindLibsnore.cmake b/CMakeModules/FindLibsnore.cmake deleted file mode 100644 index 4dc0b9e0b..000000000 --- a/CMakeModules/FindLibsnore.cmake +++ /dev/null @@ -1,34 +0,0 @@ -# - Try to find the libsnore library -# Once done this will define -# -# LIBSNORE_FOUND - system has the LIBSNORE library -# LIBSNORE_LIBRARIES - The libraries needed to use LIBSNORE -# LIBSNORE_INCLUDE_DIRS - The includes needed to use LIBSNORE -# LIBSNORE_PLUGIN_PATH - Path of the plugins -# Copyright 2013 Patrick von Reth - -find_path(LIBSNORE_INCLUDE_DIR - NAMES snore/core/snore.h - PATHS ${KDE4_INCLUDE_DIR} -) - -find_library(LIBSNORE_LIBRARY - NAMES - libsnore - snore - PATHS ${KDE4_LIB_DIR} -) - -find_path(LIBSNORE_PLUGIN_PATH snoreplugins) - -if(LIBSNORE_LIBRARY AND LIBSNORE_PLUGIN_PATH) - set(LIBSNORE_PLUGIN_PATH ${LIBSNORE_PLUGIN_PATH}/snoreplugins) -endif() - -set(LIBSNORE_LIBRARIES ${LIBSNORE_LIBRARY}) -set(LIBSNORE_INCLUDE_DIRS ${LIBSNORE_INCLUDE_DIR}) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LIBSNORE DEFAULT_MSG LIBSNORE_LIBRARIES LIBSNORE_INCLUDE_DIRS) - -mark_as_advanced(LIBSNORE_LIBRARIES LIBSNORE_INCLUDE_DIRS) diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp index 603d608d8..fdc876b73 100644 --- a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp @@ -33,8 +33,20 @@ #include #include + + +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) +namespace Qt +{ +inline QString escape( const QString &x ) +{ + x.toHtmlEscaped(); + } + } +#else // QTextDocument provides Qt::escape() #include +#endif namespace Tomahawk { From 7de3e27536780ac895a5ffc11c073b9351386ea1 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Sun, 22 Jun 2014 17:06:36 +0200 Subject: [PATCH 16/16] added missing return ... --- src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp index fdc876b73..f8dc361f2 100644 --- a/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp +++ b/src/infoplugins/generic/snorenotify/SnoreNotifyPlugin.cpp @@ -40,7 +40,7 @@ namespace Qt { inline QString escape( const QString &x ) { - x.toHtmlEscaped(); + return x.toHtmlEscaped(); } } #else