~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/libtomahawk/Collection.cpp

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 
2
 *
 
3
 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
 
4
 *   Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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/>.
 
18
 */
 
19
 
 
20
#include "Collection.h"
 
21
 
 
22
#include "Source.h"
 
23
 
 
24
#include "utils/Logger.h"
 
25
#include "playlist/PlaylistUpdaterInterface.h"
 
26
 
 
27
#include <QMetaObject>
 
28
#include <QGenericArgument>
 
29
 
 
30
using namespace Tomahawk;
 
31
 
 
32
 
 
33
Collection::Collection( const source_ptr& source, const QString& name, QObject* parent )
 
34
    : QObject( parent )
 
35
    , m_name( name )
 
36
    , m_lastmodified( 0 )
 
37
    , m_changed( false )
 
38
    , m_source( source )
 
39
{
 
40
    qDebug() << Q_FUNC_INFO << name << source->friendlyName();
 
41
 
 
42
    connect( source.data(), SIGNAL( synced() ), SLOT( onSynced() ) );
 
43
}
 
44
 
 
45
 
 
46
Collection::~Collection()
 
47
{
 
48
    qDebug() << Q_FUNC_INFO;
 
49
}
 
50
 
 
51
 
 
52
QString
 
53
Collection::name() const
 
54
{
 
55
    return m_name;
 
56
}
 
57
 
 
58
 
 
59
const
 
60
source_ptr& Collection::source() const
 
61
{
 
62
    return m_source;
 
63
}
 
64
 
 
65
 
 
66
void
 
67
Collection::addPlaylist( const Tomahawk::playlist_ptr& p )
 
68
{
 
69
    if ( m_playlists.contains( p->guid() ) )
 
70
        return;
 
71
 
 
72
    QList<playlist_ptr> toadd;
 
73
    toadd << p;
 
74
    m_playlists.insert( p->guid(), p );
 
75
 
 
76
/*    qDebug() << Q_FUNC_INFO << "Collection name" << name()
 
77
                            << "from source id" << source()->id()
 
78
                            << "numplaylists:" << m_playlists.count();*/
 
79
    emit playlistsAdded( toadd );
 
80
}
 
81
 
 
82
 
 
83
void
 
84
Collection::addAutoPlaylist( const Tomahawk::dynplaylist_ptr& p )
 
85
{
 
86
    QList<dynplaylist_ptr> toadd;
 
87
    toadd << p;
 
88
    m_autoplaylists.insert( p->guid(), p );
 
89
 
 
90
/*    qDebug() << Q_FUNC_INFO << "Collection name" << name()
 
91
                            << "from source id" << source()->id()
 
92
                            << "numplaylists:" << m_playlists.count();*/
 
93
    emit autoPlaylistsAdded( toadd );
 
94
}
 
95
 
 
96
 
 
97
void
 
98
Collection::addStation( const dynplaylist_ptr& s )
 
99
{
 
100
    QList<dynplaylist_ptr> toadd;
 
101
    toadd << s;
 
102
    m_stations.insert( s->guid(), s );
 
103
 
 
104
/*    qDebug() << Q_FUNC_INFO << "Collection name" << name()
 
105
                            << "from source id" << source()->id()
 
106
                            << "numplaylists:" << m_playlists.count();*/
 
107
    emit stationsAdded( toadd );
 
108
}
 
109
 
 
110
 
 
111
void
 
112
Collection::deletePlaylist( const Tomahawk::playlist_ptr& p )
 
113
{
 
114
    QList<playlist_ptr> todelete;
 
115
    todelete << p;
 
116
    m_playlists.remove( p->guid() );
 
117
 
 
118
/*    qDebug() << Q_FUNC_INFO << "Collection name" << name()
 
119
                            << "from source id" << source()->id()
 
120
                            << "numplaylists:" << m_playlists.count();*/
 
121
    emit playlistsDeleted( todelete );
 
122
}
 
123
 
 
124
 
 
125
void
 
126
Collection::deleteAutoPlaylist( const Tomahawk::dynplaylist_ptr& p )
 
127
{
 
128
    QList<dynplaylist_ptr> todelete;
 
129
    todelete << p;
 
130
    m_autoplaylists.remove( p->guid() );
 
131
 
 
132
/*    qDebug() << Q_FUNC_INFO << "Collection name" << name()
 
133
                            << "from source id" << source()->id()
 
134
                            << "numplaylists:" << m_playlists.count();*/
 
135
    emit autoPlaylistsDeleted( todelete );
 
136
}
 
