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-24 20:16:07 +01:00
|
|
|
#include "songplaylistitem.h"
|
2010-04-14 16:48:10 +02:00
|
|
|
#include "settingsprovider.h"
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
#include <QtDebug>
|
2010-03-10 22:39:25 +01:00
|
|
|
#include <QFile>
|
2009-12-24 20:16:07 +01:00
|
|
|
#include <QSettings>
|
|
|
|
|
|
|
|
SongPlaylistItem::SongPlaylistItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SongPlaylistItem::SongPlaylistItem(const Song& song)
|
|
|
|
: song_(song)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-04-14 18:12:33 +02:00
|
|
|
void SongPlaylistItem::Save(SettingsProvider* settings) const {
|
|
|
|
settings->setValue("filename", song_.filename());
|
|
|
|
settings->setValue("art_automatic", song_.art_automatic());
|
|
|
|
settings->setValue("art_manual", song_.art_manual());
|
2010-03-10 22:39:25 +01:00
|
|
|
|
|
|
|
if (song_.filetype() == Song::Type_Stream) {
|
|
|
|
SaveStream(settings);
|
|
|
|
} else {
|
|
|
|
SaveFile(settings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-14 18:12:33 +02:00
|
|
|
void SongPlaylistItem::SaveFile(SettingsProvider* settings) const {
|
|
|
|
settings->setValue("stream", false);
|
|
|
|
settings->setValue("library_directory", song_.directory_id());
|
2010-03-10 22:39:25 +01:00
|
|
|
}
|
|
|
|
|
2010-04-14 18:12:33 +02:00
|
|
|
void SongPlaylistItem::SaveStream(SettingsProvider* settings) const {
|
|
|
|
settings->setValue("stream", true);
|
|
|
|
settings->setValue("title", song_.title());
|
|
|
|
settings->setValue("artist", song_.artist());
|
|
|
|
settings->setValue("album", song_.album());
|
|
|
|
settings->setValue("length", song_.length());
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2010-04-14 16:48:10 +02:00
|
|
|
void SongPlaylistItem::Restore(const SettingsProvider& settings) {
|
2010-03-10 22:39:25 +01:00
|
|
|
song_.set_art_automatic(settings.value("art_automatic").toString());
|
|
|
|
song_.set_art_manual(settings.value("art_manual").toString());
|
|
|
|
|
|
|
|
const bool stream = settings.value("stream", false).toBool();
|
|
|
|
if (stream) {
|
|
|
|
RestoreStream(settings);
|
|
|
|
} else {
|
|
|
|
RestoreFile(settings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-14 16:48:10 +02:00
|
|
|
void SongPlaylistItem::RestoreFile(const SettingsProvider& settings) {
|
2009-12-24 20:16:07 +01:00
|
|
|
QString filename(settings.value("filename").toString());
|
|
|
|
|
2010-03-10 22:39:25 +01:00
|
|
|
int directory_id(settings.value("library_directory", -1).toInt());
|
2009-12-24 20:16:07 +01:00
|
|
|
song_.InitFromFile(filename, directory_id);
|
2010-03-10 22:39:25 +01:00
|
|
|
}
|
|
|
|
|
2010-04-14 16:48:10 +02:00
|
|
|
void SongPlaylistItem::RestoreStream(const SettingsProvider& settings) {
|
2010-03-10 22:39:25 +01:00
|
|
|
QString filename(settings.value("filename").toString());
|
|
|
|
song_.set_filename(filename);
|
|
|
|
song_.set_filetype(Song::Type_Stream);
|
|
|
|
|
|
|
|
song_.Init(settings.value("title", "Unknown").toString(),
|
|
|
|
settings.value("artist", "Unknown").toString(),
|
|
|
|
settings.value("album", "Unknown").toString(),
|
|
|
|
settings.value("length", -1).toInt());
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2010-03-24 21:58:17 +01:00
|
|
|
QUrl SongPlaylistItem::Url() const {
|
2010-03-10 22:39:25 +01:00
|
|
|
if (QFile::exists(song_.filename())) {
|
|
|
|
return QUrl::fromLocalFile(song_.filename());
|
|
|
|
} else {
|
|
|
|
return song_.filename();
|
|
|
|
}
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
2010-01-16 17:12:47 +01:00
|
|
|
|
|
|
|
void SongPlaylistItem::Reload() {
|
|
|
|
song_.InitFromFile(song_.filename(), song_.directory_id());
|
|
|
|
}
|