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