mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 03:40:16 +02:00
Dynamically enable/disable the web API, and change the wording for the option to make it more enticing
This commit is contained in:
@@ -644,7 +644,7 @@
|
|||||||
<enum>Qt::RightToLeft</enum>
|
<enum>Qt::RightToLeft</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Playdar HTTP API</string>
|
<string>Allow web browsers to detect Tomahawk</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="checked">
|
<property name="checked">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
@@ -255,6 +255,7 @@ TomahawkApp::init()
|
|||||||
{
|
{
|
||||||
initHTTP();
|
initHTTP();
|
||||||
}
|
}
|
||||||
|
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( initHTTP() ) );
|
||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
if ( !s->hasScannerPaths() )
|
if ( !s->hasScannerPaths() )
|
||||||
@@ -296,6 +297,11 @@ TomahawkApp::~TomahawkApp()
|
|||||||
{
|
{
|
||||||
tLog() << "Shutting down Tomahawk...";
|
tLog() << "Shutting down Tomahawk...";
|
||||||
|
|
||||||
|
if ( !m_session.isNull() )
|
||||||
|
delete m_session.data();
|
||||||
|
if ( !m_connector.isNull() )
|
||||||
|
delete m_connector.data();
|
||||||
|
|
||||||
Pipeline::instance()->stop();
|
Pipeline::instance()->stop();
|
||||||
|
|
||||||
if ( !m_servent.isNull() )
|
if ( !m_servent.isNull() )
|
||||||
@@ -458,15 +464,43 @@ TomahawkApp::initDatabase()
|
|||||||
void
|
void
|
||||||
TomahawkApp::initHTTP()
|
TomahawkApp::initHTTP()
|
||||||
{
|
{
|
||||||
m_session.setPort( 60210 ); //TODO config
|
if ( !TomahawkSettings::instance()->httpEnabled() )
|
||||||
m_session.setListenInterface( QHostAddress::LocalHost );
|
{
|
||||||
m_session.setConnector( &m_connector );
|
tLog() << "Stopping HTTPd, not enabled";
|
||||||
|
if ( !m_session.isNull() )
|
||||||
|
delete m_session.data();
|
||||||
|
if ( !m_connector.isNull() )
|
||||||
|
delete m_connector.data();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Api_v1* api = new Api_v1( &m_session );
|
if ( m_session )
|
||||||
m_session.setStaticContentService( api );
|
{
|
||||||
|
tLog() << "HTTPd session already exists, returning";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
tLog() << "Starting HTTPd on" << m_session.listenInterface().toString() << m_session.port();
|
m_session = QWeakPointer< QxtHttpSessionManager >( new QxtHttpSessionManager() );
|
||||||
m_session.start();
|
m_connector = QWeakPointer< QxtHttpServerConnector >( new QxtHttpServerConnector );
|
||||||
|
if ( m_session.isNull() || m_connector.isNull() )
|
||||||
|
{
|
||||||
|
if ( !m_session.isNull() )
|
||||||
|
delete m_session.data();
|
||||||
|
if ( !m_connector.isNull() )
|
||||||
|
delete m_connector.data();
|
||||||
|
tLog() << "Failed to start HTTPd, could not create object";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_session.data()->setPort( 60210 ); //TODO config
|
||||||
|
m_session.data()->setListenInterface( QHostAddress::LocalHost );
|
||||||
|
m_session.data()->setConnector( m_connector.data() );
|
||||||
|
|
||||||
|
Api_v1* api = new Api_v1( m_session.data() );
|
||||||
|
m_session.data()->setStaticContentService( api );
|
||||||
|
|
||||||
|
tLog() << "Starting HTTPd on" << m_session.data()->listenInterface().toString() << m_session.data()->port();
|
||||||
|
m_session.data()->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -101,6 +101,7 @@ public slots:
|
|||||||
private slots:
|
private slots:
|
||||||
void initServent();
|
void initServent();
|
||||||
void initSIP();
|
void initSIP();
|
||||||
|
void initHTTP();
|
||||||
|
|
||||||
void spotifyApiCheckFinished();
|
void spotifyApiCheckFinished();
|
||||||
|
|
||||||
@@ -114,8 +115,6 @@ private:
|
|||||||
void initLocalCollection();
|
void initLocalCollection();
|
||||||
void initPipeline();
|
void initPipeline();
|
||||||
|
|
||||||
void initHTTP();
|
|
||||||
|
|
||||||
QWeakPointer<Database> m_database;
|
QWeakPointer<Database> m_database;
|
||||||
QWeakPointer<ScanManager> m_scanManager;
|
QWeakPointer<ScanManager> m_scanManager;
|
||||||
QWeakPointer<AudioEngine> m_audioEngine;
|
QWeakPointer<AudioEngine> m_audioEngine;
|
||||||
@@ -135,8 +134,8 @@ private:
|
|||||||
|
|
||||||
bool m_headless, m_loaded;
|
bool m_headless, m_loaded;
|
||||||
|
|
||||||
QxtHttpServerConnector m_connector;
|
QWeakPointer< QxtHttpServerConnector > m_connector;
|
||||||
QxtHttpSessionManager m_session;
|
QWeakPointer< QxtHttpSessionManager > m_session;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE( QPersistentModelIndex )
|
Q_DECLARE_METATYPE( QPersistentModelIndex )
|
||||||
|
Reference in New Issue
Block a user