1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
3
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
5
* Tomahawk is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* Tomahawk is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
19
#include "DatabaseCommand_AllArtists.h"
24
#include "DatabaseImpl.h"
26
#include "utils/TomahawkUtils.h"
27
#include "utils/Logger.h"
30
DatabaseCommand_AllArtists::DatabaseCommand_AllArtists( const Tomahawk::collection_ptr& collection, QObject* parent )
31
: DatabaseCommand( parent )
32
, m_collection( collection )
34
, m_sortOrder( DatabaseCommand_AllArtists::None )
35
, m_sortDescending( false )
40
DatabaseCommand_AllArtists::~DatabaseCommand_AllArtists()
46
DatabaseCommand_AllArtists::exec( DatabaseImpl* dbi )
48
TomahawkSqlQuery query = dbi->newquery();
49
QString orderToken, sourceToken, filterToken, tables, joins;
51
switch ( m_sortOrder )
56
case ModificationTime:
57
orderToken = "file.mtime";
60
if ( !m_collection.isNull() )
61
sourceToken = QString( "AND file.source %1" ).arg( m_collection->source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( m_collection->source()->id() ) );
63
if ( !m_filter.isEmpty() )
66
QStringList sl = m_filter.split( " ", QString::SkipEmptyParts );
67
foreach( QString s, sl )
69
filtersql += QString( " AND ( artist.name LIKE '%%1%' OR album.name LIKE '%%1%' OR track.name LIKE '%%1%' )" ).arg( TomahawkSqlQuery::escape( s ) );
72
filterToken = QString( "AND file_join.track = track.id %1" ).arg( filtersql );
73
joins = "LEFT JOIN album ON album.id = file_join.album";
74
tables = "artist, track, file, file_join";
77
tables = "artist, file, file_join";
79
QString sql = QString(
80
"SELECT DISTINCT artist.id, artist.name "
83
"WHERE file.id = file_join.file "
84
"AND file_join.artist = artist.id "
90
.arg( m_sortOrder > 0 ? QString( "ORDER BY %1" ).arg( orderToken ) : QString() )
91
.arg( m_sortDescending ? "DESC" : QString() )
92
.arg( m_amount > 0 ? QString( "LIMIT 0, %1" ).arg( m_amount ) : QString() );
97
QList<Tomahawk::artist_ptr> al;
98
while ( query.next() )
100
Tomahawk::artist_ptr artist = Tomahawk::Artist::get( query.value( 0 ).toUInt(), query.value( 1 ).toString() );