PageRenderTime 142ms CodeModel.GetById 60ms app.highlight 5ms RepoModel.GetById 75ms app.codeStats 0ms

/src/libtomahawk/database/DatabaseCommand_CollectionAttributes.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 63 lines | 33 code | 8 blank | 22 comment | 6 complexity | aa3b7fd5aadea6e9cc2decb44a1ecf80 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#include "DatabaseCommand_CollectionAttributes.h"
19
20#include "DatabaseImpl.h"
21#include "Source.h"
22
23namespace Tomahawk
24{
25
26DatabaseCommand_CollectionAttributes::DatabaseCommand_CollectionAttributes( DatabaseCommand_SetCollectionAttributes::AttributeType type )
27    : DatabaseCommand()
28    , m_type( type )
29{
30}
31
32void
33DatabaseCommand_CollectionAttributes::exec( DatabaseImpl *lib )
34{
35    TomahawkSqlQuery query = lib->newquery();
36
37//    QString sourceStr;
38//    if ( source().isNull() )
39//        sourceStr = "id IS NULL";
40//    else
41//        sourceStr = QString( "id == %1" ).arg( source()->id() );
42
43    QString typeStr;
44    if ( m_type == DatabaseCommand_SetCollectionAttributes::EchonestSongCatalog )
45        typeStr = "echonest_song";
46    else if ( m_type == DatabaseCommand_SetCollectionAttributes::EchonestArtistCatalog )
47        typeStr = "echonest_artist";
48
49    QString queryStr = QString( "SELECT id, v FROM collection_attributes WHERE k = \"%1\"" ).arg( typeStr );
50    qDebug() << "Doing queryL" << queryStr;
51    query.exec( queryStr );
52    PairList data;
53    while ( query.next() )
54    {
55        QPair< QString, QString  > part;
56        part.first = query.value( 0 ).toString();
57        part.second = query.value( 1 ).toString();
58        data << part;
59    }
60    emit collectionAttributes( data );
61}
62
63}