1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-29 16:50:11 +02:00

* Split tomahawk into application and tomahawklib.

* Plugins link to and interface with tomahawklib.
* Compiles on Linux and Win32, but needs some more export macro love for the sip plugins on Win32.
This commit is contained in:
Christian Muehlhaeuser
2010-12-28 06:12:48 +01:00
parent 1496d322bf
commit 27e906f712
179 changed files with 946 additions and 691 deletions

View File

@@ -1,6 +1,7 @@
SET( OS_SPECIFIC_LINK_LIBRARIES
${OS_SPECIFIC_LINK_LIBRARIES}
alsaplayback
tomahawklib
)
IF( "${gui}" STREQUAL "no" )

View File

@@ -27,16 +27,6 @@ SET( TOMAHAWK_INC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../include/" )
#ENDFOREACH( moddir )
SET( tomahawkSources ${tomahawkSources}
artist.cpp
album.cpp
pipeline.cpp
playlist.cpp
pluginapi.cpp
query.cpp
result.cpp
source.cpp
sourcelist.cpp
audio/madtranscode.cpp
audio/vorbistranscode.cpp
audio/flactranscode.cpp
@@ -45,57 +35,18 @@ SET( tomahawkSources ${tomahawkSources}
utils/tomahawkutils.cpp
sip/SipHandler.cpp
sip/SipPlugin.cpp
infosystem/infosystem.cpp
infosystem/infoplugins/echonestplugin.cpp
infosystem/infoplugins/musixmatchplugin.cpp
collection.cpp
musicscanner.cpp
scriptresolver.cpp
network/bufferiodevice.cpp
network/msgprocessor.cpp
network/connection.cpp
network/controlconnection.cpp
network/filetransferconnection.cpp
network/dbsyncconnection.cpp
network/remotecollection.cpp
network/servent.cpp
database/fuzzyindex.cpp
database/database.cpp
database/databaseworker.cpp
database/databaseimpl.cpp
database/databaseresolver.cpp
database/databasecommand.cpp
database/databasecommandloggable.cpp
database/databasecommand_resolve.cpp
database/databasecommand_allalbums.cpp
database/databasecommand_alltracks.cpp
database/databasecommand_addfiles.cpp
database/databasecommand_dirmtimes.cpp
database/databasecommand_loadfile.cpp
database/databasecommand_addsource.cpp
database/databasecommand_sourceoffline.cpp
database/databasecommand_collectionstats.cpp
database/databasecommand_loadplaylistentries.cpp
database/databasecommand_modifyplaylist.cpp
database/databasecommand_setplaylistrevision.cpp
database/databasecommand_loadallplaylists.cpp
database/databasecommand_createplaylist.cpp
database/databasecommand_deleteplaylist.cpp
database/databasecommand_renameplaylist.cpp
database/databasecommand_loadops.cpp
database/databasecommand_updatesearchindex.cpp
database/databasecollection.cpp
scrobbler.cpp
xmppbot/xmppbot.cpp
web/api_v1.cpp
tomahawksettings.cpp
tomahawkapp.cpp
main.cpp
)
@@ -155,76 +106,21 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
SET( tomahawkHeaders ${tomahawkHeaders}
"${TOMAHAWK_INC_DIR}/tomahawk/tomahawkapp.h"
"${TOMAHAWK_INC_DIR}/tomahawk/collection.h"
"${TOMAHAWK_INC_DIR}/tomahawk/pipeline.h"
"${TOMAHAWK_INC_DIR}/tomahawk/pluginapi.h"
"${TOMAHAWK_INC_DIR}/tomahawk/query.h"
"${TOMAHAWK_INC_DIR}/tomahawk/resolver.h"
"${TOMAHAWK_INC_DIR}/tomahawk/result.h"
"${TOMAHAWK_INC_DIR}/tomahawk/source.h"
"${TOMAHAWK_INC_DIR}/tomahawk/sourcelist.h"
"${TOMAHAWK_INC_DIR}/tomahawk/artist.h"
"${TOMAHAWK_INC_DIR}/tomahawk/album.h"
"${TOMAHAWK_INC_DIR}/tomahawk/track.h"
"${TOMAHAWK_INC_DIR}/tomahawk/playlist.h"
"${TOMAHAWK_INC_DIR}/tomahawk/infosystem.h"
"${TOMAHAWK_INC_DIR}/tomahawk/functimeout.h"
# "${TOMAHAWK_INC_DIR}/tomahawk/tomahawkplugin.h"
audio/transcodeinterface.h
audio/madtranscode.h
audio/vorbistranscode.h
audio/flactranscode.h
audio/audioengine.h
database/fuzzyindex.h
database/database.h
database/databaseworker.h
database/databaseimpl.h
database/databaseresolver.h
database/databasecommand.h
database/databasecommandloggable.h
database/databasecommand_resolve.h
database/databasecommand_allalbums.h
database/databasecommand_alltracks.h
database/databasecommand_addfiles.h
database/databasecommand_dirmtimes.h
database/databasecommand_loadfile.h
database/databasecommand_addsource.h
database/databasecommand_sourceoffline.h
database/databasecommand_collectionstats.h
database/databasecommand_loadplaylistentries.h
database/databasecommand_modifyplaylist.h
database/databasecommand_setplaylistrevision.h
database/databasecommand_loadallplaylists.h
database/databasecommand_createplaylist.h
database/databasecommand_deleteplaylist.h
database/databasecommand_renameplaylist.h
database/databasecommand_loadops.h
database/databasecommand_updatesearchindex.h
database/databasecollection.h
sip/SipHandler.h
sip/SipPlugin.h
infosystem/infoplugins/echonestplugin.h
infosystem/infoplugins/musixmatchplugin.h
network/bufferiodevice.h
network/msgprocessor.h
network/remotecollection.h
network/servent.h
network/connection.h
network/controlconnection.h
network/filetransferconnection.h
network/dbsyncconnection.h
musicscanner.h
scriptresolver.h
tomahawksettings.h
scrobbler.h
xmppbot/xmppbot.h
@@ -307,10 +203,10 @@ INCLUDE_DIRECTORIES(
sourcetree
topbar
utils
libtomahawk
../rtaudio
../alsa-playback
../libportfwd/include
../qxt/qxtweb-standalone/qxtweb
/usr/include/taglib
@@ -361,9 +257,9 @@ MESSAGE( STATUS "OS_SPECIFIC_LINK_LIBRARIES: ${OS_SPECIFIC_LINK_LIBRARIES}" )
TARGET_LINK_LIBRARIES( tomahawk
${QT_LIBRARIES}
${MAC_EXTRA_LIBS}
portfwd
${OS_SPECIFIC_LINK_LIBRARIES}
${LIBECHONEST_LIBRARY}
qjson
tag
)

View File

@@ -1,6 +1,7 @@
ADD_DEFINITIONS( /DNOMINMAX )
ADD_DEFINITIONS( /DWIN32_LEAN_AND_MEAN )
ADD_DEFINITIONS( -static-libgcc )
#ADD_DEFINITIONS( /DNO_LIBLASTFM )
#ADD_DEFINITIONS( -DNO_OGG )
@@ -17,18 +18,23 @@ INCLUDE_DIRECTORIES(
../../taglib-1.6.3/taglib/toolkit
)
SET( GLOOX_LIBS
${GLOOX_LIBS}
gloox
)
SET( OS_SPECIFIC_LINK_LIBRARIES
${LIBLASTFM_LIBRARY}
gloox
${GLOOX_LIBS}
)
SET( OS_SPECIFIC_LINK_LIBRARIES
${OS_SPECIFIC_LINK_LIBRARIES}
"secur32.dll"
"crypt32.dll"
"ws2_32.dll"
"dnsapi.dll"
"${CMAKE_CURRENT_SOURCE_DIR}/../qxt/qxtweb-standalone/libqxtweb-standalone.dll"
"${CMAKE_CURRENT_SOURCE_DIR}/../build/src/libtomahawk/libtomahawklib.dll"
)
SET( tomahawkSourcesGui ${tomahawkSourcesGui} audio/rtaudiooutput.cpp )
@@ -45,4 +51,3 @@ SET( OS_SPECIFIC_LINK_LIBRARIES
"FLAC++"
"${CMAKE_CURRENT_SOURCE_DIR}/../rtaudio/librtaudio.dll"
)

View File

@@ -3,8 +3,8 @@
#include <QUrl>
#include <QMutexLocker>
#include <tomahawk/tomahawkapp.h>
#include "tomahawk/playlistinterface.h"
#include "playlistinterface.h"
#include "network/servent.h"
#include "madtranscode.h"
#ifndef NO_OGG
@@ -158,7 +158,7 @@ AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
emit finished( m_lastTrack );
m_currentTrack = result;
io = TomahawkApp::instance()->getIODeviceForUrl( m_currentTrack );
io = Servent::instance()->getIODeviceForUrl( m_currentTrack );
if ( !io || io.isNull() )
{

View File

@@ -5,8 +5,8 @@
#include <QMutex>
#include <QBuffer>
#include "tomahawk/result.h"
#include "tomahawk/typedefs.h"
#include "result.h"
#include "typedefs.h"
#include "rtaudiooutput.h"
#include "alsaplayback.h"

View File

@@ -4,7 +4,7 @@
#include <QNetworkReply>
#include "tomahawk/tomahawkapp.h"
#include "tomahawk/album.h"
#include "album.h"
#include "utils/tomahawkutils.h"
#include "audioengine.h"

View File

@@ -3,8 +3,8 @@
#include <QWidget>
#include "tomahawk/result.h"
#include "tomahawk/playlistinterface.h"
#include "result.h"
#include "playlistinterface.h"
namespace Ui
{

View File

@@ -3,9 +3,9 @@
#include <QWidget>
#include "tomahawk/album.h"
#include "tomahawk/result.h"
#include "tomahawk/playlistinterface.h"
#include "album.h"
#include "result.h"
#include "playlistinterface.h"
class AlbumModel;
class CollectionFlatModel;

View File

@@ -0,0 +1,150 @@
project( tomahawklib )
SET( QT_USE_QTSQL TRUE )
SET( QT_USE_QTNETWORK TRUE )
SET( QT_USE_QTXML TRUE )
include( ${QT_USE_FILE} )
add_definitions( ${QT_DEFINITIONS} )
add_definitions( -DQT_SHARED )
add_definitions( -DDLLEXPORT_PRO )
set( libSources
tomahawksettings.cpp
sourcelist.cpp
pipeline.cpp
artist.cpp
album.cpp
collection.cpp
playlist.cpp
pluginapi.cpp
query.cpp
result.cpp
source.cpp
sip/SipPlugin.cpp
network/bufferiodevice.cpp
network/msgprocessor.cpp
network/filetransferconnection.cpp
network/dbsyncconnection.cpp
network/remotecollection.cpp
database/fuzzyindex.cpp
database/databaseworker.cpp
database/databaseimpl.cpp
database/databaseresolver.cpp
database/databasecommand.cpp
database/databasecommandloggable.cpp
database/databasecommand_resolve.cpp
database/databasecommand_allalbums.cpp
database/databasecommand_alltracks.cpp
database/databasecommand_addfiles.cpp
database/databasecommand_dirmtimes.cpp
database/databasecommand_loadfile.cpp
database/databasecommand_addsource.cpp
database/databasecommand_sourceoffline.cpp
database/databasecommand_collectionstats.cpp
database/databasecommand_loadplaylistentries.cpp
database/databasecommand_modifyplaylist.cpp
database/databasecommand_setplaylistrevision.cpp
database/databasecommand_loadallplaylists.cpp
database/databasecommand_createplaylist.cpp
database/databasecommand_deleteplaylist.cpp
database/databasecommand_renameplaylist.cpp
database/databasecommand_loadops.cpp
database/databasecommand_updatesearchindex.cpp
database/databasecollection.cpp
database/database.cpp
network/servent.cpp
network/connection.cpp
network/controlconnection.cpp
)
set( libHeaders
tomahawksettings.h
sourcelist.h
pipeline.h
functimeout.h
collection.h
pluginapi.h
query.h
resolver.h
result.h
source.h
artist.h
album.h
track.h
playlist.h
sip/SipPlugin.h
database/database.h
database/fuzzyindex.h
database/databaseworker.h
database/databaseimpl.h
database/databaseresolver.h
database/databasecommand.h
database/databasecommandloggable.h
database/databasecommand_resolve.h
database/databasecommand_allalbums.h
database/databasecommand_alltracks.h
database/databasecommand_addfiles.h
database/databasecommand_dirmtimes.h
database/databasecommand_loadfile.h
database/databasecommand_addsource.h
database/databasecommand_sourceoffline.h
database/databasecommand_collectionstats.h
database/databasecommand_loadplaylistentries.h
database/databasecommand_modifyplaylist.h
database/databasecommand_setplaylistrevision.h
database/databasecommand_loadallplaylists.h
database/databasecommand_createplaylist.h
database/databasecommand_deleteplaylist.h
database/databasecommand_renameplaylist.h
database/databasecommand_loadops.h
database/databasecommand_updatesearchindex.h
database/databasecollection.h
network/bufferiodevice.h
network/msgprocessor.h
network/remotecollection.h
network/filetransferconnection.h
network/dbsyncconnection.h
network/servent.h
network/connection.h
network/controlconnection.h
)
include_directories( . ${CMAKE_CURRENT_BINARY_DIR} ..
${QT_INCLUDE_DIR}
../../libportfwd/include
../../include
../network
../../qxt/qxtweb-standalone/qxtweb
)
qt4_wrap_cpp( libMoc ${libHeaders} )
add_library( tomahawklib SHARED ${libSources} ${libMoc} )
IF( WIN32 )
SET( OS_SPECIFIC_LINK_LIBRARIES
${OS_SPECIFIC_LINK_LIBRARIES}
"iphlpapi.a"
"ws2_32.dll"
"dnsapi.dll"
)
ENDIF( WIN32 )
target_link_libraries( tomahawklib
${QT_LIBRARIES}
${OS_SPECIFIC_LINK_LIBRARIES}
portfwd
qjson
)
install( TARGETS tomahawklib DESTINATION . )

View File

@@ -1,9 +1,8 @@
#include "tomahawk/album.h"
#include "album.h"
#include <QDebug>
#include "tomahawk/collection.h"
#include "tomahawk/tomahawkapp.h"
#include "collection.h"
#include "database/database.h"
#include "database/databasecommand_alltracks.h"
@@ -77,7 +76,7 @@ Album::tracks()
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ),
SLOT( onTracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ) );
APP->database()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}
return m_queries;

70
src/libtomahawk/album.h Normal file
View File

@@ -0,0 +1,70 @@
#ifndef TOMAHAWKALBUM_H
#define TOMAHAWKALBUM_H
#include <QObject>
#include <QSharedPointer>
#include "typedefs.h"
#include "artist.h"
#include "collection.h"
#include "playlistinterface.h"
#include "dllmacro.h"
namespace Tomahawk
{
class DLLEXPORT Album : public QObject, public PlaylistInterface
{
Q_OBJECT
public:
static album_ptr get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist, const Tomahawk::collection_ptr& collection );
Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist, const Tomahawk::collection_ptr& collection );
unsigned int id() const { return m_id; }
QString name() const { return m_name; }
artist_ptr artist() const { return m_artist; }
Tomahawk::collection_ptr collection() const { return m_collection; }
QList<Tomahawk::query_ptr> tracks();
virtual int unfilteredTrackCount() const { return m_queries.count(); }
virtual int trackCount() const { return m_queries.count(); }
virtual Tomahawk::result_ptr siblingItem( int itemsAway );
virtual PlaylistInterface::RepeatMode repeatMode() const { return PlaylistInterface::NoRepeat; }
virtual bool shuffled() const { return false; }
virtual void setRepeatMode( PlaylistInterface::RepeatMode ) {}
virtual void setShuffled( bool ) {}
virtual void setFilter( const QString& pattern ) {}
signals:
void repeatModeChanged( PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled );
void tracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& );
void trackCountChanged( unsigned int tracks );
void sourceTrackCountChanged( unsigned int tracks );
private slots:
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection );
private:
unsigned int m_id;
QString m_name;
artist_ptr m_artist;
QList<Tomahawk::query_ptr> m_queries;
Tomahawk::collection_ptr m_collection;
unsigned int m_currentTrack;
};
}; // ns
#endif

