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

« back to all changes in this revision

Viewing changes to src/libtomahawk/database/DatabaseCollection.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, Leo Franchi            <lfranchi@kde.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 "DatabaseCollection.h"
 
21
 
 
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"
 
29
 
 
30
#include "utils/Logger.h"
 
31
 
 
32
using namespace Tomahawk;
 
33
 
 
34
 
 
35
DatabaseCollection::DatabaseCollection( const source_ptr& src, QObject* parent )
 
36
    : Collection( src, QString( "dbcollection:%1" ).arg( src->userName() ), parent )
 
37
{
 
38
}
 
39
 
 
40
 
 
41
void
 
42
DatabaseCollection::loadPlaylists()
 
43
{
 
44
    DatabaseCommand_LoadAllPlaylists* cmd = new DatabaseCommand_LoadAllPlaylists( source() );
 
45
 
 
46
    connect( cmd,  SIGNAL( done( const QList<Tomahawk::playlist_ptr>& ) ),
 
47
                     SLOT( setPlaylists( const QList<Tomahawk::playlist_ptr>& ) ) );
 
48
 
 
49
    Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
 
50
}
 
51
 
 
52
 
 
53
void
 
54
DatabaseCollection::loadAutoPlaylists()
 
55
{
 
56
    DatabaseCommand_LoadAllAutoPlaylists* cmd = new DatabaseCommand_LoadAllAutoPlaylists( source() );
 
57
 
 
58
    connect( cmd, SIGNAL( autoPlaylistLoaded( Tomahawk::source_ptr, QVariantList ) ),
 
59
                    SLOT( autoPlaylistCreated( const Tomahawk::source_ptr&, const QVariantList& ) ) );
 
60
 
 
61
    Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
 
62
}
 
63
 
 
64
 
 
65
void
 
66
DatabaseCollection::loadStations()
 
67
{
 
68
    DatabaseCommand_LoadAllStations* cmd = new DatabaseCommand_LoadAllStations( source() );
 
69
 
 
70
    connect( cmd, SIGNAL( stationLoaded( Tomahawk::source_ptr, QVariantList ) ),
 
71
             SLOT( stationCreated( const Tomahawk::source_ptr&, const QVariantList& ) ) );
 
72
 
 
73
    Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
 
74
}
 
75
 
 
76
 
 
77
void
 
78
DatabaseCollection::addTracks( const QList<QVariant>& newitems )
 
79
{
 
80
    qDebug() << Q_FUNC_INFO << newitems.length();
 
81
    DatabaseCommand_AddFiles* cmd = new DatabaseCommand_AddFiles( newitems, source() );
 
82
 
 
83
    Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
 
84
}
 
85
 
 
86
 
 
87
void
 
88
DatabaseCollection::removeTracks( const QDir& dir )
 
89
{
 
90
    qDebug() << Q_FUNC_INFO << dir;
 
91
    DatabaseCommand_DeleteFiles* cmd = new DatabaseCommand_DeleteFiles( dir, source() );
 
92
 
 
93
    Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
 
94
}
 
95
 
 
96
 
 
97
QList< Tomahawk::playlist_ptr >
 
98
DatabaseCollection::playlists()
 
99
{
 
100
    if ( Collection::playlists().isEmpty() )
 
101
    {
 
102
        loadPlaylists();
 
103
    }
 
104
 
 
105
    return Collection::playlists();
 
106
}
 
107
 
 
108
 
 
109
QList< dynplaylist_ptr >
 
110
DatabaseCollection::autoPlaylists()
 
111
{
 
112
    if ( Collection::autoPlaylists().isEmpty() )
 
113
    {
 
114
        loadAutoPlaylists();
 
115
    }
 
116
 
 
117
    return Collection::autoPlaylists();
 
118
}
 
119
 
 
120
 
 
121
QList< dynplaylist_ptr >
 
122
DatabaseCollection::stations()
 
123
{
 
124
    if ( Collection::stations().isEmpty() )
 
125
    {
 
126
        loadStations();
 
127
    }
 
128
 
 
129
    return Collection::stations();
 
130
}
 
131
 
 
132
 
 
133
void
 
134
DatabaseCollection::autoPlaylistCreated( const source_ptr& source, const QVariantList& data )
 
135
{
 
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() );
 
148
 
 
149
    addAutoPlaylist( p );
 
150
}
 
151
 
 
152
 
 
153
void
 
154
DatabaseCollection::stationCreated( const source_ptr& source, const QVariantList& data )
 
155
{
 
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() );
 
168
 
 
169
    addStation( p );
 
170
}
 
171
 
 
172