PageRenderTime 143ms CodeModel.GetById 40ms app.highlight 9ms RepoModel.GetById 92ms app.codeStats 0ms

/src/libtomahawk/database/DatabaseCommand_LoadAllStations.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 85 lines | 53 code | 15 blank | 17 comment | 3 complexity | 5d2755e7a125a32d6dff90943dd1b1a9 MD5 | raw file
 1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 2 *
 3 *   Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
 4 *
 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.
 9 *
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.
14 *
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/>.
17 */
18
19#include "DatabaseCommand_LoadAllStations.h"
20
21#include "playlist/dynamic/DynamicPlaylist.h"
22#include "utils/Logger.h"
23
24#include "DatabaseImpl.h"
25#include "PlaylistEntry.h"
26#include "Source.h"
27
28#include <QSqlQuery>
29
30using namespace Tomahawk;
31
32
33void
34DatabaseCommand_LoadAllStations::exec( DatabaseImpl* dbi )
35{
36    TomahawkSqlQuery query = dbi->newquery();
37    QString orderToken, sourceToken;
38
39    switch ( m_sortOrder )
40    {
41        case 0:
42            break;
43
44        case DatabaseCommand_LoadAllPlaylists::ModificationTime:
45            orderToken = "playlist.createdOn";
46    }
47
48    if ( !source().isNull() )
49        sourceToken = QString( "AND source %1 " ).arg( source()->isLocal() ? "IS NULL" : QString( "= %1" ).arg( source()->id() ) );
50
51
52    query.exec( QString( "SELECT playlist.guid as guid, title, info, creator, createdOn, lastmodified, shared, currentrevision, dynamic_playlist.pltype, dynamic_playlist.plmode "
53                         "FROM playlist, dynamic_playlist WHERE "
54                         "(dynplaylist = 'true' OR dynplaylist = 1) "
55                         "AND playlist.guid = dynamic_playlist.guid "
56                         "AND dynamic_playlist.plmode = %1 "
57                         "AND (dynamic_playlist.autoload = 'true' OR dynamic_playlist.autoload = 1) "
58                         "%2"
59                         "%3 %4 %5"
60                       )
61                       .arg( OnDemand )
62                       .arg( sourceToken )
63                       .arg( m_sortOrder > 0 ? QString( "ORDER BY %1" ).arg( orderToken ) : QString() )
64                       .arg( m_sortDescending ? "DESC" : QString() )
65                       .arg( m_limitAmount > 0 ? QString( "LIMIT 0, %1" ).arg( m_limitAmount ) : QString() ) );
66
67    QList<dynplaylist_ptr> plists;
68    while ( query.next() )
69    {
70            QVariantList data = QVariantList()  <<      query.value(7).toString()  //current rev
71                                                <<      query.value(1).toString()  //title
72                                                <<      query.value(2).toString()  //info
73                                                <<      query.value(3).toString()  //creator
74                                                <<      query.value(4).toString()  //createdOn
75                                                <<      query.value(8).toString()  // dynamic type
76                                                <<      static_cast<GeneratorMode>(query.value(9).toInt())  // dynamic mode
77                                                <<      query.value(6).toBool()    //shared
78                                                <<      query.value(5).toInt()     //lastmod
79                                                <<      query.value(0).toString();  //GUID
80            emit stationLoaded( source(), data );
81    }
82
83    emit done();
84}
85