diff --git a/src/libtomahawk/infosystem/infosystemworker.cpp b/src/libtomahawk/infosystem/infosystemworker.cpp index c70cbe019..4b376a932 100644 --- a/src/libtomahawk/infosystem/infosystemworker.cpp +++ b/src/libtomahawk/infosystem/infosystemworker.cpp @@ -27,6 +27,8 @@ #include "infoplugins/musixmatchplugin.h" #include "infoplugins/lastfmplugin.h" +#include "lastfm/NetworkAccessManager" + namespace Tomahawk { @@ -165,7 +167,13 @@ void InfoSystemWorker::newNam() { qDebug() << Q_FUNC_INFO; - QNetworkAccessManager *newNam = new QNetworkAccessManager(); + + QNetworkAccessManager* newNam; +#ifdef LIBLASTFM_FOUND + newNam = new lastfm::NetworkAccessManager( this ); +#else + newNam = new QNetworkAccessManager( this ); +#endif if ( m_nam ) { delete m_nam; diff --git a/src/sip/jreen/jabber.cpp b/src/sip/jreen/jabber.cpp index 10a769774..1f418e8e7 100644 --- a/src/sip/jreen/jabber.cpp +++ b/src/sip/jreen/jabber.cpp @@ -61,6 +61,8 @@ JabberPlugin::JabberPlugin() // general client setup m_client = new Jreen::Client( jid, m_currentPassword ); + setupClientHelper(); + m_client->registerStanzaExtension(new TomahawkSipMessageFactory); m_currentResource = QString::fromAscii( "tomahawk%1" ).arg( QString::number( qrand() % 10000 ) ); m_client->setResource( m_currentResource ); @@ -68,6 +70,9 @@ JabberPlugin::JabberPlugin() // add VCardUpdate extension to own presence m_client->presence().addExtension( new Jreen::VCardUpdate() ); + // initaliaze the roster + m_roster = new Jreen::SimpleRoster( m_client ); + // initialize the AvatarManager m_avatarManager = new AvatarManager( m_client ); @@ -91,9 +96,14 @@ JabberPlugin::JabberPlugin() connect(m_client, SIGNAL(serverFeaturesReceived(QSet)), SLOT(onConnect())); connect(m_client, SIGNAL(disconnected(Jreen::Client::DisconnectReason)), SLOT(onDisconnect(Jreen::Client::DisconnectReason))); connect(m_client, SIGNAL(newMessage(Jreen::Message)), SLOT(onNewMessage(Jreen::Message))); - connect(m_client, SIGNAL(newPresence(Jreen::Presence)), SLOT(onNewPresence(Jreen::Presence))); + connect(m_client, SIGNAL(newIQ(Jreen::IQ)), SLOT(onNewIq(Jreen::IQ))); + connect(m_roster, SIGNAL(presenceReceived(Jreen::RosterItem::Ptr,Jreen::Presence)), + SLOT(onPresenceReceived(Jreen::RosterItem::Ptr,Jreen::Presence))); + connect(m_roster, SIGNAL(subscriptionReceived(Jreen::RosterItem::Ptr,Jreen::Presence)), + SLOT(onSubscriptionReceived(Jreen::RosterItem::Ptr,Jreen::Presence))); + connect(m_avatarManager, SIGNAL(newAvatar(QString)), SLOT(onNewAvatar(QString))); } @@ -201,7 +211,6 @@ JabberPlugin::onConnect() m_client->setPingInterval(1000); // load roster - m_roster = new Jreen::SimpleRoster( m_client ); m_roster->load(); //FIXME: this implementation is totally broken atm, so it's disabled to avoid harm :P @@ -432,17 +441,34 @@ JabberPlugin::checkSettings() m_currentServer = TomahawkSettings::instance()->jabberServer(); m_currentPort = TomahawkSettings::instance()->jabberPort(); - Jreen::JID jid = Jreen::JID( accountName() ); - m_client->setJID( jid ); - m_client->setPassword( m_currentPassword ); - m_client->setServer( m_currentServer ); - m_client->setPort( m_currentPort ); + setupClientHelper(); qDebug() << Q_FUNC_INFO << "Updated settings"; connectPlugin( false ); } } +void JabberPlugin::setupClientHelper() +{ + Jreen::JID jid = Jreen::JID( m_currentUsername ); + + m_client->setJID( jid ); + m_client->setPassword( m_currentPassword ); + + if( !m_currentServer.isEmpty() ) + { + // set explicit server details + m_client->setServer( m_currentServer ); + m_client->setPort( m_currentPort ); + } + else + { + // let jreen find out server and port via jdns + m_client->setServer( jid.domain() ); + m_client->setPort( -1 ); + } +} + void JabberPlugin::addMenuHelper() { if( !m_menu ) @@ -497,8 +523,10 @@ void JabberPlugin::onNewMessage(const Jreen::Message& message) } -void JabberPlugin::onNewPresence( const Jreen::Presence& presence) +void JabberPlugin::onPresenceReceived( const Jreen::RosterItem::Ptr &item, const Jreen::Presence& presence ) { + Q_UNUSED(item); + Jreen::JID jid = presence.from(); QString fulljid( jid.full() ); @@ -540,6 +568,93 @@ void JabberPlugin::onNewPresence( const Jreen::Presence& presence) } } +void JabberPlugin::onSubscriptionReceived(const Jreen::RosterItem::Ptr& item, const Jreen::Presence& presence) +{ + qDebug() << Q_FUNC_INFO << "presence type: " << presence.subtype(); + if(item) + qDebug() << Q_FUNC_INFO << presence.from().full() << "subs" << item->subscription() << "ask" << item->ask(); + else + qDebug() << Q_FUNC_INFO << "item empty"; + + // don't do anything if the contact is already subscribed to us + if( presence.subtype() != Jreen::Presence::Subscribe || + ( + item && (item->subscription() == Jreen::RosterItem::From || item->subscription() == Jreen::RosterItem::Both) + ) + ) + { + return; + } + + // check if the requester is already on the roster + if(item && + ( + item->subscription() == Jreen::RosterItem::To || + ( item->subscription() == Jreen::RosterItem::None && !item->ask().isEmpty() ) + ) + ) + { + qDebug() << Q_FUNC_INFO << presence.from().bare() << "already on the roster so we assume ack'ing subscription request is okay..."; + m_roster->allowSubscription(presence.from(), true); + + return; + } + + qDebug() << Q_FUNC_INFO << presence.from().bare() << "open subscription request box"; + + // preparing the confirm box for the user + QMessageBox *confirmBox = new QMessageBox( + QMessageBox::Question, + tr( "Authorize User" ), + QString( tr( "Do you want to grant %1 access to your Collection?" ) ).arg(presence.from().bare()), + QMessageBox::Yes | QMessageBox::No, + 0 + ); + + // add confirmBox to m_subscriptionConfirmBoxes + m_subscriptionConfirmBoxes.insert( presence.from(), confirmBox ); + + // display the box and wait for the answer + confirmBox->open( this, SLOT( onSubscriptionRequestConfirmed( int ) ) ); +} + +void +JabberPlugin::onSubscriptionRequestConfirmed( int result ) +{ + qDebug() << Q_FUNC_INFO << result; + + QList< QMessageBox* > confirmBoxes = m_subscriptionConfirmBoxes.values(); + Jreen::JID jid; + + foreach( QMessageBox* currentBox, confirmBoxes ) + { + if( currentBox == sender() ) + { + jid = m_subscriptionConfirmBoxes.key( currentBox ); + } + } + + qDebug() << Q_FUNC_INFO << "box confirmed for" << jid.bare(); + + // we got an answer, deleting the box + m_subscriptionConfirmBoxes.remove( jid ); + sender()->deleteLater(); + + QMessageBox::StandardButton allowSubscription = static_cast( result ); + + if ( allowSubscription == QMessageBox::Yes ) + { + qDebug() << Q_FUNC_INFO << jid.bare() << "accepted by user, adding to roster"; + addContact(jid, ""); + } + else + { + qDebug() << Q_FUNC_INFO << jid.bare() << "declined by user"; + } + + m_roster->allowSubscription( jid, allowSubscription == QMessageBox::Yes ); +} + void JabberPlugin::onNewIq(const Jreen::IQ& iq, int context) { if( context == RequestDisco ) diff --git a/src/sip/jreen/jabber.h b/src/sip/jreen/jabber.h index 17d4cc31b..67e3722d6 100644 --- a/src/sip/jreen/jabber.h +++ b/src/sip/jreen/jabber.h @@ -38,6 +38,7 @@ #include #include +#include #define MYNAME "SIPJREEN" #define TOMAHAWK_FEATURE QLatin1String( "tomahawk:sip:v1" ) @@ -79,7 +80,10 @@ private slots: void onDisconnect(Jreen::Client::DisconnectReason reason); void onAuthError(int code, const QString &msg); - void onNewPresence( const Jreen::Presence& presence ); + void onPresenceReceived( const Jreen::RosterItem::Ptr &item, const Jreen::Presence& presence ); + void onSubscriptionReceived( const Jreen::RosterItem::Ptr &item, const Jreen::Presence& presence ); + void onSubscriptionRequestConfirmed( int result ); + void onNewMessage( const Jreen::Message& message ); void onError( const Jreen::Connection::SocketError& e ) { @@ -89,6 +93,7 @@ private slots: void onNewAvatar( const QString &jid ); private: + void setupClientHelper(); void addMenuHelper(); void removeMenuHelper(); @@ -112,6 +117,7 @@ private: Jreen::MUCRoom *m_room; Jreen::SimpleRoster *m_roster; QHash m_peers; + QHash m_subscriptionConfirmBoxes; enum IqContext { NoContext, RequestDisco, RequestedDisco, SipMessageSent, RequestedVCard }; QStringList m_legacy_peers; AvatarManager *m_avatarManager; diff --git a/src/sip/twitter/twitter.cpp b/src/sip/twitter/twitter.cpp index 643f11fcd..d2eaa93a5 100644 --- a/src/sip/twitter/twitter.cpp +++ b/src/sip/twitter/twitter.cpp @@ -270,6 +270,7 @@ TwitterPlugin::connectTimerFired() { peerData["lastseen"] = QDateTime::currentMSecsSinceEpoch(); m_cachedPeers[screenName] = peerData; + continue; } if ( QDateTime::currentMSecsSinceEpoch() - peerData["lastseen"].toLongLong() > 1209600000 ) // 2 weeks diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index b826711c2..5d9a91e23 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -224,10 +224,10 @@ TomahawkApp::init() qDebug() << "Setting NAM."; TomahawkUtils::setNam( lastfm::nam() ); - #else +#else qDebug() << "Setting NAM."; TomahawkUtils::setNam( new QNetworkAccessManager() ); - #endif +#endif // Set up proxy //FIXME: This overrides the lastfm proxy above? diff --git a/thirdparty/jreen b/thirdparty/jreen index ed1680de0..8f995f246 160000 --- a/thirdparty/jreen +++ b/thirdparty/jreen @@ -1 +1 @@ -Subproject commit ed1680de066ec7a414117f94e92a9f1b9b40fb24 +Subproject commit 8f995f246637f533feb7124744e113034a32b505