[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [amarok] src: Refactoring: Cleanup CollectionManager
From: Ralf Engels <ralf-engels () gmx ! de>
Date: 2015-01-17 18:12:21
Message-ID: E1YCXrB-000431-2H () scm ! kde ! org
[Download RAW message or body]
Git commit eb7ba50169d9949a55ebd06c6fba29c888280d1c by Ralf Engels.
Committed on 02/01/2015 at 11:19.
Pushed by rengels into branch 'master'.
Refactoring: Cleanup CollectionManager
Remove now unneeded Storage property from Collection
Replace "addUnmanagedCollection" by "addTrackProvider"
M +0 -2 src/PluginManager.cpp
M +0 -5 src/core-impl/collections/db/sql/SqlCollection.h
M +1 -0 src/core-impl/collections/playdarcollection/PlaydarCollection.cpp
M +5 -80 src/core-impl/collections/support/CollectionManager.cpp
M +0 -16 src/core-impl/collections/support/CollectionManager.h
M +2 -2 src/services/amazon/AmazonStore.cpp
M +2 -2 src/services/ampache/AmpacheService.cpp
M +9 -2 src/services/jamendo/JamendoService.cpp
M +3 -3 src/services/lastfm/LastFmService.cpp
M +2 -2 src/services/magnatune/MagnatuneStore.cpp
M +2 -3 src/services/mp3tunes/Mp3tunesService.cpp
http://commits.kde.org/amarok/eb7ba50169d9949a55ebd06c6fba29c888280d1c
diff --git a/src/PluginManager.cpp b/src/PluginManager.cpp
index 9148041..abdc707 100644
--- a/src/PluginManager.cpp
+++ b/src/PluginManager.cpp
@@ -232,8 +232,6 @@ Plugins::PluginManager::createFactory( const KPluginInfo \
&pluginInfo ) return 0;
}
- debug() << "created factory for plugin" << name << "type:" << \
pluginInfo.category();
- debug() << "is vital?" << pluginInfo.property("X-KDE-Amarok-vital").toBool();
m_factoryCreated[ pluginInfo.pluginName() ] = factory;
return factory;
}
diff --git a/src/core-impl/collections/db/sql/SqlCollection.h \
b/src/core-impl/collections/db/sql/SqlCollection.h index 71f2140..7478c79 100644
--- a/src/core-impl/collections/db/sql/SqlCollection.h
+++ b/src/core-impl/collections/db/sql/SqlCollection.h
@@ -41,11 +41,6 @@ class AMAROK_SQLCOLLECTION_EXPORT SqlCollection : public \
Collections::DatabaseCo {
Q_OBJECT
- Q_PROPERTY( SqlStorage *sqlStorage
- READ sqlStorage
- SCRIPTABLE false
- DESIGNABLE false )
-
public:
/** Creates a new SqlCollection.
* @param storage The storage this collection should work on. It will be \
freed by the collection.
diff --git a/src/core-impl/collections/playdarcollection/PlaydarCollection.cpp \
b/src/core-impl/collections/playdarcollection/PlaydarCollection.cpp index \
5c2349d..e4d5acf 100644
--- a/src/core-impl/collections/playdarcollection/PlaydarCollection.cpp
+++ b/src/core-impl/collections/playdarcollection/PlaydarCollection.cpp
@@ -51,6 +51,7 @@ namespace Collections
PlaydarCollectionFactory::~PlaydarCollectionFactory()
{
DEBUG_BLOCK
+ CollectionManager::instance()->removeTrackProvider( m_collection.data() );
delete m_collection.data();
delete m_controller;
}
diff --git a/src/core-impl/collections/support/CollectionManager.cpp \
b/src/core-impl/collections/support/CollectionManager.cpp index b96f952..8f01146 \
100644
--- a/src/core-impl/collections/support/CollectionManager.cpp
+++ b/src/core-impl/collections/support/CollectionManager.cpp
@@ -24,15 +24,15 @@
#include "core/support/Amarok.h"
#include "core/support/Debug.h"
#include "core/support/SmartPointerList.h"
-#include <core/storage/SqlStorage.h>
#include "core-impl/meta/file/FileTrackProvider.h"
#include "core-impl/meta/stream/Stream.h"
#include "core-impl/meta/timecode/TimecodeTrackProvider.h"
-#include <QCoreApplication>
-#include <QList>
#include <QMetaEnum>
#include <QMetaObject>
+
+#include <QCoreApplication>
+#include <QList>
#include <QPair>
#include <QTimer>
#include <QReadWriteLock>
@@ -46,8 +46,6 @@ struct CollectionManager::Private
QList<CollectionPair> collections;
QList<Plugins::PluginFactory*> factories; // factories belong to PluginManager
- QList<Collections::Collection*> unmanagedCollections;
-
QList<Collections::TrackProvider*> trackProviders;
TimecodeTrackProvider *timecodeTrackProvider;
Collections::TrackProvider *fileTrackProvider; // special case
@@ -103,7 +101,6 @@ CollectionManager::~CollectionManager()
delete d->timecodeTrackProvider;
delete d->fileTrackProvider;
d->collections.clear();
- d->unmanagedCollections.clear();
d->trackProviders.clear();
// Hmm, qDeleteAll from Qt 4.8 crashes with our SmartPointerList, do it \
manually. Bug 285951 @@ -270,22 +267,8 @@ CollectionManager::slotNewCollection( \
Collections::Collection* newCollection )
connect( newCollection, SIGNAL(remove()), SLOT(slotRemoveCollection()), \
Qt::QueuedConnection );
connect( newCollection, SIGNAL(updated()), SLOT(slotCollectionChanged()), \
Qt::QueuedConnection );
- // by convention, collections that provide a SQL database have a Qt property \
called "sqlStorage"
- int propertyIndex = newCollection->metaObject()->indexOfProperty( \
"sqlStorage" );
- if( propertyIndex != -1 )
- {
- SqlStorage *sqlStorage = newCollection->property( "sqlStorage" \
).value<SqlStorage*>();
- if( sqlStorage )
- {
- //let's cheat a bit and assume that sqlStorage and the \
primaryCollection are always the same
- //it is true for now anyway
- d->primaryCollection = newCollection;
- }
- else
- {
- warning() << "Collection " << newCollection->collectionId() << " has \
sqlStorage property but did not provide a SqlStorage pointer";
- }
- }
+ if( newCollection->collectionId() == "localCollection" )
+ d->primaryCollection = newCollection;
}
if( status & CollectionViewable )
@@ -353,23 +336,6 @@ CollectionManager::primaryCollection() const
return d->primaryCollection;
}
-Meta::TrackList
-CollectionManager::tracksForUrls( const KUrl::List &urls )
-{
- DEBUG_BLOCK
-
- debug() << "adding " << urls.size() << " tracks";
-
- Meta::TrackList tracks;
- foreach( const KUrl &url, urls )
- {
- Meta::TrackPtr track = trackForUrl( url );
- if( track )
- tracks.append( track );
- }
- return tracks;
-}
-
Meta::TrackPtr
CollectionManager::trackForUrl( const KUrl &url )
{
@@ -410,47 +376,6 @@ CollectionManager::trackForUrl( const KUrl &url )
}
-void
-CollectionManager::addUnmanagedCollection( Collections::Collection *newCollection, \
CollectionStatus defaultStatus )
-{
- QWriteLocker locker( &d->lock );
-
- // TODO: what happens if a collection is managed and then added as unmanaged
- // or the other way round.
- if( newCollection && d->unmanagedCollections.indexOf( newCollection ) == -1 )
- {
- const QMetaObject *mo = metaObject();
- const QMetaEnum me = mo->enumerator( mo->indexOfEnumerator( \
"CollectionStatus" ) );
- const QString &value = KGlobal::config()->group( "CollectionManager" \
).readEntry( newCollection->collectionId() );
- int enumValue = me.keyToValue( value.toLocal8Bit().constData() );
- CollectionStatus status;
- enumValue == -1 ? status = defaultStatus : status = (CollectionStatus) \
enumValue;
- d->unmanagedCollections.append( newCollection );
- CollectionPair pair( newCollection, status );
- d->collections.append( pair );
- d->trackProviders.append( newCollection );
- if( status & CollectionViewable )
- {
- emit collectionAdded( newCollection );
- emit collectionAdded( newCollection, status );
- }
- emit trackProviderAdded( newCollection );
- }
-}
-
-void
-CollectionManager::removeUnmanagedCollection( Collections::Collection *collection )
-{
- //do not remove it from collection if it is not in unmanagedCollections
- if( collection && d->unmanagedCollections.removeAll( collection ) )
- {
- CollectionPair pair( collection, collectionStatus( \
collection->collectionId() ) );
- d->collections.removeAll( pair );
- d->trackProviders.removeAll( collection );
- emit collectionRemoved( collection->collectionId() );
- }
-}
-
CollectionManager::CollectionStatus
CollectionManager::collectionStatus( const QString &collectionId ) const
{
diff --git a/src/core-impl/collections/support/CollectionManager.h \
b/src/core-impl/collections/support/CollectionManager.h index fbfe5dd..4291c56 100644
--- a/src/core-impl/collections/support/CollectionManager.h
+++ b/src/core-impl/collections/support/CollectionManager.h
@@ -97,22 +97,6 @@ class AMAROK_EXPORT CollectionManager : public QObject
could be created for the url.
*/
Meta::TrackPtr trackForUrl( const KUrl &url );
- /**
- * convenience method. See trackForUrl( const KUrl ).
- */
- Meta::TrackList tracksForUrls( const KUrl::List &urls );
-
-
- /**
- * add a collection whose lifecycle is not managed by CollectionManager.
- *
- * @param defaultStatus uses the default status passed as the second \
argument unless a custom
- * status is stored in Amarok's config file.
- *
- * Also adds the collection as track provider
- */
- void addUnmanagedCollection( Collections::Collection *newCollection, \
CollectionStatus defaultStatus );
- void removeUnmanagedCollection( Collections::Collection *collection );
CollectionStatus collectionStatus( const QString &collectionId ) const;
diff --git a/src/services/amazon/AmazonStore.cpp \
b/src/services/amazon/AmazonStore.cpp index eb42566..2471480 100644
--- a/src/services/amazon/AmazonStore.cpp
+++ b/src/services/amazon/AmazonStore.cpp
@@ -116,7 +116,7 @@ AmazonStore::AmazonStore( AmazonServiceFactory* parent, const \
char *name ) m_lastSearch.clear();
// add the collection, exclude it from global queries
- CollectionManager::instance()->addUnmanagedCollection( m_collection, \
CollectionManager::CollectionDisabled ); + \
CollectionManager::instance()->addTrackProvider( m_collection );
connect( m_searchWidget, SIGNAL(filterChanged(QString)), this, \
SLOT(newSearchRequest(QString)) );
@@ -126,7 +126,7 @@ AmazonStore::AmazonStore( AmazonServiceFactory* parent, const \
char *name )
AmazonStore::~AmazonStore()
{
- CollectionManager::instance()->removeUnmanagedCollection( m_collection );
+ CollectionManager::instance()->removeTrackProvider( m_collection );
delete m_collection;
}
diff --git a/src/services/ampache/AmpacheService.cpp \
b/src/services/ampache/AmpacheService.cpp index e3f7c68..c280ba8 100644
--- a/src/services/ampache/AmpacheService.cpp
+++ b/src/services/ampache/AmpacheService.cpp
@@ -105,7 +105,7 @@ AmpacheService::AmpacheService( AmpacheServiceFactory* parent, \
const QString & n
AmpacheService::~AmpacheService()
{
- CollectionManager::instance()->removeUnmanagedCollection( m_collection );
+ CollectionManager::instance()->removeTrackProvider( m_collection );
delete m_collection;
m_ampacheLogin->deleteLater();
}
@@ -135,7 +135,7 @@ AmpacheService::onLoginSuccessful()
m_collection = new Collections::AmpacheServiceCollection( this, \
m_ampacheLogin->server(), m_ampacheLogin->sessionId() );
// connect( m_collection, SIGNAL(authenticationNeeded()), SLOT(authenticate()) \
);
- CollectionManager::instance()->addUnmanagedCollection( m_collection, \
CollectionManager::CollectionDisabled ); + \
CollectionManager::instance()->addTrackProvider( m_collection ); \
QList<CategoryId::CatMenuId> levels; levels << CategoryId::Artist << \
CategoryId::Album;
setModel( new SingleCollectionTreeItemModel( m_collection, levels ) );
diff --git a/src/services/jamendo/JamendoService.cpp \
b/src/services/jamendo/JamendoService.cpp index 6d65244..e8ffbce 100644
--- a/src/services/jamendo/JamendoService.cpp
+++ b/src/services/jamendo/JamendoService.cpp
@@ -89,14 +89,21 @@ setImagePath( KStandardDirs::locate( "data", \
"amarok/images/hover_info_jamendo.p
ServiceMetaFactory * metaFactory = new JamendoMetaFactory( "jamendo", this );
ServiceSqlRegistry * registry = new ServiceSqlRegistry( metaFactory );
m_collection = new Collections::ServiceSqlCollection( "jamendo", "Jamendo.com", \
metaFactory, registry );
- CollectionManager::instance()->addUnmanagedCollection( m_collection, \
CollectionManager::CollectionDisabled ); + \
CollectionManager::instance()->addTrackProvider( m_collection ); setServiceReady( \
true ); }
JamendoService::~JamendoService()
{
DEBUG_BLOCK
-
+
+ if( m_collection )
+ {
+ CollectionManager::instance()->removeTrackProvider( m_collection );
+ m_collection->deleteLater();
+ m_collection = 0;
+ }
+
//if currently running, stop it or we will get crashes
if( m_xmlParser ) {
m_xmlParser->requestAbort();
diff --git a/src/services/lastfm/LastFmService.cpp \
b/src/services/lastfm/LastFmService.cpp index 9b5e51c..48a9258 100644
--- a/src/services/lastfm/LastFmService.cpp
+++ b/src/services/lastfm/LastFmService.cpp
@@ -156,9 +156,9 @@ LastFmService::~LastFmService()
delete factory;
}
- if( m_collection && CollectionManager::instance() )
+ if( m_collection )
{
- CollectionManager::instance()->removeUnmanagedCollection( m_collection );
+ CollectionManager::instance()->removeTrackProvider( m_collection );
m_collection->deleteLater();
m_collection = 0;
}
@@ -181,7 +181,7 @@ LastFmService::slotReconfigure()
if( !m_collection && ready )
{
m_collection = new Collections::LastFmServiceCollection( \
m_config->username() );
- CollectionManager::instance()->addUnmanagedCollection( m_collection, \
CollectionManager::CollectionDisabled ); + \
CollectionManager::instance()->addTrackProvider( m_collection ); }
// create Model once the username is known, it depends on it implicitly
diff --git a/src/services/magnatune/MagnatuneStore.cpp \
b/src/services/magnatune/MagnatuneStore.cpp index a8f598c..1ae4b12 100644
--- a/src/services/magnatune/MagnatuneStore.cpp
+++ b/src/services/magnatune/MagnatuneStore.cpp
@@ -134,13 +134,13 @@ MagnatuneStore::MagnatuneStore( MagnatuneServiceFactory* \
parent, const char *nam metaFactory->setStreamType( m_streamType );
m_registry = new ServiceSqlRegistry( metaFactory );
m_collection = new Collections::MagnatuneSqlCollection( "magnatune", \
"Magnatune.com", metaFactory, m_registry );
- CollectionManager::instance()->addUnmanagedCollection( m_collection, \
CollectionManager::CollectionDisabled ); + \
CollectionManager::instance()->addTrackProvider( m_collection ); setServiceReady( \
true ); }
MagnatuneStore::~MagnatuneStore()
{
- CollectionManager::instance()->removeUnmanagedCollection( m_collection );
+ CollectionManager::instance()->removeTrackProvider( m_collection );
delete m_registry;
delete m_collection;
}
diff --git a/src/services/mp3tunes/Mp3tunesService.cpp \
b/src/services/mp3tunes/Mp3tunesService.cpp index ed2b006..d926f42 100644
--- a/src/services/mp3tunes/Mp3tunesService.cpp
+++ b/src/services/mp3tunes/Mp3tunesService.cpp
@@ -127,7 +127,7 @@ Mp3tunesService::~Mp3tunesService()
delete m_locker;
// delete m_daemon;
if( m_collection ) {
- CollectionManager::instance()->removeUnmanagedCollection( m_collection );
+ CollectionManager::instance()->removeTrackProvider( m_collection );
delete m_collection;
}
}
@@ -282,8 +282,7 @@ void Mp3tunesService::authenticationComplete( const QString & \
sessionId ) m_authenticated = true;
m_collection = new Collections::Mp3tunesServiceCollection( this, \
m_sessionId, m_locker );
- CollectionManager::instance()->addUnmanagedCollection( m_collection,
- CollectionManager::CollectionDisabled );
+ CollectionManager::instance()->addTrackProvider( m_collection );
QList<CategoryId::CatMenuId> levels;
levels << CategoryId::Artist << CategoryId::Album;
setModel( new SingleCollectionTreeItemModel( m_collection, levels ) );
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic