/src/libtomahawk/database/DatabaseCommand_TrackAttributes.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 74 lines · 49 code · 8 blank · 17 comment · 4 complexity · 3a31c7a3c2ac120ea39d6a9c7993ced1 MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Leo Franchi <lfranchi@kde.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_TrackAttributes.h"
  19. #include "DatabaseImpl.h"
  20. #include "Source.h"
  21. using namespace Tomahawk;
  22. DatabaseCommand_TrackAttributes::DatabaseCommand_TrackAttributes( DatabaseCommand_SetTrackAttributes::AttributeType type, const QList< Tomahawk::QID > ids )
  23. : DatabaseCommand()
  24. , m_type( type )
  25. , m_ids( ids )
  26. {
  27. }
  28. DatabaseCommand_TrackAttributes::DatabaseCommand_TrackAttributes( DatabaseCommand_SetTrackAttributes::AttributeType type )
  29. : DatabaseCommand()
  30. , m_type( type )
  31. {
  32. }
  33. void DatabaseCommand_TrackAttributes::exec( DatabaseImpl* lib )
  34. {
  35. TomahawkSqlQuery query = lib->newquery();
  36. QString k;
  37. switch ( m_type )
  38. {
  39. case DatabaseCommand_SetTrackAttributes::EchonestCatalogId:
  40. k = "echonestcatalogid";
  41. break;
  42. }
  43. PairList results;
  44. if ( !m_ids.isEmpty() )
  45. {
  46. foreach ( const QID id, m_ids )
  47. {
  48. query.prepare( "SELECT v FROM track_attributes WHERE id = ? AND k = ?" );
  49. query.bindValue( 0, id );
  50. query.bindValue( 1, k );
  51. if ( query.exec() )
  52. results.append( QPair< QID, QString >( id, query.value( 0 ).toString() ) );
  53. }
  54. }
  55. else
  56. {
  57. query.prepare( "SELECT id, v FROM track_attributes WHERE k = ?" );
  58. query.bindValue( 0, k );
  59. query.exec();
  60. while ( query.next() )
  61. {
  62. results.append( QPair< QID, QString >( query.value( 0 ).toString(), query.value( 1 ).toString() ) );
  63. }
  64. }
  65. emit trackAttributes( results );
  66. }