2009-12-26 16:13:38 +01:00
|
|
|
#include "radiomodel.h"
|
|
|
|
#include "radioservice.h"
|
|
|
|
#include "lastfmservice.h"
|
2010-01-18 03:23:55 +01:00
|
|
|
#include "somafmservice.h"
|
2009-12-26 22:35:45 +01:00
|
|
|
#include "radiomimedata.h"
|
2010-02-24 23:26:01 +01:00
|
|
|
#include "savedradio.h"
|
2009-12-26 22:35:45 +01:00
|
|
|
|
|
|
|
#include <QMimeData>
|
|
|
|
#include <QtDebug>
|
|
|
|
|
|
|
|
QMap<QString, RadioService*> RadioModel::sServices;
|
2009-12-26 16:13:38 +01:00
|
|
|
|
|
|
|
RadioModel::RadioModel(QObject* parent)
|
2009-12-30 01:31:00 +01:00
|
|
|
: SimpleTreeModel<RadioItem>(new RadioItem(this), parent)
|
2009-12-26 16:13:38 +01:00
|
|
|
{
|
2009-12-26 22:35:45 +01:00
|
|
|
Q_ASSERT(sServices.isEmpty());
|
|
|
|
|
2009-12-26 16:13:38 +01:00
|
|
|
root_->lazy_loaded = true;
|
|
|
|
|
2009-12-26 22:35:45 +01:00
|
|
|
AddService(new LastFMService(this));
|
2010-01-18 03:23:55 +01:00
|
|
|
AddService(new SomaFMService(this));
|
2010-02-24 23:26:01 +01:00
|
|
|
AddService(new SavedRadio(this));
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RadioModel::AddService(RadioService *service) {
|
|
|
|
sServices[service->name()] = service;
|
|
|
|
service->CreateRootItem(root_);
|
|
|
|
|
2010-02-23 19:33:09 +01:00
|
|
|
connect(service, SIGNAL(TaskStarted(MultiLoadingIndicator::TaskType)), SIGNAL(TaskStarted(MultiLoadingIndicator::TaskType)));
|
|
|
|
connect(service, SIGNAL(TaskFinished(MultiLoadingIndicator::TaskType)), SIGNAL(TaskFinished(MultiLoadingIndicator::TaskType)));
|
2009-12-26 22:35:45 +01:00
|
|
|
connect(service, SIGNAL(StreamReady(QUrl,QUrl)), SIGNAL(StreamReady(QUrl,QUrl)));
|
|
|
|
connect(service, SIGNAL(StreamFinished()), SIGNAL(StreamFinished()));
|
|
|
|
connect(service, SIGNAL(StreamError(QString)), SIGNAL(StreamError(QString)));
|
2009-12-26 23:15:57 +01:00
|
|
|
connect(service, SIGNAL(StreamMetadataFound(QUrl,Song)), SIGNAL(StreamMetadataFound(QUrl,Song)));
|
2009-12-30 02:41:37 +01:00
|
|
|
connect(service, SIGNAL(AddItemToPlaylist(RadioItem*)), SIGNAL(AddItemToPlaylist(RadioItem*)));
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
RadioService* RadioModel::ServiceByName(const QString& name) {
|
|
|
|
if (sServices.contains(name))
|
|
|
|
return sServices[name];
|
|
|
|
return NULL;
|
2009-12-26 16:13:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant RadioModel::data(const QModelIndex& index, int role) const {
|
|
|
|
const RadioItem* item = IndexToItem(index);
|
|
|
|
|
|
|
|
return data(item, role);
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant RadioModel::data(const RadioItem* item, int role) const {
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
return item->DisplayText();
|
|
|
|
|
|
|
|
case Qt::DecorationRole:
|
|
|
|
return item->icon;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Role_Type:
|
|
|
|
return item->type;
|
|
|
|
|
|
|
|
case Role_Key:
|
|
|
|
return item->key;
|
|
|
|
|
|
|
|
case Role_SortText:
|
|
|
|
return item->SortText();
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadioModel::LazyPopulate(RadioItem* parent) {
|
|
|
|
if (parent->service)
|
|
|
|
parent->service->LazyPopulate(parent);
|
|
|
|
}
|
2009-12-26 22:35:45 +01:00
|
|
|
|
|
|
|
Qt::ItemFlags RadioModel::flags(const QModelIndex& index) const {
|
|
|
|
RadioItem* item = IndexToItem(index);
|
|
|
|
if (item->playable)
|
|
|
|
return Qt::ItemIsSelectable |
|
|
|
|
Qt::ItemIsEnabled |
|
|
|
|
Qt::ItemIsDragEnabled;
|
|
|
|
|
|
|
|
return Qt::ItemIsSelectable |
|
|
|
|
Qt::ItemIsEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList RadioModel::mimeTypes() const {
|
|
|
|
return QStringList() << "text/uri-list";
|
|
|
|
}
|
|
|
|
|
|
|
|
QMimeData* RadioModel::mimeData(const QModelIndexList& indexes) const {
|
|
|
|
QList<QUrl> urls;
|
2009-12-30 00:17:54 +01:00
|
|
|
QList<RadioItem*> items;
|
2009-12-26 22:35:45 +01:00
|
|
|
|
|
|
|
foreach (const QModelIndex& index, indexes) {
|
|
|
|
RadioItem* item = IndexToItem(index);
|
|
|
|
if (!item || !item->service || !item->playable)
|
|
|
|
continue;
|
|
|
|
|
2009-12-30 00:17:54 +01:00
|
|
|
items << item;
|
|
|
|
urls << item->service->UrlForItem(item);
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (urls.isEmpty())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
RadioMimeData* data = new RadioMimeData;
|
|
|
|
data->setUrls(urls);
|
2009-12-30 00:17:54 +01:00
|
|
|
data->items = items;
|
2009-12-26 22:35:45 +01:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2009-12-29 20:22:02 +01:00
|
|
|
|
|
|
|
LastFMService* RadioModel::GetLastFMService() const {
|
|
|
|
if (sServices.contains(LastFMService::kServiceName))
|
|
|
|
return static_cast<LastFMService*>(sServices[LastFMService::kServiceName]);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-12-30 00:01:07 +01:00
|
|
|
|
|
|
|
void RadioModel::ShowContextMenu(RadioItem* item, const QPoint& global_pos) {
|
|
|
|
if (item->service)
|
|
|
|
item->service->ShowContextMenu(item, global_pos);
|
|
|
|
}
|
2010-02-03 19:32:48 +01:00
|
|
|
|
|
|
|
void RadioModel::ReloadSettings() {
|
|
|
|
foreach (RadioService* service, sServices.values()) {
|
|
|
|
service->ReloadSettings();
|
|
|
|
}
|
|
|
|
}
|