1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-13 20:41:58 +02:00

Fix up the advanced settings dialog. Make it more clear whether

UPnP/Static/LAN-only is going to be used. Use a checkbox to enable proxy
since we'll likely never support anything other than socks -- at least,
not anytime soon. Group items in a nicer fashion.
This commit is contained in:
Jeff Mitchell 2012-05-03 13:36:23 -04:00
parent b1210ea43f
commit 3b332d6d12
8 changed files with 268 additions and 324 deletions

View File

@ -29,39 +29,6 @@
<number>4</number>
</property>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QComboBox" name="typeBox"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="hostLineEdit">
<property name="text">
<string/>
@ -71,21 +38,21 @@
</property>
</widget>
</item>
<item row="1" column="0">
<item row="0" column="0">
<widget class="QLabel" name="hostLabel">
<property name="text">
<string>Host</string>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="1" column="0">
<widget class="QLabel" name="portLabel">
<property name="text">
<string>Port</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="1" column="1">
<widget class="QSpinBox" name="portSpinBox">
<property name="minimum">
<number>1</number>
@ -98,28 +65,28 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="2" column="1">
<widget class="QLineEdit" name="userLineEdit">
<property name="placeholderText">
<string>Proxy login</string>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="2" column="0">
<widget class="QLabel" name="userLabel">
<property name="text">
<string>User</string>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="3" column="0">
<widget class="QLabel" name="passwordLabel">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="3" column="1">
<widget class="QLineEdit" name="passwordLineEdit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
@ -129,14 +96,7 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="typeLabel">
<property name="text">
<string>Type</string>
</property>
</widget>
</item>
<item row="5" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>No Proxy Hosts:
@ -144,21 +104,21 @@
</property>
</widget>
</item>
<item row="5" column="1">
<item row="4" column="1">
<widget class="QLineEdit" name="noHostLineEdit">
<property name="placeholderText">
<string>localhost *.example.com (space separated)</string>
</property>
</widget>
</item>
<item row="6" column="0">
<item row="5" column="0">
<widget class="QLabel" name="dnsLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="6" column="1">
<item row="5" column="1">
<widget class="QCheckBox" name="checkBoxUseProxyForDns">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>

View File

