/src/libtomahawk/database/DatabaseResolver.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 84 lines · 48 code · 19 blank · 17 comment · 0 complexity · b1e2276cf32be6e01fef0d945da3bf5e 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 "DatabaseResolver.h"
  19. #include "database/Database.h"
  20. #include "database/DatabaseCommand_Resolve.h"
  21. #include "network/Servent.h"
  22. #include "utils/Logger.h"
  23. #include "Pipeline.h"
  24. #include "PlaylistEntry.h"
  25. #include "Source.h"
  26. DatabaseResolver::DatabaseResolver( int weight )
  27. : Resolver()
  28. , m_weight( weight )
  29. {
  30. }
  31. void
  32. DatabaseResolver::resolve( const Tomahawk::query_ptr& query )
  33. {
  34. Tomahawk::DatabaseCommand_Resolve* cmd = new Tomahawk::DatabaseCommand_Resolve( query );
  35. connect( cmd, SIGNAL( results( Tomahawk::QID, QList< Tomahawk::result_ptr > ) ),
  36. SLOT( gotResults( Tomahawk::QID, QList< Tomahawk::result_ptr > ) ), Qt::QueuedConnection );
  37. connect( cmd, SIGNAL( albums( Tomahawk::QID, QList< Tomahawk::album_ptr > ) ),
  38. SLOT( gotAlbums( Tomahawk::QID, QList< Tomahawk::album_ptr > ) ), Qt::QueuedConnection );
  39. connect( cmd, SIGNAL( artists( Tomahawk::QID, QList< Tomahawk::artist_ptr > ) ),
  40. SLOT( gotArtists( Tomahawk::QID, QList< Tomahawk::artist_ptr > ) ), Qt::QueuedConnection );
  41. Tomahawk::Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );
  42. }
  43. void
  44. DatabaseResolver::gotResults( const Tomahawk::QID qid, QList< Tomahawk::result_ptr> results )
  45. {
  46. tDebug( LOGVERBOSE ) << Q_FUNC_INFO << qid << results.length();
  47. foreach ( const Tomahawk::result_ptr& r, results )
  48. r->setResolvedByResolver( this );
  49. Tomahawk::Pipeline::instance()->reportResults( qid, this, results );
  50. }
  51. void
  52. DatabaseResolver::gotAlbums( const Tomahawk::QID qid, QList< Tomahawk::album_ptr> albums )
  53. {
  54. Tomahawk::Pipeline::instance()->reportAlbums( qid, albums );
  55. }
  56. void
  57. DatabaseResolver::gotArtists( const Tomahawk::QID qid, QList< Tomahawk::artist_ptr> artists )
  58. {
  59. Tomahawk::Pipeline::instance()->reportArtists( qid, artists );
  60. }
  61. QString
  62. DatabaseResolver::name() const
  63. {
  64. return QString( "DatabaseResolver" );
  65. }