1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-07 14:46:33 +02:00

* Get rid of query_ptrs in Collection.

This commit is contained in:
Christian Muehlhaeuser
2011-11-06 06:49:26 +01:00
parent d85291ae3e
commit d88eaacf8d
8 changed files with 48 additions and 102 deletions

View File

@@ -68,7 +68,6 @@ Collection::addPlaylist( const Tomahawk::playlist_ptr& p )
QList<playlist_ptr> toadd; QList<playlist_ptr> toadd;
toadd << p; toadd << p;
// qDebug() << "Inserted playlist with guid:" << p->guid();
m_playlists.insert( p->guid(), p ); m_playlists.insert( p->guid(), p );
/* qDebug() << Q_FUNC_INFO << "Collection name" << name() /* qDebug() << Q_FUNC_INFO << "Collection name" << name()
@@ -83,7 +82,6 @@ Collection::addAutoPlaylist( const Tomahawk::dynplaylist_ptr& p )
{ {
QList<dynplaylist_ptr> toadd; QList<dynplaylist_ptr> toadd;
toadd << p; toadd << p;
// qDebug() << "Inserted dynamic playlist with guid:" << p->guid();
m_autoplaylists.insert( p->guid(), p ); m_autoplaylists.insert( p->guid(), p );
/* qDebug() << Q_FUNC_INFO << "Collection name" << name() /* qDebug() << Q_FUNC_INFO << "Collection name" << name()
@@ -98,7 +96,6 @@ Collection::addStation( const dynplaylist_ptr& s )
{ {
QList<dynplaylist_ptr> toadd; QList<dynplaylist_ptr> toadd;
toadd << s; toadd << s;
// qDebug() << "Inserted station with guid:" << s->guid();
m_stations.insert( s->guid(), s ); m_stations.insert( s->guid(), s );
/* qDebug() << Q_FUNC_INFO << "Collection name" << name() /* qDebug() << Q_FUNC_INFO << "Collection name" << name()
@@ -167,7 +164,6 @@ Collection::autoPlaylist( const QString& guid )
dynplaylist_ptr dynplaylist_ptr
Collection::station( const QString& guid ) Collection::station( const QString& guid )
{ {
return m_stations.value( guid, dynplaylist_ptr() ); return m_stations.value( guid, dynplaylist_ptr() );
} }
@@ -175,7 +171,6 @@ Collection::station( const QString& guid )
void void
Collection::setPlaylists( const QList<Tomahawk::playlist_ptr>& plists ) Collection::setPlaylists( const QList<Tomahawk::playlist_ptr>& plists )
{ {
// qDebug() << Q_FUNC_INFO << plists.count();
foreach ( const playlist_ptr& p, plists ) foreach ( const playlist_ptr& p, plists )
{ {
// qDebug() << "Batch inserting playlist:" << p->guid(); // qDebug() << "Batch inserting playlist:" << p->guid();
@@ -190,8 +185,6 @@ Collection::setPlaylists( const QList<Tomahawk::playlist_ptr>& plists )
void void
Collection::setAutoPlaylists( const QList< Tomahawk::dynplaylist_ptr >& plists ) Collection::setAutoPlaylists( const QList< Tomahawk::dynplaylist_ptr >& plists )
{ {
// qDebug() << Q_FUNC_INFO << plists.count();
foreach ( const dynplaylist_ptr& p, plists ) foreach ( const dynplaylist_ptr& p, plists )
{ {
// qDebug() << "Batch inserting dynamic playlist:" << p->guid(); // qDebug() << "Batch inserting dynamic playlist:" << p->guid();
@@ -204,8 +197,6 @@ Collection::setAutoPlaylists( const QList< Tomahawk::dynplaylist_ptr >& plists )
void void
Collection::setStations( const QList< dynplaylist_ptr >& stations ) Collection::setStations( const QList< dynplaylist_ptr >& stations )
{ {
// qDebug() << Q_FUNC_INFO << stations.count();
foreach ( const dynplaylist_ptr& s, stations ) foreach ( const dynplaylist_ptr& s, stations )
{ {
// qDebug() << "Batch inserting station:" << s->guid(); // qDebug() << "Batch inserting station:" << s->guid();
@@ -216,49 +207,22 @@ Collection::setStations( const QList< dynplaylist_ptr >& stations )
void void
Collection::setTracks( const QList<Tomahawk::query_ptr>& tracks ) Collection::setTracks( const QList<unsigned int>& ids )
{ {
// qDebug() << Q_FUNC_INFO << tracks.count() << name(); qDebug() << Q_FUNC_INFO << ids.count() << name();
emit tracksAdded( tracks ); emit tracksAdded( ids );
emit changed(); emit changed();
} }
void void
Collection::delTracks( const QStringList& files ) Collection::delTracks( const QList<unsigned int>& ids )
{ {
qDebug() << Q_FUNC_INFO << files.count() << name(); qDebug() << Q_FUNC_INFO << ids.count() << name();
emit tracksRemoved( ids );
emit changed(); emit changed();
/* QList<Tomahawk::query_ptr> tracks;
int i = 0;
foreach ( const query_ptr& query, m_tracks )
{
foreach ( const QString& file, files )
{
bool found = false;
foreach ( const result_ptr& result, query->results() )
{
if ( file == result->url() )
{
// qDebug() << Q_FUNC_INFO << "Found deleted result:" << file;
tracks << query;
m_tracks.removeAt( i );
i--;
found = true;
break;
}
}
if ( found )
break;
}
i++;
}
tDebug() << "Emitting tracks removed:" << tracks.size();
emit tracksRemoved( tracks );*/
} }