@ -64,6 +64,7 @@ SettingsDialog::SettingsDialog( QWidget *parent )
, ui( new Ui_StackedSettingsDialog )
, m_proxySettings( this )
, m_rejected( false )
, m_restartRequired( false )
, m_accountModel( 0 )
, m_sipSpinner( 0 )
{
@ -75,10 +76,28 @@ SettingsDialog::SettingsDialog( QWidget *parent )
ui->checkBoxReporter->setChecked( s->crashReporterEnabled() );
ui->checkBoxHttp->setChecked( s->httpEnabled() );
ui->checkBoxStaticPreferred->setChecked( s->preferStaticHostPort() );
ui->checkBoxUpnp->setChecked( s->externalAddressMode() == TomahawkSettings::Upnp );
ui->checkBoxUpnp->setEnabled( !s->preferStaticHostPort() );
//Network settings
TomahawkSettings::ExternalAddressMode mode = TomahawkSettings::instance()->externalAddressMode();
if ( mode == TomahawkSettings::Lan )
ui->lanOnlyRadioButton->setChecked( true );
else if ( mode == TomahawkSettings::Static )
ui->staticIpRadioButton->setChecked( true );
else
ui->upnpRadioButton->setChecked( true );
ui->staticHostNamePortLabel->setEnabled( ui->staticIpRadioButton->isChecked() );
ui->staticHostName->setEnabled( ui->staticIpRadioButton->isChecked() );
ui->staticPort->setEnabled( ui->staticIpRadioButton->isChecked() );
ui->staticHostNameLabel->setEnabled( ui->staticIpRadioButton->isChecked() );
ui->staticPortLabel->setEnabled( ui->staticIpRadioButton->isChecked() );
bool useProxy = TomahawkSettings::instance()->proxyType() == QNetworkProxy::Socks5Proxy;
ui->enableProxyCheckBox->setChecked( useProxy );
ui->proxyButton->setEnabled( useProxy );
createIcons();
#ifdef Q_WS_X11
ui->listWidget->setFrameShape( QFrame::StyledPanel );
@ -173,10 +192,13 @@ SettingsDialog::SettingsDialog( QWidget *parent )
// #endif
connect( ui->proxyButton, SIGNAL( clicked() ), SLOT( showProxySettings() ) );
connect( ui->checkBoxStaticPreferred, SIGNAL( toggled(bool) ), SLOT( toggleUpnp(bool) ) );
connect( ui->checkBoxStaticPreferred, SIGNAL( toggled(bool) ), SLOT( requiresRestart() ) );
connect( ui->checkBoxUpnp, SIGNAL( toggled(bool) ), SLOT( requiresRestart() ) );
connect( ui->checkBoxReporter, SIGNAL( toggled(bool) ), SLOT( requiresRestart() ) );
connect( ui->lanOnlyRadioButton, SIGNAL( toggled(bool) ), SLOT( requiresRestart() ) );
connect( ui->staticIpRadioButton, SIGNAL( toggled(bool) ), SLOT( requiresRestart() ) );
connect( ui->upnpRadioButton, SIGNAL( toggled(bool) ), SLOT( requiresRestart() ) );
connect( ui->lanOnlyRadioButton, SIGNAL( toggled(bool) ), SLOT( toggleRemoteMode() ) );
connect( ui->staticIpRadioButton, SIGNAL( toggled(bool) ), SLOT( toggleRemoteMode() ) );
connect( ui->upnpRadioButton, SIGNAL( toggled(bool) ), SLOT( toggleRemoteMode() ) );
connect( ui->enableProxyCheckBox, SIGNAL( toggled(bool) ), SLOT( toggleProxyEnabled() ) );
connect( this, SIGNAL( rejected() ), SLOT( onRejected() ) );
ui->listWidget->setCurrentRow( 0 );
@ -194,8 +216,8 @@ SettingsDialog::~SettingsDialog()
s->setCrashReporterEnabled( ui->checkBoxReporter->checkState() == Qt::Checked );
s->setHttpEnabled( ui->checkBoxHttp->checkState() == Qt::Checked );
s->setPreferStaticHostPort( ui->checkBoxStaticPreferred->checkState() == Qt::Checked );
s->setExternalAddressMode( ui->checkBoxUpnp->checkState() == Qt::Checked ? TomahawkSettings::Upnp : TomahawkSettings::Lan );
s->setProxyType( ui->enableProxyCheckBox->isChecked() ? QNetworkProxy::Socks5Proxy : QNetworkProxy::NoProxy );
s->setExternalAddressMode( ui->upnpRadioButton->isChecked() ? TomahawkSettings::Upnp : ( ui->lanOnlyRadioButton->isChecked() ? TomahawkSettings::Lan : TomahawkSettings::Static ) );
s->setExternalHostname( ui->staticHostName->text() );
s->setExternalPort( ui->staticPort->value() );
@ -209,10 +231,31 @@ SettingsDialog::~SettingsDialog()
s->applyChanges();
s->sync();
if ( m_restartRequired )
QMessageBox::information( this, tr( "Information" ), tr( "Some changed settings will not take effect until Tomahawk is restarted" ) );
TomahawkUtils::NetworkProxyFactory* proxyFactory = TomahawkUtils::proxyFactory();
if ( !ui->enableProxyCheckBox->isChecked() )
{
tDebug() << Q_FUNC_INFO << "Got NoProxy selected";
proxyFactory->setProxy( QNetworkProxy::NoProxy );
}
else
{
tDebug() << Q_FUNC_INFO << "Got Socks5Proxy selected";
proxyFactory->setProxy( QNetworkProxy( QNetworkProxy::Socks5Proxy, s->proxyHost(), s->proxyPort(), s->proxyUsername(), s->proxyPassword() ) );
if ( !s->proxyNoProxyHosts().isEmpty() )
{
tDebug() << Q_FUNC_INFO << "noproxy hosts:" << s->proxyNoProxyHosts();
tDebug() << Q_FUNC_INFO << "split noproxy line edit is " << s->proxyNoProxyHosts().split( ' ', QString::SkipEmptyParts );
proxyFactory->setNoProxyHosts( s->proxyNoProxyHosts().split( ' ', QString::SkipEmptyParts ) );
}
}
}
else
qDebug() << "Settings dialog cancelled, NOT saving prefs.";
delete ui;
}
@ -313,12 +356,20 @@ SettingsDialog::showProxySettings()
void
SettingsDialog::toggleUpnp( bool preferStaticEnabled )
SettingsDialog::toggleRemoteMode()
{
if ( preferStaticEnabled )
ui->checkBoxUpnp->setEnabled( false );
else
ui->checkBoxUpnp->setEnabled( true );
ui->staticHostNamePortLabel->setEnabled( ui->staticIpRadioButton->isChecked() );
ui->staticHostName->setEnabled( ui->staticIpRadioButton->isChecked() );
ui->staticPort->setEnabled( ui->staticIpRadioButton->isChecked() );
ui->staticHostNameLabel->setEnabled( ui->staticIpRadioButton->isChecked() );
ui->staticPortLabel->setEnabled( ui->staticIpRadioButton->isChecked() );
}
void
SettingsDialog::toggleProxyEnabled()
{
ui->proxyButton->setEnabled( ui->enableProxyCheckBox->isChecked() );
}
@ -422,7 +473,7 @@ SettingsDialog::scrollTo( const QModelIndex& idx )
void
SettingsDialog::requiresRestart()
{
QMessageBox::information( this, tr( "Information" ), tr( "Changing this setting requires a restart of Tomahawk!" ) );
m_restartRequired = true;
}
@ -434,58 +485,14 @@ ProxyDialog::ProxyDialog( QWidget *parent )
// ugly, I know, but...
int i = 0;
ui->typeBox->insertItem( i, "No Proxy", QNetworkProxy::NoProxy );
m_forwardMap[ QNetworkProxy::NoProxy ] = i;
m_backwardMap[ i ] = QNetworkProxy::NoProxy;
i++;
ui->typeBox->insertItem( i, "SOCKS 5", QNetworkProxy::Socks5Proxy );
m_forwardMap[ QNetworkProxy::Socks5Proxy ] = i;
m_backwardMap[ i ] = QNetworkProxy::Socks5Proxy;
i++;
TomahawkSettings* s = TomahawkSettings::instance();
ui->typeBox->setCurrentIndex( m_forwardMap[s->proxyType()] );
ui->hostLineEdit->setText( s->proxyHost() );
ui->portSpinBox->setValue( s->proxyPort() );
ui->userLineEdit->setText( s->proxyUsername() );
ui->passwordLineEdit->setText( s->proxyPassword() );
ui->checkBoxUseProxyForDns->setChecked( s->proxyDns() );
ui->noHostLineEdit->setText( s->proxyNoProxyHosts() );
if ( s->proxyType() == QNetworkProxy::NoProxy )
{
ui->hostLineEdit->setEnabled( false );
ui->portSpinBox->setEnabled( false );
ui->userLineEdit->setEnabled( false );
ui->passwordLineEdit->setEnabled( false );
ui->checkBoxUseProxyForDns->setEnabled( false );
}
connect( ui->typeBox, SIGNAL( currentIndexChanged( int ) ), SLOT( proxyTypeChangedSlot( int ) ) );
}
void
ProxyDialog::proxyTypeChangedSlot( int index )
{
if ( m_backwardMap[ index ] == QNetworkProxy::NoProxy )
{
ui->hostLineEdit->setEnabled( false );
ui->portSpinBox->setEnabled( false );
ui->userLineEdit->setEnabled( false );
ui->passwordLineEdit->setEnabled( false );
ui->checkBoxUseProxyForDns->setEnabled( false );
}
else
{
ui->hostLineEdit->setEnabled( true );
ui->portSpinBox->setEnabled( true );
ui->userLineEdit->setEnabled( true );
ui->passwordLineEdit->setEnabled( true );
ui->checkBoxUseProxyForDns->setEnabled( true );
}
}
@ -494,8 +501,6 @@ ProxyDialog::saveSettings()
{
qDebug() << Q_FUNC_INFO;
QNetworkProxy::ProxyType type = static_cast< QNetworkProxy::ProxyType>( m_backwardMap[ ui->typeBox->currentIndex() ] );
//First set settings
TomahawkSettings* s = TomahawkSettings::instance();
s->setProxyHost( ui->hostLineEdit->text() );
@ -505,26 +510,6 @@ ProxyDialog::saveSettings()
s->setProxyNoProxyHosts( ui->noHostLineEdit->text() );
s->setProxyUsername( ui->userLineEdit->text() );
s->setProxyPassword( ui->passwordLineEdit->text() );
s->setProxyType( type );
s->setProxyDns( ui->checkBoxUseProxyForDns->checkState() == Qt::Checked );
s->sync();
TomahawkUtils::NetworkProxyFactory* proxyFactory = TomahawkUtils::proxyFactory();
tDebug() << Q_FUNC_INFO << "Got proxyFactory: " << proxyFactory;
if ( type == QNetworkProxy::NoProxy )
{
tDebug() << Q_FUNC_INFO << "Got NoProxy selected";
proxyFactory->setProxy( QNetworkProxy::NoProxy );
}
else
{
tDebug() << Q_FUNC_INFO << "Got Socks5Proxy selected";
proxyFactory->setProxy( QNetworkProxy( type, s->proxyHost(), s->proxyPort(), s->proxyUsername(), s->proxyPassword() ) );
if ( !ui->noHostLineEdit->text().isEmpty() )
{
tDebug() << Q_FUNC_INFO << "noproxy line edit is " << ui->noHostLineEdit->text();
tDebug() << Q_FUNC_INFO << "split noproxy line edit is " << ui->noHostLineEdit->text().split( ' ', QString::SkipEmptyParts );
proxyFactory->setNoProxyHosts( ui->noHostLineEdit->text().split( ' ', QString::SkipEmptyParts ) );
}
}
}

View File

@ -61,13 +61,8 @@ public:
void saveSettings();
private slots:
void proxyTypeChangedSlot( int index );
private:
Ui::ProxyDialog* ui;
QHash<int,int> m_forwardMap;
QHash<int,int> m_backwardMap;
};
class SettingsDialog : public QDialog
@ -84,7 +79,8 @@ protected:
private slots:
void onRejected();
void toggleUpnp( bool preferStaticEnabled );
void toggleRemoteMode();
void toggleProxyEnabled();
void showProxySettings();
void accountsFilterChanged( int );
@ -110,6 +106,7 @@ private:
ProxyDialog m_proxySettings;
bool m_rejected;
bool m_restartRequired;
Tomahawk::Accounts::AccountModel* m_accountModel;
Tomahawk::Accounts::AccountModelFilterProxy* m_accountProxy;
AnimatedSpinner* m_sipSpinner;

View File

@ -85,7 +85,7 @@
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="accountsPage">
<layout class="QVBoxLayout" name="verticalLayout_11">
@ -242,127 +242,103 @@
</sizepolicy>
</property>
<property name="title">
<string>Advanced Network Settings</string>
<string>Advanced Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
<property name="margin">
<number>2</number>
</property>
<item>
<layout class="QVBoxLayout" name="staticSettingsLayout">
<item>
<layout class="QHBoxLayout" name="staticPreferredLayout"/>
</item>
<item>
<widget class="QLabel" name="staticHostNamePortLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>If you're having difficulty connecting to peers, try setting this to your external IP address/host name and a port number (default 50210). Make sure to forward that port to this machine!</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="staticHostNamePortLayout">
<item>
<widget class="QLabel" name="staticHostNameLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Static Host Name:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="staticHostName"/>
</item>
<item>
<widget class="QLabel" name="staticPortLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Static Port:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="staticPort">
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>50210</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxStaticPreferred">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Always use static host name/port? (Overrides UPnP discovery/port forwarding)</string>
</property>
</widget>
</item>
</layout>
<widget class="QGroupBox" name="remoteConnectionsGroupBox">
<property name="title">
<string>Remote Peer Connection Method</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QRadioButton" name="lanOnlyRadioButton">
<property name="text">
<string>None (outgoing connections only)</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="upnpRadioButton">
<property name="text">
<string>Use UPnP to establish port forward (recommended)</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="staticIpRadioButton">
<property name="text">
<string>Use static external IP address/host name and port</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="staticHostNamePortLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Set this to your external IP address or host name. Make sure to forward the port to this host!</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="staticHostNamePortLayout">
<item>
<widget class="QLabel" name="staticHostNameLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Static Host Name:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="staticHostName"/>
</item>
<item>
<widget class="QLabel" name="staticPortLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Static Port:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="staticPort">
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>50210</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="proxySettingsHLayout">
<item>
<spacer name="proxySettingsLeftSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="proxyButton">
<property name="text">
<string>Proxy Settings...</string>
</property>
</widget>
</item>
<item>
<spacer name="proxySettingsRightSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_5">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
@ -375,43 +351,88 @@
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBoxReporter">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Send reports after Tomahawk crashed</string>
</property>
<property name="checked">
<bool>true</bool>
<widget class="QGroupBox" name="proxyGroupBox">
<property name="title">
<string>SOCKS Proxy</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QCheckBox" name="enableProxyCheckBox">
<property name="text">
<string>Use SOCKS Proxy</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="proxyButton">
<property name="text">
<string>Proxy Settings...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxHttp">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="text">
<string>Allow web browsers to interact with Tomahawk (recommended)</string>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
<property name="checked">
<bool>true</bool>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="otherSettingsGroupBox">
<property name="title">
<string>Other Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="checkBoxHttp">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Allow web browsers to interact with Tomahawk (recommended)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxReporter">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Send reports after Tomahawk crashed</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxUpnp">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="text">
<string>Use UPnP to establish port forward</string>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</spacer>
</item>
</layout>
</widget>

