qt/mlplaylistmodel: Add insert, move and remove support
[vlc.git] / modules / gui / qt / medialibrary / mlplaylistmodel.hpp
blob2fb9b663c9b8808d6798cb3708d2d1a0cfb83150
1 /*****************************************************************************
2 * Copyright (C) 2021 VLC authors and VideoLAN
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * ( at your option ) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
17 *****************************************************************************/
19 #ifndef MLPLAYLISTMODEL_HPP
20 #define MLPLAYLISTMODEL_HPP
22 // MediaLibrary includes
23 #include "mlbasemodel.hpp"
25 class MLPlaylistModel : public MLBaseModel
27 Q_OBJECT
29 public:
30 enum Role
32 MEDIA_ID = Qt::UserRole + 1,
33 MEDIA_TITLE,
34 MEDIA_THUMBNAIL,
35 MEDIA_DURATION,
36 MEDIA_DURATION_SHORT,
37 MEDIA_PROGRESS,
38 MEDIA_PLAYCOUNT,
39 MEDIA_RESOLUTION,
40 MEDIA_CHANNEL,
41 MEDIA_MRL,
42 MEDIA_DISPLAY_MRL,
43 MEDIA_VIDEO_TRACK,
44 MEDIA_AUDIO_TRACK,
45 MEDIA_TITLE_FIRST_SYMBOL,
48 public:
49 explicit MLPlaylistModel(QObject * parent = nullptr);
51 public: // Interface
52 Q_INVOKABLE void insert(const QVariantList & items, int at);
54 Q_INVOKABLE void move(const QModelIndexList & indexes, int to);
56 Q_INVOKABLE void remove(const QModelIndexList & indexes);
58 public: // QAbstractItemModel implementation
59 QHash<int, QByteArray> roleNames() const override;
61 QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
63 protected: // MLBaseModel implementation
64 vlc_ml_sorting_criteria_t roleToCriteria(int role) const override;
66 vlc_ml_sorting_criteria_t nameToCriteria(QByteArray name) const override;
68 QByteArray criteriaToName(vlc_ml_sorting_criteria_t criteria) const override;
70 ListCacheLoader<std::unique_ptr<MLItem>> * createLoader() const override;
72 private: // Functions
73 QList<int> getRows(const QModelIndexList & indexes) const;
75 private: // MLBaseModel implementation
76 void onVlcMlEvent(const MLEvent & event) override;
78 private:
79 struct Loader : public MLBaseModel::BaseLoader
81 Loader(const MLPlaylistModel & model);
83 size_t count() const override;
85 std::vector<std::unique_ptr<MLItem>> load(size_t index, size_t count) const override;
89 #endif // MLPLAYLISTMODEL_HPP