mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-08 23:26:40 +02:00
Change updaters to use QMultiHash instead of QHash
This commit is contained in:
@@ -42,11 +42,14 @@ operator<<(QDataStream& out, const PlaylistUpdaterInterface::SerializedUpdaters&
|
|||||||
{
|
{
|
||||||
out << TOMAHAWK_SETTINGS_VERSION;
|
out << TOMAHAWK_SETTINGS_VERSION;
|
||||||
out << (quint32)updaters.count();
|
out << (quint32)updaters.count();
|
||||||
foreach( const QString& key, updaters.keys() )
|
PlaylistUpdaterInterface::SerializedUpdaters::const_iterator iter = updaters.begin();
|
||||||
|
int count = 0;
|
||||||
|
for ( ; iter != updaters.end(); ++iter )
|
||||||
{
|
{
|
||||||
PlaylistUpdaterInterface::SerializedUpdater updater = updaters[ key ];
|
out << iter.key() << iter->type << iter->customData;
|
||||||
out << key << updater.type << updater.customData;
|
count++;
|
||||||
}
|
}
|
||||||
|
Q_ASSERT( count == updaters.count() );
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,13 +64,11 @@ operator>>(QDataStream& in, PlaylistUpdaterInterface::SerializedUpdaters& update
|
|||||||
for ( uint i = 0; i < count; i++ )
|
for ( uint i = 0; i < count; i++ )
|
||||||
{
|
{
|
||||||
QString key, type;
|
QString key, type;
|
||||||
bool sync;
|
|
||||||
QVariantHash customData;
|
QVariantHash customData;
|
||||||
qint32 state, userRating;
|
|
||||||
in >> key;
|
in >> key;
|
||||||
in >> type;
|
in >> type;
|
||||||
in >> customData;
|
in >> customData;
|
||||||
updaters[ key ] = PlaylistUpdaterInterface::SerializedUpdater( type, customData );
|
updaters.insert( key, PlaylistUpdaterInterface::SerializedUpdater( type, customData ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
@@ -504,7 +505,7 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion )
|
|||||||
extraData[ key ] = value( key );
|
extraData[ key ] = value( key );
|
||||||
}
|
}
|
||||||
|
|
||||||
updaters[ playlist ] = PlaylistUpdaterInterface::SerializedUpdater( type, extraData );
|
updaters.insert( playlist, PlaylistUpdaterInterface::SerializedUpdater( type, extraData ) );
|
||||||
|
|
||||||
endGroup();
|
endGroup();
|
||||||
}
|
}
|
||||||
@@ -1250,14 +1251,14 @@ TomahawkSettings::setImportXspfPath( const QString& path )
|
|||||||
PlaylistUpdaterInterface::SerializedUpdaters
|
PlaylistUpdaterInterface::SerializedUpdaters
|
||||||
TomahawkSettings::playlistUpdaters() const
|
TomahawkSettings::playlistUpdaters() const
|
||||||
{
|
{
|
||||||
return value( "playlist/updaters" ).value< PlaylistUpdaterInterface::SerializedUpdaters >();
|
return value( "playlists/updaters" ).value< PlaylistUpdaterInterface::SerializedUpdaters >();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TomahawkSettings::setPlaylistUpdaters( const PlaylistUpdaterInterface::SerializedUpdaters& updaters )
|
TomahawkSettings::setPlaylistUpdaters( const PlaylistUpdaterInterface::SerializedUpdaters& updaters )
|
||||||
{
|
{
|
||||||
setValue( "playlist/updaters", QVariant::fromValue< PlaylistUpdaterInterface::SerializedUpdaters >( updaters ) );
|
setValue( "playlists/updaters", QVariant::fromValue< PlaylistUpdaterInterface::SerializedUpdaters >( updaters ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -23,6 +23,14 @@ using namespace Tomahawk;
|
|||||||
|
|
||||||
QMap< QString, PlaylistUpdaterFactory* > PlaylistUpdaterInterface::s_factories = QMap< QString, PlaylistUpdaterFactory* >();
|
QMap< QString, PlaylistUpdaterFactory* > PlaylistUpdaterInterface::s_factories = QMap< QString, PlaylistUpdaterFactory* >();
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
operator==( const Tomahawk::PlaylistUpdaterInterface::SerializedUpdater& one, const Tomahawk::PlaylistUpdaterInterface::SerializedUpdater& two )
|
||||||
|
{
|
||||||
|
return one.type == two.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistUpdaterInterface::registerUpdaterFactory( PlaylistUpdaterFactory* f )
|
PlaylistUpdaterInterface::registerUpdaterFactory( PlaylistUpdaterFactory* f )
|
||||||
{
|
{
|
||||||
@@ -31,30 +39,29 @@ PlaylistUpdaterInterface::registerUpdaterFactory( PlaylistUpdaterFactory* f )
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
PlaylistUpdaterInterface*
|
void
|
||||||
PlaylistUpdaterInterface::loadForPlaylist( const playlist_ptr& pl )
|
PlaylistUpdaterInterface::loadForPlaylist( const playlist_ptr& pl )
|
||||||
{
|
{
|
||||||
TomahawkSettings* s = TomahawkSettings::instance();
|
TomahawkSettings* s = TomahawkSettings::instance();
|
||||||
|
|
||||||
const SerializedUpdaters updaters = s->playlistUpdaters();
|
const SerializedUpdaters allUpdaters = s->playlistUpdaters();
|
||||||
if ( updaters.contains( pl->guid() ) )
|
if ( allUpdaters.contains( pl->guid() ) )
|
||||||
{
|
{
|
||||||
// Ok, we have one we can try to load
|
// Ok, we have some we can try to load
|
||||||
PlaylistUpdaterInterface* updater = 0;
|
const SerializedUpdaterList updaters = allUpdaters.values( pl->guid() );
|
||||||
const SerializedUpdater info = updaters[ pl->guid() ];
|
foreach ( const SerializedUpdater& info, updaters )
|
||||||
|
|
||||||
if ( !s_factories.contains( info.type ) )
|
|
||||||
{
|
{
|
||||||
Q_ASSERT( false );
|
if ( !s_factories.contains( info.type ) )
|
||||||
// You forgot to register your new updater type with the factory....
|
{
|
||||||
return 0;
|
Q_ASSERT( false );
|
||||||
|
// You forgot to register your new updater type with the factory....
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Updaters register themselves in their constructor
|
||||||
|
s_factories[ info.type ]->create( pl, info.customData );
|
||||||
}
|
}
|
||||||
|
|
||||||
updater = s_factories[ info.type ]->create( pl, info.customData );
|
|
||||||
return updater;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -85,14 +92,15 @@ PlaylistUpdaterInterface::save()
|
|||||||
|
|
||||||
TomahawkSettings* s = TomahawkSettings::instance();
|
TomahawkSettings* s = TomahawkSettings::instance();
|
||||||
|
|
||||||
SerializedUpdaters updaters = s->playlistUpdaters();
|
SerializedUpdaters allUpdaters = s->playlistUpdaters();
|
||||||
|
if ( allUpdaters.contains( m_playlist->guid(), SerializedUpdater( type() ) ) )
|
||||||
|
allUpdaters.remove( m_playlist->guid(), SerializedUpdater( type() ) );
|
||||||
|
|
||||||
SerializedUpdater updater = updaters.value( m_playlist ->guid() );
|
SerializedUpdater updater;
|
||||||
updater.type = type();
|
updater.type = type();
|
||||||
updater.customData = m_extraData;
|
updater.customData = m_extraData;
|
||||||
updaters[ m_playlist->guid() ] = updater;
|
allUpdaters.insert( m_playlist->guid(), updater );
|
||||||
|
s->setPlaylistUpdaters( allUpdaters );
|
||||||
s->setPlaylistUpdaters( updaters );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -102,13 +110,12 @@ PlaylistUpdaterInterface::remove()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
TomahawkSettings* s = TomahawkSettings::instance();
|
TomahawkSettings* s = TomahawkSettings::instance();
|
||||||
|
SerializedUpdaters allUpdaters = s->playlistUpdaters();
|
||||||
|
|
||||||
SerializedUpdaters updaters = s->playlistUpdaters();
|
if ( allUpdaters.remove( m_playlist->guid(), SerializedUpdater( type() ) ) )
|
||||||
if ( updaters.remove( m_playlist->guid() ) )
|
s->setPlaylistUpdaters( allUpdaters );
|
||||||
s->setPlaylistUpdaters( updaters );
|
|
||||||
|
|
||||||
aboutToDelete();
|
aboutToDelete();
|
||||||
|
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -48,11 +48,12 @@ public:
|
|||||||
QString type;
|
QString type;
|
||||||
QVariantHash customData;
|
QVariantHash customData;
|
||||||
|
|
||||||
SerializedUpdater( const QString& t, const QVariantHash cd ) : type( t ), customData( cd ) {}
|
SerializedUpdater( const QString& t, const QVariantHash cd = QVariantHash() ) : type( t ), customData( cd ) {}
|
||||||
SerializedUpdater() {}
|
SerializedUpdater() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef QHash< QString, SerializedUpdater > SerializedUpdaters;
|
typedef QMultiHash< QString, SerializedUpdater > SerializedUpdaters;
|
||||||
|
typedef QList< SerializedUpdater > SerializedUpdaterList;
|
||||||
|
|
||||||
explicit PlaylistUpdaterInterface( const playlist_ptr& pl );
|
explicit PlaylistUpdaterInterface( const playlist_ptr& pl );
|
||||||
|
|
||||||
@@ -74,9 +75,8 @@ public:
|
|||||||
|
|
||||||
playlist_ptr playlist() const { return m_playlist; }
|
playlist_ptr playlist() const { return m_playlist; }
|
||||||
|
|
||||||
/// If you want to try to load a updater from the settings. Returns a valid
|
/// If you want to try to load updaters for a playlist
|
||||||
/// updater if one was saved
|
static void loadForPlaylist( const playlist_ptr& pl );
|
||||||
static PlaylistUpdaterInterface* loadForPlaylist( const playlist_ptr& pl );
|
|
||||||
|
|
||||||
static void registerUpdaterFactory( PlaylistUpdaterFactory* f );
|
static void registerUpdaterFactory( PlaylistUpdaterFactory* f );
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user