View File

@ -562,7 +562,7 @@ TomahawkApp::initServent()
{
tDebug() << "Init Servent.";
bool upnp = !arguments().contains( "--noupnp" ) && TomahawkSettings::instance()->value( "network/upnp", true ).toBool() && !TomahawkSettings::instance()->preferStaticHostPort();
bool upnp = !arguments().contains( "--noupnp" );
int port = TomahawkSettings::instance()->externalPort();
if ( !Servent::instance()->startListening( QHostAddress( QHostAddress::Any ), upnp, port ) )
{

View File

@ -1048,8 +1048,13 @@ TomahawkSettings::removeAccount( const QString& accountId )
TomahawkSettings::ExternalAddressMode
TomahawkSettings::externalAddressMode() const
TomahawkSettings::externalAddressMode()
{
if ( value( "network/prefer-static-host-and-port", false ).toBool() )
{
remove( "network/prefer-static-host-and-port" );
setValue( "network/external-address-mode", TomahawkSettings::Static );
}
return (TomahawkSettings::ExternalAddressMode) value( "network/external-address-mode", TomahawkSettings::Upnp ).toInt();
}
@ -1061,18 +1066,6 @@ TomahawkSettings::setExternalAddressMode( ExternalAddressMode externalAddressMod
}
bool TomahawkSettings::preferStaticHostPort() const
{
return value( "network/prefer-static-host-and-port", false ).toBool();
}
void TomahawkSettings::setPreferStaticHostPort( bool prefer )
{
setValue( "network/prefer-static-host-and-port", prefer );
}
QString
TomahawkSettings::externalHostname() const
{

View File

@ -123,13 +123,10 @@ public:
QString bookmarkPlaylist() const;
/// Network settings
enum ExternalAddressMode { Lan, Upnp };
ExternalAddressMode externalAddressMode() const;
enum ExternalAddressMode { Lan, Upnp, Static };
ExternalAddressMode externalAddressMode();
void setExternalAddressMode( ExternalAddressMode externalAddressMode );
bool preferStaticHostPort() const;
void setPreferStaticHostPort( bool prefer );
bool httpEnabled() const; /// true by default
void setHttpEnabled( bool enable );

View File

@ -118,30 +118,31 @@ Servent::startListening( QHostAddress ha, bool upnp, int port )
}
}
TomahawkSettings::ExternalAddressMode mode = TomahawkSettings::instance()->externalAddressMode();
tLog() << "Servent listening on port" << m_port << "- servent thread:" << thread()
<< "- address mode:" << (int)( TomahawkSettings::instance()->externalAddressMode() );
<< "- address mode:" << (int)( mode );
// --lanhack means to advertise your LAN IP as if it were externally visible
if ( TomahawkSettings::instance()->preferStaticHostPort() )
{
m_externalHostname = TomahawkSettings::instance()->externalHostname();
m_externalPort = TomahawkSettings::instance()->externalPort();
m_ready = true;
emit ready();
return true;
}
TomahawkSettings::ExternalAddressMode mode = TomahawkSettings::instance()->externalAddressMode();
if ( mode == TomahawkSettings::Upnp && !upnp )
mode = TomahawkSettings::Lan;
switch ( mode )
{
case TomahawkSettings::Static:
m_externalHostname = TomahawkSettings::instance()->externalHostname();
m_externalPort = TomahawkSettings::instance()->externalPort();
m_ready = true;
emit ready();
break;
case TomahawkSettings::Lan:
setInternalAddress();
break;
case TomahawkSettings::Upnp:
if ( !upnp )
{
setInternalAddress();
break;
}
// TODO check if we have a public/internet IP on this machine directly
tLog() << "External address mode set to upnp...";
m_portfwd = new PortFwdThread( m_port );
@ -221,19 +222,9 @@ Servent::setExternalAddress( QHostAddress ha, unsigned int port )
if ( m_externalPort == 0 || !isValidExternalIP( ha ) )
{
if ( !TomahawkSettings::instance()->externalHostname().isEmpty() &&
!TomahawkSettings::instance()->externalPort() == 0 )
{
m_externalHostname = TomahawkSettings::instance()->externalHostname();
m_externalPort = TomahawkSettings::instance()->externalPort();
tDebug() << "UPnP failed, have external address/port - falling back" << m_externalHostname << m_externalPort << m_externalAddress;
}
else
{
tLog() << "No external access, LAN and outbound connections only!";
setInternalAddress();
return;
}
tLog() << "UPnP failed, LAN and outbound connections only!";
setInternalAddress();
return;
}
m_ready = true;