1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-02 12:20:45 +02:00

Fix up libnotify plugin (not actually using libnotify though)

This commit is contained in:
Jeff Mitchell
2011-06-21 17:39:31 -04:00
parent 69818f8c96
commit ef5f40864e
5 changed files with 56 additions and 19 deletions

View File

@@ -4,6 +4,10 @@ CMAKE_MINIMUM_REQUIRED( VERSION 2.8 )
IF( "${gui}" STREQUAL "no" ) IF( "${gui}" STREQUAL "no" )
SET( QT_DONT_USE_QTGUI TRUE ) SET( QT_DONT_USE_QTGUI TRUE )
ENDIF() ENDIF()
IF( UNIX AND NOT APPLE )
SET( QT_USE_QTDBUS TRUE )
ENDIF( UNIX AND NOT APPLE )
SET( QT_USE_QTSQL TRUE ) SET( QT_USE_QTSQL TRUE )
SET( QT_USE_QTNETWORK TRUE ) SET( QT_USE_QTNETWORK TRUE )
SET( QT_USE_QTXML TRUE ) SET( QT_USE_QTXML TRUE )

View File

@@ -350,6 +350,7 @@ AudioEngine::loadNextTrack()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
bool wasRetrying = m_retryTimer.isActive();
m_retryTimer.stop(); m_retryTimer.stop();
Tomahawk::result_ptr result; Tomahawk::result_ptr result;
@@ -371,6 +372,14 @@ AudioEngine::loadNextTrack()
stop(); stop();
if ( m_playlist && m_playlist->retryMode() == Tomahawk::PlaylistInterface::Retry ) if ( m_playlist && m_playlist->retryMode() == Tomahawk::PlaylistInterface::Retry )
{ {
if ( !wasRetrying )
{
Tomahawk::InfoSystem::InfoCriteriaHash retryInfo;
retryInfo["message"] = QString( "The current track could not be resolved. Tomahawk will keep trying..." );
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo(
s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNotifyUser,
QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( retryInfo ) );
}
m_retryTimer.setInterval( m_playlist->retryInterval() ); m_retryTimer.setInterval( m_playlist->retryInterval() );
m_retryTimer.start(); m_retryTimer.start();
} }
@@ -389,8 +398,13 @@ AudioEngine::playItem( Tomahawk::PlaylistInterface* playlist, const Tomahawk::re
setPlaylist( playlist ); setPlaylist( playlist );
m_currentTrackPlaylist = playlist; m_currentTrackPlaylist = playlist;
if ( result.isNull() ) if ( result.isNull() && m_playlist->retryMode() == PlaylistInterface::Retry )
{ {
Tomahawk::InfoSystem::InfoCriteriaHash retryInfo;
retryInfo["message"] = QString( "The current track could not be resolved. Tomahawk will keep trying..." );
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo(
s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNotifyUser,
QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( retryInfo ) );
m_retryTimer.setInterval( playlist->retryInterval() ); m_retryTimer.setInterval( playlist->retryInterval() );
m_retryTimer.start(); m_retryTimer.start();
} }

View File

@@ -20,21 +20,16 @@
#include "utils/tomahawkutils.h" #include "utils/tomahawkutils.h"
#include <libnotify/notify.h> #include <QtDBus/QDBusConnection>
#include <glib-2.0/glib.h> #include <QtDBus/QDBusMessage>
using namespace Tomahawk::InfoSystem; using namespace Tomahawk::InfoSystem;
// for internal neatness
LibNotifyPlugin::LibNotifyPlugin() LibNotifyPlugin::LibNotifyPlugin()
: InfoPlugin() : InfoPlugin()
, m_isInited( false )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
m_supportedGetTypes << Tomahawk::InfoSystem::InfoNotifyUser; m_supportedPushTypes << Tomahawk::InfoSystem::InfoNotifyUser;
gboolean initSuccess = notify_init( "Tomahawk" );
m_isInited = ( initSuccess == TRUE );
} }
LibNotifyPlugin::~LibNotifyPlugin() LibNotifyPlugin::~LibNotifyPlugin()
@@ -46,10 +41,30 @@ void
LibNotifyPlugin::pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant data ) LibNotifyPlugin::pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant data )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if ( type != Tomahawk::InfoSystem::InfoNotifyUser || !data.canConvert< Tomahawk::InfoSystem::InfoCustomData >() ) if ( type != Tomahawk::InfoSystem::InfoNotifyUser || !data.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() )
{
qDebug() << Q_FUNC_INFO << " not the right type or could not convert the hash";
return; return;
Tomahawk::InfoSystem::InfoCustomData hash = data.value< Tomahawk::InfoSystem::InfoCustomData >(); }
if ( !hash.contains( "message" ) || !(hash["message"].canConvert< QString >() ) ) Tomahawk::InfoSystem::InfoCriteriaHash hash = data.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
return; if ( !hash.contains( "message" ) )
QString message = hash["trackName"].toString(); {
qDebug() << Q_FUNC_INFO << " hash did not contain a message";
return;
}
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 << caller; //summary
arguments << hash["message"]; //body
arguments << QStringList(); //actions
QMap< QString, QVariant > dict;
dict["desktop-entry"] = QString( "tomahawk" );
arguments << dict; //hints
arguments << quint32( -1 ); //expire_timeout
message.setArguments( arguments );
QDBusConnection::sessionBus().send( message );
} }

View File

@@ -22,8 +22,6 @@
#include "infosystem/infosystem.h" #include "infosystem/infosystem.h"
#include "infosystem/infosystemworker.h" #include "infosystem/infosystemworker.h"
class QNetworkReply;
namespace Tomahawk namespace Tomahawk
{ {
@@ -38,6 +36,8 @@ public:
LibNotifyPlugin(); LibNotifyPlugin();
virtual ~LibNotifyPlugin(); virtual ~LibNotifyPlugin();
virtual void namChangedSlot( QNetworkAccessManager* ) {}
protected slots: protected slots:
virtual void getInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData ) virtual void getInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input, const Tomahawk::InfoSystem::InfoCustomData customData )
{ {
@@ -57,10 +57,6 @@ protected slots:
Q_UNUSED( input ); Q_UNUSED( input );
Q_UNUSED( customData ); Q_UNUSED( customData );
} }
private:
bool m_isInited;
}; };
} }

View File

@@ -29,6 +29,9 @@
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
#include "infoplugins/mac/adiumplugin.h" #include "infoplugins/mac/adiumplugin.h"
#endif #endif
#ifdef Q_WS_X11
#include "infoplugins/unix/libnotifyplugin.h"
#endif
#include "lastfm/NetworkAccessManager" #include "lastfm/NetworkAccessManager"
@@ -74,6 +77,11 @@ InfoSystemWorker::init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache> cac
m_plugins.append( admptr ); m_plugins.append( admptr );
registerInfoTypes( admptr, admptr.data()->supportedGetTypes(), admptr.data()->supportedPushTypes() ); registerInfoTypes( admptr, admptr.data()->supportedGetTypes(), admptr.data()->supportedPushTypes() );
#endif #endif
#ifdef Q_WS_X11
InfoPluginPtr libnotifyptr( new LibNotifyPlugin() );
m_plugins.append( libnotifyptr );
registerInfoTypes( libnotifyptr, libnotifyptr.data()->supportedGetTypes(), libnotifyptr.data()->supportedPushTypes() );
#endif
Q_FOREACH( InfoPluginPtr plugin, m_plugins ) Q_FOREACH( InfoPluginPtr plugin, m_plugins )
{ {