mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-01-18 23:17:59 +01:00
Wrap creation of Playdar api in libtomahawk-playdarapi
* Qxt is now only used in libtomahawk-playdarapi and not required in any other target.
This commit is contained in:
parent
99d46c8823
commit
39d12f573e
@ -39,62 +39,11 @@
|
||||
using namespace Tomahawk;
|
||||
using namespace TomahawkUtils;
|
||||
|
||||
QPointer< Api_v1 > Api_v1::s_instance = NULL;
|
||||
QPointer< QxtHttpServerConnector > Api_v1::s_connector;
|
||||
QPointer< QxtHttpSessionManager > Api_v1::s_session;
|
||||
|
||||
|
||||
Api_v1::Api_v1( QxtAbstractWebSessionManager* sm, QObject* parent )
|
||||
: QxtWebSlotService(sm, parent)
|
||||
{
|
||||
}
|
||||
|
||||
Api_v1*
|
||||
Api_v1::startInstance( QHostAddress interface, qint16 port )
|
||||
{
|
||||
if ( !s_session.isNull() )
|
||||
{
|
||||
tLog() << "HTTPd session already exists, returning";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s_session = QPointer< QxtHttpSessionManager >( new QxtHttpSessionManager() );
|
||||
s_connector = QPointer< QxtHttpServerConnector >( new QxtHttpServerConnector );
|
||||
if ( s_session.isNull() || s_connector.isNull() )
|
||||
{
|
||||
if ( !s_session.isNull() )
|
||||
delete s_session.data();
|
||||
if ( !s_connector.isNull() )
|
||||
delete s_connector.data();
|
||||
tLog() << "Failed to start HTTPd, could not create object";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s_session->setListenInterface( interface );
|
||||
s_session->setPort( port );
|
||||
s_session->setConnector( s_connector.data() );
|
||||
|
||||
s_instance = new Api_v1( s_session.data() );
|
||||
s_session->setStaticContentService( s_instance );
|
||||
|
||||
tLog() << "Starting HTTPd on" << s_session->listenInterface().toString() << s_session->port();
|
||||
s_session->start();
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Api_v1::stopInstance()
|
||||
{
|
||||
if ( !s_connector.isNull() )
|
||||
delete s_connector.data();
|
||||
if ( !s_session.isNull() )
|
||||
delete s_session.data();
|
||||
if ( !s_instance.isNull() )
|
||||
delete s_instance;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Api_v1::auth_1( QxtWebRequestEvent* event, QString arg )
|
||||
{
|
||||
|
@ -52,24 +52,6 @@ Q_OBJECT
|
||||
public:
|
||||
Api_v1( QxtAbstractWebSessionManager* sm, QObject* parent = 0 );
|
||||
|
||||
/**
|
||||
* Get the current running instance instaniated by the singleton helper
|
||||
* functions.
|
||||
*/
|
||||
static Api_v1* instance();
|
||||
|
||||
/**
|
||||
* Start a singleton instance of the playdar API. Though you are not
|
||||
* limited to use one instance of this class, this helper function takes
|
||||
* care of all related Qxt classes that need to be instantiated to run the API.
|
||||
*/
|
||||
static Api_v1* startInstance( QHostAddress interface, qint16 port );
|
||||
|
||||
/**
|
||||
* Stop the singleton instance and release its resources.
|
||||
*/
|
||||
static void stopInstance();
|
||||
|
||||
public slots:
|
||||
// authenticating uses /auth_1
|
||||
// we redirect to /auth_2 for the callback
|
||||
@ -100,12 +82,6 @@ private:
|
||||
|
||||
QxtWebRequestEvent* m_storedEvent;
|
||||
QSharedPointer< QIODevice > m_ioDevice;
|
||||
|
||||
// Static variables for the singleton instance.
|
||||
static QPointer< Api_v1 > s_instance;
|
||||
static QPointer< QxtHttpServerConnector > s_connector;
|
||||
static QPointer< QxtHttpSessionManager > s_session;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -3,6 +3,7 @@ set(TOMAHAWK_PLAYDARAPI_LIBRARY_TARGET tomahawk-playdarapi)
|
||||
|
||||
list(APPEND ${TOMAHAWK_PLAYDARAPI_LIBRARY_TARGET}_SOURCES
|
||||
Api_v1.cpp
|
||||
PlaydarApi.cpp
|
||||
)
|
||||
|
||||
list(APPEND ${TOMAHAWK_PLAYDARAPI_LIBRARY_TARGET}_UI
|
||||
|
70
src/libtomahawk-playdarapi/PlaydarApi.cpp
Normal file
70
src/libtomahawk-playdarapi/PlaydarApi.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
/* === 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/>.
|
||||
*/
|
||||
|
||||
#include "PlaydarApi_p.h"
|
||||
|
||||
#include "utils/Logger.h"
|
||||
|
||||
PlaydarApi::PlaydarApi( QHostAddress ha, qint16 port, QObject* parent )
|
||||
: QObject( parent )
|
||||
, d_ptr( new PlaydarApiPrivate( this ) )
|
||||
{
|
||||
Q_D( PlaydarApi );
|
||||
|
||||
d->ha = ha;
|
||||
d->port = port;
|
||||
}
|
||||
|
||||
|
||||
PlaydarApi::~PlaydarApi()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaydarApi::start()
|
||||
{
|
||||
Q_D( PlaydarApi );
|
||||
if ( d->session.isNull() )
|
||||
{
|
||||
tLog() << "HTTPd session already exists, returning";
|
||||
return;
|
||||
}
|
||||
|
||||
d->session.reset( new QxtHttpSessionManager() );
|
||||
d->connector.reset( new QxtHttpServerConnector() );
|
||||
if ( d->session.isNull() || d->connector.isNull() )
|
||||
{
|
||||
if ( !d->session.isNull() )
|
||||
delete d->session.data();
|
||||
if ( !d->connector.isNull() )
|
||||
delete d->connector.data();
|
||||
tLog() << "Failed to start HTTPd, could not create object";
|
||||
return;
|
||||
}
|
||||
|
||||
d->session->setListenInterface( d->ha );
|
||||
d->session->setPort( d->port );
|
||||
d->session->setConnector( d->connector.data() );
|
||||
|
||||
d->instance.reset( new Api_v1( d->session.data() ) );
|
||||
d->session->setStaticContentService( d->instance.data() );
|
||||
|
||||
tLog() << "Starting HTTPd on" << d->session->listenInterface().toString() << d->session->port();
|
||||
d->session->start();
|
||||
}
|
45
src/libtomahawk-playdarapi/PlaydarApi.h
Normal file
45
src/libtomahawk-playdarapi/PlaydarApi.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* === 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 PLAYDARAPI_H
|
||||
#define PLAYDARAPI_H
|
||||
|
||||
#include "PlaydarAPIDllMacro.h"
|
||||
|
||||
#include <QHostAddress>
|
||||
#include <QObject>
|
||||
|
||||
class PlaydarApiPrivate;
|
||||
|
||||
class TOMAHAWK_PLAYDARAPI_EXPORT PlaydarApi : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PlaydarApi( QHostAddress ha, qint16 port, QObject *parent = 0 );
|
||||
virtual ~PlaydarApi();
|
||||
|
||||
void start();
|
||||
|
||||
protected:
|
||||
QScopedPointer<PlaydarApiPrivate> d_ptr;
|
||||
|
||||
private:
|
||||
Q_DECLARE_PRIVATE( PlaydarApi )
|
||||
};
|
||||
|
||||
#endif // PLAYDARAPI_H
|
45
src/libtomahawk-playdarapi/PlaydarApi_p.h
Normal file
45
src/libtomahawk-playdarapi/PlaydarApi_p.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* === 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 PLAYDARAPI_P_H
|
||||
#define PLAYDARAPI_P_H
|
||||
|
||||
#include "PlaydarApi.h"
|
||||
|
||||
#include "Api_v1.h"
|
||||
|
||||
class PlaydarApiPrivate
|
||||
{
|
||||
public:
|
||||
PlaydarApiPrivate( PlaydarApi* q )
|
||||
: q_ptr( q )
|
||||
{
|
||||
}
|
||||
|
||||
PlaydarApi* q_ptr;
|
||||
Q_DECLARE_PUBLIC( PlaydarApi )
|
||||
|
||||
private:
|
||||
QScopedPointer< Api_v1 > instance;
|
||||
QScopedPointer< QxtHttpServerConnector > connector;
|
||||
QScopedPointer< QxtHttpSessionManager > session;
|
||||
QHostAddress ha;
|
||||
qint16 port;
|
||||
};
|
||||
|
||||
#endif // PLAYDARAPI_P_H
|
@ -97,7 +97,6 @@ INCLUDE_DIRECTORIES(
|
||||
|
||||
${THIRDPARTY_DIR}/breakpad
|
||||
|
||||
${QXTWEB_INCLUDE_DIRS}
|
||||
${TAGLIB_INCLUDES}
|
||||
${QJSON_INCLUDE_DIR}
|
||||
${LIBATTICA_INCLUDE_DIR}
|
||||
|
@ -64,7 +64,6 @@
|
||||
#include "jobview/ErrorStatusMessage.h"
|
||||
#include "jobview/JobStatusModel.h"
|
||||
#include "jobview/JobStatusView.h"
|
||||
#include "libtomahawk-playdarapi/Api_v1.h"
|
||||
#include "utils/XspfLoader.h"
|
||||
#include "utils/JspfLoader.h"
|
||||
#include "utils/Logger.h"
|
||||
@ -479,11 +478,11 @@ TomahawkApp::initHTTP()
|
||||
{
|
||||
if ( TomahawkSettings::instance()->httpEnabled() )
|
||||
{
|
||||
Api_v1::startInstance( QHostAddress::LocalHost, 60210 ); // TODO: Config
|
||||
}
|
||||
else
|
||||
{
|
||||
Api_v1::stopInstance();
|
||||
if ( playdarApi.isNull() )
|
||||
{
|
||||
playdarApi = new PlaydarApi( QHostAddress::LocalHost, 60210, this ); // TODO Config
|
||||
}
|
||||
playdarApi->start();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include "mac/TomahawkApp_Mac.h" // for PlatforInterface
|
||||
#include "Typedefs.h"
|
||||
#include "libtomahawk-playdarapi/PlaydarApi.h"
|
||||
#include "utils/TomahawkUtils.h"
|
||||
#include "thirdparty/kdsingleapplicationguard/kdsingleapplicationguard.h"
|
||||
|
||||
@ -142,6 +143,7 @@ private:
|
||||
#ifndef TOMAHAWK_HEADLESS
|
||||
TomahawkWindow* m_mainwindow;
|
||||
#endif
|
||||
QPointer<PlaydarApi> playdarApi;
|
||||
|
||||
bool m_headless;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user