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, Leo Franchi <lfranchi@kde.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 "DatabaseCollection.h"
22
#include "database/Database.h"
23
#include "DatabaseCommand_AllTracks.h"
24
#include "DatabaseCommand_AddFiles.h"
25
#include "DatabaseCommand_DeleteFiles.h"
26
#include "DatabaseCommand_LoadAllPlaylists.h"
27
#include "DatabaseCommand_LoadAllAutoPlaylists.h"
28
#include "DatabaseCommand_LoadAllStations.h"
30
#include "utils/Logger.h"
32
using namespace Tomahawk;
35
DatabaseCollection::DatabaseCollection( const source_ptr& src, QObject* parent )
36
: Collection( src, QString( "dbcollection:%1" ).arg( src->userName() ), parent )
42
DatabaseCollection::loadPlaylists()
44
DatabaseCommand_LoadAllPlaylists* cmd = new DatabaseCommand_LoadAllPlaylists( source() );
46
connect( cmd, SIGNAL( done( const QList<Tomahawk::playlist_ptr>& ) ),
47
SLOT( setPlaylists( const QList<Tomahawk::playlist_ptr>& ) ) );
49
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
54
DatabaseCollection::loadAutoPlaylists()
56
DatabaseCommand_LoadAllAutoPlaylists* cmd = new DatabaseCommand_LoadAllAutoPlaylists( source() );
58
connect( cmd, SIGNAL( autoPlaylistLoaded( Tomahawk::source_ptr, QVariantList ) ),
59
SLOT( autoPlaylistCreated( const Tomahawk::source_ptr&, const QVariantList& ) ) );
61
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
66
DatabaseCollection::loadStations()
68
DatabaseCommand_LoadAllStations* cmd = new DatabaseCommand_LoadAllStations( source() );
70
connect( cmd, SIGNAL( stationLoaded( Tomahawk::source_ptr, QVariantList ) ),
71
SLOT( stationCreated( const Tomahawk::source_ptr&, const QVariantList& ) ) );
73
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
78
DatabaseCollection::addTracks( const QList<QVariant>& newitems )
80
qDebug() << Q_FUNC_INFO << newitems.length();
81
DatabaseCommand_AddFiles* cmd = new DatabaseCommand_AddFiles( newitems, source() );
83
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
88
DatabaseCollection::removeTracks( const QDir& dir )
90
qDebug() << Q_FUNC_INFO << dir;
91
DatabaseCommand_DeleteFiles* cmd = new DatabaseCommand_DeleteFiles( dir, source() );
93
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
97
QList< Tomahawk::playlist_ptr >
98
DatabaseCollection::playlists()
100
if ( Collection::playlists().isEmpty() )
105
return Collection::playlists();
109
QList< dynplaylist_ptr >
110
DatabaseCollection::autoPlaylists()
112
if ( Collection::autoPlaylists().isEmpty() )
117
return Collection::autoPlaylists();
121
QList< dynplaylist_ptr >
122
DatabaseCollection::stations()
124
if ( Collection::stations().isEmpty() )
129
return Collection::stations();
134
DatabaseCollection::autoPlaylistCreated( const source_ptr& source, const QVariantList& data )
136
dynplaylist_ptr p( new DynamicPlaylist( source, //src
137
data[0].toString(), //current rev
138
data[1].toString(), //title
139
data[2].toString(), //info
140
data[3].toString(), //creator
141
data[4].toUInt(), // createdOn
142
data[5].toString(), // dynamic type
143
static_cast<GeneratorMode>(data[6].toInt()), // dynamic mode
144
data[7].toBool(), //shared
145
data[8].toInt(), //lastmod
146
data[9].toString() ), &QObject::deleteLater ); //GUID
147
p->setWeakSelf( p.toWeakRef() );
149
addAutoPlaylist( p );
154
DatabaseCollection::stationCreated( const source_ptr& source, const QVariantList& data )
156
dynplaylist_ptr p( new DynamicPlaylist( source, //src
157
data[0].toString(), //current rev
158
data[1].toString(), //title
159
data[2].toString(), //info
160
data[3].toString(), //creator
161
data[4].toUInt(), // createdOn
162
data[5].toString(), // dynamic type
163
static_cast<GeneratorMode>(data[6].toInt()), // dynamic mode
164
data[7].toBool(), //shared
165
data[8].toInt(), //lastmod
166
data[9].toString() ), &QObject::deleteLater ); //GUID
167
p->setWeakSelf( p.toWeakRef() );