mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-10 08:04:25 +02:00
* Style cleanup for XmppSip.
This commit is contained in:
@@ -65,6 +65,10 @@ using namespace Accounts;
|
||||
// instead of simply copying this function for another thirdparty lib
|
||||
// please make it a meta-function or a macro and put it in Logger.h. kthxbbq
|
||||
#define JREEN_LOG_INFIX "Jreen"
|
||||
#define TOMAHAWK_FEATURE QLatin1String( "tomahawk:sip:v1" )
|
||||
#define TOMAHAWK_CAP_NODE_NAME QLatin1String( "http://tomahawk-player.org/" )
|
||||
|
||||
|
||||
void
|
||||
JreenMessageHandler( QtMsgType type, const char *msg )
|
||||
{
|
||||
@@ -85,6 +89,7 @@ JreenMessageHandler(QtMsgType type, const char *msg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
XmppSipPlugin::XmppSipPlugin( Account* account )
|
||||
: SipPlugin( account )
|
||||
, m_state( Account::Disconnected )
|
||||
@@ -97,7 +102,6 @@ XmppSipPlugin::XmppSipPlugin( Account *account )
|
||||
Jreen::Logger::addHandler( JreenMessageHandler );
|
||||
|
||||
m_currentUsername = readUsername();
|
||||
|
||||
m_currentServer = readServer();
|
||||
m_currentPassword = readPassword();
|
||||
m_currentPort = readPort();
|
||||
@@ -122,6 +126,7 @@ XmppSipPlugin::XmppSipPlugin( Account *account )
|
||||
m_xmlConsole->show();
|
||||
}
|
||||
#endif
|
||||
|
||||
// add VCardUpdate extension to own presence
|
||||
m_client->presence().addExtension( new Jreen::VCardUpdate() );
|
||||
|
||||
@@ -169,14 +174,15 @@ XmppSipPlugin::XmppSipPlugin( Account *account )
|
||||
// Clear status
|
||||
Jreen::Tune::Ptr tune( new Jreen::Tune() );
|
||||
m_pubSubManager->publishItems( QList<Jreen::Payload::Ptr>() << tune, Jreen::JID() );
|
||||
|
||||
}
|
||||
|
||||
|
||||
XmppSipPlugin::~XmppSipPlugin()
|
||||
{
|
||||
//Note: the next two lines don't currently work, because the deletion wipes out internally posted events, need to talk to euro about a fix
|
||||
Jreen::Tune::Ptr tune( new Jreen::Tune() );
|
||||
m_pubSubManager->publishItems( QList<Jreen::Payload::Ptr>() << tune, Jreen::JID() );
|
||||
|
||||
delete m_pubSubManager;
|
||||
delete m_avatarManager;
|
||||
delete m_roster;
|
||||
@@ -205,11 +211,10 @@ XmppSipPlugin::menu()
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
XmppSipPlugin::connectPlugin()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
if ( m_client->isConnected() )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Already connected to server, not connecting again...";
|
||||
@@ -232,7 +237,6 @@ XmppSipPlugin::connectPlugin()
|
||||
|
||||
m_state = Account::Connecting;
|
||||
emit stateChanged( m_state );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -267,8 +271,6 @@ XmppSipPlugin::disconnectPlugin()
|
||||
void
|
||||
XmppSipPlugin::onConnect()
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO;
|
||||
|
||||
// update jid resource, servers like gtalk use resource binding and may
|
||||
// have changed our requested /resource
|
||||
if ( m_client->jid().resource() != m_currentResource )
|
||||
@@ -277,15 +279,9 @@ XmppSipPlugin::onConnect()
|
||||
emit jidChanged( m_client->jid().full() );
|
||||
}
|
||||
|
||||
qDebug() << "Connected to xmpp as:" << m_client->jid().full();
|
||||
|
||||
// set presence to least valid value
|
||||
m_client->setPresence( Jreen::Presence::XA, "Got Tomahawk? http://gettomahawk.com", -127 );
|
||||
|
||||
// set ping timeout to 15 secs (TODO: verify if this works)
|
||||
m_client->setPingInterval( 1000 );
|
||||
|
||||
// load roster
|
||||
m_roster->load();
|
||||
|
||||
// load XmppInfoPlugin
|
||||
@@ -298,7 +294,7 @@ XmppSipPlugin::onConnect()
|
||||
//FIXME: this implementation is totally broken atm, so it's disabled to avoid harm :P
|
||||
// join MUC with bare jid as nickname
|
||||
//TODO: make the room a list of rooms and make that configurable
|
||||
QString mucNickname = QString( "tomahawk@conference.qutim.org/" ).append( QString( m_client->jid().bare() ).replace( "@", "-" ) );
|
||||
// QString mucNickname = QString( "tomahawk@conference.qutim.org/" ).append( QString( m_client->jid().bare() ).replace( "@", "-" ) );
|
||||
//m_room = new Jreen::MUCRoom(m_client, Jreen::JID( mucNickname ) );
|
||||
//m_room->setHistorySeconds(0);
|
||||
//m_room->join();
|
||||
@@ -317,8 +313,6 @@ XmppSipPlugin::onConnect()
|
||||
void
|
||||
XmppSipPlugin::onDisconnect( Jreen::Client::DisconnectReason reason )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
switch( reason )
|
||||
{
|
||||
case Jreen::Client::User:
|
||||
@@ -345,7 +339,7 @@ XmppSipPlugin::onDisconnect( Jreen::Client::DisconnectReason reason )
|
||||
|
||||
default:
|
||||
qDebug() << "Not all Client::DisconnectReasons checked" << ( int ) reason;
|
||||
Q_ASSERT(false);
|
||||
Q_ASSERT( false s);
|
||||
break;
|
||||
}
|
||||
m_state = Account::Disconnected;
|
||||
@@ -402,26 +396,21 @@ XmppSipPlugin::errorMessage( Jreen::Client::DisconnectReason reason )
|
||||
case Jreen::Client::Conflict:
|
||||
return tr( "Conflict" );
|
||||
break;
|
||||
|
||||
case Jreen::Client::Unknown:
|
||||
return tr("Unknown");
|
||||
break;
|
||||
|
||||
case Jreen::Client::NoCompressionSupport:
|
||||
return tr( "No Compression Support" );
|
||||
break;
|
||||
|
||||
case Jreen::Client::NoEncryptionSupport:
|
||||
return tr( "No Encryption Support" );
|
||||
break;
|
||||
|
||||
case Jreen::Client::NoAuthorizationSupport:
|
||||
return tr( "No Authorization Support" );
|
||||
break;
|
||||
|
||||
case Jreen::Client::NoSupportedFeature:
|
||||
return tr( "No Supported Feature" );
|
||||
break;
|
||||
case Jreen::Client::Unknown:
|
||||
return tr( "Unknown" );
|
||||
break;
|
||||
|
||||
default:
|
||||
qDebug() << "Not all Client::DisconnectReasons checked";
|
||||
@@ -441,9 +430,8 @@ XmppSipPlugin::sendMsg( const QString& to, const QString& msg )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << to << msg;
|
||||
|
||||
if ( !m_client ) {
|
||||
if ( !m_client )
|
||||
return;
|
||||
}
|
||||
|
||||
/*******************************************************
|
||||
* Obsolete this by a SipMessage class
|
||||
@@ -456,22 +444,17 @@ XmppSipPlugin::sendMsg( const QString& to, const QString& msg )
|
||||
qDebug() << "Invalid JSON in Xmpp msg";
|
||||
return;
|
||||
}
|
||||
|
||||
QVariantMap m = v.toMap();
|
||||
/*******************************************************/
|
||||
|
||||
TomahawkXmppMessage *sipMessage;
|
||||
if ( m["visible"].toBool() )
|
||||
{
|
||||
sipMessage = new TomahawkXmppMessage( m["ip"].toString(),
|
||||
m["port"].toInt(),
|
||||
m["uniqname"].toString(),
|
||||
m["key"].toString()
|
||||
);
|
||||
sipMessage = new TomahawkXmppMessage( m["ip"].toString(), m["port"].toInt(), m["uniqname"].toString(), m["key"].toString() );
|
||||
}
|
||||
else
|
||||
{
|
||||
sipMessage = new TomahawkXmppMessage();
|
||||
}
|
||||
|
||||
qDebug() << "Send sip messsage to" << to;
|
||||
Jreen::IQ iq( Jreen::IQ::Set, to );
|
||||
@@ -485,8 +468,6 @@ XmppSipPlugin::sendMsg( const QString& to, const QString& msg )
|
||||
void
|
||||
XmppSipPlugin::broadcastMsg( const QString& msg )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
if ( !m_client )
|
||||
return;
|
||||
|
||||
@@ -501,14 +482,11 @@ void
|
||||
XmppSipPlugin::addContact( const QString& jid, const QString& msg )
|
||||
{
|
||||
// Add contact to the Tomahawk group on the roster
|
||||
|
||||
QString realJid = jid;
|
||||
if ( !realJid.contains( '@' ) )
|
||||
realJid += defaultSuffix();
|
||||
|
||||
m_roster->subscribe( realJid, msg, realJid, QStringList() << "Tomahawk" );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -642,7 +620,9 @@ XmppSipPlugin::configurationChanged()
|
||||
}
|
||||
}
|
||||
|
||||
void XmppSipPlugin::setupClientHelper()
|
||||
|
||||
void
|
||||
XmppSipPlugin::setupClientHelper()
|
||||
{
|
||||
Jreen::JID jid = Jreen::JID( m_currentUsername );
|
||||
m_client->setJID( jid );
|
||||
@@ -662,7 +642,9 @@ void XmppSipPlugin::setupClientHelper()
|
||||
}
|
||||
}
|
||||
|
||||
void XmppSipPlugin::addMenuHelper()
|
||||
|
||||
void
|
||||
XmppSipPlugin::addMenuHelper()
|
||||
{
|
||||
#ifndef ENABLE_HEADLESS
|
||||
if ( !m_menu )
|
||||
@@ -670,12 +652,12 @@ void XmppSipPlugin::addMenuHelper()
|
||||
m_menu = new QMenu( QString( "%1 (" ).arg( friendlyName() ).append( readUsername() ).append(")" ) );
|
||||
|
||||
QAction* addFriendAction = m_menu->addAction( tr( "Add Friend..." ) );
|
||||
connect( addFriendAction, SIGNAL( triggered() ), this, SLOT( showAddFriendDialog() ) );
|
||||
connect( addFriendAction, SIGNAL( triggered() ), SLOT( showAddFriendDialog() ) );
|
||||
|
||||
if ( readXmlConsoleEnabled() )
|
||||
{
|
||||
QAction* showXmlConsoleAction = m_menu->addAction( tr( "XML Console..." ) );
|
||||
connect( showXmlConsoleAction, SIGNAL( triggered() ), this, SLOT( showXmlConsole() ) );
|
||||
connect( showXmlConsoleAction, SIGNAL( triggered() ), SLOT( showXmlConsole() ) );
|
||||
}
|
||||
|
||||
emit addMenu( m_menu );
|
||||
@@ -683,7 +665,9 @@ void XmppSipPlugin::addMenuHelper()
|
||||
#endif
|
||||
}
|
||||
|
||||
void XmppSipPlugin::removeMenuHelper()
|
||||
|
||||
void
|
||||
XmppSipPlugin::removeMenuHelper()
|
||||
{
|
||||
#ifndef ENABLE_HEADLESS
|
||||
if ( m_menu )
|
||||
@@ -697,13 +681,12 @@ void XmppSipPlugin::removeMenuHelper()
|
||||
}
|
||||
|
||||
|
||||
void XmppSipPlugin::onNewMessage( const Jreen::Message& message )
|
||||
void
|
||||
XmppSipPlugin::onNewMessage( const Jreen::Message& message )
|
||||
{
|
||||
if ( m_state != Account::Connected )
|
||||
return;
|
||||
|
||||
// qDebug() << Q_FUNC_INFO << "message type" << message.subtype();
|
||||
|
||||
QString from = message.from().full();
|
||||
QString msg = message.body();
|
||||
|
||||
@@ -718,7 +701,6 @@ void XmppSipPlugin::onNewMessage( const Jreen::Message& message )
|
||||
}
|
||||
|
||||
SipInfo info = SipInfo::fromJson( msg );
|
||||
|
||||
if ( !info.isValid() )
|
||||
{
|
||||
QString to = from;
|
||||
@@ -738,7 +720,8 @@ void XmppSipPlugin::onNewMessage( const Jreen::Message& message )
|
||||
}
|
||||
|
||||
|
||||
void XmppSipPlugin::onPresenceReceived( const Jreen::RosterItem::Ptr &item, const Jreen::Presence& presence )
|
||||
void
|
||||
XmppSipPlugin::onPresenceReceived( const Jreen::RosterItem::Ptr& item, const Jreen::Presence& presence )
|
||||
{
|
||||
Q_UNUSED(item);
|
||||
if ( m_state != Account::Connected )
|
||||
@@ -752,7 +735,8 @@ void XmppSipPlugin::onPresenceReceived( const Jreen::RosterItem::Ptr &item, cons
|
||||
if ( jid == m_client->jid() )
|
||||
return;
|
||||
|
||||
if ( presence.error() ) {
|
||||
if ( presence.error() )
|
||||
{
|
||||
//qDebug() << Q_FUNC_INFO << fulljid << "Running tomahawk: no" << "presence error";
|
||||
return;
|
||||
}
|
||||
@@ -782,12 +766,12 @@ void XmppSipPlugin::onPresenceReceived( const Jreen::RosterItem::Ptr &item, cons
|
||||
}
|
||||
|
||||
|
||||
void XmppSipPlugin::onSubscriptionReceived( const Jreen::RosterItem::Ptr& item, const Jreen::Presence& presence )
|
||||
void
|
||||
XmppSipPlugin::onSubscriptionReceived( const Jreen::RosterItem::Ptr& item, const Jreen::Presence& presence )
|
||||
{
|
||||
if ( m_state != Account::Connected )
|
||||
return;
|
||||
|
||||
// qDebug() << Q_FUNC_INFO << "presence type:" << presence.subtype();
|
||||
if ( item )
|
||||
qDebug() << Q_FUNC_INFO << presence.from().full() << "subs" << item->subscription() << "ask" << item->ask();
|
||||
else
|
||||
@@ -795,27 +779,21 @@ void XmppSipPlugin::onSubscriptionReceived( const Jreen::RosterItem::Ptr& item,
|
||||
|
||||
// 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)
|
||||
)
|
||||
)
|
||||
( 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() )
|
||||
)
|
||||
)
|
||||
( 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;
|
||||
}
|
||||
|
||||
#ifndef ENABLE_HEADLESS
|
||||
// preparing the confirm box for the user
|
||||
QMessageBox *confirmBox = new QMessageBox(
|
||||
@@ -857,7 +835,6 @@ XmppSipPlugin::onSubscriptionRequestConfirmed( int result )
|
||||
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";
|
||||
@@ -873,7 +850,8 @@ XmppSipPlugin::onSubscriptionRequestConfirmed( int result )
|
||||
}
|
||||
|
||||
|
||||
void XmppSipPlugin::onNewIq( const Jreen::IQ& iq )
|
||||
void
|
||||
XmppSipPlugin::onNewIq( const Jreen::IQ& iq )
|
||||
{
|
||||
if ( m_state != Account::Connected )
|
||||
return;
|
||||
@@ -887,10 +865,9 @@ void XmppSipPlugin::onNewIq( const Jreen::IQ& iq )
|
||||
Jreen::Disco::Info *discoInfo = iq.payload< Jreen::Disco::Info >().data();
|
||||
if ( !discoInfo )
|
||||
return;
|
||||
|
||||
iq.accept();
|
||||
|
||||
Jreen::JID jid = iq.from();
|
||||
|
||||
Jreen::DataForm::Ptr form = discoInfo->form();
|
||||
|
||||
if ( discoInfo->features().contains( TOMAHAWK_FEATURE ) )
|
||||
@@ -937,7 +914,6 @@ void XmppSipPlugin::onNewIq( const Jreen::IQ& iq )
|
||||
info.setVisible( sipMessage->visible() );
|
||||
if ( sipMessage->visible() )
|
||||
{
|
||||
|
||||
QHostInfo hi;
|
||||
hi.setHostName( sipMessage->ip() );
|
||||
info.setHost( hi );
|
||||
@@ -955,7 +931,8 @@ void XmppSipPlugin::onNewIq( const Jreen::IQ& iq )
|
||||
}
|
||||
|
||||
|
||||
bool XmppSipPlugin::presenceMeansOnline( Jreen::Presence::Type p )
|
||||
bool
|
||||
XmppSipPlugin::presenceMeansOnline( Jreen::Presence::Type p )
|
||||
{
|
||||
switch( p )
|
||||
{
|
||||
@@ -964,22 +941,21 @@ bool XmppSipPlugin::presenceMeansOnline( Jreen::Presence::Type p )
|
||||
case Jreen::Presence::Error:
|
||||
return false;
|
||||
break;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void XmppSipPlugin::handlePeerStatus( const Jreen::JID& jid, Jreen::Presence::Type presenceType )
|
||||
void
|
||||
XmppSipPlugin::handlePeerStatus( const Jreen::JID& jid, Jreen::Presence::Type presenceType )
|
||||
{
|
||||
QString fulljid = jid.full();
|
||||
|
||||
// "going offline" event
|
||||
if ( !presenceMeansOnline( presenceType ) &&
|
||||
( !m_peers.contains( jid ) ||
|
||||
presenceMeansOnline( m_peers.value( jid ) )
|
||||
)
|
||||
)
|
||||
( !m_peers.contains( jid ) || presenceMeansOnline( m_peers.value( jid ) ) ) )
|
||||
{
|
||||
m_peers[ jid ] = presenceType;
|
||||
qDebug() << Q_FUNC_INFO << "* Peer goes offline:" << fulljid;
|
||||
@@ -990,10 +966,7 @@ void XmppSipPlugin::handlePeerStatus( const Jreen::JID& jid, Jreen::Presence::Ty
|
||||
|
||||
// "coming online" event
|
||||
if ( presenceMeansOnline( presenceType ) &&
|
||||
( !m_peers.contains( jid ) ||
|
||||
!presenceMeansOnline( m_peers.value( jid ) )
|
||||
)
|
||||
)
|
||||
( !m_peers.contains( jid ) || !presenceMeansOnline( m_peers.value( jid ) ) ) )
|
||||
{
|
||||
m_peers[ jid ] = presenceType;
|
||||
qDebug() << Q_FUNC_INFO << "* Peer goes online:" << fulljid;
|
||||
@@ -1020,7 +993,8 @@ void XmppSipPlugin::handlePeerStatus( const Jreen::JID& jid, Jreen::Presence::Ty
|
||||
}
|
||||
|
||||
|
||||
void XmppSipPlugin::onNewAvatar( const QString& jid )
|
||||
void
|
||||
XmppSipPlugin::onNewAvatar( const QString& jid )
|
||||
{
|
||||
#ifndef ENABLE_HEADLESS
|
||||
// qDebug() << Q_FUNC_INFO << jid;
|
||||
@@ -1065,6 +1039,7 @@ XmppSipPlugin::readUsername()
|
||||
return credentials.contains( "username" ) ? credentials[ "username" ].toString() : QString();
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
XmppSipPlugin::readPassword()
|
||||
{
|
||||
|
@@ -48,9 +48,6 @@
|
||||
#include <QtGui/QMessageBox>
|
||||
#endif
|
||||
|
||||
#define TOMAHAWK_FEATURE QLatin1String( "tomahawk:sip:v1" )
|
||||
#define TOMAHAWK_CAP_NODE_NAME QLatin1String( "http://tomahawk-player.org/" )
|
||||
|
||||
#include "accounts/AccountDllMacro.h"
|
||||
|
||||
#include "../XmppInfoPlugin.h"
|
||||
@@ -90,8 +87,9 @@ public slots:
|
||||
virtual void checkSettings();
|
||||
virtual void configurationChanged();
|
||||
virtual void sendMsg( const QString& to, const QString& msg );
|
||||
void broadcastMsg( const QString &msg );
|
||||
virtual void addContact( const QString& jid, const QString& msg = QString() );
|
||||
|
||||
void broadcastMsg( const QString& msg );
|
||||
void showAddFriendDialog();
|
||||
void publishTune( const QUrl& url, const Tomahawk::InfoSystem::InfoStringHash& trackInfo );
|
||||
|
||||
@@ -142,11 +140,13 @@ private:
|
||||
Jreen::MUCRoom* m_room;
|
||||
Jreen::SimpleRoster* m_roster;
|
||||
QHash< Jreen::JID, Jreen::Presence::Type > m_peers;
|
||||
|
||||
#ifndef ENABLE_HEADLESS
|
||||
QHash< Jreen::JID, QMessageBox* > m_subscriptionConfirmBoxes;
|
||||
QMenu* m_menu;
|
||||
XmlConsole* m_xmlConsole;
|
||||
#endif
|
||||
|
||||
enum IqContext { NoContext, RequestDisco, RequestedDisco, SipMessageSent, RequestedVCard, RequestVersion, RequestedVersion };
|
||||
AvatarManager* m_avatarManager;
|
||||
Jreen::PubSub::Manager* m_pubSubManager;
|
||||
|
Reference in New Issue
Block a user