2011-04-02 15:34:06 +02:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
|
|
|
|
|
|
|
Clementine 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.
|
|
|
|
|
|
|
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-04-02 17:31:28 +02:00
|
|
|
#include "config.h"
|
2011-05-17 19:53:36 +02:00
|
|
|
#include "coverproviderfactory.h"
|
2011-04-02 15:34:06 +02:00
|
|
|
#include "coverproviders.h"
|
2011-04-02 16:43:50 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBLASTFM
|
2011-05-17 19:53:36 +02:00
|
|
|
# include "lastfmcoverproviderfactory.h"
|
2011-04-02 16:43:50 +02:00
|
|
|
#endif
|
2011-04-02 15:34:06 +02:00
|
|
|
|
|
|
|
CoverProviders::CoverProviders()
|
|
|
|
{
|
2011-05-17 19:53:36 +02:00
|
|
|
// registering built-in provider factories...
|
2011-04-02 15:34:06 +02:00
|
|
|
|
2011-05-17 19:53:36 +02:00
|
|
|
// every built-in provider factory needs an explicit parent; otherwise,
|
2011-04-02 15:34:06 +02:00
|
|
|
// the default parent, namely CoverProviders::instance(), will
|
|
|
|
// cause an infinite recursion here
|
2011-04-02 16:43:50 +02:00
|
|
|
#ifdef HAVE_LIBLASTFM
|
2011-05-17 19:53:36 +02:00
|
|
|
cover_provider_factories_.append(new LastFmCoverProviderFactory(this));
|
2011-04-02 16:43:50 +02:00
|
|
|
#endif
|
2011-04-02 15:34:06 +02:00
|
|
|
}
|
|
|
|
|
2011-05-17 19:53:36 +02:00
|
|
|
void CoverProviders::AddCoverProviderFactory(CoverProviderFactory* factory) {
|
2011-04-02 15:34:06 +02:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&mutex_);
|
|
|
|
Q_UNUSED(locker);
|
|
|
|
|
2011-05-17 19:53:36 +02:00
|
|
|
cover_provider_factories_.append(factory);
|
|
|
|
connect(factory, SIGNAL(destroyed()), SLOT(RemoveCoverProviderFactory()));
|
2011-04-02 15:34:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-17 19:53:36 +02:00
|
|
|
void CoverProviders::RemoveCoverProviderFactory() {
|
|
|
|
// qobject_cast doesn't work here with factories created by python
|
|
|
|
CoverProviderFactory* factory = static_cast<CoverProviderFactory*>(sender());
|
2011-04-02 15:34:06 +02:00
|
|
|
|
2011-05-17 19:53:36 +02:00
|
|
|
if (factory) {
|
2011-04-02 15:34:06 +02:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&mutex_);
|
|
|
|
Q_UNUSED(locker);
|
|
|
|
|
2011-05-17 19:53:36 +02:00
|
|
|
cover_provider_factories_.removeAll(factory);
|
2011-04-02 15:34:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-17 19:53:36 +02:00
|
|
|
const QList<CoverProvider*> CoverProviders::List(AlbumCoverFetcherSearch* parent) {
|
2011-04-02 15:34:06 +02:00
|
|
|
{
|
|
|
|
QMutexLocker locker(&mutex_);
|
|
|
|
Q_UNUSED(locker);
|
|
|
|
|
2011-05-17 19:53:36 +02:00
|
|
|
QList<CoverProvider*> result;
|
|
|
|
foreach(CoverProviderFactory* factory, cover_provider_factories_) {
|
|
|
|
result.append(factory->CreateCoverProvider(parent));
|
|
|
|
}
|
|
|
|
return result;
|
2011-04-02 15:34:06 +02:00
|
|
|
}
|
|
|
|
}
|