From a3b78a0043253a3b302c235b5e87d96870848a0b Mon Sep 17 00:00:00 2001 From: John Maguire Date: Tue, 1 Mar 2011 14:34:06 +0000 Subject: [PATCH] Sync libxrme. --- 3rdparty/libxrme/CMakeLists.txt | 2 +- 3rdparty/libxrme/connection.cpp | 11 ++- 3rdparty/libxrme/extensions.cpp | 10 +++ 3rdparty/libxrme/extensions.h | 92 +++++++++++++++++++++++ 3rdparty/libxrme/mediaplayerhandler.cpp | 15 ++-- 3rdparty/libxrme/remotecontrolhandler.cpp | 10 ++- 6 files changed, 129 insertions(+), 11 deletions(-) create mode 100644 3rdparty/libxrme/extensions.cpp create mode 100644 3rdparty/libxrme/extensions.h diff --git a/3rdparty/libxrme/CMakeLists.txt b/3rdparty/libxrme/CMakeLists.txt index 8ff426874..e6b27bae2 100644 --- a/3rdparty/libxrme/CMakeLists.txt +++ b/3rdparty/libxrme/CMakeLists.txt @@ -1,9 +1,9 @@ include_directories(${CMAKE_BINARY_DIR}) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../gloox/src) set(SOURCES common.cpp connection.cpp + extensions.cpp handler.cpp mediaplayerhandler.cpp mediaplayerinterface.cpp diff --git a/3rdparty/libxrme/connection.cpp b/3rdparty/libxrme/connection.cpp index 1a05cd489..843b4bb44 100644 --- a/3rdparty/libxrme/connection.cpp +++ b/3rdparty/libxrme/connection.cpp @@ -17,6 +17,7 @@ #include "common.h" #include "connection.h" +#include "extensions.h" #include "mediaplayerhandler.h" #include "remotecontrolhandler.h" @@ -47,7 +48,9 @@ struct Connection::Private : public gloox::ConnectionListener, verbose_(false), media_player_(NULL), remote_control_(NULL), - spontaneous_disconnect_(true) {} + spontaneous_disconnect_(true), + media_player_extension_(new MediaPlayerExtension()), + remote_control_extension_(new RemoteControlExtension()) {} static const char* kDefaultServer; static const char* kDefaultJIDResource; @@ -73,6 +76,9 @@ struct Connection::Private : public gloox::ConnectionListener, QScopedPointer client_; QScopedPointer socket_notifier_; + MediaPlayerExtension* media_player_extension_; + RemoteControlExtension* remote_control_extension_; + // After discovering a peer we query it to find its capabilities. Only after // it replies to the query do we put it in peers_ and emit PeerFound(). QList peers_; @@ -245,6 +251,9 @@ bool Connection::Connect() { d->client_->disco()->setVersion(d->agent_name_.toUtf8().constData(), std::string()); d->client_->disco()->addFeature(kXmlnsXrme); + d->client_->registerStanzaExtension(d->media_player_extension_); + d->client_->registerStanzaExtension(d->remote_control_extension_); + // Initialise the handlers foreach (Handler* handler, d->handlers_) { handler->Init(this, d->client_.data()); diff --git a/3rdparty/libxrme/extensions.cpp b/3rdparty/libxrme/extensions.cpp new file mode 100644 index 000000000..f3e06e5ba --- /dev/null +++ b/3rdparty/libxrme/extensions.cpp @@ -0,0 +1,10 @@ +#include "extensions.h" + +namespace xrme { + +const char* MediaPlayerExtension::kFilterString = + "/iq/xrme[@xmlns='http://purplehatstands.com/xmlns/xrme/mediaplayer']"; +const char* RemoteControlExtension::kFilterString = + "/iq/xrme[@xmlns='http://purplehatstands.com/xmlns/xrme/remotecontrol']"; + +} diff --git a/3rdparty/libxrme/extensions.h b/3rdparty/libxrme/extensions.h new file mode 100644 index 000000000..db9d44f7e --- /dev/null +++ b/3rdparty/libxrme/extensions.h @@ -0,0 +1,92 @@ +#ifndef EXTENSIONS_H +#define EXTENSIONS_H + +#include +#include + +#include "common.h" + +namespace xrme { + +template +class XRMEExtension : public gloox::StanzaExtension { + public: + XRMEExtension(); + // gloox::StanzaExtension + const std::string& filterString() const; + StanzaExtension* newInstance(const gloox::Tag* tag) const; + gloox::Tag* tag() const; + StanzaExtension* clone() const; + + int extension_type() const { + return T::kExtensionType; + } + + protected: + explicit XRMEExtension(const gloox::Tag* tag); + explicit XRMEExtension(const XRMEExtension& other); + + static const char* kMediaPlayerFilterString; + static const char* kRemoteControlFilterString; + + const std::string filter_string_; + + const gloox::Tag* tag_; +}; + +class RemoteControlExtension : public XRMEExtension { + public: + static const int kExtensionType = gloox::ExtUser + 1; + static const char* kFilterString; +}; + +class MediaPlayerExtension : public XRMEExtension { + public: + static const int kExtensionType = gloox::ExtUser + 2; + static const char* kFilterString; +}; + +template +XRMEExtension::XRMEExtension() + : StanzaExtension(T::kExtensionType), + filter_string_(T::kFilterString), + tag_(NULL) { +} + +template +const std::string& XRMEExtension::filterString() const { + return filter_string_; +} + +template +gloox::StanzaExtension* XRMEExtension::newInstance(const gloox::Tag* tag) const { + return new XRMEExtension(tag); +} + +template +gloox::Tag* XRMEExtension::tag() const { + return tag_ ? tag_->clone() : NULL; +} + +template +gloox::StanzaExtension* XRMEExtension::clone() const { + return new XRMEExtension(*this); +} + +template +XRMEExtension::XRMEExtension(const gloox::Tag* tag) + : StanzaExtension(T::kExtensionType), + filter_string_(T::kFilterString), + tag_(tag) { +} + +template +XRMEExtension::XRMEExtension(const XRMEExtension& other) + : StanzaExtension(T::kExtensionType), + filter_string_(T::kFilterString), + tag_(other.tag_) { +} + +} // namespace xrme + +#endif // EXTENSIONS_H diff --git a/3rdparty/libxrme/mediaplayerhandler.cpp b/3rdparty/libxrme/mediaplayerhandler.cpp index 970015099..5fe49cb65 100644 --- a/3rdparty/libxrme/mediaplayerhandler.cpp +++ b/3rdparty/libxrme/mediaplayerhandler.cpp @@ -123,7 +123,8 @@ void MediaPlayerHandler::AlbumArtChanged() { void MediaPlayerHandler::Init(Connection* connection, gloox::Client* client) { Handler::Init(connection, client); - client->registerIqHandler(this, XRMEExtension::kExtensionType); + client->registerIqHandler( + this, MediaPlayerExtension::kExtensionType); client->disco()->addFeature(kXmlnsXrmeMediaPlayer); } @@ -134,15 +135,17 @@ bool MediaPlayerHandler::handleIq(const gloox::IQ& stanza) { return false; } - if (stanza.tag()->hasChild("playpause")) { + gloox::Tag* xrme = stanza.tag()->findChild("xrme"); + + if (xrme->hasChild("playpause")) { interface_->PlayPause(); - } else if (stanza.tag()->hasChild("stop")) { + } else if (xrme->hasChild("stop")) { interface_->Stop(); - } else if (stanza.tag()->hasChild("previous")) { + } else if (xrme->hasChild("previous")) { interface_->Previous(); - } else if (stanza.tag()->hasChild("next")) { + } else if (xrme->hasChild("next")) { interface_->Next(); - } else if (stanza.tag()->hasChild("querystate")) { + } else if (xrme->hasChild("querystate")) { StateChanged(); AlbumArtChanged(); } else { diff --git a/3rdparty/libxrme/remotecontrolhandler.cpp b/3rdparty/libxrme/remotecontrolhandler.cpp index 7bd839a06..5db377dee 100644 --- a/3rdparty/libxrme/remotecontrolhandler.cpp +++ b/3rdparty/libxrme/remotecontrolhandler.cpp @@ -36,7 +36,8 @@ RemoteControlHandler::RemoteControlHandler(RemoteControlInterface* interface) void RemoteControlHandler::Init(Connection* connection, gloox::Client* client) { Handler::Init(connection, client); - client->registerIqHandler(this, XRMEExtension::kExtensionType); + client->registerIqHandler( + this, RemoteControlExtension::kExtensionType); client->disco()->addFeature(kXmlnsXrmeRemoteControl); } @@ -92,6 +93,7 @@ QString RemoteControlHandler::ParseString(gloox::Tag* tag, const char* attribute } bool RemoteControlHandler::handleIq(const gloox::IQ& stanza) { + qDebug() << Q_FUNC_INFO << stanza.tag()->xml().c_str(); // Ignore stanzas from anyone else if (stanza.from().bareJID() != client_->jid().bareJID()) { return false; @@ -101,7 +103,9 @@ bool RemoteControlHandler::handleIq(const gloox::IQ& stanza) { qDebug() << resource << stanza.tag()->xml().c_str(); - gloox::Tag* state = stanza.tag()->findChild("state"); + gloox::Tag* xrme = stanza.tag()->findChild("xrme"); + + gloox::Tag* state = xrme->findChild("state"); if (state) { gloox::Tag* metadata = state->findChild("metadata"); if (metadata) { @@ -129,7 +133,7 @@ bool RemoteControlHandler::handleIq(const gloox::IQ& stanza) { } } - gloox::Tag* album_art = stanza.tag()->findChild("album_art"); + gloox::Tag* album_art = xrme->findChild("album_art"); if (album_art) { QByteArray data(album_art->cdata().c_str(), album_art->cdata().size());