mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 22:26:32 +02:00
Use SipInfo class
This commit is contained in:
@@ -59,10 +59,10 @@ public slots:
|
|||||||
void disconnectPlugin();
|
void disconnectPlugin();
|
||||||
void configurationChanged();
|
void configurationChanged();
|
||||||
|
|
||||||
void sendMsg( const QString& to, const QString& msg )
|
void sendMsg( const QString& peerId, const SipInfo& info )
|
||||||
{
|
{
|
||||||
Q_UNUSED( to );
|
Q_UNUSED( peerId );
|
||||||
Q_UNUSED( msg );
|
Q_UNUSED( info );
|
||||||
}
|
}
|
||||||
|
|
||||||
void broadcastMsg( const QString &msg )
|
void broadcastMsg( const QString &msg )
|
||||||
@@ -70,9 +70,9 @@ public slots:
|
|||||||
Q_UNUSED( msg );
|
Q_UNUSED( msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
void addContact( const QString &jid, const QString& msg = QString() )
|
void addContact( const QString &peerId, const QString& msg = QString() )
|
||||||
{
|
{
|
||||||
Q_UNUSED( jid );
|
Q_UNUSED( peerId );
|
||||||
Q_UNUSED( msg );
|
Q_UNUSED( msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -110,7 +110,7 @@ XmppSipPlugin::XmppSipPlugin( Account* account )
|
|||||||
Jreen::JID jid = Jreen::JID( readUsername() );
|
Jreen::JID jid = Jreen::JID( readUsername() );
|
||||||
|
|
||||||
// general client setup
|
// general client setup
|
||||||
m_client = new Jreen::Client( jid, m_currentPassword );
|
m_client = new Jreen::Client( jid, m_currentPassword );
|
||||||
setupClientHelper();
|
setupClientHelper();
|
||||||
|
|
||||||
m_client->registerPayload( new TomahawkXmppMessageFactory );
|
m_client->registerPayload( new TomahawkXmppMessageFactory );
|
||||||
@@ -425,32 +425,17 @@ XmppSipPlugin::errorMessage( Jreen::Client::DisconnectReason reason )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
XmppSipPlugin::sendMsg( const QString& to, const QString& msg )
|
XmppSipPlugin::sendMsg( const QString& to, const SipInfo& info )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << to << msg;
|
qDebug() << Q_FUNC_INFO << to << info;
|
||||||
|
|
||||||
if ( !m_client )
|
if ( !m_client )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/*******************************************************
|
|
||||||
* Obsolete this by a SipMessage class
|
|
||||||
*/
|
|
||||||
QJson::Parser parser;
|
|
||||||
bool ok;
|
|
||||||
QVariant v = parser.parse( msg.toAscii(), &ok );
|
|
||||||
if ( !ok || v.type() != QVariant::Map )
|
|
||||||
{
|
|
||||||
qDebug() << "Invalid JSON in Xmpp msg";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariantMap m = v.toMap();
|
|
||||||
/*******************************************************/
|
|
||||||
|
|
||||||
TomahawkXmppMessage *sipMessage;
|
TomahawkXmppMessage *sipMessage;
|
||||||
if ( m["visible"].toBool() )
|
if ( info.isVisible() )
|
||||||
{
|
{
|
||||||
sipMessage = new TomahawkXmppMessage( m["ip"].toString(), m["port"].toInt(), m["uniqname"].toString(), m["key"].toString() );
|
sipMessage = new TomahawkXmppMessage( info.host().hostName(), info.port(), info.uniqname(), info.key() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
sipMessage = new TomahawkXmppMessage();
|
sipMessage = new TomahawkXmppMessage();
|
||||||
@@ -467,13 +452,6 @@ XmppSipPlugin::sendMsg( const QString& to, const QString& msg )
|
|||||||
void
|
void
|
||||||
XmppSipPlugin::broadcastMsg( const QString& msg )
|
XmppSipPlugin::broadcastMsg( const QString& msg )
|
||||||
{
|
{
|
||||||
if ( !m_client )
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach ( const Jreen::JID& jid, m_peers.keys() )
|
|
||||||
{
|
|
||||||
sendMsg( jid.full(), msg );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -86,8 +86,8 @@ public slots:
|
|||||||
virtual void disconnectPlugin();
|
virtual void disconnectPlugin();
|
||||||
virtual void checkSettings();
|
virtual void checkSettings();
|
||||||
virtual void configurationChanged();
|
virtual void configurationChanged();
|
||||||
virtual void sendMsg( const QString& to, const QString& msg );
|
virtual void sendMsg( const QString& peerId, const SipInfo& info );
|
||||||
virtual void addContact( const QString& jid, const QString& msg = QString() );
|
virtual void addContact( const QString& peerId, const QString& msg = QString() );
|
||||||
|
|
||||||
void broadcastMsg( const QString& msg );
|
void broadcastMsg( const QString& msg );
|
||||||
void showAddFriendDialog();
|
void showAddFriendDialog();
|
||||||
|
@@ -64,7 +64,7 @@ public slots:
|
|||||||
|
|
||||||
void advertise();
|
void advertise();
|
||||||
|
|
||||||
void sendMsg( const QString& , const QString& ) {}
|
void sendMsg( const QString& peerId , const SipInfo& ) {}
|
||||||
void broadcastMsg( const QString & ) {}
|
void broadcastMsg( const QString & ) {}
|
||||||
void addContact( const QString &, const QString& ) {}
|
void addContact( const QString &, const QString& ) {}
|
||||||
|
|
||||||
|
@@ -118,50 +118,47 @@ SipHandler::hookUpPlugin( SipPlugin* sip )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SipHandler::onPeerOnline( const QString& jid )
|
SipHandler::onPeerOnline( const QString& peerId )
|
||||||
{
|
{
|
||||||
// qDebug() << Q_FUNC_INFO;
|
// qDebug() << Q_FUNC_INFO;
|
||||||
tDebug() << "SIP online:" << jid;
|
tDebug() << "SIP online:" << peerId;
|
||||||
|
|
||||||
SipPlugin* sip = qobject_cast<SipPlugin*>(sender());
|
SipPlugin* sip = qobject_cast<SipPlugin*>(sender());
|
||||||
|
|
||||||
QVariantMap m;
|
SipInfo info;
|
||||||
if( Servent::instance()->visibleExternally() )
|
if( Servent::instance()->visibleExternally() )
|
||||||
{
|
{
|
||||||
QString key = uuid();
|
QString key = uuid();
|
||||||
ControlConnection* conn = new ControlConnection( Servent::instance(), QString() );
|
ControlConnection* conn = new ControlConnection( Servent::instance(), QString() );
|
||||||
|
|
||||||
const QString& nodeid = Database::instance()->impl()->dbid();
|
const QString& nodeid = Database::instance()->impl()->dbid();
|
||||||
conn->setName( jid.left( jid.indexOf( "/" ) ) );
|
conn->setName( peerId.left( peerId.indexOf( "/" ) ) );
|
||||||
conn->setId( nodeid );
|
conn->setId( nodeid );
|
||||||
|
|
||||||
Servent::instance()->registerOffer( key, conn );
|
Servent::instance()->registerOffer( key, conn );
|
||||||
m["visible"] = true;
|
info.setVisible( true );
|
||||||
m["ip"] = Servent::instance()->externalAddress();
|
info.setHost( QHostInfo::fromName( Servent::instance()->externalAddress() ) );
|
||||||
m["port"] = Servent::instance()->externalPort();
|
info.setPort( Servent::instance()->externalPort() );
|
||||||
m["key"] = key;
|
info.setKey( key );
|
||||||
m["uniqname"] = nodeid;
|
info.setUniqname( nodeid );
|
||||||
|
|
||||||
qDebug() << "Asking them to connect to us:" << m;
|
tDebug() << "Asking them to connect to us:" << info;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m["visible"] = false;
|
info.setVisible( false );
|
||||||
qDebug() << "We are not visible externally:" << m;
|
tDebug() << "We are not visible externally:" << info;
|
||||||
}
|
}
|
||||||
|
|
||||||
QJson::Serializer ser;
|
sip->sendMsg( peerId, info );
|
||||||
QByteArray ba = ser.serialize( m );
|
|
||||||
|
|
||||||
sip->sendMsg( jid, QString::fromAscii( ba ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SipHandler::onPeerOffline( const QString& jid )
|
SipHandler::onPeerOffline( const QString& peerId )
|
||||||
{
|
{
|
||||||
// qDebug() << Q_FUNC_INFO;
|
// qDebug() << Q_FUNC_INFO;
|
||||||
qDebug() << "SIP offline:" << jid;
|
tDebug() << "SIP offline:" << peerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -174,7 +171,7 @@ SipHandler::onSipInfo( const QString& peerId, const SipInfo& info )
|
|||||||
|
|
||||||
//FIXME: We should probably be using barePeerId in the connectToPeer call below.
|
//FIXME: We should probably be using barePeerId in the connectToPeer call below.
|
||||||
//But, verify this doesn't cause any problems (there is still a uniquename after all)
|
//But, verify this doesn't cause any problems (there is still a uniquename after all)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
If only one party is externally visible, connection is obvious
|
If only one party is externally visible, connection is obvious
|
||||||
If both are, peer with lowest IP address initiates the connection.
|
If both are, peer with lowest IP address initiates the connection.
|
||||||
|
@@ -67,7 +67,7 @@ public slots:
|
|||||||
virtual void configurationChanged() = 0;
|
virtual void configurationChanged() = 0;
|
||||||
|
|
||||||
virtual void addContact( const QString &jid, const QString& msg = QString() ) = 0;
|
virtual void addContact( const QString &jid, const QString& msg = QString() ) = 0;
|
||||||
virtual void sendMsg( const QString& to, const QString& msg ) = 0;
|
virtual void sendMsg( const QString& to, const SipInfo& info ) = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void peerOnline( const QString& );
|
void peerOnline( const QString& );
|
||||||
|
Reference in New Issue
Block a user