Don't statically initialise the RadioModel's services map
This commit is contained in:
parent
cdac0c6c86
commit
c80a4301cc
|
@ -32,7 +32,7 @@
|
|||
#include <QMimeData>
|
||||
#include <QtDebug>
|
||||
|
||||
QMap<QString, RadioService*> RadioModel::sServices;
|
||||
QMap<QString, RadioService*>* RadioModel::sServices = NULL;
|
||||
|
||||
RadioModel::RadioModel(BackgroundThread<Database>* db_thread,
|
||||
TaskManager* task_manager, QObject* parent)
|
||||
|
@ -41,7 +41,10 @@ RadioModel::RadioModel(BackgroundThread<Database>* db_thread,
|
|||
merged_model_(new MergedProxyModel(this)),
|
||||
task_manager_(task_manager)
|
||||
{
|
||||
Q_ASSERT(sServices.isEmpty());
|
||||
if (!sServices) {
|
||||
sServices = new QMap<QString, RadioService*>;
|
||||
}
|
||||
Q_ASSERT(sServices->isEmpty());
|
||||
|
||||
root_->lazy_loaded = true;
|
||||
merged_model_->setSourceModel(this);
|
||||
|
@ -57,7 +60,7 @@ RadioModel::RadioModel(BackgroundThread<Database>* db_thread,
|
|||
}
|
||||
|
||||
void RadioModel::AddService(RadioService *service) {
|
||||
sServices[service->name()] = service;
|
||||
sServices->insert(service->name(), service);
|
||||
service->CreateRootItem(root_);
|
||||
|
||||
connect(service, SIGNAL(AsyncLoadFinished(PlaylistItem::SpecialLoadResult)), SIGNAL(AsyncLoadFinished(PlaylistItem::SpecialLoadResult)));
|
||||
|
@ -69,8 +72,8 @@ void RadioModel::AddService(RadioService *service) {
|
|||
}
|
||||
|
||||
RadioService* RadioModel::ServiceByName(const QString& name) {
|
||||
if (sServices.contains(name))
|
||||
return sServices[name];
|
||||
if (sServices->contains(name))
|
||||
return sServices->value(name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -146,9 +149,7 @@ QMimeData* RadioModel::mimeData(const QModelIndexList& indexes) const {
|
|||
|
||||
#ifdef HAVE_LIBLASTFM
|
||||
LastFMService* RadioModel::GetLastFMService() const {
|
||||
if (sServices.contains(LastFMService::kServiceName))
|
||||
return static_cast<LastFMService*>(sServices[LastFMService::kServiceName]);
|
||||
return NULL;
|
||||
return Service<LastFMService>();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -159,7 +160,7 @@ void RadioModel::ShowContextMenu(RadioItem* item, const QModelIndex& index,
|
|||
}
|
||||
|
||||
void RadioModel::ReloadSettings() {
|
||||
foreach (RadioService* service, sServices.values()) {
|
||||
foreach (RadioService* service, sServices->values()) {
|
||||
service->ReloadSettings();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ class TaskManager;
|
|||
class RadioModel : public SimpleTreeModel<RadioItem> {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
public:
|
||||
RadioModel(BackgroundThread<Database>* db_thread, TaskManager* task_manager,
|
||||
QObject* parent = 0);
|
||||
|
||||
|
@ -54,10 +54,7 @@ class RadioModel : public SimpleTreeModel<RadioItem> {
|
|||
|
||||
template<typename T>
|
||||
static T* Service() {
|
||||
if (sServices.contains(T::kServiceName)) {
|
||||
return static_cast<T*>(sServices[T::kServiceName]);
|
||||
}
|
||||
return NULL;
|
||||
return static_cast<T*>(ServiceByName(T::kServiceName));
|
||||
}
|
||||
|
||||
// This is special because Player needs it for scrobbling
|
||||
|
@ -79,7 +76,7 @@ class RadioModel : public SimpleTreeModel<RadioItem> {
|
|||
MergedProxyModel* merged_model() const { return merged_model_; }
|
||||
TaskManager* task_manager() const { return task_manager_; }
|
||||
|
||||
signals:
|
||||
signals:
|
||||
void AsyncLoadFinished(const PlaylistItem::SpecialLoadResult& result);
|
||||
void StreamError(const QString& message);
|
||||
void StreamMetadataFound(const QUrl& original_url, const Song& song);
|
||||
|
@ -88,15 +85,15 @@ class RadioModel : public SimpleTreeModel<RadioItem> {
|
|||
void AddItemToPlaylist(RadioItem* item, bool clear_first);
|
||||
void AddItemsToPlaylist(const PlaylistItemList& items, bool clear_first);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
void LazyPopulate(RadioItem* parent);
|
||||
|
||||
private:
|
||||
private:
|
||||
QVariant data(const RadioItem* item, int role) const;
|
||||
void AddService(RadioService* service);
|
||||
|
||||
private:
|
||||
static QMap<QString, RadioService*> sServices;
|
||||
private:
|
||||
static QMap<QString, RadioService*>* sServices;
|
||||
BackgroundThread<Database>* db_thread_;
|
||||
MergedProxyModel* merged_model_;
|
||||
TaskManager* task_manager_;
|
||||
|
|
Loading…
Reference in New Issue