PageRenderTime 195ms CodeModel.GetById 113ms app.highlight 6ms RepoModel.GetById 75ms app.codeStats 0ms

/src/libtomahawk/playlist/dynamic/GeneratorFactory.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 74 lines | 39 code | 18 blank | 17 comment | 6 complexity | 100f26020f38be52708ed8eeba61a018 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 "playlist/dynamic/GeneratorFactory.h"
20#include "playlist/dynamic/GeneratorInterface.h"
21
22#include "utils/Logger.h"
23#include "Source.h"
24
25using namespace Tomahawk;
26
27
28QHash< QString, GeneratorFactoryInterface* > GeneratorFactory::s_factories = QHash< QString, GeneratorFactoryInterface* >();
29
30geninterface_ptr
31GeneratorFactory::create ( const QString& type )
32{
33    if( type.isEmpty() && !s_factories.isEmpty() ) // default, return first
34        return geninterface_ptr( s_factories.begin().value()->create() );
35
36    if( !s_factories.contains( type ) )
37        return geninterface_ptr();
38
39    return geninterface_ptr( s_factories.value( type )->create() );
40}
41
42
43dyncontrol_ptr
44GeneratorFactory::createControl( const QString& generatorType, const QString& controlType )
45{
46    if( generatorType.isEmpty() || !s_factories.contains( generatorType ) )
47        return dyncontrol_ptr();
48
49    return s_factories.value( generatorType )->createControl( controlType );
50}
51
52
53void
54GeneratorFactory::registerFactory ( const QString& type, GeneratorFactoryInterface* interface )
55{
56    s_factories.insert( type, interface );
57}
58
59
60QStringList
61GeneratorFactory::types()
62{
63    return s_factories.keys();
64}
65
66
67QStringList
68GeneratorFactory::typeSelectors( const QString& type )
69{
70    if( !s_factories.contains( type ) )
71        return QStringList();
72
73    return s_factories.value( type )->typeSelectors();
74}