1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-15 18:58:55 +01:00
Clementine-audio-player-Mac.../src/radioplaylistitem.cpp

94 lines
2.2 KiB
C++
Raw Normal View History

2009-12-26 22:35:45 +01:00
#include "radioplaylistitem.h"
#include "radioservice.h"
#include "radiomodel.h"
#include <QSettings>
2010-02-23 19:33:09 +01:00
#include <QApplication>
2009-12-26 22:35:45 +01:00
RadioPlaylistItem::RadioPlaylistItem()
: service_(NULL)
{
}
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)
2009-12-26 22:35:45 +01:00
: 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
}
void RadioPlaylistItem::Save(QSettings& settings) const {
settings.setValue("service", service_->name());
settings.setValue("url", url_.toString());
2009-12-26 23:15:57 +01:00
settings.setValue("title", title_);
2010-02-03 23:20:31 +01:00
settings.setValue("artist", artist_);
2009-12-26 22:35:45 +01:00
}
void RadioPlaylistItem::Restore(const QSettings& settings) {
service_ = RadioModel::ServiceByName(settings.value("service").toString());
url_ = settings.value("url").toString();
2009-12-26 23:15:57 +01:00
title_ = settings.value("title").toString();
2010-01-18 03:23:55 +01:00
artist_ = settings.value("artist").toString();
2009-12-26 23:15:57 +01:00
2009-12-29 20:22:02 +01:00
InitMetadata();
2009-12-26 22:35:45 +01:00
}
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_);
metadata_.set_filetype(Song::Type_Stream);
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_)
service_->LoadNext(url_);
}
2009-12-26 22:35:45 +01:00
QUrl RadioPlaylistItem::Url() {
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;
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
}