/src/libtomahawk/Query.h

http://github.com/tomahawk-player/tomahawk · C Header · 170 lines · 88 code · 43 blank · 39 comment · 0 complexity · be1dc0ad259b0676ba6243b9ef0b38e6 MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2015, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4. * Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
  5. * Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
  6. *
  7. * Tomahawk is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Tomahawk is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #pragma once
  21. #ifndef TOMAHAWK_QUERY_H
  22. #define TOMAHAWK_QUERY_H
  23. #include <QObject>
  24. #include <QList>
  25. #include <QVariant>
  26. #include "DllMacro.h"
  27. #include "Typedefs.h"
  28. namespace Tomahawk
  29. {
  30. class DatabaseCommand_LoadPlaylistEntries;
  31. class Resolver;
  32. class QueryPrivate;
  33. class DLLEXPORT Query : public QObject
  34. {
  35. Q_OBJECT
  36. friend class DatabaseCommand_LoadPlaylistEntries;
  37. friend class Pipeline;
  38. public:
  39. static query_ptr get( const QString& artist, const QString& title, const QString& album, const QID& qid = QString(), bool autoResolve = true );
  40. static query_ptr get( const Tomahawk::track_ptr& track, const QID& qid = QString() );
  41. static query_ptr get( const QString& query, const QID& qid );
  42. /**
  43. * Get a Query object with a fixed Result reference which is not re-resolved.
  44. */
  45. static query_ptr getFixed( const Tomahawk::track_ptr& track, const Tomahawk::result_ptr& result );
  46. virtual ~Query();
  47. bool equals( const Tomahawk::query_ptr& other, bool ignoreCase = false, bool ignoreAlbum = false ) const;
  48. float howSimilar( const Tomahawk::result_ptr& r );
  49. QVariant toVariant() const;
  50. QString toString() const;
  51. QID id() const;
  52. track_ptr queryTrack() const;
  53. track_ptr track() const;
  54. /// returns list of all results so far
  55. QList< result_ptr > results() const;
  56. /// how many results found so far?
  57. unsigned int numResults( bool onlyPlayableResults = false ) const;
  58. bool resolvingFinished() const;
  59. /// true when a perfect result has been found (score of 1.0)
  60. bool solved() const;
  61. /// true when any result has been found (score may be less than 1.0)
  62. bool playable() const;
  63. float score() const;
  64. Tomahawk::Resolver* currentResolver() const;
  65. QList< QPointer< Tomahawk::Resolver > > resolvedBy() const;
  66. QString fullTextQuery() const;
  67. bool isFullTextQuery() const;
  68. void setResolveFinished( bool resolved );
  69. /**
  70. * Allow contacting the Pipeline if the state of this Query changes to
  71. * not solved.
  72. */
  73. void allowReresolve();
  74. /**
  75. * Disallow contacting the Pipeline if the state of this Query changes to
  76. * not solved.
  77. */
  78. void disallowReresolve();
  79. void setSaveHTTPResultHint( bool saveResultHint );
  80. bool saveHTTPResultHint() const;
  81. QString resultHint() const;
  82. void setResultHint( const QString& resultHint );
  83. QWeakPointer< Tomahawk::Query > weakRef();
  84. void setWeakRef( QWeakPointer< Tomahawk::Query > weakRef );
  85. /// sorter for list of results
  86. bool resultSorter( const result_ptr& left, const result_ptr& right );
  87. result_ptr preferredResult() const;
  88. void setPreferredResult( const result_ptr& result );
  89. signals:
  90. void resultsAdded( const QList<Tomahawk::result_ptr>& );
  91. void resultsRemoved( const Tomahawk::result_ptr& );
  92. void albumsAdded( const QList<Tomahawk::album_ptr>& );
  93. void artistsAdded( const QList<Tomahawk::artist_ptr>& );
  94. void resultsChanged();
  95. void solvedStateChanged( bool state );
  96. void playableStateChanged( bool state );
  97. void resolvingFinished( bool hasResults );
  98. public slots:
  99. /// (indirectly) called by resolver plugins when results are found
  100. void addResults( const QList< Tomahawk::result_ptr >& );
  101. void removeResult( const Tomahawk::result_ptr& );
  102. void addAlbums( const QList< Tomahawk::album_ptr >& );
  103. void addArtists( const QList< Tomahawk::artist_ptr >& );
  104. void onResolvingFinished();
  105. void onResolverAdded();
  106. protected:
  107. QScopedPointer<QueryPrivate> d_ptr;
  108. private slots:
  109. void onResultStatusChanged();
  110. void refreshResults();
  111. private:
  112. explicit Query( const track_ptr& track, const QID& qid, bool autoResolve );
  113. /**
  114. * Respective constructor for getFixed
  115. */
  116. explicit Query( const track_ptr& track, const result_ptr& result );
  117. explicit Query( const QString& query, const QID& qid );
  118. Q_DECLARE_PRIVATE( Query )
  119. void init();
  120. void setCurrentResolver( Tomahawk::Resolver* resolver );
  121. void clearResults();
  122. void checkResults();
  123. void sortResults();
  124. };
  125. } //ns
  126. Q_DECLARE_METATYPE( Tomahawk::query_ptr )
  127. #endif // TOMAHAWK_QUERY_H