1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-13 12:31:52 +02:00

* Moved InfoSystem into libTomahawk.

* Made InfoSystem a singleton.
* Don't access InfoSystem via TomahawkApp any longer.
* Progress on ArtistView & TreeModel.
This commit is contained in:
Christian Muehlhaeuser 2011-04-14 00:32:16 +02:00
parent 43a08b7957
commit 9f4c3bb461
35 changed files with 352 additions and 273 deletions

View File

@ -52,10 +52,6 @@ class XMPPBot;
namespace Tomahawk
{
class ShortcutHandler;
namespace InfoSystem
{
class InfoSystem;
}
}
#ifdef LIBLASTFM_FOUND
@ -83,7 +79,6 @@ public:
static TomahawkApp* instance();
SipHandler* sipHandler() { return m_sipHandler; }
Tomahawk::InfoSystem::InfoSystem* infoSystem() { return m_infoSystem; }
XMPPBot* xmppBot() { return m_xmppBot; }
#ifndef TOMAHAWK_HEADLESS
@ -138,8 +133,6 @@ private:
bool m_headless;
Tomahawk::InfoSystem::InfoSystem* m_infoSystem;
QxtHttpServerConnector m_connector;
QxtHttpSessionManager m_session;
};

View File

@ -34,12 +34,6 @@ ENDIF()
SET( tomahawkSources ${tomahawkSources}
sip/SipHandler.cpp
infosystem/infosystemcache.cpp
infosystem/infosystem.cpp
infosystem/infoplugins/echonestplugin.cpp
infosystem/infoplugins/lastfmplugin.cpp
infosystem/infoplugins/musixmatchplugin.cpp
web/api_v1.cpp
resolvers/scriptresolver.cpp
@ -74,15 +68,9 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
SET( tomahawkHeaders ${tomahawkHeaders}
"${TOMAHAWK_INC_DIR}/tomahawk/tomahawkapp.h"
"${TOMAHAWK_INC_DIR}/tomahawk/infosystem.h"
sip/SipHandler.h
infosystem/infosystemcache.h
infosystem/infoplugins/echonestplugin.h
infosystem/infoplugins/lastfmplugin.h
infosystem/infoplugins/musixmatchplugin.h
web/api_v1.h
resolvers/scriptresolver.h
@ -137,8 +125,6 @@ INCLUDE_DIRECTORIES(
topbar
utils
libtomahawk
libtomahawk/utils
infosystem
mac
${THIRDPARTY_DIR}/alsa-playback

View File

@ -21,7 +21,6 @@
#include <QNetworkReply>
#include "tomahawk/tomahawkapp.h"
#include "audio/audioengine.h"
#include "playlist/playlistmanager.h"
#include "utils/imagebutton.h"
@ -31,7 +30,7 @@
#define LASTFM_DEFAULT_COVER "http://cdn.last.fm/flatness/catalogue/noimage"
static QString s_infoIdentifier = QString( "AUDIOCONTROLS" );
static QString s_acInfoIdentifier = QString( "AUDIOCONTROLS" );
AudioControls::AudioControls( QWidget* parent )
@ -168,11 +167,11 @@ AudioControls::AudioControls( QWidget* parent )
m_defaultCover = QPixmap( RESPATH "images/no-album-art-placeholder.png" )
.scaled( ui->coverImage->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
connect( TomahawkApp::instance()->infoSystem(),
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
SLOT( infoSystemInfo( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ) );
connect( TomahawkApp::instance()->infoSystem(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );
connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );
onPlaybackStopped(); // initial state
}
@ -220,8 +219,8 @@ AudioControls::onPlaybackStarted( const Tomahawk::result_ptr& result )
trackInfo["artist"] = QVariant::fromValue< QString >( result->artist()->name() );
trackInfo["album"] = QVariant::fromValue< QString >( result->album()->name() );
TomahawkApp::instance()->infoSystem()->getInfo(
s_infoIdentifier, Tomahawk::InfoSystem::InfoAlbumCoverArt,
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo(
s_acInfoIdentifier, Tomahawk::InfoSystem::InfoAlbumCoverArt,
QVariant::fromValue< Tomahawk::InfoSystem::InfoCustomData >( trackInfo ), Tomahawk::InfoSystem::InfoCustomData() );
}
@ -232,8 +231,8 @@ AudioControls::infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType ty
Q_UNUSED( input );
Q_UNUSED( customData );
qDebug() << Q_FUNC_INFO;
if ( caller != s_infoIdentifier || type != Tomahawk::InfoSystem::InfoAlbumCoverArt )
qDebug() << Q_FUNC_INFO << caller << type << s_acInfoIdentifier << Tomahawk::InfoSystem::InfoAlbumCoverArt;
if ( caller != s_acInfoIdentifier || type != Tomahawk::InfoSystem::InfoAlbumCoverArt )
{
qDebug() << "Info of wrong type or not with our identifier";
return;

View File

@ -23,7 +23,7 @@
#include "result.h"
#include "playlistinterface.h"
#include "tomahawk/infosystem.h"
#include "infosystem/infosystem.h"
namespace Ui
{

View File

@ -75,6 +75,12 @@ set( libSources
database/databasecommand_clientauthvalid.cpp
database/database.cpp
infosystem/infosystemcache.cpp
infosystem/infosystem.cpp
infosystem/infoplugins/echonestplugin.cpp
infosystem/infoplugins/lastfmplugin.cpp
infosystem/infoplugins/musixmatchplugin.cpp
playlist/treemodel.cpp
playlist/treeproxymodel.cpp
playlist/treeheader.cpp
@ -226,6 +232,12 @@ set( libHeaders
database/databasecommand_addclientauth.h
database/databasecommand_clientauthvalid.h
infosystem/infosystem.h
infosystem/infosystemcache.h
infosystem/infoplugins/echonestplugin.h
infosystem/infoplugins/lastfmplugin.h
infosystem/infoplugins/musixmatchplugin.h
network/bufferiodevice.h
network/msgprocessor.h
network/remotecollection.h
@ -330,9 +342,9 @@ include_directories( . ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/.
${LIBECHONEST_INCLUDE_DIR}/..
${CLUCENE_INCLUDE_DIR}
${CLUCENE_LIBRARY_DIR}
${CMAKE_BINARY_DIR}/thirdparty/liblastfm2/src
../../include
../network
playlist
${THIRDPARTY_DIR}/libportfwd/include
@ -394,6 +406,10 @@ IF( UNIX AND NOT APPLE )
)
ENDIF( UNIX AND NOT APPLE )
IF(LIBLASTFM_FOUND)
SET(LINK_LIBRARIES ${LINK_LIBRARIES} tomahawk_lastfm2 )
ENDIF(LIBLASTFM_FOUND)
qt4_wrap_ui( libUI_H ${libUI} )
qt4_wrap_cpp( libMoc ${libHeaders} )
@ -422,6 +438,7 @@ target_link_libraries( tomahawklib
${QT_LIBRARIES}
${OS_SPECIFIC_LINK_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${LINK_LIBRARIES}
)
INSTALL( TARGETS tomahawklib DESTINATION lib${LIB_SUFFIX} )

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -93,7 +93,7 @@ Album::tracks()
cmd->setAlbum( this );
cmd->setSortOrder( DatabaseCommand_AllTracks::AlbumPosition );
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ),
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ),
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -95,7 +95,7 @@ Artist::tracks()
cmd->setArtist( this );
cmd->setSortOrder( DatabaseCommand_AllTracks::Album );
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ),
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ),
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -52,10 +52,10 @@ DatabaseCollection::loadDynamicPlaylists()
{
qDebug() << Q_FUNC_INFO;
DatabaseCommand_LoadAllDynamicPlaylists* cmd = new DatabaseCommand_LoadAllDynamicPlaylists( source() );
connect( cmd, SIGNAL( playlistLoaded( Tomahawk::source_ptr, QVariantList ) ),
SLOT( dynamicPlaylistCreated( const Tomahawk::source_ptr&, const QVariantList& ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}
@ -68,7 +68,7 @@ DatabaseCollection::loadTracks()
setLoaded();
DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( source()->collection() );
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ),
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ),
SLOT( setTracks( QList<Tomahawk::query_ptr> ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
@ -112,12 +112,12 @@ DatabaseCollection::playlists()
QList< dynplaylist_ptr > DatabaseCollection::dynamicPlaylists()
{
qDebug() << Q_FUNC_INFO;
if ( Collection::dynamicPlaylists().isEmpty() )
{
loadDynamicPlaylists();
}
return Collection::dynamicPlaylists();
}

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -16,8 +16,6 @@
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tomahawk/infosystem.h"
#include "tomahawk/tomahawkapp.h"
#include "echonestplugin.h"
#include <echonest/Artist.h>
#include <echonest/ArtistTypes.h>
@ -72,10 +70,10 @@ void EchoNestPlugin::getSongProfile(const QString &caller, const QVariant& data,
if( !isValidTrackData( caller, data, customData ) )
return;
// Track track( data.toString() );
// Artist artist( customData.data()->property("artistName").toString() );
// reply->setProperty("artist", QVariant::fromValue<Artist>(artist));
// reply->setProperty("artist", QVariant::fromValue<Artist>(artist));
// reply->setProperty( "data", data );
// m_replyMap[reply] = customData;
// connect(reply, SIGNAL(finished()), SLOT(getArtistBiographySlot()));
@ -85,7 +83,7 @@ void EchoNestPlugin::getArtistBiography(const QString &caller, const QVariant& d
{
if( !isValidArtistData( caller, data, customData ) )
return;
Echonest::Artist artist( data.toString() );
QNetworkReply *reply = artist.fetchBiographies();
reply->setProperty("artist", QVariant::fromValue<Echonest::Artist>(artist));
@ -99,7 +97,7 @@ void EchoNestPlugin::getArtistFamiliarity(const QString &caller, const QVariant&
{
if( !isValidArtistData( caller, data, customData ) )
return;
qDebug() << "Fetching artist familiarity!" << data;
Echonest::Artist artist( data.toString() );
QNetworkReply* reply = artist.fetchFamiliarity();
@ -107,14 +105,14 @@ void EchoNestPlugin::getArtistFamiliarity(const QString &caller, const QVariant&
reply->setProperty( "data", data );
m_replyMap[reply] = customData;
m_callerMap[reply] = caller;
connect(reply, SIGNAL(finished()), SLOT(getArtistFamiliaritySlot()));
connect(reply, SIGNAL(finished()), SLOT(getArtistFamiliaritySlot()));
}
void EchoNestPlugin::getArtistHotttnesss(const QString &caller, const QVariant& data, InfoCustomData &customData)
{
if( !isValidArtistData( caller, data, customData ) )
return;
Echonest::Artist artist( data.toString() );
QNetworkReply* reply = artist.fetchHotttnesss();
reply->setProperty( "artist", QVariant::fromValue<Echonest::Artist>(artist));
@ -128,7 +126,7 @@ void EchoNestPlugin::getArtistTerms(const QString &caller, const QVariant& data,
{
if( !isValidArtistData( caller, data, customData ) )
return;
Echonest::Artist artist( data.toString() );
QNetworkReply* reply = artist.fetchTerms( Echonest::Artist::Weight );
reply->setProperty( "artist", QVariant::fromValue<Echonest::Artist>(artist));
@ -162,7 +160,7 @@ void EchoNestPlugin::getArtistBiographySlot()
biographyMap[biography.site()]["attribution"] = biography.license().attribution;
biographyMap[biography.site()]["licensetype"] = biography.license().type;
biographyMap[biography.site()]["attribution"] = biography.license().url.toString();
}
emit info( m_callerMap[reply], Tomahawk::InfoSystem::InfoArtistBiography, reply->property( "data" ), QVariant::fromValue<Tomahawk::InfoSystem::InfoGenericMap>(biographyMap), m_replyMap[reply] );
m_replyMap.remove(reply);
@ -256,7 +254,7 @@ bool EchoNestPlugin::isValidTrackData(const QString &caller, const QVariant& dat
emit info(caller, Tomahawk::InfoSystem::InfoNoInfo, QVariant(), QVariant(), customData);
return false;
}
if (!customData.contains("artistName") ||
if (!customData.contains("artistName") ||
customData["artistName"].toString().isEmpty())
return false;
return true;

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -19,7 +19,7 @@
#ifndef ECHONESTPLUGIN_H
#define ECHONESTPLUGIN_H
#include "tomahawk/infosystem.h"
#include "infosystem/infosystem.h"
#include <QObject>
@ -37,13 +37,13 @@ namespace InfoSystem
class EchoNestPlugin : public InfoPlugin
{
Q_OBJECT
public:
EchoNestPlugin(QObject *parent);
virtual ~EchoNestPlugin();
void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData );
private:
void getSongProfile( const QString &caller, const QVariant &data, InfoCustomData &customData, const QString &item = QString() );
void getArtistBiography ( const QString &caller, const QVariant &data, InfoCustomData &customData );
@ -55,14 +55,14 @@ private:
bool isValidArtistData( const QString &caller, const QVariant& data, InfoCustomData& customData );
bool isValidTrackData( const QString &caller, const QVariant& data, InfoCustomData& customData );
Echonest::Artist artistFromReply( QNetworkReply* );
private slots:
void getArtistBiographySlot();
void getArtistFamiliaritySlot();
void getArtistHotttnesssSlot();
void getArtistTermsSlot();
void getMiscTopSlot();
private:
QHash< QNetworkReply*, InfoCustomData > m_replyMap;
QHash< QNetworkReply*, QString > m_callerMap;

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -26,7 +26,7 @@
#include "typedefs.h"
#include "audio/audioengine.h"
#include "tomahawksettings.h"
#include "tomahawk/tomahawkapp.h"
#include "utils/tomahawkutils.h"
#include <lastfm/ws.h>
#include <lastfm/XmlQuery>
@ -49,7 +49,7 @@ LastFmPlugin::LastFmPlugin( QObject* parent )
QSet< InfoType > supportedTypes;
supportedTypes << InfoMiscSubmitScrobble << InfoMiscSubmitNowPlaying << InfoAlbumCoverArt;
qobject_cast< InfoSystem* >(parent)->registerInfoTypes(this, supportedTypes);
/*
Your API Key is 7194b85b6d1f424fe1668173a78c0c4a
Your secret is ba80f1df6d27ae63e9cb1d33ccf2052f
@ -61,14 +61,14 @@ LastFmPlugin::LastFmPlugin( QObject* parent )
lastfm::ws::ApiKey = "7194b85b6d1f424fe1668173a78c0c4a";
lastfm::ws::SharedSecret = "ba80f1df6d27ae63e9cb1d33ccf2052f";
lastfm::ws::Username = TomahawkSettings::instance()->lastFmUsername();
m_pw = TomahawkSettings::instance()->lastFmPassword();
if( TomahawkSettings::instance()->scrobblingEnabled() && !lastfm::ws::Username.isEmpty() )
{
createScrobbler();
}
//HACK work around a bug in liblastfm---it doesn't create its config dir, so when it
// tries to write the track cache, it fails silently. until we have a fixed version, do this
// code taken from Amarok (src/services/lastfm/ScrobblerAdapter.cpp)
@ -126,7 +126,7 @@ LastFmPlugin::nowPlaying( const QString &caller, const InfoType type, const QVar
dataError( caller, type, data, customData );
return;
}
m_track = lastfm::MutableTrack();
m_track.stamp();
@ -154,7 +154,7 @@ LastFmPlugin::scrobble( const QString &caller, const InfoType type, const QVaria
qDebug() << Q_FUNC_INFO << m_track.toString();
m_scrobbler->cache( m_track );
m_scrobbler->submit();
emit info( caller, type, data, QVariant(), customData );
}
@ -173,11 +173,11 @@ LastFmPlugin::fetchCoverArt( const QString &caller, const InfoType type, const Q
dataError( caller, type, data, customData );
return;
}
Tomahawk::InfoSystem::InfoCacheCriteria criteria;
criteria["artist"] = hash["artist"].toString();
criteria["album"] = hash["album"].toString();
emit getCachedInfo( criteria, 2419200000, caller, type, data, customData );
}
@ -217,7 +217,7 @@ LastFmPlugin::coverArtReturned()
InfoCustomData returnedData;
returnedData["imgbytes"] = ba;
returnedData["url"] = reply->url().toString();
InfoCustomData customData = reply->property( "customData" ).value< Tomahawk::InfoSystem::InfoCustomData >();
InfoType type = (Tomahawk::InfoSystem::InfoType)(reply->property( "type" ).toUInt());
emit info(
@ -227,12 +227,12 @@ LastFmPlugin::coverArtReturned()
returnedData,
customData
);
InfoCustomData origData = reply->property( "origData" ).value< Tomahawk::InfoSystem::InfoCustomData >();
Tomahawk::InfoSystem::InfoCacheCriteria criteria;
criteria["artist"] = origData["artist"].toString();
criteria["album"] = origData["album"].toString();
emit updateCache( criteria, type, returnedData );
emit updateCache( criteria, 2419200000, type, returnedData );
}
else
{
@ -280,12 +280,12 @@ LastFmPlugin::settingsChanged()
void
LastFmPlugin::onAuthenticated()
{
if( !m_authJob )
if( !m_authJob )
{
qDebug() << Q_FUNC_INFO << "Help! No longer got a last.fm auth job!";
return;
}
if( m_authJob->error() == QNetworkReply::NoError )
{
lastfm::XmlQuery lfm = lastfm::XmlQuery( m_authJob->readAll() );
@ -294,7 +294,7 @@ LastFmPlugin::onAuthenticated()
{
qDebug() << "Error from authenticating with Last.fm service:" << lfm.text();
TomahawkSettings::instance()->setLastFmSessionKey( QByteArray() );
}
else
{
@ -310,7 +310,7 @@ LastFmPlugin::onAuthenticated()
{
qDebug() << "Got error in Last.fm authentication job:" << m_authJob->errorString();
}
m_authJob->deleteLater();
}
@ -321,19 +321,19 @@ LastFmPlugin::createScrobbler()
if( TomahawkSettings::instance()->lastFmSessionKey().isEmpty() ) // no session key, so get one
{
QString authToken = md5( ( lastfm::ws::Username.toLower() + md5( m_pw.toUtf8() ) ).toUtf8() );
QMap<QString, QString> query;
query[ "method" ] = "auth.getMobileSession";
query[ "username" ] = lastfm::ws::Username;
query[ "authToken" ] = authToken;
m_authJob = lastfm::ws::post( query );
connect( m_authJob, SIGNAL( finished() ), SLOT( onAuthenticated() ) );
}
else
{
lastfm::ws::SessionKey = TomahawkSettings::instance()->lastFmSessionKey();
m_scrobbler = new lastfm::Audioscrobbler( "thk" );
m_scrobbler->moveToThread( thread() );
}

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -18,7 +18,7 @@
#ifndef LASTFMPLUGIN_H
#define LASTFMPLUGIN_H
#include "tomahawk/infosystem.h"
#include "infosystem/infosystem.h"
#include "result.h"
#include <lastfm/Track>
@ -38,30 +38,30 @@ namespace InfoSystem
class LastFmPlugin : public InfoPlugin
{
Q_OBJECT
public:
LastFmPlugin( QObject *parent );
virtual ~LastFmPlugin();
void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData );
public slots:
void settingsChanged();
void onAuthenticated();
void coverArtReturned();
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData );
private:
void fetchCoverArt( const QString &caller, const InfoType type, const QVariant& data, Tomahawk::InfoSystem::InfoCustomData &customData );
void scrobble( const QString &caller, const InfoType type, const QVariant& data, InfoCustomData &customData );
void createScrobbler();
void nowPlaying( const QString &caller, const InfoType type, const QVariant& data, InfoCustomData &customData );
void dataError( const QString &caller, const InfoType type, const QVariant& data, InfoCustomData &customData );
lastfm::MutableTrack m_track;
lastfm::Audioscrobbler* m_scrobbler;
QString m_pw;
QNetworkReply* m_authJob;
};

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -16,10 +16,10 @@
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tomahawk/infosystem.h"
#include "tomahawk/tomahawkapp.h"
#include "musixmatchplugin.h"
#include "utils/tomahawkutils.h"
#include <QNetworkReply>
#include <QDomDocument>
@ -65,7 +65,7 @@ void MusixMatchPlugin::getInfo(const QString &caller, const InfoType type, const
reply->setProperty("customData", QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>(customData));
reply->setProperty("origData", data);
reply->setProperty("caller", caller);
connect(reply, SIGNAL(finished()), SLOT(trackSearchSlot()));
}

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -18,7 +18,8 @@
#ifndef MUSIXMATCHPLUGIN_H
#define MUSIXMATCHPLUGIN_H
#include "tomahawk/infosystem.h"
#include "infosystem/infosystem.h"
class QNetworkReply;
@ -31,16 +32,16 @@ namespace InfoSystem
class MusixMatchPlugin : public InfoPlugin
{
Q_OBJECT
public:
MusixMatchPlugin(QObject *parent);
virtual ~MusixMatchPlugin();
void getInfo(const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData);
private:
bool isValidTrackData( const QString &caller, const QVariant& data, InfoCustomData &customData );
public slots:
void trackSearchSlot();
void trackLyricsSlot();

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -18,8 +18,8 @@
#include <QCoreApplication>
#include "tomahawk/infosystem.h"
#include "tomahawkutils.h"
#include "infosystem.h"
#include "utils/tomahawkutils.h"
#include "infosystemcache.h"
#include "infoplugins/echonestplugin.h"
#include "infoplugins/musixmatchplugin.h"
@ -27,7 +27,7 @@
namespace Tomahawk
{
namespace InfoSystem
{
@ -40,9 +40,9 @@ InfoPlugin::InfoPlugin(QObject *parent)
{
QObject::connect(
this,
SIGNAL( getCachedInfo( Tomahawk::InfoSystem::InfoCacheCriteria, QString, Tomahawk::InfoSystem::InfoType, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
SIGNAL( getCachedInfo( Tomahawk::InfoSystem::InfoCacheCriteria, qint64, QString, Tomahawk::InfoSystem::InfoType, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
system->getCache(),
SLOT( getCachedInfoSlot( Tomahawk::InfoSystem::InfoCacheCriteria, QString, Tomahawk::InfoSystem::InfoType, QVariant, Tomahawk::InfoSystem::InfoCustomData ) )
SLOT( getCachedInfoSlot( Tomahawk::InfoSystem::InfoCacheCriteria, qint64, QString, Tomahawk::InfoSystem::InfoType, QVariant, Tomahawk::InfoSystem::InfoCustomData ) )
);
QObject::connect(
system->getCache(),
@ -52,35 +52,45 @@ InfoPlugin::InfoPlugin(QObject *parent)
);
QObject::connect(
this,
SIGNAL( updateCache( Tomahawk::InfoSystem::InfoCacheCriteria, Tomahawk::InfoSystem::InfoType, QVariant ) ),
SIGNAL( updateCache( Tomahawk::InfoSystem::InfoCacheCriteria, qint64, Tomahawk::InfoSystem::InfoType, QVariant ) ),
system->getCache(),
SLOT( updateCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria, Tomahawk::InfoSystem::InfoType, QVariant ) )
SLOT( updateCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria, qint64, Tomahawk::InfoSystem::InfoType, QVariant ) )
);
}
}
InfoSystem* InfoSystem::s_instance = 0;
InfoSystem*
InfoSystem::instance()
{
return s_instance;
}
InfoSystem::InfoSystem(QObject *parent)
: QObject(parent)
{
s_instance = this;
qDebug() << Q_FUNC_INFO;
qRegisterMetaType< QMap< QString, QMap< QString, QString > > >( "Tomahawk::InfoSystem::InfoGenericMap" );
qRegisterMetaType< QHash< QString, QVariant > >( "Tomahawk::InfoSystem::InfoCustomData" );
qRegisterMetaType< QHash< QString, QString > >( "Tomahawk::InfoSystem::InfoCacheCriteria" );
qRegisterMetaType< Tomahawk::InfoSystem::InfoType >( "Tomahawk::InfoSystem::InfoType" );
m_infoSystemCacheThreadController = new QThread( this );
m_cache = new InfoSystemCache();
m_cache->moveToThread( m_infoSystemCacheThreadController );
m_infoSystemCacheThreadController->start( QThread::IdlePriority );
InfoPluginPtr enptr( new EchoNestPlugin( this ) );
m_plugins.append( enptr );
InfoPluginPtr mmptr( new MusixMatchPlugin( this ) );
m_plugins.append( mmptr );
InfoPluginPtr lfmptr( new LastFmPlugin( this ) );
m_plugins.append( lfmptr );
Q_FOREACH( InfoPluginPtr plugin, m_plugins )
{
connect(
@ -107,19 +117,19 @@ InfoSystem::~InfoSystem()
if( m_infoSystemCacheThreadController )
{
m_infoSystemCacheThreadController->quit();
while( !m_infoSystemCacheThreadController->isFinished() )
{
QCoreApplication::processEvents( QEventLoop::AllEvents, 200 );
TomahawkUtils::Sleep::msleep( 100 );
}
if( m_cache )
{
delete m_cache;
m_cache = 0;
}
delete m_infoSystemCacheThreadController;
m_infoSystemCacheThreadController = 0;
}
@ -152,7 +162,7 @@ void InfoSystem::getInfo(const QString &caller, const InfoType type, const QVari
emit finished(caller);
return;
}
InfoPluginPtr ptr = providers.first();
if (!ptr)
{
@ -160,7 +170,7 @@ void InfoSystem::getInfo(const QString &caller, const InfoType type, const QVari
emit finished(caller);
return;
}
m_dataTracker[caller][type] = m_dataTracker[caller][type] + 1;
qDebug() << "current count in dataTracker for type" << type << "is" << m_dataTracker[caller][type];
ptr.data()->getInfo(caller, type, data, customData);
@ -182,7 +192,7 @@ void InfoSystem::infoSlot(QString target, InfoType type, QVariant input, QVarian
return;
}
emit info(target, type, input, output, customData);
m_dataTracker[target][type] = m_dataTracker[target][type] - 1;
qDebug() << "current count in dataTracker is " << m_dataTracker[target][type];
Q_FOREACH(InfoType testtype, m_dataTracker[target].keys())

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -34,7 +34,7 @@ namespace Tomahawk {
namespace InfoSystem {
class InfoSystemCache;
enum InfoType {
InfoTrackID = 0,
InfoTrackArtist,
@ -58,7 +58,7 @@ enum InfoType {
InfoTrackDanceability,
InfoTrackTempo,
InfoTrackLoudness,
InfoArtistID,
InfoArtistName,
InfoArtistBiography,
@ -74,7 +74,7 @@ enum InfoType {
InfoArtistTerms,
InfoArtistLinks,
InfoArtistVideos,
InfoAlbumID,
InfoAlbumName,
InfoAlbumArtist,
@ -85,10 +85,10 @@ enum InfoType {
InfoMiscTopHotttness,
InfoMiscTopTerms,
InfoMiscSubmitNowPlaying,
InfoMiscSubmitScrobble,
InfoNoInfo
};
@ -100,7 +100,7 @@ typedef QHash< QString, QString > InfoCacheCriteria;
class InfoPlugin : public QObject
{
Q_OBJECT
public:
InfoPlugin( QObject *parent );
@ -108,15 +108,15 @@ public:
{
qDebug() << Q_FUNC_INFO;
}
virtual void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData ) = 0;
signals:
void getCachedInfo( Tomahawk::InfoSystem::InfoCacheCriteria criteria, qint64 newMaxAge, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData );
void updateCache( Tomahawk::InfoSystem::InfoCacheCriteria criteria, Tomahawk::InfoSystem::InfoType type, QVariant output );
void updateCache( Tomahawk::InfoSystem::InfoCacheCriteria criteria, qint64, Tomahawk::InfoSystem::InfoType type, QVariant output );
void info( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
void finished( QString, Tomahawk::InfoSystem::InfoType );
public slots:
//FIXME: Make pure virtual when everything supports it
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData )
@ -127,7 +127,7 @@ public slots:
Q_UNUSED( input );
Q_UNUSED( customData );
}
protected:
InfoType m_type;
};
@ -137,38 +137,41 @@ typedef QWeakPointer< InfoPlugin > InfoPluginPtr;
class InfoSystem : public QObject
{
Q_OBJECT
public:
static InfoSystem* instance();
InfoSystem( QObject *parent );
~InfoSystem();
void registerInfoTypes( const InfoPluginPtr &plugin, const QSet< InfoType > &types );
void getInfo( const QString &caller, const InfoType type, const QVariant &data, InfoCustomData customData );
void getInfo( const QString &caller, const InfoMap &input, InfoCustomData customData );
InfoSystemCache* getCache() { return m_cache; }
signals:
void info( QString caller, Tomahawk::InfoSystem::InfoType, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
void finished( QString target );
public slots:
void infoSlot( QString target, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
private:
QLinkedList< InfoPluginPtr > determineOrderedMatches( const InfoType type ) const;
QMap< InfoType, QLinkedList< InfoPluginPtr > > m_infoMap;
// For now, statically instantiate plugins; this is just somewhere to keep them
QLinkedList< InfoPluginPtr > m_plugins;
QHash< QString, QHash< InfoType, int > > m_dataTracker;
InfoSystemCache* m_cache;
QThread* m_infoSystemCacheThreadController;
static InfoSystem* s_instance;
};
}
@ -182,14 +185,14 @@ inline uint qHash( Tomahawk::InfoSystem::InfoCacheCriteria hash )
md5.addData( key.toUtf8() );
foreach( QString value, hash.values() )
md5.addData( value.toUtf8() );
QString hexData = md5.result();
uint returnval = 0;
foreach( uint val, hexData.toUcs4() )
returnval += val;
return returnval;
}

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -23,11 +23,11 @@
#include <QObject>
#include <QtDebug>
#include "tomahawk/infosystem.h"
#include "infosystem.h"
namespace Tomahawk
{
namespace InfoSystem
{
@ -37,7 +37,7 @@ Q_OBJECT
public:
InfoSystemCache( QObject *parent = 0 );
virtual ~InfoSystemCache();
signals:
@ -47,11 +47,11 @@ signals:
public slots:
void getCachedInfoSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, qint64 newMaxAge, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData );
void updateCacheSlot( Tomahawk::InfoSystem::InfoCacheCriteria criteria, qint64 maxAge, Tomahawk::InfoSystem::InfoType type, QVariant output );
private:
void loadCache( InfoType type, const QString &cacheFile );
void saveCache( InfoType type, const QString &cacheDir );
QHash< InfoType, QHash< InfoCacheCriteria, QVariant > > m_dataCache;
QHash< InfoType, QHash< InfoCacheCriteria, QDateTime > > m_insertTimeCache;
QHash< InfoType, QHash< InfoCacheCriteria, QDateTime > > m_maxTimeCache;

View File

@ -26,6 +26,7 @@
#include <QNetworkProxy>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QPushButton>
#include <QMessageBox>
#include "result.h"
@ -41,7 +42,6 @@
#include "tomahawksettings.h"
#include "utils/tomahawkutils.h"
#include <aclsystem.h>
#include <tomahawk/tomahawkapp.h>
using namespace Tomahawk;

View File

@ -240,8 +240,8 @@ AlbumModel::addCollection( const collection_ptr& collection )
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( collection );
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, Tomahawk::collection_ptr ) ),
SLOT( onAlbumsAdded( QList<Tomahawk::album_ptr>, Tomahawk::collection_ptr ) ) );
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ),
SLOT( onAlbumsAdded( QList<Tomahawk::album_ptr> ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
@ -262,7 +262,7 @@ AlbumModel::addFilteredCollection( const collection_ptr& collection, unsigned in
cmd->setSortOrder( order );
cmd->setSortDescending( true );
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr> ) ),
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ),
SLOT( onAlbumsAdded( QList<Tomahawk::album_ptr> ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );

View File

@ -27,6 +27,7 @@
#include "audio/audioengine.h"
#include "tomahawksettings.h"
#include "treeheader.h"
#include "treeitemdelegate.h"
#include "playlistmanager.h"
@ -37,17 +38,35 @@ ArtistView::ArtistView( QWidget* parent )
: QTreeView( parent )
, m_model( 0 )
, m_proxyModel( 0 )
, m_header( new TreeHeader( this ) )
// , m_delegate( 0 )
{
setAlternatingRowColors( true );
setDragEnabled( true );
setDropIndicatorShown( false );
setDragDropOverwriteMode( false );
setUniformRowHeights( false );
setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
setRootIsDecorated( true );
setAnimated( false );
setAllColumnsShowFocus( true );
setSelectionMode( QAbstractItemView::ExtendedSelection );
setSelectionBehavior( QAbstractItemView::SelectRows );
setHeader( m_header );
setProxyModel( new TreeProxyModel( this ) );
#ifndef Q_WS_WIN
QFont f = font();
f.setPointSize( f.pointSize() - 1 );
setFont( f );
#endif
#ifdef Q_WS_MAC
f.setPointSize( f.pointSize() - 2 );
setFont( f );
#endif
connect( this, SIGNAL( doubleClicked( QModelIndex ) ), SLOT( onItemActivated( QModelIndex ) ) );
}

View File

@ -28,6 +28,8 @@
#include "dllmacro.h"
class TreeHeader;
class DLLEXPORT ArtistView : public QTreeView, public Tomahawk::ViewPage
{
Q_OBJECT
@ -71,6 +73,7 @@ private slots:
private:
QPixmap createDragPixmap( int itemCount ) const;
TreeHeader* m_header;
TreeModel* m_model;
TreeProxyModel* m_proxyModel;
// PlaylistItemDelegate* m_delegate;

View File

@ -102,8 +102,8 @@ CollectionFlatModel::addFilteredCollection( const collection_ptr& collection, un
cmd->setSortOrder( order );
cmd->setSortDescending( true );
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ),
SLOT( onTracksAdded( QList<Tomahawk::query_ptr>, Tomahawk::collection_ptr ) ), Qt::QueuedConnection );
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ),
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ), Qt::QueuedConnection );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}

View File

@ -390,6 +390,10 @@ PlaylistManager::showSuperCollection()
{
setPage( m_superCollectionView );
}
else if ( m_currentMode == 1 )
{
setPage( m_superCollectionView );
}
else if ( m_currentMode == 2 )
{
setPage( m_superAlbumView );

View File

@ -78,6 +78,9 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
opt.palette.setColor( QPalette::Text, opt.palette.color( QPalette::HighlightedText ) );
}
if ( index.column() > 0 )
return;
painter->save();
painter->setRenderHint( QPainter::Antialiasing );
painter->setPen( opt.palette.color( QPalette::Text ) );
@ -92,7 +95,8 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
QFont boldFont = opt.font;
boldFont.setBold( true );
r = option.rect.adjusted( option.rect.height(), 6, 0, -option.rect.height() + 22 );
r = option.rect.adjusted( option.rect.height(), 6, -4, -option.rect.height() + 22 );
text = painter->fontMetrics().elidedText( text, Qt::ElideRight, r.width() );
painter->drawText( r, text, to );
painter->setFont( boldFont );

View File

@ -30,7 +30,7 @@
#define LASTFM_DEFAULT_COVER "http://cdn.last.fm/flatness/catalogue/noimage"
static QString s_infoIdentifier = QString( "TREEMODEL" );
static QString s_tmInfoIdentifier = QString( "TREEMODEL" );
using namespace Tomahawk;
@ -44,11 +44,11 @@ TreeModel::TreeModel( QObject* parent )
m_defaultCover = QPixmap( RESPATH "images/no-album-art-placeholder.png" )
.scaled( QSize( 120, 120 ), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
/* connect( TomahawkApp::instance()->infoSystem(),
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
SLOT( infoSystemInfo( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ) );
connect( TomahawkApp::instance()->infoSystem(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );*/
connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );
}
@ -142,7 +142,7 @@ int
TreeModel::columnCount( const QModelIndex& parent ) const
{
Q_UNUSED( parent );
return 4;
return 7;
}
@ -190,22 +190,47 @@ TreeModel::data( const QModelIndex& index, int role ) const
if ( role != Qt::DisplayRole ) // && role != Qt::ToolTipRole )
return QVariant();
switch( index.column() )
if ( !entry->artist().isNull() && index.column() == Name )
{
case 0:
if ( !entry->artist().isNull() )
{
return entry->artist()->name();
}
else if ( !entry->artist().isNull() )
{
return entry->album()->name();
}
else if ( !entry->result().isNull() )
{
return entry->result()->track();
}
break;
return entry->artist()->name();
}
else if ( !entry->album().isNull() && index.column() == Name )
{
return entry->album()->name();
}
else
{
const result_ptr& result = entry->result();
switch( index.column() )
{
case Name:
return QString( "%1%2" ).arg( result->albumpos() > 0 ? QString( "%1. ").arg( result->albumpos() ) : QString() )
.arg( result->track() );
case Duration:
return TomahawkUtils::timeToString( result->duration() );
case Bitrate:
return result->bitrate();
case Age:
return TomahawkUtils::ageToString( QDateTime::fromTime_t( result->modificationTime() ) );
case Year:
return result->year();
case Filesize:
return TomahawkUtils::filesizeToString( result->size() );
case Origin:
return result->friendlySource();
case AlbumPosition:
return result->albumpos();
default:
return QVariant();
}
}
return QVariant();
@ -216,7 +241,7 @@ QVariant
TreeModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
QStringList headers;
headers << tr( "Artist" );
headers << tr( "Name" ) << tr( "Duration" ) << tr( "Bitrate" ) << tr( "Age" ) << tr( "Year" ) << tr( "Size" ) << tr( "Origin" );
if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 )
{
return headers.at( section );
@ -453,14 +478,14 @@ TreeModel::onAlbumsAdded( const QList<Tomahawk::album_ptr>& albums, const QVaria
albumitem->index = createIndex( parentItem->children.count() - 1, 0, albumitem );
connect( albumitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) );
/* Tomahawk::InfoSystem::InfoCustomData trackInfo;
Tomahawk::InfoSystem::InfoCustomData trackInfo;
trackInfo["artist"] = QVariant::fromValue< QString >( album->artist()->name() );
trackInfo["album"] = QVariant::fromValue< QString >( album->name() );
trackInfo["pptr"] = (qlonglong)albumitem;
trackInfo["pptr"] = QVariant::fromValue< qlonglong >( (qlonglong)albumitem );
TomahawkApp::instance()->infoSystem()->getInfo(
s_infoIdentifier, Tomahawk::InfoSystem::InfoAlbumCoverArt,
QVariant::fromValue< Tomahawk::InfoSystem::InfoCustomData >( trackInfo ), Tomahawk::InfoSystem::InfoCustomData() );*/
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo(
s_tmInfoIdentifier, Tomahawk::InfoSystem::InfoAlbumCoverArt,
QVariant::fromValue< Tomahawk::InfoSystem::InfoCustomData >( trackInfo ), Tomahawk::InfoSystem::InfoCustomData() );
}
if ( crows.second > 0 )
@ -517,7 +542,7 @@ void
TreeModel::infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData )
{
qDebug() << Q_FUNC_INFO;
if ( caller != s_infoIdentifier || type != Tomahawk::InfoSystem::InfoAlbumCoverArt )
if ( caller != s_tmInfoIdentifier || type != Tomahawk::InfoSystem::InfoAlbumCoverArt )
{
qDebug() << "Info of wrong type or not with our identifier";
return;
@ -529,6 +554,7 @@ TreeModel::infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type,
return;
}
Tomahawk::InfoSystem::InfoCustomData pptr = input.value< Tomahawk::InfoSystem::InfoCustomData >();
Tomahawk::InfoSystem::InfoCustomData returnedData = output.value< Tomahawk::InfoSystem::InfoCustomData >();
const QByteArray ba = returnedData["imgbytes"].toByteArray();
if ( ba.length() )
@ -536,13 +562,15 @@ TreeModel::infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type,
QPixmap pm;
pm.loadFromData( ba );
qlonglong pptr = input.toLongLong();
TreeModelItem* ai = reinterpret_cast<TreeModelItem*>(pptr);
qlonglong p = pptr["pptr"].toLongLong();
TreeModelItem* ai = reinterpret_cast<TreeModelItem*>(p);
if ( pm.isNull() || returnedData["url"].toString().startsWith( LASTFM_DEFAULT_COVER ) )
ai->cover = m_defaultCover;
else
ai->cover = pm;
emit dataChanged( ai->index, ai->index.sibling( ai->index.row(), columnCount( QModelIndex() ) - 1 ) );
}
}

View File

@ -28,7 +28,7 @@
#include "database/databasecommand_allartists.h"
#include "treemodelitem.h"
#include "tomahawk/infosystem.h"
#include "infosystem/infosystem.h"
#include "dllmacro.h"
@ -39,6 +39,17 @@ class DLLEXPORT TreeModel : public QAbstractItemModel
Q_OBJECT
public:
enum Columns {
Name = 0,
Duration,
Bitrate,
Age,
Year,
Filesize,
Origin,
AlbumPosition
};
explicit TreeModel( QObject* parent = 0 );
virtual ~TreeModel();

View File

@ -99,6 +99,12 @@ TreeProxyModel::lessThan( const QModelIndex& left, const QModelIndex& right ) co
if ( !p2 )
return false;
if ( !p1->result().isNull() )
{
if ( p1->result()->albumpos() != p2->result()->albumpos() )
return p1->result()->albumpos() < p2->result()->albumpos();
}
return QString::localeAwareCompare( textForItem( p1 ), textForItem( p2 ) ) < 0;
}

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -26,7 +26,7 @@
#include "musicscanner.h"
#include "tomahawksettings.h"
#include "tomahawkutils.h"
#include "utils/tomahawkutils.h"
#include "database/database.h"
#include "database/databasecommand_dirmtimes.h"
@ -60,15 +60,15 @@ ScanManager::ScanManager( QObject* parent )
m_deferredScanTimer->setSingleShot( false );
m_deferredScanTimer->setInterval( 1000 );
m_dirWatcher = new QFileSystemWatcher( this );
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( onSettingsChanged() ) );
connect( m_queuedScanTimer, SIGNAL( timeout() ), SLOT( queuedScanTimeout() ) );
connect( m_deferredScanTimer, SIGNAL( timeout() ), SLOT( deferredScanTimeout() ) );
connect( m_dirWatcher, SIGNAL( directoryChanged( const QString & ) ), SLOT( handleChangedDir( const QString & ) ) );
if ( TomahawkSettings::instance()->hasScannerPaths() )
m_currScannerPaths = TomahawkSettings::instance()->scannerPaths();
qDebug() << "loading initial directories to watch";
QTimer::singleShot( 1000, this, SLOT( startupWatchPaths() ) );
m_deferredScanTimer->start();
@ -78,11 +78,11 @@ ScanManager::ScanManager( QObject* parent )
ScanManager::~ScanManager()
{
qDebug() << Q_FUNC_INFO;
if( m_musicScannerThreadController )
{
m_musicScannerThreadController->quit();
while( !m_musicScannerThreadController->isFinished() )
{
QCoreApplication::processEvents( QEventLoop::AllEvents, 200 );
@ -94,7 +94,7 @@ ScanManager::~ScanManager()
delete m_scanner;
m_scanner = 0;
}
delete m_musicScannerThreadController;
m_musicScannerThreadController = 0;
}
@ -112,7 +112,7 @@ ScanManager::onSettingsChanged()
m_dirWatcher->addPaths( m_currScannerPaths );
runManualScan( m_currScannerPaths );
}
if( TomahawkSettings::instance()->watchForChanges() &&
!m_queuedChangedDirs.isEmpty() )
runManualScan( m_queuedChangedDirs, false );
@ -123,13 +123,13 @@ void
ScanManager::startupWatchPaths()
{
qDebug() << Q_FUNC_INFO;
if( !Database::instance() || ( Database::instance() && !Database::instance()->isReady() ) )
{
QTimer::singleShot( 1000, this, SLOT( startupWatchPaths() ) );
return;
}
DatabaseCommand_DirMtimes* cmd = new DatabaseCommand_DirMtimes( m_currScannerPaths );
connect( cmd, SIGNAL( done( QMap< QString, unsigned int > ) ),
SLOT( setInitialPaths( QMap< QString, unsigned int > ) ) );
@ -155,7 +155,7 @@ void
ScanManager::runManualScan( const QStringList& paths, bool recursive )
{
qDebug() << Q_FUNC_INFO;
if ( !m_musicScannerThreadController && !m_scanner ) //still running if these are not zero
{
m_musicScannerThreadController = new QThread( this );
@ -185,7 +185,7 @@ ScanManager::runManualScan( const QStringList& paths, bool recursive )
m_deferredDirs[recursive] << path;
}
}
}
}
}
@ -244,7 +244,7 @@ ScanManager::deferredScanTimeout()
runManualScan( m_deferredDirs[true], true );
}
else if( !m_deferredDirs[false].isEmpty() )
{
{
qDebug() << "Running scan for deferred non-recursive paths";
runManualScan( m_deferredDirs[false], false );
}

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -26,10 +26,9 @@
#include "typedefs.h"
#include "audio/audioengine.h"
#include "tomahawksettings.h"
#include "tomahawk/tomahawkapp.h"
#include "tomahawk/infosystem.h"
#include "infosystem/infosystem.h"
static QString s_infoIdentifier = QString("SCROBBLER");
static QString s_scInfoIdentifier = QString( "SCROBBLER" );
Scrobbler::Scrobbler( QObject* parent )
: QObject( parent )
@ -37,13 +36,11 @@ Scrobbler::Scrobbler( QObject* parent )
{
connect( AudioEngine::instance(), SIGNAL( timerSeconds( unsigned int ) ),
SLOT( engineTick( unsigned int ) ), Qt::QueuedConnection );
connect( TomahawkApp::instance()->infoSystem(),
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
SIGNAL( info( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ),
SLOT( infoSystemInfo( QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData ) ) );
connect( TomahawkApp::instance()->infoSystem(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );
connect( AudioEngine::instance(), SIGNAL( started( const Tomahawk::result_ptr& ) ),
SLOT( trackStarted( const Tomahawk::result_ptr& ) ), Qt::QueuedConnection );
@ -55,6 +52,8 @@ Scrobbler::Scrobbler( QObject* parent )
connect( AudioEngine::instance(), SIGNAL( stopped() ),
SLOT( trackStopped() ), Qt::QueuedConnection );
connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );
}
@ -63,7 +62,7 @@ Scrobbler::~Scrobbler()
}
void
void
Scrobbler::trackStarted( const Tomahawk::result_ptr& track )
{
Q_ASSERT( QThread::currentThread() == thread() );
@ -76,34 +75,34 @@ Scrobbler::trackStarted( const Tomahawk::result_ptr& track )
}
Tomahawk::InfoSystem::InfoCustomData trackInfo;
trackInfo["title"] = QVariant::fromValue< QString >( track->track() );
trackInfo["artist"] = QVariant::fromValue< QString >( track->artist()->name() );
trackInfo["album"] = QVariant::fromValue< QString >( track->album()->name() );
trackInfo["duration"] = QVariant::fromValue< uint >( track->duration() );
TomahawkApp::instance()->infoSystem()->getInfo(
s_infoIdentifier, Tomahawk::InfoSystem::InfoMiscSubmitNowPlaying,
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo(
s_scInfoIdentifier, Tomahawk::InfoSystem::InfoMiscSubmitNowPlaying,
QVariant::fromValue< Tomahawk::InfoSystem::InfoCustomData >( trackInfo ), Tomahawk::InfoSystem::InfoCustomData() );
m_scrobblePoint = ScrobblePoint( track->duration() / 2 );
}
void
void
Scrobbler::trackPaused()
{
Q_ASSERT( QThread::currentThread() == thread() );
}
void
void
Scrobbler::trackResumed()
{
Q_ASSERT( QThread::currentThread() == thread() );
}
void
void
Scrobbler::trackStopped()
{
Q_ASSERT( QThread::currentThread() == thread() );
@ -128,19 +127,20 @@ void
Scrobbler::scrobble()
{
Q_ASSERT( QThread::currentThread() == thread() );
TomahawkApp::instance()->infoSystem()->getInfo(
s_infoIdentifier, Tomahawk::InfoSystem::InfoMiscSubmitScrobble,
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo(
s_scInfoIdentifier, Tomahawk::InfoSystem::InfoMiscSubmitScrobble,
QVariant(), Tomahawk::InfoSystem::InfoCustomData() );
}
void
Scrobbler::infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData )
{
Q_UNUSED( input );
Q_UNUSED( output );
Q_UNUSED( customData );
if ( caller == s_infoIdentifier )
if ( caller == s_scInfoIdentifier )
{
qDebug() << Q_FUNC_INFO;
if ( type == Tomahawk::InfoSystem::InfoMiscSubmitNowPlaying )
@ -150,10 +150,11 @@ Scrobbler::infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type,
}
}
void
void
Scrobbler::infoSystemFinished( QString target )
{
if ( target == s_infoIdentifier )
if ( target == s_scInfoIdentifier )
{
qDebug() << Q_FUNC_INFO;
qDebug() << "Scrobbler received done signal from InfoSystem";

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -23,7 +23,7 @@
#include "lastfm/ScrobblePoint"
#include "tomahawk/infosystem.h"
#include "infosystem/infosystem.h"
#include <QObject>
@ -37,20 +37,20 @@ class Scrobbler : public QObject
public:
Scrobbler( QObject* parent = 0 );
virtual ~Scrobbler();
public slots:
void trackStarted( const Tomahawk::result_ptr& );
void trackPaused();
void trackResumed();
void trackStopped();
void engineTick( unsigned int secondsElapsed );
void infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
void infoSystemFinished( QString target );
private:
void scrobble();
bool m_reachedScrobblePoint;
ScrobblePoint m_scrobblePoint;
};

View File

@ -32,7 +32,7 @@
#include "artist.h"
#include "album.h"
#include "collection.h"
#include "tomahawk/infosystem.h"
#include "infosystem/infosystem.h"
#include "database/database.h"
#include "database/databasecollection.h"
#include "database/databasecommand_collectionstats.h"
@ -152,7 +152,6 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] )
, m_shortcutHandler( 0 )
, m_scrubFriendlyName( false )
, m_mainwindow( 0 )
, m_infoSystem( 0 )
{
qDebug() << "TomahawkApp thread:" << this->thread();
setOrganizationName( QLatin1String( ORGANIZATION_NAME ) );
@ -176,7 +175,6 @@ TomahawkApp::init()
#endif
registerMetaTypes();
setupLogfile();
Echonest::Config::instance()->setAPIKey( "JRIHWEP6GPOER2QQ6" );
@ -217,7 +215,7 @@ TomahawkApp::init()
}
qDebug() << "Init InfoSystem.";
m_infoSystem = new Tomahawk::InfoSystem::InfoSystem( this );
new Tomahawk::InfoSystem::InfoSystem( this );
#ifdef LIBLASTFM_FOUND
qDebug() << "Init Scrobbler.";
@ -304,7 +302,7 @@ TomahawkApp::~TomahawkApp()
delete m_mainwindow;
delete m_audioEngine;
#endif
delete m_infoSystem;
// delete m_infoSystem;
delete m_database;
}

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -38,8 +38,7 @@
#include <QStringList>
#include "network/servent.h"
#include "tomahawkutils.h"
#include "tomahawk/tomahawkapp.h"
#include "utils/tomahawkutils.h"
#include <database/databasecommand_addclientauth.h>
#include <qxtwebcontent.h>
#include <database/database.h>

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -18,8 +18,7 @@
#include "xmppbot.h"
#include "tomahawk/tomahawkapp.h"
#include "tomahawk/infosystem.h"
#include "infosystem/infosystem.h"
#include "album.h"
#include "typedefs.h"
#include "tomahawksettings.h"
@ -36,7 +35,7 @@
using namespace gloox;
using namespace Tomahawk::InfoSystem;
static QString s_infoIdentifier = QString("XMPPBot");
static QString s_botInfoIdentifier = QString( "XMPPBot" );
XMPPBot::XMPPBot(QObject *parent)
: QObject(parent)
@ -50,7 +49,7 @@ XMPPBot::XMPPBot(QObject *parent)
int port = settings->xmppBotPort();
if (jidstring.isEmpty() || password.isEmpty())
return;
JID jid(jidstring.toStdString());
jid.setResource( QString( "tomahawkbot%1" ).arg( qrand() ).toStdString() );
@ -66,11 +65,11 @@ XMPPBot::XMPPBot(QObject *parent)
connect(AudioEngine::instance(), SIGNAL(started(const Tomahawk::result_ptr &)),
SLOT(newTrackSlot(const Tomahawk::result_ptr &)));
connect(TomahawkApp::instance()->infoSystem(),
connect(InfoSystem::instance(),
SIGNAL(info(QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData)),
SLOT(infoReturnedSlot(QString, Tomahawk::InfoSystem::InfoType, QVariant, QVariant, Tomahawk::InfoSystem::InfoCustomData)));
connect(TomahawkApp::instance()->infoSystem(), SIGNAL(finished(QString)), SLOT(infoFinishedSlot(QString)));
connect(InfoSystem::instance(), SIGNAL(finished(QString)), SLOT(infoFinishedSlot(QString)));
bool success = m_client.data()->gloox::Client::connect(false);
if (success)
@ -149,7 +148,7 @@ void XMPPBot::handleMessage(const Message& msg, MessageSession* session)
//TODO: implement "properly" with MessageSessions, if the bot is to be multi-user
if (msg.subtype() != Message::Chat || msg.from().full().empty() || msg.to().full().empty())
return;
QString body = QString::fromStdString( msg.body() ).toLower().trimmed();
QString originatingJid = QString::fromStdString( msg.from().full() );
@ -192,7 +191,7 @@ void XMPPBot::handleMessage(const Message& msg, MessageSession* session)
qDebug() << "jid from:" << QString::fromStdString(msg.from().full()) << ", jid to:" << QString::fromStdString(msg.to().full());
qDebug() << "Operating on tokens:" << tokens;
if (m_currTrack.isNull() || m_currTrack->artist()->name().isEmpty() || m_currTrack->track().isEmpty())
{
qDebug() << "XMPPBot can't figure out track";
@ -201,8 +200,8 @@ void XMPPBot::handleMessage(const Message& msg, MessageSession* session)
m_client.data()->send(retMsg);
return;
}
InfoMap infoMap;
InfoMap infoMap;
Q_FOREACH(QString token, tokens)
{
if (token == "biography")
@ -221,7 +220,7 @@ void XMPPBot::handleMessage(const Message& msg, MessageSession* session)
infoMap[InfoTrackLyrics] = QVariant::fromValue<Tomahawk::InfoSystem::InfoCustomData>(myhash);
}
}
if (infoMap.isEmpty())
{
qDebug() << "XMPPBot can't figure out track";
@ -229,38 +228,38 @@ void XMPPBot::handleMessage(const Message& msg, MessageSession* session)
Message retMsg(Message::Chat, JID(originatingJid.toStdString()), m_currReturnMessage.toStdString());
m_client.data()->send(retMsg);
return;
}
}
m_currInfoMap.unite(infoMap);
QString waitMsg("Please wait...");
Message retMsg(Message::Chat, JID(originatingJid.toStdString()), waitMsg.toStdString());
m_client.data()->send(retMsg);
Tomahawk::InfoSystem::InfoCustomData hash;
hash["XMPPBotSendToJID"] = originatingJid;
TomahawkApp::instance()->infoSystem()->getInfo(s_infoIdentifier, infoMap, hash);
InfoSystem::instance()->getInfo(s_botInfoIdentifier, infoMap, hash);
}
void XMPPBot::infoReturnedSlot(QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData)
{
qDebug() << Q_FUNC_INFO;
if (caller != s_infoIdentifier ||
if (caller != s_botInfoIdentifier ||
input.isNull() || !input.isValid() ||
!customData.contains("XMPPBotSendToJID")
)
{
qDebug() << "Not the right object, custom data is null, or don't have a set JID";
return;
}
}
if (!m_currInfoMap.contains(type))
{
qDebug() << "not in currInfoMap";
return;
}
else
else
m_currInfoMap.remove(type);
QString jid = customData["XMPPBotSendToJID"].toString();
if (!m_currReturnJid.isEmpty() && m_currReturnJid != jid && !m_currReturnMessage.isEmpty())
{
@ -269,7 +268,7 @@ void XMPPBot::infoReturnedSlot(QString caller, Tomahawk::InfoSystem::InfoType ty
m_currReturnMessage = QString("\n");
}
m_currReturnJid = jid;
switch(type)
{
case InfoArtistBiography:
@ -287,7 +286,7 @@ void XMPPBot::infoReturnedSlot(QString caller, Tomahawk::InfoSystem::InfoType ty
m_currReturnMessage += QString("\nBiographies for %1\n").arg(artist);
Q_FOREACH(QString source, bmap.keys())
{
m_currReturnMessage += (bmap[source]["attribution"].isEmpty() ?
m_currReturnMessage += (bmap[source]["attribution"].isEmpty() ?
QString("From %1:\n").arg(bmap[source]["site"]) :
QString("From %1 at %2:\n").arg(bmap[source]["attribution"]).arg(bmap[source]["site"]));
m_currReturnMessage += bmap[source]["text"] + QString("\n");
@ -381,15 +380,15 @@ void XMPPBot::infoReturnedSlot(QString caller, Tomahawk::InfoSystem::InfoType ty
default:
break;
}
if (m_currReturnMessage.isEmpty())
{
qDebug() << "Empty message, not sending anything back";
return;
}
qDebug() << "Going to send message: " << m_currReturnMessage << " to " << jid;
//gloox::Message msg(Message::Chat, JID(jid.toStdString()), m_currReturnMessage.toStdString());
//m_client.data()->send(msg);
}
@ -398,10 +397,10 @@ void XMPPBot::infoFinishedSlot(QString caller)
{
qDebug() << Q_FUNC_INFO;
qDebug() << "current return message is" << m_currReturnMessage;
qDebug() << "id is" << caller << "and our id is" << s_infoIdentifier;
if (m_currReturnMessage.isEmpty() || caller != s_infoIdentifier)
qDebug() << "id is" << caller << "and our id is" << s_botInfoIdentifier;
if (m_currReturnMessage.isEmpty() || caller != s_botInfoIdentifier)
return;
qDebug() << "Sending message to JID" << m_currReturnJid;
gloox::Message msg(Message::Chat, JID(m_currReturnJid.toStdString()), m_currReturnMessage.toStdString());
m_client.data()->send(msg);

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -20,7 +20,7 @@
#define XMPPBOT_H
#include <result.h>
#include <tomahawk/infosystem.h>
#include <infosystem/infosystem.h>
#include <QtCore/QObject>
#include <QtCore/qsharedpointer.h>
@ -42,12 +42,12 @@ class XMPPBotClient
public:
XMPPBotClient(QObject* parent, gloox::JID &jid, std::string password, int port);
virtual ~XMPPBotClient();
void run();
private slots:
void recvSlot();
private:
QTimer m_timer;
};
@ -59,7 +59,7 @@ class XMPPBot
, public gloox::MessageHandler
{
Q_OBJECT
public:
XMPPBot(QObject *parent);
virtual ~XMPPBot();
@ -68,16 +68,16 @@ public slots:
virtual void newTrackSlot(const Tomahawk::result_ptr &track);
virtual void infoReturnedSlot(QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData);
virtual void infoFinishedSlot(QString caller);
protected:
// ConnectionListener
virtual void onConnect();
virtual void onDisconnect(gloox::ConnectionError e);
virtual bool onTLSConnect(const gloox::CertInfo &info);
// SubscriptionHandler
virtual void handleSubscription(const gloox::Subscription &subscription);
// MessageHandler
virtual void handleMessage(const gloox::Message &msg, gloox::MessageSession *session = 0);