mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-09-02 10:24:01 +02:00
Decouple Servent from TomahawkSettings
This commit is contained in:
@@ -1286,20 +1286,20 @@ TomahawkSettings::removeAccount( const QString& accountId )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TomahawkSettings::ExternalAddressMode
|
Tomahawk::Network::ExternalAddress::Mode
|
||||||
TomahawkSettings::externalAddressMode()
|
TomahawkSettings::externalAddressMode()
|
||||||
{
|
{
|
||||||
if ( value( "network/prefer-static-host-and-port", false ).toBool() )
|
if ( value( "network/prefer-static-host-and-port", false ).toBool() )
|
||||||
{
|
{
|
||||||
remove( "network/prefer-static-host-and-port" );
|
remove( "network/prefer-static-host-and-port" );
|
||||||
setValue( "network/external-address-mode", TomahawkSettings::Static );
|
setValue( "network/external-address-mode", Tomahawk::Network::ExternalAddress::Static );
|
||||||
}
|
}
|
||||||
return (TomahawkSettings::ExternalAddressMode) value( "network/external-address-mode", TomahawkSettings::Upnp ).toInt();
|
return (Tomahawk::Network::ExternalAddress::Mode) value( "network/external-address-mode", Tomahawk::Network::ExternalAddress::Upnp ).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TomahawkSettings::setExternalAddressMode( ExternalAddressMode externalAddressMode )
|
TomahawkSettings::setExternalAddressMode( Tomahawk::Network::ExternalAddress::Mode externalAddressMode )
|
||||||
{
|
{
|
||||||
setValue( "network/external-address-mode", externalAddressMode );
|
setValue( "network/external-address-mode", externalAddressMode );
|
||||||
}
|
}
|
||||||
|
@@ -21,11 +21,13 @@
|
|||||||
#ifndef TOMAHAWK_SETTINGS_H
|
#ifndef TOMAHAWK_SETTINGS_H
|
||||||
#define TOMAHAWK_SETTINGS_H
|
#define TOMAHAWK_SETTINGS_H
|
||||||
|
|
||||||
|
#include "network/Enums.h"
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
|
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QtNetwork/QNetworkProxy>
|
#include <QNetworkProxy>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
#define TOMAHAWK_SETTINGS_VERSION 15
|
#define TOMAHAWK_SETTINGS_VERSION 15
|
||||||
@@ -134,9 +136,8 @@ public:
|
|||||||
QString bookmarkPlaylist() const;
|
QString bookmarkPlaylist() const;
|
||||||
|
|
||||||
/// Network settings
|
/// Network settings
|
||||||
enum ExternalAddressMode { Lan, Upnp, Static };
|
Tomahawk::Network::ExternalAddress::Mode externalAddressMode();
|
||||||
ExternalAddressMode externalAddressMode();
|
void setExternalAddressMode( Tomahawk::Network::ExternalAddress::Mode externalAddressMode );
|
||||||
void setExternalAddressMode( ExternalAddressMode externalAddressMode );
|
|
||||||
|
|
||||||
bool httpEnabled() const; /// true by default
|
bool httpEnabled() const; /// true by default
|
||||||
void setHttpEnabled( bool enable );
|
void setHttpEnabled( bool enable );
|
||||||
|
39
src/libtomahawk/network/Enums.h
Normal file
39
src/libtomahawk/network/Enums.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ENUMS_H
|
||||||
|
#define ENUMS_H
|
||||||
|
|
||||||
|
namespace Tomahawk
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Network
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace ExternalAddress
|
||||||
|
{
|
||||||
|
|
||||||
|
enum Mode { Lan, Upnp, Static };
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ENUMS_H
|
@@ -44,7 +44,6 @@
|
|||||||
#include "Source.h"
|
#include "Source.h"
|
||||||
#include "SourceList.h"
|
#include "SourceList.h"
|
||||||
#include "StreamConnection.h"
|
#include "StreamConnection.h"
|
||||||
#include "TomahawkSettings.h"
|
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
@@ -125,29 +124,28 @@ Servent::~Servent()
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Servent::startListening( QHostAddress ha, bool upnp, int port )
|
Servent::startListening( QHostAddress ha, bool upnp, int port, Tomahawk::Network::ExternalAddress::Mode mode, int defaultPort, bool autoDetectExternalIp, const QString& externalHost, int externalPort )
|
||||||
{
|
{
|
||||||
Q_D( Servent );
|
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();
|
|
||||||
|
|
||||||
// Listen on both the selected port and, if not the same, the default port -- the latter sometimes necessary for zeroconf
|
// Listen on both the selected port and, if not the same, the default port -- the latter sometimes necessary for zeroconf
|
||||||
// TODO: only listen on both when zeroconf sip is enabled
|
// TODO: only listen on both when zeroconf sip is enabled
|
||||||
// TODO: use a real zeroconf system instead of a simple UDP broadcast?
|
// TODO: use a real zeroconf system instead of a simple UDP broadcast?
|
||||||
if ( !listen( ha, d_func()->port ) )
|
if ( !listen( ha, d_func()->port ) )
|
||||||
{
|
{
|
||||||
if ( d_func()->port != defPort )
|
if ( d_func()->port != defaultPort )
|
||||||
{
|
{
|
||||||
if ( !listen( ha, defPort ) )
|
if ( !listen( ha, defaultPort ) )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "Failed to listen on both port" << d_func()->port << "and port" << defPort;
|
tLog() << Q_FUNC_INFO << "Failed to listen on both port" << d_func()->port << "and port" << defaultPort;
|
||||||
tLog() << Q_FUNC_INFO << "Error string is:" << errorString();
|
tLog() << Q_FUNC_INFO << "Error string is:" << errorString();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
d_func()->port = defPort;
|
d_func()->port = defaultPort;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,15 +174,14 @@ Servent::startListening( QHostAddress ha, bool upnp, int port )
|
|||||||
}
|
}
|
||||||
// If we only accept connections via localhost, we'll announce nothing.
|
// If we only accept connections via localhost, we'll announce nothing.
|
||||||
|
|
||||||
TomahawkSettings::ExternalAddressMode mode = TomahawkSettings::instance()->externalAddressMode();
|
|
||||||
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Servent listening on port" << d_func()->port << "- servent thread:" << thread()
|
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Servent listening on port" << d_func()->port << "- servent thread:" << thread()
|
||||||
<< "- address mode:" << (int)( mode );
|
<< "- address mode:" << (int)( mode );
|
||||||
|
|
||||||
switch ( mode )
|
switch ( mode )
|
||||||
{
|
{
|
||||||
case TomahawkSettings::Static:
|
case Tomahawk::Network::ExternalAddress::Static:
|
||||||
d->externalPort = TomahawkSettings::instance()->externalPort();
|
d->externalPort = externalPort;
|
||||||
if ( TomahawkSettings::instance()->autoDetectExternalIp() )
|
if ( autoDetectExternalIp )
|
||||||
{
|
{
|
||||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( QUrl( "http://toma.hk/?stat=1" ) ) );
|
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( QUrl( "http://toma.hk/?stat=1" ) ) );
|
||||||
connect( reply, SIGNAL( finished() ), SLOT( ipDetected() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( ipDetected() ) );
|
||||||
@@ -192,20 +189,20 @@ Servent::startListening( QHostAddress ha, bool upnp, int port )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
d->externalHostname = TomahawkSettings::instance()->externalHostname();
|
d->externalHostname = externalHost;
|
||||||
d->ready = true;
|
d->ready = true;
|
||||||
// All setup is made, were done.
|
// All setup is made, were done.
|
||||||
emit ready();
|
emit ready();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TomahawkSettings::Lan:
|
case Tomahawk::Network::ExternalAddress::Lan:
|
||||||
// Nothing has to be done here.
|
// Nothing has to be done here.
|
||||||
d_func()->ready = true;
|
d_func()->ready = true;
|
||||||
emit ready();
|
emit ready();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TomahawkSettings::Upnp:
|
case Tomahawk::Network::ExternalAddress::Upnp:
|
||||||
if ( upnp )
|
if ( upnp )
|
||||||
{
|
{
|
||||||
// upnp could be turned of on the cli with --noupnp
|
// upnp could be turned of on the cli with --noupnp
|
||||||
|
@@ -25,15 +25,17 @@
|
|||||||
// time before new connection terminate if it could not be established
|
// time before new connection terminate if it could not be established
|
||||||
#define CONNECT_TIMEOUT 10000
|
#define CONNECT_TIMEOUT 10000
|
||||||
|
|
||||||
|
#include "network/Enums.h"
|
||||||
|
|
||||||
|
#include "DllMacro.h"
|
||||||
|
#include "Typedefs.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QTcpServer>
|
#include <QTcpServer>
|
||||||
|
|
||||||
#include "DllMacro.h"
|
|
||||||
#include "Typedefs.h"
|
|
||||||
|
|
||||||
class Connection;
|
class Connection;
|
||||||
class Connector;
|
class Connector;
|
||||||
class ControlConnection;
|
class ControlConnection;
|
||||||
@@ -67,7 +69,7 @@ public:
|
|||||||
explicit Servent( QObject* parent = 0 );
|
explicit Servent( QObject* parent = 0 );
|
||||||
virtual ~Servent();
|
virtual ~Servent();
|
||||||
|
|
||||||
bool startListening( QHostAddress ha, bool upnp, int port );
|
bool startListening( QHostAddress ha, bool upnp, int port, Tomahawk::Network::ExternalAddress::Mode mode, int defaultPort, bool autoDetectExternalIp = false, const QString& externalHost = "", int externalPort = -1 );
|
||||||
|
|
||||||
// creates new token that allows a controlconnection to be set up
|
// creates new token that allows a controlconnection to be set up
|
||||||
QString createConnectionKey( const QString& name = "", const QString &nodeid = "", const QString &key = "", bool onceOnly = true );
|
QString createConnectionKey( const QString& name = "", const QString &nodeid = "", const QString &key = "", bool onceOnly = true );
|
||||||
|
@@ -99,10 +99,10 @@ SettingsDialog::SettingsDialog(QObject *parent )
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Network settings
|
//Network settings
|
||||||
TomahawkSettings::ExternalAddressMode mode = TomahawkSettings::instance()->externalAddressMode();
|
Tomahawk::Network::ExternalAddress::Mode mode = TomahawkSettings::instance()->externalAddressMode();
|
||||||
if ( mode == TomahawkSettings::Lan )
|
if ( mode == Tomahawk::Network::ExternalAddress::Lan )
|
||||||
m_advancedWidgetUi->lanOnlyRadioButton->setChecked( true );
|
m_advancedWidgetUi->lanOnlyRadioButton->setChecked( true );
|
||||||
else if ( mode == TomahawkSettings::Static )
|
else if ( mode == Tomahawk::Network::ExternalAddress::Static )
|
||||||
m_advancedWidgetUi->staticIpRadioButton->setChecked( true );
|
m_advancedWidgetUi->staticIpRadioButton->setChecked( true );
|
||||||
else
|
else
|
||||||
m_advancedWidgetUi->upnpRadioButton->setChecked( true );
|
m_advancedWidgetUi->upnpRadioButton->setChecked( true );
|
||||||
@@ -269,7 +269,7 @@ SettingsDialog::saveSettings()
|
|||||||
s->setHttpEnabled( m_advancedWidgetUi->checkBoxHttp->checkState() == Qt::Checked );
|
s->setHttpEnabled( m_advancedWidgetUi->checkBoxHttp->checkState() == Qt::Checked );
|
||||||
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() ? Tomahawk::Network::ExternalAddress::Upnp : ( m_advancedWidgetUi->lanOnlyRadioButton->isChecked() ? Tomahawk::Network::ExternalAddress::Lan : Tomahawk::Network::ExternalAddress::Static ) );
|
||||||
s->setAutoDetectExternalIp( m_advancedWidgetUi->autoDetectIpCheckBox->isChecked() );
|
s->setAutoDetectExternalIp( m_advancedWidgetUi->autoDetectIpCheckBox->isChecked() );
|
||||||
|
|
||||||
s->setExternalHostname( m_advancedWidgetUi->staticHostName->text() );
|
s->setExternalHostname( m_advancedWidgetUi->staticHostName->text() );
|
||||||
|
@@ -545,10 +545,15 @@ TomahawkApp::initServent()
|
|||||||
bool upnp = !arguments().contains( "--noupnp" );
|
bool upnp = !arguments().contains( "--noupnp" );
|
||||||
int port = TomahawkSettings::instance()->externalPort();
|
int port = TomahawkSettings::instance()->externalPort();
|
||||||
connect( Servent::instance(), SIGNAL( ipDetectionFailed( QNetworkReply::NetworkError, QString ) ), this, SLOT( ipDetectionFailed( QNetworkReply::NetworkError, QString ) ) );
|
connect( Servent::instance(), SIGNAL( ipDetectionFailed( QNetworkReply::NetworkError, QString ) ), this, SLOT( ipDetectionFailed( QNetworkReply::NetworkError, QString ) ) );
|
||||||
|
int defaultPort = TomahawkSettings::instance()->defaultPort();
|
||||||
|
Tomahawk::Network::ExternalAddress::Mode mode = TomahawkSettings::instance()->externalAddressMode();
|
||||||
|
const QString externalHostname = TomahawkSettings::instance()->externalHostname();
|
||||||
|
int externalPort = TomahawkSettings::instance()->externalPort();
|
||||||
|
bool autodetectIp = TomahawkSettings::instance()->autoDetectExternalIp();
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
||||||
if ( !Servent::instance()->startListening( QHostAddress( QHostAddress::Any ), upnp, port ) )
|
if ( !Servent::instance()->startListening( QHostAddress( QHostAddress::Any ), upnp, port, mode, defaultPort, autodetectIp, externalHostname, externalPort ) )
|
||||||
#else
|
#else
|
||||||
if ( !Servent::instance()->startListening( QHostAddress( QHostAddress::AnyIPv6 ), upnp, port ) )
|
if ( !Servent::instance()->startListening( QHostAddress( QHostAddress::AnyIPv6 ), upnp, port, mode, defaultPort, autodetectIp, externalHostname, externalPort ) )
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
tLog() << "Failed to start listening with servent";
|
tLog() << "Failed to start listening with servent";
|
||||||
|
Reference in New Issue
Block a user