1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-12 09:04:33 +02:00

* Merged stable to master.

This commit is contained in:
Christian Muehlhaeuser
2011-03-27 06:57:33 +02:00
2 changed files with 75 additions and 12 deletions

View File

@@ -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 );
@@ -612,25 +612,85 @@ Jabber_p::handleSubscriptionRequest( const JID& jid, const std::string& /*msg*/
{
qDebug() << Q_FUNC_INFO << jid.bare().c_str();
QMessageBox::StandardButton allowSubscription;
allowSubscription = QMessageBox::question( 0,
// check if the requester is already on the roster
RosterItem *item = m_client->rosterManager()->getRosterItem(jid);
if(item) qDebug() << "subscription status:" << static_cast<int>( 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.
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 << jid.bare().c_str() << "Already on the roster so we assume ack'ing subscription request is okay...";
m_client->rosterManager()->ackSubscriptionRequest( jid, true );
return false;
}
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
m_client->rosterManager()->ackSubscriptionRequest( jid, false );
return false;
}
// preparing the confirm box for the user
QWeakPointer<QMessageBox> confirmBox = QWeakPointer<QMessageBox>( new QMessageBox(
QMessageBox::Question,
tr("Friend Request in Jabber"),
QString(tr("Do you want to be friends with <b>%1</b>?")).arg(QLatin1String(jid.bare().c_str())),
QMessageBox::Ok | QMessageBox::Cancel
);
QMessageBox::Ok | QMessageBox::Cancel,
0) );
if(allowSubscription == QMessageBox::Ok)
{
StringList groups;
groups.push_back( "Tomahawk" );
m_client->rosterManager()->subscribe( jid, "", groups, "" );
// add confirmBox to m_subscriptionConfirmBoxes
m_subscriptionConfirmBoxes.insert( jid, confirmBox );
return true;
}
// display the box and wait for the answer
confirmBox.data()->open( this, SLOT( onSubscriptionRequestConfirmed( int ) ) );
return false;
}
void
Jabber_p::onSubscriptionRequestConfirmed(int result)
{
qDebug() << Q_FUNC_INFO;
QList< QWeakPointer<QMessageBox> > confirmBoxes = m_subscriptionConfirmBoxes.values();
JID jid;
foreach(QWeakPointer<QMessageBox> currentBox, confirmBoxes)
{
if( !currentBox.isNull() && currentBox.data() == sender() )
{
jid = m_subscriptionConfirmBoxes.key( currentBox );
}
}
// we got an answer, deleting the box
sender()->deleteLater();
QMessageBox::StandardButton allowSubscription = static_cast<QMessageBox::StandardButton>( result );
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, "" );
m_client->rosterManager()->ackSubscriptionRequest( jid, true );
return;
}
qDebug() << Q_FUNC_INFO << jid.bare().c_str() << "declined by user";
m_client->rosterManager()->ackSubscriptionRequest( jid, false );
return;
}
bool
Jabber_p::handleUnsubscriptionRequest( const JID& jid, const std::string& /*msg*/ )

View File

@@ -30,6 +30,7 @@
#include <QSocketNotifier>
#include <QMap>
#include <QNetworkProxy>
#include <QMessageBox>
#include <string>
@@ -153,6 +154,7 @@ public slots:
private slots:
void doJabberRecv();
void onSubscriptionRequestConfirmed(int result);
private:
bool presenceMeansOnline( gloox::Presence::PresenceType p );
@@ -164,6 +166,7 @@ private:
QSharedPointer<gloox::VCardManager> m_vcardManager;
QString m_server;
QScopedPointer<QSocketNotifier> m_notifier;
QHash<gloox::JID, QWeakPointer<QMessageBox> > m_subscriptionConfirmBoxes;
};
#endif // JABBER_H