From 6da813d4c3c5c677637c4fa4ee37cf44330ce710 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sat, 26 Mar 2011 07:19:15 +0100 Subject: [PATCH 1/6] * Updated stable README. --- README | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/README b/README index b5814e47a..a90caf57e 100644 --- a/README +++ b/README @@ -30,7 +30,7 @@ QJson (Qt JSON library) $ ./configure && make $ sudo make install -libEchonest 1.1.1 +libEchonest 1.1.4 --------------- See: http://projects.kde.org/projects/playground/libs/libechonest/ @@ -95,7 +95,7 @@ Dependencies libogg 1.1.4 http://xiph.org/ogg/ libflac++ 1.2.0 http://flac.sourceforge.net/ liblastfm 0.3.3 http://github.com/mxcl/liblastfm/ - libechonest 1.1.1 http://projects.kde.org/projects/playground/libs/libechonest/ + libechonest 1.1.4 http://projects.kde.org/projects/playground/libs/libechonest/ Third party libraries that we ship with our source: @@ -106,11 +106,7 @@ Dependencies To build the app: ----------------- $ mkdir build && cd build - - Pick one of the following two choices. If uncertain pick the second one, you probably want a GUI. - $ cmake -Dgui=no .. # enables headless mode, build without GUI - $ cmake .. # normal build including GUI - + $ cmake .. $ make To run the app: From 4677d761acd5e0d9c789a8e7f5917ad41f01c98e Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sat, 26 Mar 2011 18:26:31 +0100 Subject: [PATCH 2/6] Make the sip plugin aware of subscription requests again --- src/sip/jabber/jabber_p.cpp | 24 ++++++++++++++++++++---- src/sip/jabber/jabber_p.h | 6 ++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/sip/jabber/jabber_p.cpp b/src/sip/jabber/jabber_p.cpp index aafd29543..aa2a5598d 100644 --- a/src/sip/jabber/jabber_p.cpp +++ b/src/sip/jabber/jabber_p.cpp @@ -26,6 +26,7 @@ #include #include #include +#include using namespace gloox; using namespace std; @@ -148,6 +149,7 @@ Jabber_p::go() m_client->registerPresenceHandler( this ); m_client->registerConnectionListener( this ); + m_client->rosterManager()->registerRosterListener( this ); m_client->logInstance().registerLogHandler( LogLevelWarning, LogAreaAll, this ); m_client->registerMessageHandler( this ); @@ -598,10 +600,24 @@ bool Jabber_p::handleSubscriptionRequest( const JID& jid, const std::string& /*msg*/ ) { qDebug() << Q_FUNC_INFO << jid.bare().c_str(); - StringList groups; - groups.push_back( "Tomahawk" ); - m_client->rosterManager()->subscribe( jid, "", groups, "" ); - return true; + + QMessageBox::StandardButton allowSubscription; + allowSubscription = QMessageBox::question( 0, + tr("Friend Request in Jabber"), + QString(tr("Do you want to be friends with %1?")).arg(QLatin1String(jid.bare().c_str())), + QMessageBox::Ok | QMessageBox::Cancel + ); + + if(allowSubscription == QMessageBox::Ok) + { + StringList groups; + groups.push_back( "Tomahawk" ); + m_client->rosterManager()->subscribe( jid, "", groups, "" ); + + return true; + } + + return false; } diff --git a/src/sip/jabber/jabber_p.h b/src/sip/jabber/jabber_p.h index 3e14c7c69..f051915bc 100644 --- a/src/sip/jabber/jabber_p.h +++ b/src/sip/jabber/jabber_p.h @@ -76,6 +76,7 @@ class SIPDLLEXPORT Jabber_p : public gloox::MessageHandler, public gloox::VCardHandler, public gloox::PresenceHandler, + public gloox::RosterListener, gloox::LogHandler //public gloox::DiscoHandler, { @@ -109,6 +110,11 @@ public: virtual void handleRoster( const gloox::Roster& roster ); virtual void handleRosterError( const gloox::IQ& /*iq*/ ); + + // not actually used, just needed for the interface to support subscription requests, see handlePresence for presence handling + virtual void handleRosterPresence( const gloox::RosterItem&, const std::string&, gloox::Presence::PresenceType, const std::string& ) {} + virtual void handleSelfPresence( const gloox::RosterItem&, const std::string&, gloox::Presence::PresenceType, const std::string& ) {} + virtual void handlePresence( const gloox::Presence& presence ); virtual bool handleSubscription( const gloox::JID& jid, const std::string& /*msg*/ ); virtual bool handleSubscriptionRequest( const gloox::JID& jid, const std::string& /*msg*/ ); From 9496885d63d2493b36cbe141834571cc8387fc6f Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sat, 26 Mar 2011 19:58:31 +0100 Subject: [PATCH 3/6] Don't ask the user again to ack the subscription request in sip_jabber if the requesting contact is already on the roster --- src/sip/jabber/jabber_p.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/sip/jabber/jabber_p.cpp b/src/sip/jabber/jabber_p.cpp index aa2a5598d..9f2d6276b 100644 --- a/src/sip/jabber/jabber_p.cpp +++ b/src/sip/jabber/jabber_p.cpp @@ -601,6 +601,17 @@ Jabber_p::handleSubscriptionRequest( const JID& jid, const std::string& /*msg*/ { qDebug() << Q_FUNC_INFO << jid.bare().c_str(); + // check if the requester is already on the roster + RosterItem *item = m_client->rosterManager()->getRosterItem(jid); + if(item) + { + qDebug() << Q_FUNC_INFO << "Already on the roster so we assume ack'ing subscription request is okay..."; + return true; + } + + + + // ask whether to accept subscription request or not QMessageBox::StandardButton allowSubscription; allowSubscription = QMessageBox::question( 0, tr("Friend Request in Jabber"), From 9558270d86be86dff2e5bee53871f75360d085e1 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sat, 26 Mar 2011 16:49:26 -0400 Subject: [PATCH 4/6] Display a helpful message when someone gives non-JSON data to the xmpp bot --- src/sip/jabber/jabber_p.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/sip/jabber/jabber_p.cpp b/src/sip/jabber/jabber_p.cpp index 9f2d6276b..2c080004b 100644 --- a/src/sip/jabber/jabber_p.cpp +++ b/src/sip/jabber/jabber_p.cpp @@ -24,9 +24,11 @@ #include #include #include +#include #include #include #include +#include using namespace gloox; using namespace std; @@ -430,6 +432,15 @@ Jabber_p::handleMessage( const Message& m, MessageSession * /*session*/ ) //sendMsg( from, QString("You said %1").arg(msg) ); + QJson::Parser parser; + bool ok; + QVariant v = parser.parse( msg.toAscii(), &ok ); + if ( !ok || v.type() != QVariant::Map ) + { + sendMsg( from, QString( "I'm sorry -- I'm just an automatic presence used by Tomahawk Player (http://gettomahawk.com). If you are getting this message, the person you are trying to reach is probably not signed on, so please try again later!" ) ); + return; + } + emit msgReceived( from, msg ); } From 5056aadcd20160756378c5da3d7ed0c67a0cbc8a Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sun, 27 Mar 2011 01:24:18 +0100 Subject: [PATCH 5/6] Don't open more than one SubscriptionRequest window and auto-ack only contacts that the user is already subscribed to --- src/sip/jabber/jabber_p.cpp | 41 +++++++++++++++++++++++++++++-------- src/sip/jabber/jabber_p.h | 2 ++ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/sip/jabber/jabber_p.cpp b/src/sip/jabber/jabber_p.cpp index 2c080004b..294ea032a 100644 --- a/src/sip/jabber/jabber_p.cpp +++ b/src/sip/jabber/jabber_p.cpp @@ -614,24 +614,46 @@ Jabber_p::handleSubscriptionRequest( const JID& jid, const std::string& /*msg*/ // check if the requester is already on the roster RosterItem *item = m_client->rosterManager()->getRosterItem(jid); - if(item) + if(item && + ( + item->subscription() == gloox::S10nNoneOut || // Contact and user are not subscribed to each other, and user has sent contact a subscription request but contact has not replied yet. + item->subscription() == gloox::S10nTo || // User is subscribed to contact (one-way). + item->subscription() == gloox::S10nToIn // User is subscribed to contact, and contact has sent user a subscription request but user has not replied yet. + ) + ) { - qDebug() << Q_FUNC_INFO << "Already on the roster so we assume ack'ing subscription request is okay..."; + qDebug() << Q_FUNC_INFO << jid.bare().c_str() << "Already on the roster so we assume ack'ing subscription request is okay..."; return true; } + if( !m_subscriptionConfirmBoxes.value(jid).isNull() ) + { + qDebug() << Q_FUNC_INFO << jid.bare().c_str() << " confirmBox already open" ; + // the user decides with the already open box, so we can return false here + return false; + } - // ask whether to accept subscription request or not - QMessageBox::StandardButton allowSubscription; - allowSubscription = QMessageBox::question( 0, - tr("Friend Request in Jabber"), - QString(tr("Do you want to be friends with %1?")).arg(QLatin1String(jid.bare().c_str())), - QMessageBox::Ok | QMessageBox::Cancel - ); + // preparing the confirm box for the user + QWeakPointer confirmBox = QWeakPointer(new QMessageBox( + QMessageBox::Question, + tr("Friend Request in Jabber"), + QString(tr("Do you want to be friends with %1?")).arg(QLatin1String(jid.bare().c_str())), + QMessageBox::Ok | QMessageBox::Cancel, + 0)); + + // add confirmBox to m_subscriptionConfirmBoxes + m_subscriptionConfirmBoxes.insert(jid, confirmBox); + + // display the box and wait for the answer + QMessageBox::StandardButton allowSubscription = static_cast(confirmBox.data()->exec()); + + // we got an answer, deleting the box + confirmBox.data()->deleteLater(); if(allowSubscription == QMessageBox::Ok) { + qDebug() << Q_FUNC_INFO << jid.bare().c_str() << "accepted by user, adding to roster"; StringList groups; groups.push_back( "Tomahawk" ); m_client->rosterManager()->subscribe( jid, "", groups, "" ); @@ -639,6 +661,7 @@ Jabber_p::handleSubscriptionRequest( const JID& jid, const std::string& /*msg*/ return true; } + qDebug() << Q_FUNC_INFO << jid.bare().c_str() << "declined by user"; return false; } diff --git a/src/sip/jabber/jabber_p.h b/src/sip/jabber/jabber_p.h index f051915bc..6f9431985 100644 --- a/src/sip/jabber/jabber_p.h +++ b/src/sip/jabber/jabber_p.h @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -164,6 +165,7 @@ private: QSharedPointer m_vcardManager; QString m_server; QScopedPointer m_notifier; + QHash > m_subscriptionConfirmBoxes; }; #endif // JABBER_H From 99e1b6f327c7fa69f569c01248f6605c5dfbc383 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sun, 27 Mar 2011 04:29:09 +0200 Subject: [PATCH 6/6] Make the subscription request box non-blocking. --- src/sip/jabber/jabber_p.cpp | 46 +++++++++++++++++++++++++++++-------- src/sip/jabber/jabber_p.h | 1 + 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/sip/jabber/jabber_p.cpp b/src/sip/jabber/jabber_p.cpp index 294ea032a..9e28ed034 100644 --- a/src/sip/jabber/jabber_p.cpp +++ b/src/sip/jabber/jabber_p.cpp @@ -151,7 +151,7 @@ Jabber_p::go() m_client->registerPresenceHandler( this ); m_client->registerConnectionListener( this ); - m_client->rosterManager()->registerRosterListener( this ); + m_client->rosterManager()->registerRosterListener( this, false ); // false means async m_client->logInstance().registerLogHandler( LogLevelWarning, LogAreaAll, this ); m_client->registerMessageHandler( this ); @@ -614,6 +614,8 @@ Jabber_p::handleSubscriptionRequest( const JID& jid, const std::string& /*msg*/ // check if the requester is already on the roster RosterItem *item = m_client->rosterManager()->getRosterItem(jid); + if(item) qDebug() << "subscription status:" << static_cast( item->subscription() ); + if(item && ( item->subscription() == gloox::S10nNoneOut || // Contact and user are not subscribed to each other, and user has sent contact a subscription request but contact has not replied yet. @@ -623,7 +625,9 @@ Jabber_p::handleSubscriptionRequest( const JID& jid, const std::string& /*msg*/ ) { qDebug() << Q_FUNC_INFO << jid.bare().c_str() << "Already on the roster so we assume ack'ing subscription request is okay..."; - return true; + + m_client->rosterManager()->ackSubscriptionRequest( jid, true ); + return false; } if( !m_subscriptionConfirmBoxes.value(jid).isNull() ) @@ -631,25 +635,46 @@ Jabber_p::handleSubscriptionRequest( const JID& jid, const std::string& /*msg*/ qDebug() << Q_FUNC_INFO << jid.bare().c_str() << " confirmBox already open" ; // the user decides with the already open box, so we can return false here + m_client->rosterManager()->ackSubscriptionRequest( jid, false ); return false; } // preparing the confirm box for the user - QWeakPointer confirmBox = QWeakPointer(new QMessageBox( + QWeakPointer confirmBox = QWeakPointer( new QMessageBox( QMessageBox::Question, tr("Friend Request in Jabber"), QString(tr("Do you want to be friends with %1?")).arg(QLatin1String(jid.bare().c_str())), QMessageBox::Ok | QMessageBox::Cancel, - 0)); + 0) ); // add confirmBox to m_subscriptionConfirmBoxes - m_subscriptionConfirmBoxes.insert(jid, confirmBox); + m_subscriptionConfirmBoxes.insert( jid, confirmBox ); // display the box and wait for the answer - QMessageBox::StandardButton allowSubscription = static_cast(confirmBox.data()->exec()); + confirmBox.data()->open( this, SLOT( onSubscriptionRequestConfirmed( int ) ) ); + + return false; +} + +void +Jabber_p::onSubscriptionRequestConfirmed(int result) +{ + qDebug() << Q_FUNC_INFO; + + QList< QWeakPointer > confirmBoxes = m_subscriptionConfirmBoxes.values(); + JID jid; + foreach(QWeakPointer currentBox, confirmBoxes) + { + if( !currentBox.isNull() && currentBox.data() == sender() ) + { + jid = m_subscriptionConfirmBoxes.key( currentBox ); + } + } // we got an answer, deleting the box - confirmBox.data()->deleteLater(); + sender()->deleteLater(); + + QMessageBox::StandardButton allowSubscription = static_cast( result ); if(allowSubscription == QMessageBox::Ok) { @@ -658,14 +683,15 @@ Jabber_p::handleSubscriptionRequest( const JID& jid, const std::string& /*msg*/ groups.push_back( "Tomahawk" ); m_client->rosterManager()->subscribe( jid, "", groups, "" ); - return true; + m_client->rosterManager()->ackSubscriptionRequest( jid, true ); + return; } qDebug() << Q_FUNC_INFO << jid.bare().c_str() << "declined by user"; - return false; + m_client->rosterManager()->ackSubscriptionRequest( jid, false ); + return; } - bool Jabber_p::handleUnsubscriptionRequest( const JID& jid, const std::string& /*msg*/ ) { diff --git a/src/sip/jabber/jabber_p.h b/src/sip/jabber/jabber_p.h index 6f9431985..9a9ddee0f 100644 --- a/src/sip/jabber/jabber_p.h +++ b/src/sip/jabber/jabber_p.h @@ -154,6 +154,7 @@ public slots: private slots: void doJabberRecv(); + void onSubscriptionRequestConfirmed(int result); private: bool presenceMeansOnline( gloox::Presence::PresenceType p );