mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-10 08:04:25 +02:00
Make the subscription request box non-blocking.
This commit is contained in:
@@ -151,7 +151,7 @@ Jabber_p::go()
|
|||||||
|
|
||||||
m_client->registerPresenceHandler( this );
|
m_client->registerPresenceHandler( this );
|
||||||
m_client->registerConnectionListener( 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->logInstance().registerLogHandler( LogLevelWarning, LogAreaAll, this );
|
||||||
m_client->registerMessageHandler( 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
|
// check if the requester is already on the roster
|
||||||
RosterItem *item = m_client->rosterManager()->getRosterItem(jid);
|
RosterItem *item = m_client->rosterManager()->getRosterItem(jid);
|
||||||
|
if(item) qDebug() << "subscription status:" << static_cast<int>( item->subscription() );
|
||||||
|
|
||||||
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::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...";
|
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() )
|
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" ;
|
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
|
// the user decides with the already open box, so we can return false here
|
||||||
|
m_client->rosterManager()->ackSubscriptionRequest( jid, false );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// preparing the confirm box for the user
|
// preparing the confirm box for the user
|
||||||
QWeakPointer<QMessageBox> confirmBox = QWeakPointer<QMessageBox>(new QMessageBox(
|
QWeakPointer<QMessageBox> confirmBox = QWeakPointer<QMessageBox>( new QMessageBox(
|
||||||
QMessageBox::Question,
|
QMessageBox::Question,
|
||||||
tr("Friend Request in Jabber"),
|
tr("Friend Request in Jabber"),
|
||||||
QString(tr("Do you want to be friends with <b>%1</b>?")).arg(QLatin1String(jid.bare().c_str())),
|
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));
|
0) );
|
||||||
|
|
||||||
// add confirmBox to m_subscriptionConfirmBoxes
|
// add confirmBox to m_subscriptionConfirmBoxes
|
||||||
m_subscriptionConfirmBoxes.insert(jid, confirmBox);
|
m_subscriptionConfirmBoxes.insert( jid, confirmBox );
|
||||||
|
|
||||||
// display the box and wait for the answer
|
// 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
|
// we got an answer, deleting the box
|
||||||
confirmBox.data()->deleteLater();
|
sender()->deleteLater();
|
||||||
|
|
||||||
|
QMessageBox::StandardButton allowSubscription = static_cast<QMessageBox::StandardButton>( result );
|
||||||
|
|
||||||
if(allowSubscription == QMessageBox::Ok)
|
if(allowSubscription == QMessageBox::Ok)
|
||||||
{
|
{
|
||||||
@@ -658,14 +683,15 @@ Jabber_p::handleSubscriptionRequest( const JID& jid, const std::string& /*msg*/
|
|||||||
groups.push_back( "Tomahawk" );
|
groups.push_back( "Tomahawk" );
|
||||||
m_client->rosterManager()->subscribe( jid, "", groups, "" );
|
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";
|
qDebug() << Q_FUNC_INFO << jid.bare().c_str() << "declined by user";
|
||||||
return false;
|
m_client->rosterManager()->ackSubscriptionRequest( jid, false );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Jabber_p::handleUnsubscriptionRequest( const JID& jid, const std::string& /*msg*/ )
|
Jabber_p::handleUnsubscriptionRequest( const JID& jid, const std::string& /*msg*/ )
|
||||||
{
|
{
|
||||||
|
@@ -154,6 +154,7 @@ public slots:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void doJabberRecv();
|
void doJabberRecv();
|
||||||
|
void onSubscriptionRequestConfirmed(int result);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool presenceMeansOnline( gloox::Presence::PresenceType p );
|
bool presenceMeansOnline( gloox::Presence::PresenceType p );
|
||||||
|
Reference in New Issue
Block a user