From a8980f7c32c2d19830ae7a0e0578dad6d87df235 Mon Sep 17 00:00:00 2001 From: Florian Richter Date: Fri, 31 May 2013 15:39:14 +0200 Subject: [PATCH 1/2] autogenerate dbus adaptors for mpris --- src/infoplugins/linux/CMakeLists.txt | 8 +- .../linux/mpris/MprisPluginPlayerAdaptor.cpp | 205 ------------------ .../linux/mpris/MprisPluginPlayerAdaptor.h | 140 ------------ .../linux/mpris/MprisPluginRootAdaptor.cpp | 92 -------- .../linux/mpris/MprisPluginRootAdaptor.h | 77 ------- 5 files changed, 6 insertions(+), 516 deletions(-) delete mode 100644 src/infoplugins/linux/mpris/MprisPluginPlayerAdaptor.cpp delete mode 100644 src/infoplugins/linux/mpris/MprisPluginPlayerAdaptor.h delete mode 100644 src/infoplugins/linux/mpris/MprisPluginRootAdaptor.cpp delete mode 100644 src/infoplugins/linux/mpris/MprisPluginRootAdaptor.h diff --git a/src/infoplugins/linux/CMakeLists.txt b/src/infoplugins/linux/CMakeLists.txt index 6c23ef980..7ab51bb26 100644 --- a/src/infoplugins/linux/CMakeLists.txt +++ b/src/infoplugins/linux/CMakeLists.txt @@ -18,12 +18,16 @@ if(NOT Qt5Core_DIR) endif() +INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ) SET(mpris_srcs - mpris/MprisPluginRootAdaptor.cpp - mpris/MprisPluginPlayerAdaptor.cpp mpris/MprisPlugin.cpp ) +qt4_add_dbus_adaptor(mpris_srcs mpris/MprisPluginRootAdaptor.xml + mpris/MprisPlugin.h Tomahawk::InfoSystem::MprisPlugin MprisPluginRootAdaptor MprisPluginRootAdaptor) +qt4_add_dbus_adaptor(mpris_srcs mpris/MprisPluginPlayerAdaptor.xml + mpris/MprisPlugin.h Tomahawk::InfoSystem::MprisPlugin MprisPluginPlayerAdaptor MprisPluginPlayerAdaptor) + tomahawk_add_plugin(mpris TYPE infoplugin EXPORT_MACRO INFOPLUGINDLLEXPORT_PRO SOURCES "${mpris_srcs}" diff --git a/src/infoplugins/linux/mpris/MprisPluginPlayerAdaptor.cpp b/src/infoplugins/linux/mpris/MprisPluginPlayerAdaptor.cpp deleted file mode 100644 index f707ce3a4..000000000 --- a/src/infoplugins/linux/mpris/MprisPluginPlayerAdaptor.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/* - * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp -a mprispluginplayeradaptor -c MprisPluginPlayerAdaptor MprisPluginPlayerAdaptor.xml - * - * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). - * - * This is an auto-generated file. - * Do not edit! All changes made to it will be lost. - */ - -#include "MprisPluginPlayerAdaptor.h" -#include -#include -#include -#include -#include -#include -#include - -/* - * Implementation of adaptor class MprisPluginPlayerAdaptor - */ - -MprisPluginPlayerAdaptor::MprisPluginPlayerAdaptor(QObject *parent) - : QDBusAbstractAdaptor(parent) -{ - // constructor - setAutoRelaySignals(true); -} - -MprisPluginPlayerAdaptor::~MprisPluginPlayerAdaptor() -{ - // destructor -} - -bool MprisPluginPlayerAdaptor::canControl() const -{ - // get the value of property CanControl - return qvariant_cast< bool >(parent()->property("CanControl")); -} - -bool MprisPluginPlayerAdaptor::canGoNext() const -{ - // get the value of property CanGoNext - return qvariant_cast< bool >(parent()->property("CanGoNext")); -} - -bool MprisPluginPlayerAdaptor::canGoPrevious() const -{ - // get the value of property CanGoPrevious - return qvariant_cast< bool >(parent()->property("CanGoPrevious")); -} - -bool MprisPluginPlayerAdaptor::canPause() const -{ - // get the value of property CanPause - return qvariant_cast< bool >(parent()->property("CanPause")); -} - -bool MprisPluginPlayerAdaptor::canPlay() const -{ - // get the value of property CanPlay - return qvariant_cast< bool >(parent()->property("CanPlay")); -} - -bool MprisPluginPlayerAdaptor::canSeek() const -{ - // get the value of property CanSeek - return qvariant_cast< bool >(parent()->property("CanSeek")); -} - -QString MprisPluginPlayerAdaptor::loopStatus() const -{ - // get the value of property LoopStatus - return qvariant_cast< QString >(parent()->property("LoopStatus")); -} - -void MprisPluginPlayerAdaptor::setLoopStatus(const QString &value) -{ - // set the value of property LoopStatus - parent()->setProperty("LoopStatus", qVariantFromValue(value)); -} - -double MprisPluginPlayerAdaptor::maximumRate() const -{ - // get the value of property MaximumRate - return qvariant_cast< double >(parent()->property("MaximumRate")); -} - -QVariantMap MprisPluginPlayerAdaptor::metadata() const -{ - // get the value of property Metadata - return qvariant_cast< QVariantMap >(parent()->property("Metadata")); -} - -double MprisPluginPlayerAdaptor::minimumRate() const -{ - // get the value of property MinimumRate - return qvariant_cast< double >(parent()->property("MinimumRate")); -} - -QString MprisPluginPlayerAdaptor::playbackStatus() const -{ - // get the value of property PlaybackStatus - return qvariant_cast< QString >(parent()->property("PlaybackStatus")); -} - -qlonglong MprisPluginPlayerAdaptor::position() const -{ - // get the value of property Position - return qvariant_cast< qlonglong >(parent()->property("Position")); -} - -double MprisPluginPlayerAdaptor::rate() const -{ - // get the value of property Rate - return qvariant_cast< double >(parent()->property("Rate")); -} - -void MprisPluginPlayerAdaptor::setRate(double value) -{ - // set the value of property Rate - parent()->setProperty("Rate", qVariantFromValue(value)); -} - -bool MprisPluginPlayerAdaptor::shuffle() const -{ - // get the value of property Shuffle - return qvariant_cast< bool >(parent()->property("Shuffle")); -} - -void MprisPluginPlayerAdaptor::setShuffle(bool value) -{ - // set the value of property Shuffle - parent()->setProperty("Shuffle", qVariantFromValue(value)); -} - -double MprisPluginPlayerAdaptor::volume() const -{ - // get the value of property Volume - return qvariant_cast< double >(parent()->property("Volume")); -} - -void MprisPluginPlayerAdaptor::setVolume(double value) -{ - // set the value of property Volume - parent()->setProperty("Volume", qVariantFromValue(value)); -} - -void MprisPluginPlayerAdaptor::Next() -{ - // handle method call org.mpris.MediaPlayer2.Player.Next - QMetaObject::invokeMethod(parent(), "Next"); -} - -void MprisPluginPlayerAdaptor::OpenUri(const QString &Uri) -{ - // handle method call org.mpris.MediaPlayer2.Player.OpenUri - QMetaObject::invokeMethod(parent(), "OpenUri", Q_ARG(QString, Uri)); -} - -void MprisPluginPlayerAdaptor::Pause() -{ - // handle method call org.mpris.MediaPlayer2.Player.Pause - QMetaObject::invokeMethod(parent(), "Pause"); -} - -void MprisPluginPlayerAdaptor::Play() -{ - // handle method call org.mpris.MediaPlayer2.Player.Play - QMetaObject::invokeMethod(parent(), "Play"); -} - -void MprisPluginPlayerAdaptor::PlayPause() -{ - // handle method call org.mpris.MediaPlayer2.Player.PlayPause - QMetaObject::invokeMethod(parent(), "PlayPause"); -} - -void MprisPluginPlayerAdaptor::Previous() -{ - // handle method call org.mpris.MediaPlayer2.Player.Previous - QMetaObject::invokeMethod(parent(), "Previous"); -} - -void MprisPluginPlayerAdaptor::Seek(qlonglong Offset) -{ - qDebug() << Q_FUNC_INFO; - // handle method call org.mpris.MediaPlayer2.Player.Seek - QMetaObject::invokeMethod(parent(), "Seek", Q_ARG(qlonglong, Offset)); -} - -void MprisPluginPlayerAdaptor::SetPosition(const QDBusObjectPath &TrackId, qlonglong Position) -{ - qDebug() << Q_FUNC_INFO; - // handle method call org.mpris.MediaPlayer2.Player.SetPosition - QMetaObject::invokeMethod(parent(), "SetPosition", Q_ARG(QDBusObjectPath, TrackId), Q_ARG(qlonglong, Position)); -} - -void MprisPluginPlayerAdaptor::Stop() -{ - // handle method call org.mpris.MediaPlayer2.Player.Stop - QMetaObject::invokeMethod(parent(), "Stop"); -} - diff --git a/src/infoplugins/linux/mpris/MprisPluginPlayerAdaptor.h b/src/infoplugins/linux/mpris/MprisPluginPlayerAdaptor.h deleted file mode 100644 index ebef4698e..000000000 --- a/src/infoplugins/linux/mpris/MprisPluginPlayerAdaptor.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp -a mprispluginplayeradaptor -c MprisPluginPlayerAdaptor MprisPluginPlayerAdaptor.xml - * - * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). - * - * This is an auto-generated file. - * This file may have been hand-edited. Look for HAND-EDIT comments - * before re-generating it. - */ - -#ifndef MPRISPLUGINPLAYERADAPTOR_H_1313089554 -#define MPRISPLUGINPLAYERADAPTOR_H_1313089554 - -#include -#include - -class QByteArray; -template class QList; -template class QMap; -class QString; -class QStringList; -class QVariant; - -/* - * Adaptor class for interface org.mpris.MediaPlayer2.Player - */ -class MprisPluginPlayerAdaptor: public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2.Player") - Q_CLASSINFO("D-Bus Introspection", "" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" - "") -public: - MprisPluginPlayerAdaptor(QObject *parent); - virtual ~MprisPluginPlayerAdaptor(); - -public: // PROPERTIES - Q_PROPERTY(bool CanControl READ canControl) - bool canControl() const; - - Q_PROPERTY(bool CanGoNext READ canGoNext) - bool canGoNext() const; - - Q_PROPERTY(bool CanGoPrevious READ canGoPrevious) - bool canGoPrevious() const; - - Q_PROPERTY(bool CanPause READ canPause) - bool canPause() const; - - Q_PROPERTY(bool CanPlay READ canPlay) - bool canPlay() const; - - Q_PROPERTY(bool CanSeek READ canSeek) - bool canSeek() const; - - Q_PROPERTY(QString LoopStatus READ loopStatus WRITE setLoopStatus) - QString loopStatus() const; - void setLoopStatus(const QString &value); - - Q_PROPERTY(double MaximumRate READ maximumRate) - double maximumRate() const; - - Q_PROPERTY(QVariantMap Metadata READ metadata) - QVariantMap metadata() const; - - Q_PROPERTY(double MinimumRate READ minimumRate) - double minimumRate() const; - - Q_PROPERTY(QString PlaybackStatus READ playbackStatus) - QString playbackStatus() const; - - Q_PROPERTY(qlonglong Position READ position) - qlonglong position() const; - - Q_PROPERTY(double Rate READ rate WRITE setRate) - double rate() const; - void setRate(double value); - - Q_PROPERTY(bool Shuffle READ shuffle WRITE setShuffle) - bool shuffle() const; - void setShuffle(bool value); - - Q_PROPERTY(double Volume READ volume WRITE setVolume) - double volume() const; - void setVolume(double value); - -public Q_SLOTS: // METHODS - void Next(); - void OpenUri(const QString &Uri); - void Pause(); - void Play(); - void PlayPause(); - void Previous(); - void Seek(qlonglong Offset); - void SetPosition(const QDBusObjectPath &TrackId, qlonglong Position); - void Stop(); -Q_SIGNALS: // SIGNALS - void Seeked(qlonglong Position); -}; - -#endif diff --git a/src/infoplugins/linux/mpris/MprisPluginRootAdaptor.cpp b/src/infoplugins/linux/mpris/MprisPluginRootAdaptor.cpp deleted file mode 100644 index 38caea346..000000000 --- a/src/infoplugins/linux/mpris/MprisPluginRootAdaptor.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp -a mprispluginrootadaptor -c MprisPluginRootAdaptor MprisPluginRootAdaptor.xml - * - * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). - * - * This is an auto-generated file. - * Do not edit! All changes made to it will be lost. - */ - -#include "MprisPluginRootAdaptor.h" -#include -#include -#include -#include -#include -#include -#include - -/* - * Implementation of adaptor class MprisPluginRootAdaptor - */ - -MprisPluginRootAdaptor::MprisPluginRootAdaptor(QObject *parent) - : QDBusAbstractAdaptor(parent) -{ - // constructor - setAutoRelaySignals(true); -} - -MprisPluginRootAdaptor::~MprisPluginRootAdaptor() -{ - // destructor -} - -bool MprisPluginRootAdaptor::canQuit() const -{ - // get the value of property CanQuit - return qvariant_cast< bool >(parent()->property("CanQuit")); -} - -bool MprisPluginRootAdaptor::canRaise() const -{ - qDebug() << Q_FUNC_INFO; - // get the value of property CanRaise - bool ret = qvariant_cast< bool >(parent()->property("CanRaise")); - qDebug() << "ret: " << ret; - return ret; -} - -QString MprisPluginRootAdaptor::desktopEntry() const -{ - // get the value of property DesktopEntry - return qvariant_cast< QString >(parent()->property("DesktopEntry")); -} - -bool MprisPluginRootAdaptor::hasTrackList() const -{ - // get the value of property HasTrackList - return qvariant_cast< bool >(parent()->property("HasTrackList")); -} - -QString MprisPluginRootAdaptor::identity() const -{ - // get the value of property Identity - return qvariant_cast< QString >(parent()->property("Identity")); -} - -QStringList MprisPluginRootAdaptor::supportedMimeTypes() const -{ - // get the value of property SupportedMimeTypes - return qvariant_cast< QStringList >(parent()->property("SupportedMimeTypes")); -} - -QStringList MprisPluginRootAdaptor::supportedUriSchemes() const -{ - // get the value of property SupportedUriSchemes - return qvariant_cast< QStringList >(parent()->property("SupportedUriSchemes")); -} - -void MprisPluginRootAdaptor::Quit() -{ - // handle method call org.mpris.MediaPlayer2.Quit - QMetaObject::invokeMethod(parent(), "Quit"); -} - -void MprisPluginRootAdaptor::Raise() -{ - // handle method call org.mpris.MediaPlayer2.Raise - QMetaObject::invokeMethod(parent(), "Raise"); -} - diff --git a/src/infoplugins/linux/mpris/MprisPluginRootAdaptor.h b/src/infoplugins/linux/mpris/MprisPluginRootAdaptor.h deleted file mode 100644 index a875f0065..000000000 --- a/src/infoplugins/linux/mpris/MprisPluginRootAdaptor.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp -a mprispluginrootadaptor -c MprisPluginRootAdaptor MprisPluginRootAdaptor.xml - * - * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). - * - * This is an auto-generated file. - * This file may have been hand-edited. Look for HAND-EDIT comments - * before re-generating it. - */ - -#ifndef MPRISPLUGINROOTADAPTOR_H_1312900930 -#define MPRISPLUGINROOTADAPTOR_H_1312900930 - -#include -#include - -class QByteArray; -template class QList; -template class QMap; -class QString; -class QStringList; -class QVariant; - -/* - * Adaptor class for interface org.mpris.MediaPlayer2 - */ -class MprisPluginRootAdaptor: public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "org.mpris.MediaPlayer2") - Q_CLASSINFO("D-Bus Introspection", "" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" - "") -public: - MprisPluginRootAdaptor(QObject *parent); - virtual ~MprisPluginRootAdaptor(); - -public: // PROPERTIES - Q_PROPERTY(bool CanQuit READ canQuit) - bool canQuit() const; - - Q_PROPERTY(bool CanRaise READ canRaise) - bool canRaise() const; - - Q_PROPERTY(QString DesktopEntry READ desktopEntry) - QString desktopEntry() const; - - Q_PROPERTY(bool HasTrackList READ hasTrackList) - bool hasTrackList() const; - - Q_PROPERTY(QString Identity READ identity) - QString identity() const; - - Q_PROPERTY(QStringList SupportedMimeTypes READ supportedMimeTypes) - QStringList supportedMimeTypes() const; - - Q_PROPERTY(QStringList SupportedUriSchemes READ supportedUriSchemes) - QStringList supportedUriSchemes() const; - -public Q_SLOTS: // METHODS - void Quit(); - void Raise(); -Q_SIGNALS: // SIGNALS -}; - -#endif From 15f6ea854369aebb91f2eba1599648297fac02ab Mon Sep 17 00:00:00 2001 From: Florian Richter Date: Fri, 31 May 2013 16:43:29 +0200 Subject: [PATCH 2/2] use autogenerated dbus interface for fdonotify --- src/infoplugins/linux/CMakeLists.txt | 2 + .../linux/fdonotify/FdoNotifyPlugin.cpp | 136 +++++++++--------- .../linux/fdonotify/FdoNotifyPlugin.h | 8 +- .../org.freedesktop.Notifications.xml | 38 +++++ 4 files changed, 112 insertions(+), 72 deletions(-) create mode 100644 src/infoplugins/linux/fdonotify/org.freedesktop.Notifications.xml diff --git a/src/infoplugins/linux/CMakeLists.txt b/src/infoplugins/linux/CMakeLists.txt index 7ab51bb26..7e02fa288 100644 --- a/src/infoplugins/linux/CMakeLists.txt +++ b/src/infoplugins/linux/CMakeLists.txt @@ -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 diff --git a/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.cpp b/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.cpp index 425af986e..80d1044ae 100644 --- a/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.cpp +++ b/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.cpp @@ -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 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 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 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 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 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(); diff --git a/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.h b/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.h index 32003633f..cd27ee6b8 100644 --- a/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.h +++ b/src/infoplugins/linux/fdonotify/FdoNotifyPlugin.h @@ -23,8 +23,9 @@ #include "../../InfoPluginDllMacro.h" #include "infosystem/InfoSystem.h" +#include "FreedesktopNotificationsProxy.h" -#include +#include 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; }; } diff --git a/src/infoplugins/linux/fdonotify/org.freedesktop.Notifications.xml b/src/infoplugins/linux/fdonotify/org.freedesktop.Notifications.xml new file mode 100644 index 000000000..bee75d68c --- /dev/null +++ b/src/infoplugins/linux/fdonotify/org.freedesktop.Notifications.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +