/src/libtomahawk/database/DatabaseCommand_CollectionAttributes.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 63 lines · 33 code · 8 blank · 22 comment · 6 complexity · aa3b7fd5aadea6e9cc2decb44a1ecf80 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_CollectionAttributes.h"
  19. #include "DatabaseImpl.h"
  20. #include "Source.h"
  21. namespace Tomahawk
  22. {
  23. DatabaseCommand_CollectionAttributes::DatabaseCommand_CollectionAttributes( DatabaseCommand_SetCollectionAttributes::AttributeType type )
  24. : DatabaseCommand()
  25. , m_type( type )
  26. {
  27. }
  28. void
  29. DatabaseCommand_CollectionAttributes::exec( DatabaseImpl *lib )
  30. {
  31. TomahawkSqlQuery query = lib->newquery();
  32. // QString sourceStr;
  33. // if ( source().isNull() )
  34. // sourceStr = "id IS NULL";
  35. // else
  36. // sourceStr = QString( "id == %1" ).arg( source()->id() );
  37. QString typeStr;
  38. if ( m_type == DatabaseCommand_SetCollectionAttributes::EchonestSongCatalog )
  39. typeStr = "echonest_song";
  40. else if ( m_type == DatabaseCommand_SetCollectionAttributes::EchonestArtistCatalog )
  41. typeStr = "echonest_artist";
  42. QString queryStr = QString( "SELECT id, v FROM collection_attributes WHERE k = \"%1\"" ).arg( typeStr );
  43. qDebug() << "Doing queryL" << queryStr;
  44. query.exec( queryStr );
  45. PairList data;
  46. while ( query.next() )
  47. {
  48. QPair< QString, QString > part;
  49. part.first = query.value( 0 ).toString();
  50. part.second = query.value( 1 ).toString();
  51. data << part;
  52. }
  53. emit collectionAttributes( data );
  54. }
  55. }