mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-19 23:39:42 +01:00
Port echonest catalog sync to new collection add/remove
This commit is contained in:
parent
06ba09f357
commit
85662bb478
@ -68,7 +68,7 @@ set( libSources
|
||||
database/databasecommand_deletefiles.cpp
|
||||
database/databasecommand_dirmtimes.cpp
|
||||
database/databasecommand_filemtimes.cpp
|
||||
database/databasecommand_loadfile.cpp
|
||||
database/databasecommand_loadfiles.cpp
|
||||
database/databasecommand_logplayback.cpp
|
||||
database/databasecommand_addsource.cpp
|
||||
database/databasecommand_sourceoffline.cpp
|
||||
@ -296,7 +296,7 @@ set( libHeaders
|
||||
database/databasecommand_deletefiles.h
|
||||
database/databasecommand_dirmtimes.h
|
||||
database/databasecommand_filemtimes.h
|
||||
database/databasecommand_loadfile.h
|
||||
database/databasecommand_loadfiles.h
|
||||
database/databasecommand_logplayback.h
|
||||
database/databasecommand_addsource.h
|
||||
database/databasecommand_sourceoffline.h
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "database/database.h"
|
||||
#include "database/databasecommand_genericselect.h"
|
||||
#include "database/databasecommand_setcollectionattributes.h"
|
||||
#include "database/databasecommand_loadfiles.h"
|
||||
#include "tomahawksettings.h"
|
||||
#include "sourcelist.h"
|
||||
#include "query.h"
|
||||
@ -41,8 +42,8 @@ EchonestCatalogSynchronizer::EchonestCatalogSynchronizer( QObject *parent )
|
||||
qRegisterMetaType<QList<QStringList> >("QList<QStringList>");
|
||||
|
||||
connect( TomahawkSettings::instance(), SIGNAL( changed() ), this, SLOT( checkSettingsChanged() ) );
|
||||
connect( SourceList::instance()->getLocal()->collection().data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksAdded( QList<Tomahawk::query_ptr> ) ), Qt::QueuedConnection );
|
||||
connect( SourceList::instance()->getLocal()->collection().data(), SIGNAL( tracksRemoved( QList<Tomahawk::query_ptr> ) ), this, SLOT( tracksRemoved( QList<Tomahawk::query_ptr> ) ), Qt::QueuedConnection );
|
||||
connect( SourceList::instance()->getLocal()->collection().data(), SIGNAL( tracksAdded( QList<unsigned int> ) ), this, SLOT( tracksAdded( QList<unsigned int> ) ), Qt::QueuedConnection );
|
||||
connect( SourceList::instance()->getLocal()->collection().data(), SIGNAL( tracksRemoved( QList<unsigned int> ) ), this, SLOT( tracksRemoved( QList<unsigned int> ) ), Qt::QueuedConnection );
|
||||
|
||||
const QByteArray artist = TomahawkSettings::instance()->value( "collection/artistCatalog" ).toByteArray();
|
||||
const QByteArray song = TomahawkSettings::instance()->value( "collection/songCatalog" ).toByteArray();
|
||||
@ -81,7 +82,7 @@ EchonestCatalogSynchronizer::checkSettingsChanged()
|
||||
} else if ( !TomahawkSettings::instance()->enableEchonestCatalogs() && m_syncing )
|
||||
{
|
||||
|
||||
tDebug() << "FOund echonest change, doing catalog deletes!";
|
||||
tDebug() << "Found echonest change, doing catalog deletes!";
|
||||
// delete all track nums and catalog ids from our peers
|
||||
{
|
||||
DatabaseCommand_SetTrackAttributes* cmd = new DatabaseCommand_SetTrackAttributes( DatabaseCommand_SetTrackAttributes::EchonestCatalogId );
|
||||
@ -123,7 +124,9 @@ EchonestCatalogSynchronizer::catalogDeleted()
|
||||
// If we didn't throw, no errors, so clear our config
|
||||
TomahawkSettings::instance()->setValue( toDel, QString() );
|
||||
} catch ( const Echonest::ParseError& e )
|
||||
{}
|
||||
{
|
||||
tLog() << "Error in libechonest parsing catalog delete:" << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -293,60 +296,60 @@ EchonestCatalogSynchronizer::checkTicket()
|
||||
}
|
||||
|
||||
void
|
||||
EchonestCatalogSynchronizer::tracksAdded( const QList< query_ptr >& tracks )
|
||||
EchonestCatalogSynchronizer::tracksAdded( const QList< unsigned int >& tracks )
|
||||
{
|
||||
if ( !m_syncing || m_songCatalog.id().isEmpty() || tracks.isEmpty() )
|
||||
return;
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Got tracks added from db, fetching metadata" << tracks;
|
||||
// Get the result_ptrs from the tracks
|
||||
DatabaseCommand_LoadFiles* cmd = new DatabaseCommand_LoadFiles( tracks );
|
||||
connect( cmd, SIGNAL( results( QList<Tomahawk::result_ptr> ) ), this, SLOT( loadedResults( QList<Tomahawk::result_ptr> ) ) );
|
||||
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
EchonestCatalogSynchronizer::loadedResults( const QList<result_ptr>& results )
|
||||
{
|
||||
QList< QStringList > rawTracks;
|
||||
foreach( const query_ptr& track, tracks )
|
||||
qDebug() << Q_FUNC_INFO << "Got track metadata..." << results.size();
|
||||
|
||||
foreach( const result_ptr& result, results )
|
||||
{
|
||||
// DatabaseCommand_AddFiles sets the track id on the result
|
||||
int id = -1;
|
||||
if ( track->results().size() == 1 )
|
||||
id = track->results().first()->dbid();
|
||||
else
|
||||
{
|
||||
tLog() << Q_FUNC_INFO << "No dbid for track we got in tracksAdded()!";
|
||||
if ( result.isNull() )
|
||||
continue;
|
||||
}
|
||||
rawTracks << ( QStringList() << QString::number( id ) << track->track() << track->artist() << track->album() );
|
||||
|
||||
qDebug() << "Metadata for item:" << result->fileId();
|
||||
|
||||
const QString artist = result->artist().isNull() ? QString() : result->artist()->name();
|
||||
const QString album = result->album().isNull() ? QString() : result->album()->name();
|
||||
rawTracks << ( QStringList() << QString::number( result->fileId() ) << result->track() << artist << album );
|
||||
}
|
||||
rawTracksAdd( rawTracks );
|
||||
}
|
||||
|
||||
void
|
||||
EchonestCatalogSynchronizer::tracksRemoved( const QList< query_ptr >& tracks )
|
||||
EchonestCatalogSynchronizer::tracksRemoved( const QList< unsigned int >& trackIds )
|
||||
{
|
||||
|
||||
if ( !m_syncing || m_songCatalog.id().isEmpty() || tracks.isEmpty() )
|
||||
if ( !m_syncing || m_songCatalog.id().isEmpty() || trackIds.isEmpty() )
|
||||
return;
|
||||
|
||||
|
||||
Echonest::CatalogUpdateEntries entries;
|
||||
entries.reserve( tracks.size() );
|
||||
entries.reserve( trackIds.size() );
|
||||
|
||||
foreach ( const query_ptr& q, tracks )
|
||||
foreach ( unsigned int id, trackIds )
|
||||
{
|
||||
QByteArray itemId;
|
||||
if ( q->results().size() > 0 )
|
||||
{
|
||||
// Should always be the case, should have the local result from the db that we are deleting!
|
||||
itemId = QString::number( q->results().first()->dbid() ).toLatin1();
|
||||
}
|
||||
else
|
||||
{
|
||||
tLog() << "Got deleted query_ptr with no local result! Wtf!" << q->track() << q->artist() << q->results();
|
||||
continue;
|
||||
}
|
||||
|
||||
tDebug() << "Deleting item with id:" << itemId;
|
||||
tDebug() << "Deleting item with id:" << id;
|
||||
Echonest::CatalogUpdateEntry e( Echonest::CatalogTypes::Delete );
|
||||
e.setItemId( itemId );
|
||||
e.setItemId( QString::number( id ).toLatin1() );
|
||||
entries.append( e );
|
||||
}
|
||||
|
||||
m_songCatalog.update( entries );
|
||||
QNetworkReply* reply = m_songCatalog.update( entries );
|
||||
connect( reply, SIGNAL( finished() ), this, SLOT( songUpdateFinished() ) );
|
||||
}
|
||||
|
||||
QByteArray
|
||||
|
@ -54,8 +54,10 @@ signals:
|
||||
|
||||
private slots:
|
||||
void checkSettingsChanged();
|
||||
void tracksAdded( const QList<Tomahawk::query_ptr>& );
|
||||
void tracksRemoved( const QList<Tomahawk::query_ptr>& );
|
||||
void tracksAdded( const QList<unsigned int>& );
|
||||
void tracksRemoved( const QList<unsigned int>& );
|
||||
|
||||
void loadedResults( const QList<Tomahawk::result_ptr>& results );
|
||||
|
||||
// Echonest slots
|
||||
void songCreateFinished();
|
||||
|
@ -78,8 +78,8 @@ public:
|
||||
unsigned int lastmodified() const { return m_lastmodified; }
|
||||
|
||||
signals:
|
||||
void tracksAdded( const QList<unsigned int>& ids );
|
||||
void tracksRemoved( const QList<unsigned int>& ids );
|
||||
void tracksAdded( const QList<unsigned int>& fileids );
|
||||
void tracksRemoved( const QList<unsigned int>& fileids );
|
||||
|
||||
void playlistsAdded( const QList<Tomahawk::playlist_ptr>& );
|
||||
void playlistsDeleted( const QList<Tomahawk::playlist_ptr>& );
|
||||
@ -100,8 +100,8 @@ public slots:
|
||||
void setAutoPlaylists( const QList< Tomahawk::dynplaylist_ptr >& autoplists );
|
||||
void setStations( const QList< Tomahawk::dynplaylist_ptr >& stations );
|
||||
|
||||
void setTracks( const QList<unsigned int>& ids );
|
||||
void delTracks( const QList<unsigned int>& ids );
|
||||
void setTracks( const QList<unsigned int>& fileids );
|
||||
void delTracks( const QList<unsigned int>& fileids );
|
||||
|
||||
protected:
|
||||
QString m_name;
|
||||
|
@ -1,49 +0,0 @@
|
||||
/* === 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tomahawk is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "databasecommand_loadfile.h"
|
||||
|
||||
#include "databaseimpl.h"
|
||||
#include "collection.h"
|
||||
#include "utils/logger.h"
|
||||
|
||||
|
||||
DatabaseCommand_LoadFile::DatabaseCommand_LoadFile( const QString& id, QObject* parent )
|
||||
: DatabaseCommand( parent )
|
||||
, m_id( id )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DatabaseCommand_LoadFile::exec( DatabaseImpl* dbi )
|
||||
{
|
||||
Tomahawk::result_ptr r;
|
||||
// file ids internally are really ints, at least for now:
|
||||
bool ok;
|
||||
do
|
||||
{
|
||||
unsigned int fid = m_id.toInt( &ok );
|
||||
if( !ok )
|
||||
break;
|
||||
|
||||
r = dbi->file( fid );
|
||||
} while( false );
|
||||
|
||||
emit result( r );
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/* === 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Tomahawk is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DATABASECOMMAND_LOADFILE_H
|
||||
#define DATABASECOMMAND_LOADFILE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariantMap>
|
||||
#include <QMap>
|
||||
|
||||
#include "databasecommand.h"
|
||||
#include "result.h"
|
||||
#include "dllmacro.h"
|
||||
|
||||
class DLLEXPORT DatabaseCommand_LoadFile : public DatabaseCommand
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DatabaseCommand_LoadFile( const QString& id, QObject* parent = 0 );
|
||||
virtual void exec( DatabaseImpl* );
|
||||
virtual bool doesMutates() const { return false; }
|
||||
virtual QString commandname() const { return "loadfile"; }
|
||||
|
||||
signals:
|
||||
void result( const Tomahawk::result_ptr& result );
|
||||
|
||||
private:
|
||||
QString m_id;
|
||||
};
|
||||
|
||||
#endif // DATABASECOMMAND_LOADFILE_H
|
@ -25,7 +25,7 @@
|
||||
#include "bufferiodevice.h"
|
||||
#include "network/controlconnection.h"
|
||||
#include "network/servent.h"
|
||||
#include "database/databasecommand_loadfile.h"
|
||||
#include "database/databasecommand_loadfiles.h"
|
||||
#include "database/database.h"
|
||||
#include "sourcelist.h"
|
||||
#include "utils/logger.h"
|
||||
@ -158,7 +158,7 @@ StreamConnection::setup()
|
||||
|
||||
qDebug() << "in TX mode, fid:" << m_fid;
|
||||
|
||||
DatabaseCommand_LoadFile* cmd = new DatabaseCommand_LoadFile( m_fid );
|
||||
DatabaseCommand_LoadFiles* cmd = new DatabaseCommand_LoadFiles( m_fid.toUInt() );
|
||||
connect( cmd, SIGNAL( result( Tomahawk::result_ptr ) ), SLOT( startSending( Tomahawk::result_ptr ) ) );
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
}
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "database/databasecommand_resolve.h"
|
||||
#include "database/databasecommand_alltracks.h"
|
||||
#include "database/databasecommand_addfiles.h"
|
||||
#include "database/databasecommand_loadfile.h"
|
||||
#include "database/databasecommand_loadsocialactions.h"
|
||||
|
||||
#include "utils/logger.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user