mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 15:59:42 +01:00
use autogenerated dbus interface for fdonotify
This commit is contained in:
parent
a8980f7c32
commit
15f6ea8543
@ -9,6 +9,8 @@ if(NOT Qt5Core_DIR)
|
||||
${THIRDPARTY_DIR}/libqnetwm/libqnetwm/netwm.cpp
|
||||
)
|
||||
SET(FDO_LINK_LIBRARIES ${LINK_LIBRARIES} ${X11_LIBRARIES})
|
||||
qt4_add_dbus_interface(fdo_srcs fdonotify/org.freedesktop.Notifications.xml
|
||||
FreedesktopNotificationsProxy)
|
||||
|
||||
tomahawk_add_plugin(fdonotify
|
||||
TYPE infoplugin EXPORT_MACRO INFOPLUGINDLLEXPORT_PRO
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "FdoNotifyPlugin.h"
|
||||
#include "utils/TomahawkUtils.h"
|
||||
#include "ImageConverter.h"
|
||||
#include "FreedesktopNotificationsProxy.h"
|
||||
|
||||
#include "TomahawkSettings.h"
|
||||
|
||||
@ -66,8 +67,12 @@ FdoNotifyPlugin::FdoNotifyPlugin()
|
||||
m_supportedPushTypes << InfoNotifyUser << InfoNowPlaying << InfoTrackUnresolved << InfoNowStopped << InfoInboxReceived;
|
||||
|
||||
// Query the window manager for its capabilties in styling notifications.
|
||||
QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "GetCapabilities" );
|
||||
QDBusConnection::sessionBus().callWithCallback( message, this, SLOT( dbusCapabiltiesReplyReceived( QDBusMessage ) ) );
|
||||
notifications_interface = new org::freedesktop::Notifications("org.freedesktop.Notifications", "/org/freedesktop/Notifications",
|
||||
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
|
||||
FdoNotifyPlugin::dbusCapabiltiesReplyReceived( const QDBusMessage& reply )
|
||||
FdoNotifyPlugin::dbusCapabilitiesReplyReceived( QDBusPendingCallWatcher* watcher )
|
||||
{
|
||||
if ( reply.type() != QDBusMessage::ReplyMessage )
|
||||
{
|
||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Did not receive a ReplyMessage";
|
||||
QDBusMessage reply = watcher->reply();
|
||||
watcher->deleteLater();
|
||||
|
||||
if (reply.type() == QDBusMessage::ErrorMessage) {
|
||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Failed to request capabilities of notifications";
|
||||
}
|
||||
|
||||
const QStringList &list = reply.arguments().at( 0 ).toStringList();
|
||||
QListIterator<QString> iter( list );
|
||||
while ( iter.hasNext() )
|
||||
{
|
||||
QString capabilty = iter.next();
|
||||
if ( capabilty.compare( "body-markup" ) == 0 )
|
||||
{
|
||||
m_wmSupportsBodyMarkup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const QStringList &capability_list = reply.arguments().at( 0 ).toStringList();
|
||||
m_wmSupportsBodyMarkup = capability_list.contains("body-markup");
|
||||
}
|
||||
|
||||
|
||||
@ -151,23 +149,19 @@ FdoNotifyPlugin::getNotificationIconHeight()
|
||||
void
|
||||
FdoNotifyPlugin::notifyUser( const QString& messageText )
|
||||
{
|
||||
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 << QString( "Tomahawk" ); //summary
|
||||
arguments << QString( messageText ); //body
|
||||
arguments << QStringList(); //actions
|
||||
|
||||
QVariantMap dict;
|
||||
dict["desktop-entry"] = QString( "tomahawk" );
|
||||
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 );
|
||||
QVariantMap hints;
|
||||
hints["desktop-entry"] = QString( "tomahawk" );
|
||||
hints[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "icons/tomahawk-icon-512x512.png" ).scaledToHeight( getNotificationIconHeight() ) );
|
||||
notifications_interface->Notify(
|
||||
"Tomahawk", // app_name
|
||||
0, // notification_id
|
||||
"", // app_icon
|
||||
"Tomahawk", // summary
|
||||
messageText, // body
|
||||
QStringList(), // actions
|
||||
hints, // hints
|
||||
-1 // expire_timeout
|
||||
);
|
||||
}
|
||||
|
||||
void FdoNotifyPlugin::inboxReceived(const QVariant &input)
|
||||
@ -216,26 +210,21 @@ void FdoNotifyPlugin::inboxReceived(const QVariant &input)
|
||||
|
||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "sending message" << messageText;
|
||||
|
||||
QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify" );
|
||||
QList<QVariant> arguments;
|
||||
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" );
|
||||
QVariantMap hints;
|
||||
hints["desktop-entry"] = QString( "tomahawk" );
|
||||
|
||||
// Convert image to QVariant and scale to a consistent size.
|
||||
dict[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "images/inbox-512x512.png" ).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
|
||||
QDBusConnection::sessionBus().send( message );
|
||||
hints[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "images/inbox-512x512.png" ).scaledToHeight( getNotificationIconHeight() ) );
|
||||
notifications_interface->Notify(
|
||||
"Tomahawk", // app_name
|
||||
m_nowPlayingId, // notification_id
|
||||
"", // app_icon
|
||||
"Tomahawk - Track received", // summary
|
||||
messageText, // body
|
||||
QStringList(), // actions
|
||||
hints, // hints
|
||||
-1 // expire_timeout
|
||||
);
|
||||
}
|
||||
|
||||
void
|
||||
@ -286,16 +275,8 @@ FdoNotifyPlugin::nowPlaying( const QVariant& input )
|
||||
|
||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "sending message" << messageText;
|
||||
|
||||
QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify" );
|
||||
QList<QVariant> arguments;
|
||||
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" );
|
||||
QVariantMap hints;
|
||||
hints["desktop-entry"] = QString( "tomahawk" );
|
||||
|
||||
// If there is a cover availble use it, else use Tomahawk logo as default.
|
||||
QImage image;
|
||||
@ -304,14 +285,24 @@ FdoNotifyPlugin::nowPlaying( const QVariant& input )
|
||||
else
|
||||
image = QImage( RESPATH "icons/tomahawk-icon-512x512.png" );
|
||||
// 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
|
||||
QDBusConnection::sessionBus().callWithCallback( message, this, SLOT( dbusPlayingReplyReceived( QDBusMessage ) ) );
|
||||
QDBusPendingReply<> reply = notifications_interface->Notify(
|
||||
"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
|
||||
*/
|
||||
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();
|
||||
if ( list.count() > 0 )
|
||||
m_nowPlayingId = list.at( 0 ).toInt();
|
||||
|
@ -23,8 +23,9 @@
|
||||
#include "../../InfoPluginDllMacro.h"
|
||||
|
||||
#include "infosystem/InfoSystem.h"
|
||||
#include "FreedesktopNotificationsProxy.h"
|
||||
|
||||
#include <QDBusMessage>
|
||||
#include <QtDBus>
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
@ -45,8 +46,8 @@ public:
|
||||
protected slots:
|
||||
virtual void init() {}
|
||||
|
||||
virtual void dbusPlayingReplyReceived( const QDBusMessage& reply );
|
||||
virtual void dbusCapabiltiesReplyReceived( const QDBusMessage& reply );
|
||||
virtual void dbusPlayingReplyReceived( QDBusPendingCallWatcher* watcher );
|
||||
virtual void dbusCapabilitiesReplyReceived( QDBusPendingCallWatcher* watcher );
|
||||
|
||||
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
|
||||
bool m_wmSupportsBodyMarkup;
|
||||
org::freedesktop::Notifications* notifications_interface;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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>
|
Loading…
x
Reference in New Issue
Block a user