View File

@@ -1,9 +1,8 @@
#include "tomahawk/artist.h"
#include "artist.h"
#include <QDebug>
#include "tomahawk/collection.h"
#include "tomahawk/tomahawkapp.h"
#include "collection.h"
#include "database/database.h"
#include "database/databasecommand_alltracks.h"

41
src/libtomahawk/artist.h Normal file
View File

@@ -0,0 +1,41 @@
#ifndef TOMAHAWKARTIST_H
#define TOMAHAWKARTIST_H
#include <QObject>
#include <QSharedPointer>
#include "typedefs.h"
#include "collection.h"
#include "dllmacro.h"
namespace Tomahawk
{
class DLLEXPORT Artist : public QObject
{
Q_OBJECT
public:
static artist_ptr get( unsigned int id, const QString& name, const Tomahawk::collection_ptr& collection );
Artist( unsigned int id, const QString& name, const Tomahawk::collection_ptr& collection );
unsigned int id() const { return m_id; }
QString name() const { return m_name; }
Tomahawk::collection_ptr collection() const { return m_collection; }
// QList<Tomahawk::query_ptr> tracks();
// virtual int trackCount() const { return 0; }
private:
unsigned int m_id;
QString m_name;
Tomahawk::collection_ptr m_collection;
};
}; // ns
#endif

View File

@@ -1,9 +1,9 @@
#include "tomahawk/collection.h"
#include "collection.h"
#include <QMetaObject>
#include <QGenericArgument>
#include "tomahawk/playlist.h"
#include "playlist.h"
using namespace Tomahawk;

View File

@@ -0,0 +1,81 @@
/*
The collection - acts as container for someones music library
load() -> async populate by calling addArtists etc,
then finishedLoading() is emitted.
then use artists() etc to get the data.
*/
#ifndef TOMAHAWK_COLLECTION_H
#define TOMAHAWK_COLLECTION_H
#include <QHash>
#include <QList>
#include <QSharedPointer>
#include <QDebug>
#include "functimeout.h"
#include "playlist.h"
#include "source.h"
#include "typedefs.h"
#include "dllmacro.h"
namespace Tomahawk
{
class DLLEXPORT Collection : public QObject
{
Q_OBJECT
public:
Collection( const source_ptr& source, const QString& name, QObject* parent = 0 );
virtual ~Collection();
virtual QString name() const;
virtual void loadPlaylists() { qDebug() << Q_FUNC_INFO; }
virtual void loadTracks() { qDebug() << Q_FUNC_INFO; }
virtual Tomahawk::playlist_ptr playlist( const QString& guid );
virtual void addPlaylist( const Tomahawk::playlist_ptr& p );
virtual void deletePlaylist( const Tomahawk::playlist_ptr& p );
virtual QList< Tomahawk::playlist_ptr > playlists() { return m_playlists; }
virtual QList< Tomahawk::query_ptr > tracks() { return m_tracks; }
const source_ptr& source() const { return m_source; }
unsigned int lastmodified() const { return m_lastmodified; }
signals:
void tracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& );
void tracksRemoved( const QList<QVariant>&, const Tomahawk::collection_ptr& );
void tracksFinished( const Tomahawk::collection_ptr& );
void playlistsAdded( const QList<Tomahawk::playlist_ptr>& );
void playlistsDeleted( const QList<Tomahawk::playlist_ptr>& );
public slots:
virtual void addTracks( const QList<QVariant> &newitems ) = 0;
virtual void removeTracks( const QList<QVariant> &olditems ) = 0;
void setPlaylists( const QList<Tomahawk::playlist_ptr>& plists );
void setTracks( const QList<Tomahawk::query_ptr>& tracks, Tomahawk::collection_ptr collection );
protected:
QString m_name;
unsigned int m_lastmodified; // unix time of last change to collection
private:
source_ptr m_source;
QList< Tomahawk::playlist_ptr > m_playlists;
QList< Tomahawk::query_ptr > m_tracks;
};
}; // ns
inline uint qHash( const QSharedPointer<Tomahawk::Collection>& key )
{
return qHash( (void *)key.data() );
}
#endif // TOMAHAWK_COLLECTION_H

View File

@@ -1,5 +1,14 @@
#include "database.h"
Database* Database::s_instance = 0;
Database*
Database::instance()
{
return s_instance;
}
Database::Database( const QString& dbname, QObject* parent )
: QObject( parent )
@@ -7,6 +16,8 @@ Database::Database( const QString& dbname, QObject* parent )
, m_workerRO( new DatabaseWorker( m_impl, this, false ) )
, m_workerRW( new DatabaseWorker( m_impl, this, true ) )
{
s_instance = this;
m_workerRO->start();
m_workerRW->start();
}

View File

@@ -4,9 +4,11 @@
#include <QSharedPointer>
#include <QVariant>
#include "databaseimpl.h"
#include "databasecommand.h"
#include "databaseworker.h"
#include "database/databaseimpl.h"
#include "database/databasecommand.h"
#include "database/databaseworker.h"
#include "dllmacro.h"
/*
This class is really a firewall/pimpl - the public functions of LibraryImpl
@@ -19,10 +21,12 @@
Update: 1 thread for mutates, one for readonly queries.
*/
class Database : public QObject
class DLLEXPORT Database : public QObject
{
Q_OBJECT
public:
static Database* instance();
explicit Database( const QString& dbname, QObject* parent = 0 );
~Database();
@@ -43,6 +47,8 @@ private:
DatabaseImpl* m_impl;
DatabaseWorker *m_workerRO, *m_workerRW;
bool m_indexReady;
static Database* s_instance;
};
#endif // DATABASE_H

View File

@@ -1,7 +1,6 @@
#include "databasecollection.h"
#include "tomahawk/tomahawkapp.h"
#include "database.h"
#include "database/database.h"
#include "databasecommand_alltracks.h"
#include "databasecommand_addfiles.h"
#include "databasecommand_loadallplaylists.h"
@@ -24,7 +23,7 @@ DatabaseCollection::loadPlaylists()
connect( cmd, SIGNAL( done( const QList<Tomahawk::playlist_ptr>& ) ),
SLOT( setPlaylists( const QList<Tomahawk::playlist_ptr>& ) ) );
TomahawkApp::instance()->database()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}
@@ -39,7 +38,7 @@ DatabaseCollection::loadTracks()
/* connect( cmd, SIGNAL( done( Tomahawk::collection_ptr ) ),
SIGNAL( tracksFinished( Tomahawk::collection_ptr ) ) );*/
TomahawkApp::instance()->database()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}
@@ -49,7 +48,7 @@ DatabaseCollection::addTracks( const QList<QVariant> &newitems )
qDebug() << Q_FUNC_INFO << newitems.length();
DatabaseCommand_AddFiles* cmd = new DatabaseCommand_AddFiles( newitems, source() );
TomahawkApp::instance()->database()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}

View File

@@ -1,10 +1,12 @@
#ifndef DATABASECOLLECTION_H
#define DATABASECOLLECTION_H
#include "tomahawk/collection.h"
#include "tomahawk/typedefs.h"
#include "collection.h"
#include "typedefs.h"
class DatabaseCollection : public Tomahawk::Collection
#include "dllmacro.h"
class DLLEXPORT DatabaseCollection : public Tomahawk::Collection
{
Q_OBJECT

View File

@@ -6,13 +6,15 @@
#include <QTime>
#include <QSqlQuery>
#include "tomahawk/source.h"
#include "tomahawk/typedefs.h"
#include "source.h"
#include "typedefs.h"
#include "database/op.h"
#include "dllmacro.h"
class DatabaseImpl;
class DatabaseCommand : public QObject
class DLLEXPORT DatabaseCommand : public QObject
{
Q_OBJECT
Q_PROPERTY( QString guid READ guid WRITE setGuid )

View File

@@ -2,12 +2,11 @@
#include <QSqlQuery>
#include "tomahawk/collection.h"
#include "tomahawk/tomahawkapp.h"
#include "database.h"
#include "collection.h"
#include "database/database.h"
#include "databasecommand_collectionstats.h"
#include "databaseimpl.h"
#include "controlconnection.h"
#include "network/controlconnection.h"
using namespace Tomahawk;
@@ -49,10 +48,10 @@ DatabaseCommand_AddFiles::postCommitHook()
DatabaseCommand_CollectionStats* cmd = new DatabaseCommand_CollectionStats( source() );
connect( cmd, SIGNAL( done( const QVariantMap& ) ),
source().data(), SLOT( setStats( const QVariantMap& ) ), Qt::QueuedConnection );
APP->database()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
if( source()->isLocal() )
APP->servent().triggerDBSync();
Servent::instance()->triggerDBSync();
}

View File

@@ -5,9 +5,11 @@
#include <QVariantMap>
#include "database/databasecommandloggable.h"
#include "tomahawk/typedefs.h"
#include "typedefs.h"
class DatabaseCommand_AddFiles : public DatabaseCommandLoggable
#include "dllmacro.h"
class DLLEXPORT DatabaseCommand_AddFiles : public DatabaseCommandLoggable
{
Q_OBJECT
Q_PROPERTY( QVariantList files READ files WRITE setFiles )

View File

@@ -6,7 +6,9 @@
#include "databasecommand.h"
class DatabaseCommand_addSource : public DatabaseCommand
#include "dllmacro.h"
class DLLEXPORT DatabaseCommand_addSource : public DatabaseCommand
{
Q_OBJECT

View File

@@ -5,11 +5,13 @@
#include <QVariantMap>
#include "databasecommand.h"
#include "tomahawk/album.h"
#include "tomahawk/collection.h"
#include "tomahawk/typedefs.h"
#include "album.h"
#include "collection.h"
#include "typedefs.h"
class DatabaseCommand_AllAlbums : public DatabaseCommand
#include "dllmacro.h"
class DLLEXPORT DatabaseCommand_AllAlbums : public DatabaseCommand
{
Q_OBJECT
public:

View File

@@ -5,11 +5,13 @@
#include <QVariantMap>
#include "databasecommand.h"
#include "tomahawk/album.h"
#include "tomahawk/collection.h"
#include "tomahawk/typedefs.h"
#include "album.h"
#include "collection.h"
#include "typedefs.h"
class DatabaseCommand_AllTracks : public DatabaseCommand
#include "dllmacro.h"
class DLLEXPORT DatabaseCommand_AllTracks : public DatabaseCommand
{
Q_OBJECT
public:

View File

@@ -4,10 +4,12 @@
#include <QVariantMap>
#include "databasecommand.h"
#include "tomahawk/source.h"
#include "tomahawk/typedefs.h"
#include "source.h"
#include "typedefs.h"
class DatabaseCommand_CollectionStats : public DatabaseCommand
#include "dllmacro.h"
class DLLEXPORT DatabaseCommand_CollectionStats : public DatabaseCommand
{
Q_OBJECT

View File

@@ -2,7 +2,7 @@
#include <QSqlQuery>
#include "tomahawk/tomahawkapp.h"
#include "network/servent.h"
using namespace Tomahawk;
@@ -60,5 +60,5 @@ DatabaseCommand_CreatePlaylist::postCommitHook()
m_playlist->reportCreated( m_playlist );
if( source()->isLocal() )
APP->servent().triggerDBSync();
Servent::instance()->triggerDBSync();
}

View File

@@ -3,10 +3,12 @@
#include "databaseimpl.h"
#include "databasecommandloggable.h"
#include "tomahawk/playlist.h"
#include "tomahawk/typedefs.h"
#include "playlist.h"
#include "typedefs.h"
class DatabaseCommand_CreatePlaylist : public DatabaseCommandLoggable
#include "dllmacro.h"
class DLLEXPORT DatabaseCommand_CreatePlaylist : public DatabaseCommandLoggable
{
Q_OBJECT
Q_PROPERTY( QVariant playlist READ playlistV WRITE setPlaylistV )

View File

@@ -2,7 +2,7 @@
#include <QSqlQuery>
#include "tomahawk/tomahawkapp.h"
#include "network/servent.h"
using namespace Tomahawk;
@@ -41,5 +41,5 @@ DatabaseCommand_DeletePlaylist::postCommitHook()
playlist->reportDeleted( playlist );
if( source()->isLocal() )
APP->servent().triggerDBSync();
Servent::instance()->triggerDBSync();
}

View File

@@ -3,10 +3,12 @@
#include "databaseimpl.h"
#include "databasecommandloggable.h"
#include "tomahawk/source.h"
#include "tomahawk/typedefs.h"
#include "source.h"
#include "typedefs.h"
class DatabaseCommand_DeletePlaylist : public DatabaseCommandLoggable
#include "dllmacro.h"
class DLLEXPORT DatabaseCommand_DeletePlaylist : public DatabaseCommandLoggable
{
Q_OBJECT
Q_PROPERTY( QString playlistguid READ playlistguid WRITE setPlaylistguid )

View File

@@ -7,9 +7,11 @@
#include "databasecommand.h"
#include "dllmacro.h"
// Not loggable, mtimes only used to speed up our local scanner.
class DatabaseCommand_DirMtimes : public DatabaseCommand
class DLLEXPORT DatabaseCommand_DirMtimes : public DatabaseCommand
{
Q_OBJECT

View File

@@ -1,13 +1,17 @@
#ifndef DATABASECOMMAND_IMPORTPLAYLIST_H
#define DATABASECOMMAND_IMPORTPLAYLIST_H
#include <QObject>
#include <QVariantMap>
#include "databasecommand.h"
#include "tomahawk/source.h"
#include "dllmacro.h"
class Playlist;
class DatabaseCommand_ImportPlaylist : public DatabaseCommand
class DLLEXPORT DatabaseCommand_ImportPlaylist : public DatabaseCommand
{
Q_OBJECT
public:

View File

@@ -2,7 +2,7 @@
#include <QSqlQuery>
#include "tomahawk/playlist.h"
#include "playlist.h"
#include "databaseimpl.h"
using namespace Tomahawk;

View File

@@ -5,9 +5,11 @@
#include <QVariantMap>
#include "databasecommand.h"
#include "tomahawk/typedefs.h"
#include "typedefs.h"
class DatabaseCommand_LoadAllPlaylists : public DatabaseCommand
#include "dllmacro.h"
class DLLEXPORT DatabaseCommand_LoadAllPlaylists : public DatabaseCommand
{
Q_OBJECT

View File

@@ -1,7 +1,7 @@
#include "databasecommand_loadfile.h"
#include "databaseimpl.h"
#include "tomahawk/collection.h"
#include "collection.h"
DatabaseCommand_LoadFile::DatabaseCommand_LoadFile( const QString& id, QObject* parent )

View File

@@ -7,7 +7,9 @@
#include "databasecommand.h"
class DatabaseCommand_LoadFile : public DatabaseCommand
#include "dllmacro.h"
class DLLEXPORT DatabaseCommand_LoadFile : public DatabaseCommand
{
Q_OBJECT

View File

@@ -1,12 +1,14 @@
#ifndef DATABASECOMMAND_LOADOPS_H
#define DATABASECOMMAND_LOADOPS_H
#include "tomahawk/typedefs.h"
#include "typedefs.h"
#include "databasecommand.h"
#include "databaseimpl.h"
#include "op.h"
class DatabaseCommand_loadOps : public DatabaseCommand
#include "dllmacro.h"
class DLLEXPORT DatabaseCommand_loadOps : public DatabaseCommand
{
Q_OBJECT
public:

View File

@@ -5,9 +5,11 @@
#include <QVariantMap>
#include "databasecommand.h"
#include "tomahawk/playlist.h"
#include "playlist.h"
class DatabaseCommand_LoadPlaylistEntries : public DatabaseCommand
#include "dllmacro.h"
class DLLEXPORT DatabaseCommand_LoadPlaylistEntries : public DatabaseCommand
{
Q_OBJECT

View File

@@ -5,10 +5,12 @@
#include <QVariantMap>
#include "databasecommand.h"
#include "tomahawk/source.h"
#include "tomahawk/playlist.h"
#include "source.h"
#include "playlist.h"
class DatabaseCommand_ModifyPlaylist : public DatabaseCommand
#include "dllmacro.h"
class DLLEXPORT DatabaseCommand_ModifyPlaylist : public DatabaseCommand
{
Q_OBJECT
Q_PROPERTY( int mode READ mode WRITE setMode )

View File

@@ -2,7 +2,7 @@
#include <QSqlQuery>
#include "tomahawk/tomahawkapp.h"
#include "network/servent.h"
using namespace Tomahawk;
@@ -44,5 +44,5 @@ DatabaseCommand_RenamePlaylist::postCommitHook()
playlist->setTitle( m_playlistTitle );
if( source()->isLocal() )
APP->servent().triggerDBSync();
Servent::instance()->triggerDBSync();
}

View File

@@ -3,10 +3,12 @@
#include "databaseimpl.h"
#include "databasecommandloggable.h"
#include "tomahawk/source.h"
#include "tomahawk/typedefs.h"
#include "source.h"
#include "typedefs.h"
class DatabaseCommand_RenamePlaylist : public DatabaseCommandLoggable
#include "dllmacro.h"
class DLLEXPORT DatabaseCommand_RenamePlaylist : public DatabaseCommandLoggable
{
Q_OBJECT
Q_PROPERTY( QString playlistguid READ playlistguid WRITE setPlaylistguid )

View File

@@ -1,7 +1,7 @@
#include "databasecommand_resolve.h"
#include "tomahawk/tomahawkapp.h"
#include "tomahawk/album.h"
#include "album.h"
#include "sourcelist.h"
#define MINSCORE 0.5
@@ -114,13 +114,13 @@ DatabaseCommand_Resolve::exec( DatabaseImpl* lib )
const QString url_str = files_query.value( 0 ).toString();
if( m_searchlocal )
{
coll = APP->sourcelist().getLocal()->collection();
coll = SourceList::instance()->getLocal()->collection();
m["url"] = url_str;
m["source"] = "Local Database"; // TODO
}
else
{
source_ptr s = APP->sourcelist().get( files_query.value( 13 ).toUInt() );
source_ptr s = SourceList::instance()->get( files_query.value( 13 ).toUInt() );
if( s.isNull() )
{
//qDebug() << "Skipping result for offline sourceid:" << files_query.value(13).toUInt();

View File

@@ -3,11 +3,13 @@
#include "databasecommand.h"
#include "databaseimpl.h"
#include "tomahawk/result.h"
#include "result.h"
#include <QVariant>
class DatabaseCommand_Resolve : public DatabaseCommand
#include "dllmacro.h"
class DLLEXPORT DatabaseCommand_Resolve : public DatabaseCommand
{
Q_OBJECT
public:

View File

@@ -3,7 +3,7 @@
#include <QSqlQuery>
#include "tomahawksqlquery.h"
#include "tomahawk/tomahawkapp.h"
#include "network/servent.h"
DatabaseCommand_SetPlaylistRevision::DatabaseCommand_SetPlaylistRevision(
@@ -56,7 +56,7 @@ DatabaseCommand_SetPlaylistRevision::postCommitHook()
m_applied );
if( source()->isLocal() )
APP->servent().triggerDBSync();
Servent::instance()->triggerDBSync();
}

View File

@@ -3,12 +3,14 @@
#include "databasecommandloggable.h"
#include "databaseimpl.h"
#include "tomahawk/collection.h"
#include "tomahawk/playlist.h"
#include "collection.h"
#include "playlist.h"
#include "dllmacro.h"
using namespace Tomahawk;
class DatabaseCommand_SetPlaylistRevision : public DatabaseCommandLoggable
class DLLEXPORT DatabaseCommand_SetPlaylistRevision : public DatabaseCommandLoggable
{
Q_OBJECT
Q_PROPERTY( QString playlistguid READ playlistguid WRITE setPlaylistguid )

View File

@@ -4,7 +4,9 @@
#include "databasecommand.h"
#include "databaseimpl.h"
class DatabaseCommand_SourceOffline : public DatabaseCommand
#include "dllmacro.h"
class DLLEXPORT DatabaseCommand_SourceOffline : public DatabaseCommand
{
Q_OBJECT

View File

@@ -4,7 +4,9 @@
#include "databasecommand.h"
#include "databaseimpl.h"
class DatabaseCommand_UpdateSearchIndex : public DatabaseCommand
#include "dllmacro.h"
class DLLEXPORT DatabaseCommand_UpdateSearchIndex : public DatabaseCommand
{
Q_OBJECT
public:

View File

@@ -3,9 +3,11 @@
#include "database/databasecommand.h"
#include "dllmacro.h"
/// A Database Command that will be added to the oplog and sent over the network
/// so peers can sync up and changes to our collection in their cached copy.
class DatabaseCommandLoggable : public DatabaseCommand
class DLLEXPORT DatabaseCommandLoggable : public DatabaseCommand
{
Q_OBJECT
Q_PROPERTY(QString command READ commandname)

View File

@@ -1,11 +1,12 @@
#include "databaseimpl.h"
#include <QCoreApplication>
#include <QRegExp>
#include <QStringList>
#include <QtAlgorithms>
#include <QFile>
#include "database.h"
#include "tomahawk/tomahawkapp.h"
#include "database/database.h"
#include "databasecommand_updatesearchindex.h"
/* !!!! You need to manually generate schema.sql.h when the schema changes:
@@ -69,7 +70,7 @@ DatabaseImpl::DatabaseImpl( const QString& dbname, Database* parent )
else
{
Q_ASSERT(0);
QTimer::singleShot( 0, APP, SLOT( quit() ) );
QTimer::singleShot( 0, qApp, SLOT( quit() ) );
return;
}
}
@@ -102,7 +103,7 @@ DatabaseImpl::DatabaseImpl( const QString& dbname, Database* parent )
DatabaseImpl::~DatabaseImpl()
{
m_indexThread.quit();
m_indexThread.wait(5000);
m_indexThread.wait( 5000 );
}
@@ -121,7 +122,7 @@ void
DatabaseImpl::updateSearchIndex( const QString& table, int pkey )
{
DatabaseCommand* cmd = new DatabaseCommand_UpdateSearchIndex(table, pkey);
APP->database()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}

View File

@@ -1,7 +1,7 @@
#include "databaseresolver.h"
#include "tomahawk/tomahawkapp.h"
#include "database.h"
#include "network/servent.h"
#include "database/database.h"
#include "database/databasecommand_resolve.h"
DatabaseResolver::DatabaseResolver( bool searchlocal, int weight )
@@ -19,7 +19,7 @@ DatabaseResolver::resolve( const QVariant& v )
if( !m_searchlocal )
{
if( APP->servent().numConnectedPeers() == 0 )
if( Servent::instance()->numConnectedPeers() == 0 )
return;
}
@@ -28,7 +28,7 @@ DatabaseResolver::resolve( const QVariant& v )
connect( cmd, SIGNAL( results( Tomahawk::QID, QList< Tomahawk::result_ptr> ) ),
SLOT( gotResults( Tomahawk::QID, QList< Tomahawk::result_ptr> ) ), Qt::QueuedConnection );
APP->database()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}
@@ -38,7 +38,7 @@ DatabaseResolver::gotResults( const Tomahawk::QID qid, QList< Tomahawk::result_p
{
// qDebug() << Q_FUNC_INFO << qid << results.length();
APP->pipeline()->reportResults( qid, results );
Tomahawk::Pipeline::instance()->reportResults( qid, results );
}

View File

@@ -1,10 +1,14 @@
#ifndef DATABASERESOLVER_H
#define DATABASERESOLVER_H
#include "tomahawk/resolver.h"
#include "tomahawk/result.h"
#include "pipeline.h"
class DatabaseResolver : public Tomahawk::Resolver
#include "resolver.h"
#include "result.h"
#include "dllmacro.h"
class DLLEXPORT DatabaseResolver : public Tomahawk::Resolver
{
Q_OBJECT

View File

@@ -4,8 +4,7 @@
#include <QTime>
#include <QSqlQuery>
#include "tomahawk/tomahawkapp.h"
#include "database.h"
#include "database/database.h"
#include "database/databasecommandloggable.h"

View File

@@ -0,0 +1,14 @@
#ifndef DLLMACRO_H
#define DLLMACRO_H
#ifdef WIN32
#ifdef DLLEXPORT_PRO
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif
#else
#define DLLEXPORT
#endif
#endif

View File

@@ -0,0 +1,51 @@
#ifndef FUNCTIMEOUT_H
#define FUNCTIMEOUT_H
#include <QObject>
#include <QTimer>
#include <QDebug>
#include "boost/function.hpp"
#include "boost/bind.hpp"
/*
I want to do:
QTimer::singleShot(1000, this, SLOT(doSomething(x)));
instead, I'm doing:
new FuncTimeout(1000, boost::bind(&MyClass::doSomething, this, x));
*/
namespace Tomahawk
{
class FuncTimeout : public QObject
{
Q_OBJECT
public:
FuncTimeout( int ms, boost::function<void()> func )
: m_func( func )
{
//qDebug() << Q_FUNC_INFO;
QTimer::singleShot( ms, this, SLOT(exec() ) );
};
~FuncTimeout()
{
//qDebug() << Q_FUNC_INFO;
};
public slots:
void exec()
{
m_func();
this->deleteLater();
};
private:
boost::function<void()> m_func;
};
}; // ns
#endif // FUNCTIMEOUT_H

View File

@@ -3,7 +3,7 @@
#include <QTime>
#include <QThread>
#include "servent.h"
#include "network/servent.h"
#define PROTOVER "3" // must match remote peer, or we can't talk.

View File

@@ -21,9 +21,11 @@
#include "msg.h"
#include "msgprocessor.h"
#include "dllmacro.h"
class Servent;
class Connection : public QObject
class DLLEXPORT Connection : public QObject
{
Q_OBJECT

View File

@@ -1,11 +1,11 @@
#include "controlconnection.h"
#include "tomahawk/tomahawkapp.h"
#include "remotecollection.h"
#include "filetransferconnection.h"
#include "database.h"
#include "databasecommand_collectionstats.h"
#include "database/database.h"
#include "database/databasecommand_collectionstats.h"
#include "dbsyncconnection.h"
#include "sourcelist.h"
#define TCP_TIMEOUT 600
@@ -96,7 +96,7 @@ ControlConnection::registerSource()
collection_ptr coll( new RemoteCollection( m_source ) );
m_source->addCollection( coll );
TomahawkApp::instance()->sourcelist().add( m_source );
SourceList::instance()->add( m_source );
m_registered = true;
setupDbSyncConnection();

View File

@@ -9,13 +9,15 @@
#define CONTROLCONNECTION_H
#include "connection.h"
#include "servent.h"
#include "tomahawk/source.h"
#include "tomahawk/typedefs.h"
#include "network/servent.h"
#include "source.h"
#include "typedefs.h"
#include "dllmacro.h"
class FileTransferSession;
class ControlConnection : public Connection
class DLLEXPORT ControlConnection : public Connection
{
Q_OBJECT

View File

@@ -14,14 +14,14 @@
#include <QDebug>
#include "tomahawk/tomahawkapp.h"
#include "tomahawk/source.h"
#include "source.h"
#include "database.h"
#include "databasecommand.h"
#include "databasecommand_collectionstats.h"
#include "databasecommand_loadops.h"
#include "database/database.h"
#include "database/databasecommand.h"
#include "database/databasecommand_collectionstats.h"
#include "database/databasecommand_loadops.h"
#include "remotecollection.h"
#include "sourcelist.h"
// close the dbsync connection after this much inactivity.
// it's automatically reestablished as needed.
@@ -120,7 +120,7 @@ DBSyncConnection::check()
// load last-modified etc data for our collection and theirs from our DB:
DatabaseCommand_CollectionStats * cmd_us =
new DatabaseCommand_CollectionStats( APP->sourcelist().getLocal() );
new DatabaseCommand_CollectionStats( SourceList::instance()->getLocal() );
DatabaseCommand_CollectionStats * cmd_them =
new DatabaseCommand_CollectionStats( m_source );
@@ -132,9 +132,8 @@ DBSyncConnection::check()
this, SLOT( gotThemCache(const QVariantMap&) ) );
APP->database()->enqueue( QSharedPointer<DatabaseCommand>(cmd_us) );
APP->database()->enqueue( QSharedPointer<DatabaseCommand>(cmd_them) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd_us) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd_them) );
// restarts idle countdown
m_timer.start();
@@ -178,13 +177,13 @@ DBSyncConnection::handleMsg( msg_ptr msg )
msg->payload() == "ok" )
{
qDebug() << "No ops to apply, we are synced.";
changeState(SYNCED);
changeState( SYNCED );
// calc the collection stats, to updates the "X tracks" in the sidebar etc
// this is done automatically if you run a dbcmd to add files.
DatabaseCommand_CollectionStats * cmd = new DatabaseCommand_CollectionStats( m_source );
DatabaseCommand_CollectionStats* cmd = new DatabaseCommand_CollectionStats( m_source );
connect( cmd, SIGNAL( done( const QVariantMap & ) ),
m_source.data(), SLOT( setStats( const QVariantMap& ) ), Qt::QueuedConnection );
APP->database()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
return;
}
@@ -218,7 +217,7 @@ DBSyncConnection::handleMsg( msg_ptr msg )
changeState( SAVING ); // just DB work left to complete
connect( cmd, SIGNAL( finished() ), this, SLOT( lastOpApplied() ) );
}
APP->database()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
return;
}
@@ -261,13 +260,13 @@ DBSyncConnection::sendOps()
qDebug() << "Will send peer all ops since" << sinceguid;
source_ptr src = APP->sourcelist().getLocal();
source_ptr src = SourceList::instance()->getLocal();
DatabaseCommand_loadOps * cmd = new DatabaseCommand_loadOps( src, sinceguid );
DatabaseCommand_loadOps* cmd = new DatabaseCommand_loadOps( src, sinceguid );
connect( cmd, SIGNAL( done( QString, QList< dbop_ptr > ) ),
this, SLOT( sendOpsData( QString, QList< dbop_ptr > ) ) );
APP->database()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}

View File

@@ -6,9 +6,9 @@
#include <QSharedPointer>
#include <QIODevice>
#include "connection.h"
#include "network/connection.h"
#include "database/op.h"
#include "tomahawk/typedefs.h"
#include "typedefs.h"
class DBSyncConnection : public Connection
{

View File

@@ -2,13 +2,13 @@
#include <QFile>
#include "tomahawk/tomahawkapp.h"
#include "tomahawk/result.h"
#include "result.h"
#include "bufferiodevice.h"
#include "controlconnection.h"
#include "databasecommand_loadfile.h"
#include "database.h"
#include "network/controlconnection.h"
#include "database/databasecommand_loadfile.h"
#include "database/database.h"
#include "sourcelist.h"
// Msgs are framed, this is the size each msg we send containing audio data:
#define BLOCKSIZE 4096
@@ -33,7 +33,7 @@ FileTransferConnection::FileTransferConnection( Servent* s, ControlConnection* c
m_iodev = QSharedPointer<QIODevice>( bio ); // device audio data gets written to
m_iodev->open( QIODevice::ReadWrite );
APP->servent().registerFileTransferConnection( this );
Servent::instance()->registerFileTransferConnection( this );
// if the audioengine closes the iodev (skip/stop/etc) then kill the connection
// immediately to avoid unnecessary network transfer
@@ -58,7 +58,7 @@ FileTransferConnection::FileTransferConnection( Servent* s, ControlConnection* c
, m_allok( false )
, m_transferRate( 0 )
{
APP->servent().registerFileTransferConnection( this );
Servent::instance()->registerFileTransferConnection( this );
// auto delete when connection closes:
connect( this, SIGNAL( finished() ), SLOT( deleteLater() ), Qt::QueuedConnection );
}
@@ -78,7 +78,7 @@ FileTransferConnection::~FileTransferConnection()
((BufferIODevice*)m_iodev.data())->inputComplete();
}
APP->servent().onFileTransferFinished( this );
Servent::instance()->onFileTransferFinished( this );
}
@@ -109,7 +109,7 @@ FileTransferConnection::showStats( qint64 tx, qint64 rx )
void
FileTransferConnection::setup()
{
QList<source_ptr> sources = APP->sourcelist().sources();
QList<source_ptr> sources = SourceList::instance()->sources();
foreach( const source_ptr& src, sources )
{
// local src doesnt have a control connection, skip it:
@@ -135,7 +135,7 @@ FileTransferConnection::setup()
DatabaseCommand_LoadFile* cmd = new DatabaseCommand_LoadFile( m_fid );
connect( cmd, SIGNAL( result( Tomahawk::result_ptr ) ), SLOT( startSending( Tomahawk::result_ptr ) ) );
TomahawkApp::instance()->database()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}
@@ -152,7 +152,7 @@ FileTransferConnection::startSending( const Tomahawk::result_ptr& result )
m_result = result;
qDebug() << "Starting to transmit" << m_result->url();
QSharedPointer<QIODevice> io = TomahawkApp::instance()->getIODeviceForUrl( m_result );
QSharedPointer<QIODevice> io = Servent::instance()->getIODeviceForUrl( m_result );
if( !io )
{
qDebug() << "Couldn't read from source:" << m_result->url();

View File

@@ -5,8 +5,8 @@
#include <QSharedPointer>
#include <QIODevice>
#include "connection.h"
#include "tomahawk/result.h"
#include "network/connection.h"
#include "result.h"
class ControlConnection;
class BufferIODevice;

View File

@@ -1,14 +1,17 @@
#include "msgprocessor.h"
#include "tomahawk/tomahawkapp.h"
#include "network/servent.h"
MsgProcessor::MsgProcessor( quint32 mode, quint32 t ) :
QObject(), m_mode( mode ), m_threshold( t ), m_totmsgsize( 0 )
{
moveToThread( APP->servent().thread() );
moveToThread( Servent::instance()->thread() );
}
void MsgProcessor::append( msg_ptr msg )
void
MsgProcessor::append( msg_ptr msg )
{
if( QThread::currentThread() != thread() )
{
@@ -39,7 +42,8 @@ void MsgProcessor::append( msg_ptr msg )
}
void MsgProcessor::processed()
void
MsgProcessor::processed()
{
QFutureWatcher<msg_ptr> * watcher = (QFutureWatcher<msg_ptr> *) sender();
msg_ptr msg = watcher->result();
@@ -47,7 +51,9 @@ void MsgProcessor::processed()
handleProcessedMsg( msg );
}
void MsgProcessor::handleProcessedMsg( msg_ptr msg )
void
MsgProcessor::handleProcessedMsg( msg_ptr msg )
{
Q_ASSERT( QThread::currentThread() == thread() );
@@ -74,7 +80,8 @@ void MsgProcessor::handleProcessedMsg( msg_ptr msg )
/// This method is run by QtConcurrent:
msg_ptr MsgProcessor::process( msg_ptr msg, quint32 mode, quint32 threshold )
msg_ptr
MsgProcessor::process( msg_ptr msg, quint32 mode, quint32 threshold )
{
// uncompress if needed
if( (mode & UNCOMPRESS_ALL) && msg->is( Msg::COMPRESSED ) )
@@ -109,5 +116,3 @@ msg_ptr MsgProcessor::process( msg_ptr msg, quint32 mode, quint32 threshold )
}
return msg;
}

View File

@@ -1,10 +1,10 @@
#ifndef REMOTECOLLECTION_H
#define REMOTECOLLECTION_H
#include "tomahawk/typedefs.h"
#include "typedefs.h"
#include "controlconnection.h"
#include "databasecollection.h"
#include "network/controlconnection.h"
#include "database/databasecollection.h"
class RemoteCollection : public DatabaseCollection
{

View File

@@ -1,27 +1,64 @@
#include "servent.h"
#include <QCoreApplication>
#include <QMutexLocker>
#include <QNetworkInterface>
#include <QFile>
#include <QTime>
#include <QThread>
#include <QNetworkRequest>
#include <QNetworkReply>
#include "tomahawk/tomahawkapp.h"
#include "tomahawk/result.h"
#include "tomahawk/source.h"
#include "result.h"
#include "source.h"
#include "bufferiodevice.h"
#include "connection.h"
#include "controlconnection.h"
#include "database/database.h"
#include "filetransferconnection.h"
#include "sourcelist.h"
#include "portfwd/portfwd.h"
using namespace Tomahawk;
Servent* Servent::s_instance = 0;
Servent*
Servent::instance()
{
return s_instance;
}
Servent::Servent( QObject* parent )
: QTcpServer( parent )
, m_port( 0 )
, m_externalPort( 0 )
, pf( new Portfwd() )
{
s_instance = this;
qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) );
{
boost::function<QSharedPointer<QIODevice>(result_ptr)> fac =
boost::bind( &Servent::localFileIODeviceFactory, this, _1 );
this->registerIODeviceFactory( "file", fac );
}
{
boost::function<QSharedPointer<QIODevice>(result_ptr)> fac =
boost::bind( &Servent::remoteIODeviceFactory, this, _1 );
this->registerIODeviceFactory( "servent", fac );
}
{
boost::function<QSharedPointer<QIODevice>(result_ptr)> fac =
boost::bind( &Servent::httpIODeviceFactory, this, _1 );
this->registerIODeviceFactory( "http", fac );
}
}
@@ -30,7 +67,7 @@ Servent::~Servent()
if( m_externalPort )
{
qDebug() << "Unregistering port fwd";
pf.remove( m_externalPort );
pf->remove( m_externalPort );
}
}
@@ -56,30 +93,30 @@ Servent::startListening( QHostAddress ha, bool upnp, int port )
if( upnp )
{
// try and pick an available port:
if( pf.init( 2000 ) )
if( pf->init( 2000 ) )
{
int tryport = m_port;
// last.fm office firewall policy hack
// (corp. firewall allows outgoing connections to this port,
// so listen on this if you want lastfmers to connect to you)
if( APP->arguments().contains("--porthack") )
if( qApp->arguments().contains("--porthack") )
{
tryport = 3389;
pf.remove( tryport );
pf->remove( tryport );
}
for( int r=0; r<5; ++r )
{
qDebug() << "Trying to setup portfwd on" << tryport;
if( pf.add( tryport, m_port ) )
if( pf->add( tryport, m_port ) )
{
QString pubip = QString( pf.external_ip().c_str() );
QString pubip = QString( pf->external_ip().c_str() );
m_externalAddress = QHostAddress( pubip );
m_externalPort = tryport;
qDebug() << "External servent address detected as" << pubip << ":" << m_externalPort;
qDebug() << "Max upstream " << pf.max_upstream_bps() << "bps";
qDebug() << "Max downstream" << pf.max_downstream_bps() << "bps";
qDebug() << "Max upstream " << pf->max_upstream_bps() << "bps";
qDebug() << "Max downstream" << pf->max_downstream_bps() << "bps";
break;
}
tryport = 10000 + 50000 * (float)qrand()/RAND_MAX;
@@ -98,7 +135,7 @@ Servent::startListening( QHostAddress ha, bool upnp, int port )
}
// --lanhack means to advertise your LAN IP over jabber as if it were externallyVisible
if( TomahawkApp::instance()->arguments().contains( "--lanhack" ) )
if( qApp->arguments().contains( "--lanhack" ) )
{
QList<QHostAddress> ifs = QNetworkInterface::allAddresses();
foreach( QHostAddress ha, ifs )
@@ -327,7 +364,7 @@ Servent::createParallelConnection( Connection* orig_conn, Connection* new_conn,
m.insert( "key", tmpkey );
m.insert( "offer", key );
m.insert( "port", externalPort() );
m.insert( "controlid", APP->nodeID() );
m.insert( "controlid", Database::instance()->dbid() );
QJson::Serializer ser;
orig_conn->sendMsg( Msg::factory( ser.serialize(m), Msg::JSON ) );
@@ -404,7 +441,7 @@ Servent::connectToPeer( const QString& ha, int port, const QString &key, const Q
m["conntype"] = "accept-offer";
m["key"] = key;
m["port"] = externalPort();
m["nodeid"] = APP->nodeID();
m["nodeid"] = Database::instance()->dbid();
conn->setFirstMessage( m );
if( name.length() )
@@ -432,7 +469,7 @@ Servent::connectToPeer( const QString& ha, int port, const QString &key, Connect
m["conntype"] = "accept-offer";
m["key"] = key;
m["port"] = externalPort();
m["controlid"] = APP->nodeID();
m["controlid"] = Database::instance()->dbid();
conn->setFirstMessage( m );
}
@@ -471,7 +508,7 @@ Servent::reverseOfferRequest( ControlConnection* orig_conn, const QString& key,
m["conntype"] = "push-offer";
m["key"] = theirkey;
m["port"] = externalPort();
m["controlid"] = APP->nodeID();
m["controlid"] = Database::instance()->dbid();
new_conn->setFirstMessage( m );
createParallelConnection( orig_conn, new_conn, QString() );
}
@@ -572,7 +609,7 @@ Servent::remoteIODeviceFactory( const result_ptr& result )
QStringList parts = result->url().mid( QString( "servent://" ).length()).split( "\t" );
const QString& sourceName = parts.at( 0 );
const QString& fileId = parts.at( 1 );
const source_ptr& s = TomahawkApp::instance()->sourcelist().get( sourceName );
const source_ptr& s = SourceList::instance()->get( sourceName );
if ( s.isNull() )
return sp;
@@ -668,7 +705,7 @@ Servent::triggerDBSync()
qDebug() << Q_FUNC_INFO;
// tell peers we have new stuff they should sync
QList<source_ptr> sources = APP->sourcelist().sources();
QList<source_ptr> sources = SourceList::instance()->sources();
foreach( const source_ptr& src, sources )
{
// local src doesnt have a control connection, skip it:
@@ -678,3 +715,53 @@ Servent::triggerDBSync()
src->controlConnection()->dbSyncConnection()->trigger();
}
}
void
Servent::registerIODeviceFactory( const QString &proto, boost::function<QSharedPointer<QIODevice>(Tomahawk::result_ptr)> fac )
{
m_iofactories.insert( proto, fac );
qDebug() << "Registered IODevice Factory for" << proto;
}
QSharedPointer<QIODevice>
Servent::getIODeviceForUrl( const Tomahawk::result_ptr& result )
{
qDebug() << Q_FUNC_INFO << thread();
QSharedPointer<QIODevice> sp;
QRegExp rx( "^([a-zA-Z0-9]+)://(.+)$" );
if ( rx.indexIn( result->url() ) == -1 )
return sp;
const QString proto = rx.cap( 1 );
//const QString urlpart = rx.cap( 2 );
if ( !m_iofactories.contains( proto ) )
return sp;
return m_iofactories.value( proto )( result );
}
QSharedPointer<QIODevice>
Servent::localFileIODeviceFactory( const Tomahawk::result_ptr& result )
{
// ignore "file://" at front of url
QFile * io = new QFile( result->url().mid( QString( "file://" ).length() ) );
if ( io )
io->open( QIODevice::ReadOnly );
return QSharedPointer<QIODevice>( io );
}
QSharedPointer<QIODevice>
Servent::httpIODeviceFactory( const Tomahawk::result_ptr& result )
{
/* qDebug() << Q_FUNC_INFO << result->url();
QNetworkRequest req( result->url() );
QNetworkReply* reply = APP->nam()->get( req );
return QSharedPointer<QIODevice>( reply );*/
}

View File

@@ -20,20 +20,24 @@
#include <qjson/serializer.h>
#include <qjson/qobjecthelper.h>
#include "portfwd/portfwd.h"
#include "tomahawk/typedefs.h"
#include "typedefs.h"
#include "msg.h"
#include <boost/function.hpp>
#include "dllmacro.h"
class Connection;
class Connector;
class ControlConnection;
class FileTransferConnection;
class ProxyConnection;
class RemoteCollectionConnection;
class Portfwd;
// this is used to hold a bit of state, so when a connected signal is emitted
// from a socket, we can associate it with a Connection object etc.
class QTcpSocketExtra : public QTcpSocket
class DLLEXPORT QTcpSocketExtra : public QTcpSocket
{
Q_OBJECT
@@ -59,11 +63,13 @@ private slots:
}
};
class Servent : public QTcpServer
class DLLEXPORT Servent : public QTcpServer
{
Q_OBJECT
public:
static Servent* instance();
explicit Servent( QObject* parent = 0 );
virtual ~Servent();
@@ -97,6 +103,11 @@ public:
QList< FileTransferConnection* > fileTransfers() const { return m_ftsessions; }
QSharedPointer<QIODevice> getIODeviceForUrl( const Tomahawk::result_ptr& result );
void registerIODeviceFactory( const QString &proto, boost::function<QSharedPointer<QIODevice>(Tomahawk::result_ptr)> fac );
QSharedPointer<QIODevice> localFileIODeviceFactory( const Tomahawk::result_ptr& result );
QSharedPointer<QIODevice> httpIODeviceFactory( const Tomahawk::result_ptr& result );
signals:
void fileTransferStarted( FileTransferConnection* );
void fileTransferFinished( FileTransferConnection* );
@@ -134,7 +145,10 @@ private:
QList< FileTransferConnection* > m_ftsessions;
QMutex m_ftsession_mut;
Portfwd pf;
Portfwd* pf;
QMap< QString,boost::function<QSharedPointer<QIODevice>(Tomahawk::result_ptr)> > m_iofactories;
static Servent* s_instance;
};
#endif // SERVENT_H

View File

@@ -1,28 +1,36 @@
#include "tomahawk/pipeline.h"
#include "pipeline.h"
#include <QDebug>
#include <QMutexLocker>
#include "tomahawk/functimeout.h"
#include "tomahawk/tomahawkapp.h"
#include "functimeout.h"
#include "database/database.h"
using namespace Tomahawk;
Pipeline* Pipeline::s_instance = 0;
Pipeline*
Pipeline::instance()
{
return s_instance;
}
Pipeline::Pipeline( QObject* parent )
: QObject( parent )
, m_index_ready( false )
{
s_instance = this;
}
void
Pipeline::databaseReady()
{
connect( APP->database(), SIGNAL(indexReady()), this, SLOT(indexReady()), Qt::QueuedConnection );
APP->database()->loadIndex();
connect( Database::instance(), SIGNAL(indexReady()), this, SLOT(indexReady()), Qt::QueuedConnection );
Database::instance()->loadIndex();
}

View File

@@ -0,0 +1,76 @@
#ifndef PIPELINE_H
#define PIPELINE_H
#include <QObject>
#include <QList>
#include <QMap>
#include <QMutex>
#include "typedefs.h"
#include "query.h"
#include "result.h"
#include "resolver.h"
#include "dllmacro.h"
namespace Tomahawk
{
class Resolver;
class DLLEXPORT Pipeline : public QObject
{
Q_OBJECT
public:
static Pipeline* instance();
explicit Pipeline( QObject* parent = 0 );
// const query_ptr& query( QID qid ) const;
// result_ptr result( RID rid ) const;
void reportResults( QID qid, const QList< result_ptr >& results );
/// sorter to rank resolver priority
static bool resolverSorter( const Resolver* left, const Resolver* right );
void addResolver( Resolver* r, bool sort = true );
void removeResolver( Resolver* r );
query_ptr query( const QID& qid ) const
{
return m_qids.value( qid );
}
result_ptr result( const RID& rid ) const
{
return m_rids.value( rid );
}
public slots:
void add( const query_ptr& q );
void add( const QList<query_ptr>& qlist );
void databaseReady();
private slots:
void shunt( const query_ptr& q );
void indexReady();
private:
QList< Resolver* > m_resolvers;
QMap< QID, query_ptr > m_qids;
QMap< RID, result_ptr > m_rids;
QMutex m_mut; // for m_qids, m_rids
// store queries here until DB index is loaded, then shunt them all
QList< query_ptr > m_queries_pending;
bool m_index_ready;
static Pipeline* s_instance;
};
}; //ns
#endif // PIPELINE_H

View File

@@ -1,15 +1,17 @@
#include "tomahawk/playlist.h"
#include "playlist.h"
#include <QDomDocument>
#include <QDomElement>
#include "tomahawk/tomahawkapp.h"
#include "database.h"
#include "databasecommand_loadplaylistentries.h"
#include "databasecommand_setplaylistrevision.h"
#include "databasecommand_createplaylist.h"
#include "databasecommand_deleteplaylist.h"
#include "databasecommand_renameplaylist.h"
#include "database/database.h"
#include "database/databasecommand_loadplaylistentries.h"
#include "database/databasecommand_setplaylistrevision.h"
#include "database/databasecommand_createplaylist.h"
#include "database/databasecommand_deleteplaylist.h"
#include "database/databasecommand_renameplaylist.h"
#include "pipeline.h"
#include "sourcelist.h"
using namespace Tomahawk;
@@ -93,7 +95,7 @@ Playlist::create( const source_ptr& author,
DatabaseCommand_CreatePlaylist* cmd = new DatabaseCommand_CreatePlaylist( author, playlist );
connect( cmd, SIGNAL(finished()), playlist.data(), SIGNAL(created()) );
APP->database()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
playlist->reportCreated( playlist );
return playlist;
}
@@ -103,7 +105,7 @@ bool
Playlist::remove( const playlist_ptr& playlist )
{
DatabaseCommand_DeletePlaylist* cmd = new DatabaseCommand_DeletePlaylist( playlist->author(), playlist->guid() );
APP->database()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
return true; // FIXME
}
@@ -113,7 +115,7 @@ bool
Playlist::rename( const QString& title )
{
DatabaseCommand_RenamePlaylist* cmd = new DatabaseCommand_RenamePlaylist( author(), guid(), title );
APP->database()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
return true; // FIXME
}
@@ -159,7 +161,7 @@ Playlist::loadRevision( const QString& rev )
const QMap< QString, Tomahawk::plentry_ptr >&,
bool ) ) );
APP->database()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}
@@ -185,7 +187,7 @@ Playlist::createNewRevision( const QString& newrev, const QString& oldrev, const
}
// source making the change (localy user in this case)
source_ptr author = APP->sourcelist().getLocal();
source_ptr author = SourceList::instance()->getLocal();
// command writes new rev to DB and calls setRevision, which emits our signal
DatabaseCommand_SetPlaylistRevision* cmd =
new DatabaseCommand_SetPlaylistRevision( author,
@@ -194,7 +196,7 @@ Playlist::createNewRevision( const QString& newrev, const QString& oldrev, const
oldrev,
orderedguids,
added );
APP->database()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}
@@ -321,7 +323,7 @@ void Playlist::resolve()
{
qlist << p->query();
}
APP->pipeline()->add( qlist );
Pipeline::instance()->add( qlist );
}

193
src/libtomahawk/playlist.h Normal file
View File

@@ -0,0 +1,193 @@
#ifndef PLAYLIST_H
#define PLAYLIST_H
#include <QObject>
#include <QList>
#include <QSharedPointer>
#include "query.h"
#include "typedefs.h"
#include "dllmacro.h"
class DatabaseCommand_LoadAllPlaylists;
class DatabaseCommand_SetPlaylistRevision;
class DatabaseCommand_CreatePlaylist;
namespace Tomahawk
{
class DLLEXPORT PlaylistEntry : public QObject
{
Q_OBJECT
Q_PROPERTY( QString guid READ guid WRITE setGuid )
Q_PROPERTY( QString annotation READ annotation WRITE setAnnotation )
Q_PROPERTY( QString resulthint READ resulthint WRITE setResulthint )
Q_PROPERTY( unsigned int duration READ duration WRITE setDuration )
Q_PROPERTY( unsigned int lastmodified READ lastmodified WRITE setLastmodified )
Q_PROPERTY( QVariant query READ queryvariant WRITE setQueryvariant )
public:
void setQuery( const Tomahawk::query_ptr& q ) { m_query = q; }
const Tomahawk::query_ptr& query() const { return m_query; }
// I wish Qt did this for me once i specified the Q_PROPERTIES:
void setQueryvariant( const QVariant& v );
QVariant queryvariant() const;
QString guid() const { return m_guid; }
void setGuid( const QString& s ) { m_guid = s; }
QString annotation() const { return m_annotation; }
void setAnnotation( const QString& s ) { m_annotation = s; }
QString resulthint() const { return m_resulthint; }
void setResulthint( const QString& s ) { m_resulthint= s; }
unsigned int duration() const { return m_duration; }
void setDuration( unsigned int i ) { m_duration = i; }
unsigned int lastmodified() const { return m_lastmodified; }
void setLastmodified( unsigned int i ) { m_lastmodified = i; }
source_ptr lastsource() const { return m_lastsource; }
void setLastsource( source_ptr s ) { m_lastsource = s; }
private:
QString m_guid;
Tomahawk::query_ptr m_query;
QString m_annotation;
unsigned int m_duration;
unsigned int m_lastmodified;
source_ptr m_lastsource;
QString m_resulthint;
};
struct PlaylistRevision
{
QString revisionguid;
QString oldrevisionguid;
QList<plentry_ptr> newlist;
QList<plentry_ptr> added;
QList<plentry_ptr> removed;
bool applied; // false if conflict
};
class DLLEXPORT Playlist : public QObject
{
Q_OBJECT
Q_PROPERTY( QString guid READ guid WRITE setGuid )
Q_PROPERTY( QString currentrevision READ currentrevision WRITE setCurrentrevision )
Q_PROPERTY( QString title READ title WRITE setTitle )
Q_PROPERTY( QString info READ info WRITE setInfo )
Q_PROPERTY( QString creator READ creator WRITE setCreator )
Q_PROPERTY( bool shared READ shared WRITE setShared )
friend class ::DatabaseCommand_LoadAllPlaylists;
friend class ::DatabaseCommand_SetPlaylistRevision;
friend class ::DatabaseCommand_CreatePlaylist;
public:
// one CTOR is private, only called by DatabaseCommand_LoadAllPlaylists
static Tomahawk::playlist_ptr create( const source_ptr& author,
const QString& guid,
const QString& title,
const QString& info,
const QString& creator,
bool shared );
static bool remove( const playlist_ptr& playlist );
bool rename( const QString& title );
virtual void loadRevision( const QString& rev = "" );
const source_ptr& author() { return m_source; }
const QString& currentrevision() { return m_currentrevision; }
const QString& title() { return m_title; }
const QString& info() { return m_info; }
const QString& creator() { return m_creator; }
unsigned int lastmodified() { return m_lastmodified; }
const QString& guid() { return m_guid; }
bool shared() const { return m_shared; }
const QList< plentry_ptr >& entries() { return m_entries; }
void addEntry( const Tomahawk::query_ptr& query, const QString& oldrev );
void addEntries( const QList<Tomahawk::query_ptr>& queries, const QString& oldrev );
// <IGNORE hack="true">
// these need to exist and be public for the json serialization stuff
// you SHOULD NOT call them. They are used for an alternate CTOR method from json.
// maybe friend QObjectHelper and make them private?
Playlist( const source_ptr& author )
: m_source( author )
, m_lastmodified( 0 )
{
qDebug() << Q_FUNC_INFO << "JSON";
}
void setCurrentrevision( const QString& s ) { m_currentrevision = s; }
void setTitle( const QString& s ) { m_title = s; }
void setInfo( const QString& s ) { m_info = s; }
void setCreator( const QString& s ) { m_creator = s; }
void setGuid( const QString& s ) { m_guid = s; }
void setShared( bool b ) { m_shared = b; }
// </IGNORE>
signals:
/// emitted when the playlist revision changes (whenever the playlist changes)
void revisionLoaded( Tomahawk::PlaylistRevision );
/// watch for this to see when newly created playlist is synced to DB (if you care)
void created();
public slots:
// want to update the playlist from the model?
// generate a newrev using uuid() and call this:
void createNewRevision( const QString& newrev, const QString& oldrev, const QList< plentry_ptr >& entries );
void reportCreated( const Tomahawk::playlist_ptr& self );
void reportDeleted( const Tomahawk::playlist_ptr& self );
void setRevision( const QString& rev,
const QList<QString>& neworderedguids,
const QList<QString>& oldorderedguids,
bool is_newest_rev,
const QMap< QString, Tomahawk::plentry_ptr >& addedmap,
bool applied );
void resolve();
private:
// called from loadAllPlaylists DB cmd:
explicit Playlist( const source_ptr& src,
const QString& currentrevision,
const QString& title,
const QString& info,
const QString& creator,
bool shared,
int lastmod,
const QString& guid = "" ); // populate db
// called when creating new playlist
explicit Playlist( const source_ptr& author,
const QString& guid,
const QString& title,
const QString& info,
const QString& creator,
bool shared );
void rundb();
source_ptr m_source;
QString m_currentrevision;
QString m_guid, m_title, m_info, m_creator;
unsigned int m_lastmodified;
bool m_shared;
QList< plentry_ptr > m_entries;
};
};
#endif // PLAYLIST_H

View File

@@ -0,0 +1,51 @@
#ifndef PLAYLISTINTERFACE_H
#define PLAYLISTINTERFACE_H
#include <QModelIndex>
#include <QWidget>
#include "typedefs.h"
#include "dllmacro.h"
class DLLEXPORT PlaylistInterface
{
public:
enum RepeatMode { NoRepeat, RepeatOne, RepeatAll };
PlaylistInterface( QObject* parent ) : m_widget( 0 ), m_object( parent ) {}
virtual ~PlaylistInterface() {}
virtual int unfilteredTrackCount() const = 0;
virtual int trackCount() const = 0;
virtual Tomahawk::result_ptr previousItem() { return siblingItem( -1 ); }
virtual Tomahawk::result_ptr nextItem() { return siblingItem( 1 ); }
virtual Tomahawk::result_ptr siblingItem( int itemsAway ) = 0;
virtual PlaylistInterface::RepeatMode repeatMode() const = 0;
virtual bool shuffled() const = 0;
virtual void setFilter( const QString& pattern ) = 0;
QWidget* widget() const { return m_widget; }
void setWidget( QWidget* widget ) { m_widget = widget; }
QObject* object() const { return m_object; }
public slots:
virtual void setRepeatMode( RepeatMode mode ) = 0;
virtual void setShuffled( bool enabled ) = 0;
signals:
virtual void repeatModeChanged( PlaylistInterface::RepeatMode mode ) = 0;
virtual void shuffleModeChanged( bool enabled ) = 0;
virtual void trackCountChanged( unsigned int tracks ) = 0;
virtual void sourceTrackCountChanged( unsigned int tracks ) = 0;
private:
QWidget* m_widget;
QObject* m_object;
};
#endif // PLAYLISTINTERFACE_H

View File

@@ -1,8 +1,11 @@
#include "tomahawk/pluginapi.h"
#include "tomahawk/tomahawkapp.h"
#include "pluginapi.h"
#include "pipeline.h"
#include "sourcelist.h"
using namespace Tomahawk;
PluginAPI::PluginAPI( Pipeline* p )
: m_pipeline( p )
{
@@ -25,19 +28,19 @@ PluginAPI::reportResults( const QString& qid, const QList<QVariantMap>& vresults
void
PluginAPI::addSource( source_ptr s )
{
TomahawkApp::instance()->sourcelist().add( s );
SourceList::instance()->add( s );
}
void
PluginAPI::removeSource( source_ptr s )
{
TomahawkApp::instance()->sourcelist().remove( s );
SourceList::instance()->remove( s );
}
void
PluginAPI::addResolver( Resolver* r )
{
TomahawkApp::instance()->pipeline()->addResolver( r );
Pipeline::instance()->addResolver( r );
}

Some files were not shown because too many files have changed in this diff Show More