137
 
 
138
 
 
139
void
 
140
Collection::deleteStation( const dynplaylist_ptr& s )
 
141
{
 
142
    QList<dynplaylist_ptr> todelete;
 
143
    todelete << s;
 
144
    m_stations.remove( s->guid() );
 
145
 
 
146
/*    qDebug() << Q_FUNC_INFO << "Collection name" << name()
 
147
                            << "from source id" << source()->id()
 
148
                            << "numplaylists:" << m_playlists.count();*/
 
149
    emit stationsDeleted( todelete );
 
150
}
 
151
 
 
152
 
 
153
Tomahawk::playlist_ptr
 
154
Collection::playlist( const QString& guid )
 
155
{
 
156
    return m_playlists.value( guid, Tomahawk::playlist_ptr() );
 
157
}
 
158
 
 
159
 
 
160
Tomahawk::dynplaylist_ptr
 
161
Collection::autoPlaylist( const QString& guid )
 
162
{
 
163
    return m_autoplaylists.value( guid, Tomahawk::dynplaylist_ptr() );
 
164
}
 
165
 
 
166
 
 
167
Tomahawk::dynplaylist_ptr
 
168
Collection::station( const QString& guid )
 
169
{
 
170
    return m_stations.value( guid, Tomahawk::dynplaylist_ptr() );
 
171
}
 
172
 
 
173
 
 
174
void
 
175
Collection::setPlaylists( const QList<Tomahawk::playlist_ptr>& plists )
 
176
{
 
177
    foreach ( const playlist_ptr& p, plists )
 
178
    {
 
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 );
 
183
    }
 
184
    emit playlistsAdded( plists );
 
185
}
 
186
 
 
187
 
 
188
void
 
189
Collection::setAutoPlaylists( const QList< Tomahawk::dynplaylist_ptr >& plists )
 
190
{
 
191
    foreach ( const dynplaylist_ptr& p, plists )
 
192
    {
 
193
//        qDebug() << "Batch inserting dynamic playlist:" << p->guid();
 
194
        m_autoplaylists.insert( p->guid(), p );
 
195
    }
 
196
    emit autoPlaylistsAdded( plists );
 
197
}
 
198
 
 
199
 
 
200
void
 
201
Collection::setStations( const QList< dynplaylist_ptr >& stations )
 
202
{
 
203
    foreach ( const dynplaylist_ptr& s, stations )
 
204
    {
 
205
//        qDebug() << "Batch inserting station:" << s->guid();
 
206
        m_stations.insert( s->guid(), s );
 
207
    }
 
208
    emit autoPlaylistsAdded( stations );
 
209
}
 
210
 
 
211
 
 
212
void
 
213
Collection::setTracks( const QList<unsigned int>& ids )
 
214
{
 
215
    tDebug() << Q_FUNC_INFO << ids.count() << name();
 
216
 
 
217
    m_changed = true;
 
218
    emit tracksAdded( ids );
 
219
}
 
220
 
 
221
 
 
222
void
 
223
Collection::delTracks( const QList<unsigned int>& ids )
 
224
{
 
225
    tDebug() << Q_FUNC_INFO << ids.count() << name();
 
226
 
 
227
    m_changed = true;
 
228
    emit tracksRemoved( ids );
 
229
}
 
230
 
 
231
 
 
232
void
 
233
Collection::onSynced()
 
234
{
 
235
    tDebug() << Q_FUNC_INFO << m_changed;
 
236
    if ( m_changed )
 
237
    {
 
238
        m_changed = false;
 
239
        emit changed();
 
240
    }
 
241
}
 
242
 
 
243
 
 
244
void
 
245
Collection::moveAutoToStation( const QString& guid )
 
246
{
 
247
    if ( m_autoplaylists.contains( guid ) )
 
248
        m_stations.insert( guid, m_autoplaylists.take( guid ) );
 
249
}
 
250
 
 
251
 
 
252
void
 
253
Collection::moveStationToAuto( const QString& guid )
 
254
{
 
255
    if ( m_stations.contains( guid ) )
 
256
        m_autoplaylists.insert( guid, m_stations.take( guid ) );
 
257
}