PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/src/libtomahawk/database/DatabaseCommand_LoadFiles.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 65 lines | 36 code | 11 blank | 18 comment | 3 complexity | ba444c849ca54b776258c2967356abc6 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 "DatabaseCommand_LoadFiles.h"
20
21#include "collection/Collection.h"
22#include "utils/Logger.h"
23
24#include "DatabaseImpl.h"
25#include "PlaylistEntry.h"
26#include "Source.h"
27
28namespace Tomahawk
29{
30
31DatabaseCommand_LoadFiles::DatabaseCommand_LoadFiles( unsigned int id, QObject* parent )
32    : DatabaseCommand( parent )
33    , m_single( true )
34{
35    m_ids << id;
36}
37
38DatabaseCommand_LoadFiles::DatabaseCommand_LoadFiles( const QList<unsigned int>& ids, QObject* parent )
39    : DatabaseCommand( parent )
40    , m_single( false )
41    , m_ids( ids )
42{
43}
44
45
46void
47DatabaseCommand_LoadFiles::exec( DatabaseImpl* dbi )
48{
49    QList<Tomahawk::result_ptr> resultList;
50    // file ids internally are really ints, at least for now:
51    foreach ( unsigned int id, m_ids )
52    {
53        qDebug() << "Loading file from db with id:" << id;
54        resultList << dbi->file( id );
55    }
56
57    Q_ASSERT( !m_single || resultList.size() <= 1 );
58
59    if ( m_single && !resultList.isEmpty() )
60        emit result( resultList.first() );
61    else
62        emit results( resultList );
63}
64
65}