PageRenderTime 198ms CodeModel.GetById 70ms app.highlight 56ms RepoModel.GetById 65ms app.codeStats 1ms

/src/libtomahawk/database/DatabaseCommand_LoadDynamicPlaylist.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 87 lines | 43 code | 16 blank | 28 comment | 1 complexity | ccbdb4928df43112706db4ac99affc1d 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_LoadDynamicPlaylist.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
30
31using namespace Tomahawk;
32
33Tomahawk::DatabaseCommand_LoadDynamicPlaylist::DatabaseCommand_LoadDynamicPlaylist( const source_ptr& s, const QString& guid, QObject* parent )
34    : DatabaseCommand( s, parent )
35    , m_plid( guid )
36{
37
38}
39
40
41void
42Tomahawk::DatabaseCommand_LoadDynamicPlaylist::exec( DatabaseImpl* dbi )
43{
44    TomahawkSqlQuery query = dbi->newquery();
45
46    query.exec( QString( "SELECT playlist.guid as guid, title, info, creator, createdOn, lastmodified, shared, currentrevision, dynamic_playlist.pltype, dynamic_playlist.plmode "
47                         "FROM playlist, dynamic_playlist WHERE "
48                         "source %1 "
49                         "AND (dynplaylist = 'true' OR dynplaylist = 1)"
50                         "AND playlist.guid = dynamic_playlist.guid "
51                         "AND playlist.guid = '%2'" )
52    .arg( source()->isLocal() ? "IS NULL" : QString( "=%1" ).arg( source()->id() ) ).arg( m_plid ) );
53
54    QList<dynplaylist_ptr> plists;
55    if( query.next() )
56    {
57        dynplaylist_ptr p( new DynamicPlaylist( source(),
58                                                query.value(7).toString(),  //current rev
59                                                query.value(1).toString(),  //title
60                                                query.value(2).toString(),  //info
61                                                query.value(3).toString(),  //creator
62                                                query.value(4).toUInt(),  //createdOn
63                                                query.value(8).toString(),  // dynamic type
64                                                static_cast<GeneratorMode>(query.value(9).toInt()),  // dynamic mode
65                                                query.value(6).toBool(),    //shared
66                                                query.value(5).toInt(),     //lastmod
67                                                query.value(0).toString() ) );  //GUID
68
69        p->setWeakSelf( p.toWeakRef() );
70/*
71        tLog() << "Loaded individual dynamic playlist:" <<      query.value(7).toString()  //current rev
72        <<      query.value(1).toString()  //title
73        <<      query.value(2).toString()  //info
74        <<      query.value(3).toString()  //creator
75        <<      query.value(4).toString()  //createdOn
76        <<      query.value(8).toString()  // dynamic type
77        <<      static_cast<GeneratorMode>(query.value(9).toInt())  // dynamic mode
78        <<      query.value(6).toBool()    //shared
79        <<      query.value(5).toInt()     //lastmod
80        <<      query.value(0).toString();  //GUID */
81
82        emit dynamicPlaylistLoaded( p );
83    }
84
85    emit done();
86}
87