View File

@@ -35,7 +35,6 @@
#include "functimeout.h" #include "functimeout.h"
#include "playlist.h" #include "playlist.h"
#include "playlist/dynamic/DynamicPlaylist.h" #include "playlist/dynamic/DynamicPlaylist.h"
#include "query.h"
#include "dllmacro.h" #include "dllmacro.h"
@@ -79,8 +78,8 @@ public:
unsigned int lastmodified() const { return m_lastmodified; } unsigned int lastmodified() const { return m_lastmodified; }
signals: signals:
void tracksAdded( const QList<Tomahawk::query_ptr>& tracks ); void tracksAdded( const QList<unsigned int>& ids );
void tracksRemoved( const QList<Tomahawk::query_ptr>& tracks ); void tracksRemoved( const QList<unsigned int>& ids );
void playlistsAdded( const QList<Tomahawk::playlist_ptr>& ); void playlistsAdded( const QList<Tomahawk::playlist_ptr>& );
void playlistsDeleted( const QList<Tomahawk::playlist_ptr>& ); void playlistsDeleted( const QList<Tomahawk::playlist_ptr>& );
@@ -101,8 +100,8 @@ public slots:
void setAutoPlaylists( const QList< Tomahawk::dynplaylist_ptr >& autoplists ); void setAutoPlaylists( const QList< Tomahawk::dynplaylist_ptr >& autoplists );
void setStations( const QList< Tomahawk::dynplaylist_ptr >& stations ); void setStations( const QList< Tomahawk::dynplaylist_ptr >& stations );
void setTracks( const QList<Tomahawk::query_ptr>& tracks ); void setTracks( const QList<unsigned int>& ids );
void delTracks( const QStringList& files ); void delTracks( const QList<unsigned int>& ids );
protected: protected:
QString m_name; QString m_name;

View File

