2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2009-12-26 22:35:45 +01:00
|
|
|
#include "radioplaylistitem.h"
|
|
|
|
#include "radioservice.h"
|
|
|
|
#include "radiomodel.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "core/settingsprovider.h"
|
2010-08-03 20:57:17 +02:00
|
|
|
#include "library/sqlrow.h"
|
2011-04-27 00:06:58 +02:00
|
|
|
#include "playlist/playlistbackend.h"
|
2009-12-26 22:35:45 +01:00
|
|
|
|
|
|
|
#include <QSettings>
|
2010-02-23 19:33:09 +01:00
|
|
|
#include <QApplication>
|
2010-04-14 23:03:00 +02:00
|
|
|
#include <QtDebug>
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2010-04-14 23:03:00 +02:00
|
|
|
RadioPlaylistItem::RadioPlaylistItem(const QString& type)
|
|
|
|
: PlaylistItem(type),
|
2011-01-15 01:53:39 +01:00
|
|
|
set_service_icon_(false)
|
2009-12-26 22:35:45 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-04-27 00:06:58 +02:00
|
|
|
RadioPlaylistItem::RadioPlaylistItem(RadioService* service, const Song& metadata)
|
2010-04-14 23:03:00 +02:00
|
|
|
: PlaylistItem("Radio"),
|
2011-01-12 20:59:17 +01:00
|
|
|
service_name_(service->name()),
|
2011-04-27 00:06:58 +02:00
|
|
|
set_service_icon_(false),
|
|
|
|
metadata_(metadata)
|
2009-12-26 22:35:45 +01:00
|
|
|
{
|
2009-12-29 20:22:02 +01:00
|
|
|
InitMetadata();
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
2010-08-03 20:57:17 +02:00
|
|
|
bool RadioPlaylistItem::InitFromQuery(const SqlRow& query) {
|
2010-05-10 16:19:43 +02:00
|
|
|
// The song tables gets joined first, plus one each for the song ROWIDs
|
2011-04-27 00:06:58 +02:00
|
|
|
const int row = (Song::kColumns.count() + 1) * PlaylistBackend::kSongTableJoins;
|
2010-04-14 23:03:00 +02:00
|
|
|
|
2011-04-27 00:06:58 +02:00
|
|
|
service_name_ = query.value(row + 1).toString();
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2011-04-27 00:06:58 +02:00
|
|
|
metadata_.InitFromQuery(query, (Song::kColumns.count() + 1) * 3);
|
2009-12-29 20:22:02 +01:00
|
|
|
InitMetadata();
|
2011-04-27 00:06:58 +02:00
|
|
|
|
2010-04-27 19:37:26 +02:00
|
|
|
return true;
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
2011-01-12 20:59:17 +01:00
|
|
|
RadioService* RadioPlaylistItem::service() const {
|
2011-01-15 01:53:39 +01:00
|
|
|
RadioService* ret = RadioModel::ServiceByName(service_name_);
|
|
|
|
|
|
|
|
if (ret && !set_service_icon_) {
|
|
|
|
const_cast<RadioPlaylistItem*>(this)->set_service_icon_ = true;
|
|
|
|
|
|
|
|
QString icon = ret->Icon();
|
|
|
|
if (!icon.isEmpty()) {
|
|
|
|
const_cast<RadioPlaylistItem*>(this)->metadata_.set_art_manual(icon);
|
2011-01-12 20:59:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-15 01:53:39 +01:00
|
|
|
return ret;
|
2011-01-12 20:59:17 +01:00
|
|
|
}
|
|
|
|
|
2010-04-14 23:03:00 +02:00
|
|
|
QVariant RadioPlaylistItem::DatabaseValue(DatabaseColumn column) const {
|
|
|
|
switch (column) {
|
2011-01-15 01:53:39 +01:00
|
|
|
case Column_RadioService: return service_name_;
|
2010-04-14 23:03:00 +02:00
|
|
|
default: return PlaylistItem::DatabaseValue(column);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-29 20:22:02 +01:00
|
|
|
void RadioPlaylistItem::InitMetadata() {
|
2011-04-27 00:06:58 +02:00
|
|
|
if (metadata_.title().isEmpty())
|
2011-04-28 14:27:53 +02:00
|
|
|
metadata_.set_title(metadata_.url().toString());
|
2010-03-07 23:46:41 +01:00
|
|
|
metadata_.set_filetype(Song::Type_Stream);
|
2011-04-27 00:06:58 +02:00
|
|
|
metadata_.set_valid(true);
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
2009-12-29 20:22:02 +01:00
|
|
|
Song RadioPlaylistItem::Metadata() const {
|
2011-02-03 21:59:53 +01:00
|
|
|
if (!set_service_icon_) {
|
|
|
|
// Get the icon if we don't have it already
|
|
|
|
service();
|
|
|
|
}
|
|
|
|
|
2010-07-10 21:45:29 +02:00
|
|
|
if (HasTemporaryMetadata())
|
2009-12-29 20:22:02 +01:00
|
|
|
return temp_metadata_;
|
|
|
|
return metadata_;
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
2010-03-24 21:58:17 +01:00
|
|
|
QUrl RadioPlaylistItem::Url() const {
|
2011-04-28 14:27:53 +02:00
|
|
|
return metadata_.url();
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
2009-12-26 23:15:57 +01:00
|
|
|
|
2009-12-29 17:12:08 +01:00
|
|
|
PlaylistItem::Options RadioPlaylistItem::options() const {
|
2011-01-15 01:53:39 +01:00
|
|
|
RadioService* s = service();
|
|
|
|
if (!s)
|
2010-05-18 22:43:10 +02:00
|
|
|
return Default;
|
2011-01-15 01:53:39 +01:00
|
|
|
return s->playlistitem_options();
|
2009-12-29 17:12:08 +01:00
|
|
|
}
|