/src/libtomahawk/PlaylistInterface.h

http://github.com/tomahawk-player/tomahawk · C Header · 137 lines · 82 code · 34 blank · 21 comment · 0 complexity · fb4a6e6c00775e158a33d38e6542ec5b MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2012, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4. * Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
  5. *
  6. * Tomahawk is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Tomahawk is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef PLAYLISTINTERFACE_H
  20. #define PLAYLISTINTERFACE_H
  21. #include <QtCore/QModelIndex>
  22. #include "playlist/PlayableItem.h"
  23. #include "Typedefs.h"
  24. #include "DllMacro.h"
  25. namespace Tomahawk
  26. {
  27. class DLLEXPORT PlaylistInterface : public QObject
  28. {
  29. Q_OBJECT
  30. public:
  31. explicit PlaylistInterface();
  32. virtual ~PlaylistInterface();
  33. const QString id() const { return m_id; }
  34. virtual QList< Tomahawk::query_ptr > tracks() const = 0;
  35. bool isFinished() const { return m_finished; }
  36. bool hasFirstPlayableTrack() const { return m_foundFirstTrack; }
  37. virtual int trackCount() const = 0;
  38. virtual Tomahawk::result_ptr currentItem() const = 0;
  39. virtual void setCurrentIndex( qint64 index );
  40. virtual bool hasNextResult() const;
  41. virtual bool hasPreviousResult() const;
  42. virtual Tomahawk::result_ptr nextResult() const;
  43. virtual Tomahawk::result_ptr previousResult() const;
  44. virtual qint64 siblingIndex( int itemsAway, qint64 rootIndex = -1 ) const = 0;
  45. virtual qint64 siblingResultIndex( int itemsAway, qint64 rootIndex = -1 ) const;
  46. virtual Tomahawk::result_ptr siblingResult( int itemsAway, qint64 rootIndex = -1 ) const;
  47. virtual Tomahawk::result_ptr setSiblingResult( int itemsAway, qint64 rootIndex = -1 );
  48. virtual Tomahawk::result_ptr resultAt( qint64 index ) const = 0;
  49. virtual Tomahawk::query_ptr queryAt( qint64 index ) const = 0;
  50. virtual qint64 indexOfResult( const Tomahawk::result_ptr& result ) const = 0;
  51. virtual qint64 indexOfQuery( const Tomahawk::query_ptr& query ) const = 0;
  52. virtual int posOfResult( const Tomahawk::result_ptr& result ) const;
  53. virtual int posOfQuery( const Tomahawk::query_ptr& query ) const;
  54. virtual PlaylistModes::RepeatMode repeatMode() const = 0;
  55. virtual bool shuffled() const = 0;
  56. virtual PlaylistModes::ViewMode viewMode() const { return PlaylistModes::Unknown; }
  57. virtual PlaylistModes::SeekRestrictions seekRestrictions() const { return PlaylistModes::NoSeekRestrictions; }
  58. virtual PlaylistModes::SkipRestrictions skipRestrictions() const { return PlaylistModes::NoSkipRestrictions; }
  59. virtual PlaylistModes::RetryMode retryMode() const { return PlaylistModes::NoRetry; }
  60. virtual quint32 retryInterval() const { return 30000; }
  61. virtual PlaylistModes::LatchMode latchMode() const { return m_latchMode; }
  62. virtual void setLatchMode( PlaylistModes::LatchMode latchMode ) { m_latchMode = latchMode; }
  63. virtual bool setCurrentTrack( unsigned int albumpos ) { Q_UNUSED( albumpos ); return false; }
  64. virtual void reset() {}
  65. //TODO: Get rid of the next two functions once all playlsitinterfaces are factored out
  66. // Some playlist interfaces can wrap other interfaces. When checking for top-level
  67. // equality (say, to compare the currently playing interface) this might be needed
  68. virtual bool hasChildInterface( const Tomahawk::playlistinterface_ptr& ) { return false; }
  69. public slots:
  70. virtual void setRepeatMode( PlaylistModes::RepeatMode mode ) = 0;
  71. virtual void setShuffled( bool enabled ) = 0;
  72. signals:
  73. void itemCountChanged( unsigned int tracks );
  74. void repeatModeChanged( Tomahawk::PlaylistModes::RepeatMode mode );
  75. void shuffleModeChanged( bool enabled );
  76. void latchModeChanged( Tomahawk::PlaylistModes::LatchMode mode );
  77. void previousTrackAvailable( bool available );
  78. void nextTrackAvailable( bool available );
  79. void currentIndexChanged();
  80. void finishedLoading();
  81. void foundFirstPlayableTrack();
  82. protected slots:
  83. virtual void onItemsChanged();
  84. void startLoading();
  85. void finishLoading();
  86. void onQueryResolved();
  87. protected:
  88. virtual QList<Tomahawk::query_ptr> filterTracks( const QList<Tomahawk::query_ptr>& queries );
  89. PlaylistModes::LatchMode m_latchMode;
  90. mutable bool m_prevAvail;
  91. mutable bool m_nextAvail;
  92. mutable qint64 m_currentIndex;
  93. private:
  94. Q_DISABLE_COPY( PlaylistInterface )
  95. private:
  96. QString m_id;
  97. QString m_filter;
  98. bool m_finished;
  99. bool m_foundFirstTrack;
  100. };
  101. }
  102. Q_DECLARE_METATYPE( Tomahawk::playlistinterface_ptr )
  103. #endif // PLAYLISTINTERFACE_H