@@ -56,7 +56,6 @@ DatabaseCommand_AddFiles::files() const
void void
DatabaseCommand_AddFiles::postCommitHook() DatabaseCommand_AddFiles::postCommitHook()
{ {
qDebug() << Q_FUNC_INFO;
if ( source().isNull() || source()->collection().isNull() ) if ( source().isNull() || source()->collection().isNull() )
{ {
qDebug() << "Source has gone offline, not emitting to GUI."; qDebug() << "Source has gone offline, not emitting to GUI.";
@@ -67,11 +66,11 @@ DatabaseCommand_AddFiles::postCommitHook()
// collection browser will update/fade in etc. // collection browser will update/fade in etc.
Collection* coll = source()->collection().data(); Collection* coll = source()->collection().data();
connect( this, SIGNAL( notify( QList<Tomahawk::query_ptr> ) ), connect( this, SIGNAL( notify( QList<unsigned int> ) ),
coll, SLOT( setTracks( QList<Tomahawk::query_ptr> ) ), coll, SLOT( setTracks( QList<unsigned int> ) ),
Qt::QueuedConnection ); Qt::QueuedConnection );
emit notify( m_queries ); emit notify( m_ids );
if ( source()->isLocal() ) if ( source()->isLocal() )
{ {
@@ -185,7 +184,7 @@ DatabaseCommand_AddFiles::exec( DatabaseImpl* dbi )
query_trackattr.bindValue( 2, year ); query_trackattr.bindValue( 2, year );
query_trackattr.exec(); query_trackattr.exec();
QVariantMap attr; /* QVariantMap attr;
Tomahawk::query_ptr query = Tomahawk::Query::get( artist, track, album ); Tomahawk::query_ptr query = Tomahawk::Query::get( artist, track, album );
attr["releaseyear"] = m.value( "year" ); attr["releaseyear"] = m.value( "year" );
@@ -210,12 +209,13 @@ DatabaseCommand_AddFiles::exec( DatabaseImpl* dbi )
results << result; results << result;
query->addResults( results ); query->addResults( results );
m_queries << query; m_queries << query;*/
m_ids << trackid;
added++; added++;
} }
qDebug() << "Inserted" << added << "tracks to database"; qDebug() << "Inserted" << added << "tracks to database";
// TODO building the index could be a separate job, outside this transaction
if ( added ) if ( added )
source()->updateIndexWhenSynced(); source()->updateIndexWhenSynced();

View File

@@ -55,11 +55,11 @@ public:
signals: signals:
void done( const QList<QVariant>&, const Tomahawk::collection_ptr& ); void done( const QList<QVariant>&, const Tomahawk::collection_ptr& );
void notify( const QList<Tomahawk::query_ptr>& ); void notify( const QList<unsigned int>& ids );
private: private:
QVariantList m_files; QVariantList m_files;
QList<Tomahawk::query_ptr> m_queries; QList<unsigned int> m_ids;
}; };
#endif // DATABASECOMMAND_ADDFILES_H #endif // DATABASECOMMAND_ADDFILES_H

View File

@@ -45,11 +45,14 @@ DatabaseCommand_DeleteFiles::postCommitHook()
// collection browser will update/fade in etc. // collection browser will update/fade in etc.
Collection* coll = source()->collection().data(); Collection* coll = source()->collection().data();
connect( this, SIGNAL( notify( QStringList ) ), connect( this, SIGNAL( notify( QList<unsigned int> ) ),
coll, SLOT( delTracks( QStringList ) ), Qt::QueuedConnection ); coll, SLOT( delTracks( QList<unsigned int> ) ), Qt::QueuedConnection );
tDebug() << "Notifying of deleted tracks: " << m_files.size() << " from source " << source()->id(); tDebug() << "Notifying of deleted tracks:" << m_ids.size() << "from source" << source()->id();
emit notify( m_files ); QList<unsigned int> ids;
foreach ( QVariant id, m_ids )
ids << id.toUInt();
emit notify( ids );
if( source()->isLocal() ) if( source()->isLocal() )
Servent::instance()->triggerDBSync(); Servent::instance()->triggerDBSync();
@@ -59,7 +62,6 @@ DatabaseCommand_DeleteFiles::postCommitHook()
void void
DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi ) DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi )
{ {
// qDebug() << Q_FUNC_INFO;
Q_ASSERT( !source().isNull() ); Q_ASSERT( !source().isNull() );
QVariant srcid = source()->isLocal() ? QVariant( QVariant::Int ) : source()->id(); QVariant srcid = source()->isLocal() ? QVariant( QVariant::Int ) : source()->id();
@@ -68,7 +70,6 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi )
if ( source()->isLocal() ) if ( source()->isLocal() )
{ {
tDebug() << Q_FUNC_INFO << " source is local";
if ( m_dir.path() != QString( "." ) ) if ( m_dir.path() != QString( "." ) )
{ {
tDebug() << "Deleting" << m_dir.path() << "from db for localsource" << srcid; tDebug() << "Deleting" << m_dir.path() << "from db for localsource" << srcid;
@@ -108,12 +109,8 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi )
dirquery.exec(); dirquery.exec();
while ( dirquery.next() ) while ( dirquery.next() )
{ {
//tDebug() << Q_FUNC_INFO << " found dirquery value 0: " << dirquery.value( 0 ).toString() << " and value 1: " << dirquery.value( 1 ).toString();
m_files << dirquery.value( 1 ).toString(); m_files << dirquery.value( 1 ).toString();
} }
//tDebug() << Q_FUNC_INFO << " executed query was: " << dirquery.executedQuery();
//tDebug() << Q_FUNC_INFO << " files selected for delete: " << m_files;
} }
else if ( m_deleteAll ) else if ( m_deleteAll )
{ {
@@ -136,8 +133,8 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi )
TomahawkSqlQuery dirquery = dbi->newquery(); TomahawkSqlQuery dirquery = dbi->newquery();
dirquery.prepare( QString( "SELECT url FROM file WHERE source = %1" ).arg( source()->id() ) ); dirquery.prepare( QString( "SELECT url FROM file WHERE source = %1" ).arg( source()->id() ) );
dirquery.exec(); dirquery.exec();
while ( dirquery.next() ) while ( dirquery.next() )
m_ids << dirquery.value( 0 ).toString(); m_ids << dirquery.value( 0 ).toString();
} }
@@ -153,18 +150,11 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi )
delquery.prepare( QString( "DELETE FROM file WHERE source %1" ) delquery.prepare( QString( "DELETE FROM file WHERE source %1" )
.arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) ); .arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) );
if( !delquery.exec() ) delquery.exec();
{
qDebug() << "Failed to delete file:"
<< delquery.lastError().databaseText()
<< delquery.lastError().driverText()
<< delquery.boundValues();
}
} }
} }
else if ( !m_ids.isEmpty() ) else if ( !m_ids.isEmpty() )
{ {
tDebug() << Q_FUNC_INFO << " executing delete";
delquery.prepare( QString( "DELETE FROM file WHERE source %1 AND %2 IN ( ? )" ) delquery.prepare( QString( "DELETE FROM file WHERE source %1 AND %2 IN ( ? )" )
.arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) ) .arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) )
.arg( source()->isLocal() ? "id" : "url" ) ); .arg( source()->isLocal() ? "id" : "url" ) );
@@ -179,15 +169,7 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi )
.arg( source()->isLocal() ? "id" : "url" ) .arg( source()->isLocal() ? "id" : "url" )
.arg( idstring ) ); .arg( idstring ) );
if( !delquery.exec() ) delquery.exec();
{
qDebug() << "Failed to delete file:"
<< delquery.lastError().databaseText()
<< delquery.lastError().driverText()
<< delquery.boundValues();
}
//tDebug() << Q_FUNC_INFO << " executed query was: " << delquery.executedQuery();
} }
emit done( m_files, source()->collection() ); emit done( m_files, source()->collection() );

