/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. #include "playlist/dynamic/GeneratorFactory.h"
  19. #include "playlist/dynamic/GeneratorInterface.h"
  20. #include "utils/Logger.h"
  21. #include "Source.h"
  22. using namespace Tomahawk;
  23. QHash< QString, GeneratorFactoryInterface* > GeneratorFactory::s_factories = QHash< QString, GeneratorFactoryInterface* >();
  24. geninterface_ptr
  25. GeneratorFactory::create ( const QString& type )
  26. {
  27. if( type.isEmpty() && !s_factories.isEmpty() ) // default, return first
  28. return geninterface_ptr( s_factories.begin().value()->create() );
  29. if( !s_factories.contains( type ) )
  30. return geninterface_ptr();
  31. return geninterface_ptr( s_factories.value( type )->create() );
  32. }
  33. dyncontrol_ptr
  34. GeneratorFactory::createControl( const QString& generatorType, const QString& controlType )
  35. {
  36. if( generatorType.isEmpty() || !s_factories.contains( generatorType ) )
  37. return dyncontrol_ptr();
  38. return s_factories.value( generatorType )->createControl( controlType );
  39. }
  40. void
  41. GeneratorFactory::registerFactory ( const QString& type, GeneratorFactoryInterface* interface )
  42. {
  43. s_factories.insert( type, interface );
  44. }
  45. QStringList
  46. GeneratorFactory::types()
  47. {
  48. return s_factories.keys();
  49. }
  50. QStringList
  51. GeneratorFactory::typeSelectors( const QString& type )
  52. {
  53. if( !s_factories.contains( type ) )
  54. return QStringList();
  55. return s_factories.value( type )->typeSelectors();
  56. }