12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #ifndef PLAYLISTMODEL_H
- #define PLAYLISTMODEL_H
- #include <qmobilityglobal.h>
- #include <QAbstractItemModel>
- #include <QUrl>
- #include "metadatavalue.h"
- QT_BEGIN_NAMESPACE
- class QMediaPlaylist;
- QT_END_NAMESPACE
- QT_USE_NAMESPACE
- /* Model for a single playlist.
- Wrapper for a QMediaPlaylist from QtMobility.
- Roles exposed so it also works in a QML ListView.
- @author Alan Ezust
- */
- class PlaylistModel : public QAbstractListModel
- {
- Q_OBJECT
- public:
- enum PlayListRoles {
- NameRole = Qt::UserRole + 1,
- UrlRole,
- PictureRole,
- ArtistRole,
- AlbumRole,
- TrackNumberRole,
- DurationRole,
- CommentRole,
- GenreRole,
- LastModifiedRole
- };
- PlaylistModel(QObject *parent = 0);
-
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
-
- QMediaPlaylist *playlist() const;
- void setPlaylist(QMediaPlaylist *playlist);
- int findRow(QUrl key);
- /** @returns true if the entire playlist has been fetched at least once */
- bool isFetched() const {return m_isFetched;}
- public slots:
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
- void fetchAll();
- void fetch(int i);
- void deleteTrack(int i);
- void sortByRole(PlayListRoles role);
- void clear();
- void shuffle();
- void fetched(MetaDataValue);
- void setFetched(bool f = true);
- private slots:
- void beginInsertItems(int start, int end);
- void endInsertItems();
- void beginRemoveItems(int start, int end);
- void endRemoveItems();
- void changeItems(int start, int end);
- private:
- bool m_isFetched;
- QMediaPlaylist *m_playlist;
- QHash<QUrl, int> m_indexes;
- QHash<QUrl, MetaDataValue> m_values;
- };
- #endif
|