1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-09 23:57:34 +02:00

use autogenerated dbus interface for fdonotify

This commit is contained in:
Florian Richter
2013-05-31 16:43:29 +02:00
parent a8980f7c32
commit 15f6ea8543
4 changed files with 112 additions and 72 deletions

View File

@@ -9,6 +9,8 @@ if(NOT Qt5Core_DIR)
${THIRDPARTY_DIR}/libqnetwm/libqnetwm/netwm.cpp ${THIRDPARTY_DIR}/libqnetwm/libqnetwm/netwm.cpp
) )
SET(FDO_LINK_LIBRARIES ${LINK_LIBRARIES} ${X11_LIBRARIES}) SET(FDO_LINK_LIBRARIES ${LINK_LIBRARIES} ${X11_LIBRARIES})
qt4_add_dbus_interface(fdo_srcs fdonotify/org.freedesktop.Notifications.xml
FreedesktopNotificationsProxy)
tomahawk_add_plugin(fdonotify tomahawk_add_plugin(fdonotify
TYPE infoplugin EXPORT_MACRO INFOPLUGINDLLEXPORT_PRO TYPE infoplugin EXPORT_MACRO INFOPLUGINDLLEXPORT_PRO

View File

@@ -40,6 +40,7 @@
#include "FdoNotifyPlugin.h" #include "FdoNotifyPlugin.h"
#include "utils/TomahawkUtils.h" #include "utils/TomahawkUtils.h"
#include "ImageConverter.h" #include "ImageConverter.h"
#include "FreedesktopNotificationsProxy.h"
#include "TomahawkSettings.h" #include "TomahawkSettings.h"
@@ -66,8 +67,12 @@ FdoNotifyPlugin::FdoNotifyPlugin()
m_supportedPushTypes << InfoNotifyUser << InfoNowPlaying << InfoTrackUnresolved << InfoNowStopped << InfoInboxReceived; m_supportedPushTypes << InfoNotifyUser << InfoNowPlaying << InfoTrackUnresolved << InfoNowStopped << InfoInboxReceived;
// Query the window manager for its capabilties in styling notifications. // Query the window manager for its capabilties in styling notifications.
QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "GetCapabilities" ); notifications_interface = new org::freedesktop::Notifications("org.freedesktop.Notifications", "/org/freedesktop/Notifications",
QDBusConnection::sessionBus().callWithCallback( message, this, SLOT( dbusCapabiltiesReplyReceived( QDBusMessage ) ) ); QDBusConnection::sessionBus(), this);
QDBusPendingReply<QStringList> reply = notifications_interface->GetCapabilities();
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(dbusCapabilitiesReplyReceived(QDBusPendingCallWatcher*)));
} }
@@ -78,24 +83,17 @@ FdoNotifyPlugin::~FdoNotifyPlugin()
void void
FdoNotifyPlugin::dbusCapabiltiesReplyReceived( const QDBusMessage& reply ) FdoNotifyPlugin::dbusCapabilitiesReplyReceived( QDBusPendingCallWatcher* watcher )
{ {
if ( reply.type() != QDBusMessage::ReplyMessage ) QDBusMessage reply = watcher->reply();
{ watcher->deleteLater();
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Did not receive a ReplyMessage";
if (reply.type() == QDBusMessage::ErrorMessage) {
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Failed to request capabilities of notifications";
} }
const QStringList &list = reply.arguments().at( 0 ).toStringList(); const QStringList &capability_list = reply.arguments().at( 0 ).toStringList();
QListIterator<QString> iter( list ); m_wmSupportsBodyMarkup = capability_list.contains("body-markup");
while ( iter.hasNext() )
{
QString capabilty = iter.next();
if ( capabilty.compare( "body-markup" ) == 0 )
{
m_wmSupportsBodyMarkup = true;
break;
}
}
} }
@@ -151,23 +149,19 @@ FdoNotifyPlugin::getNotificationIconHeight()
void void
FdoNotifyPlugin::notifyUser( const QString& messageText ) FdoNotifyPlugin::notifyUser( const QString& messageText )
{ {
QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify" ); QVariantMap hints;
hints["desktop-entry"] = QString( "tomahawk" );
QList<QVariant> arguments; hints[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "icons/tomahawk-icon-512x512.png" ).scaledToHeight( getNotificationIconHeight() ) );
arguments << QString( "Tomahawk" ); //app_name notifications_interface->Notify(
arguments << quint32( 0 ); //notification_id "Tomahawk", // app_name
arguments << QString(); //app_icon 0, // notification_id
arguments << QString( "Tomahawk" ); //summary "", // app_icon
arguments << QString( messageText ); //body "Tomahawk", // summary
arguments << QStringList(); //actions messageText, // body
QStringList(), // actions
QVariantMap dict; hints, // hints
dict["desktop-entry"] = QString( "tomahawk" ); -1 // expire_timeout
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) void FdoNotifyPlugin::inboxReceived(const QVariant &input)
@@ -216,26 +210,21 @@ void FdoNotifyPlugin::inboxReceived(const QVariant &input)
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "sending message" << messageText; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "sending message" << messageText;
QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify" ); QVariantMap hints;
QList<QVariant> arguments; hints["desktop-entry"] = QString( "tomahawk" );
arguments << QString( "Tomahawk" ); //app_name
arguments << m_nowPlayingId; //notification_id
arguments << QString(); //app_icon
arguments << QString( "Tomahawk - Track received" ); //summary
arguments << messageText; //body
arguments << QStringList(); //actions
QVariantMap dict;
dict["desktop-entry"] = QString( "tomahawk" );
// Convert image to QVariant and scale to a consistent size. // Convert image to QVariant and scale to a consistent size.
dict[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "images/inbox-512x512.png" ).scaledToHeight( getNotificationIconHeight() ) ); hints[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "images/inbox-512x512.png" ).scaledToHeight( getNotificationIconHeight() ) );
notifications_interface->Notify(
arguments << dict; //hints "Tomahawk", // app_name
arguments << qint32( -1 ); //expire_timeout m_nowPlayingId, // notification_id
message.setArguments( arguments ); "", // app_icon
"Tomahawk - Track received", // summary
// Handle reply in a callback, so that this a non-blocking call messageText, // body
QDBusConnection::sessionBus().send( message ); QStringList(), // actions
hints, // hints
-1 // expire_timeout
);
} }
void void
@@ -286,16 +275,8 @@ FdoNotifyPlugin::nowPlaying( const QVariant& input )
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "sending message" << messageText; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "sending message" << messageText;
QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify" ); QVariantMap hints;
QList<QVariant> arguments; hints["desktop-entry"] = QString( "tomahawk" );
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. // If there is a cover availble use it, else use Tomahawk logo as default.
QImage image; QImage image;
@@ -304,14 +285,24 @@ FdoNotifyPlugin::nowPlaying( const QVariant& input )
else else
image = QImage( RESPATH "icons/tomahawk-icon-512x512.png" ); image = QImage( RESPATH "icons/tomahawk-icon-512x512.png" );
// Convert image to QVariant and scale to a consistent size. // Convert image to QVariant and scale to a consistent size.
dict[ "image_data" ] = ImageConverter::variantForImage( image.scaledToHeight( getNotificationIconHeight() ) ); hints[ "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 QDBusPendingReply<> reply = notifications_interface->Notify(
QDBusConnection::sessionBus().callWithCallback( message, this, SLOT( dbusPlayingReplyReceived( QDBusMessage ) ) ); "Tomahawk", // app_name
m_nowPlayingId, // notification_id
"", // app_icon
"Tomahawk - Now Playing", // summary
messageText, // body
QStringList(), // actions
hints, // hints
-1 // expire_timeout
);
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
this, SLOT(RegisterFinished(dbusPlayingReplyReceived*)));
} }
@@ -319,8 +310,15 @@ FdoNotifyPlugin::nowPlaying( const QVariant& input )
* Handle the DBus reply triggered by FdoNotifyPlugin::nowPlaying * Handle the DBus reply triggered by FdoNotifyPlugin::nowPlaying
*/ */
void void
FdoNotifyPlugin::dbusPlayingReplyReceived( const QDBusMessage& reply ) FdoNotifyPlugin::dbusPlayingReplyReceived( QDBusPendingCallWatcher* watcher )
{ {
QDBusMessage reply = watcher->reply();
watcher->deleteLater();
if (reply.type() == QDBusMessage::ErrorMessage) {
tLog(LOGVERBOSE) << "Failed to grab media keys" << reply.errorName() << reply.errorMessage();
return;
}
const QVariantList& list = reply.arguments(); const QVariantList& list = reply.arguments();
if ( list.count() > 0 ) if ( list.count() > 0 )
m_nowPlayingId = list.at( 0 ).toInt(); m_nowPlayingId = list.at( 0 ).toInt();

View File

@@ -23,8 +23,9 @@
#include "../../InfoPluginDllMacro.h" #include "../../InfoPluginDllMacro.h"
#include "infosystem/InfoSystem.h" #include "infosystem/InfoSystem.h"
#include "FreedesktopNotificationsProxy.h"
#include <QDBusMessage> #include <QtDBus>
namespace Tomahawk namespace Tomahawk
{ {
@@ -45,8 +46,8 @@ public:
protected slots: protected slots:
virtual void init() {} virtual void init() {}
virtual void dbusPlayingReplyReceived( const QDBusMessage& reply ); virtual void dbusPlayingReplyReceived( QDBusPendingCallWatcher* watcher );
virtual void dbusCapabiltiesReplyReceived( const QDBusMessage& reply ); virtual void dbusCapabilitiesReplyReceived( QDBusPendingCallWatcher* watcher );
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
{ {
@@ -72,6 +73,7 @@ private:
// Does the window manger support basic XML-based markup (a small HTML subset), see Desktop Notifications specification // Does the window manger support basic XML-based markup (a small HTML subset), see Desktop Notifications specification
bool m_wmSupportsBodyMarkup; bool m_wmSupportsBodyMarkup;
org::freedesktop::Notifications* notifications_interface;
}; };
} }

View File

@@ -0,0 +1,38 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.Notifications">
<signal name="NotificationClosed">
<arg name="id" type="u" direction="out"/>
<arg name="reason" type="u" direction="out"/>
</signal>
<signal name="ActionInvoked">
<arg name="id" type="u" direction="out"/>
<arg name="action_key" type="s" direction="out"/>
</signal>
<method name="GetServerInformation">
<arg name="return_name" type="s" direction="out"/>
<arg name="return_vendor" type="s" direction="out"/>
<arg name="return_version" type="s" direction="out"/>
<arg name="return_spec_version" type="s" direction="out"/>
</method>
<method name="GetCapabilities">
<arg name="return_caps" type="as" direction="out"/>
</method>
<method name="CloseNotification">
<arg name="id" type="u" direction="in"/>
</method>
<method name="Notify">
<arg name="app_name" type="s" direction="in"/>
<arg name="id" type="u" direction="in"/>
<arg name="icon" type="s" direction="in"/>
<arg name="summary" type="s" direction="in"/>
<arg name="body" type="s" direction="in"/>
<arg name="actions" type="as" direction="in"/>
<arg name="hints" type="a{sv}" direction="in"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In6" value="QVariantMap"/>
<arg name="timeout" type="i" direction="in"/>
<arg name="return_id" type="u" direction="out"/>
</method>
</interface>
</node>