/src/libtomahawk/Result.h

http://github.com/tomahawk-player/tomahawk · C Header · 202 lines · 106 code · 45 blank · 51 comment · 0 complexity · 342dc4644ba2ff08b9d81736cfd99ef5 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-2011, Jeff Mitchell <jeff@tomahawk-player.org>
  5. * Copyright 2015, Dominik Schmidt <domme@tomahawk-player.org>
  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. #ifndef RESULT_H
  21. #define RESULT_H
  22. #include "DownloadJob.h"
  23. #include "utils/TomahawkUtils.h"
  24. #include "Typedefs.h"
  25. #include "DllMacro.h"
  26. #include <QObject>
  27. #include <QPixmap>
  28. #include <QPointer>
  29. #include <QVariant>
  30. #include <QMutex>
  31. class MetadataEditor;
  32. namespace Tomahawk
  33. {
  34. class Resolver;
  35. class DLLEXPORT Result : public QObject
  36. {
  37. Q_OBJECT
  38. friend class ::MetadataEditor;
  39. public:
  40. /**
  41. * Get a Result instance for an URL if it is cached, otherwise create a new
  42. * instance using the supplied Track object.
  43. */
  44. static Tomahawk::result_ptr get( const QString& url,
  45. const Tomahawk::track_ptr& track );
  46. /**
  47. * Get a Result instance for an URL if it is already cached.
  48. *
  49. * This will not create a new Result instance if there is no matching
  50. * Result in the cache, use Result::get for this.
  51. *
  52. * @param url Unique result identifier
  53. * @return nullptr if the Result is not yet cached
  54. */
  55. static Tomahawk::result_ptr getCached( const QString& url );
  56. virtual ~Result();
  57. QWeakPointer< Tomahawk::Result > weakRef();
  58. void setWeakRef( QWeakPointer< Tomahawk::Result > weakRef );
  59. QVariant toVariant() const;
  60. QString toString() const;
  61. Tomahawk::query_ptr toQuery();
  62. /**
  63. * Associate the used collection for this result.
  64. *
  65. * @param emitOnlineEvents disableing this will not emit statusChanged anymore thus the query will not update (use with care!, only when this is the sole result)
  66. */
  67. void setResolvedByCollection( const Tomahawk::collection_ptr& collection, bool emitOnlineEvents = true );
  68. collection_ptr resolvedByCollection() const;
  69. QPointer< Tomahawk::Resolver > resolvedByResolver() const;
  70. void setResolvedByResolver( Tomahawk::Resolver* resolver );
  71. /**
  72. * TODO: Make this a smart pointer
  73. */
  74. Resolver* resolvedBy() const;
  75. RID id() const;
  76. bool isOnline() const;
  77. bool playable() const;
  78. /**
  79. * @brief whether this result isLocal, i.e. resolved by a local collection
  80. * @return isLocal
  81. */
  82. bool isLocal() const;
  83. QString url() const;
  84. /**
  85. * Has the given url been checked that it is accessible/valid.
  86. *
  87. * Results marked as true will bypass the ResultUrlChecker.
  88. */
  89. bool checked() const;
  90. QString mimetype() const;
  91. QString friendlySource() const;
  92. bool isPreview() const;
  93. QString purchaseUrl() const;
  94. QString linkUrl() const;
  95. QPixmap sourceIcon( TomahawkUtils::ImageMode style, const QSize& desiredSize = QSize() ) const;
  96. unsigned int bitrate() const;
  97. unsigned int size() const;
  98. unsigned int modificationTime() const;
  99. void setFileId( unsigned int id );
  100. void setRID( RID id ) { m_rid = id; }
  101. void setFriendlySource( const QString& s );
  102. void setPreview( bool isPreview );
  103. void setPurchaseUrl( const QString& u );
  104. void setLinkUrl( const QString& u );
  105. void setChecked( bool checked );
  106. void setMimetype( const QString& mimetype );
  107. void setBitrate( unsigned int bitrate );
  108. void setSize( unsigned int size );
  109. void setModificationTime( unsigned int modtime );
  110. void setTrack( const track_ptr& track );
  111. unsigned int fileId() const;
  112. track_ptr track() const;
  113. QList< DownloadFormat > downloadFormats() const;
  114. void setDownloadFormats( const QList<DownloadFormat>& formats );
  115. downloadjob_ptr downloadJob() const { return m_downloadJob; }
  116. downloadjob_ptr toDownloadJob( const DownloadFormat& format );
  117. public slots:
  118. void deleteLater();
  119. signals:
  120. // emitted when the collection this result comes from is going offline/online:
  121. void statusChanged();
  122. void updated();
  123. private slots:
  124. void onOffline();
  125. void onOnline();
  126. void onResolverRemoved( Tomahawk::Resolver* resolver );
  127. void doneEditing();
  128. void onDownloadJobStateChanged( DownloadJob::TrackState newState, DownloadJob::TrackState oldState );
  129. void onSettingsChanged();
  130. private:
  131. // private constructor
  132. explicit Result( const QString& url, const Tomahawk::track_ptr& track );
  133. explicit Result();
  134. mutable QMutex m_mutex;
  135. mutable RID m_rid;
  136. collection_wptr m_collection;
  137. QPointer< Tomahawk::Resolver > m_resolver;
  138. QString m_url;
  139. bool m_isPreview;
  140. QString m_purchaseUrl;
  141. QString m_linkUrl;
  142. QString m_mimetype;
  143. QString m_friendlySource;
  144. QList<DownloadFormat> m_formats;
  145. downloadjob_ptr m_downloadJob;
  146. bool m_checked;
  147. unsigned int m_bitrate;
  148. unsigned int m_size;
  149. unsigned int m_modtime;
  150. unsigned int m_fileId;
  151. track_ptr m_track;
  152. query_wptr m_query;
  153. QWeakPointer< Tomahawk::Result > m_ownRef;
  154. };
  155. } //ns
  156. Q_DECLARE_METATYPE( Tomahawk::result_ptr )
  157. #endif // RESULT_H