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