mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 03:40:16 +02:00
Use QHostInfo instead of QHostAddress
This commit is contained in:
@@ -127,7 +127,7 @@ void DiagnosticsDialog::updateLogView()
|
|||||||
log.append(
|
log.append(
|
||||||
QString(" %1: %2:%3 (%4)\n")
|
QString(" %1: %2:%3 (%4)\n")
|
||||||
.arg( peerId )
|
.arg( peerId )
|
||||||
.arg( sipInfo.host().toString() )
|
.arg( sipInfo.host().hostName() )
|
||||||
.arg( sipInfo.port() )
|
.arg( sipInfo.port() )
|
||||||
.arg( connected ? "connected" : "not connected")
|
.arg( connected ? "connected" : "not connected")
|
||||||
);
|
);
|
||||||
|
@@ -497,10 +497,10 @@ SipHandler::onSipInfo( const QString& peerId, const SipInfo& info )
|
|||||||
if ( info.isVisible() )
|
if ( info.isVisible() )
|
||||||
{
|
{
|
||||||
if( !Servent::instance()->visibleExternally() ||
|
if( !Servent::instance()->visibleExternally() ||
|
||||||
Servent::instance()->externalAddress() <= info.host().toString() )
|
Servent::instance()->externalAddress() <= info.host().hostName() )
|
||||||
{
|
{
|
||||||
qDebug() << "Initiate connection to" << peerId;
|
qDebug() << "Initiate connection to" << peerId;
|
||||||
Servent::instance()->connectToPeer( info.host().toString(),
|
Servent::instance()->connectToPeer( info.host().hostName(),
|
||||||
info.port(),
|
info.port(),
|
||||||
info.key(),
|
info.key(),
|
||||||
peerId,
|
peerId,
|
||||||
|
@@ -41,7 +41,7 @@ public:
|
|||||||
~SipInfoPrivate() { }
|
~SipInfoPrivate() { }
|
||||||
|
|
||||||
QVariant visible;
|
QVariant visible;
|
||||||
QHostAddress host;
|
QHostInfo host;
|
||||||
int port;
|
int port;
|
||||||
QString uniqname;
|
QString uniqname;
|
||||||
QString key;
|
QString key;
|
||||||
@@ -73,7 +73,7 @@ void
|
|||||||
SipInfo::clear()
|
SipInfo::clear()
|
||||||
{
|
{
|
||||||
d->visible.clear();
|
d->visible.clear();
|
||||||
d->host = QHostAddress();
|
d->host = QHostInfo();
|
||||||
d->port = -1;
|
d->port = -1;
|
||||||
d->uniqname = QString();
|
d->uniqname = QString();
|
||||||
d->key = QString();
|
d->key = QString();
|
||||||
@@ -82,12 +82,13 @@ SipInfo::clear()
|
|||||||
bool
|
bool
|
||||||
SipInfo::isValid() const
|
SipInfo::isValid() const
|
||||||
{
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << d->visible << d->host.hostName() << d->port << d->uniqname << d->key;
|
||||||
if( !d->visible.isNull() )
|
if( !d->visible.isNull() )
|
||||||
if(
|
if(
|
||||||
// visible and all data available
|
// visible and all data available
|
||||||
( d->visible.toBool() && !d->host.isNull() && ( d->port > 0 ) && !d->uniqname.isNull() && !d->key.isNull() )
|
( d->visible.toBool() && !d->host.hostName().isNull() && ( d->port > 0 ) && !d->uniqname.isNull() && !d->key.isNull() )
|
||||||
// invisible and no data available
|
// invisible and no data available
|
||||||
|| ( !d->visible.toBool() && d->host.isNull() && ( d->port < 0 ) && d->uniqname.isNull() && d->key.isNull() )
|
|| ( !d->visible.toBool() && d->host.hostName().isNull() && ( d->port < 0 ) && d->uniqname.isNull() && d->key.isNull() )
|
||||||
)
|
)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
@@ -110,12 +111,12 @@ SipInfo::isVisible() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SipInfo::setHost( const QHostAddress& host )
|
SipInfo::setHost( const QHostInfo& host )
|
||||||
{
|
{
|
||||||
d->host = host;
|
d->host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QHostAddress
|
const QHostInfo
|
||||||
SipInfo::host() const
|
SipInfo::host() const
|
||||||
{
|
{
|
||||||
Q_ASSERT( isValid() );
|
Q_ASSERT( isValid() );
|
||||||
@@ -168,14 +169,12 @@ SipInfo::key() const
|
|||||||
const QString
|
const QString
|
||||||
SipInfo::toJson() const
|
SipInfo::toJson() const
|
||||||
{
|
{
|
||||||
Q_ASSERT( isValid() );
|
|
||||||
|
|
||||||
// build variant map
|
// build variant map
|
||||||
QVariantMap m;
|
QVariantMap m;
|
||||||
m["visible"] = isVisible();
|
m["visible"] = isVisible();
|
||||||
if( isVisible() )
|
if( isVisible() )
|
||||||
{
|
{
|
||||||
m["ip"] = host().toString();
|
m["ip"] = host().hostName();
|
||||||
m["port"] = port();
|
m["port"] = port();
|
||||||
m["key"] = key();
|
m["key"] = key();
|
||||||
m["uniqname"] = uniqname();
|
m["uniqname"] = uniqname();
|
||||||
@@ -198,7 +197,7 @@ SipInfo::fromJson( QString json )
|
|||||||
QVariant v = parser.parse( json.toAscii(), &ok );
|
QVariant v = parser.parse( json.toAscii(), &ok );
|
||||||
if ( !ok || v.type() != QVariant::Map )
|
if ( !ok || v.type() != QVariant::Map )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "Invalid JSON";
|
qDebug() << Q_FUNC_INFO << "Invalid JSON: " << json;
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
QVariantMap m = v.toMap();
|
QVariantMap m = v.toMap();
|
||||||
@@ -206,7 +205,9 @@ SipInfo::fromJson( QString json )
|
|||||||
info.setVisible( m["visible"].toBool() );
|
info.setVisible( m["visible"].toBool() );
|
||||||
if( m["visible"].toBool() )
|
if( m["visible"].toBool() )
|
||||||
{
|
{
|
||||||
info.setHost( QHostAddress( m["host"].toString() ) );
|
QHostInfo hostInfo;
|
||||||
|
hostInfo.setHostName( m["host"].toString() );
|
||||||
|
info.setHost( hostInfo );
|
||||||
info.setPort( m["port"].toInt() );
|
info.setPort( m["port"].toInt() );
|
||||||
info.setUniqname( m["uniqname"].toString() );
|
info.setUniqname( m["uniqname"].toString() );
|
||||||
info.setKey( m["key"].toString() );
|
info.setKey( m["key"].toString() );
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QHostAddress>
|
#include <QHostInfo>
|
||||||
|
|
||||||
class SipInfoPrivate;
|
class SipInfoPrivate;
|
||||||
|
|
||||||
@@ -30,12 +30,10 @@ class SipInfo : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// create invalid message
|
|
||||||
// becomes valid if either visible == false or visible == true and all attributes are set
|
|
||||||
SipInfo();
|
SipInfo();
|
||||||
SipInfo(const SipInfo &other);
|
SipInfo(const SipInfo& other);
|
||||||
virtual ~SipInfo();
|
virtual ~SipInfo();
|
||||||
SipInfo& operator=(const SipInfo &info);
|
SipInfo& operator=(const SipInfo& info);
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
@@ -43,16 +41,16 @@ public:
|
|||||||
void setVisible( bool visible );
|
void setVisible( bool visible );
|
||||||
bool isVisible() const;
|
bool isVisible() const;
|
||||||
|
|
||||||
void setHost( const QHostAddress &host );
|
void setHost( const QHostInfo& host );
|
||||||
const QHostAddress host() const;
|
const QHostInfo host() const;
|
||||||
|
|
||||||
void setPort( int port );
|
void setPort( int port );
|
||||||
int port() const;
|
int port() const;
|
||||||
|
|
||||||
void setUniqname( const QString &uniqname );
|
void setUniqname( const QString& uniqname );
|
||||||
const QString uniqname() const;
|
const QString uniqname() const;
|
||||||
|
|
||||||
void setKey( const QString &key );
|
void setKey( const QString& key );
|
||||||
const QString key() const;
|
const QString key() const;
|
||||||
|
|
||||||
|
|
||||||
|
@@ -556,6 +556,9 @@ void JabberPlugin::onNewMessage(const Jreen::Message& message)
|
|||||||
QString from = message.from().full();
|
QString from = message.from().full();
|
||||||
QString msg = message.body();
|
QString msg = message.body();
|
||||||
|
|
||||||
|
if(msg.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
SipInfo info = SipInfo::fromJson( msg );
|
SipInfo info = SipInfo::fromJson( msg );
|
||||||
|
|
||||||
if ( !info.isValid() )
|
if ( !info.isValid() )
|
||||||
@@ -777,7 +780,10 @@ void JabberPlugin::onNewIq(const Jreen::IQ& iq, int context)
|
|||||||
info.setVisible( sipMessage->visible() );
|
info.setVisible( sipMessage->visible() );
|
||||||
if( sipMessage->visible() )
|
if( sipMessage->visible() )
|
||||||
{
|
{
|
||||||
info.setHost( QHostAddress( sipMessage->ip() ) );
|
|
||||||
|
QHostInfo hi;
|
||||||
|
hi.setHostName( sipMessage->ip() );
|
||||||
|
info.setHost( hi );
|
||||||
info.setPort( sipMessage->port() );
|
info.setPort( sipMessage->port() );
|
||||||
info.setUniqname( sipMessage->uniqname() );
|
info.setUniqname( sipMessage->uniqname() );
|
||||||
info.setKey( sipMessage->key() );
|
info.setKey( sipMessage->key() );
|
||||||
|
Reference in New Issue
Block a user