View File

@@ -74,7 +74,7 @@ public:
signals: signals:
void done( const QStringList&, const Tomahawk::collection_ptr& ); void done( const QStringList&, const Tomahawk::collection_ptr& );
void notify( const QStringList& ); void notify( const QList<unsigned int>& ids );
private: private:
QStringList m_files; QStringList m_files;

View File

@@ -502,6 +502,7 @@ TomahawkApp::initServent()
} }
} }
void void
TomahawkApp::initSIP() TomahawkApp::initSIP()
{ {
@@ -518,6 +519,7 @@ TomahawkApp::initSIP()
} }
} }
void void
TomahawkApp::spotifyApiCheckFinished() TomahawkApp::spotifyApiCheckFinished()
{ {
@@ -543,7 +545,6 @@ TomahawkApp::activate()
bool bool
TomahawkApp::loadUrl( const QString& url ) TomahawkApp::loadUrl( const QString& url )
{ {
activate();
if ( url.startsWith( "tomahawk://" ) ) if ( url.startsWith( "tomahawk://" ) )
return GlobalActionManager::instance()->parseTomahawkLink( url ); return GlobalActionManager::instance()->parseTomahawkLink( url );
else if ( url.contains( "open.spotify.com" ) || url.contains( "spotify:track" ) ) else if ( url.contains( "open.spotify.com" ) || url.contains( "spotify:track" ) )
@@ -561,7 +562,8 @@ TomahawkApp::loadUrl( const QString& url )
l->load( QUrl::fromUserInput( url ) ); l->load( QUrl::fromUserInput( url ) );
return true; return true;
} else if ( info.suffix() == "jspf" ) }
else if ( info.suffix() == "jspf" )
{ {
JSPFLoader* l = new JSPFLoader( true, this ); JSPFLoader* l = new JSPFLoader( true, this );
tDebug( LOGINFO ) << "Loading j-spiff:" << url; tDebug( LOGINFO ) << "Loading j-spiff:" << url;
@@ -580,10 +582,9 @@ TomahawkApp::instanceStarted( KDSingleApplicationGuard::Instance instance )
{ {
tDebug( LOGINFO ) << "Instance started!" << instance.pid << instance.arguments; tDebug( LOGINFO ) << "Instance started!" << instance.pid << instance.arguments;
activate();
if ( instance.arguments.size() < 2 ) if ( instance.arguments.size() < 2 )
{
return; return;
}
QString arg1 = instance.arguments[ 1 ]; QString arg1 = instance.arguments[ 1 ];
loadUrl( arg1 ); loadUrl( arg1 );