1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-22 16:59:58 +01:00

Merge remote-tracking branch 'origin/master' into cleanmaster

This commit is contained in:
Leo Franchi 2011-05-02 16:29:42 -04:00
commit 59d72df046
6 changed files with 143 additions and 13 deletions

View File

@ -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;

View File

@ -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<QString>)), 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 <b>%1</b> 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<QMessageBox::StandardButton>( 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 )

View File

@ -38,6 +38,7 @@
#include <jreen/mucroom.h>
#include <QNetworkProxy>
#include <QMessageBox>
#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<Jreen::JID, Jreen::Presence::Type> m_peers;
QHash<Jreen::JID, QMessageBox*> m_subscriptionConfirmBoxes;
enum IqContext { NoContext, RequestDisco, RequestedDisco, SipMessageSent, RequestedVCard };
QStringList m_legacy_peers;
AvatarManager *m_avatarManager;

View File

@ -270,6 +270,7 @@ TwitterPlugin::connectTimerFired()
{
peerData["lastseen"] = QDateTime::currentMSecsSinceEpoch();
m_cachedPeers[screenName] = peerData;
continue;
}
if ( QDateTime::currentMSecsSinceEpoch() - peerData["lastseen"].toLongLong() > 1209600000 ) // 2 weeks

View File

@ -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?

2
thirdparty/jreen vendored

@ -1 +1 @@
Subproject commit ed1680de066ec7a414117f94e92a9f1b9b40fb24
Subproject commit 8f995f246637f533feb7124744e113034a32b505