1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-14 13:01:53 +02:00

Make the subscription request box non-blocking.

This commit is contained in:
Dominik Schmidt 2011-03-27 04:29:09 +02:00
parent 5056aadcd2
commit 99e1b6f327
2 changed files with 37 additions and 10 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 );
@ -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<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.
@ -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<QMessageBox> confirmBox = QWeakPointer<QMessageBox>(new QMessageBox(
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,
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<QMessageBox::StandardButton>(confirmBox.data()->exec());
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
confirmBox.data()->deleteLater();
sender()->deleteLater();
QMessageBox::StandardButton allowSubscription = static_cast<QMessageBox::StandardButton>( 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*/ )
{

View File

@ -154,6 +154,7 @@ public slots:
private slots:
void doJabberRecv();
void onSubscriptionRequestConfirmed(int result);
private:
bool presenceMeansOnline( gloox::Presence::PresenceType p );