diff --git a/CMakeLists.txt b/CMakeLists.txt index bf7f00762..73079fa95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,5 +25,6 @@ ENDIF( UNIX AND NOT APPLE ) ADD_SUBDIRECTORY( libportfwd ) ADD_SUBDIRECTORY( qxt ) +ADD_SUBDIRECTORY( src/libtomahawk ) ADD_SUBDIRECTORY( src ) diff --git a/README b/README index 12c584092..450847415 100644 --- a/README +++ b/README @@ -49,6 +49,31 @@ Now compile Tomahawk $ make $ ./tomahawk +Quickstart on OS X +------------------ + +# Install homebrew +$ ruby -e "$(curl -fsSL https://gist.github.com/raw/323731/install_homebrew.rb)" +$ brew install qt qjson gloox libmad libvorbis flac taglib boost liblastfm +# Install libEchnoest as per the above instructions + +# If liblastfm gives problems, do the below: +$ brew edit liblastfm +# change url to https://github.com/davidsansome/liblastfm/tarball/0.3.1 +$ brew install liblastfm +# copy the md5 hash it gives +$ brew edit liblastfm +# replace the md5 hash with the new one you copied +$ brew install liblastfm + +# Build Tomahawk +$ git clone git://github.com/tomahawk-player/tomahawk.git +$ cd tomahawk +$ mkdir build && cd build +$ cmake .. +$ make +$ open tomahawk.app + Dependencies ------------ diff --git a/admin/win/revision.txt b/admin/win/revision.txt index 801f18010..8783e3051 100644 --- a/admin/win/revision.txt +++ b/admin/win/revision.txt @@ -1 +1 @@ -47 \ No newline at end of file +53 \ No newline at end of file diff --git a/admin/win/tomahawk.nsi b/admin/win/tomahawk.nsi index 8cd675d9c..3212d7a51 100755 --- a/admin/win/tomahawk.nsi +++ b/admin/win/tomahawk.nsi @@ -253,6 +253,11 @@ Section "Tomahawk Player" SEC_TOMAHAWK_PLAYER ;Main executable. File "${ROOT_PATH}\build\tomahawk.exe" + ;Plugins + File "${ROOT_PATH}\build\src\libtomahawk\libtomahawklib.dll" + File "${ROOT_PATH}\build\libsip_jabber.dll" + File "${ROOT_PATH}\build\libsip_zeroconf.dll" + ;License & release notes. File "${ROOT_PATH}\LICENSE.txt" File /oname=NOTES.txt RELEASE_NOTES.txt diff --git a/data/images/list-remove.png b/data/images/list-remove.png new file mode 100644 index 000000000..5a4d15b7b Binary files /dev/null and b/data/images/list-remove.png differ diff --git a/include/tomahawk/tomahawkapp.h b/include/tomahawk/tomahawkapp.h index 2210f7afe..839022079 100644 --- a/include/tomahawk/tomahawkapp.h +++ b/include/tomahawk/tomahawkapp.h @@ -16,21 +16,15 @@ #include "QxtHttpServerConnector" #include "QxtHttpSessionManager" -#include "tomahawk/functimeout.h" -#include "tomahawk/typedefs.h" #include "tomahawk/tomahawkplugin.h" -#include "tomahawk/playlist.h" -#include "tomahawk/pipeline.h" +#include "typedefs.h" +#include "playlist.h" #include "utils/tomahawkutils.h" -#include "sourcelist.h" -#include "servent.h" - class AudioEngine; class Database; class SipHandler; -class TomahawkZeroconf; class TomahawkSettings; class XMPPBot; @@ -67,17 +61,12 @@ public: static TomahawkApp* instance(); - Tomahawk::Pipeline* pipeline() { return &m_pipeline; } AudioEngine* audioEngine() { return m_audioEngine; } - Database* database() { return m_db; } - SourceList& sourcelist() { return m_sources; } - Servent& servent() { return m_servent; } SipHandler* sipHandler() { return m_sipHandler; } QNetworkAccessManager* nam() { return m_nam; } QNetworkProxy* proxy() { return m_proxy; } Tomahawk::InfoSystem::InfoSystem* infoSystem() { return m_infoSystem; } XMPPBot* xmppBot() { return m_xmppBot; } - const QString& nodeID() const; #ifndef TOMAHAWK_HEADLESS AudioControls* audioControls(); @@ -85,21 +74,9 @@ public: TomahawkWindow* mainWindow() const { return m_mainwindow; } #endif - void registerIODeviceFactory( const QString &proto, boost::function(Tomahawk::result_ptr)> fac ); - QSharedPointer localFileIODeviceFactory( const Tomahawk::result_ptr& result ); - QSharedPointer httpIODeviceFactory( const Tomahawk::result_ptr& result ); - - TomahawkSettings* settings() { return m_settings; } - signals: void settingsChanged(); -public slots: - QSharedPointer getIODeviceForUrl( const Tomahawk::result_ptr& result ); - -private slots: - void lanHostFound( const QString&, int, const QString&, const QString& ); - private: void initLocalCollection(); void loadPlugins(); @@ -113,12 +90,7 @@ private: QList m_collections; QList m_plugins; - Tomahawk::Pipeline m_pipeline; AudioEngine* m_audioEngine; - Database* m_db; - Servent m_servent; - SourceList m_sources; - TomahawkZeroconf* m_zeroconf; SipHandler* m_sipHandler; XMPPBot* m_xmppBot; @@ -130,10 +102,7 @@ private: TomahawkWindow* m_mainwindow; #endif - QMap< QString,boost::function(Tomahawk::result_ptr)> > m_iofactories; - bool m_headless; - TomahawkSettings* m_settings; QNetworkAccessManager* m_nam; QNetworkProxy* m_proxy; diff --git a/include/tomahawk/tomahawkplugin.h b/include/tomahawk/tomahawkplugin.h index f27e2d5ea..9f5f81d0e 100644 --- a/include/tomahawk/tomahawkplugin.h +++ b/include/tomahawk/tomahawkplugin.h @@ -1,9 +1,10 @@ #ifndef TOMAHAWK_PLUGIN_H #define TOMAHAWK_PLUGIN_H + #include #include -#include "tomahawk/pluginapi.h" +#include "pluginapi.h" class TomahawkPlugin { diff --git a/libportfwd/CMakeLists.txt b/libportfwd/CMakeLists.txt index 88ccaf107..ad0799f9f 100644 --- a/libportfwd/CMakeLists.txt +++ b/libportfwd/CMakeLists.txt @@ -38,7 +38,7 @@ ADD_LIBRARY(portfwd STATIC ) IF(WIN32) - TARGET_LINK_LIBRARIES( portfwd "ws2_32.dll" ) + TARGET_LINK_LIBRARIES( portfwd "ws2_32.dll" "iphlpapi.a" ) ENDIF() #ADD_EXECUTABLE(portfwd-demo @@ -46,6 +46,6 @@ ENDIF() # ) #TARGET_LINK_LIBRARIES(portfwd-demo portfwd) -#INSTALL(TARGETS portfwd ARCHIVE DESTINATION lib) +INSTALL(TARGETS portfwd ARCHIVE DESTINATION lib) #INSTALL(TARGETS portfwd-demo RUNTIME DESTINATION bin) #INSTALL(DIRECTORY include/portfwd DESTINATION include PATTERN "*~" EXCLUDE) diff --git a/rtaudio/RtAudio.cpp b/rtaudio/RtAudio.cpp index 69ac86f40..ab158b4af 100644 --- a/rtaudio/RtAudio.cpp +++ b/rtaudio/RtAudio.cpp @@ -558,7 +558,14 @@ RtAudio::DeviceInfo RtApiCore :: getDeviceInfo( unsigned int device ) return info; } - const char *mname = CFStringGetCStringPtr( cfname, CFStringGetSystemEncoding() ); + CFIndex numbytes_cfname = CFStringGetMaximumSizeOfFileSystemRepresentation( cfname ); + if( numbytes_cfname == 0 ) + numbytes_cfname=256; + char mname[numbytes_cfname]; + + if(! CFStringGetCString( cfname, mname,numbytes_cfname,CFStringGetSystemEncoding() ) ) + strcpy(mname,""); + info.name.append( (const char *)mname, strlen(mname) ); info.name.append( ": " ); CFRelease( cfname ); @@ -572,7 +579,13 @@ RtAudio::DeviceInfo RtApiCore :: getDeviceInfo( unsigned int device ) return info; } - const char *name = CFStringGetCStringPtr( cfname, CFStringGetSystemEncoding() ); + numbytes_cfname = CFStringGetMaximumSizeOfFileSystemRepresentation( cfname ); + if( numbytes_cfname == 0 ) + numbytes_cfname=256; + char name[numbytes_cfname]; + if(! CFStringGetCString( cfname, name,numbytes_cfname,CFStringGetSystemEncoding() ) ) + strcpy(mname,""); + info.name.append( (const char *)name, strlen(name) ); CFRelease( cfname ); diff --git a/src/CMakeLists.linux.txt b/src/CMakeLists.linux.txt index edbcafd3a..eacb2d368 100644 --- a/src/CMakeLists.linux.txt +++ b/src/CMakeLists.linux.txt @@ -1,6 +1,7 @@ SET( OS_SPECIFIC_LINK_LIBRARIES ${OS_SPECIFIC_LINK_LIBRARIES} alsaplayback + tomahawklib ) IF( "${gui}" STREQUAL "no" ) diff --git a/src/CMakeLists.osx.txt b/src/CMakeLists.osx.txt index 7db1f0f95..0b2753ed7 100644 --- a/src/CMakeLists.osx.txt +++ b/src/CMakeLists.osx.txt @@ -10,4 +10,5 @@ SET( OS_SPECIFIC_LINK_LIBRARIES ${COREAUDIO_LIBRARY} ${COREFOUNDATION_LIBRARY} rtaudio + tomahawklib ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a2be78c36..4ed08c7e1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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,70 +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/databasecommand_loadallplaylists.cpp - database/databasecommand_setdynamicplaylistrevision.cpp - database/databasecommand_createdynamicplaylist.cpp - database/databasecommand_loaddynamicplaylist.cpp - database/databasecommand_loadalldynamicplaylists.cpp - database/databasecommand_deletedynamicplaylist.cpp - database/databasecollection.cpp - - dynamic/DynamicPlaylist.cpp - dynamic/DynamicControl.cpp - dynamic/GeneratorFactory.cpp - dynamic/GeneratorInterface.cpp - dynamic/echonest/EchonestGenerator.cpp - dynamic/echonest/EchonestControl.cpp - scrobbler.cpp xmppbot/xmppbot.cpp web/api_v1.cpp - tomahawksettings.cpp tomahawkapp.cpp main.cpp ) @@ -150,11 +88,6 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui} sourcetree/sourcetreeitemwidget.cpp sourcetree/sourcetreeview.cpp - dynamic/widgets/DynamicWidget.cpp - dynamic/widgets/DynamicControlWidget.cpp - dynamic/widgets/DynamicControlList.cpp - dynamic/DynamicPlaylistModel.cpp - topbar/topbar.cpp topbar/clearbutton.cpp topbar/searchlineedit.cpp @@ -163,6 +96,10 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui} infowidgets/sourceinfowidget.cpp + dynamic/widgets/DynamicWidget.cpp + dynamic/widgets/DynamicControlWidget.cpp + dynamic/widgets/DynamicControlList.cpp + dynamic/DynamicPlaylistModel.cpp transferview.cpp tomahawkwindow.cpp @@ -174,89 +111,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_setdynamicplaylistrevision.h - database/databasecommand_createdynamicplaylist.h - database/databasecommand_loaddynamicplaylist.h - database/databasecommand_deletedynamicplaylist.h - database/databasecommand_loadalldynamicplaylists.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 - - dynamic/DynamicPlaylist.h - dynamic/DynamicControl.h - dynamic/GeneratorFactory.h - dynamic/GeneratorInterface.h - dynamic/echonest/EchonestGenerator.h - dynamic/echonest/EchonestControl.h - musicscanner.h scriptresolver.h - tomahawksettings.h - tomahawkzeroconf.h scrobbler.h xmppbot/xmppbot.h @@ -345,10 +214,10 @@ INCLUDE_DIRECTORIES( topbar utils dynamic + libtomahawk ../rtaudio ../alsa-playback - ../libportfwd/include ../qxt/qxtweb-standalone/qxtweb /usr/include/taglib @@ -369,6 +238,7 @@ IF( UNIX ) ENDIF( UNIX ) ADD_SUBDIRECTORY( sip/jabber ) +ADD_SUBDIRECTORY( sip/zeroconf ) kde4_add_app_icon( tomahawkSources "${CMAKE_CURRENT_SOURCE_DIR}/../data/icons/tomahawk-icon-*.png" ) qt4_add_resources( RC_SRCS "../resources.qrc" ) @@ -398,9 +268,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 ) diff --git a/src/CMakeLists.win32.txt b/src/CMakeLists.win32.txt index cb53f3f23..ea504bb25 100644 --- a/src/CMakeLists.win32.txt +++ b/src/CMakeLists.win32.txt @@ -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" ) - diff --git a/src/audio/audioengine.cpp b/src/audio/audioengine.cpp index 92048f98b..7dd7b0a7e 100644 --- a/src/audio/audioengine.cpp +++ b/src/audio/audioengine.cpp @@ -3,8 +3,8 @@ #include #include -#include -#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() ) { diff --git a/src/audio/audioengine.h b/src/audio/audioengine.h index 0244695ff..fdda5dd33 100644 --- a/src/audio/audioengine.h +++ b/src/audio/audioengine.h @@ -5,8 +5,8 @@ #include #include -#include "tomahawk/result.h" -#include "tomahawk/typedefs.h" +#include "result.h" +#include "typedefs.h" #include "rtaudiooutput.h" #include "alsaplayback.h" diff --git a/src/audiocontrols.cpp b/src/audiocontrols.cpp index aa2e01f2f..640b44b46 100644 --- a/src/audiocontrols.cpp +++ b/src/audiocontrols.cpp @@ -4,7 +4,7 @@ #include #include "tomahawk/tomahawkapp.h" -#include "tomahawk/album.h" +#include "album.h" #include "utils/tomahawkutils.h" #include "audioengine.h" diff --git a/src/audiocontrols.h b/src/audiocontrols.h index df8feb795..2ba63eeed 100644 --- a/src/audiocontrols.h +++ b/src/audiocontrols.h @@ -3,8 +3,8 @@ #include -#include "tomahawk/result.h" -#include "tomahawk/playlistinterface.h" +#include "result.h" +#include "playlistinterface.h" namespace Ui { diff --git a/src/database/databasecommand_deletedynamicplaylist.cpp b/src/database/databasecommand_deletedynamicplaylist.cpp deleted file mode 100644 index 788ddcfdb..000000000 --- a/src/database/databasecommand_deletedynamicplaylist.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************************** - * Copyright (c) 2010 Leo Franchi * - * * - * This program 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 2 of the License, or (at your option) any later * - * version. * - * * - * This program 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 * - * this program. If not, see . * - ****************************************************************************************/ -#include "databasecommand_deletedynamicplaylist.h" - -#include - -#include "tomahawk/tomahawkapp.h" - -using namespace Tomahawk; - - -DatabaseCommand_DeleteDynamicPlaylist::DatabaseCommand_DeleteDynamicPlaylist( const source_ptr& source, const QString& playlistguid ) - : DatabaseCommand_DeletePlaylist( source, playlistguid ) -{ -} - - -void -DatabaseCommand_DeleteDynamicPlaylist::exec( DatabaseImpl* lib ) -{ - qDebug() << Q_FUNC_INFO; - DatabaseCommand_DeletePlaylist::exec( lib ); - TomahawkSqlQuery cre = lib->newquery(); - - cre.prepare( "DELETE FROM dynamic_playlist WHERE guid = :id" ); - cre.bindValue( ":id", m_playlistguid ); - - cre.exec(); -} - - -void -DatabaseCommand_DeleteDynamicPlaylist::postCommitHook() -{ - qDebug() << Q_FUNC_INFO << "..reporting.."; - - dynplaylist_ptr playlist = source()->collection()->dynamicPlaylist( m_playlistguid ); - Q_ASSERT( !playlist.isNull() ); - - playlist->reportDeleted( playlist ); - - if( source()->isLocal() ) - APP->servent().triggerDBSync(); -} diff --git a/src/database/databasecommand_deletedynamicplaylist.h b/src/database/databasecommand_deletedynamicplaylist.h deleted file mode 100644 index 5038f406a..000000000 --- a/src/database/databasecommand_deletedynamicplaylist.h +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************************** - * Copyright (c) 2010 Leo Franchi * - * * - * This program 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 2 of the License, or (at your option) any later * - * version. * - * * - * This program 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 * - * this program. If not, see . * - ****************************************************************************************/ - -#ifndef DATABASECOMMAND_DELETEDYNAMICPLAYLIST_H -#define DATABASECOMMAND_DELETEDYNAMICPLAYLIST_H - -#include "databaseimpl.h" -#include "databasecommand_deleteplaylist.h" -#include "tomahawk/source.h" -#include "tomahawk/typedefs.h" - -class DatabaseCommand_DeleteDynamicPlaylist : public DatabaseCommand_DeletePlaylist -{ - Q_OBJECT -public: - explicit DatabaseCommand_DeleteDynamicPlaylist( QObject* parent = 0 ) - : DatabaseCommand_DeletePlaylist( parent ) - {} - - explicit DatabaseCommand_DeleteDynamicPlaylist( const Tomahawk::source_ptr& source, const QString& playlistguid ); - - QString commandname() const { return "deletedynamicplaylist"; } - - virtual void exec( DatabaseImpl* lib ); - virtual void postCommitHook(); - virtual bool doesMutates() const { return true; } - -private: - QString m_playlistguid; -}; - -#endif // DATABASECOMMAND_DELETEDYNAMICPLAYLIST_H diff --git a/src/database/databasecommand_loadalldynamicplaylists.cpp b/src/database/databasecommand_loadalldynamicplaylists.cpp deleted file mode 100644 index c547b18e6..000000000 --- a/src/database/databasecommand_loadalldynamicplaylists.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************************** - * Copyright (c) 2010 Leo Franchi * - * * - * This program 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 2 of the License, or (at your option) any later * - * version. * - * * - * This program 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 * - * this program. If not, see . * - ****************************************************************************************/ -#include "databasecommand_loadalldynamicplaylists.h" - -#include - -#include "dynamic/DynamicPlaylist.h" -#include "databaseimpl.h" - -using namespace Tomahawk; - - -void DatabaseCommand_LoadAllDynamicPlaylists::exec( DatabaseImpl* dbi ) -{ - TomahawkSqlQuery query = dbi->newquery(); - - query.exec( QString( "SELECT playlist.guid as guid, title, info, creator, lastmodified, shared, currentrevision, dynamic_playlist.pltype, dynamic_playlist.plmode " - "FROM playlist, dynamic_playlist WHERE source %1 AND dynplaylist AND playlist.guid = dynamic_playlist.guid" ) - .arg( source()->isLocal() ? "IS NULL" : - QString( "=%1" ).arg( source()->id() ) - ) ); - - QList plists; - while ( query.next() ) - { - dynplaylist_ptr p( new DynamicPlaylist( source(), //src - query.value(6).toString(), //current rev - query.value(1).toString(), //title - query.value(2).toString(), //info - query.value(3).toString(), //creator - query.value(7).toString(), // dynamic type - static_cast(query.value(8).toInt()), // dynamic mode - query.value(5).toBool(), //shared - query.value(4).toInt(), //lastmod - query.value(0).toString() //GUID - - ) ); - plists.append( p ); - } - - emit done( plists ); -} - diff --git a/src/database/databasecommand_loadalldynamicplaylists.h b/src/database/databasecommand_loadalldynamicplaylists.h deleted file mode 100644 index c1a71bcf9..000000000 --- a/src/database/databasecommand_loadalldynamicplaylists.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************************** - * Copyright (c) 2010 Leo Franchi * - * * - * This program 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 2 of the License, or (at your option) any later * - * version. * - * * - * This program 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 * - * this program. If not, see . * - ****************************************************************************************/ -#ifndef DATABASECOMMAND_LOADALLDYNAMICPLAYLISTS_H -#define DATABASECOMMAND_LOADALLDYNAMICPLAYLISTS_H - -#include -#include - -#include "databasecommand.h" -#include "tomahawk/typedefs.h" - -class DatabaseCommand_LoadAllDynamicPlaylists : public DatabaseCommand -{ - Q_OBJECT - -public: - explicit DatabaseCommand_LoadAllDynamicPlaylists( const Tomahawk::source_ptr& s, QObject* parent = 0 ) - : DatabaseCommand( s, parent ) - {} - - virtual void exec( DatabaseImpl* ); - virtual bool doesMutates() const { return false; } - virtual QString commandname() const { return "loadalldynamicplaylists"; } - -signals: - void done( const QList& playlists ); -}; - -#endif // DATABASECOMMAND_ADDFILES_H diff --git a/src/database/databasecommand_loaddynamicplaylist.cpp b/src/database/databasecommand_loaddynamicplaylist.cpp deleted file mode 100644 index a17df77fc..000000000 --- a/src/database/databasecommand_loaddynamicplaylist.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "databasecommand_loaddynamicplaylist.h" - -#include -#include - -#include "databaseimpl.h" -#include "tomahawksqlquery.h" -#include "dynamic/DynamicControl.h" -#include "dynamic/GeneratorInterface.h" - -using namespace Tomahawk; - - -void -DatabaseCommand_LoadDynamicPlaylist::exec( DatabaseImpl* dbi ) -{ - qDebug() << "Loading dynamic playlist revision" << guid(); - // load the entries first - generateEntries( dbi ); - - // now load the controls etc - - TomahawkSqlQuery controlsQuery = dbi->newquery(); - controlsQuery.prepare("SELECT playlist_revision.playlist, controls, plmode, pltype " - "FROM dynamic_playlist_revision, playlist_revision " - "WHERE dynamic_playlist_revision.guid = ? AND playlist_revision.guid = dynamic_playlist_revision.guid"); - controlsQuery.addBindValue( revisionGuid() ); - controlsQuery.exec(); - - QList< dyncontrol_ptr > controls; - QString playlist_guid; - if( controlsQuery.next() ) - { - playlist_guid = controlsQuery.value( 0 ).toString(); - QStringList controlIds = controlsQuery.value( 1 ).toStringList(); - foreach( const QString& controlId, controlIds ) - { - TomahawkSqlQuery controlQuery = dbi->newquery(); - controlQuery.prepare( "SELECT selectedType, match, input " - "FROM dynamic_playlist_controls " - "WHERE id = :id" ); - controlQuery.bindValue( ":id", controlId ); - controlQuery.exec(); - if( controlQuery.next() ) - { - dyncontrol_ptr c = dyncontrol_ptr( new DynamicControl ); - c->setId( controlId ); - c->setSelectedType( controlQuery.value( 0 ).toString() ); - c->setMatch( controlQuery.value( 1 ).toString() ); - c->setInput( controlQuery.value( 2 ).toString() ); - controls << c; - } - } - } - - TomahawkSqlQuery info = dbi->newquery(); - info.prepare( QString( "SELECT dynamic_playlist.pltype, dynamic_playlist.plmode FROM playlist, dynamic_playlist WHERE playlist.guid = \"%1\" AND playlist.guid = dynamic_playlist.guid" ).arg( playlist_guid ) ); - if( !info.exec() ) { - qWarning() << "Failed to load dynplaylist info.."; - return; - } else if( !info.first() ) { - qWarning() << "Noo results for queryL:" << info.lastQuery(); - return; - } - QString type = info.value( 0 ).toString(); - GeneratorMode mode = static_cast( info.value( 1 ).toInt() ); - if( mode == OnDemand ) { - Q_ASSERT( m_entrymap.isEmpty() ); // ondemand should have no entry - - emit done( revisionGuid(), m_islatest, type, controls, true ); - } else { - emit done( revisionGuid(), m_guids, m_oldentries, type, controls, m_islatest, m_entrymap, true ); - } -} diff --git a/src/database/databasecommand_loaddynamicplaylist.h b/src/database/databasecommand_loaddynamicplaylist.h deleted file mode 100644 index de281f405..000000000 --- a/src/database/databasecommand_loaddynamicplaylist.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef DATABASECOMMAND_LOADDYNAMICPLAYLIST_H -#define DATABASECOMMAND_LOADDYNAMICPLAYLIST_H - -#include -#include - -#include "tomahawk/typedefs.h" -#include "databasecommand.h" -#include "databasecommand_loadplaylistentries.h" -#include "tomahawk/playlist.h" -#include "dynamic/DynamicControl.h" - -class DatabaseCommand_LoadDynamicPlaylist : public DatabaseCommand_LoadPlaylistEntries -{ - Q_OBJECT - -public: - explicit DatabaseCommand_LoadDynamicPlaylist( QString revision_guid, QObject* parent = 0 ) - : DatabaseCommand_LoadPlaylistEntries( revision_guid, parent ) - { qDebug() << "loaded with:" << revision_guid << guid(); } - - - virtual void exec( DatabaseImpl* ); - virtual bool doesMutates() const { return false; } - virtual QString commandname() const { return "loaddynamicplaylist"; } - -signals: - // used if loading an ondemand playlist - void done( QString, - bool, - QString, - QList< Tomahawk::dyncontrol_ptr>, - bool ); - // used when loading a static playlist - void done( QString, - QList< QString >, - QList< QString >, - QString, - QList< Tomahawk::dyncontrol_ptr>, - bool, - QMap< QString, Tomahawk::plentry_ptr >, - bool ); - -private: -}; - -#endif // DATABASECOMMAND_LOADDYNAMICPLAYLIST_H diff --git a/src/database/databasecommand_setdynamicplaylistrevision.cpp b/src/database/databasecommand_setdynamicplaylistrevision.cpp deleted file mode 100644 index 432a2cf77..000000000 --- a/src/database/databasecommand_setdynamicplaylistrevision.cpp +++ /dev/null @@ -1,150 +0,0 @@ -#include "databasecommand_setdynamicplaylistrevision.h" - -#include - -#include "tomahawksqlquery.h" -#include "dynamic/DynamicPlaylist.h" -#include "dynamic/DynamicControl.h" -#include "tomahawk/tomahawkapp.h" - -DatabaseCommand_SetDynamicPlaylistRevision::DatabaseCommand_SetDynamicPlaylistRevision(const Tomahawk::source_ptr& s, - const QString& playlistguid, - const QString& newrev, - const QString& oldrev, - const QStringList& orderedguids, - const QList< plentry_ptr >& addedentries, - const QString& type, - GeneratorMode mode, - const QList< dyncontrol_ptr >& controls ) - : DatabaseCommand_SetPlaylistRevision( s, playlistguid, newrev, oldrev, orderedguids, addedentries ) - , m_type( type ) - , m_mode( mode ) - , m_controls( controls ) -{ - -} - -DatabaseCommand_SetDynamicPlaylistRevision::DatabaseCommand_SetDynamicPlaylistRevision(const Tomahawk::source_ptr& s, - const QString& playlistguid, - const QString& newrev, - const QString& oldrev, - const QString& type, - GeneratorMode mode, - const QList< dyncontrol_ptr >& controls ) - : DatabaseCommand_SetPlaylistRevision( s, playlistguid, newrev, oldrev, QStringList(), QList< plentry_ptr >() ) - , m_type( type ) - , m_mode( mode ) - , m_controls( controls ) -{ - -} - -QVariantList DatabaseCommand_SetDynamicPlaylistRevision::controlsV() -{ - if( m_controls.isEmpty() ) - return m_controlsV; - - if( !m_controls.isEmpty() && m_controlsV.isEmpty() ) - { - foreach( const dyncontrol_ptr& control, m_controls ) - { - m_controlsV << QJson::QObjectHelper::qobject2qvariant( control.data() ); - } - } - return m_controlsV; - -} - - -void -DatabaseCommand_SetDynamicPlaylistRevision::postCommitHook() -{ - qDebug() << Q_FUNC_INFO; - - QStringList orderedentriesguids; - foreach( const QVariant& v, orderedguids() ) - orderedentriesguids << v.toString(); - - // private, but we are a friend. will recall itself in its own thread: - dynplaylist_ptr playlist = source()->collection()->dynamicPlaylist( playlistguid() ); - - if ( playlist.isNull() ) - { - qDebug() << playlistguid(); - Q_ASSERT( !playlist.isNull() ); - return; - } - - if( m_controls.isEmpty() && !m_controlsV.isEmpty() ) // we were creatd from JSON, not programmatically. construct the controls fromthe playlist now - { - foreach( const QVariant& contrl, m_controlsV ) { - dyncontrol_ptr control = playlist->generator()->createControl( m_type ); - QJson::QObjectHelper::qvariant2qobject( contrl.toMap(), control.data( )); - m_controls << control; - } - } - - if( m_mode == OnDemand ) - playlist->setRevision( newrev(), - true, // this *is* the newest revision so far - m_type, - m_controls, - m_applied ); - else - playlist->setRevision( newrev(), - orderedentriesguids, - m_previous_rev_orderedguids, - m_type, - m_controls, - true, // this *is* the newest revision so far - m_addedmap, - m_applied ); - - if( source()->isLocal() ) - APP->servent().triggerDBSync(); -} - - -void -DatabaseCommand_SetDynamicPlaylistRevision::exec( DatabaseImpl* lib ) -{ - DatabaseCommand_SetPlaylistRevision::exec( lib ); - - QVariantList newcontrols; - foreach( const dyncontrol_ptr& control, m_controls ) { - newcontrols << control->id(); - } - QJson::Serializer ser; - const QByteArray newcontrols_data = ser.serialize( newcontrols ); - - TomahawkSqlQuery query = lib->newquery(); - QString sql = "INSERT INTO dynamic_playlist_revision (guid, controls, plmode, pltype) " - "VALUES(?, ?, ?, ?)"; - - query.prepare( sql ); - query.addBindValue( m_newrev ); - query.addBindValue( newcontrols_data ); - query.addBindValue( QString::number( (int) m_mode ) ); - query.addBindValue( m_type ); - query.exec(); - - // delete all the old controls, replace with new onws - TomahawkSqlQuery delQuery = lib->newquery(); - delQuery.prepare( "DELETE * FROM dynamic_playlist_controls" ); - delQuery.exec(); - - TomahawkSqlQuery controlsQuery = lib->newquery(); - controlsQuery.prepare( "INSERT INTO dynamic_playlist_controls( id, playlist, selectedType, match, input ) " - "VALUES( ?, ?, ?, ?, ?" ); - foreach( const dyncontrol_ptr& control, m_controls ) - { - controlsQuery.addBindValue( control->id() ); - controlsQuery.addBindValue( m_playlistguid ); - controlsQuery.addBindValue( control->selectedType() ); - controlsQuery.addBindValue( control->match() ); - controlsQuery.addBindValue( control->input() ); - - controlsQuery.exec(); - } - -} diff --git a/src/database/databasecommand_setdynamicplaylistrevision.h b/src/database/databasecommand_setdynamicplaylistrevision.h deleted file mode 100644 index 916b9edaf..000000000 --- a/src/database/databasecommand_setdynamicplaylistrevision.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef DATABASECOMMAND_SETDYNAMICPLAYLISTREVISION_H -#define DATABASECOMMAND_SETDYNAMICPLAYLISTREVISION_H - -#include "databasecommand_setplaylistrevision.h" -#include "databaseimpl.h" -#include "tomahawk/collection.h" -#include "tomahawk/playlist.h" -#include "dynamic/GeneratorInterface.h" - -using namespace Tomahawk; - -class DatabaseCommand_SetDynamicPlaylistRevision : public DatabaseCommand_SetPlaylistRevision -{ - Q_OBJECT - Q_PROPERTY( QString type READ type WRITE setType ) - Q_PROPERTY( int mode READ mode WRITE setMode ) - Q_PROPERTY( QVariantList controls READ controlsV WRITE setControlsV ) - -public: - explicit DatabaseCommand_SetDynamicPlaylistRevision( QObject* parent = 0 ) - : DatabaseCommand_SetPlaylistRevision( parent ) - {} - - explicit DatabaseCommand_SetDynamicPlaylistRevision( const source_ptr& s, - const QString& playlistguid, - const QString& newrev, - const QString& oldrev, - const QStringList& orderedguids, - const QList& addedentries, - const QString& type, - GeneratorMode mode, - const QList< dyncontrol_ptr >& controls ); - - explicit DatabaseCommand_SetDynamicPlaylistRevision( const source_ptr& s, - const QString& playlistguid, - const QString& newrev, - const QString& oldrev, - const QString& type, - GeneratorMode mode, - const QList< dyncontrol_ptr >& controls ); - - QString commandname() const { return "setdynamicplaylistrevision"; } - - virtual void exec( DatabaseImpl* lib ); - virtual void postCommitHook(); - virtual bool doesMutates() const { return true; } - - void setControlsV( const QVariantList& vlist ) - { - m_controlsV = vlist; - } - - QVariantList controlsV(); - - QString type() const { return m_type; } -// GeneratorMode mode() const { return m_mode; } - int mode() const { return (int)m_mode; } - - void setType( const QString& type ) { m_type = type; } -// void setMode( GeneratorMode mode ) { m_mode = mode; } - void setMode( int mode ) { m_mode = (GeneratorMode)mode; } - -private: - QString m_type; - GeneratorMode m_mode; - QList< dyncontrol_ptr > m_controls; - QList< QVariant > m_controlsV; -}; - -#endif // DATABASECOMMAND_SETDYNAMICPLAYLISTREVISION_H diff --git a/src/dynamic/DynamicControl.cpp b/src/dynamic/DynamicControl.cpp deleted file mode 100644 index 61f7cd315..000000000 --- a/src/dynamic/DynamicControl.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/**************************************************************************************** - * Copyright (c) 2010 Leo Franchi * - * * - * This program 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 2 of the License, or (at your option) any later * - * version. * - * * - * This program 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 * - * this program. If not, see . * - ****************************************************************************************/ - -#include "DynamicControl.h" - -Tomahawk::DynamicControl::DynamicControl( const QStringList& typeSelectors ) - : m_typeSelectors( typeSelectors ) -{ - -} - -Tomahawk::DynamicControl::~DynamicControl() -{ - -} - -Tomahawk::DynamicControl::DynamicControl(const QString& selectedType, const QStringList& typeSelectors, QObject* parent) - : QObject(parent) - , m_selectedType( selectedType ) - , m_typeSelectors( typeSelectors ) -{ - -} diff --git a/src/dynamic/DynamicControl.h b/src/dynamic/DynamicControl.h deleted file mode 100644 index 636108b49..000000000 --- a/src/dynamic/DynamicControl.h +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************************** - * Copyright (c) 2010 Leo Franchi * - * * - * This program 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 2 of the License, or (at your option) any later * - * version. * - * * - * This program 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 * - * this program. If not, see . * - ****************************************************************************************/ - -#ifndef DYNAMIC_PLAYLIST_CONTROL -#define DYNAMIC_PLAYLIST_CONTROL - -#include -#include -#include -#include -#include - -namespace Tomahawk -{ - -/** - * A Dynamic Control is a single constraint that limits a dynamic playlist. Each generator creates controls specific to that generator. - * Each control has 3 pieces: - * - Type (string selector for what this control is matching) - * - Match selector (how to match the type to the input) - * - Input field (the user input field). - * - * Each control also has a list of TypeSelectors that comes from the generator, and only one is selected at once. - * - */ -class DynamicControl : public QObject -{ - Q_OBJECT - Q_PROPERTY( QString id READ id WRITE setId ) - Q_PROPERTY( QString selectedType READ selectedType WRITE setSelectedType ) - Q_PROPERTY( QString match READ match WRITE setMatch ) - Q_PROPERTY( QString input READ input WRITE setInput ) - -public: - DynamicControl( const QStringList& typeSelectors = QStringList() ); - virtual ~DynamicControl(); - - - /// The current type of this control - QString selectedType() const { return m_selectedType; } - /** - * The match selector widget based on this control's type - * - * The control manages the lifetime of the widget. - */ - virtual QWidget* matchSelector() { Q_ASSERT( false ); return 0; } - /** - * The input field widget that is associated with this type - * - * The control manages the lifetime of the widget. - */ - virtual QWidget* inputField() { Q_ASSERT( false ); return 0; } - - /// the serializable value of the match - QString match() const { return m_match; } - /// the serializable value of the input - QString input() const { return m_input; } - - // used by JSON serialization - void setMatch( const QString& match ) { m_match = match; } - void setInput( const QString& input ) { m_input = input; } - - /// All the potential type selectors for this control - QStringList typeSelectors() const { return m_typeSelectors; } - - QString id() { - if( m_id.isEmpty() ) - m_id = uuid(); - return m_id; - }; - void setId( const QString& id ) { m_id = id; } - -public slots: - /** - * Sets the type to the newly specified one. Note that this will update the matchSelector - * and inputField widgets, so you should fetch the new widgets for use immediately. - */ - virtual void setSelectedType( const QString& selectedType ) { m_selectedType = selectedType; } - -protected: - // Private constructor, you can't make one. Get it from your Generator. - explicit DynamicControl( const QString& selectedType, const QStringList& typeSelectors, QObject* parent = 0 ); - - QString m_match; - QString m_input; - -private: - QString m_selectedType; - QStringList m_typeSelectors; - QString m_id; -}; - -}; - -#endif diff --git a/src/dynamic/DynamicPlaylist.cpp b/src/dynamic/DynamicPlaylist.cpp deleted file mode 100644 index a8a884df0..000000000 --- a/src/dynamic/DynamicPlaylist.cpp +++ /dev/null @@ -1,349 +0,0 @@ -/**************************************************************************************** - * Copyright (c) 2010 Leo Franchi * - * * - * This program 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 2 of the License, or (at your option) any later * - * version. * - * * - * This program 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 * - * this program. If not, see . * - ****************************************************************************************/ - -#include "DynamicPlaylist.h" - -#include "tomahawk/tomahawkapp.h" -#include "GeneratorFactory.h" -#include "database.h" -#include "databasecommand.h" -#include "databasecommand_createdynamicplaylist.h" -#include "databasecommand_setdynamicplaylistrevision.h" -#include "databasecommand_loaddynamicplaylist.h" - -using namespace Tomahawk; - -DynamicPlaylist::DynamicPlaylist(const Tomahawk::source_ptr& author) - : Playlist(author) -{ - qDebug() << Q_FUNC_INFO << "JSON"; -} - - -DynamicPlaylist::~DynamicPlaylist() -{ - -} - -// Called by loadAllPlaylists command -DynamicPlaylist::DynamicPlaylist ( const Tomahawk::source_ptr& src, - const QString& currentrevision, - const QString& title, - const QString& info, - const QString& creator, - const QString& type, - GeneratorMode mode, - bool shared, - int lastmod, - const QString& guid ) - : Playlist( src, currentrevision, title, info, creator, shared, lastmod, guid ) -{ - qDebug() << "Creating Dynamic Playlist 1"; - // TODO instantiate generator - m_generator = geninterface_ptr( GeneratorFactory::create( type ) ); - m_generator->setMode( mode ); -} - - -// called when a new playlist is created (no currentrevision, new guid) -DynamicPlaylist::DynamicPlaylist ( const Tomahawk::source_ptr& author, - const QString& guid, - const QString& title, - const QString& info, - const QString& creator, - const QString& type, - bool shared ) - : Playlist ( author, guid, title, info, creator, shared ) -{ - qDebug() << "Creating Dynamic Playlist 2"; - m_generator = geninterface_ptr( GeneratorFactory::create( type ) ); -} - -geninterface_ptr -DynamicPlaylist::generator() const -{ - return m_generator; -} - -GeneratorMode -DynamicPlaylist::mode() const -{ - return m_generator->mode(); -} - -void -DynamicPlaylist::setGenerator(const Tomahawk::geninterface_ptr& gen_ptr) -{ - m_generator = gen_ptr; -} - -QString -DynamicPlaylist::type() const -{ - return m_generator->type(); -} - -void -DynamicPlaylist::setMode(GeneratorMode mode) -{ - m_generator->setMode( mode ); -} - - - -dynplaylist_ptr -DynamicPlaylist::create( const Tomahawk::source_ptr& author, - const QString& guid, - const QString& title, - const QString& info, - const QString& creator, - bool shared ) -{ - // default generator - QString type = ""; - dynplaylist_ptr dynplaylist = dynplaylist_ptr( new DynamicPlaylist( author, guid, title, info, creator, type, shared ) ); - - DatabaseCommand_CreateDynamicPlaylist* cmd = new DatabaseCommand_CreateDynamicPlaylist( author, dynplaylist ); - connect( cmd, SIGNAL(finished()), dynplaylist.data(), SIGNAL(created()) ); - APP->database()->enqueue( QSharedPointer(cmd) ); - dynplaylist->reportCreated( dynplaylist ); - return dynplaylist; - -} - -// create a new revision that will be a static playlist, as it has entries -void -DynamicPlaylist::createNewRevision( const QString& newrev, - const QString& oldrev, - const QString& type, - const QList< dyncontrol_ptr>& controls, - const QList< plentry_ptr >& entries ) -{ - // get the newly added tracks - QList< plentry_ptr > added = newEntries( entries ); - - QStringList orderedguids; - for( int i = 0; i < entries.size(); ++i ) - orderedguids << entries.at(i)->guid(); - - // no conflict resolution or partial updating for controls. all or nothing baby - - // source making the change (local user in this case) - source_ptr author = APP->sourcelist().getLocal(); - // command writes new rev to DB and calls setRevision, which emits our signal - DatabaseCommand_SetDynamicPlaylistRevision* cmd = - new DatabaseCommand_SetDynamicPlaylistRevision( author, - guid(), - newrev, - oldrev, - orderedguids, - added, - type, - Static, - controls ); - APP->database()->enqueue( QSharedPointer( cmd ) ); -} - -// create a new revision that will be an ondemand playlist, as it has no entries -void -DynamicPlaylist::createNewRevision( const QString& newrev, - const QString& oldrev, - const QString& type, - const QList< dyncontrol_ptr>& controls ) -{ - // can skip the entry stuff. just overwrite with new info - source_ptr author = APP->sourcelist().getLocal(); - // command writes new rev to DB and calls setRevision, which emits our signal - DatabaseCommand_SetDynamicPlaylistRevision* cmd = - new DatabaseCommand_SetDynamicPlaylistRevision( author, - guid(), - newrev, - oldrev, - type, - OnDemand, - controls ); - APP->database()->enqueue( QSharedPointer( cmd ) ); -} - -void -DynamicPlaylist::loadRevision( const QString& rev ) -{ - qDebug() << Q_FUNC_INFO << "Loading with:" << ( rev.isEmpty() ? currentrevision() : rev ); - - DatabaseCommand_LoadDynamicPlaylist* cmd = new DatabaseCommand_LoadDynamicPlaylist( rev.isEmpty() ? currentrevision() : rev ); - - if( m_generator->mode() == OnDemand ) { - connect( cmd, SIGNAL( done( QString, - bool, - QString, - QList< Tomahawk::dyncontrol_ptr>, - bool ) ), - SLOT( setRevision( QString, - bool, - QString, - QList< Tomahawk::dyncontrol_ptr>, - bool) ) ); - } else if( m_generator->mode() == Static ) { - connect( cmd, SIGNAL( done( QString, - QList< QString >, - QList< QString >, - QString, - QList< Tomahawk::dyncontrol_ptr>, - bool, - QMap< QString, Tomahawk::plentry_ptr >, - bool ) ), - SLOT( setRevision( QString, - QList< QString >, - QList< QString >, - QString, - QList< Tomahawk::dyncontrol_ptr>, - bool, - QMap< QString, Tomahawk::plentry_ptr >, - bool ) ) ); - - } - APP->database()->enqueue( QSharedPointer( cmd ) ); -} - -bool -DynamicPlaylist::remove( const Tomahawk::dynplaylist_ptr& playlist ) -{ - // TODO -// DatabaseCommand_DeletePlaylist* cmd = new DatabaseCommand_DeletePlaylist( playlist->author(), playlist->guid() ); -// APP->database()->enqueue( QSharedPointer(cmd) ); - - return false; -} - -void -DynamicPlaylist::reportCreated( const Tomahawk::dynplaylist_ptr& self ) -{ - qDebug() << Q_FUNC_INFO; - Q_ASSERT( self.data() == this ); - // will emit Collection::playlistCreated(...) - author()->collection()->addDynamicPlaylist( self ); -} - -void -DynamicPlaylist::reportDeleted( const Tomahawk::dynplaylist_ptr& self ) -{ - qDebug() << Q_FUNC_INFO; - Q_ASSERT( self.data() == this ); - // will emit Collection::playlistCreated(...) - author()->collection()->deleteDynamicPlaylist( self ); -} - -void DynamicPlaylist::addEntries(const QList< query_ptr >& queries, const QString& oldrev) -{ - Q_ASSERT( m_generator->mode() == Static ); - - QList el = addEntriesInternal( queries ); - - QString newrev = uuid(); - createNewRevision( newrev, oldrev, m_generator->type(), m_generator->controls(), el ); -} - -void DynamicPlaylist::addEntry(const Tomahawk::query_ptr& query, const QString& oldrev) -{ - QList queries; - queries << query; - - addEntries( queries, oldrev ); -} - -// static version -void -DynamicPlaylist::setRevision( const QString& rev, - const QList< QString >& neworderedguids, - const QList< QString >& oldorderedguids, - const QString& type, - const QList< Tomahawk::dyncontrol_ptr>& controls, - bool is_newest_rev, - const QMap< QString, Tomahawk::plentry_ptr >& addedmap, - bool applied ) -{ - // we're probably being called by a database worker thread - if( QThread::currentThread() != thread() ) - { - QMetaObject::invokeMethod( this, - "setRevision", - Qt::BlockingQueuedConnection, - Q_ARG( QString, rev ), - Q_ARG( QList , neworderedguids ), - Q_ARG( QList , oldorderedguids ), - Q_ARG( QString , type ), - QGenericArgument( "QList< Tomahawk::dyncontrol_ptr > " , (const void*)&controls ), - Q_ARG( bool, is_newest_rev ), - QGenericArgument( "QMap< QString,Tomahawk::plentry_ptr > " , (const void*)&addedmap ), - Q_ARG( bool, applied ) ); - return; - } - if( m_generator->type() != type ) { // new generator needed - m_generator = GeneratorFactory::create( type ); - } - - m_generator->setControls( controls ); - m_generator->setMode( Static ); - - DynamicPlaylistRevision pr = setNewRevision( rev, neworderedguids, oldorderedguids, is_newest_rev, addedmap ); - pr.controls = controls; - pr.type = type; - pr.mode = Static; - - if( applied ) - setCurrentrevision( rev ); - pr.applied = applied; - - emit revisionLoaded( pr ); -} - -// ondemand version -void -DynamicPlaylist::setRevision( const QString& rev, - bool is_newest_rev, - const QString& type, - const QList< Tomahawk::dyncontrol_ptr>& controls, - bool applied ) -{ - if( QThread::currentThread() != thread() ) - { - QMetaObject::invokeMethod( this, - "setRevision", - Qt::BlockingQueuedConnection, - Q_ARG( QString, rev ), - Q_ARG( bool, is_newest_rev ), - Q_ARG( QString, type ), - QGenericArgument( "QList< Tomahawk::dyncontrol_ptr >" , (const void*)&controls ), - Q_ARG( bool, applied ) ); - return; - } - if( m_generator->type() != type ) { // new generator needed - m_generator = geninterface_ptr( GeneratorFactory::create( type ) ); - } - - m_generator->setControls( controls ); - m_generator->setMode( OnDemand ); - - DynamicPlaylistRevision pr; - pr.oldrevisionguid = currentrevision(); - pr.revisionguid = rev; - pr.controls = controls; - pr.type = type; - pr.mode = OnDemand; - - emit revisionLoaded( pr ); -} - diff --git a/src/dynamic/DynamicPlaylist.h b/src/dynamic/DynamicPlaylist.h deleted file mode 100644 index b9a86b154..000000000 --- a/src/dynamic/DynamicPlaylist.h +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************************** - * Copyright (c) 2010 Leo Franchi * - * * - * This program 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 2 of the License, or (at your option) any later * - * version. * - * * - * This program 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 * - * this program. If not, see . * - ****************************************************************************************/ - -#ifndef DYNAMIC_PLAYLIST_H -#define DYNAMIC_PLAYLIST_H - -#include -#include -#include - -#include "tomahawk/playlist.h" -#include "tomahawk/typedefs.h" -#include "dynamic/DynamicControl.h" - -class DatabaseCommand_LoadAllDynamicPlaylists; -class DatabaseCommand_SetDynamicPlaylistRevision; -class DatabaseCommand_CreateDynamicPlaylist; - -namespace Tomahawk { - -/** - * Subclass of playlist that adds the information needed to store a dynamic playlist. - * It uses normal PlaylistEntries but also has a mode, a generator, and a list of controls -*/ - -struct DynamicPlaylistRevision : PlaylistRevision -{ - QList< dyncontrol_ptr > controls; - Tomahawk::GeneratorMode mode; - QString type; - - DynamicPlaylistRevision( const PlaylistRevision& other ) - { - revisionguid = other.revisionguid; - oldrevisionguid = other.oldrevisionguid; - newlist = other.newlist; - added = other.added; - removed = other.removed; - applied = other.applied; - } - - DynamicPlaylistRevision() {} -}; - -class DynamicPlaylist : public Playlist -{ - Q_OBJECT - - Q_PROPERTY( GeneratorMode mode WRITE setMode READ mode ) - Q_PROPERTY( QString type WRITE setType READ type ) - - friend class ::DatabaseCommand_LoadAllDynamicPlaylists; - friend class ::DatabaseCommand_SetDynamicPlaylistRevision; - friend class ::DatabaseCommand_CreateDynamicPlaylist; - -public: - virtual ~DynamicPlaylist(); - - /// Generate an empty dynamic playlist with default generator - static Tomahawk::dynplaylist_ptr create( const source_ptr& author, - const QString& guid, - const QString& title, - const QString& info, - const QString& creator, - bool shared - ); - static bool remove( const dynplaylist_ptr& playlist ); - - virtual void loadRevision( const QString& rev = "" ); - - GeneratorMode mode() const; - QString type() const; - geninterface_ptr generator() const; - - virtual void addEntries( const QList< query_ptr >& queries, const QString& oldrev ); - virtual void addEntry( const Tomahawk::query_ptr& query, const QString& oldrev ); - - // - // 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? - explicit DynamicPlaylist( const source_ptr& author ); - void setMode( GeneratorMode mode ); - void setType( const QString& type ) { /** TODO */; } - void setGenerator( const geninterface_ptr& gen_ptr ); - // - -signals: - /// emitted when the playlist revision changes (whenever the playlist changes) - void revisionLoaded( Tomahawk::DynamicPlaylistRevision ); - -public slots: - // want to update the playlist from the model? - // generate a newrev using uuid() and call this: - // if this is a static playlist, pass it a new list of entries. implicitly sets mode to static - void createNewRevision( const QString& newrev, const QString& oldrev, const QString& type, const QList< dyncontrol_ptr>& controls, const QList< plentry_ptr >& entries ); - // if it is ondemand, no entries are needed implicitly sets mode to ondemand - void createNewRevision( const QString& newrev, const QString& oldrev, const QString& type, const QList< dyncontrol_ptr>& controls ); - - void reportCreated( const Tomahawk::dynplaylist_ptr& self ); - void reportDeleted( const Tomahawk::dynplaylist_ptr& self ); - - // called from setdynamicplaylistrevision db cmd - // static version - void setRevision( const QString& rev, - const QList& neworderedguids, - const QList& oldorderedguids, - const QString& type, - const QList< Tomahawk::dyncontrol_ptr>& controls, - bool is_newest_rev, - const QMap< QString, Tomahawk::plentry_ptr >& addedmap, - bool applied ); - - // ondemand version - void setRevision( const QString& rev, - bool is_newest_rev, - const QString& type, - const QList< Tomahawk::dyncontrol_ptr>& controls, - bool applied ); -private: - // called from loadAllPlaylists DB cmd: - explicit DynamicPlaylist( const source_ptr& src, - const QString& currentrevision, - const QString& title, - const QString& info, - const QString& creator, - const QString& type, - GeneratorMode mode, - bool shared, - int lastmod, - const QString& guid = "" ); // populate db - - // called when creating new playlist - explicit DynamicPlaylist( const source_ptr& author, - const QString& guid, - const QString& title, - const QString& info, - const QString& creator, - const QString& type, - bool shared ); - -private: - geninterface_ptr m_generator; -}; - -}; // namespace - -#endif \ No newline at end of file diff --git a/src/dynamic/DynamicPlaylistModel.h b/src/dynamic/DynamicPlaylistModel.h index 940a6707c..cca3cfa35 100644 --- a/src/dynamic/DynamicPlaylistModel.h +++ b/src/dynamic/DynamicPlaylistModel.h @@ -16,7 +16,7 @@ #ifndef DYNAMIC_PLAYLIST_MODEL_H #define DYNAMIC_PLAYLIST_MODEL_H -#include "tomahawk/typedefs.h" +#include "typedefs.h" #include "playlist/playlistmodel.h" /** diff --git a/src/dynamic/GeneratorFactory.cpp b/src/dynamic/GeneratorFactory.cpp deleted file mode 100644 index 794909911..000000000 --- a/src/dynamic/GeneratorFactory.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "dynamic/GeneratorFactory.h" -#include "dynamic/GeneratorInterface.h" - -using namespace Tomahawk; - -QHash< QString, GeneratorFactoryInterface* > GeneratorFactory::s_factories = QHash< QString, GeneratorFactoryInterface* >(); - -geninterface_ptr GeneratorFactory::create ( const QString& type ) -{ - if( type.isEmpty() && !s_factories.isEmpty() ) // default, return first - return geninterface_ptr( s_factories.begin().value()->create() ); - - if( !s_factories.contains( type ) ) - return geninterface_ptr(); - - return geninterface_ptr( s_factories.value( type )->create() ); -} - -void GeneratorFactory::registerFactory ( const QString& type, GeneratorFactoryInterface* interface ) -{ - s_factories.insert( type, interface ); -} - -QStringList GeneratorFactory::types() -{ - return s_factories.keys(); -} diff --git a/src/dynamic/GeneratorFactory.h b/src/dynamic/GeneratorFactory.h deleted file mode 100644 index 204c06ec4..000000000 --- a/src/dynamic/GeneratorFactory.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef GENERATOR_FACTORY_H -#define GENERATOR_FACTORY_H - -#include -#include - -#include "dynamic/GeneratorInterface.h" - -namespace Tomahawk { - -/** - * Generators should subclass this and have it create the custom Generator - */ -class GeneratorFactoryInterface -{ -public: - GeneratorFactoryInterface() {} - - virtual GeneratorInterface* create() = 0; -}; - -/** - * Simple factory that generates Generators from string type descriptors - */ -class GeneratorFactory -{ -public: - static geninterface_ptr create( const QString& type ); - static void registerFactory( const QString& type, GeneratorFactoryInterface* interface ); - static QStringList types(); - -private: - static QHash s_factories; - -}; - - -}; - -#endif diff --git a/src/dynamic/GeneratorInterface.cpp b/src/dynamic/GeneratorInterface.cpp deleted file mode 100644 index 1124a9cdc..000000000 --- a/src/dynamic/GeneratorInterface.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************************** - * Copyright (c) 2010 Leo Franchi * - * * - * This program 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 2 of the License, or (at your option) any later * - * version. * - * * - * This program 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 * - * this program. If not, see . * - ****************************************************************************************/ - -#include "dynamic/GeneratorInterface.h" - -// lame -Tomahawk::GeneratorInterface::GeneratorInterface() -{ - -} - -Tomahawk::GeneratorInterface::GeneratorInterface( QObject* parent ): QObject( parent ) -{ - -} - -Tomahawk::GeneratorInterface::~GeneratorInterface() -{ - -} - -QList< Tomahawk::dyncontrol_ptr > -Tomahawk::GeneratorInterface::controls() -{ - if( m_controls.isEmpty() ) { // return a default control (so the user can add more) - return QList< Tomahawk::dyncontrol_ptr >() << createControl(); - } - - return m_controls; -} - -void -Tomahawk::GeneratorInterface::addControl( const Tomahawk::dyncontrol_ptr& control ) -{ - m_controls << control; -} - -void -Tomahawk::GeneratorInterface::clearControls() -{ - m_controls.clear(); -} - -void -Tomahawk::GeneratorInterface::setControls( const QList< Tomahawk::dyncontrol_ptr >& controls ) -{ - m_controls = controls; -} - -Tomahawk::dyncontrol_ptr Tomahawk::GeneratorInterface::createControl(const QString& type) -{ - return dyncontrol_ptr(); -} - diff --git a/src/dynamic/GeneratorInterface.h b/src/dynamic/GeneratorInterface.h deleted file mode 100644 index 7956c4a4f..000000000 --- a/src/dynamic/GeneratorInterface.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************************** - * Copyright (c) 2010 Leo Franchi * - * * - * This program 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 2 of the License, or (at your option) any later * - * version. * - * * - * This program 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 * - * this program. If not, see . * - ****************************************************************************************/ - -#ifndef GENERATOR_INTERFACE_H -#define GENERATOR_INTERFACE_H - -#include -#include -#include - -#include "tomahawk/typedefs.h" -#include "tomahawk/query.h" -#include "dynamic/DynamicControl.h" - -namespace Tomahawk { - -/** - * The abstract interface for Dynamic Playlist Generators. Generators have the following features: - * - They create new DynamicControls that are appropriate for the generator - * - They expose a list of controls that this generator currently is operating on - * - They have a mode of OnDemand or Static - * - * And they generate tracks - */ -class GeneratorInterface : public QObject -{ - Q_OBJECT - Q_PROPERTY( QString type READ type ) - Q_PROPERTY( GeneratorMode mode READ mode WRITE setMode ) - Q_ENUMS( GeneratorMode ) - -public: - // can't inline constructors/destructors for forward declared shared pointer types - GeneratorInterface(); - explicit GeneratorInterface( QObject* parent = 0 ); - virtual ~GeneratorInterface(); - - // Can't make it pure otherwise we can't shove it in QVariants :-/ - // empty QString means use default - /// The generator will keep track of all the controls it creates. No need to tell it about controls - /// you ask it to create - virtual dyncontrol_ptr createControl( const QString& type = QString() ); - - /** - * Generate tracks from the controls in this playlist. If the current mode is - * OnDemand, then \p number is not taken into account. If this generator is in static - * mode, then it will return the desired number of tracks - * - * Connect to the generated() signal for the results. - * - */ - virtual void generate( int number = -1 ) {} - - /// The type of this generator - QString type() const { return m_type; } - - GeneratorMode mode() const { return m_mode; } - void setMode( GeneratorMode mode ) { m_mode = mode; } - - // control functions - QList< dyncontrol_ptr > controls(); - void addControl( const dyncontrol_ptr& control ); - void clearControls(); - void setControls( const QList< dyncontrol_ptr>& controls ); - - QStringList typeSelectors() const { return m_typeSelectors; } - -signals: - void generated( const QList< Tomahawk::query_ptr>& queries ); - -protected: - QString m_type; - GeneratorMode m_mode; - QList< dyncontrol_ptr > m_controls; - QStringList m_typeSelectors; -}; - -typedef QSharedPointer geninterface_ptr; - -}; - -#endif diff --git a/src/dynamic/echonest/EchonestControl.cpp b/src/dynamic/echonest/EchonestControl.cpp deleted file mode 100644 index 27d621a98..000000000 --- a/src/dynamic/echonest/EchonestControl.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************************** - * Copyright (c) 2010 Leo Franchi * - * * - * This program 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 2 of the License, or (at your option) any later * - * version. * - * * - * This program 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 * - * this program. If not, see . * - ****************************************************************************************/ - -#include "echonest/EchonestControl.h" - -#include - -#include -#include - - -Tomahawk::EchonestControl::EchonestControl( const QString& type, const QStringList& typeSelectors, QObject* parent ) - : DynamicControl ( type.isEmpty() ? "Artist" : type, typeSelectors, parent ) -{ - updateWidgets(); -} - -QWidget* -Tomahawk::EchonestControl::inputField() -{ - return m_input.data(); -} - -QWidget* -Tomahawk::EchonestControl::matchSelector() -{ - return m_match.data(); -} - -void -Tomahawk::EchonestControl::setSelectedType ( const QString& type ) -{ - if( !m_input.isNull() ) - delete m_input.data(); - if( !m_match.isNull() ) - delete m_match.data(); - - Tomahawk::DynamicControl::setSelectedType ( type ); - updateWidgets(); -} - -Echonest::DynamicPlaylist::PlaylistParamData -Tomahawk::EchonestControl::toENParam() const -{ - return m_data; -} - -void -Tomahawk::EchonestControl::updateWidgets() -{ - if( !m_input.isNull() ) - delete m_input.data(); - if( !m_match.isNull() ) - delete m_match.data(); - - // make sure the widgets are the proper kind for the selected type, and hook up to their slots - if( selectedType() == "Artist" ) { - m_currentType = Echonest::DynamicPlaylist::Artist; - - QComboBox* match = new QComboBox(); - QLineEdit* input = new QLineEdit(); - - match->addItem( "Limit To", Echonest::DynamicPlaylist::ArtistType ); - match->addItem( "Similar To", Echonest::DynamicPlaylist::ArtistRadioType ); - - input->setPlaceholderText( "Artist name" ); - input->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed ); - - connect( match, SIGNAL( currentIndexChanged(int) ), this, SLOT( updateData() ) ); - connect( input, SIGNAL( textChanged(QString) ), this, SLOT( updateData() ) ); - - match->hide(); - input->hide(); - m_match = QWeakPointer< QWidget >( match ); - m_input = QWeakPointer< QWidget >( input ); - } else { - m_match = QWeakPointer( new QWidget ); - m_input = QWeakPointer( new QWidget ); - } -} - -void -Tomahawk::EchonestControl::updateData() -{ - qDebug() << "Sender:" << sender() << qobject_cast(sender()) << m_input << qobject_cast(m_input.data()); - if( selectedType() == "Artist" ) { - QComboBox* combo = qobject_cast( m_match.data() ); - if( combo ) { - } - QLineEdit* edit = qobject_cast( m_input.data() ); - if( edit && !edit->text().isEmpty() ) { - m_data.first = m_currentType; - m_data.second = edit->text(); - } - } -} diff --git a/src/dynamic/echonest/EchonestControl.h b/src/dynamic/echonest/EchonestControl.h deleted file mode 100644 index 1215ce69e..000000000 --- a/src/dynamic/echonest/EchonestControl.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************************** - * Copyright (c) 2010 Leo Franchi * - * * - * This program 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 2 of the License, or (at your option) any later * - * version. * - * * - * This program 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 * - * this program. If not, see . * - ****************************************************************************************/ - -#ifndef ECHONEST_CONTROL_H -#define ECHONEST_CONTROL_H - -#include - -#include "dynamic/DynamicControl.h" - -namespace Tomahawk -{ - -class EchonestControl : public DynamicControl -{ - Q_OBJECT -public: - virtual QWidget* inputField(); - virtual QWidget* matchSelector(); - - /// Converts this to an echonest suitable parameter - Echonest::DynamicPlaylist::PlaylistParamData toENParam() const; - -public slots: - virtual void setSelectedType ( const QString& type ); - -private slots: - void updateData(); - -protected: - explicit EchonestControl( const QString& type, const QStringList& typeSelectors, QObject* parent = 0 ); - -private: - void updateWidgets(); - - Echonest::DynamicPlaylist::PlaylistParam m_currentType; - - QWeakPointer< QWidget > m_input; - QWeakPointer< QWidget > m_match; - - Echonest::DynamicPlaylist::PlaylistParamData m_data; - - friend class EchonestGenerator; -}; - -typedef QSharedPointer encontrol_ptr; - -}; - -#endif diff --git a/src/dynamic/echonest/EchonestGenerator.cpp b/src/dynamic/echonest/EchonestGenerator.cpp deleted file mode 100644 index 783e7f922..000000000 --- a/src/dynamic/echonest/EchonestGenerator.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************************** - * Copyright (c) 2010 Leo Franchi * - * * - * This program 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 2 of the License, or (at your option) any later * - * version. * - * * - * This program 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 * - * this program. If not, see . * - ****************************************************************************************/ - -#include "echonest/EchonestGenerator.h" -#include "echonest/EchonestControl.h" -#include "tomahawk/query.h" - -using namespace Tomahawk; - - -EchonestFactory::EchonestFactory() -{} - -GeneratorInterface* -EchonestFactory::create() -{ - return new EchonestGenerator(); -} - -EchonestGenerator::EchonestGenerator ( QObject* parent ) - : GeneratorInterface ( parent ) -{ - m_typeSelectors << "Artist" << "Variety" << "Description" << "Tempo" << "Duration" << "Loudness" - << "Danceability" << "Energy" << "Artist Familiarity" << "Artist Hotttnesss" << "Song Familiarity" - << "Longitude" << "Latitude" << "Mode" << "Key" << "Sorting"; - m_type = "echonest"; - m_mode = OnDemand; - -} - -EchonestGenerator::~EchonestGenerator() -{ - -} - -dyncontrol_ptr -EchonestGenerator::createControl( const QString& type ) -{ - m_controls << dyncontrol_ptr( new EchonestControl( type, m_typeSelectors ) ); - return m_controls.last(); -} - -void -EchonestGenerator::generate ( int number ) -{ - // convert to an echonest query, and fire it off - if( number < 0 ) { // dynamic - - } else { // static - Echonest::DynamicPlaylist::PlaylistParams params; - foreach( const dyncontrol_ptr& control, m_controls ) { - params.append( control.dynamicCast()->toENParam() ); - } - params.append( Echonest::DynamicPlaylist::PlaylistParamData( Echonest::DynamicPlaylist::Type, determineRadioType() ) ); - params.append( Echonest::DynamicPlaylist::PlaylistParamData( Echonest::DynamicPlaylist::Results, number ) ); - QNetworkReply* reply = Echonest::DynamicPlaylist::staticPlaylist( params ); - qDebug() << "Generating a static playlist from echonest!" << reply->url().toString(); - connect( reply, SIGNAL( finished() ), this, SLOT( staticFinished() ) ); - } -} - -void -EchonestGenerator::staticFinished() -{ - Q_ASSERT( sender() ); - Q_ASSERT( qobject_cast< QNetworkReply* >( sender() ) ); - - QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() ); - - Echonest::SongList songs; - try { - songs = Echonest::DynamicPlaylist::parseStaticPlaylist( reply ); - } catch( const Echonest::ParseError& e ) { - qWarning() << "libechonest threw an error trying to parse the static playlist!" << e.errorType() << e.what(); - - return; - } - - QList< query_ptr > queries; - foreach( const Echonest::Song& song, songs ) { - qDebug() << "EchonestGenerator got song:" << song; - QVariantMap track; - track[ "artist" ] = song.artistName(); -// track[ "album" ] = song.release(); // TODO should we include it? can be quite specific - track[ "track" ] = song.title(); - queries << query_ptr( new Query( track ) ); - } - - emit generated( queries ); -} - - -// tries to heuristically determine what sort of radio this is based on the controls -Echonest::DynamicPlaylist::ArtistTypeEnum EchonestGenerator::determineRadioType() const -{ - // TODO - return Echonest::DynamicPlaylist::ArtistRadioType; -} - diff --git a/src/dynamic/echonest/EchonestGenerator.h b/src/dynamic/echonest/EchonestGenerator.h deleted file mode 100644 index cfbdd5b05..000000000 --- a/src/dynamic/echonest/EchonestGenerator.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************************** - * Copyright (c) 2010 Leo Franchi * - * * - * This program 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 2 of the License, or (at your option) any later * - * version. * - * * - * This program 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 * - * this program. If not, see . * - ****************************************************************************************/ - -#ifndef ECHONEST_GENERATOR_H -#define ECHONEST_GENERATOR_H - -#include - -#include "dynamic/GeneratorInterface.h" -#include "dynamic/GeneratorFactory.h" -#include "dynamic/DynamicControl.h" - -namespace Tomahawk -{ - -class EchonestFactory : public GeneratorFactoryInterface -{ -public: - EchonestFactory(); - - virtual GeneratorInterface* create(); - -}; - -class EchonestGenerator : public GeneratorInterface -{ - Q_OBJECT -public: - explicit EchonestGenerator( QObject* parent = 0 ); - virtual ~EchonestGenerator(); - - virtual dyncontrol_ptr createControl( const QString& type = QString() ); - - virtual void generate ( int number = -1 ); - -private slots: - void staticFinished(); - -private: - Echonest::DynamicPlaylist::ArtistTypeEnum determineRadioType() const; -}; - -}; - -#endif diff --git a/src/dynamic/widgets/DynamicControlList.cpp b/src/dynamic/widgets/DynamicControlList.cpp index 51fa1ab67..b5b0d6287 100644 --- a/src/dynamic/widgets/DynamicControlList.cpp +++ b/src/dynamic/widgets/DynamicControlList.cpp @@ -22,7 +22,7 @@ #include #include "DynamicControlWidget.h" -#include "GeneratorInterface.h" +#include "dynamic/GeneratorInterface.h" using namespace Tomahawk; diff --git a/src/dynamic/widgets/DynamicControlList.h b/src/dynamic/widgets/DynamicControlList.h index 4a90b3256..436a47909 100644 --- a/src/dynamic/widgets/DynamicControlList.h +++ b/src/dynamic/widgets/DynamicControlList.h @@ -18,7 +18,7 @@ #define DYNAMIC_CONTROL_LIST_H #include "animatedsplitter.h" -#include "tomahawk/typedefs.h" +#include "typedefs.h" #include "dynamic/DynamicPlaylist.h" class QVBoxLayout; diff --git a/src/dynamic/widgets/DynamicControlWidget.h b/src/dynamic/widgets/DynamicControlWidget.h index f0fca3ee3..00da98041 100644 --- a/src/dynamic/widgets/DynamicControlWidget.h +++ b/src/dynamic/widgets/DynamicControlWidget.h @@ -19,7 +19,7 @@ #include -#include "tomahawk/typedefs.h" +#include "typedefs.h" class QStackedLayout; class QEvent; diff --git a/src/dynamic/widgets/DynamicWidget.cpp b/src/dynamic/widgets/DynamicWidget.cpp index 65b56fa03..5a1809a91 100644 --- a/src/dynamic/widgets/DynamicWidget.cpp +++ b/src/dynamic/widgets/DynamicWidget.cpp @@ -18,15 +18,15 @@ #include #include +#include +#include #include "DynamicControlList.h" #include "playlistview.h" #include "playlistmodel.h" #include "trackproxymodel.h" #include "dynamic/GeneratorInterface.h" -#include #include "dynamic/GeneratorFactory.h" -#include using namespace Tomahawk; diff --git a/src/dynamic/widgets/DynamicWidget.h b/src/dynamic/widgets/DynamicWidget.h index 2e32ead55..490ea354e 100644 --- a/src/dynamic/widgets/DynamicWidget.h +++ b/src/dynamic/widgets/DynamicWidget.h @@ -18,7 +18,7 @@ #define DYNAMIC_WIDGET_H #include -#include +#include class QVBoxLayout; class QHBoxLayout; diff --git a/src/infosystem/infoplugins/echonestplugin.h b/src/infosystem/infoplugins/echonestplugin.h index 8ffb120b2..89d4a15ce 100644 --- a/src/infosystem/infoplugins/echonestplugin.h +++ b/src/infosystem/infoplugins/echonestplugin.h @@ -1,7 +1,10 @@ #ifndef ECHONESTPLUGIN_H #define ECHONESTPLUGIN_H + #include "tomahawk/infosystem.h" +#include + class QNetworkReply; namespace Echonest { class Artist; diff --git a/src/infowidgets/sourceinfowidget.h b/src/infowidgets/sourceinfowidget.h index c16b55b37..0af88baa6 100644 --- a/src/infowidgets/sourceinfowidget.h +++ b/src/infowidgets/sourceinfowidget.h @@ -3,9 +3,9 @@ #include -#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; diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt new file mode 100644 index 000000000..c74c7a826 --- /dev/null +++ b/src/libtomahawk/CMakeLists.txt @@ -0,0 +1,177 @@ +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/databasecommand_setdynamicplaylistrevision.cpp + database/databasecommand_createdynamicplaylist.cpp + database/databasecommand_loaddynamicplaylist.cpp + database/databasecommand_loadalldynamicplaylists.cpp + database/databasecommand_deletedynamicplaylist.cpp + + dynamic/DynamicPlaylist.cpp + dynamic/DynamicControl.cpp + dynamic/GeneratorFactory.cpp + dynamic/GeneratorInterface.cpp + dynamic/echonest/EchonestGenerator.cpp + dynamic/echonest/EchonestControl.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 + database/databasecommand_setdynamicplaylistrevision.h + database/databasecommand_createdynamicplaylist.h + database/databasecommand_loaddynamicplaylist.h + database/databasecommand_deletedynamicplaylist.h + database/databasecommand_loadalldynamicplaylists.h + + dynamic/DynamicPlaylist.h + dynamic/DynamicControl.h + dynamic/GeneratorFactory.h + dynamic/GeneratorInterface.h + dynamic/echonest/EchonestGenerator.h + dynamic/echonest/EchonestControl.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} + ${LIBECHONEST_INCLUDE_DIR} + ${LIBECHONEST_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} + ${LIBECHONEST_LIBRARY} + portfwd + qjson +) + +install( TARGETS tomahawklib DESTINATION lib ) diff --git a/src/album.cpp b/src/libtomahawk/album.cpp similarity index 91% rename from src/album.cpp rename to src/libtomahawk/album.cpp index 110bf755b..a2032a858 100644 --- a/src/album.cpp +++ b/src/libtomahawk/album.cpp @@ -1,9 +1,8 @@ -#include "tomahawk/album.h" +#include "album.h" #include -#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::collection_ptr ) ), SLOT( onTracksAdded( QList, Tomahawk::collection_ptr ) ) ); - APP->database()->enqueue( QSharedPointer( cmd ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); } return m_queries; diff --git a/include/tomahawk/album.h b/src/libtomahawk/album.h similarity index 90% rename from include/tomahawk/album.h rename to src/libtomahawk/album.h index 9267b62d8..a1c6834b5 100644 --- a/include/tomahawk/album.h +++ b/src/libtomahawk/album.h @@ -4,16 +4,17 @@ #include #include -#include "tomahawk/typedefs.h" -#include "tomahawk/artist.h" -#include "tomahawk/collection.h" +#include "typedefs.h" +#include "artist.h" +#include "collection.h" +#include "playlistinterface.h" -#include "tomahawk/playlistinterface.h" +#include "dllmacro.h" namespace Tomahawk { -class Album : public QObject, public PlaylistInterface +class DLLEXPORT Album : public QObject, public PlaylistInterface { Q_OBJECT diff --git a/src/artist.cpp b/src/libtomahawk/artist.cpp similarity index 80% rename from src/artist.cpp rename to src/libtomahawk/artist.cpp index 1933750b1..224f43369 100644 --- a/src/artist.cpp +++ b/src/libtomahawk/artist.cpp @@ -1,14 +1,16 @@ -#include "tomahawk/artist.h" +#include "artist.h" #include -#include "tomahawk/collection.h" -#include "tomahawk/tomahawkapp.h" +#include "collection.h" #include "database/database.h" #include "database/databasecommand_alltracks.h" using namespace Tomahawk; +Artist::Artist() {} + +Artist::~Artist() {} artist_ptr Artist::get( unsigned int id, const QString& name, const Tomahawk::collection_ptr& collection ) @@ -33,3 +35,10 @@ Artist::Artist( unsigned int id, const QString& name, const Tomahawk::collection , m_collection( collection ) { } + + +Tomahawk::collection_ptr +Artist::collection() const +{ + return m_collection; +} \ No newline at end of file diff --git a/include/tomahawk/artist.h b/src/libtomahawk/artist.h similarity index 79% rename from include/tomahawk/artist.h rename to src/libtomahawk/artist.h index 645011e40..d7d162db0 100644 --- a/include/tomahawk/artist.h +++ b/src/libtomahawk/artist.h @@ -4,25 +4,26 @@ #include #include -#include "tomahawk/typedefs.h" -#include "tomahawk/collection.h" +#include "typedefs.h" +#include "dllmacro.h" namespace Tomahawk { -class Artist : public QObject +class DLLEXPORT Artist : public QObject { Q_OBJECT public: static artist_ptr get( unsigned int id, const QString& name, const Tomahawk::collection_ptr& collection ); - + Artist(); Artist( unsigned int id, const QString& name, const Tomahawk::collection_ptr& collection ); - + virtual ~Artist(); + unsigned int id() const { return m_id; } QString name() const { return m_name; } - Tomahawk::collection_ptr collection() const { return m_collection; } + Tomahawk::collection_ptr collection() const; // QList tracks(); // virtual int trackCount() const { return 0; } diff --git a/src/collection.cpp b/src/libtomahawk/collection.cpp similarity index 98% rename from src/collection.cpp rename to src/libtomahawk/collection.cpp index f578b16a4..674a72643 100644 --- a/src/collection.cpp +++ b/src/libtomahawk/collection.cpp @@ -1,10 +1,10 @@ -#include "tomahawk/collection.h" +#include "collection.h" #include #include -#include "tomahawk/playlist.h" #include "dynamic/DynamicPlaylist.h" +#include "playlist.h" using namespace Tomahawk; diff --git a/include/tomahawk/collection.h b/src/libtomahawk/collection.h similarity index 95% rename from include/tomahawk/collection.h rename to src/libtomahawk/collection.h index f8944083b..b2024176d 100644 --- a/include/tomahawk/collection.h +++ b/src/libtomahawk/collection.h @@ -13,17 +13,18 @@ #include #include -#include "tomahawk/functimeout.h" -#include "tomahawk/query.h" -#include "tomahawk/source.h" -#include "tomahawk/typedefs.h" +#include "functimeout.h" +#include "playlist.h" +#include "source.h" #include "typedefs.h" #include "dynamic/DynamicPlaylist.h" +#include "dllmacro.h" + namespace Tomahawk { -class Collection : public QObject +class DLLEXPORT Collection : public QObject { Q_OBJECT diff --git a/src/database/README.txt b/src/libtomahawk/database/README.txt similarity index 100% rename from src/database/README.txt rename to src/libtomahawk/database/README.txt diff --git a/src/database/database.cpp b/src/libtomahawk/database/database.cpp similarity index 88% rename from src/database/database.cpp rename to src/libtomahawk/database/database.cpp index e415e1650..59a3f540c 100644 --- a/src/database/database.cpp +++ b/src/libtomahawk/database/database.cpp @@ -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(); } diff --git a/src/database/database.h b/src/libtomahawk/database/database.h similarity index 82% rename from src/database/database.h rename to src/libtomahawk/database/database.h index 4b388f223..b62ebe050 100644 --- a/src/database/database.h +++ b/src/libtomahawk/database/database.h @@ -4,9 +4,11 @@ #include #include -#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 diff --git a/src/database/databasecollection.cpp b/src/libtomahawk/database/databasecollection.cpp similarity index 86% rename from src/database/databasecollection.cpp rename to src/libtomahawk/database/databasecollection.cpp index 5915f0378..483860450 100644 --- a/src/database/databasecollection.cpp +++ b/src/libtomahawk/database/databasecollection.cpp @@ -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" @@ -25,7 +24,7 @@ DatabaseCollection::loadPlaylists() connect( cmd, SIGNAL( done( const QList& ) ), SLOT( setPlaylists( const QList& ) ) ); - TomahawkApp::instance()->database()->enqueue( QSharedPointer( cmd ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); } void @@ -37,7 +36,7 @@ DatabaseCollection::loadDynamicPlaylists() connect( cmd, SIGNAL( done( const QList& ) ), SLOT( setDynamicPlaylists( const QList& ) ) ); - TomahawkApp::instance()->database()->enqueue( QSharedPointer( cmd ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); } @@ -53,7 +52,7 @@ DatabaseCollection::loadTracks() /* connect( cmd, SIGNAL( done( Tomahawk::collection_ptr ) ), SIGNAL( tracksFinished( Tomahawk::collection_ptr ) ) );*/ - TomahawkApp::instance()->database()->enqueue( QSharedPointer( cmd ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); } @@ -63,7 +62,7 @@ DatabaseCollection::addTracks( const QList &newitems ) qDebug() << Q_FUNC_INFO << newitems.length(); DatabaseCommand_AddFiles* cmd = new DatabaseCommand_AddFiles( newitems, source() ); - TomahawkApp::instance()->database()->enqueue( QSharedPointer( cmd ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); } diff --git a/src/database/databasecollection.h b/src/libtomahawk/database/databasecollection.h similarity index 84% rename from src/database/databasecollection.h rename to src/libtomahawk/database/databasecollection.h index 0a305b03f..95063ae83 100644 --- a/src/database/databasecollection.h +++ b/src/libtomahawk/database/databasecollection.h @@ -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 diff --git a/src/database/databasecommand.cpp b/src/libtomahawk/database/databasecommand.cpp similarity index 100% rename from src/database/databasecommand.cpp rename to src/libtomahawk/database/databasecommand.cpp diff --git a/src/database/databasecommand.h b/src/libtomahawk/database/databasecommand.h similarity index 94% rename from src/database/databasecommand.h rename to src/libtomahawk/database/databasecommand.h index 9aa0fd020..d747769da 100644 --- a/src/database/databasecommand.h +++ b/src/libtomahawk/database/databasecommand.h @@ -6,13 +6,15 @@ #include #include -#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 ) diff --git a/src/database/databasecommand_addfiles.cpp b/src/libtomahawk/database/databasecommand_addfiles.cpp similarity index 96% rename from src/database/databasecommand_addfiles.cpp rename to src/libtomahawk/database/databasecommand_addfiles.cpp index 942df663a..c4cabccc5 100644 --- a/src/database/databasecommand_addfiles.cpp +++ b/src/libtomahawk/database/databasecommand_addfiles.cpp @@ -2,12 +2,11 @@ #include -#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( cmd ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); if( source()->isLocal() ) - APP->servent().triggerDBSync(); + Servent::instance()->triggerDBSync(); } diff --git a/src/database/databasecommand_addfiles.h b/src/libtomahawk/database/databasecommand_addfiles.h similarity index 90% rename from src/database/databasecommand_addfiles.h rename to src/libtomahawk/database/databasecommand_addfiles.h index bfd6a368e..d3193c54f 100644 --- a/src/database/databasecommand_addfiles.h +++ b/src/libtomahawk/database/databasecommand_addfiles.h @@ -5,9 +5,11 @@ #include #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 ) diff --git a/src/database/databasecommand_addsource.cpp b/src/libtomahawk/database/databasecommand_addsource.cpp similarity index 100% rename from src/database/databasecommand_addsource.cpp rename to src/libtomahawk/database/databasecommand_addsource.cpp diff --git a/src/database/databasecommand_addsource.h b/src/libtomahawk/database/databasecommand_addsource.h similarity index 86% rename from src/database/databasecommand_addsource.h rename to src/libtomahawk/database/databasecommand_addsource.h index a45fcfa4e..aa657aae8 100644 --- a/src/database/databasecommand_addsource.h +++ b/src/libtomahawk/database/databasecommand_addsource.h @@ -6,7 +6,9 @@ #include "databasecommand.h" -class DatabaseCommand_addSource : public DatabaseCommand +#include "dllmacro.h" + +class DLLEXPORT DatabaseCommand_addSource : public DatabaseCommand { Q_OBJECT diff --git a/src/database/databasecommand_allalbums.cpp b/src/libtomahawk/database/databasecommand_allalbums.cpp similarity index 100% rename from src/database/databasecommand_allalbums.cpp rename to src/libtomahawk/database/databasecommand_allalbums.cpp diff --git a/src/database/databasecommand_allalbums.h b/src/libtomahawk/database/databasecommand_allalbums.h similarity index 89% rename from src/database/databasecommand_allalbums.h rename to src/libtomahawk/database/databasecommand_allalbums.h index 69ec71ced..37b6d0db2 100644 --- a/src/database/databasecommand_allalbums.h +++ b/src/libtomahawk/database/databasecommand_allalbums.h @@ -5,11 +5,13 @@ #include #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: diff --git a/src/database/databasecommand_alltracks.cpp b/src/libtomahawk/database/databasecommand_alltracks.cpp similarity index 100% rename from src/database/databasecommand_alltracks.cpp rename to src/libtomahawk/database/databasecommand_alltracks.cpp diff --git a/src/database/databasecommand_alltracks.h b/src/libtomahawk/database/databasecommand_alltracks.h similarity index 90% rename from src/database/databasecommand_alltracks.h rename to src/libtomahawk/database/databasecommand_alltracks.h index 80ec99361..7cdc6dfd9 100644 --- a/src/database/databasecommand_alltracks.h +++ b/src/libtomahawk/database/databasecommand_alltracks.h @@ -5,11 +5,13 @@ #include #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: diff --git a/src/database/databasecommand_collectionstats.cpp b/src/libtomahawk/database/databasecommand_collectionstats.cpp similarity index 100% rename from src/database/databasecommand_collectionstats.cpp rename to src/libtomahawk/database/databasecommand_collectionstats.cpp diff --git a/src/database/databasecommand_collectionstats.h b/src/libtomahawk/database/databasecommand_collectionstats.h similarity index 79% rename from src/database/databasecommand_collectionstats.h rename to src/libtomahawk/database/databasecommand_collectionstats.h index 50dcee941..1c14a3eb4 100644 --- a/src/database/databasecommand_collectionstats.h +++ b/src/libtomahawk/database/databasecommand_collectionstats.h @@ -4,10 +4,12 @@ #include #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 diff --git a/src/database/databasecommand_createdynamicplaylist.cpp b/src/libtomahawk/database/databasecommand_createdynamicplaylist.cpp similarity index 96% rename from src/database/databasecommand_createdynamicplaylist.cpp rename to src/libtomahawk/database/databasecommand_createdynamicplaylist.cpp index cc3120470..19a9ab829 100644 --- a/src/database/databasecommand_createdynamicplaylist.cpp +++ b/src/libtomahawk/database/databasecommand_createdynamicplaylist.cpp @@ -3,11 +3,12 @@ #include #include -#include "tomahawk/tomahawkapp.h" #include "dynamic/DynamicPlaylist.h" #include "dynamic/DynamicControl.h" #include "dynamic/GeneratorInterface.h" +#include "network/servent.h" + using namespace Tomahawk; @@ -73,5 +74,5 @@ DatabaseCommand_CreateDynamicPlaylist::postCommitHook() m_playlist->reportCreated( m_playlist ); if( source()->isLocal() ) - APP->servent().triggerDBSync(); + Servent::instance()->triggerDBSync(); } diff --git a/src/database/databasecommand_createdynamicplaylist.h b/src/libtomahawk/database/databasecommand_createdynamicplaylist.h similarity index 97% rename from src/database/databasecommand_createdynamicplaylist.h rename to src/libtomahawk/database/databasecommand_createdynamicplaylist.h index aab3673d3..e1116e9e7 100644 --- a/src/database/databasecommand_createdynamicplaylist.h +++ b/src/libtomahawk/database/databasecommand_createdynamicplaylist.h @@ -4,7 +4,7 @@ #include "databaseimpl.h" #include "databasecommand_createplaylist.h" #include "dynamic/DynamicPlaylist.h" -#include "tomahawk/typedefs.h" +#include "typedefs.h" class DatabaseCommand_CreateDynamicPlaylist : public DatabaseCommand_CreatePlaylist { diff --git a/src/database/databasecommand_createplaylist.cpp b/src/libtomahawk/database/databasecommand_createplaylist.cpp similarity index 96% rename from src/database/databasecommand_createplaylist.cpp rename to src/libtomahawk/database/databasecommand_createplaylist.cpp index 13d35144e..f8fd377ff 100644 --- a/src/database/databasecommand_createplaylist.cpp +++ b/src/libtomahawk/database/databasecommand_createplaylist.cpp @@ -2,7 +2,7 @@ #include -#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(); } diff --git a/src/database/databasecommand_createplaylist.h b/src/libtomahawk/database/databasecommand_createplaylist.h similarity index 89% rename from src/database/databasecommand_createplaylist.h rename to src/libtomahawk/database/databasecommand_createplaylist.h index 69118dd79..a7fccda36 100644 --- a/src/database/databasecommand_createplaylist.h +++ b/src/libtomahawk/database/databasecommand_createplaylist.h @@ -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 ) diff --git a/src/database/databasecommand_deleteplaylist.cpp b/src/libtomahawk/database/databasecommand_deleteplaylist.cpp similarity index 93% rename from src/database/databasecommand_deleteplaylist.cpp rename to src/libtomahawk/database/databasecommand_deleteplaylist.cpp index 840fbb019..2f85a5a0e 100644 --- a/src/database/databasecommand_deleteplaylist.cpp +++ b/src/libtomahawk/database/databasecommand_deleteplaylist.cpp @@ -2,7 +2,7 @@ #include -#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(); } diff --git a/src/database/databasecommand_deleteplaylist.h b/src/libtomahawk/database/databasecommand_deleteplaylist.h similarity index 85% rename from src/database/databasecommand_deleteplaylist.h rename to src/libtomahawk/database/databasecommand_deleteplaylist.h index 84d069750..838f6fd46 100644 --- a/src/database/databasecommand_deleteplaylist.h +++ b/src/libtomahawk/database/databasecommand_deleteplaylist.h @@ -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 ) diff --git a/src/database/databasecommand_dirmtimes.cpp b/src/libtomahawk/database/databasecommand_dirmtimes.cpp similarity index 100% rename from src/database/databasecommand_dirmtimes.cpp rename to src/libtomahawk/database/databasecommand_dirmtimes.cpp diff --git a/src/database/databasecommand_dirmtimes.h b/src/libtomahawk/database/databasecommand_dirmtimes.h similarity index 92% rename from src/database/databasecommand_dirmtimes.h rename to src/libtomahawk/database/databasecommand_dirmtimes.h index bc9ba4bef..9071599e0 100644 --- a/src/database/databasecommand_dirmtimes.h +++ b/src/libtomahawk/database/databasecommand_dirmtimes.h @@ -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 diff --git a/src/database/databasecommand_importplaylist.cpp b/src/libtomahawk/database/databasecommand_importplaylist.cpp similarity index 100% rename from src/database/databasecommand_importplaylist.cpp rename to src/libtomahawk/database/databasecommand_importplaylist.cpp diff --git a/src/database/databasecommand_importplaylist.h b/src/libtomahawk/database/databasecommand_importplaylist.h similarity index 86% rename from src/database/databasecommand_importplaylist.h rename to src/libtomahawk/database/databasecommand_importplaylist.h index 19832a4d2..62e3a5d3f 100644 --- a/src/database/databasecommand_importplaylist.h +++ b/src/libtomahawk/database/databasecommand_importplaylist.h @@ -1,13 +1,17 @@ #ifndef DATABASECOMMAND_IMPORTPLAYLIST_H #define DATABASECOMMAND_IMPORTPLAYLIST_H + #include #include + #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: diff --git a/src/database/databasecommand_loadallplaylists.cpp b/src/libtomahawk/database/databasecommand_loadallplaylists.cpp similarity index 97% rename from src/database/databasecommand_loadallplaylists.cpp rename to src/libtomahawk/database/databasecommand_loadallplaylists.cpp index fe42e7f86..78967383d 100644 --- a/src/database/databasecommand_loadallplaylists.cpp +++ b/src/libtomahawk/database/databasecommand_loadallplaylists.cpp @@ -2,7 +2,7 @@ #include -#include "tomahawk/playlist.h" +#include "playlist.h" #include "databaseimpl.h" using namespace Tomahawk; diff --git a/src/database/databasecommand_loadallplaylists.h b/src/libtomahawk/database/databasecommand_loadallplaylists.h similarity index 83% rename from src/database/databasecommand_loadallplaylists.h rename to src/libtomahawk/database/databasecommand_loadallplaylists.h index 371651eea..2738f26df 100644 --- a/src/database/databasecommand_loadallplaylists.h +++ b/src/libtomahawk/database/databasecommand_loadallplaylists.h @@ -5,9 +5,11 @@ #include #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 diff --git a/src/database/databasecommand_loadfile.cpp b/src/libtomahawk/database/databasecommand_loadfile.cpp similarity index 94% rename from src/database/databasecommand_loadfile.cpp rename to src/libtomahawk/database/databasecommand_loadfile.cpp index 2542eda70..6b1870e26 100644 --- a/src/database/databasecommand_loadfile.cpp +++ b/src/libtomahawk/database/databasecommand_loadfile.cpp @@ -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 ) diff --git a/src/database/databasecommand_loadfile.h b/src/libtomahawk/database/databasecommand_loadfile.h similarity index 86% rename from src/database/databasecommand_loadfile.h rename to src/libtomahawk/database/databasecommand_loadfile.h index f4d596ea7..7cc2fdf89 100644 --- a/src/database/databasecommand_loadfile.h +++ b/src/libtomahawk/database/databasecommand_loadfile.h @@ -7,7 +7,9 @@ #include "databasecommand.h" -class DatabaseCommand_LoadFile : public DatabaseCommand +#include "dllmacro.h" + +class DLLEXPORT DatabaseCommand_LoadFile : public DatabaseCommand { Q_OBJECT diff --git a/src/database/databasecommand_loadops.cpp b/src/libtomahawk/database/databasecommand_loadops.cpp similarity index 100% rename from src/database/databasecommand_loadops.cpp rename to src/libtomahawk/database/databasecommand_loadops.cpp diff --git a/src/database/databasecommand_loadops.h b/src/libtomahawk/database/databasecommand_loadops.h similarity index 85% rename from src/database/databasecommand_loadops.h rename to src/libtomahawk/database/databasecommand_loadops.h index f6e11b09a..15c015e1d 100644 --- a/src/database/databasecommand_loadops.h +++ b/src/libtomahawk/database/databasecommand_loadops.h @@ -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: diff --git a/src/database/databasecommand_loadplaylistentries.cpp b/src/libtomahawk/database/databasecommand_loadplaylistentries.cpp similarity index 100% rename from src/database/databasecommand_loadplaylistentries.cpp rename to src/libtomahawk/database/databasecommand_loadplaylistentries.cpp diff --git a/src/database/databasecommand_loadplaylistentries.h b/src/libtomahawk/database/databasecommand_loadplaylistentries.h similarity index 89% rename from src/database/databasecommand_loadplaylistentries.h rename to src/libtomahawk/database/databasecommand_loadplaylistentries.h index 86605826e..4ddc6f0af 100644 --- a/src/database/databasecommand_loadplaylistentries.h +++ b/src/libtomahawk/database/databasecommand_loadplaylistentries.h @@ -5,9 +5,11 @@ #include #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 diff --git a/src/database/databasecommand_modifyplaylist.cpp b/src/libtomahawk/database/databasecommand_modifyplaylist.cpp similarity index 100% rename from src/database/databasecommand_modifyplaylist.cpp rename to src/libtomahawk/database/databasecommand_modifyplaylist.cpp diff --git a/src/database/databasecommand_modifyplaylist.h b/src/libtomahawk/database/databasecommand_modifyplaylist.h similarity index 85% rename from src/database/databasecommand_modifyplaylist.h rename to src/libtomahawk/database/databasecommand_modifyplaylist.h index 9bae6f0d4..e967bdb29 100644 --- a/src/database/databasecommand_modifyplaylist.h +++ b/src/libtomahawk/database/databasecommand_modifyplaylist.h @@ -5,10 +5,12 @@ #include #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 ) diff --git a/src/database/databasecommand_renameplaylist.cpp b/src/libtomahawk/database/databasecommand_renameplaylist.cpp similarity index 93% rename from src/database/databasecommand_renameplaylist.cpp rename to src/libtomahawk/database/databasecommand_renameplaylist.cpp index 51da0ff6d..9b3737ae9 100644 --- a/src/database/databasecommand_renameplaylist.cpp +++ b/src/libtomahawk/database/databasecommand_renameplaylist.cpp @@ -2,7 +2,7 @@ #include -#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(); } diff --git a/src/database/databasecommand_renameplaylist.h b/src/libtomahawk/database/databasecommand_renameplaylist.h similarity index 88% rename from src/database/databasecommand_renameplaylist.h rename to src/libtomahawk/database/databasecommand_renameplaylist.h index a5e3c186e..c6692dcff 100644 --- a/src/database/databasecommand_renameplaylist.h +++ b/src/libtomahawk/database/databasecommand_renameplaylist.h @@ -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 ) diff --git a/src/database/databasecommand_resolve.cpp b/src/libtomahawk/database/databasecommand_resolve.cpp similarity index 97% rename from src/database/databasecommand_resolve.cpp rename to src/libtomahawk/database/databasecommand_resolve.cpp index bd28d6f0d..0bd1f915d 100644 --- a/src/database/databasecommand_resolve.cpp +++ b/src/libtomahawk/database/databasecommand_resolve.cpp @@ -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(); diff --git a/src/database/databasecommand_resolve.h b/src/libtomahawk/database/databasecommand_resolve.h similarity index 96% rename from src/database/databasecommand_resolve.h rename to src/libtomahawk/database/databasecommand_resolve.h index 26945698a..81ab23263 100644 --- a/src/database/databasecommand_resolve.h +++ b/src/libtomahawk/database/databasecommand_resolve.h @@ -3,11 +3,13 @@ #include "databasecommand.h" #include "databaseimpl.h" -#include "tomahawk/result.h" +#include "result.h" #include -class DatabaseCommand_Resolve : public DatabaseCommand +#include "dllmacro.h" + +class DLLEXPORT DatabaseCommand_Resolve : public DatabaseCommand { Q_OBJECT public: diff --git a/src/database/databasecommand_setplaylistrevision.cpp b/src/libtomahawk/database/databasecommand_setplaylistrevision.cpp similarity index 98% rename from src/database/databasecommand_setplaylistrevision.cpp rename to src/libtomahawk/database/databasecommand_setplaylistrevision.cpp index 6d5bd7562..2f60afcb5 100644 --- a/src/database/databasecommand_setplaylistrevision.cpp +++ b/src/libtomahawk/database/databasecommand_setplaylistrevision.cpp @@ -3,7 +3,7 @@ #include #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(); } diff --git a/src/database/databasecommand_setplaylistrevision.h b/src/libtomahawk/database/databasecommand_setplaylistrevision.h similarity index 94% rename from src/database/databasecommand_setplaylistrevision.h rename to src/libtomahawk/database/databasecommand_setplaylistrevision.h index 23b97deb2..cc193bbb6 100644 --- a/src/database/databasecommand_setplaylistrevision.h +++ b/src/libtomahawk/database/databasecommand_setplaylistrevision.h @@ -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 ) diff --git a/src/database/databasecommand_sourceoffline.cpp b/src/libtomahawk/database/databasecommand_sourceoffline.cpp similarity index 100% rename from src/database/databasecommand_sourceoffline.cpp rename to src/libtomahawk/database/databasecommand_sourceoffline.cpp diff --git a/src/database/databasecommand_sourceoffline.h b/src/libtomahawk/database/databasecommand_sourceoffline.h similarity index 79% rename from src/database/databasecommand_sourceoffline.h rename to src/libtomahawk/database/databasecommand_sourceoffline.h index c5988d378..02ccc1571 100644 --- a/src/database/databasecommand_sourceoffline.h +++ b/src/libtomahawk/database/databasecommand_sourceoffline.h @@ -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 diff --git a/src/database/databasecommand_updatesearchindex.cpp b/src/libtomahawk/database/databasecommand_updatesearchindex.cpp similarity index 100% rename from src/database/databasecommand_updatesearchindex.cpp rename to src/libtomahawk/database/databasecommand_updatesearchindex.cpp diff --git a/src/database/databasecommand_updatesearchindex.h b/src/libtomahawk/database/databasecommand_updatesearchindex.h similarity index 85% rename from src/database/databasecommand_updatesearchindex.h rename to src/libtomahawk/database/databasecommand_updatesearchindex.h index 87d886ff8..c9278e0cb 100644 --- a/src/database/databasecommand_updatesearchindex.h +++ b/src/libtomahawk/database/databasecommand_updatesearchindex.h @@ -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: diff --git a/src/database/databasecommandloggable.cpp b/src/libtomahawk/database/databasecommandloggable.cpp similarity index 100% rename from src/database/databasecommandloggable.cpp rename to src/libtomahawk/database/databasecommandloggable.cpp diff --git a/src/database/databasecommandloggable.h b/src/libtomahawk/database/databasecommandloggable.h similarity index 89% rename from src/database/databasecommandloggable.h rename to src/libtomahawk/database/databasecommandloggable.h index 90dfab1e4..9877085ae 100644 --- a/src/database/databasecommandloggable.h +++ b/src/libtomahawk/database/databasecommandloggable.h @@ -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) diff --git a/src/database/databaseimpl.cpp b/src/libtomahawk/database/databaseimpl.cpp similarity index 98% rename from src/database/databaseimpl.cpp rename to src/libtomahawk/database/databaseimpl.cpp index 53e6f6ca2..48382f454 100644 --- a/src/database/databaseimpl.cpp +++ b/src/libtomahawk/database/databaseimpl.cpp @@ -1,11 +1,12 @@ #include "databaseimpl.h" +#include #include #include #include #include -#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( cmd ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); } diff --git a/src/database/databaseimpl.h b/src/libtomahawk/database/databaseimpl.h similarity index 100% rename from src/database/databaseimpl.h rename to src/libtomahawk/database/databaseimpl.h diff --git a/src/database/databaseresolver.cpp b/src/libtomahawk/database/databaseresolver.cpp similarity index 78% rename from src/database/databaseresolver.cpp rename to src/libtomahawk/database/databaseresolver.cpp index e0bb8b6d8..60326949f 100644 --- a/src/database/databaseresolver.cpp +++ b/src/libtomahawk/database/databaseresolver.cpp @@ -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( cmd ) ); + Database::instance()->enqueue( QSharedPointer( 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 ); } diff --git a/src/database/databaseresolver.h b/src/libtomahawk/database/databaseresolver.h similarity index 79% rename from src/database/databaseresolver.h rename to src/libtomahawk/database/databaseresolver.h index f9bbd2696..b40f2a200 100644 --- a/src/database/databaseresolver.h +++ b/src/libtomahawk/database/databaseresolver.h @@ -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 diff --git a/src/database/databaseworker.cpp b/src/libtomahawk/database/databaseworker.cpp similarity index 99% rename from src/database/databaseworker.cpp rename to src/libtomahawk/database/databaseworker.cpp index 25a9199e8..c626c9ffd 100644 --- a/src/database/databaseworker.cpp +++ b/src/libtomahawk/database/databaseworker.cpp @@ -4,8 +4,7 @@ #include #include -#include "tomahawk/tomahawkapp.h" -#include "database.h" +#include "database/database.h" #include "database/databasecommandloggable.h" diff --git a/src/database/databaseworker.h b/src/libtomahawk/database/databaseworker.h similarity index 100% rename from src/database/databaseworker.h rename to src/libtomahawk/database/databaseworker.h diff --git a/src/database/fuzzyindex.cpp b/src/libtomahawk/database/fuzzyindex.cpp similarity index 100% rename from src/database/fuzzyindex.cpp rename to src/libtomahawk/database/fuzzyindex.cpp diff --git a/src/database/fuzzyindex.h b/src/libtomahawk/database/fuzzyindex.h similarity index 100% rename from src/database/fuzzyindex.h rename to src/libtomahawk/database/fuzzyindex.h diff --git a/src/database/gen_schema.h.sh b/src/libtomahawk/database/gen_schema.h.sh similarity index 100% rename from src/database/gen_schema.h.sh rename to src/libtomahawk/database/gen_schema.h.sh diff --git a/src/database/op.h b/src/libtomahawk/database/op.h similarity index 100% rename from src/database/op.h rename to src/libtomahawk/database/op.h diff --git a/src/database/schema.sql b/src/libtomahawk/database/schema.sql similarity index 100% rename from src/database/schema.sql rename to src/libtomahawk/database/schema.sql diff --git a/src/database/schema.sql.h b/src/libtomahawk/database/schema.sql.h similarity index 100% rename from src/database/schema.sql.h rename to src/libtomahawk/database/schema.sql.h diff --git a/src/database/tomahawksqlquery.h b/src/libtomahawk/database/tomahawksqlquery.h similarity index 100% rename from src/database/tomahawksqlquery.h rename to src/libtomahawk/database/tomahawksqlquery.h diff --git a/src/libtomahawk/dllmacro.h b/src/libtomahawk/dllmacro.h new file mode 100644 index 000000000..b4b199505 --- /dev/null +++ b/src/libtomahawk/dllmacro.h @@ -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 diff --git a/include/tomahawk/functimeout.h b/src/libtomahawk/functimeout.h similarity index 100% rename from include/tomahawk/functimeout.h rename to src/libtomahawk/functimeout.h diff --git a/src/network/bufferiodevice.cpp b/src/libtomahawk/network/bufferiodevice.cpp similarity index 100% rename from src/network/bufferiodevice.cpp rename to src/libtomahawk/network/bufferiodevice.cpp diff --git a/src/network/bufferiodevice.h b/src/libtomahawk/network/bufferiodevice.h similarity index 100% rename from src/network/bufferiodevice.h rename to src/libtomahawk/network/bufferiodevice.h diff --git a/src/network/connection.cpp b/src/libtomahawk/network/connection.cpp similarity index 99% rename from src/network/connection.cpp rename to src/libtomahawk/network/connection.cpp index 3e83e650f..2dc64db52 100644 --- a/src/network/connection.cpp +++ b/src/libtomahawk/network/connection.cpp @@ -3,7 +3,7 @@ #include #include -#include "servent.h" +#include "network/servent.h" #define PROTOVER "3" // must match remote peer, or we can't talk. diff --git a/src/network/connection.h b/src/libtomahawk/network/connection.h similarity index 97% rename from src/network/connection.h rename to src/libtomahawk/network/connection.h index 7c964913a..4bcefe214 100644 --- a/src/network/connection.h +++ b/src/libtomahawk/network/connection.h @@ -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 diff --git a/src/network/controlconnection.cpp b/src/libtomahawk/network/controlconnection.cpp similarity index 97% rename from src/network/controlconnection.cpp rename to src/libtomahawk/network/controlconnection.cpp index e05511653..a9aec0ba7 100644 --- a/src/network/controlconnection.cpp +++ b/src/libtomahawk/network/controlconnection.cpp @@ -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(); diff --git a/src/network/controlconnection.h b/src/libtomahawk/network/controlconnection.h similarity index 86% rename from src/network/controlconnection.h rename to src/libtomahawk/network/controlconnection.h index cad4941f9..77261ffd3 100644 --- a/src/network/controlconnection.h +++ b/src/libtomahawk/network/controlconnection.h @@ -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 diff --git a/src/network/dbsyncconnection.cpp b/src/libtomahawk/network/dbsyncconnection.cpp similarity index 88% rename from src/network/dbsyncconnection.cpp rename to src/libtomahawk/network/dbsyncconnection.cpp index 16a3d1d02..6f0ebdd8f 100644 --- a/src/network/dbsyncconnection.cpp +++ b/src/libtomahawk/network/dbsyncconnection.cpp @@ -14,14 +14,14 @@ #include -#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(cmd_us) ); - - APP->database()->enqueue( QSharedPointer(cmd_them) ); + Database::instance()->enqueue( QSharedPointer(cmd_us) ); + Database::instance()->enqueue( QSharedPointer(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(cmd) ); + Database::instance()->enqueue( QSharedPointer(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( cmd ) ); + Database::instance()->enqueue( QSharedPointer( 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( cmd ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); } diff --git a/src/network/dbsyncconnection.h b/src/libtomahawk/network/dbsyncconnection.h similarity index 95% rename from src/network/dbsyncconnection.h rename to src/libtomahawk/network/dbsyncconnection.h index 762a01111..2a888ce97 100644 --- a/src/network/dbsyncconnection.h +++ b/src/libtomahawk/network/dbsyncconnection.h @@ -6,9 +6,9 @@ #include #include -#include "connection.h" +#include "network/connection.h" #include "database/op.h" -#include "tomahawk/typedefs.h" +#include "typedefs.h" class DBSyncConnection : public Connection { diff --git a/src/network/filetransferconnection.cpp b/src/libtomahawk/network/filetransferconnection.cpp similarity index 89% rename from src/network/filetransferconnection.cpp rename to src/libtomahawk/network/filetransferconnection.cpp index 7d64d0ee1..0b60de435 100644 --- a/src/network/filetransferconnection.cpp +++ b/src/libtomahawk/network/filetransferconnection.cpp @@ -2,13 +2,13 @@ #include -#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( 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 ); } @@ -91,6 +91,12 @@ FileTransferConnection::id() const } +Tomahawk::source_ptr +FileTransferConnection::source() const +{ + return m_source; +} + void FileTransferConnection::showStats( qint64 tx, qint64 rx ) { @@ -109,7 +115,7 @@ FileTransferConnection::showStats( qint64 tx, qint64 rx ) void FileTransferConnection::setup() { - QList sources = APP->sourcelist().sources(); + QList sources = SourceList::instance()->sources(); foreach( const source_ptr& src, sources ) { // local src doesnt have a control connection, skip it: @@ -135,7 +141,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( cmd ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); } @@ -152,7 +158,7 @@ FileTransferConnection::startSending( const Tomahawk::result_ptr& result ) m_result = result; qDebug() << "Starting to transmit" << m_result->url(); - QSharedPointer io = TomahawkApp::instance()->getIODeviceForUrl( m_result ); + QSharedPointer io = Servent::instance()->getIODeviceForUrl( m_result ); if( !io ) { qDebug() << "Couldn't read from source:" << m_result->url(); diff --git a/src/network/filetransferconnection.h b/src/libtomahawk/network/filetransferconnection.h similarity index 91% rename from src/network/filetransferconnection.h rename to src/libtomahawk/network/filetransferconnection.h index b9258b60c..72182f9b8 100644 --- a/src/network/filetransferconnection.h +++ b/src/libtomahawk/network/filetransferconnection.h @@ -6,9 +6,8 @@ #include #include -#include "connection.h" -#include "tomahawk/result.h" -#include "tomahawk/source.h" +#include "network/connection.h" +#include "result.h" class ControlConnection; class BufferIODevice; @@ -38,7 +37,7 @@ public: const QSharedPointer& iodevice() { return m_iodev; } ControlConnection* controlConnection() const { return m_cc; } - Tomahawk::source_ptr source() const { return m_source; } + Tomahawk::source_ptr source() const; Tomahawk::result_ptr track() const { return m_result; } qint64 transferRate() const { return m_transferRate; } diff --git a/src/network/msg.h b/src/libtomahawk/network/msg.h similarity index 100% rename from src/network/msg.h rename to src/libtomahawk/network/msg.h diff --git a/src/network/msgprocessor.cpp b/src/libtomahawk/network/msgprocessor.cpp similarity index 90% rename from src/network/msgprocessor.cpp rename to src/libtomahawk/network/msgprocessor.cpp index f910b62a6..c84107a22 100644 --- a/src/network/msgprocessor.cpp +++ b/src/libtomahawk/network/msgprocessor.cpp @@ -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 * watcher = (QFutureWatcher *) 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; } - - diff --git a/src/network/msgprocessor.h b/src/libtomahawk/network/msgprocessor.h similarity index 100% rename from src/network/msgprocessor.h rename to src/libtomahawk/network/msgprocessor.h diff --git a/src/network/remotecollection.cpp b/src/libtomahawk/network/remotecollection.cpp similarity index 100% rename from src/network/remotecollection.cpp rename to src/libtomahawk/network/remotecollection.cpp diff --git a/src/network/remotecollection.h b/src/libtomahawk/network/remotecollection.h similarity index 83% rename from src/network/remotecollection.h rename to src/libtomahawk/network/remotecollection.h index bde90af93..63124d618 100644 --- a/src/network/remotecollection.h +++ b/src/libtomahawk/network/remotecollection.h @@ -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 { diff --git a/src/network/servent.cpp b/src/libtomahawk/network/servent.cpp similarity index 85% rename from src/network/servent.cpp rename to src/libtomahawk/network/servent.cpp index 59480e429..3c0967d34 100644 --- a/src/network/servent.cpp +++ b/src/libtomahawk/network/servent.cpp @@ -1,27 +1,64 @@ #include "servent.h" +#include #include #include +#include #include #include +#include +#include -#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(result_ptr)> fac = + boost::bind( &Servent::localFileIODeviceFactory, this, _1 ); + this->registerIODeviceFactory( "file", fac ); + } + + { + boost::function(result_ptr)> fac = + boost::bind( &Servent::remoteIODeviceFactory, this, _1 ); + this->registerIODeviceFactory( "servent", fac ); + } + + { + boost::function(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 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 sources = APP->sourcelist().sources(); + QList 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(Tomahawk::result_ptr)> fac ) +{ + m_iofactories.insert( proto, fac ); + qDebug() << "Registered IODevice Factory for" << proto; +} + + + +QSharedPointer +Servent::getIODeviceForUrl( const Tomahawk::result_ptr& result ) +{ + qDebug() << Q_FUNC_INFO << thread(); + QSharedPointer 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 +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( io ); +} + + +QSharedPointer +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( reply );*/ +} diff --git a/src/network/servent.h b/src/libtomahawk/network/servent.h similarity index 83% rename from src/network/servent.h rename to src/libtomahawk/network/servent.h index 625ceb434..9082ce14a 100644 --- a/src/network/servent.h +++ b/src/libtomahawk/network/servent.h @@ -20,20 +20,24 @@ #include #include -#include "portfwd/portfwd.h" -#include "tomahawk/typedefs.h" +#include "typedefs.h" #include "msg.h" +#include + +#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 getIODeviceForUrl( const Tomahawk::result_ptr& result ); + void registerIODeviceFactory( const QString &proto, boost::function(Tomahawk::result_ptr)> fac ); + QSharedPointer localFileIODeviceFactory( const Tomahawk::result_ptr& result ); + QSharedPointer 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(Tomahawk::result_ptr)> > m_iofactories; + + static Servent* s_instance; }; #endif // SERVENT_H diff --git a/src/pipeline.cpp b/src/libtomahawk/pipeline.cpp similarity index 93% rename from src/pipeline.cpp rename to src/libtomahawk/pipeline.cpp index b5a294221..92951bf19 100644 --- a/src/pipeline.cpp +++ b/src/libtomahawk/pipeline.cpp @@ -1,28 +1,36 @@ -#include "tomahawk/pipeline.h" +#include "pipeline.h" #include #include -#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(); } diff --git a/include/tomahawk/pipeline.h b/src/libtomahawk/pipeline.h similarity index 85% rename from include/tomahawk/pipeline.h rename to src/libtomahawk/pipeline.h index 17dce1895..e62cad4f9 100644 --- a/include/tomahawk/pipeline.h +++ b/src/libtomahawk/pipeline.h @@ -6,21 +6,25 @@ #include #include -#include "tomahawk/typedefs.h" -#include "tomahawk/query.h" -#include "tomahawk/result.h" -#include "tomahawk/resolver.h" +#include "typedefs.h" +#include "query.h" +#include "result.h" +#include "resolver.h" + +#include "dllmacro.h" namespace Tomahawk { class Resolver; -class Pipeline : public QObject +class DLLEXPORT Pipeline : public QObject { Q_OBJECT public: + static Pipeline* instance(); + explicit Pipeline( QObject* parent = 0 ); // const query_ptr& query( QID qid ) const; @@ -63,6 +67,8 @@ private: // 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 diff --git a/src/playlist.cpp b/src/libtomahawk/playlist.cpp similarity index 93% rename from src/playlist.cpp rename to src/libtomahawk/playlist.cpp index ca098c92a..740c4dd61 100644 --- a/src/playlist.cpp +++ b/src/libtomahawk/playlist.cpp @@ -1,15 +1,17 @@ -#include "tomahawk/playlist.h" +#include "playlist.h" #include #include -#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; @@ -127,7 +129,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(cmd) ); + Database::instance()->enqueue( QSharedPointer(cmd) ); playlist->reportCreated( playlist ); return playlist; } @@ -137,7 +139,7 @@ bool Playlist::remove( const playlist_ptr& playlist ) { DatabaseCommand_DeletePlaylist* cmd = new DatabaseCommand_DeletePlaylist( playlist->author(), playlist->guid() ); - APP->database()->enqueue( QSharedPointer(cmd) ); + Database::instance()->enqueue( QSharedPointer(cmd) ); return true; // FIXME } @@ -147,7 +149,7 @@ bool Playlist::rename( const QString& title ) { DatabaseCommand_RenamePlaylist* cmd = new DatabaseCommand_RenamePlaylist( author(), guid(), title ); - APP->database()->enqueue( QSharedPointer(cmd) ); + Database::instance()->enqueue( QSharedPointer(cmd) ); return true; // FIXME } @@ -193,7 +195,7 @@ Playlist::loadRevision( const QString& rev ) const QMap< QString, Tomahawk::plentry_ptr >&, bool ) ) ); - APP->database()->enqueue( QSharedPointer( cmd ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); } @@ -209,7 +211,7 @@ Playlist::createNewRevision( const QString& newrev, const QString& oldrev, const orderedguids << p->guid(); // 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, @@ -218,7 +220,7 @@ Playlist::createNewRevision( const QString& newrev, const QString& oldrev, const oldrev, orderedguids, added ); - APP->database()->enqueue( QSharedPointer( cmd ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); } @@ -361,7 +363,7 @@ void Playlist::resolve() { qlist << p->query(); } - APP->pipeline()->add( qlist ); + Pipeline::instance()->add( qlist ); } diff --git a/include/tomahawk/playlist.h b/src/libtomahawk/playlist.h similarity index 97% rename from include/tomahawk/playlist.h rename to src/libtomahawk/playlist.h index 4da920c02..746740a90 100644 --- a/include/tomahawk/playlist.h +++ b/src/libtomahawk/playlist.h @@ -7,7 +7,10 @@ #include #include -#include "tomahawk/typedefs.h" +#include "query.h" +#include "typedefs.h" + +#include "dllmacro.h" class DatabaseCommand_LoadAllPlaylists; class DatabaseCommand_SetPlaylistRevision; @@ -16,7 +19,7 @@ class DatabaseCommand_CreatePlaylist; namespace Tomahawk { -class PlaylistEntry : public QObject +class DLLEXPORT PlaylistEntry : public QObject { Q_OBJECT Q_PROPERTY( QString guid READ guid WRITE setGuid ) @@ -77,7 +80,7 @@ struct PlaylistRevision }; -class Playlist : public QObject +class DLLEXPORT Playlist : public QObject { Q_OBJECT Q_PROPERTY( QString guid READ guid WRITE setGuid ) diff --git a/include/tomahawk/playlistinterface.h b/src/libtomahawk/playlistinterface.h similarity index 94% rename from include/tomahawk/playlistinterface.h rename to src/libtomahawk/playlistinterface.h index 0e6d053c6..1c220bdc9 100644 --- a/include/tomahawk/playlistinterface.h +++ b/src/libtomahawk/playlistinterface.h @@ -4,9 +4,11 @@ #include #include -#include "tomahawk/typedefs.h" +#include "typedefs.h" -class PlaylistInterface +#include "dllmacro.h" + +class DLLEXPORT PlaylistInterface { public: enum RepeatMode { NoRepeat, RepeatOne, RepeatAll }; diff --git a/src/pluginapi.cpp b/src/libtomahawk/pluginapi.cpp similarity index 70% rename from src/pluginapi.cpp rename to src/libtomahawk/pluginapi.cpp index 0649c6fb4..850d693df 100644 --- a/src/pluginapi.cpp +++ b/src/libtomahawk/pluginapi.cpp @@ -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& 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 ); } diff --git a/include/tomahawk/pluginapi.h b/src/libtomahawk/pluginapi.h similarity index 89% rename from include/tomahawk/pluginapi.h rename to src/libtomahawk/pluginapi.h index 3f6ab07fa..b824a3204 100644 --- a/include/tomahawk/pluginapi.h +++ b/src/libtomahawk/pluginapi.h @@ -4,8 +4,10 @@ #include #include -#include "tomahawk/collection.h" -#include "tomahawk/source.h" +#include "collection.h" +#include "source.h" + +#include "dllmacro.h" /* This is the only API plugins have access to. @@ -18,7 +20,7 @@ namespace Tomahawk class Resolver; class Pipeline; -class PluginAPI : public QObject +class DLLEXPORT PluginAPI : public QObject { Q_OBJECT diff --git a/src/query.cpp b/src/libtomahawk/query.cpp similarity index 98% rename from src/query.cpp rename to src/libtomahawk/query.cpp index 348c77708..cbfbb4e99 100644 --- a/src/query.cpp +++ b/src/libtomahawk/query.cpp @@ -1,5 +1,6 @@ -#include "tomahawk/query.h" +#include "query.h" +#include "collection.h" #include using namespace Tomahawk; diff --git a/include/tomahawk/query.h b/src/libtomahawk/query.h similarity index 93% rename from include/tomahawk/query.h rename to src/libtomahawk/query.h index 536063337..58018dfa0 100644 --- a/include/tomahawk/query.h +++ b/src/libtomahawk/query.h @@ -6,14 +6,15 @@ #include #include -// #include "tomahawk/collection.h" -#include "tomahawk/result.h" -#include "tomahawk/typedefs.h" +#include "result.h" +#include "typedefs.h" + +#include "dllmacro.h" namespace Tomahawk { -class Query : public QObject +class DLLEXPORT Query : public QObject { Q_OBJECT diff --git a/include/tomahawk/resolver.h b/src/libtomahawk/resolver.h similarity index 89% rename from include/tomahawk/resolver.h rename to src/libtomahawk/resolver.h index 16e55bda2..da898d6b2 100644 --- a/include/tomahawk/resolver.h +++ b/src/libtomahawk/resolver.h @@ -3,7 +3,9 @@ #include -#include "tomahawk/pluginapi.h" +#include "pluginapi.h" + +#include "dllmacro.h" // implement this if you can resolve queries to content @@ -17,7 +19,7 @@ namespace Tomahawk { class PluginAPI; -class Resolver : public QObject +class DLLEXPORT Resolver : public QObject { Q_OBJECT diff --git a/src/result.cpp b/src/libtomahawk/result.cpp similarity index 95% rename from src/result.cpp rename to src/libtomahawk/result.cpp index 19eefe616..791705a60 100644 --- a/src/result.cpp +++ b/src/libtomahawk/result.cpp @@ -1,9 +1,11 @@ -#include "tomahawk/result.h" +#include "result.h" -#include "tomahawk/album.h" +#include "album.h" +#include "collection.h" using namespace Tomahawk; +Result::Result() {} Result::Result( const QVariant& v, const collection_ptr& collection ) : m_v( v ) diff --git a/include/tomahawk/result.h b/src/libtomahawk/result.h similarity index 94% rename from include/tomahawk/result.h rename to src/libtomahawk/result.h index fc7a34f75..4b358bf81 100644 --- a/include/tomahawk/result.h +++ b/src/libtomahawk/result.h @@ -5,16 +5,20 @@ #include #include -#include "tomahawk/typedefs.h" + +#include "typedefs.h" + +#include "dllmacro.h" namespace Tomahawk { -class Result : public QObject +class DLLEXPORT Result : public QObject { Q_OBJECT public: + Result(); explicit Result( const QVariant& v, const collection_ptr& collection ); virtual ~Result(); diff --git a/src/sip/SipPlugin.cpp b/src/libtomahawk/sip/SipPlugin.cpp similarity index 100% rename from src/sip/SipPlugin.cpp rename to src/libtomahawk/sip/SipPlugin.cpp diff --git a/src/sip/SipPlugin.h b/src/libtomahawk/sip/SipPlugin.h similarity index 84% rename from src/sip/SipPlugin.h rename to src/libtomahawk/sip/SipPlugin.h index 3853f8c97..b0d046740 100644 --- a/src/sip/SipPlugin.h +++ b/src/libtomahawk/sip/SipPlugin.h @@ -4,7 +4,9 @@ #include #include -class SipPlugin : public QObject +#include "dllmacro.h" + +class DLLEXPORT SipPlugin : public QObject { Q_OBJECT @@ -27,7 +29,7 @@ signals: void peerOnline( const QString& ); void peerOffline( const QString& ); - void msgReceived( const QString&, const QString& ); + void msgReceived( const QString& from, const QString& msg ); }; Q_DECLARE_INTERFACE( SipPlugin, "tomahawk.Sip/1.0" ) diff --git a/src/source.cpp b/src/libtomahawk/source.cpp similarity index 82% rename from src/source.cpp rename to src/libtomahawk/source.cpp index cf8341a34..4fa3ed240 100644 --- a/src/source.cpp +++ b/src/libtomahawk/source.cpp @@ -1,12 +1,12 @@ -#include "tomahawk/source.h" +#include "source.h" -#include "tomahawk/tomahawkapp.h" -#include "tomahawk/collection.h" +#include "collection.h" +#include "sourcelist.h" -#include "controlconnection.h" -#include "databasecommand_addsource.h" -#include "databasecommand_sourceoffline.h" -#include "database.h" +#include "network/controlconnection.h" +#include "database/databasecommand_addsource.h" +#include "database/databasecommand_sourceoffline.h" +#include "database/database.h" using namespace Tomahawk; @@ -43,7 +43,7 @@ Source::~Source() return; // TODO mark source as offline in database DatabaseCommand_SourceOffline* cmd = new DatabaseCommand_SourceOffline( id() ); - APP->database()->enqueue( QSharedPointer(cmd) ); + Database::instance()->enqueue( QSharedPointer(cmd) ); } @@ -62,10 +62,10 @@ void Source::doDBSync() { // ensure username is in the database - DatabaseCommand_addSource * cmd = new DatabaseCommand_addSource( m_username, m_friendlyname ); + DatabaseCommand_addSource* cmd = new DatabaseCommand_addSource( m_username, m_friendlyname ); connect( cmd, SIGNAL( done( unsigned int, QString ) ), SLOT( dbLoaded( unsigned int, const QString& ) ) ); - APP->database()->enqueue( QSharedPointer(cmd) ); + Database::instance()->enqueue( QSharedPointer(cmd) ); } @@ -84,7 +84,7 @@ Source::remove() m_cc = 0; emit offline(); - APP->sourcelist().remove( this ); + SourceList::instance()->remove( this ); m_collections.clear(); } diff --git a/include/tomahawk/source.h b/src/libtomahawk/source.h similarity index 95% rename from include/tomahawk/source.h rename to src/libtomahawk/source.h index 9978a1002..4dadcd18e 100644 --- a/include/tomahawk/source.h +++ b/src/libtomahawk/source.h @@ -5,17 +5,19 @@ #include #include -#include "dbsyncconnection.h" +#include "network/dbsyncconnection.h" #include "collection.h" #include "typedefs.h" +#include "dllmacro.h" + class ControlConnection; class FileTransferConnection; namespace Tomahawk { -class Source : public QObject +class DLLEXPORT Source : public QObject { Q_OBJECT diff --git a/src/sourcelist.cpp b/src/libtomahawk/sourcelist.cpp similarity index 84% rename from src/sourcelist.cpp rename to src/libtomahawk/sourcelist.cpp index 2999bbaeb..7d2dc94ee 100644 --- a/src/sourcelist.cpp +++ b/src/libtomahawk/sourcelist.cpp @@ -1,9 +1,23 @@ -#include "tomahawk/sourcelist.h" +#include "sourcelist.h" #include using namespace Tomahawk; +SourceList* SourceList::s_instance = 0; + + +SourceList* +SourceList::instance() +{ + if ( !s_instance ) + { + s_instance = new SourceList(); + } + + return s_instance; +} + SourceList::SourceList( QObject* parent ) : QObject( parent ) { @@ -69,6 +83,16 @@ SourceList::remove( Tomahawk::Source* s ) emit sourceRemoved( src ); } +void +SourceList::removeAllRemote() +{ + foreach( source_ptr s, m_sources ) + { + if( s != m_local ) + remove( s ); + } +} + QList SourceList::sources() const diff --git a/include/tomahawk/sourcelist.h b/src/libtomahawk/sourcelist.h similarity index 81% rename from include/tomahawk/sourcelist.h rename to src/libtomahawk/sourcelist.h index 12320c6d7..ad31b2c92 100644 --- a/include/tomahawk/sourcelist.h +++ b/src/libtomahawk/sourcelist.h @@ -5,20 +5,25 @@ #include #include -#include "tomahawk/source.h" -#include "tomahawk/typedefs.h" +#include "source.h" +#include "typedefs.h" -class SourceList : public QObject +#include "dllmacro.h" + +class DLLEXPORT SourceList : public QObject { Q_OBJECT public: + static SourceList* instance(); + explicit SourceList( QObject* parent = 0 ); const Tomahawk::source_ptr& getLocal(); void add( const Tomahawk::source_ptr& s ); void remove( const Tomahawk::source_ptr& s ); void remove( Tomahawk::Source* s ); + void removeAllRemote(); QList sources() const; Tomahawk::source_ptr get( const QString& username ) const; @@ -35,6 +40,8 @@ private: Tomahawk::source_ptr m_local; mutable QMutex m_mut; // mutable so const methods can use a lock + + static SourceList* s_instance; }; #endif // SOURCELIST_H diff --git a/src/tomahawksettings.cpp b/src/libtomahawk/tomahawksettings.cpp similarity index 97% rename from src/tomahawksettings.cpp rename to src/libtomahawk/tomahawksettings.cpp index 44c1aa029..862f2f2e4 100644 --- a/src/tomahawksettings.cpp +++ b/src/libtomahawk/tomahawksettings.cpp @@ -1,4 +1,3 @@ -#include "tomahawk/tomahawkapp.h" #include "tomahawksettings.h" #ifndef TOMAHAWK_HEADLESS @@ -9,10 +8,21 @@ #include #include +TomahawkSettings* TomahawkSettings::s_instance = 0; + + +TomahawkSettings* +TomahawkSettings::instance() +{ + return s_instance; +} + TomahawkSettings::TomahawkSettings( QObject* parent ) : QSettings( parent ) { + s_instance = this; + #ifndef TOMAHAWK_HEADLESS if( !contains( "configversion") ) { @@ -33,6 +43,7 @@ TomahawkSettings::TomahawkSettings( QObject* parent ) TomahawkSettings::~TomahawkSettings() { + s_instance = 0; } diff --git a/src/tomahawksettings.h b/src/libtomahawk/tomahawksettings.h similarity index 92% rename from src/tomahawksettings.h rename to src/libtomahawk/tomahawksettings.h index 450c2884c..9bd8ea710 100644 --- a/src/tomahawksettings.h +++ b/src/libtomahawk/tomahawksettings.h @@ -3,14 +3,18 @@ #include +#include "dllmacro.h" + /** * Convenience wrapper around QSettings for tomahawk-specific config */ -class TomahawkSettings : public QSettings +class DLLEXPORT TomahawkSettings : public QSettings { Q_OBJECT public: - explicit TomahawkSettings(QObject* parent = 0); + static TomahawkSettings* instance(); + + explicit TomahawkSettings( QObject* parent = 0 ); virtual ~TomahawkSettings(); /// General settings @@ -91,6 +95,9 @@ public: int xmppBotPort() const; void setXmppBotPort( const int port ); + +private: + static TomahawkSettings* s_instance; }; #endif diff --git a/include/tomahawk/track.h b/src/libtomahawk/track.h similarity index 81% rename from include/tomahawk/track.h rename to src/libtomahawk/track.h index f5967619c..55ce10404 100644 --- a/include/tomahawk/track.h +++ b/src/libtomahawk/track.h @@ -4,13 +4,15 @@ #include #include -#include "tomahawk/artist.h" -#include "tomahawk/typedefs.h" +#include "artist.h" +#include "typedefs.h" + +#include "dllmacro.h" namespace Tomahawk { -class Track : public QObject +class DLLEXPORT Track : public QObject { Q_OBJECT diff --git a/include/tomahawk/typedefs.h b/src/libtomahawk/typedefs.h similarity index 100% rename from include/tomahawk/typedefs.h rename to src/libtomahawk/typedefs.h diff --git a/src/musicscanner.cpp b/src/musicscanner.cpp index da5e302c1..3652059bf 100644 --- a/src/musicscanner.cpp +++ b/src/musicscanner.cpp @@ -1,9 +1,10 @@ #include "musicscanner.h" #include "tomahawk/tomahawkapp.h" -#include "database.h" -#include "databasecommand_dirmtimes.h" -#include "databasecommand_addfiles.h" +#include "sourcelist.h" +#include "database/database.h" +#include "database/databasecommand_dirmtimes.h" +#include "database/databasecommand_addfiles.h" using namespace Tomahawk; @@ -53,7 +54,7 @@ MusicScanner::startScan() connect( cmd, SIGNAL( done( const QMap& ) ), SLOT( scan() ), Qt::DirectConnection ); - TomahawkApp::instance()->database()->enqueue( QSharedPointer(cmd) ); + Database::instance()->enqueue( QSharedPointer(cmd) ); } @@ -67,7 +68,7 @@ MusicScanner::setMtimes( const QMap& m ) void MusicScanner::scan() { - TomahawkApp::instance()->sourcelist().getLocal()->scanningProgress( 0 ); + SourceList::instance()->getLocal()->scanningProgress( 0 ); qDebug() << "Scanning, num saved mtimes from last scan:" << m_dirmtimes.size(); connect( this, SIGNAL( batchReady( QVariantList ) ), @@ -95,14 +96,14 @@ MusicScanner::listerFinished( const QMap& newmtimes ) // any remaining stuff that wasnt emitted as a batch: if( m_scannedfiles.length() ) { - TomahawkApp::instance()->sourcelist().getLocal()->scanningProgress( m_scanned ); + SourceList::instance()->getLocal()->scanningProgress( m_scanned ); commitBatch( m_scannedfiles ); } // save mtimes, then quit thread DatabaseCommand_DirMtimes* cmd = new DatabaseCommand_DirMtimes( newmtimes ); connect( cmd, SIGNAL( finished() ), SLOT( quit() ) ); - TomahawkApp::instance()->database()->enqueue( QSharedPointer(cmd) ); + Database::instance()->enqueue( QSharedPointer(cmd) ); qDebug() << "Scanning complete, saving to database. " "(scanned" << m_scanned << "skipped" << m_skipped << ")"; @@ -119,8 +120,8 @@ MusicScanner::commitBatch( const QVariantList& tracks ) if ( tracks.length() ) { qDebug() << Q_FUNC_INFO << tracks.length(); - source_ptr localsrc = TomahawkApp::instance()->sourcelist().getLocal(); - TomahawkApp::instance()->database()->enqueue( + source_ptr localsrc = SourceList::instance()->getLocal(); + Database::instance()->enqueue( QSharedPointer( new DatabaseCommand_AddFiles( tracks, localsrc ) ) ); } @@ -155,7 +156,7 @@ MusicScanner::readFile( const QFileInfo& fi ) } if( m_scanned % 3 == 0 ) - TomahawkApp::instance()->sourcelist().getLocal()->scanningProgress( m_scanned ); + SourceList::instance()->getLocal()->scanningProgress( m_scanned ); if( m_scanned % 100 == 0 ) qDebug() << "SCAN" << m_scanned << fi.absoluteFilePath(); diff --git a/src/playlist/albumitem.h b/src/playlist/albumitem.h index 15866dd88..028f018a1 100644 --- a/src/playlist/albumitem.h +++ b/src/playlist/albumitem.h @@ -6,7 +6,7 @@ #include #include -#include "tomahawk/album.h" +#include "album.h" class AlbumItem : public QObject { diff --git a/src/playlist/albumitemdelegate.cpp b/src/playlist/albumitemdelegate.cpp index f4941fff5..508a4256f 100644 --- a/src/playlist/albumitemdelegate.cpp +++ b/src/playlist/albumitemdelegate.cpp @@ -4,8 +4,8 @@ #include #include -#include "tomahawk/query.h" -#include "tomahawk/result.h" +#include "query.h" +#include "result.h" #include "tomahawk/tomahawkapp.h" #include "playlist/albumitem.h" diff --git a/src/playlist/albummodel.cpp b/src/playlist/albummodel.cpp index 4ef709f69..b791c79c9 100644 --- a/src/playlist/albummodel.cpp +++ b/src/playlist/albummodel.cpp @@ -6,7 +6,7 @@ #include #include "tomahawk/tomahawkapp.h" -#include "database.h" +#include "database/database.h" #define LASTFM_DEFAULT_COVER "http://cdn.last.fm/flatness/catalogue/noimage" @@ -223,7 +223,7 @@ AlbumModel::addCollection( const collection_ptr& collection ) connect( cmd, SIGNAL( albums( QList, Tomahawk::collection_ptr ) ), SLOT( onAlbumsAdded( QList, Tomahawk::collection_ptr ) ) ); - TomahawkApp::instance()->database()->enqueue( QSharedPointer( cmd ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); } @@ -243,7 +243,7 @@ AlbumModel::addFilteredCollection( const collection_ptr& collection, unsigned in connect( cmd, SIGNAL( albums( QList, Tomahawk::collection_ptr ) ), SLOT( onAlbumsAdded( QList, Tomahawk::collection_ptr ) ) ); - TomahawkApp::instance()->database()->enqueue( QSharedPointer( cmd ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); } diff --git a/src/playlist/albummodel.h b/src/playlist/albummodel.h index 63cc70da8..46f8ce29f 100644 --- a/src/playlist/albummodel.h +++ b/src/playlist/albummodel.h @@ -4,9 +4,9 @@ #include #include -#include "tomahawk/album.h" -#include "tomahawk/collection.h" -#include "tomahawk/playlistinterface.h" +#include "album.h" +#include "collection.h" +#include "playlistinterface.h" #include "database/databasecommand_allalbums.h" #include "albumitem.h" diff --git a/src/playlist/albumproxymodel.cpp b/src/playlist/albumproxymodel.cpp index f880a01a8..36c470fe7 100644 --- a/src/playlist/albumproxymodel.cpp +++ b/src/playlist/albumproxymodel.cpp @@ -3,7 +3,7 @@ #include #include -#include "tomahawk/query.h" +#include "query.h" #include "collectionmodel.h" diff --git a/src/playlist/albumproxymodel.h b/src/playlist/albumproxymodel.h index 598dbaa08..f259f79f2 100644 --- a/src/playlist/albumproxymodel.h +++ b/src/playlist/albumproxymodel.h @@ -3,7 +3,7 @@ #include -#include "tomahawk/playlistinterface.h" +#include "playlistinterface.h" #include "playlist/albummodel.h" class AlbumProxyModel : public QSortFilterProxyModel, public PlaylistInterface diff --git a/src/playlist/collectionflatmodel.cpp b/src/playlist/collectionflatmodel.cpp index dfdd2f4d7..167398d6e 100644 --- a/src/playlist/collectionflatmodel.cpp +++ b/src/playlist/collectionflatmodel.cpp @@ -4,7 +4,8 @@ #include #include -#include "database.h" +#include "database/database.h" +#include "sourcelist.h" using namespace Tomahawk; @@ -14,7 +15,7 @@ CollectionFlatModel::CollectionFlatModel( QObject* parent ) { qDebug() << Q_FUNC_INFO; - connect( &APP->sourcelist(), SIGNAL( sourceRemoved( Tomahawk::source_ptr ) ), SLOT( onSourceOffline( Tomahawk::source_ptr ) ) ); + connect( SourceList::instance(), SIGNAL( sourceRemoved( Tomahawk::source_ptr ) ), SLOT( onSourceOffline( Tomahawk::source_ptr ) ) ); } @@ -80,7 +81,7 @@ CollectionFlatModel::addFilteredCollection( const collection_ptr& collection, un connect( cmd, SIGNAL( tracks( QList, Tomahawk::collection_ptr ) ), SLOT( onTracksAdded( QList, Tomahawk::collection_ptr ) ), Qt::QueuedConnection ); - TomahawkApp::instance()->database()->enqueue( QSharedPointer( cmd ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); } diff --git a/src/playlist/collectionflatmodel.h b/src/playlist/collectionflatmodel.h index 56cc6c1a1..25cb62f23 100644 --- a/src/playlist/collectionflatmodel.h +++ b/src/playlist/collectionflatmodel.h @@ -7,14 +7,13 @@ #include "plitem.h" #include "trackmodel.h" -#include "tomahawk/tomahawkapp.h" -#include "tomahawk/collection.h" -#include "tomahawk/query.h" -#include "tomahawk/typedefs.h" -#include "tomahawk/playlist.h" -#include "tomahawk/playlistinterface.h" +#include "collection.h" +#include "query.h" +#include "typedefs.h" +#include "playlist.h" +#include "playlistinterface.h" -#include "databasecommand_alltracks.h" +#include "database/databasecommand_alltracks.h" class QMetaData; diff --git a/src/playlist/collectionmodel.cpp b/src/playlist/collectionmodel.cpp index d127bba9c..d951b4aed 100644 --- a/src/playlist/collectionmodel.cpp +++ b/src/playlist/collectionmodel.cpp @@ -4,6 +4,9 @@ #include #include +#include "sourcelist.h" +#include "utils/tomahawkutils.h" + using namespace Tomahawk; @@ -13,7 +16,7 @@ CollectionModel::CollectionModel( QObject* parent ) { qDebug() << Q_FUNC_INFO; - connect( &APP->sourcelist(), SIGNAL( sourceRemoved( Tomahawk::source_ptr ) ), SLOT( onSourceOffline( Tomahawk::source_ptr ) ) ); + connect( SourceList::instance(), SIGNAL( sourceRemoved( Tomahawk::source_ptr ) ), SLOT( onSourceOffline( Tomahawk::source_ptr ) ) ); } diff --git a/src/playlist/collectionmodel.h b/src/playlist/collectionmodel.h index 6dcef3249..4eb918d3a 100644 --- a/src/playlist/collectionmodel.h +++ b/src/playlist/collectionmodel.h @@ -6,12 +6,11 @@ #include #include "plitem.h" -#include "tomahawk/tomahawkapp.h" -#include "tomahawk/collection.h" -#include "tomahawk/query.h" -#include "tomahawk/typedefs.h" -#include "tomahawk/playlist.h" -#include "tomahawk/playlistinterface.h" +#include "collection.h" +#include "query.h" +#include "typedefs.h" +#include "playlist.h" +#include "playlistinterface.h" class QMetaData; diff --git a/src/playlist/collectionproxymodel.cpp b/src/playlist/collectionproxymodel.cpp index e0be4b0fc..b477d2d17 100644 --- a/src/playlist/collectionproxymodel.cpp +++ b/src/playlist/collectionproxymodel.cpp @@ -3,8 +3,8 @@ #include #include -#include "tomahawk/album.h" -#include "tomahawk/query.h" +#include "album.h" +#include "query.h" #include "collectionmodel.h" diff --git a/src/playlist/playlistitemdelegate.cpp b/src/playlist/playlistitemdelegate.cpp index 10a536ccc..bb7583168 100644 --- a/src/playlist/playlistitemdelegate.cpp +++ b/src/playlist/playlistitemdelegate.cpp @@ -4,8 +4,8 @@ #include #include -#include "tomahawk/query.h" -#include "tomahawk/result.h" +#include "query.h" +#include "result.h" #include "tomahawk/tomahawkapp.h" #include "playlist/plitem.h" diff --git a/src/playlist/playlistmanager.cpp b/src/playlist/playlistmanager.cpp index 5d33e4dfd..2c0d2ae8e 100644 --- a/src/playlist/playlistmanager.cpp +++ b/src/playlist/playlistmanager.cpp @@ -16,6 +16,7 @@ #include "albumview.h" #include "albumproxymodel.h" #include "albummodel.h" +#include "sourcelist.h" #include "infowidgets/sourceinfowidget.h" #include @@ -108,7 +109,7 @@ PlaylistManager::show( const Tomahawk::playlist_ptr& playlist ) m_modesAvailable = false; linkPlaylist(); - emit numSourcesChanged( APP->sourcelist().count() ); + emit numSourcesChanged( SourceList::instance()->count() ); return true; } @@ -129,8 +130,8 @@ PlaylistManager::show(const Tomahawk::dynplaylist_ptr& playlist) m_statsAvailable = true; m_modesAvailable = false; linkPlaylist(); - - emit numSourcesChanged( APP->sourcelist().count() ); + emit numSourcesChanged( SourceList::instance()->count() ); + return true; } @@ -252,7 +253,7 @@ PlaylistManager::show( const Tomahawk::source_ptr& source ) bool PlaylistManager::showSuperCollection() { - foreach( const Tomahawk::source_ptr& source, APP->sourcelist().sources() ) + foreach( const Tomahawk::source_ptr& source, SourceList::instance()->sources() ) { if ( !m_superCollections.contains( source->collection() ) ) { diff --git a/src/playlist/playlistmanager.h b/src/playlist/playlistmanager.h index 7dfe92137..ca15ea3a4 100644 --- a/src/playlist/playlistmanager.h +++ b/src/playlist/playlistmanager.h @@ -5,8 +5,8 @@ #include #include -#include "tomahawk/collection.h" -#include "tomahawk/playlistinterface.h" +#include "collection.h" +#include "playlistinterface.h" namespace Tomahawk { class DynamicWidget; diff --git a/src/playlist/playlistmodel.cpp b/src/playlist/playlistmodel.cpp index ce1fe0535..34605fcb2 100644 --- a/src/playlist/playlistmodel.cpp +++ b/src/playlist/playlistmodel.cpp @@ -4,7 +4,7 @@ #include #include -#include "tomahawk/album.h" +#include "album.h" using namespace Tomahawk; diff --git a/src/playlist/playlistmodel.h b/src/playlist/playlistmodel.h index ee7938b37..5fce18b96 100644 --- a/src/playlist/playlistmodel.h +++ b/src/playlist/playlistmodel.h @@ -7,11 +7,11 @@ #include "plitem.h" #include "trackmodel.h" #include "tomahawk/tomahawkapp.h" -#include "tomahawk/collection.h" -#include "tomahawk/query.h" -#include "tomahawk/typedefs.h" -#include "tomahawk/playlist.h" -#include "tomahawk/playlistinterface.h" +#include "collection.h" +#include "query.h" +#include "typedefs.h" +#include "playlist.h" +#include "playlistinterface.h" class QMetaData; diff --git a/src/playlist/plitem.cpp b/src/playlist/plitem.cpp index c0e291570..163855d56 100644 --- a/src/playlist/plitem.cpp +++ b/src/playlist/plitem.cpp @@ -1,8 +1,8 @@ #include "plitem.h" #include "utils/tomahawkutils.h" -#include "tomahawk/playlist.h" -#include "tomahawk/query.h" +#include "playlist.h" +#include "query.h" #include diff --git a/src/playlist/plitem.h b/src/playlist/plitem.h index 3de1dd941..aad8cadc0 100644 --- a/src/playlist/plitem.h +++ b/src/playlist/plitem.h @@ -6,8 +6,8 @@ #include #include -#include "tomahawk/result.h" -#include "tomahawk/typedefs.h" +#include "query.h" +#include "typedefs.h" class PlItem : public QObject { diff --git a/src/playlist/trackheader.cpp b/src/playlist/trackheader.cpp index 64ba237ba..ae30f5b9c 100644 --- a/src/playlist/trackheader.cpp +++ b/src/playlist/trackheader.cpp @@ -83,8 +83,7 @@ TrackHeader::onResized() void TrackHeader::restoreColumnsState() { - TomahawkSettings* s = APP->settings(); - QList list = s->playlistColumnSizes(); + QList list = TomahawkSettings::instance()->playlistColumnSizes(); if ( list.count() != count() ) // FIXME: const { @@ -101,13 +100,12 @@ TrackHeader::restoreColumnsState() void TrackHeader::saveColumnsState() { - TomahawkSettings *s = APP->settings(); QList wlist; foreach( double w, m_columnWeights ) wlist << QVariant( w ); - s->setPlaylistColumnSizes( wlist ); + TomahawkSettings::instance()->setPlaylistColumnSizes( wlist ); } diff --git a/src/playlist/trackmodel.cpp b/src/playlist/trackmodel.cpp index 25bcd2fc4..d4e348d9f 100644 --- a/src/playlist/trackmodel.cpp +++ b/src/playlist/trackmodel.cpp @@ -5,7 +5,7 @@ #include #include "tomahawk/tomahawkapp.h" -#include "tomahawk/album.h" +#include "album.h" using namespace Tomahawk; diff --git a/src/playlist/trackmodel.h b/src/playlist/trackmodel.h index 054346731..7bb11f93a 100644 --- a/src/playlist/trackmodel.h +++ b/src/playlist/trackmodel.h @@ -3,7 +3,7 @@ #include -#include "tomahawk/playlistinterface.h" +#include "playlistinterface.h" #include "playlist/plitem.h" class QMetaData; diff --git a/src/playlist/trackproxymodel.cpp b/src/playlist/trackproxymodel.cpp index 45bafa59c..c6a6536ad 100644 --- a/src/playlist/trackproxymodel.cpp +++ b/src/playlist/trackproxymodel.cpp @@ -3,8 +3,8 @@ #include #include -#include "tomahawk/album.h" -#include "tomahawk/query.h" +#include "album.h" +#include "query.h" #include "collectionmodel.h" diff --git a/src/playlist/trackproxymodel.h b/src/playlist/trackproxymodel.h index cb48287a5..88552dd27 100644 --- a/src/playlist/trackproxymodel.h +++ b/src/playlist/trackproxymodel.h @@ -3,7 +3,7 @@ #include -#include "tomahawk/playlistinterface.h" +#include "playlistinterface.h" #include "playlist/trackmodel.h" class TrackProxyModel : public QSortFilterProxyModel, public PlaylistInterface diff --git a/src/scriptresolver.cpp b/src/scriptresolver.cpp index c240f03ab..bac5774d3 100644 --- a/src/scriptresolver.cpp +++ b/src/scriptresolver.cpp @@ -1,7 +1,11 @@ -#include -#include "tomahawk/tomahawkapp.h" #include "scriptresolver.h" +#include + +#include "pipeline.h" +#include "sourcelist.h" + + ScriptResolver::ScriptResolver(const QString& exe) : Tomahawk::Resolver() , m_cmd( exe ) @@ -88,14 +92,14 @@ void ScriptResolver::handleMsg( const QByteArray& msg ) QList< Tomahawk::result_ptr > results; const QString& qid = m.value( "qid" ).toString(); const QVariantList& reslist = m.value( "results" ).toList(); - Tomahawk::collection_ptr coll = APP->sourcelist().getLocal()->collection(); + Tomahawk::collection_ptr coll = SourceList::instance()->getLocal()->collection(); foreach( const QVariant& rv, reslist ) { qDebug() << "RES" << rv; Tomahawk::result_ptr rp( new Tomahawk::Result( rv, coll ) ); results << rp; } - APP->pipeline()->reportResults( qid, results ); + Tomahawk::Pipeline::instance()->reportResults( qid, results ); } } @@ -104,7 +108,7 @@ void ScriptResolver::cmdExited(int code, QProcess::ExitStatus status) { m_ready = false; qDebug() << Q_FUNC_INFO << "SCRIPT EXITED, code" << code << "status" << status << m_cmd; - APP->pipeline()->removeResolver( this ); + Tomahawk::Pipeline::instance()->removeResolver( this ); if( m_num_restarts < 10 ) { @@ -142,5 +146,5 @@ void ScriptResolver::doSetup( const QVariantMap& m ) << " preference" << m_preference ; m_ready = true; - APP->pipeline()->addResolver( this ); + Tomahawk::Pipeline::instance()->addResolver( this ); } diff --git a/src/scriptresolver.h b/src/scriptresolver.h index 6b37ae482..a5164fbdb 100644 --- a/src/scriptresolver.h +++ b/src/scriptresolver.h @@ -7,8 +7,8 @@ #include #include -#include "tomahawk/resolver.h" -#include "tomahawk/result.h" +#include "resolver.h" +#include "result.h" class ScriptResolver : public Tomahawk::Resolver { diff --git a/src/scrobbler.cpp b/src/scrobbler.cpp index 7cbb94659..67dc21cf8 100644 --- a/src/scrobbler.cpp +++ b/src/scrobbler.cpp @@ -4,11 +4,11 @@ #include #include -#include -#include "tomahawk/album.h" -#include "tomahawk/typedefs.h" +#include "album.h" +#include "typedefs.h" #include "audio/audioengine.h" #include "tomahawksettings.h" +#include "tomahawk/tomahawkapp.h" #include #include @@ -30,11 +30,11 @@ Scrobbler::Scrobbler( QObject* parent ) { lastfm::ws::ApiKey = "2aa1089093868876bba20b0482b9cef9"; lastfm::ws::SharedSecret = "a7085ef81d7b46fe6ffe11c15b85902f"; - lastfm::ws::Username = TomahawkApp::instance()->settings()->lastFmUsername(); + lastfm::ws::Username = TomahawkSettings::instance()->lastFmUsername(); - m_pw = TomahawkApp::instance()->settings()->lastFmPassword(); + m_pw = TomahawkSettings::instance()->lastFmPassword(); - if( TomahawkApp::instance()->settings()->scrobblingEnabled() && !lastfm::ws::Username.isEmpty() ) + if( TomahawkSettings::instance()->scrobblingEnabled() && !lastfm::ws::Username.isEmpty() ) { createScrobbler(); } @@ -141,22 +141,22 @@ Scrobbler::scrobble() void Scrobbler::settingsChanged() { - if( !m_scrobbler && TomahawkApp::instance()->settings()->scrobblingEnabled() ) + if( !m_scrobbler && TomahawkSettings::instance()->scrobblingEnabled() ) { // can simply create the scrobbler - lastfm::ws::Username = TomahawkApp::instance()->settings()->lastFmUsername(); - m_pw = TomahawkApp::instance()->settings()->lastFmPassword(); + lastfm::ws::Username = TomahawkSettings::instance()->lastFmUsername(); + m_pw = TomahawkSettings::instance()->lastFmPassword(); createScrobbler(); } - else if( m_scrobbler && !TomahawkApp::instance()->settings()->scrobblingEnabled() ) + else if( m_scrobbler && !TomahawkSettings::instance()->scrobblingEnabled() ) { delete m_scrobbler; m_scrobbler = 0; } - else if( TomahawkApp::instance()->settings()->lastFmUsername() != lastfm::ws::Username || - TomahawkApp::instance()->settings()->lastFmPassword() != m_pw ) + else if( TomahawkSettings::instance()->lastFmUsername() != lastfm::ws::Username || + TomahawkSettings::instance()->lastFmPassword() != m_pw ) { - lastfm::ws::Username = TomahawkApp::instance()->settings()->lastFmUsername(); + lastfm::ws::Username = TomahawkSettings::instance()->lastFmUsername(); // credentials have changed, have to re-create scrobbler for them to take effect if( m_scrobbler ) delete m_scrobbler; @@ -182,16 +182,16 @@ Scrobbler::onAuthenticated() if( lfm.children( "error" ).size() > 0 ) { qDebug() << "Error from authenticating with Last.fm service:" << lfm.text(); - TomahawkApp::instance()->settings()->setLastFmSessionKey( QByteArray() ); + TomahawkSettings::instance()->setLastFmSessionKey( QByteArray() ); } else { lastfm::ws::SessionKey = lfm[ "session" ][ "key" ].text(); - TomahawkApp::instance()->settings()->setLastFmSessionKey( lastfm::ws::SessionKey.toLatin1() ); + TomahawkSettings::instance()->setLastFmSessionKey( lastfm::ws::SessionKey.toLatin1() ); - if( TomahawkApp::instance()->settings()->scrobblingEnabled() ) + if( TomahawkSettings::instance()->scrobblingEnabled() ) m_scrobbler = new lastfm::Audioscrobbler( "tst" ); } } @@ -207,7 +207,7 @@ Scrobbler::onAuthenticated() void Scrobbler::createScrobbler() { - if( TomahawkApp::instance()->settings()->lastFmSessionKey().isEmpty() ) // no session key, so get one + if( TomahawkSettings::instance()->lastFmSessionKey().isEmpty() ) // no session key, so get one { QString authToken = md5( ( lastfm::ws::Username.toLower() + md5( m_pw.toUtf8() ) ).toUtf8() ); @@ -221,7 +221,7 @@ Scrobbler::createScrobbler() } else { - lastfm::ws::SessionKey = TomahawkApp::instance()->settings()->lastFmSessionKey(); + lastfm::ws::SessionKey = TomahawkSettings::instance()->lastFmSessionKey(); m_scrobbler = new lastfm::Audioscrobbler( "tst" ); m_scrobbler->moveToThread( thread() ); diff --git a/src/scrobbler.h b/src/scrobbler.h index 72c5a3a55..927913d47 100644 --- a/src/scrobbler.h +++ b/src/scrobbler.h @@ -2,7 +2,7 @@ #ifndef TOMAHAWK_SCROBBLER_H #define TOMAHAWK_SCROBBLER_H -#include "tomahawk/result.h" +#include "result.h" #include #include diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 938dd021e..e8f6e4c5c 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -36,7 +36,7 @@ SettingsDialog::SettingsDialog( QWidget *parent ) , m_testLastFmQuery( 0 ) { ui->setupUi( this ); - TomahawkSettings* s = TomahawkApp::instance()->settings(); + TomahawkSettings* s = TomahawkSettings::instance(); ui->checkBoxHttp->setChecked( s->httpEnabled() ); ui->checkBoxUpnp->setChecked( s->upnpEnabled() ); @@ -84,7 +84,7 @@ SettingsDialog::~SettingsDialog() if ( !m_rejected ) { - TomahawkSettings* s = TomahawkApp::instance()->settings(); + TomahawkSettings* s = TomahawkSettings::instance(); // if jabber or scan dir changed, reconnect/rescan bool rescan = ui->lineEditMusicPath->text() != s->scannerPath(); @@ -270,7 +270,7 @@ ProxyDialog::ProxyDialog( QWidget *parent ) ui->typeBox->insertItem( i, "SOCKS 5", QNetworkProxy::Socks5Proxy ); enumMap[QNetworkProxy::Socks5Proxy] = i++; - TomahawkSettings* s = TomahawkApp::instance()->settings(); + TomahawkSettings* s = TomahawkSettings::instance(); ui->typeBox->setCurrentIndex( enumMap[s->proxyType()] ); ui->hostLineEdit->setText( s->proxyHost() ); @@ -286,7 +286,7 @@ ProxyDialog::saveSettings() qDebug() << Q_FUNC_INFO; //First set settings - TomahawkSettings* s = TomahawkApp::instance()->settings(); + TomahawkSettings* s = TomahawkSettings::instance(); s->setProxyHost( ui->hostLineEdit->text() ); bool ok; diff --git a/src/sip/SipHandler.cpp b/src/sip/SipHandler.cpp index d2aa6cb3a..e5ef7fb05 100644 --- a/src/sip/SipHandler.cpp +++ b/src/sip/SipHandler.cpp @@ -1,17 +1,20 @@ #include "SipHandler.h" #include "sip/SipPlugin.h" +#include #include #include #include -#include "tomahawk/tomahawkapp.h" -#include "controlconnection.h" +#include "database/database.h" +#include "network/controlconnection.h" +#include "sourcelist.h" SipHandler::SipHandler( QObject* parent ) : QObject( parent ) { + m_connected = false; loadPlugins(); } @@ -24,9 +27,20 @@ SipHandler::~SipHandler() void SipHandler::loadPlugins() { - qDebug() << TomahawkApp::instance(); - qDebug() << TomahawkApp::instance()->applicationDirPath(); - QDir pluginsDir( TomahawkApp::instance()->applicationDirPath() ); + QDir pluginsDir( qApp->applicationDirPath() ); + + #if defined(Q_OS_WIN) + if ( pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release" ) + pluginsDir.cdUp(); + #elif defined(Q_OS_MAC) + if ( pluginsDir.dirName() == "MacOS" ) + { + pluginsDir.cdUp(); + pluginsDir.cdUp(); + pluginsDir.cdUp(); + } + #endif + pluginsDir.cd( "plugins" ); foreach ( QString fileName, pluginsDir.entryList( QDir::Files ) ) { @@ -68,6 +82,7 @@ SipHandler::connect() { foreach( SipPlugin* sip, m_plugins ) sip->connect(); + m_connected = true; } @@ -76,6 +91,17 @@ SipHandler::disconnect() { foreach( SipPlugin* sip, m_plugins ) sip->disconnect(); + SourceList::instance()->removeAllRemote(); + m_connected = false; +} + +void +SipHandler::toggleConnect() +{ + if( m_connected ) + disconnect(); + else + connect(); } @@ -88,27 +114,19 @@ SipHandler::onPeerOnline( const QString& jid ) SipPlugin* sip = qobject_cast(sender()); QVariantMap m; - if( APP->servent().visibleExternally() ) + if( Servent::instance()->visibleExternally() ) { QString key = uuid(); - ControlConnection* conn = new ControlConnection( &APP->servent() ); + ControlConnection* conn = new ControlConnection( Servent::instance() ); - const QString& nodeid = APP->nodeID(); + const QString& nodeid = Database::instance()->dbid(); conn->setName( jid.left( jid.indexOf( "/" ) ) ); conn->setId( nodeid ); - // FIXME strip /resource, but we should use a UID per database install - //QString uniqname = jid.left( jid.indexOf("/") ); - //conn->setName( uniqname ); //FIXME - - // FIXME: - //QString ouruniqname = m_settings->value( "jabber/username" ).toString() - // .left( m_settings->value( "jabber/username" ).toString().indexOf("/") ); - - APP->servent().registerOffer( key, conn ); + Servent::instance()->registerOffer( key, conn ); m["visible"] = true; - m["ip"] = APP->servent().externalAddress().toString(); - m["port"] = APP->servent().externalPort(); + m["ip"] = Servent::instance()->externalAddress().toString(); + m["port"] = Servent::instance()->externalPort(); m["key"] = key; m["uniqname"] = nodeid; @@ -158,15 +176,15 @@ SipHandler::onMessage( const QString& from, const QString& msg ) */ if ( m.value( "visible" ).toBool() ) { - if( !APP->servent().visibleExternally() || - APP->servent().externalAddress().toString() <= m.value( "ip" ).toString() ) + if( !Servent::instance()->visibleExternally() || + Servent::instance()->externalAddress().toString() <= m.value( "ip" ).toString() ) { qDebug() << "Initiate connection to" << from; - APP->servent().connectToPeer( m.value( "ip" ).toString(), - m.value( "port" ).toInt(), - m.value( "key" ).toString(), - from, - m.value( "uniqname" ).toString() ); + Servent::instance()->connectToPeer( m.value( "ip" ).toString(), + m.value( "port" ).toInt(), + m.value( "key" ).toString(), + from, + m.value( "uniqname" ).toString() ); } else { @@ -176,8 +194,6 @@ SipHandler::onMessage( const QString& from, const QString& msg ) else { qDebug() << Q_FUNC_INFO << "They are not visible, doing nothing atm"; -// if ( m_servent.visibleExternally() ) -// jabberPeerOnline( from ); // HACK FIXME } } diff --git a/src/sip/SipHandler.h b/src/sip/SipHandler.h index f1ea7d3ff..7055cdacd 100644 --- a/src/sip/SipHandler.h +++ b/src/sip/SipHandler.h @@ -21,6 +21,7 @@ public slots: void connect(); void disconnect(); + void toggleConnect(); signals: void connected(); @@ -38,6 +39,7 @@ private: void loadPlugin( QObject* plugin ); QList< SipPlugin* > m_plugins; + bool m_connected; }; #endif diff --git a/src/sip/jabber/CMakeLists.txt b/src/sip/jabber/CMakeLists.txt index 0f8303f20..2f35be10a 100644 --- a/src/sip/jabber/CMakeLists.txt +++ b/src/sip/jabber/CMakeLists.txt @@ -4,6 +4,7 @@ include( ${QT_USE_FILE} ) add_definitions( ${QT_DEFINITIONS} ) add_definitions( -DQT_PLUGIN ) add_definitions( -DQT_SHARED ) +add_definitions( -DDLLEXPORT_PRO ) set( jabberSources jabber.cpp @@ -22,9 +23,21 @@ include_directories( . ${CMAKE_CURRENT_BINARY_DIR} .. qt4_wrap_cpp( jabberMoc ${jabberHeaders} ) add_library( sip_jabber SHARED ${jabberSources} ${jabberMoc} ) +IF( WIN32 ) +SET( OS_SPECIFIC_LINK_LIBRARIES + ${OS_SPECIFIC_LINK_LIBRARIES} + "${CMAKE_CURRENT_SOURCE_DIR}/../../../build/src/libtomahawk/libtomahawklib.dll" +) +ENDIF( WIN32 ) + target_link_libraries( sip_jabber ${QT_LIBRARIES} ${GLOOX_LIBS} + ${OS_SPECIFIC_LINK_LIBRARIES} ) -install( TARGETS sip_jabber DESTINATION . ) +IF( APPLE ) + SET( CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} "-undefined dynamic_lookup" ) +ENDIF( APPLE ) + +install( TARGETS sip_jabber DESTINATION lib ) diff --git a/src/sip/jabber/jabber.cpp b/src/sip/jabber/jabber.cpp index 05b72edb3..6748c0577 100644 --- a/src/sip/jabber/jabber.cpp +++ b/src/sip/jabber/jabber.cpp @@ -1,8 +1,9 @@ #include "jabber.h" -#include "tomahawk/tomahawkapp.h" #include "tomahawksettings.h" +#include + void JabberPlugin::setProxy( QNetworkProxy* proxy ) @@ -14,13 +15,13 @@ JabberPlugin::setProxy( QNetworkProxy* proxy ) bool JabberPlugin::connect() { - if ( !APP->settings()->value( "jabber/autoconnect", true ).toBool() ) + if ( !TomahawkSettings::instance()->value( "jabber/autoconnect", true ).toBool() ) return false; - QString jid = APP->settings()->value( "jabber/username" ).toString(); - QString server = APP->settings()->value( "jabber/server" ).toString(); - QString password = APP->settings()->value( "jabber/password" ).toString(); - unsigned int port = APP->settings()->value( "jabber/port", 5222 ).toUInt(); + QString jid = TomahawkSettings::instance()->value( "jabber/username" ).toString(); + QString server = TomahawkSettings::instance()->value( "jabber/server" ).toString(); + QString password = TomahawkSettings::instance()->value( "jabber/password" ).toString(); + unsigned int port = TomahawkSettings::instance()->value( "jabber/port", 5222 ).toUInt(); // gtalk check if( server.isEmpty() && ( jid.contains( "@gmail.com" ) || jid.contains( "@googlemail.com" ) ) ) diff --git a/src/sip/jabber/jabber.h b/src/sip/jabber/jabber.h index 69710549d..26350986b 100644 --- a/src/sip/jabber/jabber.h +++ b/src/sip/jabber/jabber.h @@ -1,10 +1,12 @@ #ifndef JABBER_H #define JABBER_H -#include "SipPlugin.h" +#include "sip/SipPlugin.h" #include "jabber_p.h" -class JabberPlugin : public SipPlugin +#include "dllmacro.h" + +class DLLEXPORT JabberPlugin : public SipPlugin { Q_OBJECT Q_INTERFACES( SipPlugin ) diff --git a/src/sip/jabber/jabber_p.cpp b/src/sip/jabber/jabber_p.cpp index dea6f6604..d6409ce51 100644 --- a/src/sip/jabber/jabber_p.cpp +++ b/src/sip/jabber/jabber_p.cpp @@ -247,6 +247,7 @@ Jabber_p::onDisconnect( ConnectionError e ) { qDebug() << "Jabber Disconnected"; QString error; + bool triggeredDisconnect = false; switch( e ) { @@ -330,14 +331,17 @@ Jabber_p::onDisconnect( ConnectionError e ) default : error = "UNKNOWN ERROR"; + triggeredDisconnect = true; } qDebug() << "Connection error msg:" << error; - emit authError( e, error ); + // Assume that an unknown error is due to a disconnect triggered by the user + if( !triggeredDisconnect ) + emit authError( e, error ); // trigger reconnect emit disconnected(); - // trigger reconnect + } diff --git a/src/sip/jabber/jabber_p.h b/src/sip/jabber/jabber_p.h index 66ab35f77..87af4779a 100644 --- a/src/sip/jabber/jabber_p.h +++ b/src/sip/jabber/jabber_p.h @@ -66,8 +66,6 @@ public: void setProxy( QNetworkProxy* proxy ); - void disconnect(); - /// GLOOX IMPLEMENTATION STUFF FOLLOWS virtual void onConnect(); virtual void onDisconnect( gloox::ConnectionError e ); @@ -124,6 +122,7 @@ public slots: void sendMsg( const QString& to, const QString& msg ); void broadcastMsg( const QString& msg ); void addContact( const QString& jid, const QString& msg = QString() ); + void disconnect(); private slots: void doJabberRecv(); diff --git a/src/sip/zeroconf/CMakeLists.txt b/src/sip/zeroconf/CMakeLists.txt new file mode 100644 index 000000000..5df9eb96f --- /dev/null +++ b/src/sip/zeroconf/CMakeLists.txt @@ -0,0 +1,41 @@ +project( tomahawk ) + +include( ${QT_USE_FILE} ) +add_definitions( ${QT_DEFINITIONS} ) +add_definitions( -DQT_PLUGIN ) +add_definitions( -DQT_SHARED ) +add_definitions( -DDLLEXPORT_PRO ) + +set( zeroconfSources + zeroconf.cpp +) + +set( zeroconfHeaders + zeroconf.h + tomahawkzeroconf.h +) + +include_directories( . ${CMAKE_CURRENT_BINARY_DIR} .. + ${QT_INCLUDE_DIR} +) + +qt4_wrap_cpp( zeroconfMoc ${zeroconfHeaders} ) +add_library( sip_zeroconf SHARED ${zeroconfSources} ${zeroconfMoc} ) + +IF( WIN32 ) +SET( OS_SPECIFIC_LINK_LIBRARIES + ${OS_SPECIFIC_LINK_LIBRARIES} + "${CMAKE_CURRENT_SOURCE_DIR}/../../../build/src/libtomahawk/libtomahawklib.dll" +) +ENDIF( WIN32 ) + +target_link_libraries( sip_zeroconf + ${QT_LIBRARIES} + ${OS_SPECIFIC_LINK_LIBRARIES} +) + +IF( APPLE ) + SET( CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} "-undefined dynamic_lookup" ) +ENDIF( APPLE ) + +install( TARGETS sip_zeroconf DESTINATION lib ) diff --git a/src/tomahawkzeroconf.h b/src/sip/zeroconf/tomahawkzeroconf.h similarity index 94% rename from src/tomahawkzeroconf.h rename to src/sip/zeroconf/tomahawkzeroconf.h index c88a1d06a..56b7acc45 100644 --- a/src/tomahawkzeroconf.h +++ b/src/sip/zeroconf/tomahawkzeroconf.h @@ -10,7 +10,8 @@ #include #include -#include "tomahawk/tomahawkapp.h" +#include "database/database.h" +#include "network/servent.h" class Node : public QObject { @@ -68,7 +69,7 @@ public slots: qDebug() << "Advertising us on the LAN"; QByteArray advert = QString( "TOMAHAWKADVERT:%1:%2" ) .arg( m_port ) - .arg( TomahawkApp::instance()->nodeID() ) + .arg( Database::instance()->dbid() ) .toAscii(); m_sock.writeDatagram( advert.data(), advert.size(), QHostAddress::Broadcast, ZCONF_PORT ); @@ -100,7 +101,7 @@ private slots: { bool ok; int port = parts.at(1).toInt( &ok ); - if(ok && TomahawkApp::instance()->nodeID() != parts.at( 2 ) ) + if(ok && Database::instance()->dbid() != parts.at( 2 ) ) { qDebug() << "ADVERT received:" << sender << port; Node *n = new Node( sender.toString(), parts.at( 2 ), port ); diff --git a/src/sip/zeroconf/zeroconf.cpp b/src/sip/zeroconf/zeroconf.cpp new file mode 100644 index 000000000..1462d5d45 --- /dev/null +++ b/src/sip/zeroconf/zeroconf.cpp @@ -0,0 +1,29 @@ +#include "zeroconf.h" + +#include + + +bool +ZeroconfPlugin::connect() +{ + delete m_zeroconf; + m_zeroconf = new TomahawkZeroconf( Servent::instance()->port(), this ); + QObject::connect( m_zeroconf, SIGNAL( tomahawkHostFound( const QString&, int, const QString&, const QString& ) ), + SLOT( lanHostFound( const QString&, int, const QString&, const QString& ) ) ); + + m_zeroconf->advertise(); + + return true; +} + + +void +ZeroconfPlugin::lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid ) +{ + qDebug() << "Found LAN host:" << host << port << nodeid; + + if ( !Servent::instance()->connectedToSession( nodeid ) ) + Servent::instance()->connectToPeer( host, port, "whitelist", name, nodeid ); +} + +Q_EXPORT_PLUGIN2( sip, ZeroconfPlugin ) diff --git a/src/sip/zeroconf/zeroconf.h b/src/sip/zeroconf/zeroconf.h new file mode 100644 index 000000000..d4fc6a314 --- /dev/null +++ b/src/sip/zeroconf/zeroconf.h @@ -0,0 +1,47 @@ +#ifndef ZEROCONF_H +#define ZEROCONF_H + +#include "sip/SipPlugin.h" +#include "tomahawkzeroconf.h" + +#include "dllmacro.h" + +class DLLEXPORT ZeroconfPlugin : public SipPlugin +{ + Q_OBJECT + Q_INTERFACES( SipPlugin ) + +public: + ZeroconfPlugin() + : m_zeroconf( 0 ) + {} + + virtual ~ZeroconfPlugin() {} + +public slots: + virtual bool connect(); + + void disconnect() + { + } + + void sendMsg( const QString& to, const QString& msg ) + { + } + + void broadcastMsg( const QString &msg ) + { + } + + void addContact( const QString &jid, const QString& msg = QString() ) + { + } + +private slots: + void lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid ); + +private: + TomahawkZeroconf* m_zeroconf; +}; + +#endif diff --git a/src/sourcetree/sourcesmodel.cpp b/src/sourcetree/sourcesmodel.cpp index 796802cc4..2d22af36c 100644 --- a/src/sourcetree/sourcesmodel.cpp +++ b/src/sourcetree/sourcesmodel.cpp @@ -6,8 +6,8 @@ #include #include "tomahawk/tomahawkapp.h" -#include "tomahawk/query.h" -#include "tomahawk/sourcelist.h" +#include "query.h" +#include "sourcelist.h" #include "sourcetreeitem.h" #include "imagebutton.h" @@ -19,8 +19,8 @@ SourcesModel::SourcesModel( QObject* parent ) { setColumnCount( 1 ); - connect( &APP->sourcelist(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) ); - connect( &APP->sourcelist(), SIGNAL( sourceRemoved( Tomahawk::source_ptr ) ), SLOT( onSourceRemoved( Tomahawk::source_ptr ) ) ); + connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) ); + connect( SourceList::instance(), SIGNAL( sourceRemoved( Tomahawk::source_ptr ) ), SLOT( onSourceRemoved( Tomahawk::source_ptr ) ) ); connect( parent, SIGNAL( onOnline( QModelIndex ) ), SLOT( onItemOnline( QModelIndex ) ) ); connect( parent, SIGNAL( onOffline( QModelIndex ) ), SLOT( onItemOffline( QModelIndex ) ) ); @@ -84,7 +84,7 @@ SourcesModel::data( const QModelIndex& index, int role ) const void SourcesModel::loadSources() { - QList sources = APP->sourcelist().sources(); + QList sources = SourceList::instance()->sources(); foreach( const source_ptr& source, sources ) appendItem( source ); diff --git a/src/sourcetree/sourcesmodel.h b/src/sourcetree/sourcesmodel.h index 816385bd8..aa33e10ac 100644 --- a/src/sourcetree/sourcesmodel.h +++ b/src/sourcetree/sourcesmodel.h @@ -3,8 +3,8 @@ #include -#include "tomahawk/source.h" -#include "tomahawk/typedefs.h" +#include "source.h" +#include "typedefs.h" class SourceTreeItem; diff --git a/src/sourcetree/sourcetreeitem.cpp b/src/sourcetree/sourcetreeitem.cpp index 2b8c21df2..234e5d4e1 100644 --- a/src/sourcetree/sourcetreeitem.cpp +++ b/src/sourcetree/sourcetreeitem.cpp @@ -3,8 +3,8 @@ #include #include -#include "tomahawk/collection.h" -#include "tomahawk/playlist.h" +#include "collection.h" +#include "playlist.h" #include "tomahawk/tomahawkapp.h" #include "sourcesmodel.h" diff --git a/src/sourcetree/sourcetreeitem.h b/src/sourcetree/sourcetreeitem.h index ecc83d3b5..f23bf2f65 100644 --- a/src/sourcetree/sourcetreeitem.h +++ b/src/sourcetree/sourcetreeitem.h @@ -4,7 +4,7 @@ #include #include -#include "tomahawk/typedefs.h" +#include "typedefs.h" #include "sourcetreeitemwidget.h" #include "dynamic/DynamicPlaylist.h" diff --git a/src/sourcetree/sourcetreeitemwidget.cpp b/src/sourcetree/sourcetreeitemwidget.cpp index b10aeecdb..edfffc93b 100644 --- a/src/sourcetree/sourcetreeitemwidget.cpp +++ b/src/sourcetree/sourcetreeitemwidget.cpp @@ -3,10 +3,10 @@ #include "ui_sourcetreeitemwidget.h" #include "tomahawk/tomahawkapp.h" -#include "tomahawk/album.h" -#include "database.h" -#include "databasecommand_collectionstats.h" -#include "dbsyncconnection.h" +#include "album.h" +#include "database/database.h" +#include "database/databasecommand_collectionstats.h" +#include "network/dbsyncconnection.h" #include "playlistmanager.h" using namespace Tomahawk; diff --git a/src/sourcetree/sourcetreeitemwidget.h b/src/sourcetree/sourcetreeitemwidget.h index 942ac9753..eae2c115e 100644 --- a/src/sourcetree/sourcetreeitemwidget.h +++ b/src/sourcetree/sourcetreeitemwidget.h @@ -3,7 +3,7 @@ #include -#include "tomahawk/source.h" +#include "source.h" namespace Ui { diff --git a/src/sourcetree/sourcetreeview.cpp b/src/sourcetree/sourcetreeview.cpp index 4305f8d2a..a6089af86 100644 --- a/src/sourcetree/sourcetreeview.cpp +++ b/src/sourcetree/sourcetreeview.cpp @@ -1,11 +1,12 @@ #include "sourcetreeview.h" -#include "tomahawk/tomahawkapp.h" -#include "tomahawk/playlist.h" +#include "playlist.h" #include "collectionmodel.h" #include "playlistmanager.h" #include "sourcetreeitem.h" #include "sourcesmodel.h" +#include "sourcelist.h" +#include "tomahawk/tomahawkapp.h" #include #include @@ -70,7 +71,7 @@ SourceTreeView::SourceTreeView( QWidget* parent ) connect( this, SIGNAL( clicked( QModelIndex ) ), SLOT( onItemActivated( QModelIndex ) ) ); connect( selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ), SLOT( onSelectionChanged() ) ); - connect( &APP->sourcelist(), SIGNAL( sourceRemoved( Tomahawk::source_ptr ) ), SLOT( onSourceOffline( Tomahawk::source_ptr ) ) ); + connect( SourceList::instance(), SIGNAL( sourceRemoved( Tomahawk::source_ptr ) ), SLOT( onSourceOffline( Tomahawk::source_ptr ) ) ); m_model->appendItem( source_ptr() ); } diff --git a/src/sourcetree/sourcetreeview.h b/src/sourcetree/sourcetreeview.h index 169f710eb..f896823c8 100644 --- a/src/sourcetree/sourcetreeview.h +++ b/src/sourcetree/sourcetreeview.h @@ -4,7 +4,7 @@ #include #include -#include "tomahawk/source.h" +#include "source.h" class CollectionModel; class PlaylistModel; diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index 9d518d41b..f33e05994 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -6,9 +6,9 @@ #include #include -#include "tomahawk/artist.h" -#include "tomahawk/album.h" -#include "tomahawk/collection.h" +#include "artist.h" +#include "album.h" +#include "collection.h" #include "tomahawk/infosystem.h" #include "database/database.h" #include "database/databasecollection.h" @@ -21,9 +21,9 @@ #include "xmppbot/xmppbot.h" #include "web/api_v1.h" #include "scriptresolver.h" +#include "sourcelist.h" #include "audioengine.h" -#include "tomahawkzeroconf.h" #ifndef TOMAHAWK_HEADLESS #include "tomahawkwindow.h" @@ -104,14 +104,16 @@ using namespace Tomahawk; TomahawkApp::TomahawkApp( int& argc, char *argv[] ) : TOMAHAWK_APPLICATION( argc, argv ) , m_audioEngine( 0 ) - , m_zeroconf( 0 ) - , m_settings( 0 ) , m_nam( 0 ) , m_proxy( 0 ) , m_infoSystem( 0 ) { qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) ); + new Pipeline( this ); + new SourceList( this ); + new Servent( this ); + #ifdef TOMAHAWK_HEADLESS m_headless = true; #else @@ -132,7 +134,7 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] ) registerMetaTypes(); setupLogfile(); - m_settings = new TomahawkSettings( this ); + new TomahawkSettings( this ); m_audioEngine = new AudioEngine; setupDatabase(); @@ -158,10 +160,10 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] ) #endif // Set up proxy - if( m_settings->proxyType() != QNetworkProxy::NoProxy && !m_settings->proxyHost().isEmpty() ) + if( TomahawkSettings::instance()->proxyType() != QNetworkProxy::NoProxy && !TomahawkSettings::instance()->proxyHost().isEmpty() ) { qDebug() << "Setting proxy to saved values"; - m_proxy = new QNetworkProxy( static_cast(m_settings->proxyType()), m_settings->proxyHost(), m_settings->proxyPort(), m_settings->proxyUsername(), m_settings->proxyPassword() ); + m_proxy = new QNetworkProxy( static_cast(TomahawkSettings::instance()->proxyType()), TomahawkSettings::instance()->proxyHost(), TomahawkSettings::instance()->proxyPort(), TomahawkSettings::instance()->proxyUsername(), TomahawkSettings::instance()->proxyPassword() ); qDebug() << "Proxy type = " << QString::number( static_cast(m_proxy->type()) ); qDebug() << "Proxy host = " << m_proxy->hostName(); QNetworkAccessManager* nam = TomahawkApp::instance()->nam(); @@ -174,10 +176,6 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] ) m_infoSystem = new Tomahawk::InfoSystem::InfoSystem( this ); - boost::function(result_ptr)> fac = - boost::bind( &TomahawkApp::httpIODeviceFactory, this, _1 ); - this->registerIODeviceFactory( "http", fac ); - if( !arguments().contains("--nojabber") ) { setupSIP(); @@ -199,22 +197,13 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] ) startServent(); //loadPlugins(); - if( arguments().contains( "--http" ) || settings()->value( "network/http", true ).toBool() ) + if( arguments().contains( "--http" ) || TomahawkSettings::instance()->value( "network/http", true ).toBool() ) startHTTP(); - if ( !arguments().contains( "--nozeroconf" ) ) - { - // advertise our servent on the LAN - m_zeroconf = new TomahawkZeroconf( m_servent.port(), this ); - connect( m_zeroconf, SIGNAL( tomahawkHostFound( const QString&, int, const QString&, const QString& ) ), - SLOT( lanHostFound( const QString&, int, const QString&, const QString& ) ) ); - m_zeroconf->advertise(); - } - m_sipHandler->connect(); #ifndef TOMAHAWK_HEADLESS - if ( !m_settings->hasScannerPath() ) + if ( !TomahawkSettings::instance()->hasScannerPath() ) { m_mainwindow->showSettingsDialog(); } @@ -232,13 +221,6 @@ TomahawkApp::~TomahawkApp() delete m_mainwindow; delete m_audioEngine; #endif - - delete m_zeroconf; - delete m_db; - m_db = 0; - - // always last thing, incase other objects save state on exit: - delete m_settings; } @@ -321,18 +303,8 @@ TomahawkApp::setupDatabase() } qDebug() << "Using database:" << dbpath; - m_db = new Database( dbpath, this ); - m_pipeline.databaseReady(); -} - - -void -TomahawkApp::lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid ) -{ - qDebug() << "Found LAN host:" << host << port << nodeid; - - if ( !m_servent.connectedToSession( nodeid ) ) - m_servent.connectToPeer( host, port, "whitelist", name, nodeid ); + new Database( dbpath, this ); + Pipeline::instance()->databaseReady(); } @@ -356,8 +328,8 @@ void TomahawkApp::setupPipeline() { // setup resolvers for local content, and (cached) remote collection content - m_pipeline.addResolver( new DatabaseResolver( true, 100 ) ); - m_pipeline.addResolver( new DatabaseResolver( false, 90 ) ); + Pipeline::instance()->addResolver( new DatabaseResolver( true, 100 ) ); + Pipeline::instance()->addResolver( new DatabaseResolver( false, 90 ) ); // new ScriptResolver("/home/rj/src/tomahawk-core/contrib/magnatune/magnatune-resolver.php"); } @@ -370,26 +342,22 @@ TomahawkApp::initLocalCollection() collection_ptr coll( new DatabaseCollection( src ) ); src->addCollection( coll ); - this->sourcelist().add( src ); - - boost::function(result_ptr)> fac = - boost::bind( &TomahawkApp::localFileIODeviceFactory, this, _1 ); - this->registerIODeviceFactory( "file", fac ); + SourceList::instance()->add( src ); // to make the stats signal be emitted by our local source // this will update the sidebar, etc. DatabaseCommand_CollectionStats* cmd = new DatabaseCommand_CollectionStats( src ); connect( cmd, SIGNAL( done( const QVariantMap& ) ), src.data(), SLOT( setStats( const QVariantMap& ) ), Qt::QueuedConnection ); - database()->enqueue( QSharedPointer( cmd ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); } void TomahawkApp::startServent() { - bool upnp = !arguments().contains( "--noupnp" ) && settings()->value( "network/upnp", true ).toBool(); - if ( !m_servent.startListening( QHostAddress( QHostAddress::Any ), upnp ) ) + bool upnp = !arguments().contains( "--noupnp" ) && TomahawkSettings::instance()->value( "network/upnp", true ).toBool(); + if ( !Servent::instance()->startListening( QHostAddress( QHostAddress::Any ), upnp ) ) { qDebug() << "Failed to start listening with servent"; exit( 1 ); @@ -397,11 +365,6 @@ TomahawkApp::startServent() //QString key = m_servent.createConnectionKey(); //qDebug() << "Generated an offer key: " << key; - - boost::function(result_ptr)> fac = - boost::bind( &Servent::remoteIODeviceFactory, &m_servent, _1 ); - - this->registerIODeviceFactory( "servent", fac ); } @@ -425,7 +388,7 @@ TomahawkApp::loadPlugins() if ( !pluginst ) continue; - PluginAPI* api = new PluginAPI( this->pipeline() ); + PluginAPI* api = new PluginAPI( Pipeline::instance() ); TomahawkPlugin* plugin = pluginst->factory( api ); qDebug() << "Loaded Plugin:" << plugin->name(); qDebug() << plugin->description(); @@ -452,58 +415,3 @@ TomahawkApp::setupSIP() // m_sipHandler->setProxy( m_proxy ); } - -void -TomahawkApp::registerIODeviceFactory( const QString &proto, boost::function(Tomahawk::result_ptr)> fac ) -{ - m_iofactories.insert( proto, fac ); - qDebug() << "Registered IODevice Factory for" << proto; -} - - -QSharedPointer -TomahawkApp::getIODeviceForUrl( const Tomahawk::result_ptr& result ) -{ - qDebug() << Q_FUNC_INFO << thread(); - QSharedPointer 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 -TomahawkApp::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( io ); -} - - -QSharedPointer -TomahawkApp::httpIODeviceFactory( const Tomahawk::result_ptr& result ) -{ - qDebug() << Q_FUNC_INFO << result->url(); - QNetworkRequest req( result->url() ); - QNetworkReply* reply = APP->nam()->get( req ); - return QSharedPointer( reply ); -} - - -const QString& -TomahawkApp::nodeID() const -{ - return m_db->dbid(); -} diff --git a/src/tomahawktrayicon.cpp b/src/tomahawktrayicon.cpp index 92996b57f..882a6023f 100644 --- a/src/tomahawktrayicon.cpp +++ b/src/tomahawktrayicon.cpp @@ -3,7 +3,7 @@ #include #include "tomahawk/tomahawkapp.h" -#include "tomahawk/artist.h" +#include "artist.h" #include "audio/audioengine.h" #include "tomahawkwindow.h" diff --git a/src/tomahawktrayicon.h b/src/tomahawktrayicon.h index d975f93f2..c73a85781 100644 --- a/src/tomahawktrayicon.h +++ b/src/tomahawktrayicon.h @@ -5,7 +5,7 @@ #include #include -#include "tomahawk/result.h" +#include "result.h" class TomahawkTrayIcon : public QSystemTrayIcon { diff --git a/src/tomahawkwindow.cpp b/src/tomahawkwindow.cpp index de81dd366..6871c4102 100644 --- a/src/tomahawkwindow.cpp +++ b/src/tomahawkwindow.cpp @@ -13,10 +13,9 @@ #include #include "tomahawk/tomahawkapp.h" -#include "tomahawk/functimeout.h" -#include "tomahawk/playlist.h" -#include "tomahawk/query.h" -#include "tomahawk/artist.h" +#include "playlist.h" +#include "query.h" +#include "artist.h" #include "database/databasecommand_collectionstats.h" #include "topbar/topbar.h" @@ -24,8 +23,8 @@ #include "sip/SipHandler.h" #include "audiocontrols.h" -#include "controlconnection.h" -#include "database.h" +#include "network/controlconnection.h" +#include "database/database.h" #include "musicscanner.h" #include "playlistmanager.h" #include "proxystyle.h" @@ -99,7 +98,7 @@ TomahawkWindow::~TomahawkWindow() void TomahawkWindow::loadSettings() { - TomahawkSettings* s = APP->settings(); + TomahawkSettings* s = TomahawkSettings::instance(); if ( !s->mainWindowGeometry().isEmpty() ) restoreGeometry( s->mainWindowGeometry() ); @@ -111,7 +110,7 @@ TomahawkWindow::loadSettings() void TomahawkWindow::saveSettings() { - TomahawkSettings* s = APP->settings(); + TomahawkSettings* s = TomahawkSettings::instance(); s->setMainWindowGeometry( saveGeometry() ); s->setMainWindowState( saveState() ); } @@ -172,6 +171,7 @@ TomahawkWindow::setupSignals() connect( ui->actionCreateDynamicPlaylist, SIGNAL( triggered() ), SLOT( createDynamicPlaylist() )); connect( ui->actionAboutTomahawk, SIGNAL( triggered() ), SLOT( showAboutTomahawk() ) ); connect( ui->actionExit, SIGNAL( triggered() ), APP, SLOT( quit() ) ); + connect( ui->statusButton, SIGNAL( clicked() ), APP->sipHandler(), SLOT( toggleConnect() ) ); // connect( APP->sipHandler(), SIGNAL( connected() ), SLOT( onSipConnected() ) ); @@ -236,7 +236,7 @@ TomahawkWindow::showSettingsDialog() void TomahawkWindow::rescanCollectionManually() { - TomahawkSettings* s = APP->settings(); + TomahawkSettings* s = TomahawkSettings::instance(); bool ok; QString path = QInputDialog::getText( this, tr( "Enter path to music dir:" ), tr( "Path pls" ), QLineEdit::Normal, @@ -263,7 +263,7 @@ TomahawkWindow::scanFinished() void TomahawkWindow::addPeerManually() { - TomahawkSettings* s = APP->settings(); + TomahawkSettings* s = TomahawkSettings::instance(); bool ok; QString addr = QInputDialog::getText( this, tr( "Connect To Peer" ), tr( "Enter peer address:" ), QLineEdit::Normal, @@ -287,7 +287,7 @@ TomahawkWindow::addPeerManually() return; qDebug() << "Attempting to connect to" << addr; - APP->servent().connectToPeer( addr, port, key ); + Servent::instance()->connectToPeer( addr, port, key ); } @@ -337,7 +337,7 @@ TomahawkWindow::createPlaylist( bool dynamic ) if ( !ok || name.isEmpty() ) return; - source_ptr author = APP->sourcelist().getLocal(); + source_ptr author = SourceList::instance()->getLocal(); QString id = uuid(); QString info = ""; // FIXME QString creator = "someone"; // FIXME @@ -400,5 +400,5 @@ TomahawkWindow::setWindowTitle( const QString& title ) void TomahawkWindow::showAboutTomahawk() { - QMessageBox::about( this, "About Tomahawk", "Copyright 2010 Christian Muehlhaeuser \n\nThanks to: Leo Franchi, Jeff Mitchell, Dominik Schmidt and Steve Robertson" ); + QMessageBox::about( this, "About Tomahawk", "Copyright 2010 Christian Muehlhaeuser \n\nThanks to: Leo Franchi, Jeff Mitchell, Dominik Schmidt, Alejandro Wainzinger and Steve Robertson" ); } diff --git a/src/tomahawkwindow.h b/src/tomahawkwindow.h index bf1e28055..e5960c41a 100644 --- a/src/tomahawkwindow.h +++ b/src/tomahawkwindow.h @@ -7,7 +7,7 @@ #include #include -#include "tomahawk/pipeline.h" +#include "result.h" class QAction; diff --git a/src/topbar/topbar.cpp b/src/topbar/topbar.cpp index 9b41878ac..a144bcdc7 100644 --- a/src/topbar/topbar.cpp +++ b/src/topbar/topbar.cpp @@ -6,7 +6,6 @@ #include #include -#include "tomahawk/functimeout.h" #include "tomahawk/tomahawkapp.h" #define MAXDUDES 3 diff --git a/src/topbar/topbar.h b/src/topbar/topbar.h index eccdcf886..8d113a847 100644 --- a/src/topbar/topbar.h +++ b/src/topbar/topbar.h @@ -5,7 +5,7 @@ #include #include -#include "tomahawk/sourcelist.h" +#include "sourcelist.h" namespace Ui { diff --git a/src/transferview.cpp b/src/transferview.cpp index 628e32f03..936be9f59 100644 --- a/src/transferview.cpp +++ b/src/transferview.cpp @@ -4,7 +4,7 @@ #include #include "tomahawk/tomahawkapp.h" -#include "tomahawk/artist.h" +#include "artist.h" #include "network/filetransferconnection.h" #include "network/servent.h" @@ -20,8 +20,8 @@ TransferView::TransferView( AnimatedSplitter* parent ) layout()->setMargin( 0 ); layout()->addWidget( m_tree ); - connect( &APP->servent(), SIGNAL( fileTransferStarted( FileTransferConnection* ) ), SLOT( fileTransferRegistered( FileTransferConnection* ) ) ); - connect( &APP->servent(), SIGNAL( fileTransferFinished( FileTransferConnection* ) ), SLOT( fileTransferFinished( FileTransferConnection* ) ) ); + connect( Servent::instance(), SIGNAL( fileTransferStarted( FileTransferConnection* ) ), SLOT( fileTransferRegistered( FileTransferConnection* ) ) ); + connect( Servent::instance(), SIGNAL( fileTransferFinished( FileTransferConnection* ) ), SLOT( fileTransferFinished( FileTransferConnection* ) ) ); QStringList headers; headers << tr( "Peer" ) << tr( "Rate" ) << tr( "Track" ); diff --git a/src/transferview.h b/src/transferview.h index cad77fae2..3520c03be 100644 --- a/src/transferview.h +++ b/src/transferview.h @@ -4,7 +4,7 @@ #include #include -#include "tomahawk/typedefs.h" +#include "typedefs.h" #include "utils/animatedsplitter.h" class FileTransferConnection; diff --git a/src/web/api_v1.h b/src/web/api_v1.h index 89b65b822..0a77a679d 100644 --- a/src/web/api_v1.h +++ b/src/web/api_v1.h @@ -3,8 +3,8 @@ // See: http://doc.libqxt.org/tip/qxtweb.html -#include "tomahawk/tomahawkapp.h" -#include "tomahawk/query.h" +#include "query.h" +#include "pipeline.h" #include "QxtHttpServerConnector" #include "QxtHttpSessionManager" @@ -18,6 +18,8 @@ #include #include +#include "network/servent.h" + class Api_v1 : public QxtWebSlotService { Q_OBJECT @@ -55,12 +57,12 @@ public slots: using namespace Tomahawk; RID rid = event->url.path().mid(5); qDebug() << "Request for sid " << rid; - result_ptr rp = APP->pipeline()->result( rid ); + result_ptr rp = Pipeline::instance()->result( rid ); if( rp.isNull() ) { return send404( event ); } - QSharedPointer iodev = APP->getIODeviceForUrl( rp ); + QSharedPointer iodev = Servent::instance()->getIODeviceForUrl( rp ); if( iodev.isNull() ) { return send404( event ); // 503? @@ -111,7 +113,7 @@ public slots: m.insert( "qid", qid ); Tomahawk::query_ptr qry( new Tomahawk::Query( m ) ); - APP->pipeline()->add( qry ); + Tomahawk::Pipeline::instance()->add( qry ); QVariantMap r; r.insert( "qid", qid ); @@ -127,7 +129,7 @@ public slots: } using namespace Tomahawk; - query_ptr qry = APP->pipeline()->query( event->url.queryItemValue("qid") ); + query_ptr qry = Pipeline::instance()->query( event->url.queryItemValue("qid") ); if( qry.isNull() ) { send404( event ); diff --git a/src/xmppbot/xmppbot.cpp b/src/xmppbot/xmppbot.cpp index 9da87516b..84f3ea9ff 100644 --- a/src/xmppbot/xmppbot.cpp +++ b/src/xmppbot/xmppbot.cpp @@ -2,10 +2,11 @@ #include "tomahawk/tomahawkapp.h" #include "tomahawk/infosystem.h" -#include "tomahawk/album.h" -#include "tomahawk/typedefs.h" -#include -#include