playlistmodel.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef PLAYLISTMODEL_H
  2. #define PLAYLISTMODEL_H
  3. #include <qmobilityglobal.h>
  4. #include <QAbstractItemModel>
  5. #include <QUrl>
  6. #include "metadatavalue.h"
  7. QT_BEGIN_NAMESPACE
  8. class QMediaPlaylist;
  9. QT_END_NAMESPACE
  10. QT_USE_NAMESPACE
  11. /* Model for a single playlist.
  12. Wrapper for a QMediaPlaylist from QtMobility.
  13. Roles exposed so it also works in a QML ListView.
  14. @author Alan Ezust
  15. */
  16. class PlaylistModel : public QAbstractListModel
  17. {
  18. Q_OBJECT
  19. public:
  20. enum PlayListRoles {
  21. NameRole = Qt::UserRole + 1,
  22. UrlRole,
  23. PictureRole,
  24. ArtistRole,
  25. AlbumRole,
  26. TrackNumberRole,
  27. DurationRole,
  28. CommentRole,
  29. GenreRole,
  30. LastModifiedRole
  31. };
  32. PlaylistModel(QObject *parent = 0);
  33. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
  34. QMediaPlaylist *playlist() const;
  35. void setPlaylist(QMediaPlaylist *playlist);
  36. int findRow(QUrl key);
  37. /** @returns true if the entire playlist has been fetched at least once */
  38. bool isFetched() const {return m_isFetched;}
  39. public slots:
  40. int rowCount(const QModelIndex &parent = QModelIndex()) const;
  41. void fetchAll();
  42. void fetch(int i);
  43. void deleteTrack(int i);
  44. void sortByRole(PlayListRoles role);
  45. void clear();
  46. void shuffle();
  47. void fetched(MetaDataValue);
  48. void setFetched(bool f = true);
  49. private slots:
  50. void beginInsertItems(int start, int end);
  51. void endInsertItems();
  52. void beginRemoveItems(int start, int end);
  53. void endRemoveItems();
  54. void changeItems(int start, int end);
  55. private:
  56. bool m_isFetched;
  57. QMediaPlaylist *m_playlist;
  58. QHash<QUrl, int> m_indexes;
  59. QHash<QUrl, MetaDataValue> m_values;
  60. };
  61. #endif