1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-21 08:19:42 +01:00

Use QHostInfo instead of QHostAddress

This commit is contained in:
Dominik Schmidt 2011-05-09 02:59:46 +02:00
parent 9c30600793
commit 2e69f91671
5 changed files with 29 additions and 24 deletions

View File

@ -127,7 +127,7 @@ void DiagnosticsDialog::updateLogView()
log.append(
QString(" %1: %2:%3 (%4)\n")
.arg( peerId )
.arg( sipInfo.host().toString() )
.arg( sipInfo.host().hostName() )
.arg( sipInfo.port() )
.arg( connected ? "connected" : "not connected")
);

View File

@ -497,10 +497,10 @@ SipHandler::onSipInfo( const QString& peerId, const SipInfo& info )
if ( info.isVisible() )
{
if( !Servent::instance()->visibleExternally() ||
Servent::instance()->externalAddress() <= info.host().toString() )
Servent::instance()->externalAddress() <= info.host().hostName() )
{
qDebug() << "Initiate connection to" << peerId;
Servent::instance()->connectToPeer( info.host().toString(),
Servent::instance()->connectToPeer( info.host().hostName(),
info.port(),
info.key(),
peerId,

View File

@ -41,7 +41,7 @@ public:
~SipInfoPrivate() { }
QVariant visible;
QHostAddress host;
QHostInfo host;
int port;
QString uniqname;
QString key;
@ -73,7 +73,7 @@ void
SipInfo::clear()
{
d->visible.clear();
d->host = QHostAddress();
d->host = QHostInfo();
d->port = -1;
d->uniqname = QString();
d->key = QString();
@ -82,12 +82,13 @@ SipInfo::clear()
bool
SipInfo::isValid() const
{
qDebug() << Q_FUNC_INFO << d->visible << d->host.hostName() << d->port << d->uniqname << d->key;
if( !d->visible.isNull() )
if(
// 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
|| ( !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;
else
@ -110,12 +111,12 @@ SipInfo::isVisible() const
}
void
SipInfo::setHost( const QHostAddress& host )
SipInfo::setHost( const QHostInfo& host )
{
d->host = host;
}
const QHostAddress
const QHostInfo
SipInfo::host() const
{
Q_ASSERT( isValid() );
@ -168,14 +169,12 @@ SipInfo::key() const
const QString
SipInfo::toJson() const
{
Q_ASSERT( isValid() );
// build variant map
QVariantMap m;
m["visible"] = isVisible();
if( isVisible() )
{
m["ip"] = host().toString();
m["ip"] = host().hostName();
m["port"] = port();
m["key"] = key();
m["uniqname"] = uniqname();
@ -198,7 +197,7 @@ SipInfo::fromJson( QString json )
QVariant v = parser.parse( json.toAscii(), &ok );
if ( !ok || v.type() != QVariant::Map )
{
qDebug() << Q_FUNC_INFO << "Invalid JSON";
qDebug() << Q_FUNC_INFO << "Invalid JSON: " << json;
return info;
}
QVariantMap m = v.toMap();
@ -206,7 +205,9 @@ SipInfo::fromJson( QString json )
info.setVisible( 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.setUniqname( m["uniqname"].toString() );
info.setKey( m["key"].toString() );

View File

@ -21,7 +21,7 @@
#include <QDebug>
#include <QSharedPointer>
#include <QHostAddress>
#include <QHostInfo>
class SipInfoPrivate;
@ -30,12 +30,10 @@ class SipInfo : public QObject
Q_OBJECT
public:
// create invalid message
// becomes valid if either visible == false or visible == true and all attributes are set
SipInfo();
SipInfo(const SipInfo &other);
SipInfo(const SipInfo& other);
virtual ~SipInfo();
SipInfo& operator=(const SipInfo &info);
SipInfo& operator=(const SipInfo& info);
void clear();
bool isValid() const;
@ -43,16 +41,16 @@ public:
void setVisible( bool visible );
bool isVisible() const;
void setHost( const QHostAddress &host );
const QHostAddress host() const;
void setHost( const QHostInfo& host );
const QHostInfo host() const;
void setPort( int port );
int port() const;
void setUniqname( const QString &uniqname );
void setUniqname( const QString& uniqname );
const QString uniqname() const;
void setKey( const QString &key );
void setKey( const QString& key );
const QString key() const;

View File

@ -556,6 +556,9 @@ void JabberPlugin::onNewMessage(const Jreen::Message& message)
QString from = message.from().full();
QString msg = message.body();
if(msg.isEmpty())
return;
SipInfo info = SipInfo::fromJson( msg );
if ( !info.isValid() )
@ -777,7 +780,10 @@ void JabberPlugin::onNewIq(const Jreen::IQ& iq, int context)
info.setVisible( sipMessage->visible() );
if( sipMessage->visible() )
{
info.setHost( QHostAddress( sipMessage->ip() ) );
QHostInfo hi;
hi.setHostName( sipMessage->ip() );
info.setHost( hi );
info.setPort( sipMessage->port() );
info.setUniqname( sipMessage->uniqname() );
info.setKey( sipMessage->key() );