2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
|
|
|
|
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"
|
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),
|
|
|
|
service_(NULL)
|
2009-12-26 22:35:45 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-12-26 23:15:57 +01:00
|
|
|
RadioPlaylistItem::RadioPlaylistItem(RadioService* service, const QUrl& url,
|
2010-01-18 03:23:55 +01:00
|
|
|
const QString& title, const QString& artist)
|
2010-04-14 23:03:00 +02:00
|
|
|
: PlaylistItem("Radio"),
|
|
|
|
service_(service),
|
2009-12-26 23:15:57 +01:00
|
|
|
url_(url),
|
2010-01-18 03:23:55 +01:00
|
|
|
title_(title),
|
|
|
|
artist_(artist)
|
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-04-27 19:37:26 +02:00
|
|
|
bool RadioPlaylistItem::InitFromQuery(const QSqlQuery &query) {
|
2010-05-10 16:19:43 +02:00
|
|
|
// The song tables gets joined first, plus one each for the song ROWIDs
|
|
|
|
const int row = (Song::kColumns.count() + 1) * 2;
|
2010-04-14 23:03:00 +02:00
|
|
|
|
|
|
|
url_ = query.value(row + 1).toString();
|
|
|
|
title_ = query.value(row + 2).toString();
|
|
|
|
artist_ = query.value(row + 3).toString();
|
|
|
|
QString service(query.value(row + 6).toString());
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2010-04-14 23:03:00 +02:00
|
|
|
service_ = RadioModel::ServiceByName(service);
|
2009-12-26 23:15:57 +01:00
|
|
|
|
2009-12-29 20:22:02 +01:00
|
|
|
InitMetadata();
|
2010-04-27 19:37:26 +02:00
|
|
|
return true;
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
2010-04-14 23:03:00 +02:00
|
|
|
QVariant RadioPlaylistItem::DatabaseValue(DatabaseColumn column) const {
|
|
|
|
switch (column) {
|
|
|
|
case Column_Url: return url_.toString();
|
|
|
|
case Column_Title: return title_;
|
|
|
|
case Column_Artist: return artist_;
|
|
|
|
case Column_RadioService: return service_->name();
|
|
|
|
default: return PlaylistItem::DatabaseValue(column);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-29 20:22:02 +01:00
|
|
|
void RadioPlaylistItem::InitMetadata() {
|
|
|
|
if (!service_)
|
2010-02-23 19:33:09 +01:00
|
|
|
metadata_.set_title(QApplication::translate("RadioPlaylistItem", "Radio service couldn't be loaded :-("));
|
2009-12-29 20:22:02 +01:00
|
|
|
else if (!title_.isEmpty())
|
|
|
|
metadata_.set_title(title_);
|
|
|
|
else
|
|
|
|
metadata_.set_title(url_.toString());
|
2010-01-18 03:23:55 +01:00
|
|
|
|
|
|
|
metadata_.set_artist(artist_);
|
2010-03-07 23:46:41 +01:00
|
|
|
metadata_.set_filetype(Song::Type_Stream);
|
2010-03-25 19:38:20 +01:00
|
|
|
|
|
|
|
if (service_) {
|
|
|
|
QString icon = service_->Icon();
|
|
|
|
if (!icon.isEmpty()) {
|
|
|
|
metadata_.set_art_manual(icon);
|
|
|
|
}
|
|
|
|
}
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
2009-12-29 20:22:02 +01:00
|
|
|
Song RadioPlaylistItem::Metadata() const {
|
|
|
|
if (temp_metadata_.is_valid())
|
|
|
|
return temp_metadata_;
|
|
|
|
return metadata_;
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
2009-12-29 17:12:08 +01:00
|
|
|
void RadioPlaylistItem::StartLoading() {
|
2009-12-26 22:35:45 +01:00
|
|
|
if (service_)
|
|
|
|
service_->StartLoading(url_);
|
|
|
|
}
|
|
|
|
|
2009-12-29 17:12:08 +01:00
|
|
|
void RadioPlaylistItem::LoadNext() {
|
|
|
|
if (service_)
|
2009-12-26 23:59:11 +01:00
|
|
|
service_->LoadNext(url_);
|
|
|
|
}
|
|
|
|
|
2010-03-24 21:58:17 +01:00
|
|
|
QUrl RadioPlaylistItem::Url() const {
|
2009-12-26 22:35:45 +01:00
|
|
|
return url_;
|
|
|
|
}
|
2009-12-26 23:15:57 +01:00
|
|
|
|
2009-12-29 17:12:08 +01:00
|
|
|
PlaylistItem::Options RadioPlaylistItem::options() const {
|
|
|
|
PlaylistItem::Options ret = SpecialPlayBehaviour;
|
|
|
|
|
|
|
|
if (service_) {
|
|
|
|
ret |= ContainsMultipleTracks;
|
|
|
|
|
|
|
|
if (!service_->IsPauseAllowed())
|
|
|
|
ret |= PauseDisabled;
|
|
|
|
if (service_->ShowLastFmControls())
|
|
|
|
ret |= LastFMControls;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-26 23:15:57 +01:00
|
|
|
void RadioPlaylistItem::SetTemporaryMetadata(const Song& metadata) {
|
2009-12-29 20:22:02 +01:00
|
|
|
temp_metadata_ = metadata;
|
2010-03-07 23:46:41 +01:00
|
|
|
temp_metadata_.set_filetype(Song::Type_Stream);
|
2009-12-26 23:15:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RadioPlaylistItem::ClearTemporaryMetadata() {
|
2009-12-29 20:22:02 +01:00
|
|
|
temp_metadata_ = Song();
|
2009-12-26 23:15:57 +01:00
|
|
|
}
|