PageRenderTime 29ms CodeModel.GetById 17ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/src/libtomahawk/database/DatabaseResolver.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 84 lines | 48 code | 19 blank | 17 comment | 0 complexity | b1e2276cf32be6e01fef0d945da3bf5e MD5 | raw file
 1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 2 *
 3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.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 "DatabaseResolver.h"
20
21#include "database/Database.h"
22#include "database/DatabaseCommand_Resolve.h"
23#include "network/Servent.h"
24#include "utils/Logger.h"
25
26#include "Pipeline.h"
27#include "PlaylistEntry.h"
28#include "Source.h"
29
30
31DatabaseResolver::DatabaseResolver( int weight )
32    : Resolver()
33    , m_weight( weight )
34{
35}
36
37
38void
39DatabaseResolver::resolve( const Tomahawk::query_ptr& query )
40{
41    Tomahawk::DatabaseCommand_Resolve* cmd = new Tomahawk::DatabaseCommand_Resolve( query );
42
43    connect( cmd, SIGNAL( results( Tomahawk::QID, QList< Tomahawk::result_ptr > ) ),
44                    SLOT( gotResults( Tomahawk::QID, QList< Tomahawk::result_ptr > ) ), Qt::QueuedConnection );
45    connect( cmd, SIGNAL( albums( Tomahawk::QID, QList< Tomahawk::album_ptr > ) ),
46                    SLOT( gotAlbums( Tomahawk::QID, QList< Tomahawk::album_ptr > ) ), Qt::QueuedConnection );
47    connect( cmd, SIGNAL( artists( Tomahawk::QID, QList< Tomahawk::artist_ptr > ) ),
48                    SLOT( gotArtists( Tomahawk::QID, QList< Tomahawk::artist_ptr > ) ), Qt::QueuedConnection );
49
50    Tomahawk::Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
51}
52
53
54void
55DatabaseResolver::gotResults( const Tomahawk::QID qid, QList< Tomahawk::result_ptr> results )
56{
57    tDebug( LOGVERBOSE ) << Q_FUNC_INFO << qid << results.length();
58
59    foreach ( const Tomahawk::result_ptr& r, results )
60        r->setResolvedByResolver( this );
61
62    Tomahawk::Pipeline::instance()->reportResults( qid, this, results );
63}
64
65
66void
67DatabaseResolver::gotAlbums( const Tomahawk::QID qid, QList< Tomahawk::album_ptr> albums )
68{
69    Tomahawk::Pipeline::instance()->reportAlbums( qid, albums );
70}
71
72
73void
74DatabaseResolver::gotArtists( const Tomahawk::QID qid, QList< Tomahawk::artist_ptr> artists )
75{
76    Tomahawk::Pipeline::instance()->reportArtists( qid, artists );
77}
78
79
80QString
81DatabaseResolver::name() const
82{
83    return QString( "DatabaseResolver" );
84}