/src/libtomahawk/playlist/trackmodel.h

http://github.com/tomahawk-player/tomahawk · C Header · 153 lines · 95 code · 39 blank · 19 comment · 0 complexity · fb73ae9594b9f138bb50a710b845f426 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. * Copyright 2011 Leo Franchi <lfranchi@kde.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 TRACKMODEL_H
  20. #define TRACKMODEL_H
  21. #include <QAbstractItemModel>
  22. #include "playlistinterface.h"
  23. #include "trackmodelitem.h"
  24. #include "typedefs.h"
  25. #include "dllmacro.h"
  26. class QMetaData;
  27. class DLLEXPORT TrackModel : public QAbstractItemModel
  28. {
  29. Q_OBJECT
  30. public:
  31. enum TrackItemStyle
  32. { Detailed = 0, Short = 1, ShortWithAvatars = 2 };
  33. enum TrackModelRole
  34. { StyleRole = Qt::UserRole + 1 };
  35. enum Columns {
  36. Artist = 0,
  37. Track = 1,
  38. Composer = 2,
  39. Album = 3,
  40. AlbumPos = 4,
  41. Duration = 5,
  42. Bitrate = 6,
  43. Age = 7,
  44. Year = 8,
  45. Filesize = 9,
  46. Origin = 10,
  47. Score = 11
  48. };
  49. explicit TrackModel( QObject* parent = 0 );
  50. virtual ~TrackModel();
  51. TrackModel::TrackItemStyle style() const { return m_style; }
  52. void setStyle( TrackModel::TrackItemStyle style );
  53. virtual QModelIndex index( int row, int column, const QModelIndex& parent ) const;
  54. virtual QModelIndex parent( const QModelIndex& child ) const;
  55. virtual bool isReadOnly() const { return m_readOnly; }
  56. virtual void setReadOnly( bool b ) { m_readOnly = b; }
  57. virtual QString title() const { return m_title; }
  58. virtual void setTitle( const QString& title ) { m_title = title; }
  59. virtual QString description() const { return m_description; }
  60. virtual void setDescription( const QString& description ) { m_description = description; }
  61. virtual int trackCount() const { return rowCount( QModelIndex() ); }
  62. virtual int rowCount( const QModelIndex& parent ) const;
  63. virtual int columnCount( const QModelIndex& parent = QModelIndex() ) const;
  64. virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
  65. virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const;
  66. virtual QMimeData* mimeData( const QModelIndexList& indexes ) const;
  67. virtual QStringList mimeTypes() const;
  68. virtual Qt::DropActions supportedDropActions() const;
  69. virtual Qt::ItemFlags flags( const QModelIndex& index ) const;
  70. virtual QPersistentModelIndex currentItem() { return m_currentIndex; }
  71. virtual Tomahawk::QID currentItemUuid() { return m_currentUuid; }
  72. virtual Tomahawk::PlaylistInterface::RepeatMode repeatMode() const { return Tomahawk::PlaylistInterface::NoRepeat; }
  73. virtual bool shuffled() const { return false; }
  74. virtual void ensureResolved();
  75. TrackModelItem* itemFromIndex( const QModelIndex& index ) const;
  76. /// Returns a flat list of all tracks in this model
  77. QList< Tomahawk::query_ptr > queries() const;
  78. signals:
  79. void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
  80. void shuffleModeChanged( bool enabled );
  81. void trackCountChanged( unsigned int tracks );
  82. void loadingStarted();
  83. void loadingFinished();
  84. public slots:
  85. virtual void setCurrentItem( const QModelIndex& index );
  86. virtual void clear();
  87. virtual void append( const QList< Tomahawk::query_ptr >& queries );
  88. virtual void append( const Tomahawk::query_ptr& query );
  89. virtual void append( const Tomahawk::artist_ptr& artist ) { Q_UNUSED( artist ); }
  90. virtual void append( const Tomahawk::album_ptr& album ) { Q_UNUSED( album ); }
  91. virtual void insert( const QList< Tomahawk::query_ptr >& queries, int row = 0 );
  92. virtual void insert( const Tomahawk::query_ptr& query, int row = 0 );
  93. virtual void remove( int row, bool moreToCome = false );
  94. virtual void remove( const QModelIndex& index, bool moreToCome = false );
  95. virtual void remove( const QList<QModelIndex>& indexes );
  96. virtual void remove( const QList<QPersistentModelIndex>& indexes );
  97. virtual void setRepeatMode( Tomahawk::PlaylistInterface::RepeatMode /*mode*/ ) {}
  98. virtual void setShuffled( bool /*shuffled*/ ) {}
  99. protected:
  100. TrackModelItem* rootItem() const { return m_rootItem; }
  101. private slots:
  102. void onPlaybackStarted( const Tomahawk::result_ptr& result );
  103. void onPlaybackStopped();
  104. private:
  105. Qt::Alignment columnAlignment( int column ) const;
  106. TrackModelItem* m_rootItem;
  107. QPersistentModelIndex m_currentIndex;
  108. Tomahawk::QID m_currentUuid;
  109. bool m_readOnly;
  110. QString m_title;
  111. QString m_description;
  112. TrackItemStyle m_style;
  113. };
  114. #endif // TRACKMODEL_H