2010-05-20 23:21:55 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-05-20 23:21:55 +02: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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "playlist.h"
|
|
|
|
#include "playlistbackend.h"
|
2011-11-12 17:12:03 +01:00
|
|
|
#include "playlistcontainer.h"
|
2010-05-20 23:21:55 +02:00
|
|
|
#include "playlistmanager.h"
|
2011-11-12 17:12:03 +01:00
|
|
|
#include "playlistview.h"
|
2011-04-28 19:50:45 +02:00
|
|
|
#include "specialplaylisttype.h"
|
2012-02-12 14:41:50 +01:00
|
|
|
#include "core/application.h"
|
2011-04-28 19:50:45 +02:00
|
|
|
#include "core/logging.h"
|
2012-02-12 14:41:50 +01:00
|
|
|
#include "core/player.h"
|
2010-08-03 16:59:18 +02:00
|
|
|
#include "core/songloader.h"
|
2010-06-12 23:20:53 +02:00
|
|
|
#include "core/utilities.h"
|
2010-06-18 16:26:46 +02:00
|
|
|
#include "library/librarybackend.h"
|
|
|
|
#include "library/libraryplaylistitem.h"
|
2010-05-23 00:20:00 +02:00
|
|
|
#include "playlistparsers/playlistparser.h"
|
2010-11-18 21:19:33 +01:00
|
|
|
#include "smartplaylists/generator.h"
|
2010-05-23 00:20:00 +02:00
|
|
|
|
|
|
|
#include <QFileInfo>
|
2010-06-13 14:45:05 +02:00
|
|
|
#include <QtDebug>
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
using smart_playlists::GeneratorPtr;
|
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
PlaylistManager::PlaylistManager(Application* app, QObject *parent)
|
|
|
|
: PlaylistManagerInterface(app, parent),
|
|
|
|
app_(app),
|
2010-05-20 23:21:55 +02:00
|
|
|
playlist_backend_(NULL),
|
|
|
|
library_backend_(NULL),
|
|
|
|
sequence_(NULL),
|
2010-12-11 11:35:07 +01:00
|
|
|
parser_(NULL),
|
2011-04-28 19:50:45 +02:00
|
|
|
default_playlist_type_(new DefaultPlaylistType),
|
2010-05-20 23:21:55 +02:00
|
|
|
current_(-1),
|
|
|
|
active_(-1)
|
|
|
|
{
|
2012-02-12 14:41:50 +01:00
|
|
|
connect(app_->player(), SIGNAL(Paused()), SLOT(SetActivePaused()));
|
|
|
|
connect(app_->player(), SIGNAL(Playing()), SLOT(SetActivePlaying()));
|
|
|
|
connect(app_->player(), SIGNAL(Stopped()), SLOT(SetActiveStopped()));
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
PlaylistManager::~PlaylistManager() {
|
|
|
|
foreach (const Data& data, playlists_.values()) {
|
|
|
|
delete data.p;
|
|
|
|
}
|
2011-04-28 19:50:45 +02:00
|
|
|
|
|
|
|
qDeleteAll(special_playlist_types_.values());
|
|
|
|
delete default_playlist_type_;
|
2010-05-21 12:29:17 +02:00
|
|
|
}
|
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
void PlaylistManager::Init(LibraryBackend* library_backend,
|
|
|
|
PlaylistBackend* playlist_backend,
|
2011-04-28 22:48:53 +02:00
|
|
|
PlaylistSequence* sequence,
|
|
|
|
PlaylistContainer* playlist_container) {
|
2010-05-20 23:21:55 +02:00
|
|
|
library_backend_ = library_backend;
|
|
|
|
playlist_backend_ = playlist_backend;
|
|
|
|
sequence_ = sequence;
|
2010-12-11 11:35:07 +01:00
|
|
|
parser_ = new PlaylistParser(library_backend, this);
|
2011-04-28 22:48:53 +02:00
|
|
|
playlist_container_ = playlist_container;
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-06-18 16:26:46 +02:00
|
|
|
connect(library_backend_, SIGNAL(SongsDiscovered(SongList)), SLOT(SongsDiscovered(SongList)));
|
2010-10-17 21:34:45 +02:00
|
|
|
connect(library_backend_, SIGNAL(SongsStatisticsChanged(SongList)), SLOT(SongsDiscovered(SongList)));
|
2010-06-18 16:26:46 +02:00
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
foreach (const PlaylistBackend::Playlist& p, playlist_backend->GetAllPlaylists()) {
|
2011-04-28 19:50:45 +02:00
|
|
|
AddPlaylist(p.id, p.name, p.special_type);
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// If no playlist exists then make a new one
|
|
|
|
if (playlists_.isEmpty())
|
|
|
|
New(tr("Playlist"));
|
2010-12-07 22:14:40 +01:00
|
|
|
|
|
|
|
emit PlaylistManagerInitialized();
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
|
2011-02-13 19:37:45 +01:00
|
|
|
QList<Playlist*> PlaylistManager::GetAllPlaylists() const {
|
2011-01-17 00:46:58 +01:00
|
|
|
QList<Playlist*> result;
|
|
|
|
|
|
|
|
foreach(const Data& data, playlists_.values()) {
|
|
|
|
result.append(data.p);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-05-29 14:55:18 +02:00
|
|
|
QItemSelection PlaylistManager::selection(int id) const {
|
2011-02-04 12:17:31 +01:00
|
|
|
QMap<int, Data>::const_iterator it = playlists_.find(id);
|
|
|
|
return it->selection;
|
|
|
|
}
|
|
|
|
|
2011-04-28 19:50:45 +02:00
|
|
|
Playlist* PlaylistManager::AddPlaylist(int id, const QString& name,
|
|
|
|
const QString& special_type) {
|
2012-02-12 14:41:50 +01:00
|
|
|
Playlist* ret = new Playlist(playlist_backend_, app_->task_manager(),
|
|
|
|
library_backend_, id, special_type);
|
2010-05-20 23:21:55 +02:00
|
|
|
ret->set_sequence(sequence_);
|
|
|
|
|
|
|
|
connect(ret, SIGNAL(CurrentSongChanged(Song)), SIGNAL(CurrentSongChanged(Song)));
|
2010-12-08 01:09:17 +01:00
|
|
|
connect(ret, SIGNAL(PlaylistChanged()), SLOT(OneOfPlaylistsChanged()));
|
2010-06-12 23:20:53 +02:00
|
|
|
connect(ret, SIGNAL(PlaylistChanged()), SLOT(UpdateSummaryText()));
|
2010-05-20 23:21:55 +02:00
|
|
|
connect(ret, SIGNAL(EditingFinished(QModelIndex)), SIGNAL(EditingFinished(QModelIndex)));
|
2010-06-15 20:24:08 +02:00
|
|
|
connect(ret, SIGNAL(LoadTracksError(QString)), SIGNAL(Error(QString)));
|
|
|
|
connect(ret, SIGNAL(PlayRequested(QModelIndex)), SIGNAL(PlayRequested(QModelIndex)));
|
2011-11-12 17:12:03 +01:00
|
|
|
connect(playlist_container_->view(), SIGNAL(ColumnAlignmentChanged(ColumnAlignmentMap)),
|
|
|
|
ret, SLOT(SetColumnAlignment(ColumnAlignmentMap)));
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
playlists_[id] = Data(ret, name);
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
emit PlaylistAdded(id, name);
|
2010-05-20 23:21:55 +02:00
|
|
|
|
|
|
|
if (current_ == -1) {
|
2010-05-21 12:29:17 +02:00
|
|
|
SetCurrentPlaylist(id);
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
if (active_ == -1) {
|
2010-05-21 12:29:17 +02:00
|
|
|
SetActivePlaylist(id);
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-28 19:50:45 +02:00
|
|
|
void PlaylistManager::New(const QString& name, const SongList& songs,
|
|
|
|
const QString& special_type) {
|
2011-03-20 18:38:15 +01:00
|
|
|
if (name.isNull())
|
|
|
|
return;
|
|
|
|
|
2011-04-28 19:50:45 +02:00
|
|
|
int id = playlist_backend_->CreatePlaylist(name, special_type);
|
2010-05-20 23:21:55 +02:00
|
|
|
|
|
|
|
if (id == -1)
|
|
|
|
qFatal("Couldn't create playlist");
|
|
|
|
|
2011-04-28 19:50:45 +02:00
|
|
|
Playlist* playlist = AddPlaylist(id, name, special_type);
|
2010-12-11 11:35:07 +01:00
|
|
|
playlist->InsertSongsOrLibraryItems(songs);
|
2010-05-22 22:28:11 +02:00
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
SetCurrentPlaylist(id);
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistManager::Load(const QString& filename) {
|
2010-08-03 16:59:18 +02:00
|
|
|
QUrl url = QUrl::fromLocalFile(filename);
|
2010-08-31 21:45:33 +02:00
|
|
|
SongLoader* loader = new SongLoader(library_backend_, this);
|
2010-08-03 16:59:18 +02:00
|
|
|
connect(loader, SIGNAL(LoadFinished(bool)), SLOT(LoadFinished(bool)));
|
|
|
|
SongLoader::Result result = loader->Load(url);
|
2010-05-23 00:20:00 +02:00
|
|
|
QFileInfo info(filename);
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-08-03 16:59:18 +02:00
|
|
|
if (result == SongLoader::Error ||
|
|
|
|
(result == SongLoader::Success && loader->songs().isEmpty())) {
|
2012-02-12 14:41:50 +01:00
|
|
|
app_->AddError(tr("The playlist '%1' was empty or could not be loaded.").arg(
|
2010-05-23 00:20:00 +02:00
|
|
|
info.completeBaseName()));
|
2010-08-03 16:59:18 +02:00
|
|
|
delete loader;
|
2010-05-23 00:20:00 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-03 16:59:18 +02:00
|
|
|
if (result == SongLoader::Success) {
|
|
|
|
New(info.baseName(), loader->songs());
|
|
|
|
delete loader;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistManager::LoadFinished(bool success) {
|
|
|
|
SongLoader* loader = qobject_cast<SongLoader*>(sender());
|
|
|
|
loader->deleteLater();
|
|
|
|
QString localfile = loader->url().toLocalFile();
|
|
|
|
QFileInfo info(localfile);
|
|
|
|
if (!success || loader->songs().isEmpty()) {
|
2012-02-12 14:41:50 +01:00
|
|
|
app_->AddError(tr("The playlist '%1' was empty or could not be loaded.").arg(
|
2010-08-03 16:59:18 +02:00
|
|
|
info.completeBaseName()));
|
|
|
|
}
|
|
|
|
|
|
|
|
New(info.baseName(), loader->songs());
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
void PlaylistManager::Save(int id, const QString& filename) {
|
|
|
|
Q_ASSERT(playlists_.contains(id));
|
2010-05-23 00:20:00 +02:00
|
|
|
|
|
|
|
parser_->Save(playlist(id)->GetAllSongs(), filename);
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
void PlaylistManager::Rename(int id, const QString& new_name) {
|
|
|
|
Q_ASSERT(playlists_.contains(id));
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
playlist_backend_->RenamePlaylist(id, new_name);
|
|
|
|
playlists_[id].name = new_name;
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
emit PlaylistRenamed(id, new_name);
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
void PlaylistManager::Remove(int id) {
|
|
|
|
Q_ASSERT(playlists_.contains(id));
|
2010-05-20 23:21:55 +02:00
|
|
|
|
|
|
|
// Won't allow removing the last playlist
|
|
|
|
if (playlists_.count() <= 1)
|
|
|
|
return;
|
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
playlist_backend_->RemovePlaylist(id);
|
|
|
|
|
2010-12-18 20:37:29 +01:00
|
|
|
int next_id = -1;
|
|
|
|
foreach (int possible_next_id, playlists_.keys()) {
|
|
|
|
if (possible_next_id != id) {
|
|
|
|
next_id = possible_next_id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (next_id == -1)
|
|
|
|
return;
|
2010-05-21 12:29:17 +02:00
|
|
|
|
|
|
|
if (id == active_)
|
|
|
|
SetActivePlaylist(next_id);
|
|
|
|
if (id == current_)
|
|
|
|
SetCurrentPlaylist(next_id);
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
Data data = playlists_.take(id);
|
|
|
|
delete data.p;
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
emit PlaylistRemoved(id);
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
|
2010-12-08 01:09:17 +01:00
|
|
|
void PlaylistManager::OneOfPlaylistsChanged() {
|
|
|
|
emit PlaylistChanged(qobject_cast<Playlist*>(sender()));
|
|
|
|
}
|
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
void PlaylistManager::SetCurrentPlaylist(int id) {
|
|
|
|
Q_ASSERT(playlists_.contains(id));
|
|
|
|
current_ = id;
|
2010-05-20 23:21:55 +02:00
|
|
|
emit CurrentChanged(current());
|
2010-06-12 23:20:53 +02:00
|
|
|
UpdateSummaryText();
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
void PlaylistManager::SetActivePlaylist(int id) {
|
|
|
|
Q_ASSERT(playlists_.contains(id));
|
2010-05-20 23:51:01 +02:00
|
|
|
|
|
|
|
// Kinda a hack: unset the current item from the old active playlist before
|
|
|
|
// setting the new one
|
2010-06-17 19:43:58 +02:00
|
|
|
if (active_ != -1 && active_ != id)
|
2010-12-17 01:21:20 +01:00
|
|
|
active()->set_current_row(-1);
|
2010-05-20 23:51:01 +02:00
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
active_ = id;
|
|
|
|
emit ActiveChanged(active());
|
2010-11-20 19:49:54 +01:00
|
|
|
|
|
|
|
sequence_->SetUsingDynamicPlaylist(active()->is_dynamic());
|
2010-05-20 23:21:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistManager::ClearCurrent() {
|
|
|
|
current()->Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistManager::ShuffleCurrent() {
|
|
|
|
current()->Shuffle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistManager::SetActivePlaying() {
|
|
|
|
active()->Playing();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistManager::SetActivePaused() {
|
|
|
|
active()->Paused();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistManager::SetActiveStopped() {
|
|
|
|
active()->Stopped();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistManager::SetActiveStreamMetadata(const QUrl &url, const Song &song) {
|
|
|
|
active()->SetStreamMetadata(url, song);
|
|
|
|
}
|
2010-05-21 12:37:24 +02:00
|
|
|
|
2010-12-17 01:21:20 +01:00
|
|
|
void PlaylistManager::RateCurrentSong(double rating) {
|
|
|
|
active()->RateSong(active()->current_index(), rating);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistManager::RateCurrentSong(int rating) {
|
|
|
|
RateCurrentSong(rating / 5.0);
|
|
|
|
}
|
|
|
|
|
2010-05-21 12:37:24 +02:00
|
|
|
void PlaylistManager::ChangePlaylistOrder(const QList<int>& ids) {
|
|
|
|
playlist_backend_->SetPlaylistOrder(ids);
|
|
|
|
}
|
2010-06-12 23:20:53 +02:00
|
|
|
|
|
|
|
void PlaylistManager::UpdateSummaryText() {
|
|
|
|
int tracks = current()->rowCount();
|
2011-02-13 19:34:30 +01:00
|
|
|
quint64 nanoseconds = 0;
|
2010-06-13 14:45:05 +02:00
|
|
|
int selected = 0;
|
|
|
|
|
|
|
|
// Get the length of the selected tracks
|
2010-09-25 17:30:47 +02:00
|
|
|
foreach (const QItemSelectionRange& range, playlists_[current_id()].selection) {
|
2010-06-18 18:06:51 +02:00
|
|
|
if (!range.isValid())
|
|
|
|
continue;
|
|
|
|
|
2010-06-13 14:45:05 +02:00
|
|
|
selected += range.bottom() - range.top() + 1;
|
|
|
|
for (int i=range.top() ; i<=range.bottom() ; ++i) {
|
2011-03-04 22:10:06 +01:00
|
|
|
qint64 length = range.model()->index(i, Playlist::Column_Length).data().toLongLong();
|
2010-06-18 17:32:52 +02:00
|
|
|
if (length > 0)
|
2011-02-13 19:34:30 +01:00
|
|
|
nanoseconds += length;
|
2010-06-13 14:45:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString summary;
|
|
|
|
if (selected > 1) {
|
|
|
|
summary += tr("%1 selected of").arg(selected) + " ";
|
|
|
|
} else {
|
2011-02-13 19:34:30 +01:00
|
|
|
nanoseconds = current()->GetTotalLength();
|
2010-06-13 14:45:05 +02:00
|
|
|
}
|
2010-06-12 23:20:53 +02:00
|
|
|
|
|
|
|
// TODO: Make the plurals translatable
|
2010-06-13 14:45:05 +02:00
|
|
|
summary += tracks == 1 ? tr("1 track") : tr("%1 tracks").arg(tracks);
|
2010-06-12 23:20:53 +02:00
|
|
|
|
2011-02-13 19:34:30 +01:00
|
|
|
if (nanoseconds)
|
|
|
|
summary += " - [ " + Utilities::WordyTimeNanosec(nanoseconds) + " ]";
|
2010-06-12 23:20:53 +02:00
|
|
|
|
|
|
|
emit SummaryTextChanged(summary);
|
|
|
|
}
|
2010-06-13 14:45:05 +02:00
|
|
|
|
2010-09-25 17:30:47 +02:00
|
|
|
void PlaylistManager::SelectionChanged(const QItemSelection& selection) {
|
|
|
|
playlists_[current_id()].selection = selection;
|
2010-06-13 14:45:05 +02:00
|
|
|
UpdateSummaryText();
|
|
|
|
}
|
2010-06-18 16:26:46 +02:00
|
|
|
|
|
|
|
void PlaylistManager::SongsDiscovered(const SongList& songs) {
|
|
|
|
// Some songs might've changed in the library, let's update any playlist
|
|
|
|
// items we have that match those songs
|
|
|
|
|
|
|
|
foreach (const Song& song, songs) {
|
|
|
|
foreach (const Data& data, playlists_) {
|
|
|
|
PlaylistItemList items = data.p->library_items_by_id(song.id());
|
2010-10-16 17:22:14 +02:00
|
|
|
foreach (PlaylistItemPtr item, items) {
|
2010-06-25 00:21:54 +02:00
|
|
|
if (item->Metadata().directory_id() != song.directory_id())
|
|
|
|
continue;
|
2010-06-18 16:26:46 +02:00
|
|
|
static_cast<LibraryPlaylistItem*>(item.get())->SetMetadata(song);
|
2010-10-23 22:58:20 +02:00
|
|
|
data.p->ItemChanged(item);
|
2010-06-18 16:26:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-24 17:38:12 +02:00
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
void PlaylistManager::PlaySmartPlaylist(GeneratorPtr generator, bool as_new, bool clear) {
|
2010-10-24 17:38:12 +02:00
|
|
|
if (as_new) {
|
|
|
|
New(generator->name());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clear) {
|
|
|
|
current()->Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
current()->InsertSmartPlaylist(generator);
|
|
|
|
}
|
2011-03-10 19:01:35 +01:00
|
|
|
|
|
|
|
// When Player has processed the new song chosen by the user...
|
|
|
|
void PlaylistManager::SongChangeRequestProcessed(const QUrl& url, bool valid) {
|
|
|
|
foreach(Playlist* playlist, GetAllPlaylists()) {
|
2011-03-19 10:41:00 +01:00
|
|
|
if(playlist->ApplyValidityOnCurrentSong(url, valid)) {
|
|
|
|
return;
|
2011-03-10 19:01:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-19 10:41:00 +01:00
|
|
|
|
|
|
|
void PlaylistManager::InvalidateDeletedSongs() {
|
|
|
|
foreach(Playlist* playlist, GetAllPlaylists()) {
|
|
|
|
playlist->InvalidateDeletedSongs();
|
|
|
|
}
|
|
|
|
}
|
2011-03-25 20:16:12 +01:00
|
|
|
|
2011-04-21 23:56:37 +02:00
|
|
|
void PlaylistManager::RemoveDeletedSongs() {
|
|
|
|
foreach(Playlist* playlist, GetAllPlaylists()) {
|
|
|
|
playlist->RemoveDeletedSongs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-25 20:16:12 +01:00
|
|
|
QString PlaylistManager::GetNameForNewPlaylist(const SongList& songs) {
|
|
|
|
if (songs.isEmpty()) {
|
|
|
|
return tr("Playlist");
|
|
|
|
}
|
|
|
|
|
|
|
|
QSet<QString> artists;
|
|
|
|
QSet<QString> albums;
|
|
|
|
|
|
|
|
foreach(const Song& song, songs) {
|
|
|
|
artists << (song.artist().isEmpty()
|
|
|
|
? tr("Unknown")
|
|
|
|
: song.artist());
|
|
|
|
albums << (song.album().isEmpty()
|
|
|
|
? tr("Unknown")
|
|
|
|
: song.album());
|
|
|
|
|
|
|
|
if(artists.size() > 1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool various_artists = artists.size() > 1;
|
|
|
|
|
|
|
|
QString result;
|
|
|
|
if(various_artists) {
|
|
|
|
result = tr("Various artists");
|
|
|
|
} else {
|
|
|
|
result = artists.values().first();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!various_artists && albums.size() == 1) {
|
|
|
|
result += " - " + albums.toList().first();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2011-04-28 19:50:45 +02:00
|
|
|
|
|
|
|
void PlaylistManager::RegisterSpecialPlaylistType(SpecialPlaylistType* type) {
|
|
|
|
const QString name = type->name();
|
|
|
|
|
|
|
|
if (special_playlist_types_.contains(name)) {
|
|
|
|
qLog(Warning) << "Tried to register a special playlist type" << name
|
|
|
|
<< "but one was already registered";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qLog(Info) << "Registered special playlist type" << name;
|
|
|
|
special_playlist_types_.insert(name, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistManager::UnregisterSpecialPlaylistType(SpecialPlaylistType* type) {
|
|
|
|
const QString name = special_playlist_types_.key(type);
|
|
|
|
if (name.isEmpty()) {
|
|
|
|
qLog(Warning) << "Tried to unregister a special playlist type" << type->name()
|
|
|
|
<< "that wasn't registered";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qLog(Info) << "Unregistered special playlist type" << name;
|
|
|
|
special_playlist_types_.remove(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
SpecialPlaylistType* PlaylistManager::GetPlaylistType(const QString& type) const {
|
|
|
|
if (special_playlist_types_.contains(type)) {
|
|
|
|
return special_playlist_types_[type];
|
|
|
|
}
|
|
|
|
return default_playlist_type_;
|
|
|
|
}
|