1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
3
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
4
* Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
6
* Tomahawk is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* Tomahawk is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
20
#include "Collection.h"
24
#include "utils/Logger.h"
25
#include "playlist/PlaylistUpdaterInterface.h"
27
#include <QMetaObject>
28
#include <QGenericArgument>
30
using namespace Tomahawk;
33
Collection::Collection( const source_ptr& source, const QString& name, QObject* parent )
40
qDebug() << Q_FUNC_INFO << name << source->friendlyName();
42
connect( source.data(), SIGNAL( synced() ), SLOT( onSynced() ) );
46
Collection::~Collection()
48
qDebug() << Q_FUNC_INFO;
53
Collection::name() const
60
source_ptr& Collection::source() const
67
Collection::addPlaylist( const Tomahawk::playlist_ptr& p )
69
if ( m_playlists.contains( p->guid() ) )
72
QList<playlist_ptr> toadd;
74
m_playlists.insert( p->guid(), p );
76
/* qDebug() << Q_FUNC_INFO << "Collection name" << name()
77
<< "from source id" << source()->id()
78
<< "numplaylists:" << m_playlists.count();*/
79
emit playlistsAdded( toadd );
84
Collection::addAutoPlaylist( const Tomahawk::dynplaylist_ptr& p )
86
QList<dynplaylist_ptr> toadd;
88
m_autoplaylists.insert( p->guid(), p );
90
/* qDebug() << Q_FUNC_INFO << "Collection name" << name()
91
<< "from source id" << source()->id()
92
<< "numplaylists:" << m_playlists.count();*/
93
emit autoPlaylistsAdded( toadd );
98
Collection::addStation( const dynplaylist_ptr& s )
100
QList<dynplaylist_ptr> toadd;
102
m_stations.insert( s->guid(), s );
104
/* qDebug() << Q_FUNC_INFO << "Collection name" << name()
105
<< "from source id" << source()->id()
106
<< "numplaylists:" << m_playlists.count();*/
107
emit stationsAdded( toadd );
112
Collection::deletePlaylist( const Tomahawk::playlist_ptr& p )
114
QList<playlist_ptr> todelete;
116
m_playlists.remove( p->guid() );
118
/* qDebug() << Q_FUNC_INFO << "Collection name" << name()
119
<< "from source id" << source()->id()
120
<< "numplaylists:" << m_playlists.count();*/
121
emit playlistsDeleted( todelete );
126
Collection::deleteAutoPlaylist( const Tomahawk::dynplaylist_ptr& p )
128
QList<dynplaylist_ptr> todelete;
130
m_autoplaylists.remove( p->guid() );
132
/* qDebug() << Q_FUNC_INFO << "Collection name" << name()
133
<< "from source id" << source()->id()
134
<< "numplaylists:" << m_playlists.count();*/
135
emit autoPlaylistsDeleted( todelete );
140
Collection::deleteStation( const dynplaylist_ptr& s )
142
QList<dynplaylist_ptr> todelete;
144
m_stations.remove( s->guid() );
146
/* qDebug() << Q_FUNC_INFO << "Collection name" << name()
147
<< "from source id" << source()->id()
148
<< "numplaylists:" << m_playlists.count();*/
149
emit stationsDeleted( todelete );
153
Tomahawk::playlist_ptr
154
Collection::playlist( const QString& guid )
156
return m_playlists.value( guid, Tomahawk::playlist_ptr() );
160
Tomahawk::dynplaylist_ptr
161
Collection::autoPlaylist( const QString& guid )
163
return m_autoplaylists.value( guid, Tomahawk::dynplaylist_ptr() );
167
Tomahawk::dynplaylist_ptr
168
Collection::station( const QString& guid )
170
return m_stations.value( guid, Tomahawk::dynplaylist_ptr() );
175
Collection::setPlaylists( const QList<Tomahawk::playlist_ptr>& plists )
177
foreach ( const playlist_ptr& p, plists )
179
// qDebug() << "Batch inserting playlist:" << p->guid();
180
m_playlists.insert( p->guid(), p );
181
if ( !m_source.isNull() && m_source->isLocal() )
182
PlaylistUpdaterInterface::loadForPlaylist( p );
184
emit playlistsAdded( plists );
189
Collection::setAutoPlaylists( const QList< Tomahawk::dynplaylist_ptr >& plists )
191
foreach ( const dynplaylist_ptr& p, plists )
193
// qDebug() << "Batch inserting dynamic playlist:" << p->guid();
194
m_autoplaylists.insert( p->guid(), p );
196
emit autoPlaylistsAdded( plists );
201
Collection::setStations( const QList< dynplaylist_ptr >& stations )
203
foreach ( const dynplaylist_ptr& s, stations )
205
// qDebug() << "Batch inserting station:" << s->guid();
206
m_stations.insert( s->guid(), s );
208
emit autoPlaylistsAdded( stations );
213
Collection::setTracks( const QList<unsigned int>& ids )
215
tDebug() << Q_FUNC_INFO << ids.count() << name();
218
emit tracksAdded( ids );
223
Collection::delTracks( const QList<unsigned int>& ids )
225
tDebug() << Q_FUNC_INFO << ids.count() << name();
228
emit tracksRemoved( ids );
233
Collection::onSynced()
235
tDebug() << Q_FUNC_INFO << m_changed;
245
Collection::moveAutoToStation( const QString& guid )
247
if ( m_autoplaylists.contains( guid ) )
248
m_stations.insert( guid, m_autoplaylists.take( guid ) );
253
Collection::moveStationToAuto( const QString& guid )
255
if ( m_stations.contains( guid ) )
256
m_autoplaylists.insert( guid, m_stations.take( guid ) );