mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-14 10:05:32 +02:00
Add an option to automatically detect the external IP(v4)
This commit is contained in:
@@ -782,6 +782,20 @@ TomahawkSettings::setSongChangeNotificationEnabled(bool enable)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
TomahawkSettings::autoDetectExternalIp() const
|
||||||
|
{
|
||||||
|
return value( "network/auto-detect-external-ip" ).toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TomahawkSettings::setAutoDetectExternalIp( bool autoDetect )
|
||||||
|
{
|
||||||
|
setValue( "network/auto-detect-external-ip", autoDetect );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
TomahawkSettings::volume() const
|
TomahawkSettings::volume() const
|
||||||
{
|
{
|
||||||
|
@@ -147,6 +147,9 @@ public:
|
|||||||
bool songChangeNotificationEnabled() const; /// true by default
|
bool songChangeNotificationEnabled() const; /// true by default
|
||||||
void setSongChangeNotificationEnabled( bool enable );
|
void setSongChangeNotificationEnabled( bool enable );
|
||||||
|
|
||||||
|
bool autoDetectExternalIp() const;
|
||||||
|
void setAutoDetectExternalIp( bool autoDetect );
|
||||||
|
|
||||||
QString externalHostname() const;
|
QString externalHostname() const;
|
||||||
void setExternalHostname( const QString& externalHostname );
|
void setExternalHostname( const QString& externalHostname );
|
||||||
|
|
||||||
|
@@ -127,6 +127,8 @@ Servent::~Servent()
|
|||||||
bool
|
bool
|
||||||
Servent::startListening( QHostAddress ha, bool upnp, int port )
|
Servent::startListening( QHostAddress ha, bool upnp, int port )
|
||||||
{
|
{
|
||||||
|
Q_D( Servent );
|
||||||
|
|
||||||
d_func()->externalAddresses = QList<QHostAddress>();
|
d_func()->externalAddresses = QList<QHostAddress>();
|
||||||
d_func()->port = port;
|
d_func()->port = port;
|
||||||
int defPort = TomahawkSettings::instance()->defaultPort();
|
int defPort = TomahawkSettings::instance()->defaultPort();
|
||||||
@@ -181,11 +183,20 @@ Servent::startListening( QHostAddress ha, bool upnp, int port )
|
|||||||
switch ( mode )
|
switch ( mode )
|
||||||
{
|
{
|
||||||
case TomahawkSettings::Static:
|
case TomahawkSettings::Static:
|
||||||
d_func()->externalHostname = TomahawkSettings::instance()->externalHostname();
|
d->externalPort = TomahawkSettings::instance()->externalPort();
|
||||||
d_func()->externalPort = TomahawkSettings::instance()->externalPort();
|
if ( TomahawkSettings::instance()->autoDetectExternalIp() )
|
||||||
d_func()->ready = true;
|
{
|
||||||
// All setup is made, were done.
|
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( QUrl( "http://toma.hk/?stat=1" ) ) );
|
||||||
emit ready();
|
connect( reply, SIGNAL( finished() ), SLOT( ipDetected() ) );
|
||||||
|
// Not emitting ready here as we are not done.
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
d->externalHostname = TomahawkSettings::instance()->externalHostname();
|
||||||
|
d->ready = true;
|
||||||
|
// All setup is made, were done.
|
||||||
|
emit ready();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TomahawkSettings::Lan:
|
case TomahawkSettings::Lan:
|
||||||
@@ -950,6 +961,39 @@ Servent::checkACLResult( const QString& nodeid, const QString& username, Tomahaw
|
|||||||
d_func()->queuedForACLResult[username].remove( nodeid );
|
d_func()->queuedForACLResult[username].remove( nodeid );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Servent::ipDetected()
|
||||||
|
{
|
||||||
|
Q_D( Servent );
|
||||||
|
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
|
||||||
|
|
||||||
|
if ( reply->error() == QNetworkReply::NoError )
|
||||||
|
{
|
||||||
|
QJson::Parser p;
|
||||||
|
bool ok;
|
||||||
|
const QVariantMap res = p.parse( reply, &ok ).toMap();
|
||||||
|
if ( !ok )
|
||||||
|
{
|
||||||
|
tLog() << Q_FUNC_INFO << "Failed parsing ip-autodetection response";
|
||||||
|
d->externalPort = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QString externalIP = res.value( "ip" ).toString();
|
||||||
|
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Found external IP:" << externalIP;
|
||||||
|
d->externalHostname = externalIP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
d->externalPort = -1;
|
||||||
|
tLog() << Q_FUNC_INFO << "ip-autodetection returned an error:" << reply->errorString();
|
||||||
|
}
|
||||||
|
|
||||||
|
d->ready = true;
|
||||||
|
emit ready();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Servent::reverseOfferRequest( ControlConnection* orig_conn, const QString& theirdbid, const QString& key, const QString& theirkey )
|
Servent::reverseOfferRequest( ControlConnection* orig_conn, const QString& theirdbid, const QString& key, const QString& theirkey )
|
||||||
|
@@ -162,6 +162,7 @@ private slots:
|
|||||||
void readyRead();
|
void readyRead();
|
||||||
void socketError( QAbstractSocket::SocketError e );
|
void socketError( QAbstractSocket::SocketError e );
|
||||||
void checkACLResult( const QString &nodeid, const QString &username, Tomahawk::ACLStatus::Type peerStatus );
|
void checkACLResult( const QString &nodeid, const QString &username, Tomahawk::ACLStatus::Type peerStatus );
|
||||||
|
void ipDetected();
|
||||||
|
|
||||||
Connection* claimOffer( ControlConnection* cc, const QString &nodeid, const QString &key, const QHostAddress peer = QHostAddress::Any );
|
Connection* claimOffer( ControlConnection* cc, const QString &nodeid, const QString &key, const QHostAddress peer = QHostAddress::Any );
|
||||||
|
|
||||||
|
@@ -108,7 +108,7 @@ SettingsDialog::SettingsDialog(QObject *parent )
|
|||||||
m_advancedWidgetUi->upnpRadioButton->setChecked( true );
|
m_advancedWidgetUi->upnpRadioButton->setChecked( true );
|
||||||
|
|
||||||
m_advancedWidgetUi->staticHostNamePortLabel->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
|
m_advancedWidgetUi->staticHostNamePortLabel->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
|
||||||
m_advancedWidgetUi->staticHostName->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
|
m_advancedWidgetUi->staticHostName->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() && !s->autoDetectExternalIp() );
|
||||||
m_advancedWidgetUi->staticPort->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
|
m_advancedWidgetUi->staticPort->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
|
||||||
m_advancedWidgetUi->staticHostNameLabel->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
|
m_advancedWidgetUi->staticHostNameLabel->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
|
||||||
m_advancedWidgetUi->staticPortLabel->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
|
m_advancedWidgetUi->staticPortLabel->setEnabled( m_advancedWidgetUi->staticIpRadioButton->isChecked() );
|
||||||
@@ -173,6 +173,7 @@ SettingsDialog::SettingsDialog(QObject *parent )
|
|||||||
m_advancedWidgetUi->staticHostName->setText( s->externalHostname() );
|
m_advancedWidgetUi->staticHostName->setText( s->externalHostname() );
|
||||||
m_advancedWidgetUi->staticPort->setValue( s->externalPort() );
|
m_advancedWidgetUi->staticPort->setValue( s->externalPort() );
|
||||||
m_advancedWidgetUi->proxyButton->setVisible( true );
|
m_advancedWidgetUi->proxyButton->setVisible( true );
|
||||||
|
m_advancedWidgetUi->autoDetectIpCheckBox->setChecked( s->autoDetectExternalIp() );
|
||||||
|
|
||||||
m_collectionWidgetUi->checkBoxWatchForChanges->setChecked( s->watchForChanges() );
|
m_collectionWidgetUi->checkBoxWatchForChanges->setChecked( s->watchForChanges() );
|
||||||
m_collectionWidgetUi->scannerTimeSpinBox->setValue( s->scannerTime() );
|
m_collectionWidgetUi->scannerTimeSpinBox->setValue( s->scannerTime() );
|
||||||
@@ -248,6 +249,7 @@ SettingsDialog::SettingsDialog(QObject *parent )
|
|||||||
connect( m_advancedWidgetUi->lanOnlyRadioButton, SIGNAL( toggled(bool) ), SLOT( toggleRemoteMode() ) );
|
connect( m_advancedWidgetUi->lanOnlyRadioButton, SIGNAL( toggled(bool) ), SLOT( toggleRemoteMode() ) );
|
||||||
connect( m_advancedWidgetUi->staticIpRadioButton, SIGNAL( toggled(bool) ), SLOT( toggleRemoteMode() ) );
|
connect( m_advancedWidgetUi->staticIpRadioButton, SIGNAL( toggled(bool) ), SLOT( toggleRemoteMode() ) );
|
||||||
connect( m_advancedWidgetUi->upnpRadioButton, SIGNAL( toggled(bool) ), SLOT( toggleRemoteMode() ) );
|
connect( m_advancedWidgetUi->upnpRadioButton, SIGNAL( toggled(bool) ), SLOT( toggleRemoteMode() ) );
|
||||||
|
connect( m_advancedWidgetUi->autoDetectIpCheckBox, SIGNAL( toggled( bool ) ), SLOT( toggleAutoDetectIp( bool ) ) );
|
||||||
connect( m_advancedWidgetUi->enableProxyCheckBox, SIGNAL( toggled(bool) ), SLOT( toggleProxyEnabled() ) );
|
connect( m_advancedWidgetUi->enableProxyCheckBox, SIGNAL( toggled(bool) ), SLOT( toggleProxyEnabled() ) );
|
||||||
connect( m_advancedWidgetUi->enableProxyCheckBox, SIGNAL( toggled(bool) ), SLOT( requiresRestart() ) );
|
connect( m_advancedWidgetUi->enableProxyCheckBox, SIGNAL( toggled(bool) ), SLOT( requiresRestart() ) );
|
||||||
|
|
||||||
@@ -268,6 +270,7 @@ SettingsDialog::saveSettings()
|
|||||||
s->setSongChangeNotificationEnabled( m_advancedWidgetUi->checkBoxSongChangeNotifications->checkState() == Qt::Checked );
|
s->setSongChangeNotificationEnabled( m_advancedWidgetUi->checkBoxSongChangeNotifications->checkState() == Qt::Checked );
|
||||||
s->setProxyType( m_advancedWidgetUi->enableProxyCheckBox->isChecked() ? QNetworkProxy::Socks5Proxy : QNetworkProxy::NoProxy );
|
s->setProxyType( m_advancedWidgetUi->enableProxyCheckBox->isChecked() ? QNetworkProxy::Socks5Proxy : QNetworkProxy::NoProxy );
|
||||||
s->setExternalAddressMode( m_advancedWidgetUi->upnpRadioButton->isChecked() ? TomahawkSettings::Upnp : ( m_advancedWidgetUi->lanOnlyRadioButton->isChecked() ? TomahawkSettings::Lan : TomahawkSettings::Static ) );
|
s->setExternalAddressMode( m_advancedWidgetUi->upnpRadioButton->isChecked() ? TomahawkSettings::Upnp : ( m_advancedWidgetUi->lanOnlyRadioButton->isChecked() ? TomahawkSettings::Lan : TomahawkSettings::Static ) );
|
||||||
|
s->setAutoDetectExternalIp( m_advancedWidgetUi->autoDetectIpCheckBox->isChecked() );
|
||||||
|
|
||||||
s->setExternalHostname( m_advancedWidgetUi->staticHostName->text() );
|
s->setExternalHostname( m_advancedWidgetUi->staticHostName->text() );
|
||||||
s->setExternalPort( m_advancedWidgetUi->staticPort->value() );
|
s->setExternalPort( m_advancedWidgetUi->staticPort->value() );
|
||||||
@@ -385,6 +388,13 @@ SettingsDialog::toggleProxyEnabled()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SettingsDialog::toggleAutoDetectIp( bool checked )
|
||||||
|
{
|
||||||
|
m_advancedWidgetUi->staticHostName->setEnabled( !checked );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SettingsDialog::updateScanOptionsView()
|
SettingsDialog::updateScanOptionsView()
|
||||||
{
|
{
|
||||||
|
@@ -39,16 +39,16 @@ class QToolbarTabDialog;
|
|||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class ProxyDialog;
|
class ProxyDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
namespace Accounts
|
namespace Accounts
|
||||||
{
|
{
|
||||||
class AccountModel;
|
class AccountModel;
|
||||||
class Account;
|
class Account;
|
||||||
class AccountFactory;
|
class AccountFactory;
|
||||||
class Account;
|
class Account;
|
||||||
class AccountModelFilterProxy;
|
class AccountModelFilterProxy;
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ Q_OBJECT
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ProxyDialog( QWidget* parent = 0 );
|
explicit ProxyDialog( QWidget* parent = 0 );
|
||||||
~ProxyDialog() {};
|
~ProxyDialog() {}
|
||||||
|
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
|
|
||||||
@@ -85,6 +85,7 @@ private slots:
|
|||||||
|
|
||||||
void toggleRemoteMode();
|
void toggleRemoteMode();
|
||||||
void toggleProxyEnabled();
|
void toggleProxyEnabled();
|
||||||
|
void toggleAutoDetectIp( bool checked );
|
||||||
void showProxySettings();
|
void showProxySettings();
|
||||||
|
|
||||||
void accountsFilterChanged( int );
|
void accountsFilterChanged( int );
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>469</width>
|
<width>473</width>
|
||||||
<height>475</height>
|
<height>475</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@@ -109,6 +109,33 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeType">
|
||||||
|
<enum>QSizePolicy::Fixed</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="autoDetectIpCheckBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>Automatically detect external IP address</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Reference in New Issue
Block a user